]>
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 | |
c17faa4b | 35 | static 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 | |
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 |
60 | static 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 |
74 | struct 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 |
90 | void 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 |
97 | void 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 | 104 | static 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 |
117 | static 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 | 134 | static 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 | 143 | static 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 |
155 | static 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 |
172 | static 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]); |
189 | dist->list[type] = NULL; | |
718e3744 | 190 | |
d62a17ae | 191 | /* Apply this distribute-list to the interface. */ |
03a38493 | 192 | (ctx->distribute_delete_hook)(ctx, dist); |
718e3744 | 193 | |
d62a17ae | 194 | /* If all dist are NULL, then free distribute list. */ |
03a38493 | 195 | distribute_free_if_empty(ctx, dist); |
d62a17ae | 196 | return 1; |
718e3744 | 197 | } |
198 | ||
199 | /* Set access-list name to the distribute list. */ | |
03a38493 PG |
200 | static void distribute_list_prefix_set(struct distribute_ctx *ctx, |
201 | const char *ifname, | |
d62a17ae | 202 | enum distribute_type type, |
203 | const char *plist_name) | |
718e3744 | 204 | { |
d62a17ae | 205 | struct distribute *dist; |
718e3744 | 206 | |
03a38493 | 207 | dist = distribute_get(ctx, ifname); |
718e3744 | 208 | |
0a22ddfb | 209 | XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); |
d62a17ae | 210 | dist->prefix[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, plist_name); |
718e3744 | 211 | |
d62a17ae | 212 | /* Apply this distribute-list to the interface. */ |
03a38493 | 213 | (ctx->distribute_add_hook)(ctx, dist); |
718e3744 | 214 | } |
215 | ||
216 | /* Unset distribute-list. If matched distribute-list exist then | |
217 | return 1. */ | |
03a38493 PG |
218 | static int distribute_list_prefix_unset(struct distribute_ctx *ctx, |
219 | const char *ifname, | |
d62a17ae | 220 | enum distribute_type type, |
221 | const char *plist_name) | |
718e3744 | 222 | { |
d62a17ae | 223 | struct distribute *dist; |
718e3744 | 224 | |
03a38493 | 225 | dist = distribute_lookup(ctx, ifname); |
d62a17ae | 226 | if (!dist) |
227 | return 0; | |
718e3744 | 228 | |
d62a17ae | 229 | if (!dist->prefix[type]) |
230 | return 0; | |
231 | if (strcmp(dist->prefix[type], plist_name) != 0) | |
232 | return 0; | |
718e3744 | 233 | |
d62a17ae | 234 | XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); |
235 | dist->prefix[type] = NULL; | |
718e3744 | 236 | |
d62a17ae | 237 | /* Apply this distribute-list to the interface. */ |
03a38493 | 238 | (ctx->distribute_delete_hook)(ctx, dist); |
718e3744 | 239 | |
d62a17ae | 240 | /* If all dist are NULL, then free distribute list. */ |
03a38493 | 241 | distribute_free_if_empty(ctx, dist); |
d62a17ae | 242 | return 1; |
718e3744 | 243 | } |
244 | ||
718e3744 | 245 | DEFUN (distribute_list, |
246 | distribute_list_cmd, | |
aa1c90a4 | 247 | "distribute-list [prefix] WORD <in|out> [WORD]", |
718e3744 | 248 | "Filter networks in routing updates\n" |
856377cc | 249 | "Specify a prefix\n" |
718e3744 | 250 | "Access-list name\n" |
251 | "Filter incoming routing updates\n" | |
252 | "Filter outgoing routing updates\n" | |
253 | "Interface name\n") | |
254 | { | |
d62a17ae | 255 | int prefix = (argv[1]->type == WORD_TKN) ? 1 : 0; |
d62a17ae | 256 | /* Check of distribute list type. */ |
257 | enum distribute_type type = argv[2 + prefix]->arg[0] == 'i' | |
258 | ? DISTRIBUTE_V4_IN | |
259 | : DISTRIBUTE_V4_OUT; | |
718e3744 | 260 | |
d62a17ae | 261 | /* Set appropriate function call */ |
03a38493 PG |
262 | void (*distfn)(struct distribute_ctx *, const char *, |
263 | enum distribute_type, const char *) = | |
d62a17ae | 264 | prefix ? &distribute_list_prefix_set : &distribute_list_set; |
03a38493 PG |
265 | struct distribute_ctx *ctx = |
266 | (struct distribute_ctx *)listnode_head(dist_ctx_list); | |
ba23a691 | 267 | |
d62a17ae | 268 | /* if interface is present, get name */ |
269 | const char *ifname = NULL; | |
270 | if (argv[argc - 1]->type == VARIABLE_TKN) | |
271 | ifname = argv[argc - 1]->arg; | |
718e3744 | 272 | |
d62a17ae | 273 | /* Get interface name corresponding distribute list. */ |
03a38493 | 274 | distfn(ctx, ifname, type, argv[1 + prefix]->arg); |
718e3744 | 275 | |
d62a17ae | 276 | return CMD_SUCCESS; |
aa1c90a4 | 277 | } |
718e3744 | 278 | |
fb23cf4a | 279 | DEFUN (ipv6_distribute_list, |
ba23a691 | 280 | ipv6_distribute_list_cmd, |
e52702f2 QY |
281 | "ipv6 distribute-list [prefix] WORD <in|out> [WORD]", |
282 | "IPv6\n" | |
fb23cf4a | 283 | "Filter networks in routing updates\n" |
4e93448f | 284 | "Specify a prefix\n" |
fb23cf4a MB |
285 | "Access-list name\n" |
286 | "Filter incoming routing updates\n" | |
287 | "Filter outgoing routing updates\n" | |
288 | "Interface name\n") | |
289 | { | |
d62a17ae | 290 | int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0; |
d62a17ae | 291 | /* Check of distribute list type. */ |
292 | enum distribute_type type = argv[3 + prefix]->arg[0] == 'i' | |
293 | ? DISTRIBUTE_V6_IN | |
294 | : DISTRIBUTE_V6_OUT; | |
e52702f2 | 295 | |
d62a17ae | 296 | /* Set appropriate function call */ |
03a38493 PG |
297 | void (*distfn)(struct distribute_ctx *, const char *, |
298 | enum distribute_type, const char *) = | |
d62a17ae | 299 | prefix ? &distribute_list_prefix_set : &distribute_list_set; |
03a38493 | 300 | struct distribute_ctx *ctx = listnode_head(dist_ctx_list); |
fb23cf4a | 301 | |
d62a17ae | 302 | /* if interface is present, get name */ |
303 | const char *ifname = NULL; | |
304 | if (argv[argc - 1]->type == VARIABLE_TKN) | |
305 | ifname = argv[argc - 1]->arg; | |
fb23cf4a | 306 | |
d62a17ae | 307 | /* Get interface name corresponding distribute list. */ |
03a38493 | 308 | distfn(ctx, ifname, type, argv[2 + prefix]->arg); |
d62a17ae | 309 | |
310 | return CMD_SUCCESS; | |
fb23cf4a | 311 | } |
d62a17ae | 312 | |
aa1c90a4 QY |
313 | DEFUN (no_distribute_list, |
314 | no_distribute_list_cmd, | |
96f05398 | 315 | "no distribute-list [prefix] WORD <in|out> [WORD]", |
ba23a691 | 316 | NO_STR |
317 | "Filter networks in routing updates\n" | |
856377cc | 318 | "Specify a prefix\n" |
ba23a691 | 319 | "Access-list name\n" |
320 | "Filter incoming routing updates\n" | |
321 | "Filter outgoing routing updates\n" | |
322 | "Interface name\n") | |
718e3744 | 323 | { |
96f05398 | 324 | int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0; |
96f05398 | 325 | int idx_alname = 2 + prefix; |
d62a17ae | 326 | int idx_disttype = idx_alname + 1; |
96f05398 PG |
327 | enum distribute_type type = |
328 | argv[idx_disttype]->arg[0] == 'i' ? | |
329 | DISTRIBUTE_V4_IN : DISTRIBUTE_V4_OUT; | |
d62a17ae | 330 | |
96f05398 | 331 | /* Set appropriate function call */ |
03a38493 PG |
332 | int (*distfn)(struct distribute_ctx *, const char *, |
333 | enum distribute_type, const char *) = | |
96f05398 | 334 | prefix ? &distribute_list_prefix_unset : &distribute_list_unset; |
03a38493 | 335 | struct distribute_ctx *ctx = listnode_head(dist_ctx_list); |
96f05398 PG |
336 | |
337 | /* if interface is present, get name */ | |
338 | const char *ifname = NULL; | |
339 | if (argv[argc - 1]->type == VARIABLE_TKN) | |
340 | ifname = argv[argc - 1]->arg; | |
341 | /* Get interface name corresponding distribute list. */ | |
03a38493 | 342 | int ret = distfn(ctx, ifname, type, argv[2 + prefix]->arg); |
96f05398 PG |
343 | |
344 | if (!ret) { | |
345 | vty_out(vty, "distribute list doesn't exist\n"); | |
346 | return CMD_WARNING_CONFIG_FAILED; | |
347 | } | |
348 | return CMD_SUCCESS; | |
349 | } | |
350 | ||
351 | DEFUN (no_ipv6_distribute_list, | |
352 | no_ipv6_distribute_list_cmd, | |
353 | "no ipv6 distribute-list [prefix] WORD <in|out> [WORD]", | |
354 | NO_STR | |
355 | "IPv6\n" | |
356 | "Filter networks in routing updates\n" | |
357 | "Specify a prefix\n" | |
358 | "Access-list name\n" | |
359 | "Filter incoming routing updates\n" | |
360 | "Filter outgoing routing updates\n" | |
361 | "Interface name\n") | |
362 | { | |
363 | int prefix = (argv[3]->type == WORD_TKN) ? 1 : 0; | |
96f05398 PG |
364 | int idx_alname = 3 + prefix; |
365 | int idx_disttype = idx_alname + 1; | |
d62a17ae | 366 | |
367 | enum distribute_type type = | |
96f05398 PG |
368 | argv[idx_disttype]->arg[0] == 'i' ? |
369 | DISTRIBUTE_V6_IN : DISTRIBUTE_V6_OUT; | |
03a38493 | 370 | struct distribute_ctx *ctx = listnode_head(dist_ctx_list); |
d62a17ae | 371 | |
372 | /* Set appropriate function call */ | |
03a38493 PG |
373 | int (*distfn)(struct distribute_ctx *, const char *, |
374 | enum distribute_type, const char *) = | |
d62a17ae | 375 | prefix ? &distribute_list_prefix_unset : &distribute_list_unset; |
376 | ||
377 | /* if interface is present, get name */ | |
378 | const char *ifname = NULL; | |
96f05398 | 379 | |
d62a17ae | 380 | if (argv[argc - 1]->type == VARIABLE_TKN) |
381 | ifname = argv[argc - 1]->arg; | |
382 | /* Get interface name corresponding distribute list. */ | |
03a38493 | 383 | int ret = distfn(ctx, ifname, type, argv[3 + prefix]->arg); |
d62a17ae | 384 | |
385 | if (!ret) { | |
386 | vty_out(vty, "distribute list doesn't exist\n"); | |
387 | return CMD_WARNING_CONFIG_FAILED; | |
388 | } | |
389 | return CMD_SUCCESS; | |
aa1c90a4 | 390 | } |
ba23a691 | 391 | |
d62a17ae | 392 | static int distribute_print(struct vty *vty, char *tab[], int is_prefix, |
393 | enum distribute_type type, int has_print) | |
ee5bb561 | 394 | { |
d62a17ae | 395 | if (tab[type]) { |
396 | vty_out(vty, "%s %s%s", has_print ? "," : "", | |
397 | is_prefix ? "(prefix-list) " : "", tab[type]); | |
398 | return 1; | |
399 | } | |
400 | return has_print; | |
ee5bb561 MB |
401 | } |
402 | ||
03a38493 | 403 | int config_show_distribute(struct vty *vty, struct distribute_ctx *dist_ctxt) |
718e3744 | 404 | { |
d62a17ae | 405 | unsigned int i; |
406 | int has_print = 0; | |
e3b78da8 | 407 | struct hash_bucket *mp; |
d62a17ae | 408 | struct distribute *dist; |
409 | ||
410 | /* Output filter configuration. */ | |
03a38493 | 411 | dist = distribute_lookup(dist_ctxt, NULL); |
d62a17ae | 412 | vty_out(vty, " Outgoing update filter list for all interface is"); |
413 | has_print = 0; | |
414 | if (dist) { | |
415 | has_print = distribute_print(vty, dist->list, 0, | |
416 | DISTRIBUTE_V4_OUT, has_print); | |
417 | has_print = distribute_print(vty, dist->prefix, 1, | |
418 | DISTRIBUTE_V4_OUT, has_print); | |
419 | has_print = distribute_print(vty, dist->list, 0, | |
420 | DISTRIBUTE_V6_OUT, has_print); | |
421 | has_print = distribute_print(vty, dist->prefix, 1, | |
422 | DISTRIBUTE_V6_OUT, has_print); | |
423 | } | |
424 | if (has_print) | |
425 | vty_out(vty, "\n"); | |
426 | else | |
427 | vty_out(vty, " not set\n"); | |
428 | ||
03a38493 PG |
429 | for (i = 0; i < dist_ctxt->disthash->size; i++) |
430 | for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) { | |
d62a17ae | 431 | dist = mp->data; |
432 | if (dist->ifname) { | |
433 | vty_out(vty, " %s filtered by", | |
434 | dist->ifname); | |
435 | has_print = 0; | |
436 | has_print = distribute_print(vty, dist->list, 0, | |
437 | DISTRIBUTE_V4_OUT, | |
438 | has_print); | |
439 | has_print = distribute_print( | |
440 | vty, dist->prefix, 1, DISTRIBUTE_V4_OUT, | |
441 | has_print); | |
442 | has_print = distribute_print(vty, dist->list, 0, | |
443 | DISTRIBUTE_V6_OUT, | |
444 | has_print); | |
445 | has_print = distribute_print( | |
446 | vty, dist->prefix, 1, DISTRIBUTE_V6_OUT, | |
447 | has_print); | |
448 | if (has_print) | |
449 | vty_out(vty, "\n"); | |
450 | else | |
451 | vty_out(vty, " nothing\n"); | |
452 | } | |
453 | } | |
454 | ||
455 | ||
456 | /* Input filter configuration. */ | |
03a38493 | 457 | dist = distribute_lookup(dist_ctxt, NULL); |
d62a17ae | 458 | vty_out(vty, " Incoming update filter list for all interface is"); |
459 | has_print = 0; | |
460 | if (dist) { | |
461 | has_print = distribute_print(vty, dist->list, 0, | |
462 | DISTRIBUTE_V4_IN, has_print); | |
463 | has_print = distribute_print(vty, dist->prefix, 1, | |
464 | DISTRIBUTE_V4_IN, has_print); | |
465 | has_print = distribute_print(vty, dist->list, 0, | |
466 | DISTRIBUTE_V6_IN, has_print); | |
467 | has_print = distribute_print(vty, dist->prefix, 1, | |
468 | DISTRIBUTE_V6_IN, has_print); | |
469 | } | |
470 | if (has_print) | |
471 | vty_out(vty, "\n"); | |
472 | else | |
473 | vty_out(vty, " not set\n"); | |
474 | ||
03a38493 PG |
475 | for (i = 0; i < dist_ctxt->disthash->size; i++) |
476 | for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) { | |
d62a17ae | 477 | dist = mp->data; |
478 | if (dist->ifname) { | |
479 | vty_out(vty, " %s filtered by", | |
480 | dist->ifname); | |
481 | has_print = 0; | |
482 | has_print = distribute_print(vty, dist->list, 0, | |
483 | DISTRIBUTE_V4_IN, | |
484 | has_print); | |
485 | has_print = distribute_print( | |
486 | vty, dist->prefix, 1, DISTRIBUTE_V4_IN, | |
487 | has_print); | |
488 | has_print = distribute_print(vty, dist->list, 0, | |
489 | DISTRIBUTE_V6_IN, | |
490 | has_print); | |
491 | has_print = distribute_print( | |
492 | vty, dist->prefix, 1, DISTRIBUTE_V6_IN, | |
493 | has_print); | |
494 | if (has_print) | |
495 | vty_out(vty, "\n"); | |
496 | else | |
497 | vty_out(vty, " nothing\n"); | |
498 | } | |
499 | } | |
500 | return 0; | |
718e3744 | 501 | } |
502 | ||
503 | /* Configuration write function. */ | |
03a38493 PG |
504 | int config_write_distribute(struct vty *vty, |
505 | struct distribute_ctx *dist_ctxt) | |
718e3744 | 506 | { |
d62a17ae | 507 | unsigned int i; |
508 | int j; | |
509 | int output, v6; | |
e3b78da8 | 510 | struct hash_bucket *mp; |
d62a17ae | 511 | int write = 0; |
512 | ||
03a38493 PG |
513 | for (i = 0; i < dist_ctxt->disthash->size; i++) |
514 | for (mp = dist_ctxt->disthash->index[i]; mp; mp = mp->next) { | |
d62a17ae | 515 | struct distribute *dist; |
516 | ||
517 | dist = mp->data; | |
518 | ||
519 | for (j = 0; j < DISTRIBUTE_MAX; j++) | |
520 | if (dist->list[j]) { | |
521 | output = j == DISTRIBUTE_V4_OUT | |
522 | || j == DISTRIBUTE_V6_OUT; | |
523 | v6 = j == DISTRIBUTE_V6_IN | |
524 | || j == DISTRIBUTE_V6_OUT; | |
525 | vty_out(vty, | |
526 | " %sdistribute-list %s %s %s\n", | |
527 | v6 ? "ipv6 " : "", | |
528 | dist->list[j], | |
529 | output ? "out" : "in", | |
530 | dist->ifname ? dist->ifname | |
531 | : ""); | |
532 | write++; | |
533 | } | |
534 | ||
535 | for (j = 0; j < DISTRIBUTE_MAX; j++) | |
536 | if (dist->prefix[j]) { | |
537 | output = j == DISTRIBUTE_V4_OUT | |
538 | || j == DISTRIBUTE_V6_OUT; | |
539 | v6 = j == DISTRIBUTE_V6_IN | |
540 | || j == DISTRIBUTE_V6_OUT; | |
541 | vty_out(vty, | |
542 | " %sdistribute-list prefix %s %s %s\n", | |
543 | v6 ? "ipv6 " : "", | |
544 | dist->prefix[j], | |
545 | output ? "out" : "in", | |
546 | dist->ifname ? dist->ifname | |
547 | : ""); | |
548 | write++; | |
549 | } | |
550 | } | |
551 | return write; | |
718e3744 | 552 | } |
553 | ||
03a38493 | 554 | void distribute_list_delete(struct distribute_ctx **ctx) |
718e3744 | 555 | { |
03a38493 PG |
556 | if ((*ctx)->disthash) { |
557 | hash_clean((*ctx)->disthash, (void (*)(void *))distribute_free); | |
558 | } | |
559 | if (!dist_ctx_list) | |
560 | dist_ctx_list = list_new(); | |
561 | listnode_delete(dist_ctx_list, *ctx); | |
562 | if (list_isempty(dist_ctx_list)) | |
563 | list_delete(&dist_ctx_list); | |
564 | XFREE(MTYPE_DISTRIBUTE_CTX, (*ctx)); | |
718e3744 | 565 | } |
566 | ||
03a38493 PG |
567 | /* Initialize distribute list container */ |
568 | struct distribute_ctx *distribute_list_ctx_create(struct vrf *vrf) | |
718e3744 | 569 | { |
03a38493 PG |
570 | struct distribute_ctx *ctx; |
571 | ||
572 | ctx = XCALLOC(MTYPE_DISTRIBUTE_CTX, sizeof(struct distribute_ctx)); | |
573 | ctx->vrf = vrf; | |
574 | ctx->disthash = hash_create( | |
d62a17ae | 575 | distribute_hash_make, |
74df8d6d | 576 | (bool (*)(const void *, const void *))distribute_cmp, NULL); |
03a38493 PG |
577 | if (!dist_ctx_list) |
578 | dist_ctx_list = list_new(); | |
579 | listnode_add(dist_ctx_list, ctx); | |
580 | return ctx; | |
581 | } | |
d62a17ae | 582 | |
03a38493 PG |
583 | /* Initialize distribute list vty commands */ |
584 | void distribute_list_init(int node) | |
585 | { | |
d62a17ae | 586 | /* vtysh command-extraction doesn't grok install_element(node, ) */ |
587 | if (node == RIP_NODE) { | |
588 | install_element(RIP_NODE, &distribute_list_cmd); | |
589 | install_element(RIP_NODE, &no_distribute_list_cmd); | |
590 | } else if (node == RIPNG_NODE) { | |
591 | install_element(RIPNG_NODE, &distribute_list_cmd); | |
592 | install_element(RIPNG_NODE, &no_distribute_list_cmd); | |
03a38493 | 593 | /* install v6 */ |
d62a17ae | 594 | install_element(RIPNG_NODE, &ipv6_distribute_list_cmd); |
96f05398 | 595 | install_element(RIPNG_NODE, &no_ipv6_distribute_list_cmd); |
d62a17ae | 596 | } |
597 | ||
598 | /* TODO: install v4 syntax command for v6 only protocols. */ | |
599 | /* if (node == RIPNG_NODE) { | |
600 | * install_element (node, &ipv6_as_v4_distribute_list_all_cmd); | |
601 | * install_element (node, &no_ipv6_as_v4_distribute_list_all_cmd); | |
602 | * install_element (node, &ipv6_as_v4_distribute_list_cmd); | |
603 | * install_element (node, &no_ipv6_as_v4_distribute_list_cmd); | |
604 | * install_element (node, &ipv6_as_v4_distribute_list_prefix_all_cmd); | |
605 | * install_element (node, | |
606 | &no_ipv6_as_v4_distribute_list_prefix_all_cmd); | |
607 | * install_element (node, &ipv6_as_v4_distribute_list_prefix_cmd); | |
608 | * install_element (node, &no_ipv6_as_v4_distribute_list_prefix_cmd); | |
609 | }*/ | |
718e3744 | 610 | } |