]> git.proxmox.com Git - mirror_frr.git/blob - lib/plist.c
Merge pull request #2697 from mjstapp/routemap_const
[mirror_frr.git] / lib / plist.c
1 /* Prefix list functions.
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
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2, or (at your
9 * option) any 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 */
20
21 #include <zebra.h>
22
23 #include "prefix.h"
24 #include "command.h"
25 #include "memory.h"
26 #include "plist.h"
27 #include "sockunion.h"
28 #include "buffer.h"
29 #include "log.h"
30 #include "routemap.h"
31 #include "lib/json.h"
32 #include "libfrr.h"
33
34 #include "plist_int.h"
35
36 DEFINE_MTYPE_STATIC(LIB, PREFIX_LIST, "Prefix List")
37 DEFINE_MTYPE_STATIC(LIB, MPREFIX_LIST_STR, "Prefix List Str")
38 DEFINE_MTYPE_STATIC(LIB, PREFIX_LIST_ENTRY, "Prefix List Entry")
39 DEFINE_MTYPE_STATIC(LIB, PREFIX_LIST_TRIE, "Prefix List Trie Table")
40
41 /* not currently changeable, code assumes bytes further down */
42 #define PLC_BITS 8
43 #define PLC_LEN (1 << PLC_BITS)
44 #define PLC_MAXLEVELV4 2 /* /24 for IPv4 */
45 #define PLC_MAXLEVELV6 4 /* /48 for IPv6 */
46 #define PLC_MAXLEVEL 4 /* max(v4,v6) */
47
48 struct pltrie_entry {
49 union {
50 struct pltrie_table *next_table;
51 struct prefix_list_entry *final_chain;
52 };
53
54 struct prefix_list_entry *up_chain;
55 };
56
57 struct pltrie_table {
58 struct pltrie_entry entries[PLC_LEN];
59 };
60
61 /* List of struct prefix_list. */
62 struct prefix_list_list {
63 struct prefix_list *head;
64 struct prefix_list *tail;
65 };
66
67 /* Master structure of prefix_list. */
68 struct prefix_master {
69 /* List of prefix_list which name is number. */
70 struct prefix_list_list num;
71
72 /* List of prefix_list which name is string. */
73 struct prefix_list_list str;
74
75 /* Whether sequential number is used. */
76 bool seqnum;
77
78 /* The latest update. */
79 struct prefix_list *recent;
80
81 /* Hook function which is executed when new prefix_list is added. */
82 void (*add_hook)(struct prefix_list *);
83
84 /* Hook function which is executed when prefix_list is deleted. */
85 void (*delete_hook)(struct prefix_list *);
86
87 /* number of bytes that have a trie level */
88 size_t trie_depth;
89 };
90
91 /* Static structure of IPv4 prefix_list's master. */
92 static struct prefix_master prefix_master_ipv4 = {
93 {NULL, NULL}, {NULL, NULL}, 1, NULL, NULL, NULL, PLC_MAXLEVELV4,
94 };
95
96 /* Static structure of IPv6 prefix-list's master. */
97 static struct prefix_master prefix_master_ipv6 = {
98 {NULL, NULL}, {NULL, NULL}, 1, NULL, NULL, NULL, PLC_MAXLEVELV6,
99 };
100
101 /* Static structure of BGP ORF prefix_list's master. */
102 static struct prefix_master prefix_master_orf_v4 = {
103 {NULL, NULL}, {NULL, NULL}, 1, NULL, NULL, NULL, PLC_MAXLEVELV4,
104 };
105
106 /* Static structure of BGP ORF prefix_list's master. */
107 static struct prefix_master prefix_master_orf_v6 = {
108 {NULL, NULL}, {NULL, NULL}, 1, NULL, NULL, NULL, PLC_MAXLEVELV6,
109 };
110
111 static struct prefix_master *prefix_master_get(afi_t afi, int orf)
112 {
113 if (afi == AFI_IP)
114 return orf ? &prefix_master_orf_v4 : &prefix_master_ipv4;
115 if (afi == AFI_IP6)
116 return orf ? &prefix_master_orf_v6 : &prefix_master_ipv6;
117 return NULL;
118 }
119
120 const char *prefix_list_name(struct prefix_list *plist)
121 {
122 return plist->name;
123 }
124
125 afi_t prefix_list_afi(struct prefix_list *plist)
126 {
127 if (plist->master == &prefix_master_ipv4
128 || plist->master == &prefix_master_orf_v4)
129 return AFI_IP;
130 return AFI_IP6;
131 }
132
133 /* Lookup prefix_list from list of prefix_list by name. */
134 static struct prefix_list *prefix_list_lookup_do(afi_t afi, int orf,
135 const char *name)
136 {
137 struct prefix_list *plist;
138 struct prefix_master *master;
139
140 if (name == NULL)
141 return NULL;
142
143 master = prefix_master_get(afi, orf);
144 if (master == NULL)
145 return NULL;
146
147 for (plist = master->num.head; plist; plist = plist->next)
148 if (strcmp(plist->name, name) == 0)
149 return plist;
150
151 for (plist = master->str.head; plist; plist = plist->next)
152 if (strcmp(plist->name, name) == 0)
153 return plist;
154
155 return NULL;
156 }
157
158 struct prefix_list *prefix_list_lookup(afi_t afi, const char *name)
159 {
160 return prefix_list_lookup_do(afi, 0, name);
161 }
162
163 struct prefix_list *prefix_bgp_orf_lookup(afi_t afi, const char *name)
164 {
165 return prefix_list_lookup_do(afi, 1, name);
166 }
167
168 static struct prefix_list *prefix_list_new(void)
169 {
170 struct prefix_list *new;
171
172 new = XCALLOC(MTYPE_PREFIX_LIST, sizeof(struct prefix_list));
173 return new;
174 }
175
176 static void prefix_list_free(struct prefix_list *plist)
177 {
178 XFREE(MTYPE_PREFIX_LIST, plist);
179 }
180
181 static struct prefix_list_entry *prefix_list_entry_new(void)
182 {
183 struct prefix_list_entry *new;
184
185 new = XCALLOC(MTYPE_PREFIX_LIST_ENTRY,
186 sizeof(struct prefix_list_entry));
187 return new;
188 }
189
190 static void prefix_list_entry_free(struct prefix_list_entry *pentry)
191 {
192 XFREE(MTYPE_PREFIX_LIST_ENTRY, pentry);
193 }
194
195 /* Insert new prefix list to list of prefix_list. Each prefix_list
196 is sorted by the name. */
197 static struct prefix_list *prefix_list_insert(afi_t afi, int orf,
198 const char *name)
199 {
200 unsigned int i;
201 long number;
202 struct prefix_list *plist;
203 struct prefix_list *point;
204 struct prefix_list_list *list;
205 struct prefix_master *master;
206
207 master = prefix_master_get(afi, orf);
208 if (master == NULL)
209 return NULL;
210
211 /* Allocate new prefix_list and copy given name. */
212 plist = prefix_list_new();
213 plist->name = XSTRDUP(MTYPE_MPREFIX_LIST_STR, name);
214 plist->master = master;
215 plist->trie =
216 XCALLOC(MTYPE_PREFIX_LIST_TRIE, sizeof(struct pltrie_table));
217
218 /* If name is made by all digit character. We treat it as
219 number. */
220 for (number = 0, i = 0; i < strlen(name); i++) {
221 if (isdigit((int)name[i]))
222 number = (number * 10) + (name[i] - '0');
223 else
224 break;
225 }
226
227 /* In case of name is all digit character */
228 if (i == strlen(name)) {
229 plist->type = PREFIX_TYPE_NUMBER;
230
231 /* Set prefix_list to number list. */
232 list = &master->num;
233
234 for (point = list->head; point; point = point->next)
235 if (atol(point->name) >= number)
236 break;
237 } else {
238 plist->type = PREFIX_TYPE_STRING;
239
240 /* Set prefix_list to string list. */
241 list = &master->str;
242
243 /* Set point to insertion point. */
244 for (point = list->head; point; point = point->next)
245 if (strcmp(point->name, name) >= 0)
246 break;
247 }
248
249 /* In case of this is the first element of master. */
250 if (list->head == NULL) {
251 list->head = list->tail = plist;
252 return plist;
253 }
254
255 /* In case of insertion is made at the tail of access_list. */
256 if (point == NULL) {
257 plist->prev = list->tail;
258 list->tail->next = plist;
259 list->tail = plist;
260 return plist;
261 }
262
263 /* In case of insertion is made at the head of access_list. */
264 if (point == list->head) {
265 plist->next = list->head;
266 list->head->prev = plist;
267 list->head = plist;
268 return plist;
269 }
270
271 /* Insertion is made at middle of the access_list. */
272 plist->next = point;
273 plist->prev = point->prev;
274
275 if (point->prev)
276 point->prev->next = plist;
277 point->prev = plist;
278
279 return plist;
280 }
281
282 static struct prefix_list *prefix_list_get(afi_t afi, int orf, const char *name)
283 {
284 struct prefix_list *plist;
285
286 plist = prefix_list_lookup_do(afi, orf, name);
287
288 if (plist == NULL)
289 plist = prefix_list_insert(afi, orf, name);
290 return plist;
291 }
292
293 static void prefix_list_trie_del(struct prefix_list *plist,
294 struct prefix_list_entry *pentry);
295
296 /* Delete prefix-list from prefix_list_master and free it. */
297 static void prefix_list_delete(struct prefix_list *plist)
298 {
299 struct prefix_list_list *list;
300 struct prefix_master *master;
301 struct prefix_list_entry *pentry;
302 struct prefix_list_entry *next;
303
304 /* If prefix-list contain prefix_list_entry free all of it. */
305 for (pentry = plist->head; pentry; pentry = next) {
306 next = pentry->next;
307 prefix_list_trie_del(plist, pentry);
308 prefix_list_entry_free(pentry);
309 plist->count--;
310 }
311
312 master = plist->master;
313
314 if (plist->type == PREFIX_TYPE_NUMBER)
315 list = &master->num;
316 else
317 list = &master->str;
318
319 if (plist->next)
320 plist->next->prev = plist->prev;
321 else
322 list->tail = plist->prev;
323
324 if (plist->prev)
325 plist->prev->next = plist->next;
326 else
327 list->head = plist->next;
328
329 if (plist->desc)
330 XFREE(MTYPE_TMP, plist->desc);
331
332 /* Make sure master's recent changed prefix-list information is
333 cleared. */
334 master->recent = NULL;
335
336 route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_DELETED);
337
338 if (master->delete_hook)
339 (*master->delete_hook)(plist);
340
341 if (plist->name)
342 XFREE(MTYPE_MPREFIX_LIST_STR, plist->name);
343
344 XFREE(MTYPE_PREFIX_LIST_TRIE, plist->trie);
345
346 prefix_list_free(plist);
347 }
348
349 static struct prefix_list_entry *
350 prefix_list_entry_make(struct prefix *prefix, enum prefix_list_type type,
351 int64_t seq, int le, int ge, int any)
352 {
353 struct prefix_list_entry *pentry;
354
355 pentry = prefix_list_entry_new();
356
357 if (any)
358 pentry->any = 1;
359
360 prefix_copy(&pentry->prefix, prefix);
361 pentry->type = type;
362 pentry->seq = seq;
363 pentry->le = le;
364 pentry->ge = ge;
365
366 return pentry;
367 }
368
369 /* Add hook function. */
370 void prefix_list_add_hook(void (*func)(struct prefix_list *plist))
371 {
372 prefix_master_ipv4.add_hook = func;
373 prefix_master_ipv6.add_hook = func;
374 }
375
376 /* Delete hook function. */
377 void prefix_list_delete_hook(void (*func)(struct prefix_list *plist))
378 {
379 prefix_master_ipv4.delete_hook = func;
380 prefix_master_ipv6.delete_hook = func;
381 }
382
383 /* Calculate new sequential number. */
384 static int64_t prefix_new_seq_get(struct prefix_list *plist)
385 {
386 int64_t maxseq;
387 int64_t newseq;
388 struct prefix_list_entry *pentry;
389
390 maxseq = newseq = 0;
391
392 for (pentry = plist->head; pentry; pentry = pentry->next) {
393 if (maxseq < pentry->seq)
394 maxseq = pentry->seq;
395 }
396
397 newseq = ((maxseq / 5) * 5) + 5;
398
399 return newseq;
400 }
401
402 /* Return prefix list entry which has same seq number. */
403 static struct prefix_list_entry *prefix_seq_check(struct prefix_list *plist,
404 int64_t seq)
405 {
406 struct prefix_list_entry *pentry;
407
408 for (pentry = plist->head; pentry; pentry = pentry->next)
409 if (pentry->seq == seq)
410 return pentry;
411 return NULL;
412 }
413
414 static struct prefix_list_entry *
415 prefix_list_entry_lookup(struct prefix_list *plist, struct prefix *prefix,
416 enum prefix_list_type type, int64_t seq,
417 int le, int ge)
418 {
419 struct prefix_list_entry *pentry;
420
421 for (pentry = plist->head; pentry; pentry = pentry->next)
422 if (prefix_same(&pentry->prefix, prefix)
423 && pentry->type == type) {
424 if (seq >= 0 && pentry->seq != seq)
425 continue;
426
427 if (pentry->le != le)
428 continue;
429 if (pentry->ge != ge)
430 continue;
431
432 return pentry;
433 }
434
435 return NULL;
436 }
437
438 static void trie_walk_affected(size_t validbits, struct pltrie_table *table,
439 uint8_t byte, struct prefix_list_entry *object,
440 void (*fn)(struct prefix_list_entry *object,
441 struct prefix_list_entry **updptr))
442 {
443 uint8_t mask;
444 uint16_t bwalk;
445
446 if (validbits > PLC_BITS) {
447 fn(object, &table->entries[byte].final_chain);
448 return;
449 }
450
451 mask = (1 << (8 - validbits)) - 1;
452 for (bwalk = byte & ~mask; bwalk <= byte + mask; bwalk++) {
453 fn(object, &table->entries[bwalk].up_chain);
454 }
455 }
456
457 static void trie_uninstall_fn(struct prefix_list_entry *object,
458 struct prefix_list_entry **updptr)
459 {
460 for (; *updptr; updptr = &(*updptr)->next_best)
461 if (*updptr == object) {
462 *updptr = object->next_best;
463 break;
464 }
465 }
466
467 static int trie_table_empty(struct pltrie_table *table)
468 {
469 size_t i;
470 for (i = 0; i < PLC_LEN; i++)
471 if (table->entries[i].next_table || table->entries[i].up_chain)
472 return 0;
473 return 1;
474 }
475
476 static void prefix_list_trie_del(struct prefix_list *plist,
477 struct prefix_list_entry *pentry)
478 {
479 size_t depth, maxdepth = plist->master->trie_depth;
480 uint8_t *bytes = pentry->prefix.u.val;
481 size_t validbits = pentry->prefix.prefixlen;
482 struct pltrie_table *table, **tables[PLC_MAXLEVEL];
483
484 table = plist->trie;
485 for (depth = 0; validbits > PLC_BITS && depth < maxdepth - 1; depth++) {
486 uint8_t byte = bytes[depth];
487 assert(table->entries[byte].next_table);
488
489 tables[depth + 1] = &table->entries[byte].next_table;
490 table = table->entries[byte].next_table;
491
492 validbits -= PLC_BITS;
493 }
494
495 trie_walk_affected(validbits, table, bytes[depth], pentry,
496 trie_uninstall_fn);
497
498 for (; depth > 0; depth--)
499 if (trie_table_empty(*tables[depth])) {
500 XFREE(MTYPE_PREFIX_LIST_TRIE, *tables[depth]);
501 *tables[depth] = NULL;
502 }
503 }
504
505
506 static void prefix_list_entry_delete(struct prefix_list *plist,
507 struct prefix_list_entry *pentry,
508 int update_list)
509 {
510 if (plist == NULL || pentry == NULL)
511 return;
512
513 prefix_list_trie_del(plist, pentry);
514
515 if (pentry->prev)
516 pentry->prev->next = pentry->next;
517 else
518 plist->head = pentry->next;
519 if (pentry->next)
520 pentry->next->prev = pentry->prev;
521 else
522 plist->tail = pentry->prev;
523
524 prefix_list_entry_free(pentry);
525
526 plist->count--;
527
528 if (update_list) {
529 route_map_notify_dependencies(plist->name,
530 RMAP_EVENT_PLIST_DELETED);
531 if (plist->master->delete_hook)
532 (*plist->master->delete_hook)(plist);
533
534 if (plist->head == NULL && plist->tail == NULL
535 && plist->desc == NULL)
536 prefix_list_delete(plist);
537 else
538 plist->master->recent = plist;
539 }
540 }
541
542 static void trie_install_fn(struct prefix_list_entry *object,
543 struct prefix_list_entry **updptr)
544 {
545 while (*updptr) {
546 if (*updptr == object)
547 return;
548 if ((*updptr)->prefix.prefixlen < object->prefix.prefixlen)
549 break;
550 if ((*updptr)->prefix.prefixlen == object->prefix.prefixlen
551 && (*updptr)->seq > object->seq)
552 break;
553 updptr = &(*updptr)->next_best;
554 }
555
556 if (!object->next_best)
557 object->next_best = *updptr;
558 else
559 assert(object->next_best == *updptr || !*updptr);
560
561 *updptr = object;
562 }
563
564 static void prefix_list_trie_add(struct prefix_list *plist,
565 struct prefix_list_entry *pentry)
566 {
567 size_t depth = plist->master->trie_depth;
568 uint8_t *bytes = pentry->prefix.u.val;
569 size_t validbits = pentry->prefix.prefixlen;
570 struct pltrie_table *table;
571
572 table = plist->trie;
573 while (validbits > PLC_BITS && depth > 1) {
574 if (!table->entries[*bytes].next_table)
575 table->entries[*bytes].next_table =
576 XCALLOC(MTYPE_PREFIX_LIST_TRIE,
577 sizeof(struct pltrie_table));
578 table = table->entries[*bytes].next_table;
579 bytes++;
580 depth--;
581 validbits -= PLC_BITS;
582 }
583
584 trie_walk_affected(validbits, table, *bytes, pentry, trie_install_fn);
585 }
586
587 static void prefix_list_entry_add(struct prefix_list *plist,
588 struct prefix_list_entry *pentry)
589 {
590 struct prefix_list_entry *replace;
591 struct prefix_list_entry *point;
592
593 /* Automatic asignment of seq no. */
594 if (pentry->seq == -1)
595 pentry->seq = prefix_new_seq_get(plist);
596
597 if (plist->tail && pentry->seq > plist->tail->seq)
598 point = NULL;
599 else {
600 /* Is there any same seq prefix list entry? */
601 replace = prefix_seq_check(plist, pentry->seq);
602 if (replace)
603 prefix_list_entry_delete(plist, replace, 0);
604
605 /* Check insert point. */
606 for (point = plist->head; point; point = point->next)
607 if (point->seq >= pentry->seq)
608 break;
609 }
610
611 /* In case of this is the first element of the list. */
612 pentry->next = point;
613
614 if (point) {
615 if (point->prev)
616 point->prev->next = pentry;
617 else
618 plist->head = pentry;
619
620 pentry->prev = point->prev;
621 point->prev = pentry;
622 } else {
623 if (plist->tail)
624 plist->tail->next = pentry;
625 else
626 plist->head = pentry;
627
628 pentry->prev = plist->tail;
629 plist->tail = pentry;
630 }
631
632 prefix_list_trie_add(plist, pentry);
633
634 /* Increment count. */
635 plist->count++;
636
637 /* Run hook function. */
638 if (plist->master->add_hook)
639 (*plist->master->add_hook)(plist);
640
641 route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_ADDED);
642 plist->master->recent = plist;
643 }
644
645 /* Return string of prefix_list_type. */
646 static const char *prefix_list_type_str(struct prefix_list_entry *pentry)
647 {
648 switch (pentry->type) {
649 case PREFIX_PERMIT:
650 return "permit";
651 case PREFIX_DENY:
652 return "deny";
653 default:
654 return "";
655 }
656 }
657
658 static int prefix_list_entry_match(struct prefix_list_entry *pentry,
659 const struct prefix *p)
660 {
661 int ret;
662
663 if (pentry->prefix.family != p->family)
664 return 0;
665
666 ret = prefix_match(&pentry->prefix, p);
667 if (!ret)
668 return 0;
669
670 /* In case of le nor ge is specified, exact match is performed. */
671 if (!pentry->le && !pentry->ge) {
672 if (pentry->prefix.prefixlen != p->prefixlen)
673 return 0;
674 } else {
675 if (pentry->le)
676 if (p->prefixlen > pentry->le)
677 return 0;
678
679 if (pentry->ge)
680 if (p->prefixlen < pentry->ge)
681 return 0;
682 }
683 return 1;
684 }
685
686 enum prefix_list_type prefix_list_apply_which_prefix(
687 struct prefix_list *plist,
688 const struct prefix **which,
689 const void *object)
690 {
691 struct prefix_list_entry *pentry, *pbest = NULL;
692
693 const struct prefix *p = (const struct prefix *)object;
694 const uint8_t *byte = p->u.val;
695 size_t depth;
696 size_t validbits = p->prefixlen;
697 struct pltrie_table *table;
698
699 if (plist == NULL) {
700 if (which)
701 *which = NULL;
702 return PREFIX_DENY;
703 }
704
705 if (plist->count == 0) {
706 if (which)
707 *which = NULL;
708 return PREFIX_PERMIT;
709 }
710
711 depth = plist->master->trie_depth;
712 table = plist->trie;
713 while (1) {
714 for (pentry = table->entries[*byte].up_chain; pentry;
715 pentry = pentry->next_best) {
716 if (pbest && pbest->seq < pentry->seq)
717 continue;
718 if (prefix_list_entry_match(pentry, p))
719 pbest = pentry;
720 }
721
722 if (validbits <= PLC_BITS)
723 break;
724 validbits -= PLC_BITS;
725
726 if (--depth) {
727 if (!table->entries[*byte].next_table)
728 break;
729
730 table = table->entries[*byte].next_table;
731 byte++;
732 continue;
733 }
734
735 for (pentry = table->entries[*byte].final_chain; pentry;
736 pentry = pentry->next_best) {
737 if (pbest && pbest->seq < pentry->seq)
738 continue;
739 if (prefix_list_entry_match(pentry, p))
740 pbest = pentry;
741 }
742 break;
743 }
744
745 if (which) {
746 if (pbest)
747 *which = &pbest->prefix;
748 else
749 *which = NULL;
750 }
751
752 if (pbest == NULL)
753 return PREFIX_DENY;
754
755 return pbest->type;
756 }
757
758 static void __attribute__((unused)) prefix_list_print(struct prefix_list *plist)
759 {
760 struct prefix_list_entry *pentry;
761
762 if (plist == NULL)
763 return;
764
765 printf("ip prefix-list %s: %d entries\n", plist->name, plist->count);
766
767 for (pentry = plist->head; pentry; pentry = pentry->next) {
768 if (pentry->any)
769 printf("any %s\n", prefix_list_type_str(pentry));
770 else {
771 struct prefix *p;
772 char buf[BUFSIZ];
773
774 p = &pentry->prefix;
775
776 printf(" seq %" PRId64 " %s %s/%d", pentry->seq,
777 prefix_list_type_str(pentry),
778 inet_ntop(p->family, p->u.val, buf, BUFSIZ),
779 p->prefixlen);
780 if (pentry->ge)
781 printf(" ge %d", pentry->ge);
782 if (pentry->le)
783 printf(" le %d", pentry->le);
784 printf("\n");
785 }
786 }
787 }
788
789 /* Retrun 1 when plist already include pentry policy. */
790 static struct prefix_list_entry *
791 prefix_entry_dup_check(struct prefix_list *plist, struct prefix_list_entry *new)
792 {
793 size_t depth, maxdepth = plist->master->trie_depth;
794 uint8_t byte, *bytes = new->prefix.u.val;
795 size_t validbits = new->prefix.prefixlen;
796 struct pltrie_table *table;
797 struct prefix_list_entry *pentry;
798 int64_t seq = 0;
799
800 if (new->seq == -1)
801 seq = prefix_new_seq_get(plist);
802 else
803 seq = new->seq;
804
805 table = plist->trie;
806 for (depth = 0; validbits > PLC_BITS && depth < maxdepth - 1; depth++) {
807 byte = bytes[depth];
808 if (!table->entries[byte].next_table)
809 return NULL;
810
811 table = table->entries[byte].next_table;
812 validbits -= PLC_BITS;
813 }
814
815 byte = bytes[depth];
816 if (validbits > PLC_BITS)
817 pentry = table->entries[byte].final_chain;
818 else
819 pentry = table->entries[byte].up_chain;
820
821 for (; pentry; pentry = pentry->next_best) {
822 if (prefix_same(&pentry->prefix, &new->prefix)
823 && pentry->type == new->type && pentry->le == new->le
824 && pentry->ge == new->ge && pentry->seq != seq)
825 return pentry;
826 }
827 return NULL;
828 }
829
830 static int vty_invalid_prefix_range(struct vty *vty, const char *prefix)
831 {
832 vty_out(vty,
833 "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value\n",
834 prefix);
835 return CMD_WARNING_CONFIG_FAILED;
836 }
837
838 static int vty_prefix_list_install(struct vty *vty, afi_t afi, const char *name,
839 const char *seq, const char *typestr,
840 const char *prefix, const char *ge,
841 const char *le)
842 {
843 int ret;
844 enum prefix_list_type type;
845 struct prefix_list *plist;
846 struct prefix_list_entry *pentry;
847 struct prefix_list_entry *dup;
848 struct prefix p, p_tmp;
849 int any = 0;
850 int64_t seqnum = -1;
851 int lenum = 0;
852 int genum = 0;
853
854 if (name == NULL || prefix == NULL || typestr == NULL) {
855 vty_out(vty, "%% Missing prefix or type\n");
856 return CMD_WARNING_CONFIG_FAILED;
857 }
858
859 /* Sequential number. */
860 if (seq)
861 seqnum = (int64_t)atol(seq);
862
863 /* ge and le number */
864 if (ge)
865 genum = atoi(ge);
866 if (le)
867 lenum = atoi(le);
868
869 /* Check filter type. */
870 if (strncmp("permit", typestr, 1) == 0)
871 type = PREFIX_PERMIT;
872 else if (strncmp("deny", typestr, 1) == 0)
873 type = PREFIX_DENY;
874 else {
875 vty_out(vty, "%% prefix type must be permit or deny\n");
876 return CMD_WARNING_CONFIG_FAILED;
877 }
878
879 /* "any" is special token for matching any IPv4 addresses. */
880 switch (afi) {
881 case AFI_IP:
882 if (strncmp("any", prefix, strlen(prefix)) == 0) {
883 ret = str2prefix_ipv4("0.0.0.0/0",
884 (struct prefix_ipv4 *)&p);
885 genum = 0;
886 lenum = IPV4_MAX_BITLEN;
887 any = 1;
888 } else
889 ret = str2prefix_ipv4(prefix, (struct prefix_ipv4 *)&p);
890
891 if (ret <= 0) {
892 vty_out(vty, "%% Malformed IPv4 prefix\n");
893 return CMD_WARNING_CONFIG_FAILED;
894 }
895
896 /* make a copy to verify prefix matches mask length */
897 prefix_copy(&p_tmp, &p);
898 apply_mask_ipv4((struct prefix_ipv4 *)&p_tmp);
899
900 break;
901 case AFI_IP6:
902 if (strncmp("any", prefix, strlen(prefix)) == 0) {
903 ret = str2prefix_ipv6("::/0", (struct prefix_ipv6 *)&p);
904 genum = 0;
905 lenum = IPV6_MAX_BITLEN;
906 any = 1;
907 } else
908 ret = str2prefix_ipv6(prefix, (struct prefix_ipv6 *)&p);
909
910 if (ret <= 0) {
911 vty_out(vty, "%% Malformed IPv6 prefix\n");
912 return CMD_WARNING_CONFIG_FAILED;
913 }
914
915 /* make a copy to verify prefix matches mask length */
916 prefix_copy(&p_tmp, &p);
917 apply_mask_ipv6((struct prefix_ipv6 *)&p_tmp);
918
919 break;
920 case AFI_L2VPN:
921 default:
922 vty_out(vty, "%% Unrecognized AFI (%d)\n", afi);
923 return CMD_WARNING_CONFIG_FAILED;
924 break;
925 }
926
927 /* If prefix has bits not under the mask, adjust it to fit */
928 if (!prefix_same(&p_tmp, &p)) {
929 char buf[PREFIX2STR_BUFFER];
930 char buf_tmp[PREFIX2STR_BUFFER];
931 prefix2str(&p, buf, sizeof(buf));
932 prefix2str(&p_tmp, buf_tmp, sizeof(buf_tmp));
933 zlog_warn(
934 "Prefix-list %s prefix changed from %s to %s to match length",
935 name, buf, buf_tmp);
936 p = p_tmp;
937 }
938
939 /* ge and le check. */
940 if (genum && (genum <= p.prefixlen))
941 return vty_invalid_prefix_range(vty, prefix);
942
943 if (lenum && (lenum < p.prefixlen))
944 return vty_invalid_prefix_range(vty, prefix);
945
946 if (lenum && (genum > lenum))
947 return vty_invalid_prefix_range(vty, prefix);
948
949 if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
950 lenum = 0;
951
952 /* Get prefix_list with name. */
953 plist = prefix_list_get(afi, 0, name);
954
955 /* Make prefix entry. */
956 pentry = prefix_list_entry_make(&p, type, seqnum, lenum, genum, any);
957
958 /* Check same policy. */
959 dup = prefix_entry_dup_check(plist, pentry);
960
961 if (dup) {
962 prefix_list_entry_free(pentry);
963 return CMD_SUCCESS;
964 }
965
966 /* Install new filter to the access_list. */
967 prefix_list_entry_add(plist, pentry);
968
969 return CMD_SUCCESS;
970 }
971
972 static int vty_prefix_list_uninstall(struct vty *vty, afi_t afi,
973 const char *name, const char *seq,
974 const char *typestr, const char *prefix,
975 const char *ge, const char *le)
976 {
977 int ret;
978 enum prefix_list_type type;
979 struct prefix_list *plist;
980 struct prefix_list_entry *pentry;
981 struct prefix p;
982 int64_t seqnum = -1;
983 int lenum = 0;
984 int genum = 0;
985
986 /* Check prefix list name. */
987 plist = prefix_list_lookup(afi, name);
988 if (!plist) {
989 vty_out(vty, "%% Can't find specified prefix-list\n");
990 return CMD_WARNING_CONFIG_FAILED;
991 }
992
993 /* Only prefix-list name specified, delete the entire prefix-list. */
994 if (seq == NULL && typestr == NULL && prefix == NULL && ge == NULL
995 && le == NULL) {
996 prefix_list_delete(plist);
997 return CMD_SUCCESS;
998 }
999
1000 /* We must have, at a minimum, both the type and prefix here */
1001 if ((typestr == NULL) || (prefix == NULL)) {
1002 vty_out(vty, "%% Both prefix and type required\n");
1003 return CMD_WARNING_CONFIG_FAILED;
1004 }
1005
1006 /* Check sequence number. */
1007 if (seq)
1008 seqnum = (int64_t)atol(seq);
1009
1010 /* ge and le number */
1011 if (ge)
1012 genum = atoi(ge);
1013 if (le)
1014 lenum = atoi(le);
1015
1016 /* Check of filter type. */
1017 if (strncmp("permit", typestr, 1) == 0)
1018 type = PREFIX_PERMIT;
1019 else if (strncmp("deny", typestr, 1) == 0)
1020 type = PREFIX_DENY;
1021 else {
1022 vty_out(vty, "%% prefix type must be permit or deny\n");
1023 return CMD_WARNING_CONFIG_FAILED;
1024 }
1025
1026 /* "any" is special token for matching any IPv4 addresses. */
1027 if (afi == AFI_IP) {
1028 if (strncmp("any", prefix, strlen(prefix)) == 0) {
1029 ret = str2prefix_ipv4("0.0.0.0/0",
1030 (struct prefix_ipv4 *)&p);
1031 genum = 0;
1032 lenum = IPV4_MAX_BITLEN;
1033 } else
1034 ret = str2prefix_ipv4(prefix, (struct prefix_ipv4 *)&p);
1035
1036 if (ret <= 0) {
1037 vty_out(vty, "%% Malformed IPv4 prefix\n");
1038 return CMD_WARNING_CONFIG_FAILED;
1039 }
1040 } else if (afi == AFI_IP6) {
1041 if (strncmp("any", prefix, strlen(prefix)) == 0) {
1042 ret = str2prefix_ipv6("::/0", (struct prefix_ipv6 *)&p);
1043 genum = 0;
1044 lenum = IPV6_MAX_BITLEN;
1045 } else
1046 ret = str2prefix_ipv6(prefix, (struct prefix_ipv6 *)&p);
1047
1048 if (ret <= 0) {
1049 vty_out(vty, "%% Malformed IPv6 prefix\n");
1050 return CMD_WARNING_CONFIG_FAILED;
1051 }
1052 }
1053
1054 /* Lookup prefix entry. */
1055 pentry =
1056 prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
1057
1058 if (pentry == NULL) {
1059 vty_out(vty, "%% Can't find specified prefix-list\n");
1060 return CMD_WARNING_CONFIG_FAILED;
1061 }
1062
1063 /* Install new filter to the access_list. */
1064 prefix_list_entry_delete(plist, pentry, 1);
1065
1066 return CMD_SUCCESS;
1067 }
1068
1069 static int vty_prefix_list_desc_unset(struct vty *vty, afi_t afi,
1070 const char *name)
1071 {
1072 struct prefix_list *plist;
1073
1074 plist = prefix_list_lookup(afi, name);
1075 if (!plist) {
1076 vty_out(vty, "%% Can't find specified prefix-list\n");
1077 return CMD_WARNING_CONFIG_FAILED;
1078 }
1079
1080 if (plist->desc) {
1081 XFREE(MTYPE_TMP, plist->desc);
1082 plist->desc = NULL;
1083 }
1084
1085 if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
1086 prefix_list_delete(plist);
1087
1088 return CMD_SUCCESS;
1089 }
1090
1091 enum display_type {
1092 normal_display,
1093 summary_display,
1094 detail_display,
1095 sequential_display,
1096 longer_display,
1097 first_match_display
1098 };
1099
1100 static void vty_show_prefix_entry(struct vty *vty, afi_t afi,
1101 struct prefix_list *plist,
1102 struct prefix_master *master,
1103 enum display_type dtype, int seqnum)
1104 {
1105 struct prefix_list_entry *pentry;
1106
1107 /* Print the name of the protocol */
1108 vty_out(vty, "%s: ", frr_protoname);
1109
1110 if (dtype == normal_display) {
1111 vty_out(vty, "ip%s prefix-list %s: %d entries\n",
1112 afi == AFI_IP ? "" : "v6", plist->name, plist->count);
1113 if (plist->desc)
1114 vty_out(vty, " Description: %s\n", plist->desc);
1115 } else if (dtype == summary_display || dtype == detail_display) {
1116 vty_out(vty, "ip%s prefix-list %s:\n",
1117 afi == AFI_IP ? "" : "v6", plist->name);
1118
1119 if (plist->desc)
1120 vty_out(vty, " Description: %s\n", plist->desc);
1121
1122 vty_out(vty,
1123 " count: %d, range entries: %d, sequences: %" PRId64 " - %" PRId64 "\n",
1124 plist->count, plist->rangecount,
1125 plist->head ? plist->head->seq : 0,
1126 plist->tail ? plist->tail->seq : 0);
1127 }
1128
1129 if (dtype != summary_display) {
1130 for (pentry = plist->head; pentry; pentry = pentry->next) {
1131 if (dtype == sequential_display
1132 && pentry->seq != seqnum)
1133 continue;
1134
1135 vty_out(vty, " ");
1136
1137 if (master->seqnum)
1138 vty_out(vty, "seq %" PRId64 " ", pentry->seq);
1139
1140 vty_out(vty, "%s ", prefix_list_type_str(pentry));
1141
1142 if (pentry->any)
1143 vty_out(vty, "any");
1144 else {
1145 struct prefix *p = &pentry->prefix;
1146 char buf[BUFSIZ];
1147
1148 vty_out(vty, "%s/%d",
1149 inet_ntop(p->family, p->u.val, buf,
1150 BUFSIZ),
1151 p->prefixlen);
1152
1153 if (pentry->ge)
1154 vty_out(vty, " ge %d", pentry->ge);
1155 if (pentry->le)
1156 vty_out(vty, " le %d", pentry->le);
1157 }
1158
1159 if (dtype == detail_display
1160 || dtype == sequential_display)
1161 vty_out(vty, " (hit count: %ld, refcount: %ld)",
1162 pentry->hitcnt, pentry->refcnt);
1163
1164 vty_out(vty, "\n");
1165 }
1166 }
1167 }
1168
1169 static int vty_show_prefix_list(struct vty *vty, afi_t afi, const char *name,
1170 const char *seq, enum display_type dtype)
1171 {
1172 struct prefix_list *plist;
1173 struct prefix_master *master;
1174 int64_t seqnum = 0;
1175
1176 master = prefix_master_get(afi, 0);
1177 if (master == NULL)
1178 return CMD_WARNING;
1179
1180 if (seq)
1181 seqnum = (int64_t)atol(seq);
1182
1183 if (name) {
1184 plist = prefix_list_lookup(afi, name);
1185 if (!plist) {
1186 vty_out(vty, "%% Can't find specified prefix-list\n");
1187 return CMD_WARNING;
1188 }
1189 vty_show_prefix_entry(vty, afi, plist, master, dtype, seqnum);
1190 } else {
1191 if (dtype == detail_display || dtype == summary_display) {
1192 if (master->recent)
1193 vty_out(vty,
1194 "Prefix-list with the last deletion/insertion: %s\n",
1195 master->recent->name);
1196 }
1197
1198 for (plist = master->num.head; plist; plist = plist->next)
1199 vty_show_prefix_entry(vty, afi, plist, master, dtype,
1200 seqnum);
1201
1202 for (plist = master->str.head; plist; plist = plist->next)
1203 vty_show_prefix_entry(vty, afi, plist, master, dtype,
1204 seqnum);
1205 }
1206
1207 return CMD_SUCCESS;
1208 }
1209
1210 static int vty_show_prefix_list_prefix(struct vty *vty, afi_t afi,
1211 const char *name, const char *prefix,
1212 enum display_type type)
1213 {
1214 struct prefix_list *plist;
1215 struct prefix_list_entry *pentry;
1216 struct prefix p;
1217 int ret;
1218 int match;
1219
1220 plist = prefix_list_lookup(afi, name);
1221 if (!plist) {
1222 vty_out(vty, "%% Can't find specified prefix-list\n");
1223 return CMD_WARNING;
1224 }
1225
1226 ret = str2prefix(prefix, &p);
1227 if (ret <= 0) {
1228 vty_out(vty, "%% prefix is malformed\n");
1229 return CMD_WARNING;
1230 }
1231
1232 for (pentry = plist->head; pentry; pentry = pentry->next) {
1233 match = 0;
1234
1235 if (type == normal_display || type == first_match_display)
1236 if (prefix_same(&p, &pentry->prefix))
1237 match = 1;
1238
1239 if (type == longer_display) {
1240 if ((p.family == pentry->prefix.family)
1241 && (prefix_match(&p, &pentry->prefix)))
1242 match = 1;
1243 }
1244
1245 if (match) {
1246 vty_out(vty, " seq %" PRId64 " %s ", pentry->seq,
1247 prefix_list_type_str(pentry));
1248
1249 if (pentry->any)
1250 vty_out(vty, "any");
1251 else {
1252 struct prefix *p = &pentry->prefix;
1253 char buf[BUFSIZ];
1254
1255 vty_out(vty, "%s/%d",
1256 inet_ntop(p->family, p->u.val, buf,
1257 BUFSIZ),
1258 p->prefixlen);
1259
1260 if (pentry->ge)
1261 vty_out(vty, " ge %d", pentry->ge);
1262 if (pentry->le)
1263 vty_out(vty, " le %d", pentry->le);
1264 }
1265
1266 if (type == normal_display
1267 || type == first_match_display)
1268 vty_out(vty, " (hit count: %ld, refcount: %ld)",
1269 pentry->hitcnt, pentry->refcnt);
1270
1271 vty_out(vty, "\n");
1272
1273 if (type == first_match_display)
1274 return CMD_SUCCESS;
1275 }
1276 }
1277 return CMD_SUCCESS;
1278 }
1279
1280 static int vty_clear_prefix_list(struct vty *vty, afi_t afi, const char *name,
1281 const char *prefix)
1282 {
1283 struct prefix_master *master;
1284 struct prefix_list *plist;
1285 struct prefix_list_entry *pentry;
1286 int ret;
1287 struct prefix p;
1288
1289 master = prefix_master_get(afi, 0);
1290 if (master == NULL)
1291 return CMD_WARNING;
1292
1293 if (name == NULL && prefix == NULL) {
1294 for (plist = master->num.head; plist; plist = plist->next)
1295 for (pentry = plist->head; pentry;
1296 pentry = pentry->next)
1297 pentry->hitcnt = 0;
1298
1299 for (plist = master->str.head; plist; plist = plist->next)
1300 for (pentry = plist->head; pentry;
1301 pentry = pentry->next)
1302 pentry->hitcnt = 0;
1303 } else {
1304 plist = prefix_list_lookup(afi, name);
1305 if (!plist) {
1306 vty_out(vty, "%% Can't find specified prefix-list\n");
1307 return CMD_WARNING;
1308 }
1309
1310 if (prefix) {
1311 ret = str2prefix(prefix, &p);
1312 if (ret <= 0) {
1313 vty_out(vty, "%% prefix is malformed\n");
1314 return CMD_WARNING;
1315 }
1316 }
1317
1318 for (pentry = plist->head; pentry; pentry = pentry->next) {
1319 if (prefix) {
1320 if (pentry->prefix.family == p.family
1321 && prefix_match(&pentry->prefix, &p))
1322 pentry->hitcnt = 0;
1323 } else
1324 pentry->hitcnt = 0;
1325 }
1326 }
1327 return CMD_SUCCESS;
1328 }
1329
1330 #ifndef VTYSH_EXTRACT_PL
1331 #include "lib/plist_clippy.c"
1332 #endif
1333
1334 DEFPY (ip_prefix_list,
1335 ip_prefix_list_cmd,
1336 "ip prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|A.B.C.D/M$dest [{ge (0-32)|le (0-32)}]>",
1337 IP_STR
1338 PREFIX_LIST_STR
1339 "Name of a prefix list\n"
1340 "sequence number of an entry\n"
1341 "Sequence number\n"
1342 "Specify packets to reject\n"
1343 "Specify packets to forward\n"
1344 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n"
1345 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1346 "Minimum prefix length to be matched\n"
1347 "Minimum prefix length\n"
1348 "Maximum prefix length to be matched\n"
1349 "Maximum prefix length\n")
1350 {
1351 return vty_prefix_list_install(vty, AFI_IP, prefix_list, seq_str,
1352 action, dest, ge_str, le_str);
1353 }
1354
1355 DEFPY (no_ip_prefix_list,
1356 no_ip_prefix_list_cmd,
1357 "no ip prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|A.B.C.D/M$dest [{ge (0-32)|le (0-32)}]>",
1358 NO_STR
1359 IP_STR
1360 PREFIX_LIST_STR
1361 "Name of a prefix list\n"
1362 "sequence number of an entry\n"
1363 "Sequence number\n"
1364 "Specify packets to reject\n"
1365 "Specify packets to forward\n"
1366 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n"
1367 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1368 "Minimum prefix length to be matched\n"
1369 "Minimum prefix length\n"
1370 "Maximum prefix length to be matched\n"
1371 "Maximum prefix length\n")
1372 {
1373 return vty_prefix_list_uninstall(vty, AFI_IP, prefix_list, seq_str,
1374 action, dest, ge_str, le_str);
1375 }
1376
1377 DEFPY (no_ip_prefix_list_all,
1378 no_ip_prefix_list_all_cmd,
1379 "no ip prefix-list WORD",
1380 NO_STR
1381 IP_STR
1382 PREFIX_LIST_STR
1383 "Name of a prefix list\n")
1384 {
1385 return vty_prefix_list_uninstall(vty, AFI_IP, prefix_list, NULL, NULL,
1386 NULL, NULL, NULL);
1387 }
1388
1389 DEFPY (ip_prefix_list_sequence_number,
1390 ip_prefix_list_sequence_number_cmd,
1391 "[no] ip prefix-list sequence-number",
1392 NO_STR
1393 IP_STR
1394 PREFIX_LIST_STR
1395 "Include/exclude sequence numbers in NVGEN\n")
1396 {
1397 prefix_master_ipv4.seqnum = no ? false : true;
1398 return CMD_SUCCESS;
1399 }
1400
1401 DEFUN (ip_prefix_list_description,
1402 ip_prefix_list_description_cmd,
1403 "ip prefix-list WORD description LINE...",
1404 IP_STR
1405 PREFIX_LIST_STR
1406 "Name of a prefix list\n"
1407 "Prefix-list specific description\n"
1408 "Up to 80 characters describing this prefix-list\n")
1409 {
1410 int idx_word = 2;
1411 int idx_line = 4;
1412 struct prefix_list *plist;
1413
1414 plist = prefix_list_get(AFI_IP, 0, argv[idx_word]->arg);
1415
1416 if (plist->desc) {
1417 XFREE(MTYPE_TMP, plist->desc);
1418 plist->desc = NULL;
1419 }
1420 plist->desc = argv_concat(argv, argc, idx_line);
1421
1422 return CMD_SUCCESS;
1423 }
1424
1425 DEFUN (no_ip_prefix_list_description,
1426 no_ip_prefix_list_description_cmd,
1427 "no ip prefix-list WORD description",
1428 NO_STR
1429 IP_STR
1430 PREFIX_LIST_STR
1431 "Name of a prefix list\n"
1432 "Prefix-list specific description\n")
1433 {
1434 int idx_word = 3;
1435 return vty_prefix_list_desc_unset(vty, AFI_IP, argv[idx_word]->arg);
1436 }
1437
1438 /* ALIAS_FIXME */
1439 DEFUN (no_ip_prefix_list_description_comment,
1440 no_ip_prefix_list_description_comment_cmd,
1441 "no ip prefix-list WORD description LINE...",
1442 NO_STR
1443 IP_STR
1444 PREFIX_LIST_STR
1445 "Name of a prefix list\n"
1446 "Prefix-list specific description\n"
1447 "Up to 80 characters describing this prefix-list\n")
1448 {
1449 return no_ip_prefix_list_description(self, vty, argc, argv);
1450 }
1451
1452 DEFPY (show_ip_prefix_list,
1453 show_ip_prefix_list_cmd,
1454 "show ip prefix-list [WORD [seq$dseq (1-4294967295)$arg]]",
1455 SHOW_STR
1456 IP_STR
1457 PREFIX_LIST_STR
1458 "Name of a prefix list\n"
1459 "sequence number of an entry\n"
1460 "Sequence number\n")
1461 {
1462 enum display_type dtype = normal_display;
1463 if (dseq)
1464 dtype = sequential_display;
1465
1466 return vty_show_prefix_list(vty, AFI_IP, prefix_list, arg_str, dtype);
1467 }
1468
1469 DEFPY (show_ip_prefix_list_prefix,
1470 show_ip_prefix_list_prefix_cmd,
1471 "show ip prefix-list WORD A.B.C.D/M$prefix [longer$dl|first-match$dfm]",
1472 SHOW_STR
1473 IP_STR
1474 PREFIX_LIST_STR
1475 "Name of a prefix list\n"
1476 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1477 "Lookup longer prefix\n"
1478 "First matched prefix\n")
1479 {
1480 enum display_type dtype = normal_display;
1481 if (dl)
1482 dtype = longer_display;
1483 else if (dfm)
1484 dtype = first_match_display;
1485
1486 return vty_show_prefix_list_prefix(vty, AFI_IP, prefix_list, prefix_str,
1487 dtype);
1488 }
1489
1490 DEFPY (show_ip_prefix_list_summary,
1491 show_ip_prefix_list_summary_cmd,
1492 "show ip prefix-list summary [WORD$prefix_list]",
1493 SHOW_STR
1494 IP_STR
1495 PREFIX_LIST_STR
1496 "Summary of prefix lists\n"
1497 "Name of a prefix list\n")
1498 {
1499 return vty_show_prefix_list(vty, AFI_IP, prefix_list, NULL,
1500 summary_display);
1501 }
1502
1503 DEFPY (show_ip_prefix_list_detail,
1504 show_ip_prefix_list_detail_cmd,
1505 "show ip prefix-list detail [WORD$prefix_list]",
1506 SHOW_STR
1507 IP_STR
1508 PREFIX_LIST_STR
1509 "Detail of prefix lists\n"
1510 "Name of a prefix list\n")
1511 {
1512 return vty_show_prefix_list(vty, AFI_IP, prefix_list, NULL,
1513 detail_display);
1514 }
1515
1516 DEFPY (clear_ip_prefix_list,
1517 clear_ip_prefix_list_cmd,
1518 "clear ip prefix-list [WORD [A.B.C.D/M$prefix]]",
1519 CLEAR_STR
1520 IP_STR
1521 PREFIX_LIST_STR
1522 "Name of a prefix list\n"
1523 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1524 {
1525 return vty_clear_prefix_list(vty, AFI_IP, prefix_list, prefix_str);
1526 }
1527
1528 DEFPY (ipv6_prefix_list,
1529 ipv6_prefix_list_cmd,
1530 "ipv6 prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|X:X::X:X/M$dest [{ge (0-128)|le (0-128)}]>",
1531 IPV6_STR
1532 PREFIX_LIST_STR
1533 "Name of a prefix list\n"
1534 "sequence number of an entry\n"
1535 "Sequence number\n"
1536 "Specify packets to reject\n"
1537 "Specify packets to forward\n"
1538 "Any prefix match. Same as \"::0/0 le 128\"\n"
1539 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1540 "Maximum prefix length to be matched\n"
1541 "Maximum prefix length\n"
1542 "Minimum prefix length to be matched\n"
1543 "Minimum prefix length\n")
1544 {
1545 return vty_prefix_list_install(vty, AFI_IP6, prefix_list, seq_str,
1546 action, dest, ge_str, le_str);
1547 }
1548
1549 DEFPY (no_ipv6_prefix_list,
1550 no_ipv6_prefix_list_cmd,
1551 "no ipv6 prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|X:X::X:X/M$dest [{ge (0-128)|le (0-128)}]>",
1552 NO_STR
1553 IPV6_STR
1554 PREFIX_LIST_STR
1555 "Name of a prefix list\n"
1556 "sequence number of an entry\n"
1557 "Sequence number\n"
1558 "Specify packets to reject\n"
1559 "Specify packets to forward\n"
1560 "Any prefix match. Same as \"::0/0 le 128\"\n"
1561 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1562 "Maximum prefix length to be matched\n"
1563 "Maximum prefix length\n"
1564 "Minimum prefix length to be matched\n"
1565 "Minimum prefix length\n")
1566 {
1567 return vty_prefix_list_uninstall(vty, AFI_IP6, prefix_list, seq_str,
1568 action, dest, ge_str, le_str);
1569 }
1570
1571 DEFPY (no_ipv6_prefix_list_all,
1572 no_ipv6_prefix_list_all_cmd,
1573 "no ipv6 prefix-list WORD",
1574 NO_STR
1575 IPV6_STR
1576 PREFIX_LIST_STR
1577 "Name of a prefix list\n")
1578 {
1579 return vty_prefix_list_uninstall(vty, AFI_IP6, prefix_list, NULL, NULL,
1580 NULL, NULL, NULL);
1581 }
1582
1583 DEFPY (ipv6_prefix_list_sequence_number,
1584 ipv6_prefix_list_sequence_number_cmd,
1585 "[no] ipv6 prefix-list sequence-number",
1586 NO_STR
1587 IPV6_STR
1588 PREFIX_LIST_STR
1589 "Include/exclude sequence numbers in NVGEN\n")
1590 {
1591 prefix_master_ipv6.seqnum = no ? false : true;
1592 return CMD_SUCCESS;
1593 }
1594
1595 DEFUN (ipv6_prefix_list_description,
1596 ipv6_prefix_list_description_cmd,
1597 "ipv6 prefix-list WORD description LINE...",
1598 IPV6_STR
1599 PREFIX_LIST_STR
1600 "Name of a prefix list\n"
1601 "Prefix-list specific description\n"
1602 "Up to 80 characters describing this prefix-list\n")
1603 {
1604 int idx_word = 2;
1605 int iddx_line = 4;
1606 struct prefix_list *plist;
1607
1608 plist = prefix_list_get(AFI_IP6, 0, argv[idx_word]->arg);
1609
1610 if (plist->desc) {
1611 XFREE(MTYPE_TMP, plist->desc);
1612 plist->desc = NULL;
1613 }
1614 plist->desc = argv_concat(argv, argc, iddx_line);
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 DEFUN (no_ipv6_prefix_list_description,
1620 no_ipv6_prefix_list_description_cmd,
1621 "no ipv6 prefix-list WORD description",
1622 NO_STR
1623 IPV6_STR
1624 PREFIX_LIST_STR
1625 "Name of a prefix list\n"
1626 "Prefix-list specific description\n")
1627 {
1628 int idx_word = 3;
1629 return vty_prefix_list_desc_unset(vty, AFI_IP6, argv[idx_word]->arg);
1630 }
1631
1632 /* ALIAS_FIXME */
1633 DEFUN (no_ipv6_prefix_list_description_comment,
1634 no_ipv6_prefix_list_description_comment_cmd,
1635 "no ipv6 prefix-list WORD description LINE...",
1636 NO_STR
1637 IPV6_STR
1638 PREFIX_LIST_STR
1639 "Name of a prefix list\n"
1640 "Prefix-list specific description\n"
1641 "Up to 80 characters describing this prefix-list\n")
1642 {
1643 return no_ipv6_prefix_list_description(self, vty, argc, argv);
1644 }
1645
1646
1647 DEFPY (show_ipv6_prefix_list,
1648 show_ipv6_prefix_list_cmd,
1649 "show ipv6 prefix-list [WORD [seq$dseq (1-4294967295)$arg]]",
1650 SHOW_STR
1651 IPV6_STR
1652 PREFIX_LIST_STR
1653 "Name of a prefix list\n"
1654 "sequence number of an entry\n"
1655 "Sequence number\n")
1656 {
1657 enum display_type dtype = normal_display;
1658 if (dseq)
1659 dtype = sequential_display;
1660
1661 return vty_show_prefix_list(vty, AFI_IP6, prefix_list, arg_str, dtype);
1662 }
1663
1664 DEFPY (show_ipv6_prefix_list_prefix,
1665 show_ipv6_prefix_list_prefix_cmd,
1666 "show ipv6 prefix-list WORD X:X::X:X/M$prefix [longer$dl|first-match$dfm]",
1667 SHOW_STR
1668 IPV6_STR
1669 PREFIX_LIST_STR
1670 "Name of a prefix list\n"
1671 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1672 "Lookup longer prefix\n"
1673 "First matched prefix\n")
1674 {
1675 enum display_type dtype = normal_display;
1676 if (dl)
1677 dtype = longer_display;
1678 else if (dfm)
1679 dtype = first_match_display;
1680
1681 return vty_show_prefix_list_prefix(vty, AFI_IP6, prefix_list,
1682 prefix_str, dtype);
1683 }
1684
1685 DEFPY (show_ipv6_prefix_list_summary,
1686 show_ipv6_prefix_list_summary_cmd,
1687 "show ipv6 prefix-list summary [WORD$prefix-list]",
1688 SHOW_STR
1689 IPV6_STR
1690 PREFIX_LIST_STR
1691 "Summary of prefix lists\n"
1692 "Name of a prefix list\n")
1693 {
1694 return vty_show_prefix_list(vty, AFI_IP6, prefix_list, NULL,
1695 summary_display);
1696 }
1697
1698 DEFPY (show_ipv6_prefix_list_detail,
1699 show_ipv6_prefix_list_detail_cmd,
1700 "show ipv6 prefix-list detail [WORD$prefix-list]",
1701 SHOW_STR
1702 IPV6_STR
1703 PREFIX_LIST_STR
1704 "Detail of prefix lists\n"
1705 "Name of a prefix list\n")
1706 {
1707 return vty_show_prefix_list(vty, AFI_IP6, prefix_list, NULL,
1708 detail_display);
1709 }
1710
1711 DEFPY (clear_ipv6_prefix_list,
1712 clear_ipv6_prefix_list_cmd,
1713 "clear ipv6 prefix-list [WORD [X:X::X:X/M$prefix]]",
1714 CLEAR_STR
1715 IPV6_STR
1716 PREFIX_LIST_STR
1717 "Name of a prefix list\n"
1718 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
1719 {
1720 return vty_clear_prefix_list(vty, AFI_IP6, prefix_list, prefix_str);
1721 }
1722
1723 /* Configuration write function. */
1724 static int config_write_prefix_afi(afi_t afi, struct vty *vty)
1725 {
1726 struct prefix_list *plist;
1727 struct prefix_list_entry *pentry;
1728 struct prefix_master *master;
1729 int write = 0;
1730
1731 master = prefix_master_get(afi, 0);
1732 if (master == NULL)
1733 return 0;
1734
1735 if (!master->seqnum) {
1736 vty_out(vty, "no ip%s prefix-list sequence-number\n",
1737 afi == AFI_IP ? "" : "v6");
1738 vty_out(vty, "!\n");
1739 }
1740
1741 for (plist = master->num.head; plist; plist = plist->next) {
1742 if (plist->desc) {
1743 vty_out(vty, "ip%s prefix-list %s description %s\n",
1744 afi == AFI_IP ? "" : "v6", plist->name,
1745 plist->desc);
1746 write++;
1747 }
1748
1749 for (pentry = plist->head; pentry; pentry = pentry->next) {
1750 vty_out(vty, "ip%s prefix-list %s ",
1751 afi == AFI_IP ? "" : "v6", plist->name);
1752
1753 if (master->seqnum)
1754 vty_out(vty, "seq %" PRId64 " ", pentry->seq);
1755
1756 vty_out(vty, "%s ", prefix_list_type_str(pentry));
1757
1758 if (pentry->any)
1759 vty_out(vty, "any");
1760 else {
1761 struct prefix *p = &pentry->prefix;
1762 char buf[BUFSIZ];
1763
1764 vty_out(vty, "%s/%d",
1765 inet_ntop(p->family, p->u.val, buf,
1766 BUFSIZ),
1767 p->prefixlen);
1768
1769 if (pentry->ge)
1770 vty_out(vty, " ge %d", pentry->ge);
1771 if (pentry->le)
1772 vty_out(vty, " le %d", pentry->le);
1773 }
1774 vty_out(vty, "\n");
1775 write++;
1776 }
1777 /* vty_out (vty, "!\n"); */
1778 }
1779
1780 for (plist = master->str.head; plist; plist = plist->next) {
1781 if (plist->desc) {
1782 vty_out(vty, "ip%s prefix-list %s description %s\n",
1783 afi == AFI_IP ? "" : "v6", plist->name,
1784 plist->desc);
1785 write++;
1786 }
1787
1788 for (pentry = plist->head; pentry; pentry = pentry->next) {
1789 vty_out(vty, "ip%s prefix-list %s ",
1790 afi == AFI_IP ? "" : "v6", plist->name);
1791
1792 if (master->seqnum)
1793 vty_out(vty, "seq %" PRId64 " ", pentry->seq);
1794
1795 vty_out(vty, "%s", prefix_list_type_str(pentry));
1796
1797 if (pentry->any)
1798 vty_out(vty, " any");
1799 else {
1800 struct prefix *p = &pentry->prefix;
1801 char buf[BUFSIZ];
1802
1803 vty_out(vty, " %s/%d",
1804 inet_ntop(p->family, p->u.val, buf,
1805 BUFSIZ),
1806 p->prefixlen);
1807
1808 if (pentry->ge)
1809 vty_out(vty, " ge %d", pentry->ge);
1810 if (pentry->le)
1811 vty_out(vty, " le %d", pentry->le);
1812 }
1813 vty_out(vty, "\n");
1814 write++;
1815 }
1816 }
1817
1818 return write;
1819 }
1820
1821 struct stream *prefix_bgp_orf_entry(struct stream *s, struct prefix_list *plist,
1822 uint8_t init_flag, uint8_t permit_flag,
1823 uint8_t deny_flag)
1824 {
1825 struct prefix_list_entry *pentry;
1826
1827 if (!plist)
1828 return s;
1829
1830 for (pentry = plist->head; pentry; pentry = pentry->next) {
1831 uint8_t flag = init_flag;
1832 struct prefix *p = &pentry->prefix;
1833
1834 flag |= (pentry->type == PREFIX_PERMIT ? permit_flag
1835 : deny_flag);
1836 stream_putc(s, flag);
1837 stream_putl(s, (uint32_t)pentry->seq);
1838 stream_putc(s, (uint8_t)pentry->ge);
1839 stream_putc(s, (uint8_t)pentry->le);
1840 stream_put_prefix(s, p);
1841 }
1842
1843 return s;
1844 }
1845
1846 int prefix_bgp_orf_set(char *name, afi_t afi, struct orf_prefix *orfp,
1847 int permit, int set)
1848 {
1849 struct prefix_list *plist;
1850 struct prefix_list_entry *pentry;
1851
1852 /* ge and le value check */
1853 if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
1854 return CMD_WARNING_CONFIG_FAILED;
1855 if (orfp->le && orfp->le <= orfp->p.prefixlen)
1856 return CMD_WARNING_CONFIG_FAILED;
1857 if (orfp->le && orfp->ge > orfp->le)
1858 return CMD_WARNING_CONFIG_FAILED;
1859
1860 if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
1861 orfp->le = 0;
1862
1863 plist = prefix_list_get(afi, 1, name);
1864 if (!plist)
1865 return CMD_WARNING_CONFIG_FAILED;
1866
1867 if (set) {
1868 pentry = prefix_list_entry_make(
1869 &orfp->p, (permit ? PREFIX_PERMIT : PREFIX_DENY),
1870 orfp->seq, orfp->le, orfp->ge, 0);
1871
1872 if (prefix_entry_dup_check(plist, pentry)) {
1873 prefix_list_entry_free(pentry);
1874 return CMD_WARNING_CONFIG_FAILED;
1875 }
1876
1877 prefix_list_entry_add(plist, pentry);
1878 } else {
1879 pentry = prefix_list_entry_lookup(
1880 plist, &orfp->p, (permit ? PREFIX_PERMIT : PREFIX_DENY),
1881 orfp->seq, orfp->le, orfp->ge);
1882
1883 if (!pentry)
1884 return CMD_WARNING_CONFIG_FAILED;
1885
1886 prefix_list_entry_delete(plist, pentry, 1);
1887 }
1888
1889 return CMD_SUCCESS;
1890 }
1891
1892 void prefix_bgp_orf_remove_all(afi_t afi, char *name)
1893 {
1894 struct prefix_list *plist;
1895
1896 plist = prefix_bgp_orf_lookup(afi, name);
1897 if (plist)
1898 prefix_list_delete(plist);
1899 }
1900
1901 /* return prefix count */
1902 int prefix_bgp_show_prefix_list(struct vty *vty, afi_t afi, char *name,
1903 uint8_t use_json)
1904 {
1905 struct prefix_list *plist;
1906 struct prefix_list_entry *pentry;
1907 json_object *json = NULL;
1908 json_object *json_prefix = NULL;
1909 json_object *json_list = NULL;
1910
1911 plist = prefix_bgp_orf_lookup(afi, name);
1912 if (!plist)
1913 return 0;
1914
1915 if (!vty)
1916 return plist->count;
1917
1918 if (use_json) {
1919 json = json_object_new_object();
1920 json_prefix = json_object_new_object();
1921 json_list = json_object_new_object();
1922
1923 json_object_int_add(json_prefix, "prefixListCounter",
1924 plist->count);
1925 json_object_string_add(json_prefix, "prefixListName",
1926 plist->name);
1927
1928 for (pentry = plist->head; pentry; pentry = pentry->next) {
1929 struct prefix *p = &pentry->prefix;
1930 char buf_a[BUFSIZ];
1931 char buf_b[BUFSIZ];
1932
1933 sprintf(buf_a, "%s/%d",
1934 inet_ntop(p->family, p->u.val, buf_b,
1935 BUFSIZ),
1936 p->prefixlen);
1937
1938 json_object_int_add(json_list, "seq", pentry->seq);
1939 json_object_string_add(json_list, "seqPrefixListType",
1940 prefix_list_type_str(pentry));
1941
1942 if (pentry->ge)
1943 json_object_int_add(json_list, "ge",
1944 pentry->ge);
1945 if (pentry->le)
1946 json_object_int_add(json_list, "le",
1947 pentry->le);
1948
1949 json_object_object_add(json_prefix, buf_a, json_list);
1950 }
1951 if (afi == AFI_IP)
1952 json_object_object_add(json, "ipPrefixList",
1953 json_prefix);
1954 else
1955 json_object_object_add(json, "ipv6PrefixList",
1956 json_prefix);
1957
1958 vty_out(vty, "%s\n", json_object_to_json_string_ext(
1959 json, JSON_C_TO_STRING_PRETTY));
1960 json_object_free(json);
1961 } else {
1962 vty_out(vty, "ip%s prefix-list %s: %d entries\n",
1963 afi == AFI_IP ? "" : "v6", plist->name, plist->count);
1964
1965 for (pentry = plist->head; pentry; pentry = pentry->next) {
1966 struct prefix *p = &pentry->prefix;
1967 char buf[BUFSIZ];
1968
1969 vty_out(vty, " seq %" PRId64 " %s %s/%d",
1970 pentry->seq,
1971 prefix_list_type_str(pentry),
1972 inet_ntop(p->family, p->u.val, buf, BUFSIZ),
1973 p->prefixlen);
1974
1975 if (pentry->ge)
1976 vty_out(vty, " ge %d", pentry->ge);
1977 if (pentry->le)
1978 vty_out(vty, " le %d", pentry->le);
1979
1980 vty_out(vty, "\n");
1981 }
1982 }
1983 return plist->count;
1984 }
1985
1986 static void prefix_list_reset_afi(afi_t afi, int orf)
1987 {
1988 struct prefix_list *plist;
1989 struct prefix_list *next;
1990 struct prefix_master *master;
1991
1992 master = prefix_master_get(afi, orf);
1993 if (master == NULL)
1994 return;
1995
1996 for (plist = master->num.head; plist; plist = next) {
1997 next = plist->next;
1998 prefix_list_delete(plist);
1999 }
2000 for (plist = master->str.head; plist; plist = next) {
2001 next = plist->next;
2002 prefix_list_delete(plist);
2003 }
2004
2005 assert(master->num.head == NULL);
2006 assert(master->num.tail == NULL);
2007
2008 assert(master->str.head == NULL);
2009 assert(master->str.tail == NULL);
2010
2011 master->seqnum = 1;
2012 master->recent = NULL;
2013 }
2014
2015
2016 /* Prefix-list node. */
2017 static struct cmd_node prefix_node = {PREFIX_NODE,
2018 "", /* Prefix list has no interface. */
2019 1};
2020
2021 static int config_write_prefix_ipv4(struct vty *vty)
2022 {
2023 return config_write_prefix_afi(AFI_IP, vty);
2024 }
2025
2026 static void plist_autocomplete_afi(afi_t afi, vector comps,
2027 struct cmd_token *token)
2028 {
2029 struct prefix_list *plist;
2030 struct prefix_master *master;
2031
2032 master = prefix_master_get(afi, 0);
2033 if (master == NULL)
2034 return;
2035
2036 for (plist = master->str.head; plist; plist = plist->next)
2037 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, plist->name));
2038 for (plist = master->num.head; plist; plist = plist->next)
2039 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, plist->name));
2040 }
2041
2042 static void plist_autocomplete(vector comps, struct cmd_token *token)
2043 {
2044 plist_autocomplete_afi(AFI_IP, comps, token);
2045 plist_autocomplete_afi(AFI_IP6, comps, token);
2046 }
2047
2048 static const struct cmd_variable_handler plist_var_handlers[] = {
2049 {/* "prefix-list WORD" */
2050 .varname = "prefix_list",
2051 .completions = plist_autocomplete},
2052 {.completions = NULL}};
2053
2054
2055 static void prefix_list_init_ipv4(void)
2056 {
2057 install_node(&prefix_node, config_write_prefix_ipv4);
2058
2059 install_element(CONFIG_NODE, &ip_prefix_list_cmd);
2060 install_element(CONFIG_NODE, &no_ip_prefix_list_cmd);
2061 install_element(CONFIG_NODE, &no_ip_prefix_list_all_cmd);
2062
2063 install_element(CONFIG_NODE, &ip_prefix_list_description_cmd);
2064 install_element(CONFIG_NODE, &no_ip_prefix_list_description_cmd);
2065 install_element(CONFIG_NODE,
2066 &no_ip_prefix_list_description_comment_cmd);
2067
2068 install_element(CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
2069
2070 install_element(VIEW_NODE, &show_ip_prefix_list_cmd);
2071 install_element(VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
2072 install_element(VIEW_NODE, &show_ip_prefix_list_summary_cmd);
2073 install_element(VIEW_NODE, &show_ip_prefix_list_detail_cmd);
2074
2075 install_element(ENABLE_NODE, &clear_ip_prefix_list_cmd);
2076 }
2077
2078 /* Prefix-list node. */
2079 static struct cmd_node prefix_ipv6_node = {
2080 PREFIX_IPV6_NODE, "", /* Prefix list has no interface. */
2081 1};
2082
2083 static int config_write_prefix_ipv6(struct vty *vty)
2084 {
2085 return config_write_prefix_afi(AFI_IP6, vty);
2086 }
2087
2088 static void prefix_list_init_ipv6(void)
2089 {
2090 install_node(&prefix_ipv6_node, config_write_prefix_ipv6);
2091
2092 install_element(CONFIG_NODE, &ipv6_prefix_list_cmd);
2093 install_element(CONFIG_NODE, &no_ipv6_prefix_list_cmd);
2094 install_element(CONFIG_NODE, &no_ipv6_prefix_list_all_cmd);
2095
2096 install_element(CONFIG_NODE, &ipv6_prefix_list_description_cmd);
2097 install_element(CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
2098 install_element(CONFIG_NODE,
2099 &no_ipv6_prefix_list_description_comment_cmd);
2100
2101 install_element(CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
2102
2103 install_element(VIEW_NODE, &show_ipv6_prefix_list_cmd);
2104 install_element(VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
2105 install_element(VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
2106 install_element(VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
2107
2108 install_element(ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
2109 }
2110
2111 void prefix_list_init()
2112 {
2113 cmd_variable_handler_register(plist_var_handlers);
2114
2115 prefix_list_init_ipv4();
2116 prefix_list_init_ipv6();
2117 }
2118
2119 void prefix_list_reset()
2120 {
2121 prefix_list_reset_afi(AFI_IP, 0);
2122 prefix_list_reset_afi(AFI_IP6, 0);
2123 prefix_list_reset_afi(AFI_IP, 1);
2124 prefix_list_reset_afi(AFI_IP6, 1);
2125 }