blob: 906e3f6d9c0df26631e144584e6a82461b6a0cdd [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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 *
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 "hash.h"
25#include "if.h"
26#include "filter.h"
27#include "command.h"
28#include "distribute.h"
29#include "memory.h"
30
31/* Hash of distribute list. */
32struct hash *disthash;
33
34/* Hook functions. */
35void (*distribute_add_hook) (struct distribute *);
36void (*distribute_delete_hook) (struct distribute *);
37
paul8cc41982005-05-06 21:25:49 +000038static struct distribute *
39distribute_new (void)
paul718e3742002-12-13 20:15:29 +000040{
41 struct distribute *new;
42
43 new = XMALLOC (MTYPE_DISTRIBUTE, sizeof (struct distribute));
44 memset (new, 0, sizeof (struct distribute));
45
46 return new;
47}
48
49/* Free distribute object. */
paul8cc41982005-05-06 21:25:49 +000050static void
paul718e3742002-12-13 20:15:29 +000051distribute_free (struct distribute *dist)
52{
53 if (dist->ifname)
paul9035efa2004-10-10 11:56:56 +000054 XFREE (MTYPE_DISTRIBUTE_IFNAME, dist->ifname);
paul718e3742002-12-13 20:15:29 +000055
56 if (dist->list[DISTRIBUTE_IN])
57 free (dist->list[DISTRIBUTE_IN]);
58 if (dist->list[DISTRIBUTE_OUT])
59 free (dist->list[DISTRIBUTE_OUT]);
60
61 if (dist->prefix[DISTRIBUTE_IN])
62 free (dist->prefix[DISTRIBUTE_IN]);
63 if (dist->prefix[DISTRIBUTE_OUT])
64 free (dist->prefix[DISTRIBUTE_OUT]);
65
66 XFREE (MTYPE_DISTRIBUTE, dist);
67}
68
69/* Lookup interface's distribute list. */
70struct distribute *
paul9035efa2004-10-10 11:56:56 +000071distribute_lookup (const char *ifname)
paul718e3742002-12-13 20:15:29 +000072{
73 struct distribute key;
74 struct distribute *dist;
75
paul9035efa2004-10-10 11:56:56 +000076 /* temporary reference */
77 key.ifname = (char *)ifname;
paul718e3742002-12-13 20:15:29 +000078
79 dist = hash_lookup (disthash, &key);
80
81 return dist;
82}
83
84void
85distribute_list_add_hook (void (*func) (struct distribute *))
86{
87 distribute_add_hook = func;
88}
89
90void
91distribute_list_delete_hook (void (*func) (struct distribute *))
92{
93 distribute_delete_hook = func;
94}
95
paul8cc41982005-05-06 21:25:49 +000096static void *
paul718e3742002-12-13 20:15:29 +000097distribute_hash_alloc (struct distribute *arg)
98{
99 struct distribute *dist;
100
101 dist = distribute_new ();
102 if (arg->ifname)
paul9035efa2004-10-10 11:56:56 +0000103 dist->ifname = XSTRDUP (MTYPE_DISTRIBUTE_IFNAME, arg->ifname);
paul718e3742002-12-13 20:15:29 +0000104 else
105 dist->ifname = NULL;
106 return dist;
107}
108
109/* Make new distribute list and push into hash. */
paul8cc41982005-05-06 21:25:49 +0000110static struct distribute *
paul9035efa2004-10-10 11:56:56 +0000111distribute_get (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000112{
113 struct distribute key;
114
paul9035efa2004-10-10 11:56:56 +0000115 /* temporary reference */
116 key.ifname = (char *)ifname;
117
paul8cc41982005-05-06 21:25:49 +0000118 return hash_get (disthash, &key, (void * (*) (void *))distribute_hash_alloc);
paul718e3742002-12-13 20:15:29 +0000119}
120
paul8cc41982005-05-06 21:25:49 +0000121static unsigned int
paul718e3742002-12-13 20:15:29 +0000122distribute_hash_make (struct distribute *dist)
123{
hasso8c328f12004-10-05 21:01:23 +0000124 unsigned int i, key;
paul718e3742002-12-13 20:15:29 +0000125
126 key = 0;
127 if (dist->ifname)
128 for (i = 0; i < strlen (dist->ifname); i++)
129 key += dist->ifname[i];
130
131 return key;
132}
133
134/* If two distribute-list have same value then return 1 else return
135 0. This function is used by hash package. */
paul8cc41982005-05-06 21:25:49 +0000136static int
Stephen Hemmingerffe11cf2008-08-14 16:25:25 +0100137distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
paul718e3742002-12-13 20:15:29 +0000138{
139 if (dist1->ifname && dist2->ifname)
140 if (strcmp (dist1->ifname, dist2->ifname) == 0)
141 return 1;
142 if (! dist1->ifname && ! dist2->ifname)
143 return 1;
144 return 0;
145}
146
147/* Set access-list name to the distribute list. */
paul8cc41982005-05-06 21:25:49 +0000148static struct distribute *
paul9035efa2004-10-10 11:56:56 +0000149distribute_list_set (const char *ifname, enum distribute_type type,
150 const char *alist_name)
paul718e3742002-12-13 20:15:29 +0000151{
152 struct distribute *dist;
153
154 dist = distribute_get (ifname);
155
156 if (type == DISTRIBUTE_IN)
157 {
158 if (dist->list[DISTRIBUTE_IN])
159 free (dist->list[DISTRIBUTE_IN]);
160 dist->list[DISTRIBUTE_IN] = strdup (alist_name);
161 }
162 if (type == DISTRIBUTE_OUT)
163 {
164 if (dist->list[DISTRIBUTE_OUT])
165 free (dist->list[DISTRIBUTE_OUT]);
166 dist->list[DISTRIBUTE_OUT] = strdup (alist_name);
167 }
168
169 /* Apply this distribute-list to the interface. */
170 (*distribute_add_hook) (dist);
171
172 return dist;
173}
174
175/* Unset distribute-list. If matched distribute-list exist then
176 return 1. */
paul8cc41982005-05-06 21:25:49 +0000177static int
paul9035efa2004-10-10 11:56:56 +0000178distribute_list_unset (const char *ifname, enum distribute_type type,
179 const char *alist_name)
paul718e3742002-12-13 20:15:29 +0000180{
181 struct distribute *dist;
182
183 dist = distribute_lookup (ifname);
184 if (!dist)
185 return 0;
186
187 if (type == DISTRIBUTE_IN)
188 {
189 if (!dist->list[DISTRIBUTE_IN])
190 return 0;
191 if (strcmp (dist->list[DISTRIBUTE_IN], alist_name) != 0)
192 return 0;
193
194 free (dist->list[DISTRIBUTE_IN]);
195 dist->list[DISTRIBUTE_IN] = NULL;
196 }
197
198 if (type == DISTRIBUTE_OUT)
199 {
200 if (!dist->list[DISTRIBUTE_OUT])
201 return 0;
202 if (strcmp (dist->list[DISTRIBUTE_OUT], alist_name) != 0)
203 return 0;
204
205 free (dist->list[DISTRIBUTE_OUT]);
206 dist->list[DISTRIBUTE_OUT] = NULL;
207 }
208
209 /* Apply this distribute-list to the interface. */
210 (*distribute_delete_hook) (dist);
211
212 /* If both out and in is NULL then free distribute list. */
213 if (dist->list[DISTRIBUTE_IN] == NULL &&
214 dist->list[DISTRIBUTE_OUT] == NULL &&
215 dist->prefix[DISTRIBUTE_IN] == NULL &&
216 dist->prefix[DISTRIBUTE_OUT] == NULL)
217 {
218 hash_release (disthash, dist);
219 distribute_free (dist);
220 }
221
222 return 1;
223}
224
225/* Set access-list name to the distribute list. */
paul8cc41982005-05-06 21:25:49 +0000226static struct distribute *
paul9035efa2004-10-10 11:56:56 +0000227distribute_list_prefix_set (const char *ifname, enum distribute_type type,
228 const char *plist_name)
paul718e3742002-12-13 20:15:29 +0000229{
230 struct distribute *dist;
231
232 dist = distribute_get (ifname);
233
234 if (type == DISTRIBUTE_IN)
235 {
236 if (dist->prefix[DISTRIBUTE_IN])
237 free (dist->prefix[DISTRIBUTE_IN]);
238 dist->prefix[DISTRIBUTE_IN] = strdup (plist_name);
239 }
240 if (type == DISTRIBUTE_OUT)
241 {
242 if (dist->prefix[DISTRIBUTE_OUT])
243 free (dist->prefix[DISTRIBUTE_OUT]);
244 dist->prefix[DISTRIBUTE_OUT] = strdup (plist_name);
245 }
246
247 /* Apply this distribute-list to the interface. */
248 (*distribute_add_hook) (dist);
249
250 return dist;
251}
252
253/* Unset distribute-list. If matched distribute-list exist then
254 return 1. */
paul8cc41982005-05-06 21:25:49 +0000255static int
paul9035efa2004-10-10 11:56:56 +0000256distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
257 const char *plist_name)
paul718e3742002-12-13 20:15:29 +0000258{
259 struct distribute *dist;
260
261 dist = distribute_lookup (ifname);
262 if (!dist)
263 return 0;
264
265 if (type == DISTRIBUTE_IN)
266 {
267 if (!dist->prefix[DISTRIBUTE_IN])
268 return 0;
269 if (strcmp (dist->prefix[DISTRIBUTE_IN], plist_name) != 0)
270 return 0;
271
272 free (dist->prefix[DISTRIBUTE_IN]);
273 dist->prefix[DISTRIBUTE_IN] = NULL;
274 }
275
276 if (type == DISTRIBUTE_OUT)
277 {
278 if (!dist->prefix[DISTRIBUTE_OUT])
279 return 0;
280 if (strcmp (dist->prefix[DISTRIBUTE_OUT], plist_name) != 0)
281 return 0;
282
283 free (dist->prefix[DISTRIBUTE_OUT]);
284 dist->prefix[DISTRIBUTE_OUT] = NULL;
285 }
286
287 /* Apply this distribute-list to the interface. */
288 (*distribute_delete_hook) (dist);
289
290 /* If both out and in is NULL then free distribute list. */
291 if (dist->list[DISTRIBUTE_IN] == NULL &&
292 dist->list[DISTRIBUTE_OUT] == NULL &&
293 dist->prefix[DISTRIBUTE_IN] == NULL &&
294 dist->prefix[DISTRIBUTE_OUT] == NULL)
295 {
296 hash_release (disthash, dist);
297 distribute_free (dist);
298 }
299
300 return 1;
301}
302
303DEFUN (distribute_list_all,
304 distribute_list_all_cmd,
305 "distribute-list WORD (in|out)",
306 "Filter networks in routing updates\n"
307 "Access-list name\n"
308 "Filter incoming routing updates\n"
309 "Filter outgoing routing updates\n")
310{
311 enum distribute_type type;
312 struct distribute *dist;
313
314 /* Check of distribute list type. */
315 if (strncmp (argv[1], "i", 1) == 0)
316 type = DISTRIBUTE_IN;
317 else if (strncmp (argv[1], "o", 1) == 0)
318 type = DISTRIBUTE_OUT;
319 else
320 {
321 vty_out (vty, "distribute list direction must be [in|out]%s",
322 VTY_NEWLINE);
323 return CMD_WARNING;
324 }
325
326 /* Get interface name corresponding distribute list. */
327 dist = distribute_list_set (NULL, type, argv[0]);
328
329 return CMD_SUCCESS;
330}
331
paulba23a692003-04-19 15:55:08 +0000332ALIAS (distribute_list_all,
333 ipv6_distribute_list_all_cmd,
334 "distribute-list WORD (in|out)",
335 "Filter networks in routing updates\n"
336 "Access-list name\n"
337 "Filter incoming routing updates\n"
338 "Filter outgoing routing updates\n")
339
paul718e3742002-12-13 20:15:29 +0000340DEFUN (no_distribute_list_all,
341 no_distribute_list_all_cmd,
342 "no distribute-list WORD (in|out)",
343 NO_STR
344 "Filter networks in routing updates\n"
345 "Access-list name\n"
346 "Filter incoming routing updates\n"
347 "Filter outgoing routing updates\n")
348{
349 int ret;
350 enum distribute_type type;
351
352 /* Check of distribute list type. */
353 if (strncmp (argv[1], "i", 1) == 0)
354 type = DISTRIBUTE_IN;
355 else if (strncmp (argv[1], "o", 1) == 0)
356 type = DISTRIBUTE_OUT;
357 else
358 {
359 vty_out (vty, "distribute list direction must be [in|out]%s",
360 VTY_NEWLINE);
361 return CMD_WARNING;
362 }
363
364 ret = distribute_list_unset (NULL, type, argv[0]);
365 if (! ret)
366 {
367 vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
368 return CMD_WARNING;
369 }
370 return CMD_SUCCESS;
371}
372
paulba23a692003-04-19 15:55:08 +0000373ALIAS (no_distribute_list_all,
374 no_ipv6_distribute_list_all_cmd,
375 "no distribute-list WORD (in|out)",
376 NO_STR
377 "Filter networks in routing updates\n"
378 "Access-list name\n"
379 "Filter incoming routing updates\n"
380 "Filter outgoing routing updates\n")
381
paul718e3742002-12-13 20:15:29 +0000382DEFUN (distribute_list,
383 distribute_list_cmd,
384 "distribute-list WORD (in|out) WORD",
385 "Filter networks in routing updates\n"
386 "Access-list name\n"
387 "Filter incoming routing updates\n"
388 "Filter outgoing routing updates\n"
389 "Interface name\n")
390{
391 enum distribute_type type;
392 struct distribute *dist;
393
394 /* Check of distribute list type. */
395 if (strncmp (argv[1], "i", 1) == 0)
396 type = DISTRIBUTE_IN;
397 else if (strncmp (argv[1], "o", 1) == 0)
398 type = DISTRIBUTE_OUT;
399 else
400 {
401 vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
402 return CMD_WARNING;
403 }
404
405 /* Get interface name corresponding distribute list. */
406 dist = distribute_list_set (argv[2], type, argv[0]);
407
408 return CMD_SUCCESS;
409}
410
paulba23a692003-04-19 15:55:08 +0000411ALIAS (distribute_list,
412 ipv6_distribute_list_cmd,
413 "distribute-list WORD (in|out) WORD",
414 "Filter networks in routing updates\n"
415 "Access-list name\n"
416 "Filter incoming routing updates\n"
417 "Filter outgoing routing updates\n"
418 "Interface name\n")
419
paul718e3742002-12-13 20:15:29 +0000420DEFUN (no_districute_list, no_distribute_list_cmd,
421 "no distribute-list WORD (in|out) WORD",
422 NO_STR
423 "Filter networks in routing updates\n"
424 "Access-list name\n"
425 "Filter incoming routing updates\n"
426 "Filter outgoing routing updates\n"
427 "Interface name\n")
428{
429 int ret;
430 enum distribute_type type;
431
432 /* Check of distribute list type. */
433 if (strncmp (argv[1], "i", 1) == 0)
434 type = DISTRIBUTE_IN;
435 else if (strncmp (argv[1], "o", 1) == 0)
436 type = DISTRIBUTE_OUT;
437 else
438 {
439 vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
440 return CMD_WARNING;
441 }
442
443 ret = distribute_list_unset (argv[2], type, argv[0]);
444 if (! ret)
445 {
446 vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
447 return CMD_WARNING;
448 }
449 return CMD_SUCCESS;
450}
451
paulba23a692003-04-19 15:55:08 +0000452ALIAS (no_districute_list, no_ipv6_distribute_list_cmd,
453 "no distribute-list WORD (in|out) WORD",
454 NO_STR
455 "Filter networks in routing updates\n"
456 "Access-list name\n"
457 "Filter incoming routing updates\n"
458 "Filter outgoing routing updates\n"
459 "Interface name\n")
460
paul718e3742002-12-13 20:15:29 +0000461DEFUN (districute_list_prefix_all,
462 distribute_list_prefix_all_cmd,
463 "distribute-list prefix WORD (in|out)",
464 "Filter networks in routing updates\n"
465 "Filter prefixes in routing updates\n"
466 "Name of an IP prefix-list\n"
467 "Filter incoming routing updates\n"
468 "Filter outgoing routing updates\n")
469{
470 enum distribute_type type;
471 struct distribute *dist;
472
473 /* Check of distribute list type. */
474 if (strncmp (argv[1], "i", 1) == 0)
475 type = DISTRIBUTE_IN;
476 else if (strncmp (argv[1], "o", 1) == 0)
477 type = DISTRIBUTE_OUT;
478 else
479 {
480 vty_out (vty, "distribute list direction must be [in|out]%s",
481 VTY_NEWLINE);
482 return CMD_WARNING;
483 }
484
485 /* Get interface name corresponding distribute list. */
486 dist = distribute_list_prefix_set (NULL, type, argv[0]);
487
488 return CMD_SUCCESS;
489}
490
paulba23a692003-04-19 15:55:08 +0000491ALIAS (districute_list_prefix_all,
492 ipv6_distribute_list_prefix_all_cmd,
493 "distribute-list prefix WORD (in|out)",
494 "Filter networks in routing updates\n"
495 "Filter prefixes in routing updates\n"
496 "Name of an IP prefix-list\n"
497 "Filter incoming routing updates\n"
498 "Filter outgoing routing updates\n")
499
paul718e3742002-12-13 20:15:29 +0000500DEFUN (no_districute_list_prefix_all,
501 no_distribute_list_prefix_all_cmd,
502 "no distribute-list prefix WORD (in|out)",
503 NO_STR
504 "Filter networks in routing updates\n"
505 "Filter prefixes in routing updates\n"
506 "Name of an IP prefix-list\n"
507 "Filter incoming routing updates\n"
508 "Filter outgoing routing updates\n")
509{
510 int ret;
511 enum distribute_type type;
512
513 /* Check of distribute list type. */
514 if (strncmp (argv[1], "i", 1) == 0)
515 type = DISTRIBUTE_IN;
516 else if (strncmp (argv[1], "o", 1) == 0)
517 type = DISTRIBUTE_OUT;
518 else
519 {
520 vty_out (vty, "distribute list direction must be [in|out]%s",
521 VTY_NEWLINE);
522 return CMD_WARNING;
523 }
524
525 ret = distribute_list_prefix_unset (NULL, type, argv[0]);
526 if (! ret)
527 {
528 vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
529 return CMD_WARNING;
530 }
531 return CMD_SUCCESS;
532}
533
paulba23a692003-04-19 15:55:08 +0000534ALIAS (no_districute_list_prefix_all,
535 no_ipv6_distribute_list_prefix_all_cmd,
536 "no distribute-list prefix WORD (in|out)",
537 NO_STR
538 "Filter networks in routing updates\n"
539 "Filter prefixes in routing updates\n"
540 "Name of an IP prefix-list\n"
541 "Filter incoming routing updates\n"
542 "Filter outgoing routing updates\n")
543
paul718e3742002-12-13 20:15:29 +0000544DEFUN (districute_list_prefix, distribute_list_prefix_cmd,
545 "distribute-list prefix WORD (in|out) WORD",
546 "Filter networks in routing updates\n"
547 "Filter prefixes in routing updates\n"
548 "Name of an IP prefix-list\n"
549 "Filter incoming routing updates\n"
550 "Filter outgoing routing updates\n"
551 "Interface name\n")
552{
553 enum distribute_type type;
554 struct distribute *dist;
555
556 /* Check of distribute list type. */
557 if (strncmp (argv[1], "i", 1) == 0)
558 type = DISTRIBUTE_IN;
559 else if (strncmp (argv[1], "o", 1) == 0)
560 type = DISTRIBUTE_OUT;
561 else
562 {
563 vty_out (vty, "distribute list direction must be [in|out]%s",
564 VTY_NEWLINE);
565 return CMD_WARNING;
566 }
567
568 /* Get interface name corresponding distribute list. */
569 dist = distribute_list_prefix_set (argv[2], type, argv[0]);
570
571 return CMD_SUCCESS;
572}
573
paulba23a692003-04-19 15:55:08 +0000574ALIAS (districute_list_prefix, ipv6_distribute_list_prefix_cmd,
575 "distribute-list prefix WORD (in|out) WORD",
576 "Filter networks in routing updates\n"
577 "Filter prefixes in routing updates\n"
578 "Name of an IP prefix-list\n"
579 "Filter incoming routing updates\n"
580 "Filter outgoing routing updates\n"
581 "Interface name\n")
582
paul718e3742002-12-13 20:15:29 +0000583DEFUN (no_districute_list_prefix, no_distribute_list_prefix_cmd,
584 "no distribute-list prefix WORD (in|out) WORD",
585 NO_STR
586 "Filter networks in routing updates\n"
587 "Filter prefixes in routing updates\n"
588 "Name of an IP prefix-list\n"
589 "Filter incoming routing updates\n"
590 "Filter outgoing routing updates\n"
591 "Interface name\n")
592{
593 int ret;
594 enum distribute_type type;
595
596 /* Check of distribute list type. */
597 if (strncmp (argv[1], "i", 1) == 0)
598 type = DISTRIBUTE_IN;
599 else if (strncmp (argv[1], "o", 1) == 0)
600 type = DISTRIBUTE_OUT;
601 else
602 {
603 vty_out (vty, "distribute list direction must be [in|out]%s",
604 VTY_NEWLINE);
605 return CMD_WARNING;
606 }
607
608 ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
609 if (! ret)
610 {
611 vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
612 return CMD_WARNING;
613 }
614 return CMD_SUCCESS;
615}
616
paulba23a692003-04-19 15:55:08 +0000617ALIAS (no_districute_list_prefix, no_ipv6_distribute_list_prefix_cmd,
618 "no distribute-list prefix WORD (in|out) WORD",
619 NO_STR
620 "Filter networks in routing updates\n"
621 "Filter prefixes in routing updates\n"
622 "Name of an IP prefix-list\n"
623 "Filter incoming routing updates\n"
624 "Filter outgoing routing updates\n"
625 "Interface name\n")
626
paul718e3742002-12-13 20:15:29 +0000627int
628config_show_distribute (struct vty *vty)
629{
hasso8c328f12004-10-05 21:01:23 +0000630 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000631 struct hash_backet *mp;
632 struct distribute *dist;
633
634 /* Output filter configuration. */
635 dist = distribute_lookup (NULL);
636 if (dist && (dist->list[DISTRIBUTE_OUT] || dist->prefix[DISTRIBUTE_OUT]))
637 {
638 vty_out (vty, " Outgoing update filter list for all interface is");
639 if (dist->list[DISTRIBUTE_OUT])
640 vty_out (vty, " %s", dist->list[DISTRIBUTE_OUT]);
641 if (dist->prefix[DISTRIBUTE_OUT])
642 vty_out (vty, "%s (prefix-list) %s",
643 dist->list[DISTRIBUTE_OUT] ? "," : "",
644 dist->prefix[DISTRIBUTE_OUT]);
645 vty_out (vty, "%s", VTY_NEWLINE);
646 }
647 else
648 vty_out (vty, " Outgoing update filter list for all interface is not set%s", VTY_NEWLINE);
649
650 for (i = 0; i < disthash->size; i++)
651 for (mp = disthash->index[i]; mp; mp = mp->next)
652 {
653 dist = mp->data;
654 if (dist->ifname)
655 if (dist->list[DISTRIBUTE_OUT] || dist->prefix[DISTRIBUTE_OUT])
656 {
657 vty_out (vty, " %s filtered by", dist->ifname);
658 if (dist->list[DISTRIBUTE_OUT])
659 vty_out (vty, " %s", dist->list[DISTRIBUTE_OUT]);
660 if (dist->prefix[DISTRIBUTE_OUT])
661 vty_out (vty, "%s (prefix-list) %s",
662 dist->list[DISTRIBUTE_OUT] ? "," : "",
663 dist->prefix[DISTRIBUTE_OUT]);
664 vty_out (vty, "%s", VTY_NEWLINE);
665 }
666 }
667
668
669 /* Input filter configuration. */
670 dist = distribute_lookup (NULL);
671 if (dist && (dist->list[DISTRIBUTE_IN] || dist->prefix[DISTRIBUTE_IN]))
672 {
673 vty_out (vty, " Incoming update filter list for all interface is");
674 if (dist->list[DISTRIBUTE_IN])
675 vty_out (vty, " %s", dist->list[DISTRIBUTE_IN]);
676 if (dist->prefix[DISTRIBUTE_IN])
677 vty_out (vty, "%s (prefix-list) %s",
678 dist->list[DISTRIBUTE_IN] ? "," : "",
679 dist->prefix[DISTRIBUTE_IN]);
680 vty_out (vty, "%s", VTY_NEWLINE);
681 }
682 else
683 vty_out (vty, " Incoming update filter list for all interface is not set%s", VTY_NEWLINE);
684
685 for (i = 0; i < disthash->size; i++)
686 for (mp = disthash->index[i]; mp; mp = mp->next)
687 {
688 dist = mp->data;
689 if (dist->ifname)
690 if (dist->list[DISTRIBUTE_IN] || dist->prefix[DISTRIBUTE_IN])
691 {
692 vty_out (vty, " %s filtered by", dist->ifname);
693 if (dist->list[DISTRIBUTE_IN])
694 vty_out (vty, " %s", dist->list[DISTRIBUTE_IN]);
695 if (dist->prefix[DISTRIBUTE_IN])
696 vty_out (vty, "%s (prefix-list) %s",
697 dist->list[DISTRIBUTE_IN] ? "," : "",
698 dist->prefix[DISTRIBUTE_IN]);
699 vty_out (vty, "%s", VTY_NEWLINE);
700 }
701 }
702 return 0;
703}
704
705/* Configuration write function. */
706int
707config_write_distribute (struct vty *vty)
708{
hasso8c328f12004-10-05 21:01:23 +0000709 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000710 struct hash_backet *mp;
711 int write = 0;
712
713 for (i = 0; i < disthash->size; i++)
714 for (mp = disthash->index[i]; mp; mp = mp->next)
715 {
716 struct distribute *dist;
717
718 dist = mp->data;
719
720 if (dist->list[DISTRIBUTE_IN])
721 {
722 vty_out (vty, " distribute-list %s in %s%s",
723 dist->list[DISTRIBUTE_IN],
724 dist->ifname ? dist->ifname : "",
725 VTY_NEWLINE);
726 write++;
727 }
728
729 if (dist->list[DISTRIBUTE_OUT])
730 {
731 vty_out (vty, " distribute-list %s out %s%s",
732
733 dist->list[DISTRIBUTE_OUT],
734 dist->ifname ? dist->ifname : "",
735 VTY_NEWLINE);
736 write++;
737 }
738
739 if (dist->prefix[DISTRIBUTE_IN])
740 {
741 vty_out (vty, " distribute-list prefix %s in %s%s",
742 dist->prefix[DISTRIBUTE_IN],
743 dist->ifname ? dist->ifname : "",
744 VTY_NEWLINE);
745 write++;
746 }
747
748 if (dist->prefix[DISTRIBUTE_OUT])
749 {
750 vty_out (vty, " distribute-list prefix %s out %s%s",
751 dist->prefix[DISTRIBUTE_OUT],
752 dist->ifname ? dist->ifname : "",
753 VTY_NEWLINE);
754 write++;
755 }
756 }
757 return write;
758}
759
760/* Clear all distribute list. */
761void
762distribute_list_reset ()
763{
764 hash_clean (disthash, (void (*) (void *)) distribute_free);
765}
766
767/* Initialize distribute list related hash. */
768void
769distribute_list_init (int node)
770{
paul8cc41982005-05-06 21:25:49 +0000771 disthash = hash_create ((unsigned int (*) (void *)) distribute_hash_make,
Stephen Hemmingerffe11cf2008-08-14 16:25:25 +0100772 (int (*) (const void *, const void *)) distribute_cmp);
paul718e3742002-12-13 20:15:29 +0000773
paulba23a692003-04-19 15:55:08 +0000774 if(node==RIP_NODE) {
775 install_element (RIP_NODE, &distribute_list_all_cmd);
776 install_element (RIP_NODE, &no_distribute_list_all_cmd);
777 install_element (RIP_NODE, &distribute_list_cmd);
778 install_element (RIP_NODE, &no_distribute_list_cmd);
779 install_element (RIP_NODE, &distribute_list_prefix_all_cmd);
780 install_element (RIP_NODE, &no_distribute_list_prefix_all_cmd);
781 install_element (RIP_NODE, &distribute_list_prefix_cmd);
782 install_element (RIP_NODE, &no_distribute_list_prefix_cmd);
783 } else {
784 install_element (RIPNG_NODE, &ipv6_distribute_list_all_cmd);
785 install_element (RIPNG_NODE, &no_ipv6_distribute_list_all_cmd);
786 install_element (RIPNG_NODE, &ipv6_distribute_list_cmd);
787 install_element (RIPNG_NODE, &no_ipv6_distribute_list_cmd);
788 install_element (RIPNG_NODE, &ipv6_distribute_list_prefix_all_cmd);
789 install_element (RIPNG_NODE, &no_ipv6_distribute_list_prefix_all_cmd);
790 install_element (RIPNG_NODE, &ipv6_distribute_list_prefix_cmd);
791 install_element (RIPNG_NODE, &no_ipv6_distribute_list_prefix_cmd);
792 }
paul718e3742002-12-13 20:15:29 +0000793}