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