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