]> git.proxmox.com Git - mirror_frr.git/blame - lib/distribute.c
Merge pull request #5104 from opensourcerouting/route-map-nbv2
[mirror_frr.git] / lib / distribute.c
CommitLineData
718e3744 1/* Distribute list functions
2 * Copyright (C) 1998, 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 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
21#include <zebra.h>
22
23#include "hash.h"
24#include "if.h"
25#include "filter.h"
26#include "command.h"
27#include "distribute.h"
28#include "memory.h"
29
03a38493 30DEFINE_MTYPE_STATIC(LIB, DISTRIBUTE_CTX, "Distribute ctx")
d62a17ae 31DEFINE_MTYPE_STATIC(LIB, DISTRIBUTE, "Distribute list")
4a1ab8e4 32DEFINE_MTYPE_STATIC(LIB, DISTRIBUTE_IFNAME, "Dist-list ifname")
d62a17ae 33DEFINE_MTYPE_STATIC(LIB, DISTRIBUTE_NAME, "Dist-list name")
4a1ab8e4 34
c17faa4b 35static struct list *dist_ctx_list;
6b0655a2 36
d62a17ae 37static struct distribute *distribute_new(void)
718e3744 38{
d62a17ae 39 return XCALLOC(MTYPE_DISTRIBUTE, sizeof(struct distribute));
718e3744 40}
41
42/* Free distribute object. */
d62a17ae 43static void distribute_free(struct distribute *dist)
718e3744 44{
d62a17ae 45 int i = 0;
ee5bb561 46
0a22ddfb 47 XFREE(MTYPE_DISTRIBUTE_IFNAME, dist->ifname);
718e3744 48
0a22ddfb
QY
49 for (i = 0; i < DISTRIBUTE_MAX; i++) {
50 XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[i]);
51 }
718e3744 52
0a22ddfb
QY
53 for (i = 0; i < DISTRIBUTE_MAX; i++) {
54 XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[i]);
55 }
718e3744 56
d62a17ae 57 XFREE(MTYPE_DISTRIBUTE, dist);
718e3744 58}
59
03a38493
PG
60static void distribute_free_if_empty(struct distribute_ctx *ctx,
61 struct distribute *dist)
ee5bb561 62{
d62a17ae 63 int i;
ee5bb561 64
d62a17ae 65 for (i = 0; i < DISTRIBUTE_MAX; i++)
66 if (dist->list[i] != NULL || dist->prefix[i] != NULL)
67 return;
ee5bb561 68
03a38493 69 hash_release(ctx->disthash, dist);
d62a17ae 70 distribute_free(dist);
ee5bb561
MB
71}
72
718e3744 73/* Lookup interface's distribute list. */
03a38493
PG
74struct distribute *distribute_lookup(struct distribute_ctx *ctx,
75 const char *ifname)
718e3744 76{
d62a17ae 77 struct distribute key;
78 struct distribute *dist;
718e3744 79
d62a17ae 80 /* temporary reference */
81 key.ifname = (ifname) ? XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname) : NULL;
718e3744 82
03a38493 83 dist = hash_lookup(ctx->disthash, &key);
3a7c85d1 84
0a22ddfb 85 XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname);
24873f0c 86
d62a17ae 87 return dist;
718e3744 88}
89
03a38493
PG
90void distribute_list_add_hook(struct distribute_ctx *ctx,
91 void (*func)(struct distribute_ctx *ctx,
92 struct distribute *))
718e3744 93{
03a38493 94 ctx->distribute_add_hook = func;
718e3744 95}
96
03a38493
PG
97void distribute_list_delete_hook(struct distribute_ctx *ctx,
98 void (*func)(struct distribute_ctx *ctx,
99 struct distribute *))
718e3744 100{
03a38493 101 ctx->distribute_delete_hook = func;
718e3744 102}
103
d62a17ae 104static void *distribute_hash_alloc(struct distribute *arg)
718e3744 105{
d62a17ae 106 struct distribute *dist;
107
108 dist = distribute_new();
109 if (arg->ifname)
110 dist->ifname = XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, arg->ifname);
111 else
112 dist->ifname = NULL;
113 return dist;
718e3744 114}
115
116/* Make new distribute list and push into hash. */
03a38493
PG
117static struct distribute *distribute_get(struct distribute_ctx *ctx,
118 const char *ifname)
718e3744 119{
d62a17ae 120 struct distribute key;
121 struct distribute *ret;
122
123 /* temporary reference */
124 key.ifname = (ifname) ? XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname) : NULL;
718e3744 125
03a38493 126 ret = hash_get(ctx->disthash, &key,
d62a17ae 127 (void *(*)(void *))distribute_hash_alloc);
24873f0c 128
0a22ddfb 129 XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname);
3a7c85d1 130
d62a17ae 131 return ret;
718e3744 132}
133
d8b87afe 134static unsigned int distribute_hash_make(const void *arg)
718e3744 135{
d62a17ae 136 const struct distribute *dist = arg;
718e3744 137
d62a17ae 138 return dist->ifname ? string_hash_make(dist->ifname) : 0;
718e3744 139}
140
141/* If two distribute-list have same value then return 1 else return
142 0. This function is used by hash package. */
74df8d6d 143static bool distribute_cmp(const struct distribute *dist1,
d62a17ae 144 const struct distribute *dist2)
718e3744 145{
d62a17ae 146 if (dist1->ifname && dist2->ifname)
147 if (strcmp(dist1->ifname, dist2->ifname) == 0)
74df8d6d 148 return true;
d62a17ae 149 if (!dist1->ifname && !dist2->ifname)
74df8d6d
DS
150 return true;
151 return false;
718e3744 152}
6b0655a2 153
718e3744 154/* Set access-list name to the distribute list. */
03a38493
PG
155static void distribute_list_set(struct distribute_ctx *ctx,
156 const char *ifname, enum distribute_type type,
d62a17ae 157 const char *alist_name)
718e3744 158{
d62a17ae 159 struct distribute *dist;
718e3744 160
03a38493 161 dist = distribute_get(ctx, ifname);
718e3744 162
0a22ddfb 163 XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]);
d62a17ae 164 dist->list[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, alist_name);
718e3744 165
d62a17ae 166 /* Apply this distribute-list to the interface. */
03a38493 167 (ctx->distribute_add_hook)(ctx, dist);
718e3744 168}
169
170/* Unset distribute-list. If matched distribute-list exist then
171 return 1. */
03a38493
PG
172static int distribute_list_unset(struct distribute_ctx *ctx,
173 const char *ifname,
174 enum distribute_type type,
d62a17ae 175 const char *alist_name)
718e3744 176{
d62a17ae 177 struct distribute *dist;
718e3744 178
03a38493 179 dist = distribute_lookup(ctx, ifname);
d62a17ae 180 if (!dist)
181 return 0;
718e3744 182
d62a17ae 183 if (!dist->list[type])
184 return 0;
185 if (strcmp(dist->list[type], alist_name) != 0)
186 return 0;
718e3744 187
d62a17ae 188 XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]);
718e3744 189
d62a17ae 190 /* Apply this distribute-list to the interface. */
03a38493 191 (ctx->distribute_delete_hook)(ctx, dist);
718e3744 192
d62a17ae 193 /* If all dist are NULL, then free distribute list. */
03a38493 194 distribute_free_if_empty(ctx, dist);
d62a17ae 195 return 1;
718e3744 196}
197
198/* Set access-list name to the distribute list. */
03a38493
PG
199static void distribute_list_prefix_set(struct distribute_ctx *ctx,
200 const char *ifname,
d62a17ae 201 enum distribute_type type,
202 const char *plist_name)
718e3744 203{
d62a17ae 204 struct distribute *dist;
718e3744 205
03a38493 206 dist = distribute_get(ctx, ifname);
718e3744 207
0a22ddfb 208 XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]);
d62a17ae 209 dist->prefix[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, plist_name);
718e3744 210
d62a17ae 211 /* Apply this distribute-list to the interface. */
03a38493 212 (ctx->distribute_add_hook)(ctx, dist);
718e3744 213}
214
215/* Unset distribute-list. If matched distribute-list exist then
216 return 1. */
03a38493
PG
217static int distribute_list_prefix_unset(struct distribute_ctx *ctx,
218 const char *ifname,
d62a17ae 219 enum distribute_type type,
220 const char *plist_name)
718e3744 221{
d62a17ae 222 struct distribute *dist;
718e3744 223
03a38493 224 dist = distribute_lookup(ctx, ifname);
d62a17ae 225 if (!dist)
226 return 0;
718e3744 227
d62a17ae 228 if (!dist->prefix[type])
229 return 0;
230 if (strcmp(dist->prefix[type], plist_name) != 0)
231 return 0;
718e3744 232
d62a17ae 233 XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]);
718e3744 234
d62a17ae 235 /* Apply this distribute-list to the interface. */
03a38493 236 (ctx->distribute_delete_hook)(ctx, dist);
718e3744 237
d62a17ae 238 /* If all dist are NULL, then free distribute list. */
03a38493 239 distribute_free_if_empty(ctx, dist);
d62a17ae 240 return 1;
718e3744 241}
242
718e3744 243DEFUN (distribute_list,
244 distribute_list_cmd,
aa1c90a4 245 "distribute-list [prefix] WORD <in|out> [WORD]",
718e3744 246 "Filter networks in routing updates\n"
856377cc 247 "Specify a prefix\n"
718e3744 248 "Access-list name\n"
249 "Filter incoming routing updates\n"
250 "Filter outgoing routing updates\n"
251 "Interface name\n")
252{
d62a17ae 253 int prefix = (argv[1]->type == WORD_TKN) ? 1 : 0;
d62a17ae 254 /* Check of distribute list type. */
255 enum distribute_type type = argv[2 + prefix]->arg[0] == 'i'
256 ? DISTRIBUTE_V4_IN
257 : DISTRIBUTE_V4_OUT;
718e3744 258
d62a17ae 259 /* Set appropriate function call */
03a38493
PG
260 void (*distfn)(struct distribute_ctx *, const char *,
261 enum distribute_type, const char *) =
d62a17ae 262 prefix ? &distribute_list_prefix_set : &distribute_list_set;
03a38493
PG
263 struct distribute_ctx *ctx =
264 (struct distribute_ctx *)listnode_head(dist_ctx_list);
ba23a691 265
d62a17ae 266 /* if interface is present, get name */
267 const char *ifname = NULL;
268 if (argv[argc - 1]->type == VARIABLE_TKN)
269 ifname = argv[argc - 1]->arg;
718e3744 270
d62a17ae 271 /* Get interface name corresponding distribute list. */
03a38493 272 distfn(ctx, ifname, type, argv[1 + prefix]->arg);
718e3744 273
d62a17ae 274 return CMD_SUCCESS;
aa1c90a4 275}
718e3744 276
fb23cf4a 277DEFUN (ipv6_distribute_list,
ba23a691 278 ipv6_distribute_list_cmd,
e52702f2
QY
279 "ipv6 distribute-list [prefix] WORD <in|out> [WORD]",
280 "IPv6\n"
fb23cf4a 281 "Filter networks in routing updates\n"
4e93448f 282 "Specify a prefix\n"
fb23cf4a
MB
283 "Access-list name\n"
284 "Filter incoming routing updates\n"
285 "Filter outgoing routing updates\n"
286 "Interface name\n")
287{
d62a17ae 288 int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;
d62a17ae 289 /* Check of distribute list type. */
290 enum distribute_type type = argv[3 + prefix]->arg[0] == 'i'
291 ? DISTRIBUTE_V6_IN
292 : DISTRIBUTE_V6_OUT;
e52702f2 293
d62a17ae 294 /* Set appropriate function call */
03a38493
PG
295 void (*distfn)(struct distribute_ctx *, const char *,
296 enum distribute_type, const char *) =
d62a17ae 297 prefix ? &distribute_list_prefix_set : &distribute_list_set;
03a38493 298 struct distribute_ctx *ctx = listnode_head(dist_ctx_list);
fb23cf4a 299
d62a17ae 300 /* if interface is present, get name */
301 const char *ifname = NULL;
302 if (argv[argc - 1]->type == VARIABLE_TKN)
303 ifname = argv[argc - 1]->arg;
fb23cf4a 304
d62a17ae 305 /* Get interface name corresponding distribute list. */
03a38493 306 distfn(ctx, ifname, type, argv[2 + prefix]->arg);
d62a17ae 307
308 return CMD_SUCCESS;
fb23cf4a 309}
d62a17ae 310
aa1c90a4
QY
311DEFUN (no_distribute_list,
312 no_distribute_list_cmd,
96f05398 313 "no distribute-list [prefix] WORD <in|out> [WORD]",
ba23a691 314 NO_STR
315 "Filter networks in routing updates\n"
856377cc 316 "Specify a prefix\n"
ba23a691 317 "Access-list name\n"
318 "Filter incoming routing updates\n"
319 "Filter outgoing routing updates\n"
320 "Interface name\n")
718e3744 321{
96f05398 322 int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;
96f05398 323 int idx_alname = 2 + prefix;
d62a17ae 324 int idx_disttype = idx_alname + 1;
96f05398
PG
325 enum distribute_type type =
326 argv[idx_disttype]->arg[0] == 'i' ?
327 DISTRIBUTE_V4_IN : DISTRIBUTE_V4_OUT;
d62a17ae 328
96f05398 329 /* Set appropriate function call */
03a38493
PG
330 int (*distfn)(struct distribute_ctx *, const char *,
331 enum distribute_type, const char *) =
96f05398 332 prefix ? &distribute_list_prefix_unset : &distribute_list_unset;
03a38493 333 struct distribute_ctx *ctx = listnode_head(dist_ctx_list);
96f05398
PG
334
335 /* if interface is present, get name */
336 const char *ifname = NULL;
337 if (argv[argc - 1]->type == VARIABLE_TKN)
338 ifname = argv[argc - 1]->arg;
339 /* Get interface name corresponding distribute list. */
03a38493 340 int ret = distfn(ctx, ifname, type, argv[2 + prefix]->arg);
96f05398
PG
341
342 if (!ret) {
343 vty_out(vty, "distribute list doesn't exist\n");
344 return CMD_WARNING_CONFIG_FAILED;
345 }
346 return CMD_SUCCESS;
347}
348
349DEFUN (no_ipv6_distribute_list,
350 no_ipv6_distribute_list_cmd,
351 "no ipv6 distribute-list [prefix] WORD <in|out> [WORD]",
352 NO_STR
353 "IPv6\n"
354 "Filter networks in routing updates\n"
355 "Specify a prefix\n"
356 "Access-list name\n"
357 "Filter incoming routing updates\n"
358 "Filter outgoing routing updates\n"
359 "Interface name\n")
360{
361 int prefix = (argv[3]->type == WORD_TKN) ? 1 : 0;
96f05398
PG
362 int idx_alname = 3 + prefix;
363 int idx_disttype = idx_alname + 1;
d62a17ae 364
365 enum distribute_type type =
96f05398
PG
366 argv[idx_disttype]->arg[0] == 'i' ?
367 DISTRIBUTE_V6_IN : DISTRIBUTE_V6_OUT;
03a38493 368 struct distribute_ctx *ctx = listnode_head(dist_ctx_list);
d62a17ae 369
370 /* Set appropriate function call */
03a38493
PG
371 int (*distfn)(struct distribute_ctx *, const char *,
372 enum distribute_type, const char *) =
d62a17ae 373 prefix ? &distribute_list_prefix_unset : &distribute_list_unset;
374
375 /* if interface is present, get name */
376 const char *ifname = NULL;
96f05398 377
d62a17ae 378 if (argv[argc - 1]->type == VARIABLE_TKN)
379 ifname = argv[argc - 1]->arg;
380 /* Get interface name corresponding distribute list. */
03a38493 381 int ret = distfn(ctx, ifname, type, argv[3 + prefix]->arg);
d62a17ae 382
383 if (!ret) {
384 vty_out(vty, "distribute list doesn't exist\n");
385 return CMD_WARNING_CONFIG_FAILED;
386 }
387 return CMD_SUCCESS;
aa1c90a4 388}
ba23a691 389
d62a17ae 390static int distribute_print(struct vty *vty, char *tab[], int is_prefix,
391 enum distribute_type type, int has_print)
ee5bb561 392{
d62a17ae 393 if (tab[type]) {
394 vty_out(vty, "%s %s%s", has_print ? "," : "",
395 is_prefix ? "(prefix-list) " : "", tab[type]);
396 return 1;
397 }
398 return has_print;
ee5bb561
MB
399}
400
03a38493 401int config_show_distribute(struct vty *vty, struct distribute_ctx *dist_ctxt)
718e3744 402{
d62a17ae 403 unsigned int i;
404 int has_print = 0;
e3b78da8 405 struct hash_bucket *mp;
d62a17ae 406 struct distribute *dist;
407
408 /* Output filter configuration. */
03a38493 409 dist = distribute_lookup(dist_ctxt, NULL);
d62a17ae 410 vty_out(vty, " Outgoing update filter list for all interface is");
411 has_print = 0;
412 if (dist) {
413 has_print = distribute_print(vty, dist->list, 0,
414 DISTRIBUTE_V4_OUT, has_print);
415 has_print = distribute_print(vty, dist->prefix, 1,
416 DISTRIBUTE_V4_OUT, has_print);
417 has_print = distribute_print(vty, dist->list, 0,
418 DISTRIBUTE_V6_OUT, has_print);
419 has_print = distribute_print(vty, dist->prefix, 1,
420 DISTRIBUTE_V6_OUT, has_print);
421 }
422 if (has_print)
423 vty_out(vty, "\n");
424 else
425 vty_out(vty, " not set\n");
426
03a38493
PG
427 for (i = 0; i < dist_ctxt->disthash->size; i++)
428 for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) {
d62a17ae 429 dist = mp->data;
430 if (dist->ifname) {
431 vty_out(vty, " %s filtered by",
432 dist->ifname);
433 has_print = 0;
434 has_print = distribute_print(vty, dist->list, 0,
435 DISTRIBUTE_V4_OUT,
436 has_print);
437 has_print = distribute_print(
438 vty, dist->prefix, 1, DISTRIBUTE_V4_OUT,
439 has_print);
440 has_print = distribute_print(vty, dist->list, 0,
441 DISTRIBUTE_V6_OUT,
442 has_print);
443 has_print = distribute_print(
444 vty, dist->prefix, 1, DISTRIBUTE_V6_OUT,
445 has_print);
446 if (has_print)
447 vty_out(vty, "\n");
448 else
449 vty_out(vty, " nothing\n");
450 }
451 }
452
453
454 /* Input filter configuration. */
03a38493 455 dist = distribute_lookup(dist_ctxt, NULL);
d62a17ae 456 vty_out(vty, " Incoming update filter list for all interface is");
457 has_print = 0;
458 if (dist) {
459 has_print = distribute_print(vty, dist->list, 0,
460 DISTRIBUTE_V4_IN, has_print);
461 has_print = distribute_print(vty, dist->prefix, 1,
462 DISTRIBUTE_V4_IN, has_print);
463 has_print = distribute_print(vty, dist->list, 0,
464 DISTRIBUTE_V6_IN, has_print);
465 has_print = distribute_print(vty, dist->prefix, 1,
466 DISTRIBUTE_V6_IN, has_print);
467 }
468 if (has_print)
469 vty_out(vty, "\n");
470 else
471 vty_out(vty, " not set\n");
472
03a38493
PG
473 for (i = 0; i < dist_ctxt->disthash->size; i++)
474 for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) {
d62a17ae 475 dist = mp->data;
476 if (dist->ifname) {
477 vty_out(vty, " %s filtered by",
478 dist->ifname);
479 has_print = 0;
480 has_print = distribute_print(vty, dist->list, 0,
481 DISTRIBUTE_V4_IN,
482 has_print);
483 has_print = distribute_print(
484 vty, dist->prefix, 1, DISTRIBUTE_V4_IN,
485 has_print);
486 has_print = distribute_print(vty, dist->list, 0,
487 DISTRIBUTE_V6_IN,
488 has_print);
489 has_print = distribute_print(
490 vty, dist->prefix, 1, DISTRIBUTE_V6_IN,
491 has_print);
492 if (has_print)
493 vty_out(vty, "\n");
494 else
495 vty_out(vty, " nothing\n");
496 }
497 }
498 return 0;
718e3744 499}
500
501/* Configuration write function. */
03a38493
PG
502int config_write_distribute(struct vty *vty,
503 struct distribute_ctx *dist_ctxt)
718e3744 504{
d62a17ae 505 unsigned int i;
506 int j;
507 int output, v6;
e3b78da8 508 struct hash_bucket *mp;
d62a17ae 509 int write = 0;
510
03a38493
PG
511 for (i = 0; i < dist_ctxt->disthash->size; i++)
512 for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) {
d62a17ae 513 struct distribute *dist;
514
515 dist = mp->data;
516
517 for (j = 0; j < DISTRIBUTE_MAX; j++)
518 if (dist->list[j]) {
519 output = j == DISTRIBUTE_V4_OUT
520 || j == DISTRIBUTE_V6_OUT;
521 v6 = j == DISTRIBUTE_V6_IN
522 || j == DISTRIBUTE_V6_OUT;
523 vty_out(vty,
524 " %sdistribute-list %s %s %s\n",
525 v6 ? "ipv6 " : "",
526 dist->list[j],
527 output ? "out" : "in",
528 dist->ifname ? dist->ifname
529 : "");
530 write++;
531 }
532
533 for (j = 0; j < DISTRIBUTE_MAX; j++)
534 if (dist->prefix[j]) {
535 output = j == DISTRIBUTE_V4_OUT
536 || j == DISTRIBUTE_V6_OUT;
537 v6 = j == DISTRIBUTE_V6_IN
538 || j == DISTRIBUTE_V6_OUT;
539 vty_out(vty,
540 " %sdistribute-list prefix %s %s %s\n",
541 v6 ? "ipv6 " : "",
542 dist->prefix[j],
543 output ? "out" : "in",
544 dist->ifname ? dist->ifname
545 : "");
546 write++;
547 }
548 }
549 return write;
718e3744 550}
551
03a38493 552void distribute_list_delete(struct distribute_ctx **ctx)
718e3744 553{
03a38493
PG
554 if ((*ctx)->disthash) {
555 hash_clean((*ctx)->disthash, (void (*)(void *))distribute_free);
556 }
557 if (!dist_ctx_list)
558 dist_ctx_list = list_new();
559 listnode_delete(dist_ctx_list, *ctx);
560 if (list_isempty(dist_ctx_list))
561 list_delete(&dist_ctx_list);
562 XFREE(MTYPE_DISTRIBUTE_CTX, (*ctx));
718e3744 563}
564
03a38493
PG
565/* Initialize distribute list container */
566struct distribute_ctx *distribute_list_ctx_create(struct vrf *vrf)
718e3744 567{
03a38493
PG
568 struct distribute_ctx *ctx;
569
570 ctx = XCALLOC(MTYPE_DISTRIBUTE_CTX, sizeof(struct distribute_ctx));
571 ctx->vrf = vrf;
572 ctx->disthash = hash_create(
d62a17ae 573 distribute_hash_make,
74df8d6d 574 (bool (*)(const void *, const void *))distribute_cmp, NULL);
03a38493
PG
575 if (!dist_ctx_list)
576 dist_ctx_list = list_new();
577 listnode_add(dist_ctx_list, ctx);
578 return ctx;
579}
d62a17ae 580
03a38493
PG
581/* Initialize distribute list vty commands */
582void distribute_list_init(int node)
583{
d62a17ae 584 /* vtysh command-extraction doesn't grok install_element(node, ) */
585 if (node == RIP_NODE) {
586 install_element(RIP_NODE, &distribute_list_cmd);
587 install_element(RIP_NODE, &no_distribute_list_cmd);
588 } else if (node == RIPNG_NODE) {
589 install_element(RIPNG_NODE, &distribute_list_cmd);
590 install_element(RIPNG_NODE, &no_distribute_list_cmd);
03a38493 591 /* install v6 */
d62a17ae 592 install_element(RIPNG_NODE, &ipv6_distribute_list_cmd);
96f05398 593 install_element(RIPNG_NODE, &no_ipv6_distribute_list_cmd);
d62a17ae 594 }
595
596 /* TODO: install v4 syntax command for v6 only protocols. */
597 /* if (node == RIPNG_NODE) {
598 * install_element (node, &ipv6_as_v4_distribute_list_all_cmd);
599 * install_element (node, &no_ipv6_as_v4_distribute_list_all_cmd);
600 * install_element (node, &ipv6_as_v4_distribute_list_cmd);
601 * install_element (node, &no_ipv6_as_v4_distribute_list_cmd);
602 * install_element (node, &ipv6_as_v4_distribute_list_prefix_all_cmd);
603 * install_element (node,
604 &no_ipv6_as_v4_distribute_list_prefix_all_cmd);
605 * install_element (node, &ipv6_as_v4_distribute_list_prefix_cmd);
606 * install_element (node, &no_ipv6_as_v4_distribute_list_prefix_cmd);
607 }*/
718e3744 608}