]> git.proxmox.com Git - mirror_frr.git/blob - lib/plist.c
pimd: Fix register message checksum
[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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23 #include "lib/json.h"
24
25 #include "prefix.h"
26 #include "command.h"
27 #include "memory.h"
28 #include "plist.h"
29 #include "sockunion.h"
30 #include "buffer.h"
31 #include "stream.h"
32 #include "log.h"
33 #include "routemap.h"
34
35 #include "plist_int.h"
36
37 /* not currently changeable, code assumes bytes further down */
38 #define PLC_BITS 8
39 #define PLC_LEN (1 << PLC_BITS)
40 #define PLC_MAXLEVELV4 2 /* /24 for IPv4 */
41 #define PLC_MAXLEVELV6 4 /* /48 for IPv6 */
42 #define PLC_MAXLEVEL 4 /* max(v4,v6) */
43
44 struct pltrie_entry {
45 union {
46 struct pltrie_table *next_table;
47 struct prefix_list_entry *final_chain;
48 };
49
50 struct prefix_list_entry *up_chain;
51 };
52
53 struct pltrie_table {
54 struct pltrie_entry entries[PLC_LEN];
55 };
56
57 /* List of struct prefix_list. */
58 struct prefix_list_list
59 {
60 struct prefix_list *head;
61 struct prefix_list *tail;
62 };
63
64 /* Master structure of prefix_list. */
65 struct prefix_master
66 {
67 /* List of prefix_list which name is number. */
68 struct prefix_list_list num;
69
70 /* List of prefix_list which name is string. */
71 struct prefix_list_list str;
72
73 /* Whether sequential number is used. */
74 int seqnum;
75
76 /* The latest update. */
77 struct prefix_list *recent;
78
79 /* Hook function which is executed when new prefix_list is added. */
80 void (*add_hook) (struct prefix_list *);
81
82 /* Hook function which is executed when prefix_list is deleted. */
83 void (*delete_hook) (struct prefix_list *);
84
85 /* number of bytes that have a trie level */
86 size_t trie_depth;
87 };
88
89 /* Static structure of IPv4 prefix_list's master. */
90 static struct prefix_master prefix_master_ipv4 =
91 {
92 {NULL, NULL},
93 {NULL, NULL},
94 1,
95 NULL,
96 NULL,
97 NULL,
98 PLC_MAXLEVELV4,
99 };
100
101 #ifdef HAVE_IPV6
102 /* Static structure of IPv6 prefix-list's master. */
103 static struct prefix_master prefix_master_ipv6 =
104 {
105 {NULL, NULL},
106 {NULL, NULL},
107 1,
108 NULL,
109 NULL,
110 NULL,
111 PLC_MAXLEVELV6,
112 };
113 #endif /* HAVE_IPV6*/
114
115 /* Static structure of BGP ORF prefix_list's master. */
116 static struct prefix_master prefix_master_orf_v4 =
117 {
118 {NULL, NULL},
119 {NULL, NULL},
120 1,
121 NULL,
122 NULL,
123 NULL,
124 PLC_MAXLEVELV4,
125 };
126
127 /* Static structure of BGP ORF prefix_list's master. */
128 static struct prefix_master prefix_master_orf_v6 =
129 {
130 {NULL, NULL},
131 {NULL, NULL},
132 1,
133 NULL,
134 NULL,
135 NULL,
136 PLC_MAXLEVELV6,
137 };
138
139 static struct prefix_master *
140 prefix_master_get (afi_t afi, int orf)
141 {
142 if (afi == AFI_IP)
143 return orf ? &prefix_master_orf_v4 : &prefix_master_ipv4;
144 if (afi == AFI_IP6)
145 return orf ? &prefix_master_orf_v6 : &prefix_master_ipv6;
146 return NULL;
147 }
148
149 const char *prefix_list_name (struct prefix_list *plist)
150 {
151 return plist->name;
152 }
153
154 /* Lookup prefix_list from list of prefix_list by name. */
155 static struct prefix_list *
156 prefix_list_lookup_do (afi_t afi, int orf, const char *name)
157 {
158 struct prefix_list *plist;
159 struct prefix_master *master;
160
161 if (name == NULL)
162 return NULL;
163
164 master = prefix_master_get (afi, orf);
165 if (master == NULL)
166 return NULL;
167
168 for (plist = master->num.head; plist; plist = plist->next)
169 if (strcmp (plist->name, name) == 0)
170 return plist;
171
172 for (plist = master->str.head; plist; plist = plist->next)
173 if (strcmp (plist->name, name) == 0)
174 return plist;
175
176 return NULL;
177 }
178
179 struct prefix_list *
180 prefix_list_lookup (afi_t afi, const char *name)
181 {
182 return prefix_list_lookup_do (afi, 0, name);
183 }
184
185 struct prefix_list *
186 prefix_bgp_orf_lookup (afi_t afi, const char *name)
187 {
188 return prefix_list_lookup_do (afi, 1, name);
189 }
190
191 static struct prefix_list *
192 prefix_list_new (void)
193 {
194 struct prefix_list *new;
195
196 new = XCALLOC (MTYPE_PREFIX_LIST, sizeof (struct prefix_list));
197 return new;
198 }
199
200 static void
201 prefix_list_free (struct prefix_list *plist)
202 {
203 XFREE (MTYPE_PREFIX_LIST, plist);
204 }
205
206 static struct prefix_list_entry *
207 prefix_list_entry_new (void)
208 {
209 struct prefix_list_entry *new;
210
211 new = XCALLOC (MTYPE_PREFIX_LIST_ENTRY, sizeof (struct prefix_list_entry));
212 return new;
213 }
214
215 static void
216 prefix_list_entry_free (struct prefix_list_entry *pentry)
217 {
218 XFREE (MTYPE_PREFIX_LIST_ENTRY, pentry);
219 }
220
221 /* Insert new prefix list to list of prefix_list. Each prefix_list
222 is sorted by the name. */
223 static struct prefix_list *
224 prefix_list_insert (afi_t afi, int orf, const char *name)
225 {
226 unsigned int i;
227 long number;
228 struct prefix_list *plist;
229 struct prefix_list *point;
230 struct prefix_list_list *list;
231 struct prefix_master *master;
232
233 master = prefix_master_get (afi, orf);
234 if (master == NULL)
235 return NULL;
236
237 /* Allocate new prefix_list and copy given name. */
238 plist = prefix_list_new ();
239 plist->name = XSTRDUP (MTYPE_PREFIX_LIST_STR, name);
240 plist->master = master;
241 plist->trie = XCALLOC (MTYPE_PREFIX_LIST_TRIE, sizeof (struct pltrie_table));
242
243 /* If name is made by all digit character. We treat it as
244 number. */
245 for (number = 0, i = 0; i < strlen (name); i++)
246 {
247 if (isdigit ((int) name[i]))
248 number = (number * 10) + (name[i] - '0');
249 else
250 break;
251 }
252
253 /* In case of name is all digit character */
254 if (i == strlen (name))
255 {
256 plist->type = PREFIX_TYPE_NUMBER;
257
258 /* Set prefix_list to number list. */
259 list = &master->num;
260
261 for (point = list->head; point; point = point->next)
262 if (atol (point->name) >= number)
263 break;
264 }
265 else
266 {
267 plist->type = PREFIX_TYPE_STRING;
268
269 /* Set prefix_list to string list. */
270 list = &master->str;
271
272 /* Set point to insertion point. */
273 for (point = list->head; point; point = point->next)
274 if (strcmp (point->name, name) >= 0)
275 break;
276 }
277
278 /* In case of this is the first element of master. */
279 if (list->head == NULL)
280 {
281 list->head = list->tail = plist;
282 return plist;
283 }
284
285 /* In case of insertion is made at the tail of access_list. */
286 if (point == NULL)
287 {
288 plist->prev = list->tail;
289 list->tail->next = plist;
290 list->tail = plist;
291 return plist;
292 }
293
294 /* In case of insertion is made at the head of access_list. */
295 if (point == list->head)
296 {
297 plist->next = list->head;
298 list->head->prev = plist;
299 list->head = plist;
300 return plist;
301 }
302
303 /* Insertion is made at middle of the access_list. */
304 plist->next = point;
305 plist->prev = point->prev;
306
307 if (point->prev)
308 point->prev->next = plist;
309 point->prev = plist;
310
311 return plist;
312 }
313
314 static struct prefix_list *
315 prefix_list_get (afi_t afi, int orf, const char *name)
316 {
317 struct prefix_list *plist;
318
319 plist = prefix_list_lookup_do (afi, orf, name);
320
321 if (plist == NULL)
322 plist = prefix_list_insert (afi, orf, name);
323 return plist;
324 }
325
326 /* Delete prefix-list from prefix_list_master and free it. */
327 static void
328 prefix_list_delete (struct prefix_list *plist)
329 {
330 struct prefix_list_list *list;
331 struct prefix_master *master;
332 struct prefix_list_entry *pentry;
333 struct prefix_list_entry *next;
334
335 /* If prefix-list contain prefix_list_entry free all of it. */
336 for (pentry = plist->head; pentry; pentry = next)
337 {
338 next = pentry->next;
339 prefix_list_entry_free (pentry);
340 plist->count--;
341 }
342
343 master = plist->master;
344
345 if (plist->type == PREFIX_TYPE_NUMBER)
346 list = &master->num;
347 else
348 list = &master->str;
349
350 if (plist->next)
351 plist->next->prev = plist->prev;
352 else
353 list->tail = plist->prev;
354
355 if (plist->prev)
356 plist->prev->next = plist->next;
357 else
358 list->head = plist->next;
359
360 if (plist->desc)
361 XFREE (MTYPE_TMP, plist->desc);
362
363 /* Make sure master's recent changed prefix-list information is
364 cleared. */
365 master->recent = NULL;
366
367 route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_DELETED);
368
369 if (master->delete_hook)
370 (*master->delete_hook) (plist);
371
372 if (plist->name)
373 XFREE (MTYPE_PREFIX_LIST_STR, plist->name);
374
375 XFREE (MTYPE_PREFIX_LIST_TRIE, plist->trie);
376
377 prefix_list_free (plist);
378
379 }
380
381 static struct prefix_list_entry *
382 prefix_list_entry_make (struct prefix *prefix, enum prefix_list_type type,
383 int seq, int le, int ge, int any)
384 {
385 struct prefix_list_entry *pentry;
386
387 pentry = prefix_list_entry_new ();
388
389 if (any)
390 pentry->any = 1;
391
392 prefix_copy (&pentry->prefix, prefix);
393 pentry->type = type;
394 pentry->seq = seq;
395 pentry->le = le;
396 pentry->ge = ge;
397
398 return pentry;
399 }
400
401 /* Add hook function. */
402 void
403 prefix_list_add_hook (void (*func) (struct prefix_list *plist))
404 {
405 prefix_master_ipv4.add_hook = func;
406 #ifdef HAVE_IPV6
407 prefix_master_ipv6.add_hook = func;
408 #endif /* HAVE_IPV6 */
409 }
410
411 /* Delete hook function. */
412 void
413 prefix_list_delete_hook (void (*func) (struct prefix_list *plist))
414 {
415 prefix_master_ipv4.delete_hook = func;
416 #ifdef HAVE_IPV6
417 prefix_master_ipv6.delete_hook = func;
418 #endif /* HAVE_IPVt6 */
419 }
420
421 /* Calculate new sequential number. */
422 static int
423 prefix_new_seq_get (struct prefix_list *plist)
424 {
425 int maxseq;
426 int newseq;
427 struct prefix_list_entry *pentry;
428
429 maxseq = newseq = 0;
430
431 for (pentry = plist->head; pentry; pentry = pentry->next)
432 {
433 if (maxseq < pentry->seq)
434 maxseq = pentry->seq;
435 }
436
437 newseq = ((maxseq / 5) * 5) + 5;
438
439 return newseq;
440 }
441
442 /* Return prefix list entry which has same seq number. */
443 static struct prefix_list_entry *
444 prefix_seq_check (struct prefix_list *plist, int seq)
445 {
446 struct prefix_list_entry *pentry;
447
448 for (pentry = plist->head; pentry; pentry = pentry->next)
449 if (pentry->seq == seq)
450 return pentry;
451 return NULL;
452 }
453
454 static struct prefix_list_entry *
455 prefix_list_entry_lookup (struct prefix_list *plist, struct prefix *prefix,
456 enum prefix_list_type type, int seq, int le, int ge)
457 {
458 struct prefix_list_entry *pentry;
459
460 for (pentry = plist->head; pentry; pentry = pentry->next)
461 if (prefix_same (&pentry->prefix, prefix) && pentry->type == type)
462 {
463 if (seq >= 0 && pentry->seq != seq)
464 continue;
465
466 if (pentry->le != le)
467 continue;
468 if (pentry->ge != ge)
469 continue;
470
471 return pentry;
472 }
473
474 return NULL;
475 }
476
477 static void
478 trie_walk_affected (size_t validbits, struct pltrie_table *table, uint8_t byte,
479 struct prefix_list_entry *object,
480 void (*fn)(struct prefix_list_entry *object,
481 struct prefix_list_entry **updptr))
482 {
483 uint8_t mask;
484 uint16_t bwalk;
485
486 if (validbits > PLC_BITS)
487 {
488 fn (object, &table->entries[byte].final_chain);
489 return;
490 }
491
492 mask = (1 << (8 - validbits)) - 1;
493 for (bwalk = byte & ~mask; bwalk <= byte + mask; bwalk++)
494 {
495 fn (object, &table->entries[bwalk].up_chain);
496 }
497 }
498
499 static void trie_uninstall_fn (struct prefix_list_entry *object,
500 struct prefix_list_entry **updptr)
501 {
502 for (; *updptr; updptr = &(*updptr)->next_best)
503 if (*updptr == object)
504 {
505 *updptr = object->next_best;
506 break;
507 }
508 }
509
510 static int
511 trie_table_empty (struct pltrie_table *table)
512 {
513 size_t i;
514 for (i = 0; i < PLC_LEN; i++)
515 if (table->entries[i].next_table || table->entries[i].up_chain)
516 return 0;
517 return 1;
518 }
519
520 static void
521 prefix_list_trie_del (struct prefix_list *plist,
522 struct prefix_list_entry *pentry)
523 {
524 size_t depth, maxdepth = plist->master->trie_depth;
525 uint8_t *bytes = &pentry->prefix.u.prefix;
526 size_t validbits = pentry->prefix.prefixlen;
527 struct pltrie_table *table, **tables[PLC_MAXLEVEL];
528
529 table = plist->trie;
530 for (depth = 0; validbits > PLC_BITS && depth < maxdepth - 1; depth++)
531 {
532 uint8_t byte = bytes[depth];
533 assert (table->entries[byte].next_table);
534
535 tables[depth + 1] = &table->entries[byte].next_table;
536 table = table->entries[byte].next_table;
537
538 validbits -= PLC_BITS;
539 }
540
541 trie_walk_affected (validbits, table, bytes[depth], pentry, trie_uninstall_fn);
542
543 for (; depth > 0; depth--)
544 if (trie_table_empty (*tables[depth]))
545 {
546 XFREE (MTYPE_PREFIX_LIST_TRIE, *tables[depth]);
547 *tables[depth] = NULL;
548 }
549 }
550
551
552 static void
553 prefix_list_entry_delete (struct prefix_list *plist,
554 struct prefix_list_entry *pentry,
555 int update_list)
556 {
557 prefix_list_trie_del (plist, pentry);
558
559 if (plist == NULL || pentry == NULL)
560 return;
561 if (pentry->prev)
562 pentry->prev->next = pentry->next;
563 else
564 plist->head = pentry->next;
565 if (pentry->next)
566 pentry->next->prev = pentry->prev;
567 else
568 plist->tail = pentry->prev;
569
570 prefix_list_entry_free (pentry);
571
572 plist->count--;
573
574 if (update_list)
575 {
576 route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_DELETED);
577 if (plist->master->delete_hook)
578 (*plist->master->delete_hook) (plist);
579
580 if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
581 prefix_list_delete (plist);
582 else
583 plist->master->recent = plist;
584 }
585 }
586
587 static void trie_install_fn (struct prefix_list_entry *object,
588 struct prefix_list_entry **updptr)
589 {
590 while (*updptr)
591 {
592 if (*updptr == object)
593 return;
594 if ((*updptr)->prefix.prefixlen < object->prefix.prefixlen)
595 break;
596 if ((*updptr)->seq > object->seq)
597 break;
598 updptr = &(*updptr)->next_best;
599 }
600
601 if (!object->next_best)
602 object->next_best = *updptr;
603 else
604 assert (object->next_best == *updptr || !*updptr);
605
606 *updptr = object;
607 }
608
609 static void
610 prefix_list_trie_add (struct prefix_list *plist,
611 struct prefix_list_entry *pentry)
612 {
613 size_t depth = plist->master->trie_depth;
614 uint8_t *bytes = &pentry->prefix.u.prefix;
615 size_t validbits = pentry->prefix.prefixlen;
616 struct pltrie_table *table;
617
618 table = plist->trie;
619 while (validbits > PLC_BITS && depth > 1)
620 {
621 if (!table->entries[*bytes].next_table)
622 table->entries[*bytes].next_table = XCALLOC (MTYPE_PREFIX_LIST_TRIE,
623 sizeof(struct pltrie_table));
624 table = table->entries[*bytes].next_table;
625 bytes++;
626 depth--;
627 validbits -= PLC_BITS;
628 }
629
630 trie_walk_affected (validbits, table, *bytes, pentry, trie_install_fn);
631 }
632
633 static void
634 prefix_list_entry_add (struct prefix_list *plist,
635 struct prefix_list_entry *pentry)
636 {
637 struct prefix_list_entry *replace;
638 struct prefix_list_entry *point;
639
640 /* Automatic asignment of seq no. */
641 if (pentry->seq == -1)
642 pentry->seq = prefix_new_seq_get (plist);
643
644 if (plist->tail && pentry->seq > plist->tail->seq)
645 point = NULL;
646 else
647 {
648 /* Is there any same seq prefix list entry? */
649 replace = prefix_seq_check (plist, pentry->seq);
650 if (replace)
651 prefix_list_entry_delete (plist, replace, 0);
652
653 /* Check insert point. */
654 for (point = plist->head; point; point = point->next)
655 if (point->seq >= pentry->seq)
656 break;
657 }
658
659 /* In case of this is the first element of the list. */
660 pentry->next = point;
661
662 if (point)
663 {
664 if (point->prev)
665 point->prev->next = pentry;
666 else
667 plist->head = pentry;
668
669 pentry->prev = point->prev;
670 point->prev = pentry;
671 }
672 else
673 {
674 if (plist->tail)
675 plist->tail->next = pentry;
676 else
677 plist->head = pentry;
678
679 pentry->prev = plist->tail;
680 plist->tail = pentry;
681 }
682
683 prefix_list_trie_add (plist, pentry);
684
685 /* Increment count. */
686 plist->count++;
687
688 /* Run hook function. */
689 if (plist->master->add_hook)
690 (*plist->master->add_hook) (plist);
691
692 route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_ADDED);
693 plist->master->recent = plist;
694 }
695
696 /* Return string of prefix_list_type. */
697 static const char *
698 prefix_list_type_str (struct prefix_list_entry *pentry)
699 {
700 switch (pentry->type)
701 {
702 case PREFIX_PERMIT:
703 return "permit";
704 case PREFIX_DENY:
705 return "deny";
706 default:
707 return "";
708 }
709 }
710
711 static int
712 prefix_list_entry_match (struct prefix_list_entry *pentry, struct prefix *p)
713 {
714 int ret;
715
716 ret = prefix_match (&pentry->prefix, p);
717 if (! ret)
718 return 0;
719
720 /* In case of le nor ge is specified, exact match is performed. */
721 if (! pentry->le && ! pentry->ge)
722 {
723 if (pentry->prefix.prefixlen != p->prefixlen)
724 return 0;
725 }
726 else
727 {
728 if (pentry->le)
729 if (p->prefixlen > pentry->le)
730 return 0;
731
732 if (pentry->ge)
733 if (p->prefixlen < pentry->ge)
734 return 0;
735 }
736 return 1;
737 }
738
739 enum prefix_list_type
740 prefix_list_apply (struct prefix_list *plist, void *object)
741 {
742 struct prefix_list_entry *pentry, *pbest = NULL;
743
744 struct prefix *p = (struct prefix *) object;
745 uint8_t *byte = &p->u.prefix;
746 size_t depth;
747 size_t validbits = p->prefixlen;
748 struct pltrie_table *table;
749
750 if (plist == NULL)
751 return PREFIX_DENY;
752
753 if (plist->count == 0)
754 return PREFIX_PERMIT;
755
756 depth = plist->master->trie_depth;
757 table = plist->trie;
758 while (1)
759 {
760 for (pentry = table->entries[*byte].up_chain; pentry; pentry = pentry->next_best)
761 {
762 if (pbest && pbest->seq < pentry->seq)
763 continue;
764 if (prefix_list_entry_match (pentry, p))
765 pbest = pentry;
766 }
767
768 if (validbits <= PLC_BITS)
769 break;
770 validbits -= PLC_BITS;
771
772 if (--depth)
773 {
774 if (!table->entries[*byte].next_table)
775 break;
776
777 table = table->entries[*byte].next_table;
778 byte++;
779 continue;
780 }
781
782 for (pentry = table->entries[*byte].final_chain; pentry; pentry = pentry->next_best)
783 {
784 if (pbest && pbest->seq < pentry->seq)
785 continue;
786 if (prefix_list_entry_match (pentry, p))
787 pbest = pentry;
788 }
789 break;
790 }
791
792 if (pbest == NULL)
793 return PREFIX_DENY;
794
795 return pbest->type;
796 }
797
798 static void __attribute__ ((unused))
799 prefix_list_print (struct prefix_list *plist)
800 {
801 struct prefix_list_entry *pentry;
802
803 if (plist == NULL)
804 return;
805
806 printf ("ip prefix-list %s: %d entries\n", plist->name, plist->count);
807
808 for (pentry = plist->head; pentry; pentry = pentry->next)
809 {
810 if (pentry->any)
811 printf ("any %s\n", prefix_list_type_str (pentry));
812 else
813 {
814 struct prefix *p;
815 char buf[BUFSIZ];
816
817 p = &pentry->prefix;
818
819 printf (" seq %u %s %s/%d",
820 pentry->seq,
821 prefix_list_type_str (pentry),
822 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
823 p->prefixlen);
824 if (pentry->ge)
825 printf (" ge %d", pentry->ge);
826 if (pentry->le)
827 printf (" le %d", pentry->le);
828 printf ("\n");
829 }
830 }
831 }
832
833 /* Retrun 1 when plist already include pentry policy. */
834 static struct prefix_list_entry *
835 prefix_entry_dup_check (struct prefix_list *plist,
836 struct prefix_list_entry *new)
837 {
838 size_t depth, maxdepth = plist->master->trie_depth;
839 uint8_t byte, *bytes = &new->prefix.u.prefix;
840 size_t validbits = new->prefix.prefixlen;
841 struct pltrie_table *table;
842 struct prefix_list_entry *pentry;
843 int seq = 0;
844
845 if (new->seq == -1)
846 seq = prefix_new_seq_get (plist);
847 else
848 seq = new->seq;
849
850 table = plist->trie;
851 for (depth = 0; validbits > PLC_BITS && depth < maxdepth - 1; depth++)
852 {
853 byte = bytes[depth];
854 if (!table->entries[byte].next_table)
855 return NULL;
856
857 table = table->entries[byte].next_table;
858 validbits -= PLC_BITS;
859 }
860
861 byte = bytes[depth];
862 if (validbits > PLC_BITS)
863 pentry = table->entries[byte].final_chain;
864 else
865 pentry = table->entries[byte].up_chain;
866
867 for (; pentry; pentry = pentry->next_best)
868 {
869 if (prefix_same (&pentry->prefix, &new->prefix)
870 && pentry->type == new->type
871 && pentry->le == new->le
872 && pentry->ge == new->ge
873 && pentry->seq != seq)
874 return pentry;
875 }
876 return NULL;
877 }
878
879 static int
880 vty_invalid_prefix_range (struct vty *vty, const char *prefix)
881 {
882 vty_out (vty, "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value%s",
883 prefix, VTY_NEWLINE);
884 return CMD_WARNING;
885 }
886
887 static int
888 vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
889 const char *seq, const char *typestr,
890 const char *prefix, const char *ge, const char *le)
891 {
892 int ret;
893 enum prefix_list_type type;
894 struct prefix_list *plist;
895 struct prefix_list_entry *pentry;
896 struct prefix_list_entry *dup;
897 struct prefix p;
898 int any = 0;
899 int seqnum = -1;
900 int lenum = 0;
901 int genum = 0;
902
903 /* Sequential number. */
904 if (seq)
905 seqnum = atoi (seq);
906
907 /* ge and le number */
908 if (ge)
909 genum = atoi (ge);
910 if (le)
911 lenum = atoi (le);
912
913 /* Check filter type. */
914 if (strncmp ("permit", typestr, 1) == 0)
915 type = PREFIX_PERMIT;
916 else if (strncmp ("deny", typestr, 1) == 0)
917 type = PREFIX_DENY;
918 else
919 {
920 vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
921 return CMD_WARNING;
922 }
923
924 /* "any" is special token for matching any IPv4 addresses. */
925 switch (afi)
926 {
927 case AFI_IP:
928 if (strncmp ("any", prefix, strlen (prefix)) == 0)
929 {
930 ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
931 genum = 0;
932 lenum = IPV4_MAX_BITLEN;
933 any = 1;
934 }
935 else
936 ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
937
938 if (ret <= 0)
939 {
940 vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
941 return CMD_WARNING;
942 }
943 break;
944 case AFI_IP6:
945 if (strncmp ("any", prefix, strlen (prefix)) == 0)
946 {
947 ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
948 genum = 0;
949 lenum = IPV6_MAX_BITLEN;
950 any = 1;
951 }
952 else
953 ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
954
955 if (ret <= 0)
956 {
957 vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
958 return CMD_WARNING;
959 }
960 break;
961 }
962
963 /* ge and le check. */
964 if (genum && (genum <= p.prefixlen))
965 return vty_invalid_prefix_range (vty, prefix);
966
967 if (lenum && (lenum <= p.prefixlen))
968 return vty_invalid_prefix_range (vty, prefix);
969
970 if (lenum && (genum > lenum))
971 return vty_invalid_prefix_range (vty, prefix);
972
973 if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
974 lenum = 0;
975
976 /* Get prefix_list with name. */
977 plist = prefix_list_get (afi, 0, name);
978
979 /* Make prefix entry. */
980 pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
981
982 /* Check same policy. */
983 dup = prefix_entry_dup_check (plist, pentry);
984
985 if (dup)
986 {
987 prefix_list_entry_free (pentry);
988 vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
989 VTY_NEWLINE);
990 vty_out (vty, " seq %u %s %s", dup->seq, typestr, prefix);
991 if (! any && genum)
992 vty_out (vty, " ge %d", genum);
993 if (! any && lenum)
994 vty_out (vty, " le %d", lenum);
995 vty_out (vty, "%s", VTY_NEWLINE);
996 return CMD_SUCCESS;
997 }
998
999 /* Install new filter to the access_list. */
1000 prefix_list_entry_add (plist, pentry);
1001
1002 return CMD_SUCCESS;
1003 }
1004
1005 static int
1006 vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
1007 const char *seq, const char *typestr,
1008 const char *prefix, const char *ge, const char *le)
1009 {
1010 int ret;
1011 enum prefix_list_type type;
1012 struct prefix_list *plist;
1013 struct prefix_list_entry *pentry;
1014 struct prefix p;
1015 int seqnum = -1;
1016 int lenum = 0;
1017 int genum = 0;
1018
1019 /* Check prefix list name. */
1020 plist = prefix_list_lookup (afi, name);
1021 if (! plist)
1022 {
1023 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1024 return CMD_WARNING;
1025 }
1026
1027 /* Only prefix-list name specified, delete the entire prefix-list. */
1028 if (seq == NULL && typestr == NULL && prefix == NULL &&
1029 ge == NULL && le == NULL)
1030 {
1031 prefix_list_delete (plist);
1032 return CMD_SUCCESS;
1033 }
1034
1035 /* We must have, at a minimum, both the type and prefix here */
1036 if ((typestr == NULL) || (prefix == NULL))
1037 {
1038 vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
1039 return CMD_WARNING;
1040 }
1041
1042 /* Check sequence number. */
1043 if (seq)
1044 seqnum = atoi (seq);
1045
1046 /* ge and le number */
1047 if (ge)
1048 genum = atoi (ge);
1049 if (le)
1050 lenum = atoi (le);
1051
1052 /* Check of filter type. */
1053 if (strncmp ("permit", typestr, 1) == 0)
1054 type = PREFIX_PERMIT;
1055 else if (strncmp ("deny", typestr, 1) == 0)
1056 type = PREFIX_DENY;
1057 else
1058 {
1059 vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
1060 return CMD_WARNING;
1061 }
1062
1063 /* "any" is special token for matching any IPv4 addresses. */
1064 if (afi == AFI_IP)
1065 {
1066 if (strncmp ("any", prefix, strlen (prefix)) == 0)
1067 {
1068 ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
1069 genum = 0;
1070 lenum = IPV4_MAX_BITLEN;
1071 }
1072 else
1073 ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
1074
1075 if (ret <= 0)
1076 {
1077 vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
1078 return CMD_WARNING;
1079 }
1080 }
1081 #ifdef HAVE_IPV6
1082 else if (afi == AFI_IP6)
1083 {
1084 if (strncmp ("any", prefix, strlen (prefix)) == 0)
1085 {
1086 ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
1087 genum = 0;
1088 lenum = IPV6_MAX_BITLEN;
1089 }
1090 else
1091 ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
1092
1093 if (ret <= 0)
1094 {
1095 vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
1096 return CMD_WARNING;
1097 }
1098 }
1099 #endif /* HAVE_IPV6 */
1100
1101 /* Lookup prefix entry. */
1102 pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
1103
1104 if (pentry == NULL)
1105 {
1106 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1107 return CMD_WARNING;
1108 }
1109
1110 /* Install new filter to the access_list. */
1111 prefix_list_entry_delete (plist, pentry, 1);
1112
1113 return CMD_SUCCESS;
1114 }
1115
1116 static int
1117 vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
1118 {
1119 struct prefix_list *plist;
1120
1121 plist = prefix_list_lookup (afi, name);
1122 if (! plist)
1123 {
1124 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1125 return CMD_WARNING;
1126 }
1127
1128 if (plist->desc)
1129 {
1130 XFREE (MTYPE_TMP, plist->desc);
1131 plist->desc = NULL;
1132 }
1133
1134 if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
1135 prefix_list_delete (plist);
1136
1137 return CMD_SUCCESS;
1138 }
1139
1140 enum display_type
1141 {
1142 normal_display,
1143 summary_display,
1144 detail_display,
1145 sequential_display,
1146 longer_display,
1147 first_match_display
1148 };
1149
1150 static void
1151 vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
1152 struct prefix_master *master, enum display_type dtype,
1153 int seqnum)
1154 {
1155 struct prefix_list_entry *pentry;
1156
1157 /* Print the name of the protocol */
1158 if (zlog_default)
1159 vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
1160
1161 if (dtype == normal_display)
1162 {
1163 vty_out (vty, "ip%s prefix-list %s: %d entries%s",
1164 afi == AFI_IP ? "" : "v6",
1165 plist->name, plist->count, VTY_NEWLINE);
1166 if (plist->desc)
1167 vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
1168 }
1169 else if (dtype == summary_display || dtype == detail_display)
1170 {
1171 vty_out (vty, "ip%s prefix-list %s:%s",
1172 afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
1173
1174 if (plist->desc)
1175 vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
1176
1177 vty_out (vty, " count: %d, range entries: %d, sequences: %u - %u%s",
1178 plist->count, plist->rangecount,
1179 plist->head ? plist->head->seq : 0,
1180 plist->tail ? plist->tail->seq : 0,
1181 VTY_NEWLINE);
1182 }
1183
1184 if (dtype != summary_display)
1185 {
1186 for (pentry = plist->head; pentry; pentry = pentry->next)
1187 {
1188 if (dtype == sequential_display && pentry->seq != seqnum)
1189 continue;
1190
1191 vty_out (vty, " ");
1192
1193 if (master->seqnum)
1194 vty_out (vty, "seq %u ", pentry->seq);
1195
1196 vty_out (vty, "%s ", prefix_list_type_str (pentry));
1197
1198 if (pentry->any)
1199 vty_out (vty, "any");
1200 else
1201 {
1202 struct prefix *p = &pentry->prefix;
1203 char buf[BUFSIZ];
1204
1205 vty_out (vty, "%s/%d",
1206 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1207 p->prefixlen);
1208
1209 if (pentry->ge)
1210 vty_out (vty, " ge %d", pentry->ge);
1211 if (pentry->le)
1212 vty_out (vty, " le %d", pentry->le);
1213 }
1214
1215 if (dtype == detail_display || dtype == sequential_display)
1216 vty_out (vty, " (hit count: %ld, refcount: %ld)",
1217 pentry->hitcnt, pentry->refcnt);
1218
1219 vty_out (vty, "%s", VTY_NEWLINE);
1220 }
1221 }
1222 }
1223
1224 static int
1225 vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
1226 const char *seq, enum display_type dtype)
1227 {
1228 struct prefix_list *plist;
1229 struct prefix_master *master;
1230 int seqnum = 0;
1231
1232 master = prefix_master_get (afi, 0);
1233 if (master == NULL)
1234 return CMD_WARNING;
1235
1236 if (seq)
1237 seqnum = atoi (seq);
1238
1239 if (name)
1240 {
1241 plist = prefix_list_lookup (afi, name);
1242 if (! plist)
1243 {
1244 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1245 return CMD_WARNING;
1246 }
1247 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1248 }
1249 else
1250 {
1251 if (dtype == detail_display || dtype == summary_display)
1252 {
1253 if (master->recent)
1254 vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
1255 master->recent->name, VTY_NEWLINE);
1256 }
1257
1258 for (plist = master->num.head; plist; plist = plist->next)
1259 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1260
1261 for (plist = master->str.head; plist; plist = plist->next)
1262 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1263 }
1264
1265 return CMD_SUCCESS;
1266 }
1267
1268 static int
1269 vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
1270 const char *prefix, enum display_type type)
1271 {
1272 struct prefix_list *plist;
1273 struct prefix_list_entry *pentry;
1274 struct prefix p;
1275 int ret;
1276 int match;
1277
1278 plist = prefix_list_lookup (afi, name);
1279 if (! plist)
1280 {
1281 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1282 return CMD_WARNING;
1283 }
1284
1285 ret = str2prefix (prefix, &p);
1286 if (ret <= 0)
1287 {
1288 vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
1289 return CMD_WARNING;
1290 }
1291
1292 for (pentry = plist->head; pentry; pentry = pentry->next)
1293 {
1294 match = 0;
1295
1296 if (type == normal_display || type == first_match_display)
1297 if (prefix_same (&p, &pentry->prefix))
1298 match = 1;
1299
1300 if (type == longer_display)
1301 if (prefix_match (&p, &pentry->prefix))
1302 match = 1;
1303
1304 if (match)
1305 {
1306 vty_out (vty, " seq %u %s ",
1307 pentry->seq,
1308 prefix_list_type_str (pentry));
1309
1310 if (pentry->any)
1311 vty_out (vty, "any");
1312 else
1313 {
1314 struct prefix *p = &pentry->prefix;
1315 char buf[BUFSIZ];
1316
1317 vty_out (vty, "%s/%d",
1318 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1319 p->prefixlen);
1320
1321 if (pentry->ge)
1322 vty_out (vty, " ge %d", pentry->ge);
1323 if (pentry->le)
1324 vty_out (vty, " le %d", pentry->le);
1325 }
1326
1327 if (type == normal_display || type == first_match_display)
1328 vty_out (vty, " (hit count: %ld, refcount: %ld)",
1329 pentry->hitcnt, pentry->refcnt);
1330
1331 vty_out (vty, "%s", VTY_NEWLINE);
1332
1333 if (type == first_match_display)
1334 return CMD_SUCCESS;
1335 }
1336 }
1337 return CMD_SUCCESS;
1338 }
1339
1340 static int
1341 vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
1342 const char *prefix)
1343 {
1344 struct prefix_master *master;
1345 struct prefix_list *plist;
1346 struct prefix_list_entry *pentry;
1347 int ret;
1348 struct prefix p;
1349
1350 master = prefix_master_get (afi, 0);
1351 if (master == NULL)
1352 return CMD_WARNING;
1353
1354 if (name == NULL && prefix == NULL)
1355 {
1356 for (plist = master->num.head; plist; plist = plist->next)
1357 for (pentry = plist->head; pentry; pentry = pentry->next)
1358 pentry->hitcnt = 0;
1359
1360 for (plist = master->str.head; plist; plist = plist->next)
1361 for (pentry = plist->head; pentry; pentry = pentry->next)
1362 pentry->hitcnt = 0;
1363 }
1364 else
1365 {
1366 plist = prefix_list_lookup (afi, name);
1367 if (! plist)
1368 {
1369 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1370 return CMD_WARNING;
1371 }
1372
1373 if (prefix)
1374 {
1375 ret = str2prefix (prefix, &p);
1376 if (ret <= 0)
1377 {
1378 vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
1379 return CMD_WARNING;
1380 }
1381 }
1382
1383 for (pentry = plist->head; pentry; pentry = pentry->next)
1384 {
1385 if (prefix)
1386 {
1387 if (prefix_match (&pentry->prefix, &p))
1388 pentry->hitcnt = 0;
1389 }
1390 else
1391 pentry->hitcnt = 0;
1392 }
1393 }
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUN (ip_prefix_list,
1398 ip_prefix_list_cmd,
1399 "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
1400 IP_STR
1401 PREFIX_LIST_STR
1402 "Name of a prefix list\n"
1403 "Specify packets to reject\n"
1404 "Specify packets to forward\n"
1405 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1406 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1407 {
1408 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
1409 argv[1], argv[2], NULL, NULL);
1410 }
1411
1412 DEFUN (ip_prefix_list_ge,
1413 ip_prefix_list_ge_cmd,
1414 "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
1415 IP_STR
1416 PREFIX_LIST_STR
1417 "Name of a prefix list\n"
1418 "Specify packets to reject\n"
1419 "Specify packets to forward\n"
1420 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1421 "Minimum prefix length to be matched\n"
1422 "Minimum prefix length\n")
1423 {
1424 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1425 argv[2], argv[3], NULL);
1426 }
1427
1428 DEFUN (ip_prefix_list_ge_le,
1429 ip_prefix_list_ge_le_cmd,
1430 "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1431 IP_STR
1432 PREFIX_LIST_STR
1433 "Name of a prefix list\n"
1434 "Specify packets to reject\n"
1435 "Specify packets to forward\n"
1436 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1437 "Minimum prefix length to be matched\n"
1438 "Minimum prefix length\n"
1439 "Maximum prefix length to be matched\n"
1440 "Maximum prefix length\n")
1441 {
1442 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1443 argv[2], argv[3], argv[4]);
1444 }
1445
1446 DEFUN (ip_prefix_list_le,
1447 ip_prefix_list_le_cmd,
1448 "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
1449 IP_STR
1450 PREFIX_LIST_STR
1451 "Name of a prefix list\n"
1452 "Specify packets to reject\n"
1453 "Specify packets to forward\n"
1454 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1455 "Maximum prefix length to be matched\n"
1456 "Maximum prefix length\n")
1457 {
1458 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1459 argv[2], NULL, argv[3]);
1460 }
1461
1462 DEFUN (ip_prefix_list_le_ge,
1463 ip_prefix_list_le_ge_cmd,
1464 "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1465 IP_STR
1466 PREFIX_LIST_STR
1467 "Name of a prefix list\n"
1468 "Specify packets to reject\n"
1469 "Specify packets to forward\n"
1470 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1471 "Maximum prefix length to be matched\n"
1472 "Maximum prefix length\n"
1473 "Minimum prefix length to be matched\n"
1474 "Minimum prefix length\n")
1475 {
1476 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1477 argv[2], argv[4], argv[3]);
1478 }
1479
1480 DEFUN (ip_prefix_list_seq,
1481 ip_prefix_list_seq_cmd,
1482 "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
1483 IP_STR
1484 PREFIX_LIST_STR
1485 "Name of a prefix list\n"
1486 "sequence number of an entry\n"
1487 "Sequence number\n"
1488 "Specify packets to reject\n"
1489 "Specify packets to forward\n"
1490 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1491 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1492 {
1493 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1494 argv[3], NULL, NULL);
1495 }
1496
1497 DEFUN (ip_prefix_list_seq_ge,
1498 ip_prefix_list_seq_ge_cmd,
1499 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
1500 IP_STR
1501 PREFIX_LIST_STR
1502 "Name of a prefix list\n"
1503 "sequence number of an entry\n"
1504 "Sequence number\n"
1505 "Specify packets to reject\n"
1506 "Specify packets to forward\n"
1507 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1508 "Minimum prefix length to be matched\n"
1509 "Minimum prefix length\n")
1510 {
1511 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1512 argv[3], argv[4], NULL);
1513 }
1514
1515 DEFUN (ip_prefix_list_seq_ge_le,
1516 ip_prefix_list_seq_ge_le_cmd,
1517 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1518 IP_STR
1519 PREFIX_LIST_STR
1520 "Name of a prefix list\n"
1521 "sequence number of an entry\n"
1522 "Sequence number\n"
1523 "Specify packets to reject\n"
1524 "Specify packets to forward\n"
1525 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1526 "Minimum prefix length to be matched\n"
1527 "Minimum prefix length\n"
1528 "Maximum prefix length to be matched\n"
1529 "Maximum prefix length\n")
1530 {
1531 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1532 argv[3], argv[4], argv[5]);
1533 }
1534
1535 DEFUN (ip_prefix_list_seq_le,
1536 ip_prefix_list_seq_le_cmd,
1537 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
1538 IP_STR
1539 PREFIX_LIST_STR
1540 "Name of a prefix list\n"
1541 "sequence number of an entry\n"
1542 "Sequence number\n"
1543 "Specify packets to reject\n"
1544 "Specify packets to forward\n"
1545 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1546 "Maximum prefix length to be matched\n"
1547 "Maximum prefix length\n")
1548 {
1549 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1550 argv[3], NULL, argv[4]);
1551 }
1552
1553 DEFUN (ip_prefix_list_seq_le_ge,
1554 ip_prefix_list_seq_le_ge_cmd,
1555 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1556 IP_STR
1557 PREFIX_LIST_STR
1558 "Name of a prefix list\n"
1559 "sequence number of an entry\n"
1560 "Sequence number\n"
1561 "Specify packets to reject\n"
1562 "Specify packets to forward\n"
1563 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1564 "Maximum prefix length to be matched\n"
1565 "Maximum prefix length\n"
1566 "Minimum prefix length to be matched\n"
1567 "Minimum prefix length\n")
1568 {
1569 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1570 argv[3], argv[5], argv[4]);
1571 }
1572
1573 DEFUN (no_ip_prefix_list,
1574 no_ip_prefix_list_cmd,
1575 "no ip prefix-list WORD",
1576 NO_STR
1577 IP_STR
1578 PREFIX_LIST_STR
1579 "Name of a prefix list\n")
1580 {
1581 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
1582 NULL, NULL, NULL);
1583 }
1584
1585 DEFUN (no_ip_prefix_list_prefix,
1586 no_ip_prefix_list_prefix_cmd,
1587 "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
1588 NO_STR
1589 IP_STR
1590 PREFIX_LIST_STR
1591 "Name of a prefix list\n"
1592 "Specify packets to reject\n"
1593 "Specify packets to forward\n"
1594 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1595 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1596 {
1597 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1598 argv[2], NULL, NULL);
1599 }
1600
1601 DEFUN (no_ip_prefix_list_ge,
1602 no_ip_prefix_list_ge_cmd,
1603 "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
1604 NO_STR
1605 IP_STR
1606 PREFIX_LIST_STR
1607 "Name of a prefix list\n"
1608 "Specify packets to reject\n"
1609 "Specify packets to forward\n"
1610 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1611 "Minimum prefix length to be matched\n"
1612 "Minimum prefix length\n")
1613 {
1614 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1615 argv[2], argv[3], NULL);
1616 }
1617
1618 DEFUN (no_ip_prefix_list_ge_le,
1619 no_ip_prefix_list_ge_le_cmd,
1620 "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1621 NO_STR
1622 IP_STR
1623 PREFIX_LIST_STR
1624 "Name of a prefix list\n"
1625 "Specify packets to reject\n"
1626 "Specify packets to forward\n"
1627 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1628 "Minimum prefix length to be matched\n"
1629 "Minimum prefix length\n"
1630 "Maximum prefix length to be matched\n"
1631 "Maximum prefix length\n")
1632 {
1633 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1634 argv[2], argv[3], argv[4]);
1635 }
1636
1637 DEFUN (no_ip_prefix_list_le,
1638 no_ip_prefix_list_le_cmd,
1639 "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
1640 NO_STR
1641 IP_STR
1642 PREFIX_LIST_STR
1643 "Name of a prefix list\n"
1644 "Specify packets to reject\n"
1645 "Specify packets to forward\n"
1646 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1647 "Maximum prefix length to be matched\n"
1648 "Maximum prefix length\n")
1649 {
1650 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1651 argv[2], NULL, argv[3]);
1652 }
1653
1654 DEFUN (no_ip_prefix_list_le_ge,
1655 no_ip_prefix_list_le_ge_cmd,
1656 "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1657 NO_STR
1658 IP_STR
1659 PREFIX_LIST_STR
1660 "Name of a prefix list\n"
1661 "Specify packets to reject\n"
1662 "Specify packets to forward\n"
1663 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1664 "Maximum prefix length to be matched\n"
1665 "Maximum prefix length\n"
1666 "Minimum prefix length to be matched\n"
1667 "Minimum prefix length\n")
1668 {
1669 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1670 argv[2], argv[4], argv[3]);
1671 }
1672
1673 DEFUN (no_ip_prefix_list_seq,
1674 no_ip_prefix_list_seq_cmd,
1675 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
1676 NO_STR
1677 IP_STR
1678 PREFIX_LIST_STR
1679 "Name of a prefix list\n"
1680 "sequence number of an entry\n"
1681 "Sequence number\n"
1682 "Specify packets to reject\n"
1683 "Specify packets to forward\n"
1684 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1685 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1686 {
1687 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1688 argv[3], NULL, NULL);
1689 }
1690
1691 DEFUN (no_ip_prefix_list_seq_ge,
1692 no_ip_prefix_list_seq_ge_cmd,
1693 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
1694 NO_STR
1695 IP_STR
1696 PREFIX_LIST_STR
1697 "Name of a prefix list\n"
1698 "sequence number of an entry\n"
1699 "Sequence number\n"
1700 "Specify packets to reject\n"
1701 "Specify packets to forward\n"
1702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1703 "Minimum prefix length to be matched\n"
1704 "Minimum prefix length\n")
1705 {
1706 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1707 argv[3], argv[4], NULL);
1708 }
1709
1710 DEFUN (no_ip_prefix_list_seq_ge_le,
1711 no_ip_prefix_list_seq_ge_le_cmd,
1712 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1713 NO_STR
1714 IP_STR
1715 PREFIX_LIST_STR
1716 "Name of a prefix list\n"
1717 "sequence number of an entry\n"
1718 "Sequence number\n"
1719 "Specify packets to reject\n"
1720 "Specify packets to forward\n"
1721 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1722 "Minimum prefix length to be matched\n"
1723 "Minimum prefix length\n"
1724 "Maximum prefix length to be matched\n"
1725 "Maximum prefix length\n")
1726 {
1727 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1728 argv[3], argv[4], argv[5]);
1729 }
1730
1731 DEFUN (no_ip_prefix_list_seq_le,
1732 no_ip_prefix_list_seq_le_cmd,
1733 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
1734 NO_STR
1735 IP_STR
1736 PREFIX_LIST_STR
1737 "Name of a prefix list\n"
1738 "sequence number of an entry\n"
1739 "Sequence number\n"
1740 "Specify packets to reject\n"
1741 "Specify packets to forward\n"
1742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1743 "Maximum prefix length to be matched\n"
1744 "Maximum prefix length\n")
1745 {
1746 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1747 argv[3], NULL, argv[4]);
1748 }
1749
1750 DEFUN (no_ip_prefix_list_seq_le_ge,
1751 no_ip_prefix_list_seq_le_ge_cmd,
1752 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1753 NO_STR
1754 IP_STR
1755 PREFIX_LIST_STR
1756 "Name of a prefix list\n"
1757 "sequence number of an entry\n"
1758 "Sequence number\n"
1759 "Specify packets to reject\n"
1760 "Specify packets to forward\n"
1761 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1762 "Maximum prefix length to be matched\n"
1763 "Maximum prefix length\n"
1764 "Minimum prefix length to be matched\n"
1765 "Minimum prefix length\n")
1766 {
1767 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1768 argv[3], argv[5], argv[4]);
1769 }
1770
1771 DEFUN (ip_prefix_list_sequence_number,
1772 ip_prefix_list_sequence_number_cmd,
1773 "ip prefix-list sequence-number",
1774 IP_STR
1775 PREFIX_LIST_STR
1776 "Include/exclude sequence numbers in NVGEN\n")
1777 {
1778 prefix_master_ipv4.seqnum = 1;
1779 return CMD_SUCCESS;
1780 }
1781
1782 DEFUN (no_ip_prefix_list_sequence_number,
1783 no_ip_prefix_list_sequence_number_cmd,
1784 "no ip prefix-list sequence-number",
1785 NO_STR
1786 IP_STR
1787 PREFIX_LIST_STR
1788 "Include/exclude sequence numbers in NVGEN\n")
1789 {
1790 prefix_master_ipv4.seqnum = 0;
1791 return CMD_SUCCESS;
1792 }
1793
1794 DEFUN (ip_prefix_list_description,
1795 ip_prefix_list_description_cmd,
1796 "ip prefix-list WORD description .LINE",
1797 IP_STR
1798 PREFIX_LIST_STR
1799 "Name of a prefix list\n"
1800 "Prefix-list specific description\n"
1801 "Up to 80 characters describing this prefix-list\n")
1802 {
1803 struct prefix_list *plist;
1804
1805 plist = prefix_list_get (AFI_IP, 0, argv[0]);
1806
1807 if (plist->desc)
1808 {
1809 XFREE (MTYPE_TMP, plist->desc);
1810 plist->desc = NULL;
1811 }
1812 plist->desc = argv_concat(argv, argc, 1);
1813
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (no_ip_prefix_list_description,
1818 no_ip_prefix_list_description_cmd,
1819 "no ip prefix-list WORD description",
1820 NO_STR
1821 IP_STR
1822 PREFIX_LIST_STR
1823 "Name of a prefix list\n"
1824 "Prefix-list specific description\n")
1825 {
1826 return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
1827 }
1828
1829 ALIAS (no_ip_prefix_list_description,
1830 no_ip_prefix_list_description_arg_cmd,
1831 "no ip prefix-list WORD description .LINE",
1832 NO_STR
1833 IP_STR
1834 PREFIX_LIST_STR
1835 "Name of a prefix list\n"
1836 "Prefix-list specific description\n"
1837 "Up to 80 characters describing this prefix-list\n")
1838
1839 DEFUN (show_ip_prefix_list,
1840 show_ip_prefix_list_cmd,
1841 "show ip prefix-list",
1842 SHOW_STR
1843 IP_STR
1844 PREFIX_LIST_STR)
1845 {
1846 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
1847 }
1848
1849 DEFUN (show_ip_prefix_list_name,
1850 show_ip_prefix_list_name_cmd,
1851 "show ip prefix-list WORD",
1852 SHOW_STR
1853 IP_STR
1854 PREFIX_LIST_STR
1855 "Name of a prefix list\n")
1856 {
1857 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
1858 }
1859
1860 DEFUN (show_ip_prefix_list_name_seq,
1861 show_ip_prefix_list_name_seq_cmd,
1862 "show ip prefix-list WORD seq <1-4294967295>",
1863 SHOW_STR
1864 IP_STR
1865 PREFIX_LIST_STR
1866 "Name of a prefix list\n"
1867 "sequence number of an entry\n"
1868 "Sequence number\n")
1869 {
1870 return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
1871 }
1872
1873 DEFUN (show_ip_prefix_list_prefix,
1874 show_ip_prefix_list_prefix_cmd,
1875 "show ip prefix-list WORD A.B.C.D/M",
1876 SHOW_STR
1877 IP_STR
1878 PREFIX_LIST_STR
1879 "Name of a prefix list\n"
1880 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1881 {
1882 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
1883 }
1884
1885 DEFUN (show_ip_prefix_list_prefix_longer,
1886 show_ip_prefix_list_prefix_longer_cmd,
1887 "show ip prefix-list WORD A.B.C.D/M longer",
1888 SHOW_STR
1889 IP_STR
1890 PREFIX_LIST_STR
1891 "Name of a prefix list\n"
1892 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1893 "Lookup longer prefix\n")
1894 {
1895 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
1896 }
1897
1898 DEFUN (show_ip_prefix_list_prefix_first_match,
1899 show_ip_prefix_list_prefix_first_match_cmd,
1900 "show ip prefix-list WORD A.B.C.D/M first-match",
1901 SHOW_STR
1902 IP_STR
1903 PREFIX_LIST_STR
1904 "Name of a prefix list\n"
1905 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1906 "First matched prefix\n")
1907 {
1908 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
1909 }
1910
1911 DEFUN (show_ip_prefix_list_summary,
1912 show_ip_prefix_list_summary_cmd,
1913 "show ip prefix-list summary",
1914 SHOW_STR
1915 IP_STR
1916 PREFIX_LIST_STR
1917 "Summary of prefix lists\n")
1918 {
1919 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
1920 }
1921
1922 DEFUN (show_ip_prefix_list_summary_name,
1923 show_ip_prefix_list_summary_name_cmd,
1924 "show ip prefix-list summary WORD",
1925 SHOW_STR
1926 IP_STR
1927 PREFIX_LIST_STR
1928 "Summary of prefix lists\n"
1929 "Name of a prefix list\n")
1930 {
1931 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
1932 }
1933
1934
1935 DEFUN (show_ip_prefix_list_detail,
1936 show_ip_prefix_list_detail_cmd,
1937 "show ip prefix-list detail",
1938 SHOW_STR
1939 IP_STR
1940 PREFIX_LIST_STR
1941 "Detail of prefix lists\n")
1942 {
1943 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
1944 }
1945
1946 DEFUN (show_ip_prefix_list_detail_name,
1947 show_ip_prefix_list_detail_name_cmd,
1948 "show ip prefix-list detail WORD",
1949 SHOW_STR
1950 IP_STR
1951 PREFIX_LIST_STR
1952 "Detail of prefix lists\n"
1953 "Name of a prefix list\n")
1954 {
1955 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
1956 }
1957
1958 DEFUN (clear_ip_prefix_list,
1959 clear_ip_prefix_list_cmd,
1960 "clear ip prefix-list",
1961 CLEAR_STR
1962 IP_STR
1963 PREFIX_LIST_STR)
1964 {
1965 return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
1966 }
1967
1968 DEFUN (clear_ip_prefix_list_name,
1969 clear_ip_prefix_list_name_cmd,
1970 "clear ip prefix-list WORD",
1971 CLEAR_STR
1972 IP_STR
1973 PREFIX_LIST_STR
1974 "Name of a prefix list\n")
1975 {
1976 return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
1977 }
1978
1979 DEFUN (clear_ip_prefix_list_name_prefix,
1980 clear_ip_prefix_list_name_prefix_cmd,
1981 "clear ip prefix-list WORD A.B.C.D/M",
1982 CLEAR_STR
1983 IP_STR
1984 PREFIX_LIST_STR
1985 "Name of a prefix list\n"
1986 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1987 {
1988 return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
1989 }
1990
1991 #ifdef HAVE_IPV6
1992 DEFUN (ipv6_prefix_list,
1993 ipv6_prefix_list_cmd,
1994 "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
1995 IPV6_STR
1996 PREFIX_LIST_STR
1997 "Name of a prefix list\n"
1998 "Specify packets to reject\n"
1999 "Specify packets to forward\n"
2000 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2001 "Any prefix match. Same as \"::0/0 le 128\"\n")
2002 {
2003 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
2004 argv[1], argv[2], NULL, NULL);
2005 }
2006
2007 DEFUN (ipv6_prefix_list_ge,
2008 ipv6_prefix_list_ge_cmd,
2009 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
2010 IPV6_STR
2011 PREFIX_LIST_STR
2012 "Name of a prefix list\n"
2013 "Specify packets to reject\n"
2014 "Specify packets to forward\n"
2015 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2016 "Minimum prefix length to be matched\n"
2017 "Minimum prefix length\n")
2018 {
2019 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
2020 argv[2], argv[3], NULL);
2021 }
2022
2023 DEFUN (ipv6_prefix_list_ge_le,
2024 ipv6_prefix_list_ge_le_cmd,
2025 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
2026 IPV6_STR
2027 PREFIX_LIST_STR
2028 "Name of a prefix list\n"
2029 "Specify packets to reject\n"
2030 "Specify packets to forward\n"
2031 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2032 "Minimum prefix length to be matched\n"
2033 "Minimum prefix length\n"
2034 "Maximum prefix length to be matched\n"
2035 "Maximum prefix length\n")
2036
2037 {
2038 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
2039 argv[2], argv[3], argv[4]);
2040 }
2041
2042 DEFUN (ipv6_prefix_list_le,
2043 ipv6_prefix_list_le_cmd,
2044 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
2045 IPV6_STR
2046 PREFIX_LIST_STR
2047 "Name of a prefix list\n"
2048 "Specify packets to reject\n"
2049 "Specify packets to forward\n"
2050 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2051 "Maximum prefix length to be matched\n"
2052 "Maximum prefix length\n")
2053 {
2054 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
2055 argv[2], NULL, argv[3]);
2056 }
2057
2058 DEFUN (ipv6_prefix_list_le_ge,
2059 ipv6_prefix_list_le_ge_cmd,
2060 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2061 IPV6_STR
2062 PREFIX_LIST_STR
2063 "Name of a prefix list\n"
2064 "Specify packets to reject\n"
2065 "Specify packets to forward\n"
2066 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2067 "Maximum prefix length to be matched\n"
2068 "Maximum prefix length\n"
2069 "Minimum prefix length to be matched\n"
2070 "Minimum prefix length\n")
2071 {
2072 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
2073 argv[2], argv[4], argv[3]);
2074 }
2075
2076 DEFUN (ipv6_prefix_list_seq,
2077 ipv6_prefix_list_seq_cmd,
2078 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
2079 IPV6_STR
2080 PREFIX_LIST_STR
2081 "Name of a prefix list\n"
2082 "sequence number of an entry\n"
2083 "Sequence number\n"
2084 "Specify packets to reject\n"
2085 "Specify packets to forward\n"
2086 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2087 "Any prefix match. Same as \"::0/0 le 128\"\n")
2088 {
2089 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
2090 argv[3], NULL, NULL);
2091 }
2092
2093 DEFUN (ipv6_prefix_list_seq_ge,
2094 ipv6_prefix_list_seq_ge_cmd,
2095 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
2096 IPV6_STR
2097 PREFIX_LIST_STR
2098 "Name of a prefix list\n"
2099 "sequence number of an entry\n"
2100 "Sequence number\n"
2101 "Specify packets to reject\n"
2102 "Specify packets to forward\n"
2103 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2104 "Minimum prefix length to be matched\n"
2105 "Minimum prefix length\n")
2106 {
2107 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
2108 argv[3], argv[4], NULL);
2109 }
2110
2111 DEFUN (ipv6_prefix_list_seq_ge_le,
2112 ipv6_prefix_list_seq_ge_le_cmd,
2113 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
2114 IPV6_STR
2115 PREFIX_LIST_STR
2116 "Name of a prefix list\n"
2117 "sequence number of an entry\n"
2118 "Sequence number\n"
2119 "Specify packets to reject\n"
2120 "Specify packets to forward\n"
2121 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2122 "Minimum prefix length to be matched\n"
2123 "Minimum prefix length\n"
2124 "Maximum prefix length to be matched\n"
2125 "Maximum prefix length\n")
2126 {
2127 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
2128 argv[3], argv[4], argv[5]);
2129 }
2130
2131 DEFUN (ipv6_prefix_list_seq_le,
2132 ipv6_prefix_list_seq_le_cmd,
2133 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
2134 IPV6_STR
2135 PREFIX_LIST_STR
2136 "Name of a prefix list\n"
2137 "sequence number of an entry\n"
2138 "Sequence number\n"
2139 "Specify packets to reject\n"
2140 "Specify packets to forward\n"
2141 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2142 "Maximum prefix length to be matched\n"
2143 "Maximum prefix length\n")
2144 {
2145 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
2146 argv[3], NULL, argv[4]);
2147 }
2148
2149 DEFUN (ipv6_prefix_list_seq_le_ge,
2150 ipv6_prefix_list_seq_le_ge_cmd,
2151 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2152 IPV6_STR
2153 PREFIX_LIST_STR
2154 "Name of a prefix list\n"
2155 "sequence number of an entry\n"
2156 "Sequence number\n"
2157 "Specify packets to reject\n"
2158 "Specify packets to forward\n"
2159 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2160 "Maximum prefix length to be matched\n"
2161 "Maximum prefix length\n"
2162 "Minimum prefix length to be matched\n"
2163 "Minimum prefix length\n")
2164 {
2165 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
2166 argv[3], argv[5], argv[4]);
2167 }
2168
2169 DEFUN (no_ipv6_prefix_list,
2170 no_ipv6_prefix_list_cmd,
2171 "no ipv6 prefix-list WORD",
2172 NO_STR
2173 IPV6_STR
2174 PREFIX_LIST_STR
2175 "Name of a prefix list\n")
2176 {
2177 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
2178 NULL, NULL, NULL);
2179 }
2180
2181 DEFUN (no_ipv6_prefix_list_prefix,
2182 no_ipv6_prefix_list_prefix_cmd,
2183 "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
2184 NO_STR
2185 IPV6_STR
2186 PREFIX_LIST_STR
2187 "Name of a prefix list\n"
2188 "Specify packets to reject\n"
2189 "Specify packets to forward\n"
2190 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2191 "Any prefix match. Same as \"::0/0 le 128\"\n")
2192 {
2193 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2194 argv[2], NULL, NULL);
2195 }
2196
2197 DEFUN (no_ipv6_prefix_list_ge,
2198 no_ipv6_prefix_list_ge_cmd,
2199 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
2200 NO_STR
2201 IPV6_STR
2202 PREFIX_LIST_STR
2203 "Name of a prefix list\n"
2204 "Specify packets to reject\n"
2205 "Specify packets to forward\n"
2206 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2207 "Minimum prefix length to be matched\n"
2208 "Minimum prefix length\n")
2209 {
2210 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2211 argv[2], argv[3], NULL);
2212 }
2213
2214 DEFUN (no_ipv6_prefix_list_ge_le,
2215 no_ipv6_prefix_list_ge_le_cmd,
2216 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
2217 NO_STR
2218 IPV6_STR
2219 PREFIX_LIST_STR
2220 "Name of a prefix list\n"
2221 "Specify packets to reject\n"
2222 "Specify packets to forward\n"
2223 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2224 "Minimum prefix length to be matched\n"
2225 "Minimum prefix length\n"
2226 "Maximum prefix length to be matched\n"
2227 "Maximum prefix length\n")
2228 {
2229 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2230 argv[2], argv[3], argv[4]);
2231 }
2232
2233 DEFUN (no_ipv6_prefix_list_le,
2234 no_ipv6_prefix_list_le_cmd,
2235 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
2236 NO_STR
2237 IPV6_STR
2238 PREFIX_LIST_STR
2239 "Name of a prefix list\n"
2240 "Specify packets to reject\n"
2241 "Specify packets to forward\n"
2242 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2243 "Maximum prefix length to be matched\n"
2244 "Maximum prefix length\n")
2245 {
2246 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2247 argv[2], NULL, argv[3]);
2248 }
2249
2250 DEFUN (no_ipv6_prefix_list_le_ge,
2251 no_ipv6_prefix_list_le_ge_cmd,
2252 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2253 NO_STR
2254 IPV6_STR
2255 PREFIX_LIST_STR
2256 "Name of a prefix list\n"
2257 "Specify packets to reject\n"
2258 "Specify packets to forward\n"
2259 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2260 "Maximum prefix length to be matched\n"
2261 "Maximum prefix length\n"
2262 "Minimum prefix length to be matched\n"
2263 "Minimum prefix length\n")
2264 {
2265 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2266 argv[2], argv[4], argv[3]);
2267 }
2268
2269 DEFUN (no_ipv6_prefix_list_seq,
2270 no_ipv6_prefix_list_seq_cmd,
2271 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
2272 NO_STR
2273 IPV6_STR
2274 PREFIX_LIST_STR
2275 "Name of a prefix list\n"
2276 "sequence number of an entry\n"
2277 "Sequence number\n"
2278 "Specify packets to reject\n"
2279 "Specify packets to forward\n"
2280 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2281 "Any prefix match. Same as \"::0/0 le 128\"\n")
2282 {
2283 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2284 argv[3], NULL, NULL);
2285 }
2286
2287 DEFUN (no_ipv6_prefix_list_seq_ge,
2288 no_ipv6_prefix_list_seq_ge_cmd,
2289 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
2290 NO_STR
2291 IPV6_STR
2292 PREFIX_LIST_STR
2293 "Name of a prefix list\n"
2294 "sequence number of an entry\n"
2295 "Sequence number\n"
2296 "Specify packets to reject\n"
2297 "Specify packets to forward\n"
2298 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2299 "Minimum prefix length to be matched\n"
2300 "Minimum prefix length\n")
2301 {
2302 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2303 argv[3], argv[4], NULL);
2304 }
2305
2306 DEFUN (no_ipv6_prefix_list_seq_ge_le,
2307 no_ipv6_prefix_list_seq_ge_le_cmd,
2308 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
2309 NO_STR
2310 IPV6_STR
2311 PREFIX_LIST_STR
2312 "Name of a prefix list\n"
2313 "sequence number of an entry\n"
2314 "Sequence number\n"
2315 "Specify packets to reject\n"
2316 "Specify packets to forward\n"
2317 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2318 "Minimum prefix length to be matched\n"
2319 "Minimum prefix length\n"
2320 "Maximum prefix length to be matched\n"
2321 "Maximum prefix length\n")
2322 {
2323 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2324 argv[3], argv[4], argv[5]);
2325 }
2326
2327 DEFUN (no_ipv6_prefix_list_seq_le,
2328 no_ipv6_prefix_list_seq_le_cmd,
2329 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
2330 NO_STR
2331 IPV6_STR
2332 PREFIX_LIST_STR
2333 "Name of a prefix list\n"
2334 "sequence number of an entry\n"
2335 "Sequence number\n"
2336 "Specify packets to reject\n"
2337 "Specify packets to forward\n"
2338 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2339 "Maximum prefix length to be matched\n"
2340 "Maximum prefix length\n")
2341 {
2342 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2343 argv[3], NULL, argv[4]);
2344 }
2345
2346 DEFUN (no_ipv6_prefix_list_seq_le_ge,
2347 no_ipv6_prefix_list_seq_le_ge_cmd,
2348 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2349 NO_STR
2350 IPV6_STR
2351 PREFIX_LIST_STR
2352 "Name of a prefix list\n"
2353 "sequence number of an entry\n"
2354 "Sequence number\n"
2355 "Specify packets to reject\n"
2356 "Specify packets to forward\n"
2357 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2358 "Maximum prefix length to be matched\n"
2359 "Maximum prefix length\n"
2360 "Minimum prefix length to be matched\n"
2361 "Minimum prefix length\n")
2362 {
2363 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2364 argv[3], argv[5], argv[4]);
2365 }
2366
2367 DEFUN (ipv6_prefix_list_sequence_number,
2368 ipv6_prefix_list_sequence_number_cmd,
2369 "ipv6 prefix-list sequence-number",
2370 IPV6_STR
2371 PREFIX_LIST_STR
2372 "Include/exclude sequence numbers in NVGEN\n")
2373 {
2374 prefix_master_ipv6.seqnum = 1;
2375 return CMD_SUCCESS;
2376 }
2377
2378 DEFUN (no_ipv6_prefix_list_sequence_number,
2379 no_ipv6_prefix_list_sequence_number_cmd,
2380 "no ipv6 prefix-list sequence-number",
2381 NO_STR
2382 IPV6_STR
2383 PREFIX_LIST_STR
2384 "Include/exclude sequence numbers in NVGEN\n")
2385 {
2386 prefix_master_ipv6.seqnum = 0;
2387 return CMD_SUCCESS;
2388 }
2389
2390 DEFUN (ipv6_prefix_list_description,
2391 ipv6_prefix_list_description_cmd,
2392 "ipv6 prefix-list WORD description .LINE",
2393 IPV6_STR
2394 PREFIX_LIST_STR
2395 "Name of a prefix list\n"
2396 "Prefix-list specific description\n"
2397 "Up to 80 characters describing this prefix-list\n")
2398 {
2399 struct prefix_list *plist;
2400
2401 plist = prefix_list_get (AFI_IP6, 0, argv[0]);
2402
2403 if (plist->desc)
2404 {
2405 XFREE (MTYPE_TMP, plist->desc);
2406 plist->desc = NULL;
2407 }
2408 plist->desc = argv_concat(argv, argc, 1);
2409
2410 return CMD_SUCCESS;
2411 }
2412
2413 DEFUN (no_ipv6_prefix_list_description,
2414 no_ipv6_prefix_list_description_cmd,
2415 "no ipv6 prefix-list WORD description",
2416 NO_STR
2417 IPV6_STR
2418 PREFIX_LIST_STR
2419 "Name of a prefix list\n"
2420 "Prefix-list specific description\n")
2421 {
2422 return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
2423 }
2424
2425 ALIAS (no_ipv6_prefix_list_description,
2426 no_ipv6_prefix_list_description_arg_cmd,
2427 "no ipv6 prefix-list WORD description .LINE",
2428 NO_STR
2429 IPV6_STR
2430 PREFIX_LIST_STR
2431 "Name of a prefix list\n"
2432 "Prefix-list specific description\n"
2433 "Up to 80 characters describing this prefix-list\n")
2434
2435 DEFUN (show_ipv6_prefix_list,
2436 show_ipv6_prefix_list_cmd,
2437 "show ipv6 prefix-list",
2438 SHOW_STR
2439 IPV6_STR
2440 PREFIX_LIST_STR)
2441 {
2442 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
2443 }
2444
2445 DEFUN (show_ipv6_prefix_list_name,
2446 show_ipv6_prefix_list_name_cmd,
2447 "show ipv6 prefix-list WORD",
2448 SHOW_STR
2449 IPV6_STR
2450 PREFIX_LIST_STR
2451 "Name of a prefix list\n")
2452 {
2453 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
2454 }
2455
2456 DEFUN (show_ipv6_prefix_list_name_seq,
2457 show_ipv6_prefix_list_name_seq_cmd,
2458 "show ipv6 prefix-list WORD seq <1-4294967295>",
2459 SHOW_STR
2460 IPV6_STR
2461 PREFIX_LIST_STR
2462 "Name of a prefix list\n"
2463 "sequence number of an entry\n"
2464 "Sequence number\n")
2465 {
2466 return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
2467 }
2468
2469 DEFUN (show_ipv6_prefix_list_prefix,
2470 show_ipv6_prefix_list_prefix_cmd,
2471 "show ipv6 prefix-list WORD X:X::X:X/M",
2472 SHOW_STR
2473 IPV6_STR
2474 PREFIX_LIST_STR
2475 "Name of a prefix list\n"
2476 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2477 {
2478 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
2479 }
2480
2481 DEFUN (show_ipv6_prefix_list_prefix_longer,
2482 show_ipv6_prefix_list_prefix_longer_cmd,
2483 "show ipv6 prefix-list WORD X:X::X:X/M longer",
2484 SHOW_STR
2485 IPV6_STR
2486 PREFIX_LIST_STR
2487 "Name of a prefix list\n"
2488 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2489 "Lookup longer prefix\n")
2490 {
2491 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
2492 }
2493
2494 DEFUN (show_ipv6_prefix_list_prefix_first_match,
2495 show_ipv6_prefix_list_prefix_first_match_cmd,
2496 "show ipv6 prefix-list WORD X:X::X:X/M first-match",
2497 SHOW_STR
2498 IPV6_STR
2499 PREFIX_LIST_STR
2500 "Name of a prefix list\n"
2501 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2502 "First matched prefix\n")
2503 {
2504 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
2505 }
2506
2507 DEFUN (show_ipv6_prefix_list_summary,
2508 show_ipv6_prefix_list_summary_cmd,
2509 "show ipv6 prefix-list summary",
2510 SHOW_STR
2511 IPV6_STR
2512 PREFIX_LIST_STR
2513 "Summary of prefix lists\n")
2514 {
2515 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
2516 }
2517
2518 DEFUN (show_ipv6_prefix_list_summary_name,
2519 show_ipv6_prefix_list_summary_name_cmd,
2520 "show ipv6 prefix-list summary WORD",
2521 SHOW_STR
2522 IPV6_STR
2523 PREFIX_LIST_STR
2524 "Summary of prefix lists\n"
2525 "Name of a prefix list\n")
2526 {
2527 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
2528 }
2529
2530 DEFUN (show_ipv6_prefix_list_detail,
2531 show_ipv6_prefix_list_detail_cmd,
2532 "show ipv6 prefix-list detail",
2533 SHOW_STR
2534 IPV6_STR
2535 PREFIX_LIST_STR
2536 "Detail of prefix lists\n")
2537 {
2538 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
2539 }
2540
2541 DEFUN (show_ipv6_prefix_list_detail_name,
2542 show_ipv6_prefix_list_detail_name_cmd,
2543 "show ipv6 prefix-list detail WORD",
2544 SHOW_STR
2545 IPV6_STR
2546 PREFIX_LIST_STR
2547 "Detail of prefix lists\n"
2548 "Name of a prefix list\n")
2549 {
2550 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
2551 }
2552
2553 DEFUN (clear_ipv6_prefix_list,
2554 clear_ipv6_prefix_list_cmd,
2555 "clear ipv6 prefix-list",
2556 CLEAR_STR
2557 IPV6_STR
2558 PREFIX_LIST_STR)
2559 {
2560 return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
2561 }
2562
2563 DEFUN (clear_ipv6_prefix_list_name,
2564 clear_ipv6_prefix_list_name_cmd,
2565 "clear ipv6 prefix-list WORD",
2566 CLEAR_STR
2567 IPV6_STR
2568 PREFIX_LIST_STR
2569 "Name of a prefix list\n")
2570 {
2571 return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
2572 }
2573
2574 DEFUN (clear_ipv6_prefix_list_name_prefix,
2575 clear_ipv6_prefix_list_name_prefix_cmd,
2576 "clear ipv6 prefix-list WORD X:X::X:X/M",
2577 CLEAR_STR
2578 IPV6_STR
2579 PREFIX_LIST_STR
2580 "Name of a prefix list\n"
2581 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2582 {
2583 return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
2584 }
2585 #endif /* HAVE_IPV6 */
2586
2587 /* Configuration write function. */
2588 static int
2589 config_write_prefix_afi (afi_t afi, struct vty *vty)
2590 {
2591 struct prefix_list *plist;
2592 struct prefix_list_entry *pentry;
2593 struct prefix_master *master;
2594 int write = 0;
2595
2596 master = prefix_master_get (afi, 0);
2597 if (master == NULL)
2598 return 0;
2599
2600 if (! master->seqnum)
2601 {
2602 vty_out (vty, "no ip%s prefix-list sequence-number%s",
2603 afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
2604 vty_out (vty, "!%s", VTY_NEWLINE);
2605 }
2606
2607 for (plist = master->num.head; plist; plist = plist->next)
2608 {
2609 if (plist->desc)
2610 {
2611 vty_out (vty, "ip%s prefix-list %s description %s%s",
2612 afi == AFI_IP ? "" : "v6",
2613 plist->name, plist->desc, VTY_NEWLINE);
2614 write++;
2615 }
2616
2617 for (pentry = plist->head; pentry; pentry = pentry->next)
2618 {
2619 vty_out (vty, "ip%s prefix-list %s ",
2620 afi == AFI_IP ? "" : "v6",
2621 plist->name);
2622
2623 if (master->seqnum)
2624 vty_out (vty, "seq %u ", pentry->seq);
2625
2626 vty_out (vty, "%s ", prefix_list_type_str (pentry));
2627
2628 if (pentry->any)
2629 vty_out (vty, "any");
2630 else
2631 {
2632 struct prefix *p = &pentry->prefix;
2633 char buf[BUFSIZ];
2634
2635 vty_out (vty, "%s/%d",
2636 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2637 p->prefixlen);
2638
2639 if (pentry->ge)
2640 vty_out (vty, " ge %d", pentry->ge);
2641 if (pentry->le)
2642 vty_out (vty, " le %d", pentry->le);
2643 }
2644 vty_out (vty, "%s", VTY_NEWLINE);
2645 write++;
2646 }
2647 /* vty_out (vty, "!%s", VTY_NEWLINE); */
2648 }
2649
2650 for (plist = master->str.head; plist; plist = plist->next)
2651 {
2652 if (plist->desc)
2653 {
2654 vty_out (vty, "ip%s prefix-list %s description %s%s",
2655 afi == AFI_IP ? "" : "v6",
2656 plist->name, plist->desc, VTY_NEWLINE);
2657 write++;
2658 }
2659
2660 for (pentry = plist->head; pentry; pentry = pentry->next)
2661 {
2662 vty_out (vty, "ip%s prefix-list %s ",
2663 afi == AFI_IP ? "" : "v6",
2664 plist->name);
2665
2666 if (master->seqnum)
2667 vty_out (vty, "seq %u ", pentry->seq);
2668
2669 vty_out (vty, "%s", prefix_list_type_str (pentry));
2670
2671 if (pentry->any)
2672 vty_out (vty, " any");
2673 else
2674 {
2675 struct prefix *p = &pentry->prefix;
2676 char buf[BUFSIZ];
2677
2678 vty_out (vty, " %s/%d",
2679 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2680 p->prefixlen);
2681
2682 if (pentry->ge)
2683 vty_out (vty, " ge %d", pentry->ge);
2684 if (pentry->le)
2685 vty_out (vty, " le %d", pentry->le);
2686 }
2687 vty_out (vty, "%s", VTY_NEWLINE);
2688 write++;
2689 }
2690 }
2691
2692 return write;
2693 }
2694
2695 struct stream *
2696 prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
2697 u_char init_flag, u_char permit_flag, u_char deny_flag)
2698 {
2699 struct prefix_list_entry *pentry;
2700
2701 if (! plist)
2702 return s;
2703
2704 for (pentry = plist->head; pentry; pentry = pentry->next)
2705 {
2706 u_char flag = init_flag;
2707 struct prefix *p = &pentry->prefix;
2708
2709 flag |= (pentry->type == PREFIX_PERMIT ?
2710 permit_flag : deny_flag);
2711 stream_putc (s, flag);
2712 stream_putl (s, (u_int32_t)pentry->seq);
2713 stream_putc (s, (u_char)pentry->ge);
2714 stream_putc (s, (u_char)pentry->le);
2715 stream_put_prefix (s, p);
2716 }
2717
2718 return s;
2719 }
2720
2721 int
2722 prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
2723 int permit, int set)
2724 {
2725 struct prefix_list *plist;
2726 struct prefix_list_entry *pentry;
2727
2728 /* ge and le value check */
2729 if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
2730 return CMD_WARNING;
2731 if (orfp->le && orfp->le <= orfp->p.prefixlen)
2732 return CMD_WARNING;
2733 if (orfp->le && orfp->ge > orfp->le)
2734 return CMD_WARNING;
2735
2736 if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
2737 orfp->le = 0;
2738
2739 plist = prefix_list_get (afi, 1, name);
2740 if (! plist)
2741 return CMD_WARNING;
2742
2743 if (set)
2744 {
2745 pentry = prefix_list_entry_make (&orfp->p,
2746 (permit ? PREFIX_PERMIT : PREFIX_DENY),
2747 orfp->seq, orfp->le, orfp->ge, 0);
2748
2749 if (prefix_entry_dup_check (plist, pentry))
2750 {
2751 prefix_list_entry_free (pentry);
2752 return CMD_WARNING;
2753 }
2754
2755 prefix_list_entry_add (plist, pentry);
2756 }
2757 else
2758 {
2759 pentry = prefix_list_entry_lookup (plist, &orfp->p,
2760 (permit ? PREFIX_PERMIT : PREFIX_DENY),
2761 orfp->seq, orfp->le, orfp->ge);
2762
2763 if (! pentry)
2764 return CMD_WARNING;
2765
2766 prefix_list_entry_delete (plist, pentry, 1);
2767 }
2768
2769 return CMD_SUCCESS;
2770 }
2771
2772 void
2773 prefix_bgp_orf_remove_all (afi_t afi, char *name)
2774 {
2775 struct prefix_list *plist;
2776
2777 plist = prefix_bgp_orf_lookup (afi, name);
2778 if (plist)
2779 prefix_list_delete (plist);
2780 }
2781
2782 /* return prefix count */
2783 int
2784 prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name, u_char use_json)
2785 {
2786 struct prefix_list *plist;
2787 struct prefix_list_entry *pentry;
2788 json_object *json = NULL;
2789 json_object *json_prefix = NULL;
2790 json_object *json_list = NULL;
2791
2792 plist = prefix_bgp_orf_lookup (afi, name);
2793 if (! plist)
2794 return 0;
2795
2796 if (! vty)
2797 return plist->count;
2798
2799 if(use_json)
2800 {
2801 json = json_object_new_object();
2802 json_prefix = json_object_new_object();
2803 json_list = json_object_new_object();
2804
2805 json_object_int_add(json_prefix, "prefixListCounter", plist->count);
2806 json_object_string_add(json_prefix, "prefixListName", plist->name);
2807
2808 for (pentry = plist->head; pentry; pentry = pentry->next)
2809 {
2810 struct prefix *p = &pentry->prefix;
2811 char buf_a[BUFSIZ];
2812 char buf_b[BUFSIZ];
2813
2814 sprintf(buf_a, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf_b, BUFSIZ),
2815 p->prefixlen);
2816
2817 json_object_int_add(json_list, "seq", pentry->seq);
2818 json_object_string_add(json_list, "seqPrefixListType", prefix_list_type_str (pentry));
2819
2820 if (pentry->ge)
2821 json_object_int_add(json_list, "ge", pentry->ge);
2822 if (pentry->le)
2823 json_object_int_add(json_list, "le", pentry->le);
2824
2825 json_object_object_add(json_prefix, buf_a, json_list);
2826 }
2827 if (afi == AFI_IP)
2828 json_object_object_add(json, "ipPrefixList", json_prefix);
2829 else
2830 json_object_object_add(json, "ipv6PrefixList", json_prefix);
2831
2832 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
2833 json_object_free(json);
2834 }
2835 else
2836 {
2837 vty_out (vty, "ip%s prefix-list %s: %d entries%s",
2838 afi == AFI_IP ? "" : "v6",
2839 plist->name, plist->count, VTY_NEWLINE);
2840
2841 for (pentry = plist->head; pentry; pentry = pentry->next)
2842 {
2843 struct prefix *p = &pentry->prefix;
2844 char buf[BUFSIZ];
2845
2846 vty_out (vty, " seq %u %s %s/%d", pentry->seq,
2847 prefix_list_type_str (pentry),
2848 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2849 p->prefixlen);
2850
2851 if (pentry->ge)
2852 vty_out (vty, " ge %d", pentry->ge);
2853 if (pentry->le)
2854 vty_out (vty, " le %d", pentry->le);
2855
2856 vty_out (vty, "%s", VTY_NEWLINE);
2857 }
2858 }
2859 return plist->count;
2860 }
2861
2862 static void
2863 prefix_list_reset_afi (afi_t afi, int orf)
2864 {
2865 struct prefix_list *plist;
2866 struct prefix_list *next;
2867 struct prefix_master *master;
2868
2869 master = prefix_master_get (afi, orf);
2870 if (master == NULL)
2871 return;
2872
2873 for (plist = master->num.head; plist; plist = next)
2874 {
2875 next = plist->next;
2876 prefix_list_delete (plist);
2877 }
2878 for (plist = master->str.head; plist; plist = next)
2879 {
2880 next = plist->next;
2881 prefix_list_delete (plist);
2882 }
2883
2884 assert (master->num.head == NULL);
2885 assert (master->num.tail == NULL);
2886
2887 assert (master->str.head == NULL);
2888 assert (master->str.tail == NULL);
2889
2890 master->seqnum = 1;
2891 master->recent = NULL;
2892 }
2893
2894
2895 /* Prefix-list node. */
2896 static struct cmd_node prefix_node =
2897 {
2898 PREFIX_NODE,
2899 "", /* Prefix list has no interface. */
2900 1
2901 };
2902
2903 static int
2904 config_write_prefix_ipv4 (struct vty *vty)
2905 {
2906 return config_write_prefix_afi (AFI_IP, vty);
2907 }
2908
2909 static void
2910 prefix_list_init_ipv4 (void)
2911 {
2912 install_node (&prefix_node, config_write_prefix_ipv4);
2913
2914 install_element (CONFIG_NODE, &ip_prefix_list_cmd);
2915 install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
2916 install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
2917 install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
2918 install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
2919 install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
2920 install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
2921 install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
2922 install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
2923 install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
2924
2925 install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
2926 install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
2927 install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
2928 install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
2929 install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
2930 install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
2931 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
2932 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
2933 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
2934 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
2935 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
2936
2937 install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
2938 install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
2939 install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
2940
2941 install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
2942 install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
2943
2944 install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
2945 install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
2946 install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
2947 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
2948 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
2949 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
2950 install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
2951 install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
2952 install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
2953 install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
2954
2955 install_element (ENABLE_NODE, &show_ip_prefix_list_cmd);
2956 install_element (ENABLE_NODE, &show_ip_prefix_list_name_cmd);
2957 install_element (ENABLE_NODE, &show_ip_prefix_list_name_seq_cmd);
2958 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_cmd);
2959 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_longer_cmd);
2960 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
2961 install_element (ENABLE_NODE, &show_ip_prefix_list_summary_cmd);
2962 install_element (ENABLE_NODE, &show_ip_prefix_list_summary_name_cmd);
2963 install_element (ENABLE_NODE, &show_ip_prefix_list_detail_cmd);
2964 install_element (ENABLE_NODE, &show_ip_prefix_list_detail_name_cmd);
2965
2966 install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
2967 install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
2968 install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
2969 }
2970
2971 #ifdef HAVE_IPV6
2972 /* Prefix-list node. */
2973 static struct cmd_node prefix_ipv6_node =
2974 {
2975 PREFIX_IPV6_NODE,
2976 "", /* Prefix list has no interface. */
2977 1
2978 };
2979
2980 static int
2981 config_write_prefix_ipv6 (struct vty *vty)
2982 {
2983 return config_write_prefix_afi (AFI_IP6, vty);
2984 }
2985
2986 static void
2987 prefix_list_init_ipv6 (void)
2988 {
2989 install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
2990
2991 install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
2992 install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
2993 install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
2994 install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
2995 install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
2996 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
2997 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
2998 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
2999 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
3000 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
3001
3002 install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
3003 install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
3004 install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
3005 install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
3006 install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
3007 install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
3008 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
3009 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
3010 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
3011 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
3012 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
3013
3014 install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
3015 install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
3016 install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
3017
3018 install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
3019 install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
3020
3021 install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
3022 install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
3023 install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
3024 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
3025 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
3026 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
3027 install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
3028 install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
3029 install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
3030 install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
3031
3032 install_element (ENABLE_NODE, &show_ipv6_prefix_list_cmd);
3033 install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_cmd);
3034 install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_seq_cmd);
3035 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_cmd);
3036 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
3037 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
3038 install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd);
3039 install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_name_cmd);
3040 install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd);
3041 install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_name_cmd);
3042
3043 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
3044 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
3045 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
3046 }
3047 #endif /* HAVE_IPV6 */
3048
3049 void
3050 prefix_list_init ()
3051 {
3052 prefix_list_init_ipv4 ();
3053 #ifdef HAVE_IPV6
3054 prefix_list_init_ipv6 ();
3055 #endif /* HAVE_IPV6 */
3056 }
3057
3058 void
3059 prefix_list_reset ()
3060 {
3061 prefix_list_reset_afi (AFI_IP, 0);
3062 prefix_list_reset_afi (AFI_IP6, 0);
3063 prefix_list_reset_afi (AFI_IP, 1);
3064 prefix_list_reset_afi (AFI_IP6, 1);
3065 }