-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcisco-full.tt2
428 lines (413 loc) · 12.5 KB
/
cisco-full.tt2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
[% # This code determines the names of the route-maps and ACLs
FOREACH ip = conf.keys.sort;
FOREACH afi = [ 'ipv4', 'ipv6', 'ipv4m', 'ipv6m' ];
NEXT IF NOT conf.$ip.$afi;
neigh = conf.$ip;
x = neigh.$afi;
# Here you can modify the map and acl names to support applying
# different policies to different neighbor IPs of the same AS (e.g.
# at different IXes).
IF ip.match('^92\.60\.70\.') OR ip.match('^2a01:658:ffff:');
mapixname = '-MINAP';
ELSE;
mapixname = '';
END;
aclixname = '';
IF afi == 'ipv4';
aclsuffix = '-IN';
x.rpfaclname = 'URPF-AS' _ neigh.as _ ixname;
ELSIF afi == 'ipv6';
aclsuffix = '-IN6';
x.rpfaclname = 'URPF6-AS' _ neigh.as _ ixname;
ELSIF afi == 'ipv4m';
aclsuffix = '-INM';
ELSIF afi == 'ipv6m';
aclsuffix = '-IN6M';
ELSE;
THROW 'Unknown AFI';
END;
IF NOT x.aclname;
x.aclname = 'AS' _ neigh.as _ aclixname _ aclsuffix;
END;
IF NOT x.mapname;
x.mapname = 'AS' _ neigh.as _ mapixname _ aclsuffix;
END;
END;
END;
%]
! lists !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% FOREACH afi = [ 'ipv4', 'ipv6', 'ipv4m', 'ipv6m' ] %]
[% IF seen.pl.${neigh.$afi.aslistnum}; NEXT;
ELSE; seen.pl.${neigh.$afi.aslistnum} = 1; END
%]
[% NEXT IF NOT neigh.$afi.import_as.size %]
no ip as-path access-list [% neigh.$afi.aslistnum +%]
[% aslist = neigh.$afi.import_as.nsort %]
[% IF aslist.size > 30 %]
[% WHILE aslist.size; l = aslist.splice(0, 30) %]
ip as-path access-list [% neigh.$afi.aslistnum %] permit _([% l.join('|') %])$
[% END %]
[% ELSE %]
ip as-path access-list [% neigh.$afi.aslistnum %] permit ^(_([% aslist.join('|') %]))+$
[% END %]
!
[% END %]
[% END %]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% FOREACH afi = [ 'ipv4', 'ipv6', 'ipv4m', 'ipv6m' ] %]
[% IF seen.pl.${neigh.$afi.aclname}; NEXT;
ELSE; seen.pl.${neigh.$afi.aclname} = 1; END
%]
[% IF afi.match('6'); acltype = 'ipv6'; ELSE; acltype = 'ip'; END %]
[% NEXT IF NOT neigh.$afi.import_routes.size %]
no [% acltype %] prefix-list [% neigh.$afi.aclname +%]
[% FOREACH route = neigh.$afi.import_routes %]
[% acltype %] prefix-list [% neigh.$afi.aclname %] permit [% route.route2cisco +%]
[% END %]
!
[% IF neigh.customer %]
no [% acltype %] prefix-list [% neigh.$afi.aclname +%]-HR
[% FOREACH route = neigh.$afi.import_routes.hostroutes %]
[% acltype %] prefix-list [% neigh.$afi.aclname %]-HR permit [% route.route2cisco +%]
[% END %]
!
[% END %]
[% IF neigh.rpfacl %]
[% IF afi.match('^ipv4') %]
no ip access-list standard [% neigh.$afi.rpfaclname +%]
ip access-list standard [% neigh.$afi.rpfaclname +%]
remark [% neigh.description +%]
permit [% neigh.ip %] 0.0.0.0
[% FOREACH route = neigh.$afi.import_routes.aggregate %]
permit [% route.route2stdacl +%]
[% END %]
deny 0.0.0.0 255.255.255.255
[% ELSE %]
no ipv6 access-list [% neigh.$afi.rpfaclname +%]
ipv6 access-list [% neigh.$afi.rpfaclname +%]
remark [% neigh.description +%]
permit fe80::/10 any
permit [% neigh.ip %]/128 any
[% FOREACH route = neigh.$afi.import_routes.aggregate %]
permit [% route +%] any
[% END %]
deny any any
[% END %]
!
[% END %]
[% END %]
[% END %]
! IPv4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv4 %]
[% NEXT IF neigh.is_backup %]
[% mapname = neigh.ipv4.mapname %]
[% IF neigh.customer AND neigh.ipv4.import_routes.size %]
no route-map [% mapname %] permit 9000
route-map [% mapname %] permit 9000
match community BLACKHOLE
match ip address prefix-list [% neigh.ipv4.aclname %]-HR
set comm-list REMOVE-LOCAL delete
set local-preference [% neigh.ipv4.localpref +%]
set ip next-hop 10.255.255.254
!
[% END %]
no route-map [% mapname %] permit 10000
route-map [% mapname %] permit 10000
[% IF neigh.description %]
description Routes from [% neigh.description +%]
[% END %]
[% IF neigh.ipv4.import_routes.size %]
match ip address prefix-list [% neigh.ipv4.aclname +%]
[% ELSE %]
match ip address prefix-list INBOUND-FILTER
[% END %]
[% IF neigh.ipv4.aslistnum %]
match as-path [% neigh.ipv4.aslistnum +%]
[% END %]
set comm-list REMOVE-LOCAL delete
[% IF neigh.customer %]
set local-preference [% neigh.ipv4.localpref +%]
set community [% var.ipv4.customers.community %] additive
[% ELSE %]
set local-preference [% neigh.ipv4.localpref +%]
set community [% var.ipv4.peers.community %][% IF neigh.akamai %][% ' ' _ var.akamai %][% END %] additive
[% END %]
[% IF neigh.ipv4.metric %]
set metric [% neigh.ipv4.metric +%]
[% END %]
!
[% END %]
! IPv4 multicast !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv4m %]
[% NEXT IF neigh.is_backup %]
[% mapname = neigh.ipv4m.mapname %]
no route-map [% mapname %] permit 10000
route-map [% mapname %] permit 10000
[% IF neigh.ipv4m.import_routes.size %]
match ip address prefix-list [% neigh.ipv4m.aclname +%]
[% END %]
[% IF neigh.ipv4m.aslistnum %]
match as-path [% neigh.ipv4m.aslistnum +%]
[% END %]
set comm-list REMOVE-LOCAL delete
[% IF neigh.customer %]
set local-preference [% neigh.ipv4m.localpref +%]
set community [% var.ipv4m.customers.community %] additive
[% ELSE %]
set local-preference [% neigh.ipv4m.localpref +%]
set community [% var.ipv4m.peers.community %] additive
[% END %]
[% IF neigh.ipv4m.metric %]
set metric [% neigh.ipv4m.metric +%]
[% END %]
!
[% END %]
! IPv6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv6 %]
[% NEXT IF neigh.is_backup %]
[% mapname = neigh.ipv6.mapname %]
[% IF neigh.customer AND neigh.ipv6.import_routes.size %]
no route-map [% mapname %] permit 9000
route-map [% mapname %] permit 9000
match community BLACKHOLE
match ipv6 address prefix-list [% neigh.ipv6.aclname %]-HR
set comm-list REMOVE-LOCAL delete
set local-preference [% neigh.ipv6.localpref +%]
set ipv6 next-hop 2001:1418::FFFF:FFFF
!
[% END %]
no route-map [% mapname %] permit 10000
route-map [% mapname %] permit 10000
[% IF neigh.ipv6.import_routes.size %]
match ipv6 address prefix-list [% neigh.ipv6.aclname +%]
[% ELSE %]
match ipv6 address prefix-list INBOUND-FILTER6
[% END %]
[% IF neigh.ipv6.aslistnum %]
match as-path [% neigh.ipv6.aslistnum +%]
[% END %]
set comm-list REMOVE-LOCAL delete
[% IF neigh.customer %]
set local-preference [% neigh.ipv6.localpref +%]
set community [% var.ipv6.customers.community %] additive
[% ELSE %]
set local-preference [% neigh.ipv6.localpref +%]
[% IF neigh.ipv6.community %]
set community [% neigh.ipv6.community %] additive
[% ELSE %]
set community [% var.ipv6.peers.community %] additive
[% END %]
[% END %]
[% IF neigh.ipv6.metric %]
set metric [% neigh.ipv6.metric +%]
[% END %]
!
[% END %]
! IPv6 multicast !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv6m %]
[% NEXT IF neigh.is_backup %]
[% mapname = neigh.ipv6m.mapname %]
no route-map [% mapname %] permit 10000
route-map [% mapname %] permit 10000
[% IF neigh.ipv6m.import_routes.size %]
match ipv6 address prefix-list [% neigh.ipv6m.aclname +%]
[% END %]
[% IF neigh.ipv6m.aslistnum %]
match as-path [% neigh.ipv6m.aslistnum +%]
[% END %]
set comm-list REMOVE-LOCAL delete
[% IF neigh.customer %]
set local-preference [% neigh.ipv6m.localpref +%]
set community [% var.ipv6m.customers.community %] additive
[% ELSE %]
set local-preference [% neigh.ipv6m.localpref +%]
set community [% var.ipv6m.peers.community %] additive
[% IF neigh.ipv6m.metric %]
set metric [% neigh.ipv6m.metric +%]
[% END %]
[% END %]
!
[% END %]
[%#
! generic outbound route-maps !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
no route-map MAP-CUST-OUT6
!
route-map MAP-CUST-OUT6 deny 3010
match community BLACKHOLE
!
route-map MAP-CUST-OUT6 permit 10000
!
no route-map MAP-CUST-OUT6M
!
route-map MAP-CUST-OUT6M deny 3010
match community BLACKHOLE
!
route-map MAP-CUST-OUT6M permit 10000
!
no route-map MAP-PEER-OUT6
!
route-map MAP-PEER-OUT6 deny 3010
match community NO-ANNOUNCE-TOPIX
!
route-map MAP-PEER-OUT6 permit 4010
match community PREPEND-TOPIX
set as-path prepend 65000 65000 65000
continue
!
route-map MAP-PEER-OUT6 permit 10000
match community CUSTOMER6
!
no route-map MAP-PEER-OUT6M
!
route-map MAP-PEER-OUT6M permit 10000
match community CUSTOMER6
!
%]
! BGP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
router bgp 65000
[%#
neighbor PEERS peer-group
neighbor PEERS version 4
neighbor CUSTOMERS peer-group
neighbor CUSTOMERS version 4
%]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
neighbor [% ip %] remote-as [% neigh.as +%]
[% IF neigh.peergroup %]
neighbor [% ip %] peer-group [% neigh.peergroup +%]
[% ELSE %]
neighbor [% ip %] version 4
[% END %]
[% IF neigh.description %]
neighbor [% ip %] description [% neigh.description +%]
[% END %]
[% FOREACH cmd = neigh.bgp_commands %]
neighbor [% ip %] [% cmd +%]
[% END %]
[% END %]
!
[%# IPv4 ###################################################################%]
address-family ipv4
[%#
neighbor PEERS send-community
neighbor PEERS soft-reconfiguration inbound
neighbor PEERS route-map MAP-PEER-OUT out
neighbor CUSTOMERS send-community
neighbor CUSTOMERS route-map MIX-CUSTOMER-OUT out
neighbor CUSTOMERS remove-private-as
%]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv4 %]
neighbor [% ip %] activate
[% IF NOT neigh.peergroup %]
neighbor [% ip %] send-community
neighbor [% ip %] soft-reconfiguration inbound
neighbor [% ip %] route-map AS[% neigh.as %]-OUT out
[% END %]
neighbor [% ip %] route-map [% neigh.ipv4.mapname %] in
[% IF neigh.ipv4.maxpref %]
neighbor [% ip %] maximum-prefix [% neigh.ipv4.maxpref %] 85
[% END %]
[% FOREACH cmd = neigh.ipv4.bgp_commands %]
neighbor [% ip %] [% cmd +%]
[% END %]
[% END %]
exit-address-family
!
[%# IPv4 multicast #########################################################%]
address-family ipv4 multicast
[%#
neighbor PEERS send-community
neighbor PEERS soft-reconfiguration inbound
neighbor PEERS route-map MAP-PEER-OUTM out
%]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv4m %]
neighbor [% ip %] activate
[% IF NOT neigh.peergroup %]
neighbor [% ip %] send-community
neighbor [% ip %] soft-reconfiguration inbound
neighbor [% ip %] route-map AS[% neigh.as %]-OUTM out
[% END %]
neighbor [% ip %] route-map [% neigh.ipv4m.mapname %] in
[% IF neigh.ipv4m.maxpref %]
neighbor [% ip %] maximum-prefix [% neigh.ipv4m.maxpref %] 85
[% END %]
[% FOREACH cmd = neigh.ipv4m.bgp_commands %]
neighbor [% ip %] [% cmd +%]
[% END %]
[% END %]
exit-address-family
!
[%# IPv6 ###################################################################%]
address-family ipv6
[%#
neighbor PEERS send-community
neighbor PEERS soft-reconfiguration inbound
neighbor PEERS route-map MAP-PEER-OUT6 out
neighbor CUSTOMERS send-community
neighbor CUSTOMERS soft-reconfiguration inbound
neighbor CUSTOMERS route-map MAP-CUST-OUT6 out
%]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv6 %]
neighbor [% ip %] activate
[% IF NOT neigh.peergroup %]
neighbor [% ip %] send-community
neighbor [% ip %] soft-reconfiguration inbound
neighbor [% ip %] route-map AS[% neigh.as %]-OUT6 out
[% END %]
neighbor [% ip %] route-map [% neigh.ipv6.mapname %] in
[% IF neigh.ipv6.maxpref %]
neighbor [% ip %] maximum-prefix [% neigh.ipv6.maxpref %] 85
[% END %]
[% FOREACH cmd = neigh.ipv6.bgp_commands %]
neighbor [% ip %] [% cmd +%]
[% END %]
[% END %]
exit-address-family
!
[%# IPv6 multicast #########################################################%]
address-family ipv6 multicast
[%#
neighbor PEERS send-community
neighbor PEERS soft-reconfiguration inbound
neighbor PEERS route-map MAP-PEER-OUT6M out
%]
[% FOREACH ip = conf.keys.sort %]
[% neigh = conf.$ip %]
[% NEXT IF NOT neigh.ipv6m %]
neighbor [% ip %] activate
[% IF NOT neigh.peergroup %]
neighbor [% ip %] send-community
neighbor [% ip %] soft-reconfiguration inbound
neighbor [% ip %] route-map AS[% neigh.as %]-OUT6M out
[% END %]
neighbor [% ip %] route-map [% neigh.ipv6m.mapname %] in
[% IF neigh.ipv6m.maxpref %]
neighbor [% ip %] maximum-prefix [% neigh.ipv6m.maxpref %] 85
[% END %]
[% FOREACH cmd = neigh.ipv6m.bgp_commands %]
neighbor [% ip %] [% cmd +%]
[% END %]
[% END %]
exit-address-family
!
end
[%# USE Dumper(Indent=1) %]
[%# Dumper.dump(conf) %]