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