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