]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_filter.c
Merge pull request #5163 from ton31337/fix/do_not_reconnect_if_prefix_overflow_7.1
[mirror_frr.git] / bgpd / bgp_filter.c
CommitLineData
718e3744 1/* AS path filter list.
896014f4
DL
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
24#include "log.h"
25#include "memory.h"
26#include "buffer.h"
3f9c7369 27#include "queue.h"
039f3a34 28#include "filter.h"
718e3744 29
30#include "bgpd/bgpd.h"
31#include "bgpd/bgp_aspath.h"
32#include "bgpd/bgp_regex.h"
33#include "bgpd/bgp_filter.h"
34
35/* List of AS filter list. */
d62a17ae 36struct as_list_list {
37 struct as_list *head;
38 struct as_list *tail;
718e3744 39};
40
41/* AS path filter master. */
d62a17ae 42struct as_list_master {
43 /* List of access_list which name is number. */
44 struct as_list_list num;
718e3744 45
d62a17ae 46 /* List of access_list which name is string. */
47 struct as_list_list str;
718e3744 48
d62a17ae 49 /* Hook function which is executed when new access_list is added. */
50 void (*add_hook)(char *);
718e3744 51
d62a17ae 52 /* Hook function which is executed when access_list is deleted. */
53 void (*delete_hook)(const char *);
718e3744 54};
55
56/* Element of AS path filter. */
d62a17ae 57struct as_filter {
58 struct as_filter *next;
59 struct as_filter *prev;
718e3744 60
d62a17ae 61 enum as_filter_type type;
718e3744 62
d62a17ae 63 regex_t *reg;
64 char *reg_str;
718e3744 65};
66
718e3744 67/* AS path filter list. */
d62a17ae 68struct as_list {
69 char *name;
718e3744 70
d62a17ae 71 enum access_type type;
718e3744 72
d62a17ae 73 struct as_list *next;
74 struct as_list *prev;
718e3744 75
d62a17ae 76 struct as_filter *head;
77 struct as_filter *tail;
718e3744 78};
6b0655a2 79
7336e101 80/* as-path access-list 10 permit AS1. */
718e3744 81
d62a17ae 82static struct as_list_master as_list_master = {{NULL, NULL},
83 {NULL, NULL},
84 NULL,
85 NULL};
718e3744 86
87/* Allocate new AS filter. */
d62a17ae 88static struct as_filter *as_filter_new(void)
718e3744 89{
d62a17ae 90 return XCALLOC(MTYPE_AS_FILTER, sizeof(struct as_filter));
718e3744 91}
92
93/* Free allocated AS filter. */
d62a17ae 94static void as_filter_free(struct as_filter *asfilter)
718e3744 95{
d62a17ae 96 if (asfilter->reg)
97 bgp_regex_free(asfilter->reg);
0a22ddfb 98 XFREE(MTYPE_AS_FILTER_STR, asfilter->reg_str);
d62a17ae 99 XFREE(MTYPE_AS_FILTER, asfilter);
718e3744 100}
101
102/* Make new AS filter. */
d62a17ae 103static struct as_filter *as_filter_make(regex_t *reg, const char *reg_str,
104 enum as_filter_type type)
718e3744 105{
d62a17ae 106 struct as_filter *asfilter;
718e3744 107
d62a17ae 108 asfilter = as_filter_new();
109 asfilter->reg = reg;
110 asfilter->type = type;
111 asfilter->reg_str = XSTRDUP(MTYPE_AS_FILTER_STR, reg_str);
718e3744 112
d62a17ae 113 return asfilter;
718e3744 114}
115
d62a17ae 116static struct as_filter *as_filter_lookup(struct as_list *aslist,
117 const char *reg_str,
118 enum as_filter_type type)
718e3744 119{
d62a17ae 120 struct as_filter *asfilter;
718e3744 121
d62a17ae 122 for (asfilter = aslist->head; asfilter; asfilter = asfilter->next)
123 if (strcmp(reg_str, asfilter->reg_str) == 0)
124 return asfilter;
125 return NULL;
718e3744 126}
127
d62a17ae 128static void as_list_filter_add(struct as_list *aslist,
129 struct as_filter *asfilter)
718e3744 130{
d62a17ae 131 asfilter->next = NULL;
132 asfilter->prev = aslist->tail;
718e3744 133
d62a17ae 134 if (aslist->tail)
135 aslist->tail->next = asfilter;
136 else
137 aslist->head = asfilter;
138 aslist->tail = asfilter;
518f0eb1 139
d62a17ae 140 /* Run hook function. */
141 if (as_list_master.add_hook)
142 (*as_list_master.add_hook)(aslist->name);
718e3744 143}
144
145/* Lookup as_list from list of as_list by name. */
d62a17ae 146struct as_list *as_list_lookup(const char *name)
718e3744 147{
d62a17ae 148 struct as_list *aslist;
718e3744 149
d62a17ae 150 if (name == NULL)
151 return NULL;
718e3744 152
d62a17ae 153 for (aslist = as_list_master.num.head; aslist; aslist = aslist->next)
154 if (strcmp(aslist->name, name) == 0)
155 return aslist;
718e3744 156
d62a17ae 157 for (aslist = as_list_master.str.head; aslist; aslist = aslist->next)
158 if (strcmp(aslist->name, name) == 0)
159 return aslist;
718e3744 160
d62a17ae 161 return NULL;
718e3744 162}
163
d62a17ae 164static struct as_list *as_list_new(void)
718e3744 165{
d62a17ae 166 return XCALLOC(MTYPE_AS_LIST, sizeof(struct as_list));
718e3744 167}
168
d62a17ae 169static void as_list_free(struct as_list *aslist)
718e3744 170{
d62a17ae 171 if (aslist->name) {
172 XFREE(MTYPE_AS_STR, aslist->name);
173 aslist->name = NULL;
174 }
175 XFREE(MTYPE_AS_LIST, aslist);
718e3744 176}
177
178/* Insert new AS list to list of as_list. Each as_list is sorted by
179 the name. */
d62a17ae 180static struct as_list *as_list_insert(const char *name)
181{
182 size_t i;
183 long number;
184 struct as_list *aslist;
185 struct as_list *point;
186 struct as_list_list *list;
187
188 /* Allocate new access_list and copy given name. */
189 aslist = as_list_new();
190 aslist->name = XSTRDUP(MTYPE_AS_STR, name);
191 assert(aslist->name);
192
193 /* If name is made by all digit character. We treat it as
194 number. */
195 for (number = 0, i = 0; i < strlen(name); i++) {
196 if (isdigit((int)name[i]))
197 number = (number * 10) + (name[i] - '0');
198 else
199 break;
200 }
201
202 /* In case of name is all digit character */
203 if (i == strlen(name)) {
204 aslist->type = ACCESS_TYPE_NUMBER;
205
206 /* Set access_list to number list. */
207 list = &as_list_master.num;
208
209 for (point = list->head; point; point = point->next)
210 if (atol(point->name) >= number)
211 break;
212 } else {
213 aslist->type = ACCESS_TYPE_STRING;
214
215 /* Set access_list to string list. */
216 list = &as_list_master.str;
217
218 /* Set point to insertion point. */
219 for (point = list->head; point; point = point->next)
220 if (strcmp(point->name, name) >= 0)
221 break;
222 }
223
224 /* In case of this is the first element of master. */
225 if (list->head == NULL) {
226 list->head = list->tail = aslist;
227 return aslist;
228 }
229
230 /* In case of insertion is made at the tail of access_list. */
231 if (point == NULL) {
232 aslist->prev = list->tail;
233 list->tail->next = aslist;
234 list->tail = aslist;
235 return aslist;
236 }
237
238 /* In case of insertion is made at the head of access_list. */
239 if (point == list->head) {
240 aslist->next = list->head;
241 list->head->prev = aslist;
242 list->head = aslist;
243 return aslist;
244 }
245
246 /* Insertion is made at middle of the access_list. */
247 aslist->next = point;
248 aslist->prev = point->prev;
249
250 if (point->prev)
251 point->prev->next = aslist;
252 point->prev = aslist;
253
254 return aslist;
718e3744 255}
256
d62a17ae 257static struct as_list *as_list_get(const char *name)
718e3744 258{
d62a17ae 259 struct as_list *aslist;
718e3744 260
d62a17ae 261 aslist = as_list_lookup(name);
262 if (aslist == NULL)
263 aslist = as_list_insert(name);
718e3744 264
d62a17ae 265 return aslist;
718e3744 266}
267
d62a17ae 268static const char *filter_type_str(enum as_filter_type type)
718e3744 269{
d62a17ae 270 switch (type) {
271 case AS_FILTER_PERMIT:
272 return "permit";
273 case AS_FILTER_DENY:
274 return "deny";
275 default:
276 return "";
277 }
718e3744 278}
279
d62a17ae 280static void as_list_delete(struct as_list *aslist)
718e3744 281{
d62a17ae 282 struct as_list_list *list;
283 struct as_filter *filter, *next;
284
285 for (filter = aslist->head; filter; filter = next) {
286 next = filter->next;
287 as_filter_free(filter);
288 }
289
290 if (aslist->type == ACCESS_TYPE_NUMBER)
291 list = &as_list_master.num;
292 else
293 list = &as_list_master.str;
294
295 if (aslist->next)
296 aslist->next->prev = aslist->prev;
297 else
298 list->tail = aslist->prev;
299
300 if (aslist->prev)
301 aslist->prev->next = aslist->next;
302 else
303 list->head = aslist->next;
304
305 as_list_free(aslist);
718e3744 306}
307
d62a17ae 308static int as_list_empty(struct as_list *aslist)
718e3744 309{
d62a17ae 310 if (aslist->head == NULL && aslist->tail == NULL)
311 return 1;
312 else
313 return 0;
718e3744 314}
315
d62a17ae 316static void as_list_filter_delete(struct as_list *aslist,
317 struct as_filter *asfilter)
718e3744 318{
d62a17ae 319 char *name = XSTRDUP(MTYPE_AS_STR, aslist->name);
518f0eb1 320
d62a17ae 321 if (asfilter->next)
322 asfilter->next->prev = asfilter->prev;
323 else
324 aslist->tail = asfilter->prev;
718e3744 325
d62a17ae 326 if (asfilter->prev)
327 asfilter->prev->next = asfilter->next;
328 else
329 aslist->head = asfilter->next;
718e3744 330
d62a17ae 331 as_filter_free(asfilter);
718e3744 332
d62a17ae 333 /* If access_list becomes empty delete it from access_master. */
334 if (as_list_empty(aslist))
335 as_list_delete(aslist);
718e3744 336
d62a17ae 337 /* Run hook function. */
338 if (as_list_master.delete_hook)
339 (*as_list_master.delete_hook)(name);
0a22ddfb 340 XFREE(MTYPE_AS_STR, name);
718e3744 341}
6b0655a2 342
d62a17ae 343static int as_filter_match(struct as_filter *asfilter, struct aspath *aspath)
718e3744 344{
d62a17ae 345 if (bgp_regexec(asfilter->reg, aspath) != REG_NOMATCH)
346 return 1;
347 return 0;
718e3744 348}
349
350/* Apply AS path filter to AS. */
d62a17ae 351enum as_filter_type as_list_apply(struct as_list *aslist, void *object)
718e3744 352{
d62a17ae 353 struct as_filter *asfilter;
354 struct aspath *aspath;
718e3744 355
d62a17ae 356 aspath = (struct aspath *)object;
718e3744 357
d62a17ae 358 if (aslist == NULL)
359 return AS_FILTER_DENY;
718e3744 360
d62a17ae 361 for (asfilter = aslist->head; asfilter; asfilter = asfilter->next) {
362 if (as_filter_match(asfilter, aspath))
363 return asfilter->type;
364 }
365 return AS_FILTER_DENY;
718e3744 366}
367
368/* Add hook function. */
d62a17ae 369void as_list_add_hook(void (*func)(char *))
718e3744 370{
d62a17ae 371 as_list_master.add_hook = func;
718e3744 372}
373
374/* Delete hook function. */
d62a17ae 375void as_list_delete_hook(void (*func)(const char *))
718e3744 376{
d62a17ae 377 as_list_master.delete_hook = func;
718e3744 378}
6b0655a2 379
d62a17ae 380static int as_list_dup_check(struct as_list *aslist, struct as_filter *new)
718e3744 381{
d62a17ae 382 struct as_filter *asfilter;
383
384 for (asfilter = aslist->head; asfilter; asfilter = asfilter->next) {
385 if (asfilter->type == new->type
386 && strcmp(asfilter->reg_str, new->reg_str) == 0)
387 return 1;
388 }
389 return 0;
718e3744 390}
391
c3900853 392int config_bgp_aspath_validate(const char *regstr)
672c2d75 393{
da6035e9 394 char valid_chars[] = "1234567890_^|[,{}() ]$*+.?-\\";
672c2d75
DA
395
396 if (strspn(regstr, valid_chars) == strlen(regstr))
397 return 1;
398
399 return 0;
400}
401
7336e101
SP
402DEFUN(as_path, bgp_as_path_cmd,
403 "bgp as-path access-list WORD <deny|permit> LINE...",
404 BGP_STR
672c2d75
DA
405 "BGP autonomous system path filter\n"
406 "Specify an access list name\n"
407 "Regular expression access list name\n"
408 "Specify packets to reject\n"
409 "Specify packets to forward\n"
a818ea74 410 "A regular-expression (1234567890_^|[,{}() ]$*+.?-\\) to match the BGP AS paths\n")
718e3744 411{
d62a17ae 412 int idx = 0;
413 enum as_filter_type type;
414 struct as_filter *asfilter;
415 struct as_list *aslist;
416 regex_t *regex;
417 char *regstr;
418
7336e101
SP
419 if (argv_find(argv, argc, "ip", &idx)) {
420 vty_out(vty, "This config option is deprecated and is scheduled for removal.\n");
421 vty_out(vty, "if you are using this please migrate to the below command\n");
422 vty_out(vty, "'bgp as-path access-list WORD <deny|permit> LINE'\n");
423 zlog_warn("Deprecated option: 'ip as-path access-list WORD <deny|permit> LINE' being used");
424 }
425
d62a17ae 426 /* Retrieve access list name */
e991f75c
VJ
427 argv_find(argv, argc, "WORD", &idx);
428 char *alname = argv[idx]->arg;
d62a17ae 429
430 /* Check the filter type. */
431 type = argv_find(argv, argc, "deny", &idx) ? AS_FILTER_DENY
432 : AS_FILTER_PERMIT;
433
434 /* Check AS path regex. */
435 argv_find(argv, argc, "LINE", &idx);
436 regstr = argv_concat(argv, argc, idx);
437
438 regex = bgp_regcomp(regstr);
439 if (!regex) {
440 vty_out(vty, "can't compile regexp %s\n", regstr);
441 XFREE(MTYPE_TMP, regstr);
442 return CMD_WARNING_CONFIG_FAILED;
443 }
444
672c2d75
DA
445 if (!config_bgp_aspath_validate(regstr)) {
446 vty_out(vty, "Invalid character in as-path access-list %s\n",
447 regstr);
448 return CMD_WARNING_CONFIG_FAILED;
449 }
450
d62a17ae 451 asfilter = as_filter_make(regex, regstr, type);
452
453 XFREE(MTYPE_TMP, regstr);
454
455 /* Install new filter to the access_list. */
456 aslist = as_list_get(alname);
457
458 /* Duplicate insertion check. */;
459 if (as_list_dup_check(aslist, asfilter))
460 as_filter_free(asfilter);
461 else
462 as_list_filter_add(aslist, asfilter);
463
464 return CMD_SUCCESS;
718e3744 465}
466
7336e101
SP
467#if CONFDATE > 20191005
468CPP_NOTICE("bgpd: remove deprecated 'ip as-path access-list WORD <deny|permit> LINE' command")
469#endif
470ALIAS(as_path, ip_as_path_cmd,
471 "ip as-path access-list WORD <deny|permit> LINE...",
472 IP_STR
473 "BGP autonomous system path filter\n"
474 "Specify an access list name\n"
475 "Regular expression access list name\n"
476 "Specify packets to reject\n"
477 "Specify packets to forward\n"
a818ea74 478 "A regular-expression (1234567890_^|[,{}() ]$*+.?-\\) to match the BGP AS paths\n")
7336e101
SP
479
480DEFUN(no_as_path, no_bgp_as_path_cmd,
481 "no bgp as-path access-list WORD <deny|permit> LINE...",
482 NO_STR
483 BGP_STR
672c2d75
DA
484 "BGP autonomous system path filter\n"
485 "Specify an access list name\n"
486 "Regular expression access list name\n"
487 "Specify packets to reject\n"
488 "Specify packets to forward\n"
a818ea74 489 "A regular-expression (1234567890_^|[,{}() ]$*+.?-\\) to match the BGP AS paths\n")
718e3744 490{
d62a17ae 491 int idx = 0;
492 enum as_filter_type type;
493 struct as_filter *asfilter;
494 struct as_list *aslist;
495 char *regstr;
496 regex_t *regex;
497
7336e101
SP
498 if (argv_find(argv, argc, "ip", &idx)) {
499 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
500 vty_out(vty, "if you are using this please migrate to the below command\n");
501 vty_out(vty, "'no bgp as-path access-list WORD <deny|permit> LINE'\n");
502 zlog_warn("Deprecated option: 'no ip as-path access-list WORD <deny|permit> LINE' being used");
503 }
d62a17ae 504 char *aslistname =
505 argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
506
507 /* Lookup AS list from AS path list. */
508 aslist = as_list_lookup(aslistname);
509 if (aslist == NULL) {
7336e101 510 vty_out(vty, "bgp as-path access-list %s doesn't exist\n",
d62a17ae 511 aslistname);
512 return CMD_WARNING_CONFIG_FAILED;
513 }
514
515 /* Check the filter type. */
516 if (argv_find(argv, argc, "permit", &idx))
517 type = AS_FILTER_PERMIT;
518 else if (argv_find(argv, argc, "deny", &idx))
519 type = AS_FILTER_DENY;
520 else {
521 vty_out(vty, "filter type must be [permit|deny]\n");
522 return CMD_WARNING_CONFIG_FAILED;
523 }
524
525 /* Compile AS path. */
526 argv_find(argv, argc, "LINE", &idx);
527 regstr = argv_concat(argv, argc, idx);
528
672c2d75
DA
529 if (!config_bgp_aspath_validate(regstr)) {
530 vty_out(vty, "Invalid character in as-path access-list %s\n",
531 regstr);
532 return CMD_WARNING_CONFIG_FAILED;
533 }
534
d62a17ae 535 regex = bgp_regcomp(regstr);
536 if (!regex) {
537 vty_out(vty, "can't compile regexp %s\n", regstr);
538 XFREE(MTYPE_TMP, regstr);
539 return CMD_WARNING_CONFIG_FAILED;
540 }
541
542 /* Lookup asfilter. */
543 asfilter = as_filter_lookup(aslist, regstr, type);
544
545 XFREE(MTYPE_TMP, regstr);
546 bgp_regex_free(regex);
547
548 if (asfilter == NULL) {
549 vty_out(vty, "\n");
550 return CMD_WARNING_CONFIG_FAILED;
551 }
552
553 as_list_filter_delete(aslist, asfilter);
554
555 return CMD_SUCCESS;
718e3744 556}
557
7336e101
SP
558ALIAS(no_as_path, no_ip_as_path_cmd,
559 "no ip as-path access-list WORD <deny|permit> LINE...",
560 NO_STR IP_STR
561 "BGP autonomous system path filter\n"
562 "Specify an access list name\n"
563 "Regular expression access list name\n"
564 "Specify packets to reject\n"
565 "Specify packets to forward\n"
a818ea74 566 "A regular-expression (1234567890_^|[,{}() ]$*+.?-\\) to match the BGP AS paths\n")
7336e101
SP
567
568DEFUN (no_as_path_all,
569 no_bgp_as_path_all_cmd,
570 "no bgp as-path access-list WORD",
718e3744 571 NO_STR
7336e101 572 BGP_STR
718e3744 573 "BGP autonomous system path filter\n"
574 "Specify an access list name\n"
575 "Regular expression access list name\n")
576{
d62a17ae 577 int idx_word = 4;
578 struct as_list *aslist;
7336e101
SP
579 int idx = 0;
580
581 if (argv_find(argv, argc, "ip", &idx)) {
582 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
583 vty_out(vty, "if you are using this please migrate to the below command\n");
584 vty_out(vty, "'no bgp as-path access-list WORD'\n");
585 zlog_warn("Deprecated option: `no ip as-path access-list WORD` being used");
586 }
718e3744 587
d62a17ae 588 aslist = as_list_lookup(argv[idx_word]->arg);
589 if (aslist == NULL) {
7336e101 590 vty_out(vty, "bgp as-path access-list %s doesn't exist\n",
d62a17ae 591 argv[idx_word]->arg);
592 return CMD_WARNING_CONFIG_FAILED;
593 }
718e3744 594
d62a17ae 595 as_list_delete(aslist);
718e3744 596
d62a17ae 597 /* Run hook function. */
598 if (as_list_master.delete_hook)
599 (*as_list_master.delete_hook)(argv[idx_word]->arg);
e0701b79 600
d62a17ae 601 return CMD_SUCCESS;
718e3744 602}
603
7336e101
SP
604ALIAS (no_as_path_all,
605 no_ip_as_path_all_cmd,
606 "no ip as-path access-list WORD",
607 NO_STR
608 IP_STR
609 "BGP autonomous system path filter\n"
610 "Specify an access list name\n"
611 "Regular expression access list name\n")
612
d62a17ae 613static void as_list_show(struct vty *vty, struct as_list *aslist)
4f991ef0 614{
d62a17ae 615 struct as_filter *asfilter;
4f991ef0 616
d62a17ae 617 vty_out(vty, "AS path access list %s\n", aslist->name);
4f991ef0 618
d62a17ae 619 for (asfilter = aslist->head; asfilter; asfilter = asfilter->next) {
620 vty_out(vty, " %s %s\n", filter_type_str(asfilter->type),
621 asfilter->reg_str);
622 }
4f991ef0 623}
624
d62a17ae 625static void as_list_show_all(struct vty *vty)
4f991ef0 626{
d62a17ae 627 struct as_list *aslist;
628 struct as_filter *asfilter;
4f991ef0 629
d62a17ae 630 for (aslist = as_list_master.num.head; aslist; aslist = aslist->next) {
631 vty_out(vty, "AS path access list %s\n", aslist->name);
4f991ef0 632
d62a17ae 633 for (asfilter = aslist->head; asfilter;
634 asfilter = asfilter->next) {
635 vty_out(vty, " %s %s\n",
636 filter_type_str(asfilter->type),
637 asfilter->reg_str);
638 }
4f991ef0 639 }
4f991ef0 640
d62a17ae 641 for (aslist = as_list_master.str.head; aslist; aslist = aslist->next) {
642 vty_out(vty, "AS path access list %s\n", aslist->name);
4f991ef0 643
d62a17ae 644 for (asfilter = aslist->head; asfilter;
645 asfilter = asfilter->next) {
646 vty_out(vty, " %s %s\n",
647 filter_type_str(asfilter->type),
648 asfilter->reg_str);
649 }
4f991ef0 650 }
4f991ef0 651}
652
7336e101
SP
653DEFUN (show_as_path_access_list,
654 show_bgp_as_path_access_list_cmd,
655 "show bgp as-path-access-list WORD",
4f991ef0 656 SHOW_STR
7336e101 657 BGP_STR
4f991ef0 658 "List AS path access lists\n"
659 "AS path access list name\n")
660{
d62a17ae 661 int idx_word = 3;
662 struct as_list *aslist;
7336e101 663 int idx = 0;
4f991ef0 664
7336e101
SP
665 if (argv_find(argv, argc, "ip", &idx)) {
666 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
667 vty_out(vty, "if you are using this please migrate to the below command\n");
668 vty_out(vty, "'show bgp as-path-access-list WORD'\n");
669 zlog_warn("Deprecated option: 'show ip as-path-access-list WORD' being used");
670 }
d62a17ae 671 aslist = as_list_lookup(argv[idx_word]->arg);
672 if (aslist)
673 as_list_show(vty, aslist);
4f991ef0 674
d62a17ae 675 return CMD_SUCCESS;
4f991ef0 676}
677
7336e101
SP
678ALIAS (show_as_path_access_list,
679 show_ip_as_path_access_list_cmd,
680 "show ip as-path-access-list WORD",
4f991ef0 681 SHOW_STR
682 IP_STR
7336e101
SP
683 "List AS path access lists\n"
684 "AS path access list name\n")
685
686DEFUN (show_as_path_access_list_all,
687 show_bgp_as_path_access_list_all_cmd,
688 "show bgp as-path-access-list",
689 SHOW_STR
690 BGP_STR
4f991ef0 691 "List AS path access lists\n")
692{
7336e101
SP
693 int idx = 0;
694
695 if (argv_find(argv, argc, "ip", &idx)) {
696 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
697 vty_out(vty, "if you are using this please migrate to the below command\n");
698 vty_out(vty, "'show bgp as-path-access-list'\n");
699 zlog_warn("Deprecated option: 'show ip as-path-access-list' being used");
700 }
d62a17ae 701 as_list_show_all(vty);
702 return CMD_SUCCESS;
4f991ef0 703}
704
7336e101
SP
705ALIAS (show_as_path_access_list_all,
706 show_ip_as_path_access_list_all_cmd,
707 "show ip as-path-access-list",
708 SHOW_STR
709 IP_STR
710 "List AS path access lists\n")
711
d62a17ae 712static int config_write_as_list(struct vty *vty)
713{
714 struct as_list *aslist;
715 struct as_filter *asfilter;
716 int write = 0;
717
718 for (aslist = as_list_master.num.head; aslist; aslist = aslist->next)
719 for (asfilter = aslist->head; asfilter;
720 asfilter = asfilter->next) {
7336e101 721 vty_out(vty, "bgp as-path access-list %s %s %s\n",
d62a17ae 722 aslist->name, filter_type_str(asfilter->type),
723 asfilter->reg_str);
724 write++;
725 }
726
727 for (aslist = as_list_master.str.head; aslist; aslist = aslist->next)
728 for (asfilter = aslist->head; asfilter;
729 asfilter = asfilter->next) {
7336e101 730 vty_out(vty, "bgp as-path access-list %s %s %s\n",
d62a17ae 731 aslist->name, filter_type_str(asfilter->type),
732 asfilter->reg_str);
733 write++;
734 }
735 return write;
718e3744 736}
737
d62a17ae 738static struct cmd_node as_list_node = {AS_LIST_NODE, "", 1};
718e3744 739
740/* Register functions. */
d62a17ae 741void bgp_filter_init(void)
718e3744 742{
d62a17ae 743 install_node(&as_list_node, config_write_as_list);
718e3744 744
7336e101 745 install_element(CONFIG_NODE, &bgp_as_path_cmd);
d62a17ae 746 install_element(CONFIG_NODE, &ip_as_path_cmd);
7336e101 747 install_element(CONFIG_NODE, &no_bgp_as_path_cmd);
d62a17ae 748 install_element(CONFIG_NODE, &no_ip_as_path_cmd);
7336e101 749 install_element(CONFIG_NODE, &no_bgp_as_path_all_cmd);
d62a17ae 750 install_element(CONFIG_NODE, &no_ip_as_path_all_cmd);
4f991ef0 751
7336e101 752 install_element(VIEW_NODE, &show_bgp_as_path_access_list_cmd);
d62a17ae 753 install_element(VIEW_NODE, &show_ip_as_path_access_list_cmd);
7336e101 754 install_element(VIEW_NODE, &show_bgp_as_path_access_list_all_cmd);
d62a17ae 755 install_element(VIEW_NODE, &show_ip_as_path_access_list_all_cmd);
718e3744 756}
228da428 757
d62a17ae 758void bgp_filter_reset(void)
228da428 759{
d62a17ae 760 struct as_list *aslist;
761 struct as_list *next;
762
763 for (aslist = as_list_master.num.head; aslist; aslist = next) {
764 next = aslist->next;
765 as_list_delete(aslist);
766 }
767
768 for (aslist = as_list_master.str.head; aslist; aslist = next) {
769 next = aslist->next;
770 as_list_delete(aslist);
771 }
772
773 assert(as_list_master.num.head == NULL);
774 assert(as_list_master.num.tail == NULL);
775
776 assert(as_list_master.str.head == NULL);
777 assert(as_list_master.str.tail == NULL);
228da428 778}