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