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