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