blob: f9e626d8beb7af2973d8c4bac99bfcf14b341aed [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. */
701 if (afi == AFI_IP)
702 {
703 if (strncmp ("any", prefix, strlen (prefix)) == 0)
704 {
705 ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
706 genum = 0;
707 lenum = IPV4_MAX_BITLEN;
708 any = 1;
709 }
710 else
711 ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
712
713 if (ret <= 0)
714 {
715 vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
716 return CMD_WARNING;
717 }
718 }
719#ifdef HAVE_IPV6
720 else if (afi == AFI_IP6)
721 {
722 if (strncmp ("any", prefix, strlen (prefix)) == 0)
723 {
724 ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
725 genum = 0;
726 lenum = IPV6_MAX_BITLEN;
727 any = 1;
728 }
729 else
730 ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
731
732 if (ret <= 0)
733 {
734 vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
735 return CMD_WARNING;
736 }
737 }
738#endif /* HAVE_IPV6 */
739
740 /* ge and le check. */
Paul Jakma18f420e2014-09-19 16:55:46 +0100741 if (genum && (genum <= p.prefixlen))
paul718e3742002-12-13 20:15:29 +0000742 return vty_invalid_prefix_range (vty, prefix);
743
Paul Jakma18f420e2014-09-19 16:55:46 +0100744 if (lenum && (lenum <= p.prefixlen))
paul718e3742002-12-13 20:15:29 +0000745 return vty_invalid_prefix_range (vty, prefix);
746
Paul Jakma18f420e2014-09-19 16:55:46 +0100747 if (lenum && (genum > lenum))
paul718e3742002-12-13 20:15:29 +0000748 return vty_invalid_prefix_range (vty, prefix);
749
Paul Jakma18f420e2014-09-19 16:55:46 +0100750 if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
paul718e3742002-12-13 20:15:29 +0000751 lenum = 0;
752
753 /* Get prefix_list with name. */
David Lamparterc9c06d02015-04-13 10:21:35 +0200754 plist = prefix_list_get (afi, 0, name);
paul718e3742002-12-13 20:15:29 +0000755
756 /* Make prefix entry. */
757 pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
758
759 /* Check same policy. */
760 dup = prefix_entry_dup_check (plist, pentry);
761
762 if (dup)
763 {
764 prefix_list_entry_free (pentry);
765 vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
766 VTY_NEWLINE);
767 vty_out (vty, " seq %d %s %s", dup->seq, typestr, prefix);
768 if (! any && genum)
769 vty_out (vty, " ge %d", genum);
770 if (! any && lenum)
771 vty_out (vty, " le %d", lenum);
772 vty_out (vty, "%s", VTY_NEWLINE);
773 return CMD_WARNING;
774 }
775
776 /* Install new filter to the access_list. */
777 prefix_list_entry_add (plist, pentry);
778
779 return CMD_SUCCESS;
780}
781
paul02ff83c2004-06-11 11:27:03 +0000782static int
paul9035efa2004-10-10 11:56:56 +0000783vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
784 const char *seq, const char *typestr,
785 const char *prefix, const char *ge, const char *le)
paul718e3742002-12-13 20:15:29 +0000786{
787 int ret;
788 enum prefix_list_type type;
789 struct prefix_list *plist;
790 struct prefix_list_entry *pentry;
791 struct prefix p;
792 int seqnum = -1;
793 int lenum = 0;
794 int genum = 0;
795
796 /* Check prefix list name. */
797 plist = prefix_list_lookup (afi, name);
798 if (! plist)
799 {
800 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
801 return CMD_WARNING;
802 }
803
804 /* Only prefix-list name specified, delete the entire prefix-list. */
805 if (seq == NULL && typestr == NULL && prefix == NULL &&
806 ge == NULL && le == NULL)
807 {
808 prefix_list_delete (plist);
809 return CMD_SUCCESS;
810 }
811
Paul Jakma9376c342006-05-12 23:17:38 +0000812 /* We must have, at a minimum, both the type and prefix here */
813 if ((typestr == NULL) || (prefix == NULL))
814 {
815 vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
816 return CMD_WARNING;
817 }
818
paul718e3742002-12-13 20:15:29 +0000819 /* Check sequence number. */
820 if (seq)
821 seqnum = atoi (seq);
822
823 /* ge and le number */
824 if (ge)
825 genum = atoi (ge);
826 if (le)
827 lenum = atoi (le);
828
829 /* Check of filter type. */
830 if (strncmp ("permit", typestr, 1) == 0)
831 type = PREFIX_PERMIT;
832 else if (strncmp ("deny", typestr, 1) == 0)
833 type = PREFIX_DENY;
834 else
835 {
836 vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
837 return CMD_WARNING;
838 }
839
840 /* "any" is special token for matching any IPv4 addresses. */
841 if (afi == AFI_IP)
842 {
843 if (strncmp ("any", prefix, strlen (prefix)) == 0)
844 {
845 ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
846 genum = 0;
847 lenum = IPV4_MAX_BITLEN;
848 }
849 else
850 ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
851
852 if (ret <= 0)
853 {
854 vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
855 return CMD_WARNING;
856 }
857 }
858#ifdef HAVE_IPV6
859 else if (afi == AFI_IP6)
860 {
861 if (strncmp ("any", prefix, strlen (prefix)) == 0)
862 {
863 ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
864 genum = 0;
865 lenum = IPV6_MAX_BITLEN;
866 }
867 else
868 ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
869
870 if (ret <= 0)
871 {
872 vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
873 return CMD_WARNING;
874 }
875 }
876#endif /* HAVE_IPV6 */
877
878 /* Lookup prefix entry. */
879 pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
880
881 if (pentry == NULL)
882 {
883 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
884 return CMD_WARNING;
885 }
886
887 /* Install new filter to the access_list. */
888 prefix_list_entry_delete (plist, pentry, 1);
889
890 return CMD_SUCCESS;
891}
892
paul02ff83c2004-06-11 11:27:03 +0000893static int
paul9035efa2004-10-10 11:56:56 +0000894vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
paul718e3742002-12-13 20:15:29 +0000895{
896 struct prefix_list *plist;
897
898 plist = prefix_list_lookup (afi, name);
899 if (! plist)
900 {
901 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
902 return CMD_WARNING;
903 }
904
905 if (plist->desc)
906 {
907 XFREE (MTYPE_TMP, plist->desc);
908 plist->desc = NULL;
909 }
910
911 if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
912 prefix_list_delete (plist);
913
914 return CMD_SUCCESS;
915}
916
917enum display_type
918{
919 normal_display,
920 summary_display,
921 detail_display,
922 sequential_display,
923 longer_display,
924 first_match_display
925};
926
paul02ff83c2004-06-11 11:27:03 +0000927static void
paul718e3742002-12-13 20:15:29 +0000928vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
929 struct prefix_master *master, enum display_type dtype,
930 int seqnum)
931{
932 struct prefix_list_entry *pentry;
933
vincentfbf5d032005-09-29 11:25:50 +0000934 /* Print the name of the protocol */
935 if (zlog_default)
936 vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
937
paul718e3742002-12-13 20:15:29 +0000938 if (dtype == normal_display)
939 {
940 vty_out (vty, "ip%s prefix-list %s: %d entries%s",
941 afi == AFI_IP ? "" : "v6",
942 plist->name, plist->count, VTY_NEWLINE);
943 if (plist->desc)
944 vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
945 }
946 else if (dtype == summary_display || dtype == detail_display)
947 {
948 vty_out (vty, "ip%s prefix-list %s:%s",
949 afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
950
951 if (plist->desc)
952 vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
953
954 vty_out (vty, " count: %d, range entries: %d, sequences: %d - %d%s",
955 plist->count, plist->rangecount,
956 plist->head ? plist->head->seq : 0,
957 plist->tail ? plist->tail->seq : 0,
958 VTY_NEWLINE);
959 }
960
961 if (dtype != summary_display)
962 {
963 for (pentry = plist->head; pentry; pentry = pentry->next)
964 {
965 if (dtype == sequential_display && pentry->seq != seqnum)
966 continue;
967
968 vty_out (vty, " ");
969
970 if (master->seqnum)
971 vty_out (vty, "seq %d ", pentry->seq);
972
973 vty_out (vty, "%s ", prefix_list_type_str (pentry));
974
975 if (pentry->any)
976 vty_out (vty, "any");
977 else
978 {
979 struct prefix *p = &pentry->prefix;
980 char buf[BUFSIZ];
981
982 vty_out (vty, "%s/%d",
983 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
984 p->prefixlen);
985
986 if (pentry->ge)
987 vty_out (vty, " ge %d", pentry->ge);
988 if (pentry->le)
989 vty_out (vty, " le %d", pentry->le);
990 }
991
992 if (dtype == detail_display || dtype == sequential_display)
993 vty_out (vty, " (hit count: %ld, refcount: %ld)",
994 pentry->hitcnt, pentry->refcnt);
995
996 vty_out (vty, "%s", VTY_NEWLINE);
997 }
998 }
999}
1000
paul02ff83c2004-06-11 11:27:03 +00001001static int
paul9035efa2004-10-10 11:56:56 +00001002vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
1003 const char *seq, enum display_type dtype)
paul718e3742002-12-13 20:15:29 +00001004{
1005 struct prefix_list *plist;
1006 struct prefix_master *master;
1007 int seqnum = 0;
1008
David Lamparterc9c06d02015-04-13 10:21:35 +02001009 master = prefix_master_get (afi, 0);
paul718e3742002-12-13 20:15:29 +00001010 if (master == NULL)
1011 return CMD_WARNING;
1012
1013 if (seq)
1014 seqnum = atoi (seq);
1015
1016 if (name)
1017 {
1018 plist = prefix_list_lookup (afi, name);
1019 if (! plist)
1020 {
1021 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1022 return CMD_WARNING;
1023 }
1024 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1025 }
1026 else
1027 {
1028 if (dtype == detail_display || dtype == summary_display)
1029 {
1030 if (master->recent)
1031 vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
1032 master->recent->name, VTY_NEWLINE);
1033 }
1034
1035 for (plist = master->num.head; plist; plist = plist->next)
1036 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1037
1038 for (plist = master->str.head; plist; plist = plist->next)
1039 vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
1040 }
1041
1042 return CMD_SUCCESS;
1043}
1044
paul02ff83c2004-06-11 11:27:03 +00001045static int
paul9035efa2004-10-10 11:56:56 +00001046vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
1047 const char *prefix, enum display_type type)
paul718e3742002-12-13 20:15:29 +00001048{
1049 struct prefix_list *plist;
1050 struct prefix_list_entry *pentry;
1051 struct prefix p;
1052 int ret;
1053 int match;
1054
1055 plist = prefix_list_lookup (afi, name);
1056 if (! plist)
1057 {
1058 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1059 return CMD_WARNING;
1060 }
1061
1062 ret = str2prefix (prefix, &p);
1063 if (ret <= 0)
1064 {
1065 vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
1066 return CMD_WARNING;
1067 }
1068
1069 for (pentry = plist->head; pentry; pentry = pentry->next)
1070 {
1071 match = 0;
1072
1073 if (type == normal_display || type == first_match_display)
1074 if (prefix_same (&p, &pentry->prefix))
1075 match = 1;
1076
1077 if (type == longer_display)
1078 if (prefix_match (&p, &pentry->prefix))
1079 match = 1;
1080
1081 if (match)
1082 {
1083 vty_out (vty, " seq %d %s ",
1084 pentry->seq,
1085 prefix_list_type_str (pentry));
1086
1087 if (pentry->any)
1088 vty_out (vty, "any");
1089 else
1090 {
1091 struct prefix *p = &pentry->prefix;
1092 char buf[BUFSIZ];
1093
1094 vty_out (vty, "%s/%d",
1095 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1096 p->prefixlen);
1097
1098 if (pentry->ge)
1099 vty_out (vty, " ge %d", pentry->ge);
1100 if (pentry->le)
1101 vty_out (vty, " le %d", pentry->le);
1102 }
1103
1104 if (type == normal_display || type == first_match_display)
1105 vty_out (vty, " (hit count: %ld, refcount: %ld)",
1106 pentry->hitcnt, pentry->refcnt);
1107
1108 vty_out (vty, "%s", VTY_NEWLINE);
1109
1110 if (type == first_match_display)
1111 return CMD_SUCCESS;
1112 }
1113 }
1114 return CMD_SUCCESS;
1115}
1116
paul02ff83c2004-06-11 11:27:03 +00001117static int
paul9035efa2004-10-10 11:56:56 +00001118vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
1119 const char *prefix)
paul718e3742002-12-13 20:15:29 +00001120{
1121 struct prefix_master *master;
1122 struct prefix_list *plist;
1123 struct prefix_list_entry *pentry;
1124 int ret;
1125 struct prefix p;
1126
David Lamparterc9c06d02015-04-13 10:21:35 +02001127 master = prefix_master_get (afi, 0);
paul718e3742002-12-13 20:15:29 +00001128 if (master == NULL)
1129 return CMD_WARNING;
1130
1131 if (name == NULL && prefix == NULL)
1132 {
1133 for (plist = master->num.head; plist; plist = plist->next)
1134 for (pentry = plist->head; pentry; pentry = pentry->next)
1135 pentry->hitcnt = 0;
1136
1137 for (plist = master->str.head; plist; plist = plist->next)
1138 for (pentry = plist->head; pentry; pentry = pentry->next)
1139 pentry->hitcnt = 0;
1140 }
1141 else
1142 {
1143 plist = prefix_list_lookup (afi, name);
1144 if (! plist)
1145 {
1146 vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
1147 return CMD_WARNING;
1148 }
1149
1150 if (prefix)
1151 {
1152 ret = str2prefix (prefix, &p);
1153 if (ret <= 0)
1154 {
1155 vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
1156 return CMD_WARNING;
1157 }
1158 }
1159
1160 for (pentry = plist->head; pentry; pentry = pentry->next)
1161 {
1162 if (prefix)
1163 {
1164 if (prefix_match (&pentry->prefix, &p))
1165 pentry->hitcnt = 0;
1166 }
1167 else
1168 pentry->hitcnt = 0;
1169 }
1170 }
1171 return CMD_SUCCESS;
1172}
David Lamparter6b0655a2014-06-04 06:53:35 +02001173
paul718e3742002-12-13 20:15:29 +00001174DEFUN (ip_prefix_list,
1175 ip_prefix_list_cmd,
1176 "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
1177 IP_STR
1178 PREFIX_LIST_STR
1179 "Name of a prefix list\n"
1180 "Specify packets to reject\n"
1181 "Specify packets to forward\n"
1182 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1183 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1184{
1185 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
1186 argv[1], argv[2], NULL, NULL);
1187}
1188
1189DEFUN (ip_prefix_list_ge,
1190 ip_prefix_list_ge_cmd,
1191 "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
1192 IP_STR
1193 PREFIX_LIST_STR
1194 "Name of a prefix list\n"
1195 "Specify packets to reject\n"
1196 "Specify packets to forward\n"
1197 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1198 "Minimum prefix length to be matched\n"
1199 "Minimum prefix length\n")
1200{
1201 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1202 argv[2], argv[3], NULL);
1203}
1204
1205DEFUN (ip_prefix_list_ge_le,
1206 ip_prefix_list_ge_le_cmd,
1207 "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> 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 "Minimum prefix length to be matched\n"
1215 "Minimum prefix length\n"
1216 "Maximum prefix length to be matched\n"
1217 "Maximum prefix length\n")
1218{
1219 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1220 argv[2], argv[3], argv[4]);
1221}
1222
1223DEFUN (ip_prefix_list_le,
1224 ip_prefix_list_le_cmd,
1225 "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
1226 IP_STR
1227 PREFIX_LIST_STR
1228 "Name of a prefix list\n"
1229 "Specify packets to reject\n"
1230 "Specify packets to forward\n"
1231 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1232 "Maximum prefix length to be matched\n"
1233 "Maximum prefix length\n")
1234{
1235 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1236 argv[2], NULL, argv[3]);
1237}
1238
1239DEFUN (ip_prefix_list_le_ge,
1240 ip_prefix_list_le_ge_cmd,
1241 "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1242 IP_STR
1243 PREFIX_LIST_STR
1244 "Name of a prefix list\n"
1245 "Specify packets to reject\n"
1246 "Specify packets to forward\n"
1247 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1248 "Maximum prefix length to be matched\n"
1249 "Maximum prefix length\n"
1250 "Minimum prefix length to be matched\n"
1251 "Minimum prefix length\n")
1252{
1253 return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
1254 argv[2], argv[4], argv[3]);
1255}
1256
1257DEFUN (ip_prefix_list_seq,
1258 ip_prefix_list_seq_cmd,
1259 "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
1260 IP_STR
1261 PREFIX_LIST_STR
1262 "Name of a prefix list\n"
1263 "sequence number of an entry\n"
1264 "Sequence number\n"
1265 "Specify packets to reject\n"
1266 "Specify packets to forward\n"
1267 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1268 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1269{
1270 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1271 argv[3], NULL, NULL);
1272}
1273
1274DEFUN (ip_prefix_list_seq_ge,
1275 ip_prefix_list_seq_ge_cmd,
1276 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <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{
1288 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1289 argv[3], argv[4], NULL);
1290}
1291
1292DEFUN (ip_prefix_list_seq_ge_le,
1293 ip_prefix_list_seq_ge_le_cmd,
1294 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1295 IP_STR
1296 PREFIX_LIST_STR
1297 "Name of a prefix list\n"
1298 "sequence number of an entry\n"
1299 "Sequence number\n"
1300 "Specify packets to reject\n"
1301 "Specify packets to forward\n"
1302 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1303 "Minimum prefix length to be matched\n"
1304 "Minimum prefix length\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], argv[4], argv[5]);
1310}
1311
1312DEFUN (ip_prefix_list_seq_le,
1313 ip_prefix_list_seq_le_cmd,
1314 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <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{
1326 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1327 argv[3], NULL, argv[4]);
1328}
1329
1330DEFUN (ip_prefix_list_seq_le_ge,
1331 ip_prefix_list_seq_le_ge_cmd,
1332 "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1333 IP_STR
1334 PREFIX_LIST_STR
1335 "Name of a prefix list\n"
1336 "sequence number of an entry\n"
1337 "Sequence number\n"
1338 "Specify packets to reject\n"
1339 "Specify packets to forward\n"
1340 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1341 "Maximum prefix length to be matched\n"
1342 "Maximum prefix length\n"
1343 "Minimum prefix length to be matched\n"
1344 "Minimum prefix length\n")
1345{
1346 return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
1347 argv[3], argv[5], argv[4]);
1348}
1349
1350DEFUN (no_ip_prefix_list,
1351 no_ip_prefix_list_cmd,
1352 "no ip prefix-list WORD",
1353 NO_STR
1354 IP_STR
1355 PREFIX_LIST_STR
1356 "Name of a prefix list\n")
1357{
1358 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
1359 NULL, NULL, NULL);
1360}
1361
1362DEFUN (no_ip_prefix_list_prefix,
1363 no_ip_prefix_list_prefix_cmd,
1364 "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
1365 NO_STR
1366 IP_STR
1367 PREFIX_LIST_STR
1368 "Name of a prefix list\n"
1369 "Specify packets to reject\n"
1370 "Specify packets to forward\n"
1371 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1372 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1373{
1374 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1375 argv[2], NULL, NULL);
1376}
1377
1378DEFUN (no_ip_prefix_list_ge,
1379 no_ip_prefix_list_ge_cmd,
1380 "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
1381 NO_STR
1382 IP_STR
1383 PREFIX_LIST_STR
1384 "Name of a prefix list\n"
1385 "Specify packets to reject\n"
1386 "Specify packets to forward\n"
1387 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1388 "Minimum prefix length to be matched\n"
1389 "Minimum prefix length\n")
1390{
1391 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1392 argv[2], argv[3], NULL);
1393}
1394
1395DEFUN (no_ip_prefix_list_ge_le,
1396 no_ip_prefix_list_ge_le_cmd,
1397 "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1398 NO_STR
1399 IP_STR
1400 PREFIX_LIST_STR
1401 "Name of a prefix list\n"
1402 "Specify packets to reject\n"
1403 "Specify packets to forward\n"
1404 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1405 "Minimum prefix length to be matched\n"
1406 "Minimum prefix length\n"
1407 "Maximum prefix length to be matched\n"
1408 "Maximum prefix length\n")
1409{
1410 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1411 argv[2], argv[3], argv[4]);
1412}
1413
1414DEFUN (no_ip_prefix_list_le,
1415 no_ip_prefix_list_le_cmd,
1416 "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
1417 NO_STR
1418 IP_STR
1419 PREFIX_LIST_STR
1420 "Name of a prefix list\n"
1421 "Specify packets to reject\n"
1422 "Specify packets to forward\n"
1423 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1424 "Maximum prefix length to be matched\n"
1425 "Maximum prefix length\n")
1426{
1427 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1428 argv[2], NULL, argv[3]);
1429}
1430
1431DEFUN (no_ip_prefix_list_le_ge,
1432 no_ip_prefix_list_le_ge_cmd,
1433 "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1434 NO_STR
1435 IP_STR
1436 PREFIX_LIST_STR
1437 "Name of a prefix list\n"
1438 "Specify packets to reject\n"
1439 "Specify packets to forward\n"
1440 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1441 "Maximum prefix length to be matched\n"
1442 "Maximum prefix length\n"
1443 "Minimum prefix length to be matched\n"
1444 "Minimum prefix length\n")
1445{
1446 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
1447 argv[2], argv[4], argv[3]);
1448}
1449
1450DEFUN (no_ip_prefix_list_seq,
1451 no_ip_prefix_list_seq_cmd,
1452 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
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 "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
1463{
1464 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1465 argv[3], NULL, NULL);
1466}
1467
1468DEFUN (no_ip_prefix_list_seq_ge,
1469 no_ip_prefix_list_seq_ge_cmd,
1470 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
1471 NO_STR
1472 IP_STR
1473 PREFIX_LIST_STR
1474 "Name of a prefix list\n"
1475 "sequence number of an entry\n"
1476 "Sequence number\n"
1477 "Specify packets to reject\n"
1478 "Specify packets to forward\n"
1479 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1480 "Minimum prefix length to be matched\n"
1481 "Minimum prefix length\n")
1482{
1483 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1484 argv[3], argv[4], NULL);
1485}
1486
1487DEFUN (no_ip_prefix_list_seq_ge_le,
1488 no_ip_prefix_list_seq_ge_le_cmd,
1489 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
1490 NO_STR
1491 IP_STR
1492 PREFIX_LIST_STR
1493 "Name of a prefix list\n"
1494 "sequence number of an entry\n"
1495 "Sequence number\n"
1496 "Specify packets to reject\n"
1497 "Specify packets to forward\n"
1498 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1499 "Minimum prefix length to be matched\n"
1500 "Minimum prefix length\n"
1501 "Maximum prefix length to be matched\n"
1502 "Maximum prefix length\n")
1503{
1504 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1505 argv[3], argv[4], argv[5]);
1506}
1507
1508DEFUN (no_ip_prefix_list_seq_le,
1509 no_ip_prefix_list_seq_le_cmd,
1510 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
1511 NO_STR
1512 IP_STR
1513 PREFIX_LIST_STR
1514 "Name of a prefix list\n"
1515 "sequence number of an entry\n"
1516 "Sequence number\n"
1517 "Specify packets to reject\n"
1518 "Specify packets to forward\n"
1519 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1520 "Maximum prefix length to be matched\n"
1521 "Maximum prefix length\n")
1522{
1523 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1524 argv[3], NULL, argv[4]);
1525}
1526
1527DEFUN (no_ip_prefix_list_seq_le_ge,
1528 no_ip_prefix_list_seq_le_ge_cmd,
1529 "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
1530 NO_STR
1531 IP_STR
1532 PREFIX_LIST_STR
1533 "Name of a prefix list\n"
1534 "sequence number of an entry\n"
1535 "Sequence number\n"
1536 "Specify packets to reject\n"
1537 "Specify packets to forward\n"
1538 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1539 "Maximum prefix length to be matched\n"
1540 "Maximum prefix length\n"
1541 "Minimum prefix length to be matched\n"
1542 "Minimum prefix length\n")
1543{
1544 return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
1545 argv[3], argv[5], argv[4]);
1546}
1547
1548DEFUN (ip_prefix_list_sequence_number,
1549 ip_prefix_list_sequence_number_cmd,
1550 "ip prefix-list sequence-number",
1551 IP_STR
1552 PREFIX_LIST_STR
1553 "Include/exclude sequence numbers in NVGEN\n")
1554{
1555 prefix_master_ipv4.seqnum = 1;
1556 return CMD_SUCCESS;
1557}
1558
1559DEFUN (no_ip_prefix_list_sequence_number,
1560 no_ip_prefix_list_sequence_number_cmd,
1561 "no ip prefix-list sequence-number",
1562 NO_STR
1563 IP_STR
1564 PREFIX_LIST_STR
1565 "Include/exclude sequence numbers in NVGEN\n")
1566{
1567 prefix_master_ipv4.seqnum = 0;
1568 return CMD_SUCCESS;
1569}
1570
1571DEFUN (ip_prefix_list_description,
1572 ip_prefix_list_description_cmd,
1573 "ip prefix-list WORD description .LINE",
1574 IP_STR
1575 PREFIX_LIST_STR
1576 "Name of a prefix list\n"
1577 "Prefix-list specific description\n"
1578 "Up to 80 characters describing this prefix-list\n")
1579{
1580 struct prefix_list *plist;
paul718e3742002-12-13 20:15:29 +00001581
David Lamparterc9c06d02015-04-13 10:21:35 +02001582 plist = prefix_list_get (AFI_IP, 0, argv[0]);
paul718e3742002-12-13 20:15:29 +00001583
1584 if (plist->desc)
1585 {
1586 XFREE (MTYPE_TMP, plist->desc);
1587 plist->desc = NULL;
1588 }
ajs3b8b1852005-01-29 18:19:13 +00001589 plist->desc = argv_concat(argv, argc, 1);
paul718e3742002-12-13 20:15:29 +00001590
1591 return CMD_SUCCESS;
1592}
1593
1594DEFUN (no_ip_prefix_list_description,
1595 no_ip_prefix_list_description_cmd,
1596 "no ip prefix-list WORD description",
1597 NO_STR
1598 IP_STR
1599 PREFIX_LIST_STR
1600 "Name of a prefix list\n"
1601 "Prefix-list specific description\n")
1602{
1603 return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
1604}
1605
1606ALIAS (no_ip_prefix_list_description,
1607 no_ip_prefix_list_description_arg_cmd,
1608 "no ip prefix-list WORD description .LINE",
1609 NO_STR
1610 IP_STR
1611 PREFIX_LIST_STR
1612 "Name of a prefix list\n"
1613 "Prefix-list specific description\n"
1614 "Up to 80 characters describing this prefix-list\n")
1615
1616DEFUN (show_ip_prefix_list,
1617 show_ip_prefix_list_cmd,
1618 "show ip prefix-list",
1619 SHOW_STR
1620 IP_STR
1621 PREFIX_LIST_STR)
1622{
1623 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
1624}
1625
1626DEFUN (show_ip_prefix_list_name,
1627 show_ip_prefix_list_name_cmd,
1628 "show ip prefix-list WORD",
1629 SHOW_STR
1630 IP_STR
1631 PREFIX_LIST_STR
1632 "Name of a prefix list\n")
1633{
1634 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
1635}
1636
1637DEFUN (show_ip_prefix_list_name_seq,
1638 show_ip_prefix_list_name_seq_cmd,
1639 "show ip prefix-list WORD seq <1-4294967295>",
1640 SHOW_STR
1641 IP_STR
1642 PREFIX_LIST_STR
1643 "Name of a prefix list\n"
1644 "sequence number of an entry\n"
1645 "Sequence number\n")
1646{
1647 return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
1648}
1649
1650DEFUN (show_ip_prefix_list_prefix,
1651 show_ip_prefix_list_prefix_cmd,
1652 "show ip prefix-list WORD A.B.C.D/M",
1653 SHOW_STR
1654 IP_STR
1655 PREFIX_LIST_STR
1656 "Name of a prefix list\n"
1657 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1658{
1659 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
1660}
1661
1662DEFUN (show_ip_prefix_list_prefix_longer,
1663 show_ip_prefix_list_prefix_longer_cmd,
1664 "show ip prefix-list WORD A.B.C.D/M longer",
1665 SHOW_STR
1666 IP_STR
1667 PREFIX_LIST_STR
1668 "Name of a prefix list\n"
1669 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1670 "Lookup longer prefix\n")
1671{
1672 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
1673}
1674
1675DEFUN (show_ip_prefix_list_prefix_first_match,
1676 show_ip_prefix_list_prefix_first_match_cmd,
1677 "show ip prefix-list WORD A.B.C.D/M first-match",
1678 SHOW_STR
1679 IP_STR
1680 PREFIX_LIST_STR
1681 "Name of a prefix list\n"
1682 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1683 "First matched prefix\n")
1684{
1685 return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
1686}
1687
1688DEFUN (show_ip_prefix_list_summary,
1689 show_ip_prefix_list_summary_cmd,
1690 "show ip prefix-list summary",
1691 SHOW_STR
1692 IP_STR
1693 PREFIX_LIST_STR
1694 "Summary of prefix lists\n")
1695{
1696 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
1697}
1698
1699DEFUN (show_ip_prefix_list_summary_name,
1700 show_ip_prefix_list_summary_name_cmd,
1701 "show ip prefix-list summary WORD",
1702 SHOW_STR
1703 IP_STR
1704 PREFIX_LIST_STR
1705 "Summary of prefix lists\n"
1706 "Name of a prefix list\n")
1707{
1708 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
1709}
1710
1711
1712DEFUN (show_ip_prefix_list_detail,
1713 show_ip_prefix_list_detail_cmd,
1714 "show ip prefix-list detail",
1715 SHOW_STR
1716 IP_STR
1717 PREFIX_LIST_STR
1718 "Detail of prefix lists\n")
1719{
1720 return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
1721}
1722
1723DEFUN (show_ip_prefix_list_detail_name,
1724 show_ip_prefix_list_detail_name_cmd,
1725 "show ip prefix-list detail WORD",
1726 SHOW_STR
1727 IP_STR
1728 PREFIX_LIST_STR
1729 "Detail of prefix lists\n"
1730 "Name of a prefix list\n")
1731{
1732 return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
1733}
1734
1735DEFUN (clear_ip_prefix_list,
1736 clear_ip_prefix_list_cmd,
1737 "clear ip prefix-list",
1738 CLEAR_STR
1739 IP_STR
1740 PREFIX_LIST_STR)
1741{
1742 return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
1743}
1744
1745DEFUN (clear_ip_prefix_list_name,
1746 clear_ip_prefix_list_name_cmd,
1747 "clear ip prefix-list WORD",
1748 CLEAR_STR
1749 IP_STR
1750 PREFIX_LIST_STR
1751 "Name of a prefix list\n")
1752{
1753 return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
1754}
1755
1756DEFUN (clear_ip_prefix_list_name_prefix,
1757 clear_ip_prefix_list_name_prefix_cmd,
1758 "clear ip prefix-list WORD A.B.C.D/M",
1759 CLEAR_STR
1760 IP_STR
1761 PREFIX_LIST_STR
1762 "Name of a prefix list\n"
1763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1764{
1765 return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
1766}
David Lamparter6b0655a2014-06-04 06:53:35 +02001767
paul718e3742002-12-13 20:15:29 +00001768#ifdef HAVE_IPV6
1769DEFUN (ipv6_prefix_list,
1770 ipv6_prefix_list_cmd,
1771 "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
1772 IPV6_STR
1773 PREFIX_LIST_STR
1774 "Name of a prefix list\n"
1775 "Specify packets to reject\n"
1776 "Specify packets to forward\n"
1777 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1778 "Any prefix match. Same as \"::0/0 le 128\"\n")
1779{
1780 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
1781 argv[1], argv[2], NULL, NULL);
1782}
1783
1784DEFUN (ipv6_prefix_list_ge,
1785 ipv6_prefix_list_ge_cmd,
1786 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
1787 IPV6_STR
1788 PREFIX_LIST_STR
1789 "Name of a prefix list\n"
1790 "Specify packets to reject\n"
1791 "Specify packets to forward\n"
1792 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1793 "Minimum prefix length to be matched\n"
1794 "Minimum prefix length\n")
1795{
1796 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
1797 argv[2], argv[3], NULL);
1798}
1799
1800DEFUN (ipv6_prefix_list_ge_le,
1801 ipv6_prefix_list_ge_le_cmd,
1802 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
1803 IPV6_STR
1804 PREFIX_LIST_STR
1805 "Name of a prefix list\n"
1806 "Specify packets to reject\n"
1807 "Specify packets to forward\n"
1808 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1809 "Minimum prefix length to be matched\n"
1810 "Minimum prefix length\n"
1811 "Maximum prefix length to be matched\n"
1812 "Maximum prefix length\n")
1813
1814{
1815 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
1816 argv[2], argv[3], argv[4]);
1817}
1818
1819DEFUN (ipv6_prefix_list_le,
1820 ipv6_prefix_list_le_cmd,
1821 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
1822 IPV6_STR
1823 PREFIX_LIST_STR
1824 "Name of a prefix list\n"
1825 "Specify packets to reject\n"
1826 "Specify packets to forward\n"
1827 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1828 "Maximum prefix length to be matched\n"
1829 "Maximum prefix length\n")
1830{
1831 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
1832 argv[2], NULL, argv[3]);
1833}
1834
1835DEFUN (ipv6_prefix_list_le_ge,
1836 ipv6_prefix_list_le_ge_cmd,
1837 "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
1838 IPV6_STR
1839 PREFIX_LIST_STR
1840 "Name of a prefix list\n"
1841 "Specify packets to reject\n"
1842 "Specify packets to forward\n"
1843 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1844 "Maximum prefix length to be matched\n"
1845 "Maximum prefix length\n"
1846 "Minimum prefix length to be matched\n"
1847 "Minimum prefix length\n")
1848{
1849 return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
1850 argv[2], argv[4], argv[3]);
1851}
1852
1853DEFUN (ipv6_prefix_list_seq,
1854 ipv6_prefix_list_seq_cmd,
1855 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
1856 IPV6_STR
1857 PREFIX_LIST_STR
1858 "Name of a prefix list\n"
1859 "sequence number of an entry\n"
1860 "Sequence number\n"
1861 "Specify packets to reject\n"
1862 "Specify packets to forward\n"
1863 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1864 "Any prefix match. Same as \"::0/0 le 128\"\n")
1865{
1866 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
1867 argv[3], NULL, NULL);
1868}
1869
1870DEFUN (ipv6_prefix_list_seq_ge,
1871 ipv6_prefix_list_seq_ge_cmd,
1872 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <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{
1884 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
1885 argv[3], argv[4], NULL);
1886}
1887
1888DEFUN (ipv6_prefix_list_seq_ge_le,
1889 ipv6_prefix_list_seq_ge_le_cmd,
1890 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
1891 IPV6_STR
1892 PREFIX_LIST_STR
1893 "Name of a prefix list\n"
1894 "sequence number of an entry\n"
1895 "Sequence number\n"
1896 "Specify packets to reject\n"
1897 "Specify packets to forward\n"
1898 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1899 "Minimum prefix length to be matched\n"
1900 "Minimum prefix length\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], argv[4], argv[5]);
1906}
1907
1908DEFUN (ipv6_prefix_list_seq_le,
1909 ipv6_prefix_list_seq_le_cmd,
1910 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <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{
1922 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
1923 argv[3], NULL, argv[4]);
1924}
1925
1926DEFUN (ipv6_prefix_list_seq_le_ge,
1927 ipv6_prefix_list_seq_le_ge_cmd,
1928 "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
1929 IPV6_STR
1930 PREFIX_LIST_STR
1931 "Name of a prefix list\n"
1932 "sequence number of an entry\n"
1933 "Sequence number\n"
1934 "Specify packets to reject\n"
1935 "Specify packets to forward\n"
1936 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1937 "Maximum prefix length to be matched\n"
1938 "Maximum prefix length\n"
1939 "Minimum prefix length to be matched\n"
1940 "Minimum prefix length\n")
1941{
1942 return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
1943 argv[3], argv[5], argv[4]);
1944}
1945
1946DEFUN (no_ipv6_prefix_list,
1947 no_ipv6_prefix_list_cmd,
1948 "no ipv6 prefix-list WORD",
1949 NO_STR
1950 IPV6_STR
1951 PREFIX_LIST_STR
1952 "Name of a prefix list\n")
1953{
1954 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
1955 NULL, NULL, NULL);
1956}
1957
1958DEFUN (no_ipv6_prefix_list_prefix,
1959 no_ipv6_prefix_list_prefix_cmd,
1960 "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
1961 NO_STR
1962 IPV6_STR
1963 PREFIX_LIST_STR
1964 "Name of a prefix list\n"
1965 "Specify packets to reject\n"
1966 "Specify packets to forward\n"
1967 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1968 "Any prefix match. Same as \"::0/0 le 128\"\n")
1969{
1970 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
1971 argv[2], NULL, NULL);
1972}
1973
1974DEFUN (no_ipv6_prefix_list_ge,
1975 no_ipv6_prefix_list_ge_cmd,
1976 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
1977 NO_STR
1978 IPV6_STR
1979 PREFIX_LIST_STR
1980 "Name of a prefix list\n"
1981 "Specify packets to reject\n"
1982 "Specify packets to forward\n"
1983 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1984 "Minimum prefix length to be matched\n"
1985 "Minimum prefix length\n")
1986{
1987 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
1988 argv[2], argv[3], NULL);
1989}
1990
1991DEFUN (no_ipv6_prefix_list_ge_le,
1992 no_ipv6_prefix_list_ge_le_cmd,
1993 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
1994 NO_STR
1995 IPV6_STR
1996 PREFIX_LIST_STR
1997 "Name of a prefix list\n"
1998 "Specify packets to reject\n"
1999 "Specify packets to forward\n"
2000 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2001 "Minimum prefix length to be matched\n"
2002 "Minimum prefix length\n"
2003 "Maximum prefix length to be matched\n"
2004 "Maximum prefix length\n")
2005{
2006 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2007 argv[2], argv[3], argv[4]);
2008}
2009
2010DEFUN (no_ipv6_prefix_list_le,
2011 no_ipv6_prefix_list_le_cmd,
2012 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
2013 NO_STR
2014 IPV6_STR
2015 PREFIX_LIST_STR
2016 "Name of a prefix list\n"
2017 "Specify packets to reject\n"
2018 "Specify packets to forward\n"
2019 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2020 "Maximum prefix length to be matched\n"
2021 "Maximum prefix length\n")
2022{
2023 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2024 argv[2], NULL, argv[3]);
2025}
2026
2027DEFUN (no_ipv6_prefix_list_le_ge,
2028 no_ipv6_prefix_list_le_ge_cmd,
2029 "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2030 NO_STR
2031 IPV6_STR
2032 PREFIX_LIST_STR
2033 "Name of a prefix list\n"
2034 "Specify packets to reject\n"
2035 "Specify packets to forward\n"
2036 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2037 "Maximum prefix length to be matched\n"
2038 "Maximum prefix length\n"
2039 "Minimum prefix length to be matched\n"
2040 "Minimum prefix length\n")
2041{
2042 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
2043 argv[2], argv[4], argv[3]);
2044}
2045
2046DEFUN (no_ipv6_prefix_list_seq,
2047 no_ipv6_prefix_list_seq_cmd,
2048 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
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 "Any prefix match. Same as \"::0/0 le 128\"\n")
2059{
2060 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2061 argv[3], NULL, NULL);
2062}
2063
2064DEFUN (no_ipv6_prefix_list_seq_ge,
2065 no_ipv6_prefix_list_seq_ge_cmd,
2066 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
2067 NO_STR
2068 IPV6_STR
2069 PREFIX_LIST_STR
2070 "Name of a prefix list\n"
2071 "sequence number of an entry\n"
2072 "Sequence number\n"
2073 "Specify packets to reject\n"
2074 "Specify packets to forward\n"
2075 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2076 "Minimum prefix length to be matched\n"
2077 "Minimum prefix length\n")
2078{
2079 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2080 argv[3], argv[4], NULL);
2081}
2082
2083DEFUN (no_ipv6_prefix_list_seq_ge_le,
2084 no_ipv6_prefix_list_seq_ge_le_cmd,
2085 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
2086 NO_STR
2087 IPV6_STR
2088 PREFIX_LIST_STR
2089 "Name of a prefix list\n"
2090 "sequence number of an entry\n"
2091 "Sequence number\n"
2092 "Specify packets to reject\n"
2093 "Specify packets to forward\n"
2094 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2095 "Minimum prefix length to be matched\n"
2096 "Minimum prefix length\n"
2097 "Maximum prefix length to be matched\n"
2098 "Maximum prefix length\n")
2099{
2100 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2101 argv[3], argv[4], argv[5]);
2102}
2103
2104DEFUN (no_ipv6_prefix_list_seq_le,
2105 no_ipv6_prefix_list_seq_le_cmd,
2106 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
2107 NO_STR
2108 IPV6_STR
2109 PREFIX_LIST_STR
2110 "Name of a prefix list\n"
2111 "sequence number of an entry\n"
2112 "Sequence number\n"
2113 "Specify packets to reject\n"
2114 "Specify packets to forward\n"
2115 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2116 "Maximum prefix length to be matched\n"
2117 "Maximum prefix length\n")
2118{
2119 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2120 argv[3], NULL, argv[4]);
2121}
2122
2123DEFUN (no_ipv6_prefix_list_seq_le_ge,
2124 no_ipv6_prefix_list_seq_le_ge_cmd,
2125 "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
2126 NO_STR
2127 IPV6_STR
2128 PREFIX_LIST_STR
2129 "Name of a prefix list\n"
2130 "sequence number of an entry\n"
2131 "Sequence number\n"
2132 "Specify packets to reject\n"
2133 "Specify packets to forward\n"
2134 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2135 "Maximum prefix length to be matched\n"
2136 "Maximum prefix length\n"
2137 "Minimum prefix length to be matched\n"
2138 "Minimum prefix length\n")
2139{
2140 return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
2141 argv[3], argv[5], argv[4]);
2142}
2143
2144DEFUN (ipv6_prefix_list_sequence_number,
2145 ipv6_prefix_list_sequence_number_cmd,
2146 "ipv6 prefix-list sequence-number",
2147 IPV6_STR
2148 PREFIX_LIST_STR
2149 "Include/exclude sequence numbers in NVGEN\n")
2150{
2151 prefix_master_ipv6.seqnum = 1;
2152 return CMD_SUCCESS;
2153}
2154
2155DEFUN (no_ipv6_prefix_list_sequence_number,
2156 no_ipv6_prefix_list_sequence_number_cmd,
2157 "no ipv6 prefix-list sequence-number",
2158 NO_STR
2159 IPV6_STR
2160 PREFIX_LIST_STR
2161 "Include/exclude sequence numbers in NVGEN\n")
2162{
2163 prefix_master_ipv6.seqnum = 0;
2164 return CMD_SUCCESS;
2165}
2166
2167DEFUN (ipv6_prefix_list_description,
2168 ipv6_prefix_list_description_cmd,
2169 "ipv6 prefix-list WORD description .LINE",
2170 IPV6_STR
2171 PREFIX_LIST_STR
2172 "Name of a prefix list\n"
2173 "Prefix-list specific description\n"
2174 "Up to 80 characters describing this prefix-list\n")
2175{
2176 struct prefix_list *plist;
paul718e3742002-12-13 20:15:29 +00002177
David Lamparterc9c06d02015-04-13 10:21:35 +02002178 plist = prefix_list_get (AFI_IP6, 0, argv[0]);
paul718e3742002-12-13 20:15:29 +00002179
2180 if (plist->desc)
2181 {
2182 XFREE (MTYPE_TMP, plist->desc);
2183 plist->desc = NULL;
2184 }
ajs3b8b1852005-01-29 18:19:13 +00002185 plist->desc = argv_concat(argv, argc, 1);
paul718e3742002-12-13 20:15:29 +00002186
2187 return CMD_SUCCESS;
2188}
2189
2190DEFUN (no_ipv6_prefix_list_description,
2191 no_ipv6_prefix_list_description_cmd,
2192 "no ipv6 prefix-list WORD description",
2193 NO_STR
2194 IPV6_STR
2195 PREFIX_LIST_STR
2196 "Name of a prefix list\n"
2197 "Prefix-list specific description\n")
2198{
2199 return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
2200}
2201
2202ALIAS (no_ipv6_prefix_list_description,
2203 no_ipv6_prefix_list_description_arg_cmd,
2204 "no ipv6 prefix-list WORD description .LINE",
2205 NO_STR
2206 IPV6_STR
2207 PREFIX_LIST_STR
2208 "Name of a prefix list\n"
2209 "Prefix-list specific description\n"
2210 "Up to 80 characters describing this prefix-list\n")
2211
2212DEFUN (show_ipv6_prefix_list,
2213 show_ipv6_prefix_list_cmd,
2214 "show ipv6 prefix-list",
2215 SHOW_STR
2216 IPV6_STR
2217 PREFIX_LIST_STR)
2218{
2219 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
2220}
2221
2222DEFUN (show_ipv6_prefix_list_name,
2223 show_ipv6_prefix_list_name_cmd,
2224 "show ipv6 prefix-list WORD",
2225 SHOW_STR
2226 IPV6_STR
2227 PREFIX_LIST_STR
2228 "Name of a prefix list\n")
2229{
2230 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
2231}
2232
2233DEFUN (show_ipv6_prefix_list_name_seq,
2234 show_ipv6_prefix_list_name_seq_cmd,
2235 "show ipv6 prefix-list WORD seq <1-4294967295>",
2236 SHOW_STR
2237 IPV6_STR
2238 PREFIX_LIST_STR
2239 "Name of a prefix list\n"
2240 "sequence number of an entry\n"
2241 "Sequence number\n")
2242{
2243 return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
2244}
2245
2246DEFUN (show_ipv6_prefix_list_prefix,
2247 show_ipv6_prefix_list_prefix_cmd,
2248 "show ipv6 prefix-list WORD X:X::X:X/M",
2249 SHOW_STR
2250 IPV6_STR
2251 PREFIX_LIST_STR
2252 "Name of a prefix list\n"
2253 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2254{
2255 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
2256}
2257
2258DEFUN (show_ipv6_prefix_list_prefix_longer,
2259 show_ipv6_prefix_list_prefix_longer_cmd,
2260 "show ipv6 prefix-list WORD X:X::X:X/M longer",
2261 SHOW_STR
2262 IPV6_STR
2263 PREFIX_LIST_STR
2264 "Name of a prefix list\n"
2265 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2266 "Lookup longer prefix\n")
2267{
2268 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
2269}
2270
2271DEFUN (show_ipv6_prefix_list_prefix_first_match,
2272 show_ipv6_prefix_list_prefix_first_match_cmd,
2273 "show ipv6 prefix-list WORD X:X::X:X/M first-match",
2274 SHOW_STR
2275 IPV6_STR
2276 PREFIX_LIST_STR
2277 "Name of a prefix list\n"
2278 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
2279 "First matched prefix\n")
2280{
2281 return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
2282}
2283
2284DEFUN (show_ipv6_prefix_list_summary,
2285 show_ipv6_prefix_list_summary_cmd,
2286 "show ipv6 prefix-list summary",
2287 SHOW_STR
2288 IPV6_STR
2289 PREFIX_LIST_STR
2290 "Summary of prefix lists\n")
2291{
2292 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
2293}
2294
2295DEFUN (show_ipv6_prefix_list_summary_name,
2296 show_ipv6_prefix_list_summary_name_cmd,
2297 "show ipv6 prefix-list summary WORD",
2298 SHOW_STR
2299 IPV6_STR
2300 PREFIX_LIST_STR
2301 "Summary of prefix lists\n"
2302 "Name of a prefix list\n")
2303{
2304 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
2305}
2306
2307DEFUN (show_ipv6_prefix_list_detail,
2308 show_ipv6_prefix_list_detail_cmd,
2309 "show ipv6 prefix-list detail",
2310 SHOW_STR
2311 IPV6_STR
2312 PREFIX_LIST_STR
2313 "Detail of prefix lists\n")
2314{
2315 return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
2316}
2317
2318DEFUN (show_ipv6_prefix_list_detail_name,
2319 show_ipv6_prefix_list_detail_name_cmd,
2320 "show ipv6 prefix-list detail WORD",
2321 SHOW_STR
2322 IPV6_STR
2323 PREFIX_LIST_STR
2324 "Detail of prefix lists\n"
2325 "Name of a prefix list\n")
2326{
2327 return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
2328}
2329
2330DEFUN (clear_ipv6_prefix_list,
2331 clear_ipv6_prefix_list_cmd,
2332 "clear ipv6 prefix-list",
2333 CLEAR_STR
2334 IPV6_STR
2335 PREFIX_LIST_STR)
2336{
2337 return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
2338}
2339
2340DEFUN (clear_ipv6_prefix_list_name,
2341 clear_ipv6_prefix_list_name_cmd,
2342 "clear ipv6 prefix-list WORD",
2343 CLEAR_STR
2344 IPV6_STR
2345 PREFIX_LIST_STR
2346 "Name of a prefix list\n")
2347{
2348 return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
2349}
2350
2351DEFUN (clear_ipv6_prefix_list_name_prefix,
2352 clear_ipv6_prefix_list_name_prefix_cmd,
2353 "clear ipv6 prefix-list WORD X:X::X:X/M",
2354 CLEAR_STR
2355 IPV6_STR
2356 PREFIX_LIST_STR
2357 "Name of a prefix list\n"
2358 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2359{
2360 return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
2361}
2362#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02002363
paul718e3742002-12-13 20:15:29 +00002364/* Configuration write function. */
paul02ff83c2004-06-11 11:27:03 +00002365static int
paul718e3742002-12-13 20:15:29 +00002366config_write_prefix_afi (afi_t afi, struct vty *vty)
2367{
2368 struct prefix_list *plist;
2369 struct prefix_list_entry *pentry;
2370 struct prefix_master *master;
2371 int write = 0;
2372
David Lamparterc9c06d02015-04-13 10:21:35 +02002373 master = prefix_master_get (afi, 0);
paul718e3742002-12-13 20:15:29 +00002374 if (master == NULL)
2375 return 0;
2376
2377 if (! master->seqnum)
2378 {
2379 vty_out (vty, "no ip%s prefix-list sequence-number%s",
2380 afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
2381 vty_out (vty, "!%s", VTY_NEWLINE);
2382 }
2383
2384 for (plist = master->num.head; plist; plist = plist->next)
2385 {
2386 if (plist->desc)
2387 {
2388 vty_out (vty, "ip%s prefix-list %s description %s%s",
2389 afi == AFI_IP ? "" : "v6",
2390 plist->name, plist->desc, VTY_NEWLINE);
2391 write++;
2392 }
2393
2394 for (pentry = plist->head; pentry; pentry = pentry->next)
2395 {
2396 vty_out (vty, "ip%s prefix-list %s ",
2397 afi == AFI_IP ? "" : "v6",
2398 plist->name);
2399
2400 if (master->seqnum)
2401 vty_out (vty, "seq %d ", pentry->seq);
2402
2403 vty_out (vty, "%s ", prefix_list_type_str (pentry));
2404
2405 if (pentry->any)
2406 vty_out (vty, "any");
2407 else
2408 {
2409 struct prefix *p = &pentry->prefix;
2410 char buf[BUFSIZ];
2411
2412 vty_out (vty, "%s/%d",
2413 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2414 p->prefixlen);
2415
2416 if (pentry->ge)
2417 vty_out (vty, " ge %d", pentry->ge);
2418 if (pentry->le)
2419 vty_out (vty, " le %d", pentry->le);
2420 }
2421 vty_out (vty, "%s", VTY_NEWLINE);
2422 write++;
2423 }
2424 /* vty_out (vty, "!%s", VTY_NEWLINE); */
2425 }
2426
2427 for (plist = master->str.head; plist; plist = plist->next)
2428 {
2429 if (plist->desc)
2430 {
2431 vty_out (vty, "ip%s prefix-list %s description %s%s",
2432 afi == AFI_IP ? "" : "v6",
2433 plist->name, plist->desc, VTY_NEWLINE);
2434 write++;
2435 }
2436
2437 for (pentry = plist->head; pentry; pentry = pentry->next)
2438 {
2439 vty_out (vty, "ip%s prefix-list %s ",
2440 afi == AFI_IP ? "" : "v6",
2441 plist->name);
2442
2443 if (master->seqnum)
2444 vty_out (vty, "seq %d ", pentry->seq);
2445
2446 vty_out (vty, "%s", prefix_list_type_str (pentry));
2447
2448 if (pentry->any)
2449 vty_out (vty, " any");
2450 else
2451 {
2452 struct prefix *p = &pentry->prefix;
2453 char buf[BUFSIZ];
2454
2455 vty_out (vty, " %s/%d",
2456 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2457 p->prefixlen);
2458
2459 if (pentry->ge)
2460 vty_out (vty, " ge %d", pentry->ge);
2461 if (pentry->le)
2462 vty_out (vty, " le %d", pentry->le);
2463 }
2464 vty_out (vty, "%s", VTY_NEWLINE);
2465 write++;
2466 }
2467 }
2468
2469 return write;
2470}
2471
paul718e3742002-12-13 20:15:29 +00002472struct stream *
2473prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
2474 u_char init_flag, u_char permit_flag, u_char deny_flag)
2475{
2476 struct prefix_list_entry *pentry;
2477
2478 if (! plist)
2479 return s;
2480
2481 for (pentry = plist->head; pentry; pentry = pentry->next)
2482 {
2483 u_char flag = init_flag;
2484 struct prefix *p = &pentry->prefix;
2485
2486 flag |= (pentry->type == PREFIX_PERMIT ?
2487 permit_flag : deny_flag);
2488 stream_putc (s, flag);
2489 stream_putl (s, (u_int32_t)pentry->seq);
2490 stream_putc (s, (u_char)pentry->ge);
2491 stream_putc (s, (u_char)pentry->le);
2492 stream_put_prefix (s, p);
2493 }
2494
2495 return s;
2496}
2497
2498int
2499prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
2500 int permit, int set)
2501{
2502 struct prefix_list *plist;
2503 struct prefix_list_entry *pentry;
2504
2505 /* ge and le value check */
2506 if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
2507 return CMD_WARNING;
2508 if (orfp->le && orfp->le <= orfp->p.prefixlen)
2509 return CMD_WARNING;
2510 if (orfp->le && orfp->ge > orfp->le)
2511 return CMD_WARNING;
2512
2513 if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
2514 orfp->le = 0;
2515
David Lamparterc9c06d02015-04-13 10:21:35 +02002516 plist = prefix_list_get (afi, 1, name);
paul718e3742002-12-13 20:15:29 +00002517 if (! plist)
2518 return CMD_WARNING;
2519
2520 if (set)
2521 {
2522 pentry = prefix_list_entry_make (&orfp->p,
2523 (permit ? PREFIX_PERMIT : PREFIX_DENY),
2524 orfp->seq, orfp->le, orfp->ge, 0);
2525
2526 if (prefix_entry_dup_check (plist, pentry))
2527 {
2528 prefix_list_entry_free (pentry);
2529 return CMD_WARNING;
2530 }
2531
2532 prefix_list_entry_add (plist, pentry);
2533 }
2534 else
2535 {
2536 pentry = prefix_list_entry_lookup (plist, &orfp->p,
2537 (permit ? PREFIX_PERMIT : PREFIX_DENY),
2538 orfp->seq, orfp->le, orfp->ge);
2539
2540 if (! pentry)
2541 return CMD_WARNING;
2542
2543 prefix_list_entry_delete (plist, pentry, 1);
2544 }
2545
2546 return CMD_SUCCESS;
2547}
2548
2549void
David Lamparterc9c06d02015-04-13 10:21:35 +02002550prefix_bgp_orf_remove_all (afi_t afi, char *name)
paul718e3742002-12-13 20:15:29 +00002551{
2552 struct prefix_list *plist;
2553
David Lamparterc9c06d02015-04-13 10:21:35 +02002554 plist = prefix_bgp_orf_lookup (afi, name);
paul718e3742002-12-13 20:15:29 +00002555 if (plist)
2556 prefix_list_delete (plist);
2557}
2558
2559/* return prefix count */
2560int
2561prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name)
2562{
2563 struct prefix_list *plist;
2564 struct prefix_list_entry *pentry;
2565
David Lamparterc9c06d02015-04-13 10:21:35 +02002566 plist = prefix_bgp_orf_lookup (afi, name);
paul718e3742002-12-13 20:15:29 +00002567 if (! plist)
2568 return 0;
2569
2570 if (! vty)
2571 return plist->count;
2572
2573 vty_out (vty, "ip%s prefix-list %s: %d entries%s",
2574 afi == AFI_IP ? "" : "v6",
2575 plist->name, plist->count, VTY_NEWLINE);
2576
2577 for (pentry = plist->head; pentry; pentry = pentry->next)
2578 {
2579 struct prefix *p = &pentry->prefix;
2580 char buf[BUFSIZ];
2581
2582 vty_out (vty, " seq %d %s %s/%d", pentry->seq,
2583 prefix_list_type_str (pentry),
2584 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
2585 p->prefixlen);
2586
2587 if (pentry->ge)
2588 vty_out (vty, " ge %d", pentry->ge);
2589 if (pentry->le)
2590 vty_out (vty, " le %d", pentry->le);
2591
2592 vty_out (vty, "%s", VTY_NEWLINE);
2593 }
2594 return plist->count;
2595}
2596
paul02ff83c2004-06-11 11:27:03 +00002597static void
David Lamparterc9c06d02015-04-13 10:21:35 +02002598prefix_list_reset_afi (afi_t afi, int orf)
paul718e3742002-12-13 20:15:29 +00002599{
2600 struct prefix_list *plist;
2601 struct prefix_list *next;
2602 struct prefix_master *master;
2603
David Lamparterc9c06d02015-04-13 10:21:35 +02002604 master = prefix_master_get (afi, orf);
paul718e3742002-12-13 20:15:29 +00002605 if (master == NULL)
2606 return;
2607
2608 for (plist = master->num.head; plist; plist = next)
2609 {
2610 next = plist->next;
2611 prefix_list_delete (plist);
2612 }
2613 for (plist = master->str.head; plist; plist = next)
2614 {
2615 next = plist->next;
2616 prefix_list_delete (plist);
2617 }
2618
2619 assert (master->num.head == NULL);
2620 assert (master->num.tail == NULL);
2621
2622 assert (master->str.head == NULL);
2623 assert (master->str.tail == NULL);
2624
2625 master->seqnum = 1;
2626 master->recent = NULL;
2627}
2628
2629
2630/* Prefix-list node. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002631static struct cmd_node prefix_node =
paul718e3742002-12-13 20:15:29 +00002632{
2633 PREFIX_NODE,
2634 "", /* Prefix list has no interface. */
2635 1
2636};
2637
paul02ff83c2004-06-11 11:27:03 +00002638static int
paul718e3742002-12-13 20:15:29 +00002639config_write_prefix_ipv4 (struct vty *vty)
2640{
2641 return config_write_prefix_afi (AFI_IP, vty);
2642}
2643
paul02ff83c2004-06-11 11:27:03 +00002644static void
paul8cc41982005-05-06 21:25:49 +00002645prefix_list_init_ipv4 (void)
paul718e3742002-12-13 20:15:29 +00002646{
2647 install_node (&prefix_node, config_write_prefix_ipv4);
2648
2649 install_element (CONFIG_NODE, &ip_prefix_list_cmd);
2650 install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
2651 install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
2652 install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
2653 install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
2654 install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
2655 install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
2656 install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
2657 install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
2658 install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
2659
2660 install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
2661 install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
2662 install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
2663 install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
2664 install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
2665 install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
2666 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
2667 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
2668 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
2669 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
2670 install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
2671
2672 install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
2673 install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
2674 install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
2675
2676 install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
2677 install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
2678
2679 install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
2680 install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
2681 install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
2682 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
2683 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
2684 install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
2685 install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
2686 install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
2687 install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
2688 install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
2689
2690 install_element (ENABLE_NODE, &show_ip_prefix_list_cmd);
2691 install_element (ENABLE_NODE, &show_ip_prefix_list_name_cmd);
2692 install_element (ENABLE_NODE, &show_ip_prefix_list_name_seq_cmd);
2693 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_cmd);
2694 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_longer_cmd);
2695 install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
2696 install_element (ENABLE_NODE, &show_ip_prefix_list_summary_cmd);
2697 install_element (ENABLE_NODE, &show_ip_prefix_list_summary_name_cmd);
2698 install_element (ENABLE_NODE, &show_ip_prefix_list_detail_cmd);
2699 install_element (ENABLE_NODE, &show_ip_prefix_list_detail_name_cmd);
2700
2701 install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
2702 install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
2703 install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
2704}
2705
2706#ifdef HAVE_IPV6
2707/* Prefix-list node. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002708static struct cmd_node prefix_ipv6_node =
paul718e3742002-12-13 20:15:29 +00002709{
2710 PREFIX_IPV6_NODE,
2711 "", /* Prefix list has no interface. */
2712 1
2713};
2714
paul02ff83c2004-06-11 11:27:03 +00002715static int
paul718e3742002-12-13 20:15:29 +00002716config_write_prefix_ipv6 (struct vty *vty)
2717{
2718 return config_write_prefix_afi (AFI_IP6, vty);
2719}
2720
paul02ff83c2004-06-11 11:27:03 +00002721static void
paul8cc41982005-05-06 21:25:49 +00002722prefix_list_init_ipv6 (void)
paul718e3742002-12-13 20:15:29 +00002723{
2724 install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
2725
2726 install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
2727 install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
2728 install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
2729 install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
2730 install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
2731 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
2732 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
2733 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
2734 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
2735 install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
2736
2737 install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
2738 install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
2739 install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
2740 install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
2741 install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
2742 install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
2743 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
2744 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
2745 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
2746 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
2747 install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
2748
2749 install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
2750 install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
2751 install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
2752
2753 install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
2754 install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
2755
2756 install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
2757 install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
2758 install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
2759 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
2760 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
2761 install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
2762 install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
2763 install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
2764 install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
2765 install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
2766
2767 install_element (ENABLE_NODE, &show_ipv6_prefix_list_cmd);
2768 install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_cmd);
2769 install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_seq_cmd);
2770 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_cmd);
2771 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
2772 install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
2773 install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd);
2774 install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_name_cmd);
2775 install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd);
2776 install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_name_cmd);
2777
2778 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
2779 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
2780 install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
2781}
2782#endif /* HAVE_IPV6 */
2783
2784void
2785prefix_list_init ()
2786{
2787 prefix_list_init_ipv4 ();
2788#ifdef HAVE_IPV6
2789 prefix_list_init_ipv6 ();
2790#endif /* HAVE_IPV6 */
2791}
2792
2793void
2794prefix_list_reset ()
2795{
David Lamparterc9c06d02015-04-13 10:21:35 +02002796 prefix_list_reset_afi (AFI_IP, 0);
2797 prefix_list_reset_afi (AFI_IP6, 0);
2798 prefix_list_reset_afi (AFI_IP, 1);
2799 prefix_list_reset_afi (AFI_IP6, 1);
paul718e3742002-12-13 20:15:29 +00002800}