distribute.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. *
  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. #include <zebra.h>
  22. #include "hash.h"
  23. #include "if.h"
  24. #include "filter.h"
  25. #include "command.h"
  26. #include "distribute.h"
  27. #include "memory.h"
  28. /* Hash of distribute list. */
  29. struct hash *disthash;
  30. /* Hook functions. */
  31. void (*distribute_add_hook) (struct distribute *);
  32. void (*distribute_delete_hook) (struct distribute *);
  33. static struct distribute *
  34. distribute_new (void)
  35. {
  36. return XCALLOC (MTYPE_DISTRIBUTE, sizeof (struct distribute));
  37. }
  38. /* Free distribute object. */
  39. static void
  40. distribute_free (struct distribute *dist)
  41. {
  42. if (dist->ifname)
  43. XFREE (MTYPE_DISTRIBUTE_IFNAME, dist->ifname);
  44. if (dist->list[DISTRIBUTE_IN])
  45. free (dist->list[DISTRIBUTE_IN]);
  46. if (dist->list[DISTRIBUTE_OUT])
  47. free (dist->list[DISTRIBUTE_OUT]);
  48. if (dist->prefix[DISTRIBUTE_IN])
  49. free (dist->prefix[DISTRIBUTE_IN]);
  50. if (dist->prefix[DISTRIBUTE_OUT])
  51. free (dist->prefix[DISTRIBUTE_OUT]);
  52. XFREE (MTYPE_DISTRIBUTE, dist);
  53. }
  54. /* Lookup interface's distribute list. */
  55. struct distribute *
  56. distribute_lookup (const char *ifname)
  57. {
  58. struct distribute key;
  59. struct distribute *dist;
  60. /* temporary reference */
  61. key.ifname = (char *)ifname;
  62. dist = hash_lookup (disthash, &key);
  63. return dist;
  64. }
  65. void
  66. distribute_list_add_hook (void (*func) (struct distribute *))
  67. {
  68. distribute_add_hook = func;
  69. }
  70. void
  71. distribute_list_delete_hook (void (*func) (struct distribute *))
  72. {
  73. distribute_delete_hook = func;
  74. }
  75. static void *
  76. distribute_hash_alloc (struct distribute *arg)
  77. {
  78. struct distribute *dist;
  79. dist = distribute_new ();
  80. if (arg->ifname)
  81. dist->ifname = XSTRDUP (MTYPE_DISTRIBUTE_IFNAME, arg->ifname);
  82. else
  83. dist->ifname = NULL;
  84. return dist;
  85. }
  86. /* Make new distribute list and push into hash. */
  87. static struct distribute *
  88. distribute_get (const char *ifname)
  89. {
  90. struct distribute key;
  91. /* temporary reference */
  92. key.ifname = (char *)ifname;
  93. return hash_get (disthash, &key, (void * (*) (void *))distribute_hash_alloc);
  94. }
  95. static unsigned int
  96. distribute_hash_make (struct distribute *dist)
  97. {
  98. unsigned int i, key;
  99. key = 0;
  100. if (dist->ifname)
  101. for (i = 0; i < strlen (dist->ifname); i++)
  102. key += dist->ifname[i];
  103. return key;
  104. }
  105. /* If two distribute-list have same value then return 1 else return
  106. 0. This function is used by hash package. */
  107. static int
  108. distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
  109. {
  110. if (dist1->ifname && dist2->ifname)
  111. if (strcmp (dist1->ifname, dist2->ifname) == 0)
  112. return 1;
  113. if (! dist1->ifname && ! dist2->ifname)
  114. return 1;
  115. return 0;
  116. }
  117. /* Set access-list name to the distribute list. */
  118. static struct distribute *
  119. distribute_list_set (const char *ifname, enum distribute_type type,
  120. const char *alist_name)
  121. {
  122. struct distribute *dist;
  123. dist = distribute_get (ifname);
  124. if (type == DISTRIBUTE_IN)
  125. {
  126. if (dist->list[DISTRIBUTE_IN])
  127. free (dist->list[DISTRIBUTE_IN]);
  128. dist->list[DISTRIBUTE_IN] = strdup (alist_name);
  129. }
  130. if (type == DISTRIBUTE_OUT)
  131. {
  132. if (dist->list[DISTRIBUTE_OUT])
  133. free (dist->list[DISTRIBUTE_OUT]);
  134. dist->list[DISTRIBUTE_OUT] = strdup (alist_name);
  135. }
  136. /* Apply this distribute-list to the interface. */
  137. (*distribute_add_hook) (dist);
  138. return dist;
  139. }
  140. /* Unset distribute-list. If matched distribute-list exist then
  141. return 1. */
  142. static int
  143. distribute_list_unset (const char *ifname, enum distribute_type type,
  144. const char *alist_name)
  145. {
  146. struct distribute *dist;
  147. dist = distribute_lookup (ifname);
  148. if (!dist)
  149. return 0;
  150. if (type == DISTRIBUTE_IN)
  151. {
  152. if (!dist->list[DISTRIBUTE_IN])
  153. return 0;
  154. if (strcmp (dist->list[DISTRIBUTE_IN], alist_name) != 0)
  155. return 0;
  156. free (dist->list[DISTRIBUTE_IN]);
  157. dist->list[DISTRIBUTE_IN] = NULL;
  158. }
  159. if (type == DISTRIBUTE_OUT)
  160. {
  161. if (!dist->list[DISTRIBUTE_OUT])
  162. return 0;
  163. if (strcmp (dist->list[DISTRIBUTE_OUT], alist_name) != 0)
  164. return 0;
  165. free (dist->list[DISTRIBUTE_OUT]);
  166. dist->list[DISTRIBUTE_OUT] = NULL;
  167. }
  168. /* Apply this distribute-list to the interface. */
  169. (*distribute_delete_hook) (dist);
  170. /* If both out and in is NULL then free distribute list. */
  171. if (dist->list[DISTRIBUTE_IN] == NULL &&
  172. dist->list[DISTRIBUTE_OUT] == NULL &&
  173. dist->prefix[DISTRIBUTE_IN] == NULL &&
  174. dist->prefix[DISTRIBUTE_OUT] == NULL)
  175. {
  176. hash_release (disthash, dist);
  177. distribute_free (dist);
  178. }
  179. return 1;
  180. }
  181. /* Set access-list name to the distribute list. */
  182. static struct distribute *
  183. distribute_list_prefix_set (const char *ifname, enum distribute_type type,
  184. const char *plist_name)
  185. {
  186. struct distribute *dist;
  187. dist = distribute_get (ifname);
  188. if (type == DISTRIBUTE_IN)
  189. {
  190. if (dist->prefix[DISTRIBUTE_IN])
  191. free (dist->prefix[DISTRIBUTE_IN]);
  192. dist->prefix[DISTRIBUTE_IN] = strdup (plist_name);
  193. }
  194. if (type == DISTRIBUTE_OUT)
  195. {
  196. if (dist->prefix[DISTRIBUTE_OUT])
  197. free (dist->prefix[DISTRIBUTE_OUT]);
  198. dist->prefix[DISTRIBUTE_OUT] = strdup (plist_name);
  199. }
  200. /* Apply this distribute-list to the interface. */
  201. (*distribute_add_hook) (dist);
  202. return dist;
  203. }
  204. /* Unset distribute-list. If matched distribute-list exist then
  205. return 1. */
  206. static int
  207. distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
  208. const char *plist_name)
  209. {
  210. struct distribute *dist;
  211. dist = distribute_lookup (ifname);
  212. if (!dist)
  213. return 0;
  214. if (type == DISTRIBUTE_IN)
  215. {
  216. if (!dist->prefix[DISTRIBUTE_IN])
  217. return 0;
  218. if (strcmp (dist->prefix[DISTRIBUTE_IN], plist_name) != 0)
  219. return 0;
  220. free (dist->prefix[DISTRIBUTE_IN]);
  221. dist->prefix[DISTRIBUTE_IN] = NULL;
  222. }
  223. if (type == DISTRIBUTE_OUT)
  224. {
  225. if (!dist->prefix[DISTRIBUTE_OUT])
  226. return 0;
  227. if (strcmp (dist->prefix[DISTRIBUTE_OUT], plist_name) != 0)
  228. return 0;
  229. free (dist->prefix[DISTRIBUTE_OUT]);
  230. dist->prefix[DISTRIBUTE_OUT] = NULL;
  231. }
  232. /* Apply this distribute-list to the interface. */
  233. (*distribute_delete_hook) (dist);
  234. /* If both out and in is NULL then free distribute list. */
  235. if (dist->list[DISTRIBUTE_IN] == NULL &&
  236. dist->list[DISTRIBUTE_OUT] == NULL &&
  237. dist->prefix[DISTRIBUTE_IN] == NULL &&
  238. dist->prefix[DISTRIBUTE_OUT] == NULL)
  239. {
  240. hash_release (disthash, dist);
  241. distribute_free (dist);
  242. }
  243. return 1;
  244. }
  245. DEFUN (distribute_list_all,
  246. distribute_list_all_cmd,
  247. "distribute-list WORD (in|out)",
  248. "Filter networks in routing updates\n"
  249. "Access-list name\n"
  250. "Filter incoming routing updates\n"
  251. "Filter outgoing routing updates\n")
  252. {
  253. enum distribute_type type;
  254. struct distribute *dist;
  255. /* Check of distribute list type. */
  256. if (strncmp (argv[1], "i", 1) == 0)
  257. type = DISTRIBUTE_IN;
  258. else if (strncmp (argv[1], "o", 1) == 0)
  259. type = DISTRIBUTE_OUT;
  260. else
  261. {
  262. vty_out (vty, "distribute list direction must be [in|out]%s",
  263. VTY_NEWLINE);
  264. return CMD_WARNING;
  265. }
  266. /* Get interface name corresponding distribute list. */
  267. dist = distribute_list_set (NULL, type, argv[0]);
  268. return CMD_SUCCESS;
  269. }
  270. ALIAS (distribute_list_all,
  271. ipv6_distribute_list_all_cmd,
  272. "distribute-list WORD (in|out)",
  273. "Filter networks in routing updates\n"
  274. "Access-list name\n"
  275. "Filter incoming routing updates\n"
  276. "Filter outgoing routing updates\n")
  277. DEFUN (no_distribute_list_all,
  278. no_distribute_list_all_cmd,
  279. "no distribute-list WORD (in|out)",
  280. NO_STR
  281. "Filter networks in routing updates\n"
  282. "Access-list name\n"
  283. "Filter incoming routing updates\n"
  284. "Filter outgoing routing updates\n")
  285. {
  286. int ret;
  287. enum distribute_type type;
  288. /* Check of distribute list type. */
  289. if (strncmp (argv[1], "i", 1) == 0)
  290. type = DISTRIBUTE_IN;
  291. else if (strncmp (argv[1], "o", 1) == 0)
  292. type = DISTRIBUTE_OUT;
  293. else
  294. {
  295. vty_out (vty, "distribute list direction must be [in|out]%s",
  296. VTY_NEWLINE);
  297. return CMD_WARNING;
  298. }
  299. ret = distribute_list_unset (NULL, type, argv[0]);
  300. if (! ret)
  301. {
  302. vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
  303. return CMD_WARNING;
  304. }
  305. return CMD_SUCCESS;
  306. }
  307. ALIAS (no_distribute_list_all,
  308. no_ipv6_distribute_list_all_cmd,
  309. "no distribute-list WORD (in|out)",
  310. NO_STR
  311. "Filter networks in routing updates\n"
  312. "Access-list name\n"
  313. "Filter incoming routing updates\n"
  314. "Filter outgoing routing updates\n")
  315. DEFUN (distribute_list,
  316. distribute_list_cmd,
  317. "distribute-list WORD (in|out) WORD",
  318. "Filter networks in routing updates\n"
  319. "Access-list name\n"
  320. "Filter incoming routing updates\n"
  321. "Filter outgoing routing updates\n"
  322. "Interface name\n")
  323. {
  324. enum distribute_type type;
  325. struct distribute *dist;
  326. /* Check of distribute list type. */
  327. if (strncmp (argv[1], "i", 1) == 0)
  328. type = DISTRIBUTE_IN;
  329. else if (strncmp (argv[1], "o", 1) == 0)
  330. type = DISTRIBUTE_OUT;
  331. else
  332. {
  333. vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
  334. return CMD_WARNING;
  335. }
  336. /* Get interface name corresponding distribute list. */
  337. dist = distribute_list_set (argv[2], type, argv[0]);
  338. return CMD_SUCCESS;
  339. }
  340. ALIAS (distribute_list,
  341. ipv6_distribute_list_cmd,
  342. "distribute-list WORD (in|out) WORD",
  343. "Filter networks in routing updates\n"
  344. "Access-list name\n"
  345. "Filter incoming routing updates\n"
  346. "Filter outgoing routing updates\n"
  347. "Interface name\n")
  348. DEFUN (no_districute_list, no_distribute_list_cmd,
  349. "no distribute-list WORD (in|out) WORD",
  350. NO_STR
  351. "Filter networks in routing updates\n"
  352. "Access-list name\n"
  353. "Filter incoming routing updates\n"
  354. "Filter outgoing routing updates\n"
  355. "Interface name\n")
  356. {
  357. int ret;
  358. enum distribute_type type;
  359. /* Check of distribute list type. */
  360. if (strncmp (argv[1], "i", 1) == 0)
  361. type = DISTRIBUTE_IN;
  362. else if (strncmp (argv[1], "o", 1) == 0)
  363. type = DISTRIBUTE_OUT;
  364. else
  365. {
  366. vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
  367. return CMD_WARNING;
  368. }
  369. ret = distribute_list_unset (argv[2], type, argv[0]);
  370. if (! ret)
  371. {
  372. vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
  373. return CMD_WARNING;
  374. }
  375. return CMD_SUCCESS;
  376. }
  377. ALIAS (no_districute_list, no_ipv6_distribute_list_cmd,
  378. "no distribute-list WORD (in|out) WORD",
  379. NO_STR
  380. "Filter networks in routing updates\n"
  381. "Access-list name\n"
  382. "Filter incoming routing updates\n"
  383. "Filter outgoing routing updates\n"
  384. "Interface name\n")
  385. DEFUN (districute_list_prefix_all,
  386. distribute_list_prefix_all_cmd,
  387. "distribute-list prefix WORD (in|out)",
  388. "Filter networks in routing updates\n"
  389. "Filter prefixes in routing updates\n"
  390. "Name of an IP prefix-list\n"
  391. "Filter incoming routing updates\n"
  392. "Filter outgoing routing updates\n")
  393. {
  394. enum distribute_type type;
  395. struct distribute *dist;
  396. /* Check of distribute list type. */
  397. if (strncmp (argv[1], "i", 1) == 0)
  398. type = DISTRIBUTE_IN;
  399. else if (strncmp (argv[1], "o", 1) == 0)
  400. type = DISTRIBUTE_OUT;
  401. else
  402. {
  403. vty_out (vty, "distribute list direction must be [in|out]%s",
  404. VTY_NEWLINE);
  405. return CMD_WARNING;
  406. }
  407. /* Get interface name corresponding distribute list. */
  408. dist = distribute_list_prefix_set (NULL, type, argv[0]);
  409. return CMD_SUCCESS;
  410. }
  411. ALIAS (districute_list_prefix_all,
  412. ipv6_distribute_list_prefix_all_cmd,
  413. "distribute-list prefix WORD (in|out)",
  414. "Filter networks in routing updates\n"
  415. "Filter prefixes in routing updates\n"
  416. "Name of an IP prefix-list\n"
  417. "Filter incoming routing updates\n"
  418. "Filter outgoing routing updates\n")
  419. DEFUN (no_districute_list_prefix_all,
  420. no_distribute_list_prefix_all_cmd,
  421. "no distribute-list prefix WORD (in|out)",
  422. NO_STR
  423. "Filter networks in routing updates\n"
  424. "Filter prefixes in routing updates\n"
  425. "Name of an IP prefix-list\n"
  426. "Filter incoming routing updates\n"
  427. "Filter outgoing routing updates\n")
  428. {
  429. int ret;
  430. enum distribute_type type;
  431. /* Check of distribute list type. */
  432. if (strncmp (argv[1], "i", 1) == 0)
  433. type = DISTRIBUTE_IN;
  434. else if (strncmp (argv[1], "o", 1) == 0)
  435. type = DISTRIBUTE_OUT;
  436. else
  437. {
  438. vty_out (vty, "distribute list direction must be [in|out]%s",
  439. VTY_NEWLINE);
  440. return CMD_WARNING;
  441. }
  442. ret = distribute_list_prefix_unset (NULL, type, argv[0]);
  443. if (! ret)
  444. {
  445. vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
  446. return CMD_WARNING;
  447. }
  448. return CMD_SUCCESS;
  449. }
  450. ALIAS (no_districute_list_prefix_all,
  451. no_ipv6_distribute_list_prefix_all_cmd,
  452. "no distribute-list prefix WORD (in|out)",
  453. NO_STR
  454. "Filter networks in routing updates\n"
  455. "Filter prefixes in routing updates\n"
  456. "Name of an IP prefix-list\n"
  457. "Filter incoming routing updates\n"
  458. "Filter outgoing routing updates\n")
  459. DEFUN (districute_list_prefix, distribute_list_prefix_cmd,
  460. "distribute-list prefix WORD (in|out) WORD",
  461. "Filter networks in routing updates\n"
  462. "Filter prefixes in routing updates\n"
  463. "Name of an IP prefix-list\n"
  464. "Filter incoming routing updates\n"
  465. "Filter outgoing routing updates\n"
  466. "Interface name\n")
  467. {
  468. enum distribute_type type;
  469. struct distribute *dist;
  470. /* Check of distribute list type. */
  471. if (strncmp (argv[1], "i", 1) == 0)
  472. type = DISTRIBUTE_IN;
  473. else if (strncmp (argv[1], "o", 1) == 0)
  474. type = DISTRIBUTE_OUT;
  475. else
  476. {
  477. vty_out (vty, "distribute list direction must be [in|out]%s",
  478. VTY_NEWLINE);
  479. return CMD_WARNING;
  480. }
  481. /* Get interface name corresponding distribute list. */
  482. dist = distribute_list_prefix_set (argv[2], type, argv[0]);
  483. return CMD_SUCCESS;
  484. }
  485. ALIAS (districute_list_prefix, ipv6_distribute_list_prefix_cmd,
  486. "distribute-list prefix WORD (in|out) WORD",
  487. "Filter networks in routing updates\n"
  488. "Filter prefixes in routing updates\n"
  489. "Name of an IP prefix-list\n"
  490. "Filter incoming routing updates\n"
  491. "Filter outgoing routing updates\n"
  492. "Interface name\n")
  493. DEFUN (no_districute_list_prefix, no_distribute_list_prefix_cmd,
  494. "no distribute-list prefix WORD (in|out) WORD",
  495. NO_STR
  496. "Filter networks in routing updates\n"
  497. "Filter prefixes in routing updates\n"
  498. "Name of an IP prefix-list\n"
  499. "Filter incoming routing updates\n"
  500. "Filter outgoing routing updates\n"
  501. "Interface name\n")
  502. {
  503. int ret;
  504. enum distribute_type type;
  505. /* Check of distribute list type. */
  506. if (strncmp (argv[1], "i", 1) == 0)
  507. type = DISTRIBUTE_IN;
  508. else if (strncmp (argv[1], "o", 1) == 0)
  509. type = DISTRIBUTE_OUT;
  510. else
  511. {
  512. vty_out (vty, "distribute list direction must be [in|out]%s",
  513. VTY_NEWLINE);
  514. return CMD_WARNING;
  515. }
  516. ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
  517. if (! ret)
  518. {
  519. vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
  520. return CMD_WARNING;
  521. }
  522. return CMD_SUCCESS;
  523. }
  524. ALIAS (no_districute_list_prefix, no_ipv6_distribute_list_prefix_cmd,
  525. "no distribute-list prefix WORD (in|out) WORD",
  526. NO_STR
  527. "Filter networks in routing updates\n"
  528. "Filter prefixes in routing updates\n"
  529. "Name of an IP prefix-list\n"
  530. "Filter incoming routing updates\n"
  531. "Filter outgoing routing updates\n"
  532. "Interface name\n")
  533. int
  534. config_show_distribute (struct vty *vty)
  535. {
  536. unsigned int i;
  537. struct hash_backet *mp;
  538. struct distribute *dist;
  539. /* Output filter configuration. */
  540. dist = distribute_lookup (NULL);
  541. if (dist && (dist->list[DISTRIBUTE_OUT] || dist->prefix[DISTRIBUTE_OUT]))
  542. {
  543. vty_out (vty, " Outgoing update filter list for all interface is");
  544. if (dist->list[DISTRIBUTE_OUT])
  545. vty_out (vty, " %s", dist->list[DISTRIBUTE_OUT]);
  546. if (dist->prefix[DISTRIBUTE_OUT])
  547. vty_out (vty, "%s (prefix-list) %s",
  548. dist->list[DISTRIBUTE_OUT] ? "," : "",
  549. dist->prefix[DISTRIBUTE_OUT]);
  550. vty_out (vty, "%s", VTY_NEWLINE);
  551. }
  552. else
  553. vty_out (vty, " Outgoing update filter list for all interface is not set%s", VTY_NEWLINE);
  554. for (i = 0; i < disthash->size; i++)
  555. for (mp = disthash->index[i]; mp; mp = mp->next)
  556. {
  557. dist = mp->data;
  558. if (dist->ifname)
  559. if (dist->list[DISTRIBUTE_OUT] || dist->prefix[DISTRIBUTE_OUT])
  560. {
  561. vty_out (vty, " %s filtered by", dist->ifname);
  562. if (dist->list[DISTRIBUTE_OUT])
  563. vty_out (vty, " %s", dist->list[DISTRIBUTE_OUT]);
  564. if (dist->prefix[DISTRIBUTE_OUT])
  565. vty_out (vty, "%s (prefix-list) %s",
  566. dist->list[DISTRIBUTE_OUT] ? "," : "",
  567. dist->prefix[DISTRIBUTE_OUT]);
  568. vty_out (vty, "%s", VTY_NEWLINE);
  569. }
  570. }
  571. /* Input filter configuration. */
  572. dist = distribute_lookup (NULL);
  573. if (dist && (dist->list[DISTRIBUTE_IN] || dist->prefix[DISTRIBUTE_IN]))
  574. {
  575. vty_out (vty, " Incoming update filter list for all interface is");
  576. if (dist->list[DISTRIBUTE_IN])
  577. vty_out (vty, " %s", dist->list[DISTRIBUTE_IN]);
  578. if (dist->prefix[DISTRIBUTE_IN])
  579. vty_out (vty, "%s (prefix-list) %s",
  580. dist->list[DISTRIBUTE_IN] ? "," : "",
  581. dist->prefix[DISTRIBUTE_IN]);
  582. vty_out (vty, "%s", VTY_NEWLINE);
  583. }
  584. else
  585. vty_out (vty, " Incoming update filter list for all interface is not set%s", VTY_NEWLINE);
  586. for (i = 0; i < disthash->size; i++)
  587. for (mp = disthash->index[i]; mp; mp = mp->next)
  588. {
  589. dist = mp->data;
  590. if (dist->ifname)
  591. if (dist->list[DISTRIBUTE_IN] || dist->prefix[DISTRIBUTE_IN])
  592. {
  593. vty_out (vty, " %s filtered by", dist->ifname);
  594. if (dist->list[DISTRIBUTE_IN])
  595. vty_out (vty, " %s", dist->list[DISTRIBUTE_IN]);
  596. if (dist->prefix[DISTRIBUTE_IN])
  597. vty_out (vty, "%s (prefix-list) %s",
  598. dist->list[DISTRIBUTE_IN] ? "," : "",
  599. dist->prefix[DISTRIBUTE_IN]);
  600. vty_out (vty, "%s", VTY_NEWLINE);
  601. }
  602. }
  603. return 0;
  604. }
  605. /* Configuration write function. */
  606. int
  607. config_write_distribute (struct vty *vty)
  608. {
  609. unsigned int i;
  610. struct hash_backet *mp;
  611. int write = 0;
  612. for (i = 0; i < disthash->size; i++)
  613. for (mp = disthash->index[i]; mp; mp = mp->next)
  614. {
  615. struct distribute *dist;
  616. dist = mp->data;
  617. if (dist->list[DISTRIBUTE_IN])
  618. {
  619. vty_out (vty, " distribute-list %s in %s%s",
  620. dist->list[DISTRIBUTE_IN],
  621. dist->ifname ? dist->ifname : "",
  622. VTY_NEWLINE);
  623. write++;
  624. }
  625. if (dist->list[DISTRIBUTE_OUT])
  626. {
  627. vty_out (vty, " distribute-list %s out %s%s",
  628. dist->list[DISTRIBUTE_OUT],
  629. dist->ifname ? dist->ifname : "",
  630. VTY_NEWLINE);
  631. write++;
  632. }
  633. if (dist->prefix[DISTRIBUTE_IN])
  634. {
  635. vty_out (vty, " distribute-list prefix %s in %s%s",
  636. dist->prefix[DISTRIBUTE_IN],
  637. dist->ifname ? dist->ifname : "",
  638. VTY_NEWLINE);
  639. write++;
  640. }
  641. if (dist->prefix[DISTRIBUTE_OUT])
  642. {
  643. vty_out (vty, " distribute-list prefix %s out %s%s",
  644. dist->prefix[DISTRIBUTE_OUT],
  645. dist->ifname ? dist->ifname : "",
  646. VTY_NEWLINE);
  647. write++;
  648. }
  649. }
  650. return write;
  651. }
  652. /* Clear all distribute list. */
  653. void
  654. distribute_list_reset ()
  655. {
  656. hash_clean (disthash, (void (*) (void *)) distribute_free);
  657. }
  658. /* Initialize distribute list related hash. */
  659. void
  660. distribute_list_init (int node)
  661. {
  662. disthash = hash_create ((unsigned int (*) (void *)) distribute_hash_make,
  663. (int (*) (const void *, const void *)) distribute_cmp);
  664. if(node==RIP_NODE) {
  665. install_element (RIP_NODE, &distribute_list_all_cmd);
  666. install_element (RIP_NODE, &no_distribute_list_all_cmd);
  667. install_element (RIP_NODE, &distribute_list_cmd);
  668. install_element (RIP_NODE, &no_distribute_list_cmd);
  669. install_element (RIP_NODE, &distribute_list_prefix_all_cmd);
  670. install_element (RIP_NODE, &no_distribute_list_prefix_all_cmd);
  671. install_element (RIP_NODE, &distribute_list_prefix_cmd);
  672. install_element (RIP_NODE, &no_distribute_list_prefix_cmd);
  673. } else {
  674. install_element (RIPNG_NODE, &ipv6_distribute_list_all_cmd);
  675. install_element (RIPNG_NODE, &no_ipv6_distribute_list_all_cmd);
  676. install_element (RIPNG_NODE, &ipv6_distribute_list_cmd);
  677. install_element (RIPNG_NODE, &no_ipv6_distribute_list_cmd);
  678. install_element (RIPNG_NODE, &ipv6_distribute_list_prefix_all_cmd);
  679. install_element (RIPNG_NODE, &no_ipv6_distribute_list_prefix_all_cmd);
  680. install_element (RIPNG_NODE, &ipv6_distribute_list_prefix_cmd);
  681. install_element (RIPNG_NODE, &no_ipv6_distribute_list_prefix_cmd);
  682. }
  683. }