ospf_routemap.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /*
  2. * Route map function of ospfd.
  3. * Copyright (C) 2000 IP Infusion Inc.
  4. *
  5. * Written by Toshiaki Takada.
  6. *
  7. * This file is part of GNU Zebra.
  8. *
  9. * GNU Zebra is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * GNU Zebra is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  21. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. * 02111-1307, USA.
  23. */
  24. #include <zebra.h>
  25. #include "memory.h"
  26. #include "prefix.h"
  27. #include "table.h"
  28. #include "routemap.h"
  29. #include "command.h"
  30. #include "log.h"
  31. #include "plist.h"
  32. #include "ospfd/ospfd.h"
  33. #include "ospfd/ospf_asbr.h"
  34. #include "ospfd/ospf_interface.h"
  35. #include "ospfd/ospf_lsa.h"
  36. #include "ospfd/ospf_route.h"
  37. #include "ospfd/ospf_zebra.h"
  38. /* Hook function for updating route_map assignment. */
  39. static void
  40. ospf_route_map_update (const char *name)
  41. {
  42. struct ospf *ospf;
  43. int type;
  44. /* If OSPF instatnce does not exist, return right now. */
  45. ospf = ospf_lookup ();
  46. if (ospf == NULL)
  47. return;
  48. /* Update route-map */
  49. for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
  50. {
  51. if (ROUTEMAP_NAME (ospf, type)
  52. && strcmp (ROUTEMAP_NAME (ospf, type), name) == 0)
  53. {
  54. /* Keep old route-map. */
  55. struct route_map *old = ROUTEMAP (ospf, type);
  56. /* Update route-map. */
  57. ROUTEMAP (ospf, type) =
  58. route_map_lookup_by_name (ROUTEMAP_NAME (ospf, type));
  59. /* No update for this distribute type. */
  60. if (old == NULL && ROUTEMAP (ospf, type) == NULL)
  61. continue;
  62. ospf_distribute_list_update (ospf, type);
  63. }
  64. }
  65. }
  66. static void
  67. ospf_route_map_event (route_map_event_t event, const char *name)
  68. {
  69. struct ospf *ospf;
  70. int type;
  71. /* If OSPF instatnce does not exist, return right now. */
  72. ospf = ospf_lookup ();
  73. if (ospf == NULL)
  74. return;
  75. /* Update route-map. */
  76. for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
  77. {
  78. if (ROUTEMAP_NAME (ospf, type) && ROUTEMAP (ospf, type)
  79. && !strcmp (ROUTEMAP_NAME (ospf, type), name))
  80. {
  81. ospf_distribute_list_update (ospf, type);
  82. }
  83. }
  84. }
  85. /* Delete rip route map rule. */
  86. static int
  87. ospf_route_match_delete (struct vty *vty, struct route_map_index *index,
  88. const char *command, const char *arg)
  89. {
  90. int ret;
  91. ret = route_map_delete_match (index, command, arg);
  92. if (ret)
  93. {
  94. switch (ret)
  95. {
  96. case RMAP_RULE_MISSING:
  97. vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
  98. return CMD_WARNING;
  99. case RMAP_COMPILE_ERROR:
  100. vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
  101. return CMD_WARNING;
  102. }
  103. }
  104. return CMD_SUCCESS;
  105. }
  106. static int
  107. ospf_route_match_add (struct vty *vty, struct route_map_index *index,
  108. const char *command, const char *arg)
  109. {
  110. int ret;
  111. ret = route_map_add_match (index, command, arg);
  112. if (ret)
  113. {
  114. switch (ret)
  115. {
  116. case RMAP_RULE_MISSING:
  117. vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
  118. return CMD_WARNING;
  119. case RMAP_COMPILE_ERROR:
  120. vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
  121. return CMD_WARNING;
  122. }
  123. }
  124. return CMD_SUCCESS;
  125. }
  126. static int
  127. ospf_route_set_add (struct vty *vty, struct route_map_index *index,
  128. const char *command, const char *arg)
  129. {
  130. int ret;
  131. ret = route_map_add_set (index, command, arg);
  132. if (ret)
  133. {
  134. switch (ret)
  135. {
  136. case RMAP_RULE_MISSING:
  137. vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
  138. return CMD_WARNING;
  139. case RMAP_COMPILE_ERROR:
  140. vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
  141. return CMD_WARNING;
  142. }
  143. }
  144. return CMD_SUCCESS;
  145. }
  146. /* Delete rip route map rule. */
  147. static int
  148. ospf_route_set_delete (struct vty *vty, struct route_map_index *index,
  149. const char *command, const char *arg)
  150. {
  151. int ret;
  152. ret = route_map_delete_set (index, command, arg);
  153. if (ret)
  154. {
  155. switch (ret)
  156. {
  157. case RMAP_RULE_MISSING:
  158. vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
  159. return CMD_WARNING;
  160. case RMAP_COMPILE_ERROR:
  161. vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
  162. return CMD_WARNING;
  163. }
  164. }
  165. return CMD_SUCCESS;
  166. }
  167. /* `match ip netxthop ' */
  168. /* Match function return 1 if match is success else return zero. */
  169. static route_map_result_t
  170. route_match_ip_nexthop (void *rule, struct prefix *prefix,
  171. route_map_object_t type, void *object)
  172. {
  173. struct access_list *alist;
  174. struct external_info *ei = object;
  175. struct prefix_ipv4 p;
  176. if (type == RMAP_OSPF)
  177. {
  178. p.family = AF_INET;
  179. p.prefix = ei->nexthop;
  180. p.prefixlen = IPV4_MAX_BITLEN;
  181. alist = access_list_lookup (AFI_IP, (char *) rule);
  182. if (alist == NULL)
  183. return RMAP_NOMATCH;
  184. return (access_list_apply (alist, &p) == FILTER_DENY ?
  185. RMAP_NOMATCH : RMAP_MATCH);
  186. }
  187. return RMAP_NOMATCH;
  188. }
  189. /* Route map `ip next-hop' match statement. `arg' should be
  190. access-list name. */
  191. static void *
  192. route_match_ip_nexthop_compile (const char *arg)
  193. {
  194. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  195. }
  196. /* Free route map's compiled `ip address' value. */
  197. static void
  198. route_match_ip_nexthop_free (void *rule)
  199. {
  200. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  201. }
  202. /* Route map commands for metric matching. */
  203. struct route_map_rule_cmd route_match_ip_nexthop_cmd =
  204. {
  205. "ip next-hop",
  206. route_match_ip_nexthop,
  207. route_match_ip_nexthop_compile,
  208. route_match_ip_nexthop_free
  209. };
  210. /* `match ip next-hop prefix-list PREFIX_LIST' */
  211. static route_map_result_t
  212. route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
  213. route_map_object_t type, void *object)
  214. {
  215. struct prefix_list *plist;
  216. struct external_info *ei = object;
  217. struct prefix_ipv4 p;
  218. if (type == RMAP_OSPF)
  219. {
  220. p.family = AF_INET;
  221. p.prefix = ei->nexthop;
  222. p.prefixlen = IPV4_MAX_BITLEN;
  223. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  224. if (plist == NULL)
  225. return RMAP_NOMATCH;
  226. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  227. RMAP_NOMATCH : RMAP_MATCH);
  228. }
  229. return RMAP_NOMATCH;
  230. }
  231. static void *
  232. route_match_ip_next_hop_prefix_list_compile (const char *arg)
  233. {
  234. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  235. }
  236. static void
  237. route_match_ip_next_hop_prefix_list_free (void *rule)
  238. {
  239. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  240. }
  241. struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
  242. {
  243. "ip next-hop prefix-list",
  244. route_match_ip_next_hop_prefix_list,
  245. route_match_ip_next_hop_prefix_list_compile,
  246. route_match_ip_next_hop_prefix_list_free
  247. };
  248. /* `match ip address IP_ACCESS_LIST' */
  249. /* Match function should return 1 if match is success else return
  250. zero. */
  251. static route_map_result_t
  252. route_match_ip_address (void *rule, struct prefix *prefix,
  253. route_map_object_t type, void *object)
  254. {
  255. struct access_list *alist;
  256. /* struct prefix_ipv4 match; */
  257. if (type == RMAP_OSPF)
  258. {
  259. alist = access_list_lookup (AFI_IP, (char *) rule);
  260. if (alist == NULL)
  261. return RMAP_NOMATCH;
  262. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  263. RMAP_NOMATCH : RMAP_MATCH);
  264. }
  265. return RMAP_NOMATCH;
  266. }
  267. /* Route map `ip address' match statement. `arg' should be
  268. access-list name. */
  269. static void *
  270. route_match_ip_address_compile (const char *arg)
  271. {
  272. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  273. }
  274. /* Free route map's compiled `ip address' value. */
  275. static void
  276. route_match_ip_address_free (void *rule)
  277. {
  278. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  279. }
  280. /* Route map commands for ip address matching. */
  281. struct route_map_rule_cmd route_match_ip_address_cmd =
  282. {
  283. "ip address",
  284. route_match_ip_address,
  285. route_match_ip_address_compile,
  286. route_match_ip_address_free
  287. };
  288. /* `match ip address prefix-list PREFIX_LIST' */
  289. static route_map_result_t
  290. route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
  291. route_map_object_t type, void *object)
  292. {
  293. struct prefix_list *plist;
  294. if (type == RMAP_OSPF)
  295. {
  296. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  297. if (plist == NULL)
  298. return RMAP_NOMATCH;
  299. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  300. RMAP_NOMATCH : RMAP_MATCH);
  301. }
  302. return RMAP_NOMATCH;
  303. }
  304. static void *
  305. route_match_ip_address_prefix_list_compile (const char *arg)
  306. {
  307. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  308. }
  309. static void
  310. route_match_ip_address_prefix_list_free (void *rule)
  311. {
  312. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  313. }
  314. struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
  315. {
  316. "ip address prefix-list",
  317. route_match_ip_address_prefix_list,
  318. route_match_ip_address_prefix_list_compile,
  319. route_match_ip_address_prefix_list_free
  320. };
  321. /* `match interface IFNAME' */
  322. /* Match function should return 1 if match is success else return
  323. zero. */
  324. static route_map_result_t
  325. route_match_interface (void *rule, struct prefix *prefix,
  326. route_map_object_t type, void *object)
  327. {
  328. struct interface *ifp;
  329. struct external_info *ei;
  330. if (type == RMAP_OSPF)
  331. {
  332. ei = object;
  333. ifp = if_lookup_by_name ((char *)rule);
  334. if (ifp == NULL || ifp->ifindex != ei->ifindex)
  335. return RMAP_NOMATCH;
  336. return RMAP_MATCH;
  337. }
  338. return RMAP_NOMATCH;
  339. }
  340. /* Route map `interface' match statement. `arg' should be
  341. interface name. */
  342. static void *
  343. route_match_interface_compile (const char *arg)
  344. {
  345. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  346. }
  347. /* Free route map's compiled `interface' value. */
  348. static void
  349. route_match_interface_free (void *rule)
  350. {
  351. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  352. }
  353. /* Route map commands for ip address matching. */
  354. struct route_map_rule_cmd route_match_interface_cmd =
  355. {
  356. "interface",
  357. route_match_interface,
  358. route_match_interface_compile,
  359. route_match_interface_free
  360. };
  361. /* Match function return 1 if match is success else return zero. */
  362. static route_map_result_t
  363. route_match_tag (void *rule, struct prefix *prefix,
  364. route_map_object_t type, void *object)
  365. {
  366. route_tag_t *tag;
  367. struct external_info *ei;
  368. if (type == RMAP_OSPF)
  369. {
  370. tag = rule;
  371. ei = object;
  372. return ((ei->tag == *tag)? RMAP_MATCH : RMAP_NOMATCH);
  373. }
  374. return RMAP_NOMATCH;
  375. }
  376. /* Route map commands for tag matching. */
  377. static struct route_map_rule_cmd route_match_tag_cmd =
  378. {
  379. "tag",
  380. route_match_tag,
  381. route_map_rule_tag_compile,
  382. route_map_rule_tag_free,
  383. };
  384. /* `set metric METRIC' */
  385. /* Set metric to attribute. */
  386. static route_map_result_t
  387. route_set_metric (void *rule, struct prefix *prefix,
  388. route_map_object_t type, void *object)
  389. {
  390. u_int32_t *metric;
  391. struct external_info *ei;
  392. if (type == RMAP_OSPF)
  393. {
  394. /* Fetch routemap's rule information. */
  395. metric = rule;
  396. ei = object;
  397. /* Set metric out value. */
  398. ei->route_map_set.metric = *metric;
  399. }
  400. return RMAP_OKAY;
  401. }
  402. /* set metric compilation. */
  403. static void *
  404. route_set_metric_compile (const char *arg)
  405. {
  406. u_int32_t *metric;
  407. int32_t ret;
  408. /* OSPF doesn't support the +/- in
  409. set metric <+/-metric> check
  410. Ignore the +/- component */
  411. if (! all_digit (arg))
  412. {
  413. if ((strncmp (arg, "+", 1) == 0 || strncmp (arg, "-", 1) == 0) &&
  414. all_digit (arg+1))
  415. {
  416. zlog_warn ("OSPF does not support 'set metric +/-'");
  417. arg++;
  418. }
  419. else
  420. return NULL;
  421. }
  422. metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  423. ret = atoi (arg);
  424. if (ret >= 0)
  425. {
  426. *metric = (u_int32_t)ret;
  427. return metric;
  428. }
  429. XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
  430. return NULL;
  431. }
  432. /* Free route map's compiled `set metric' value. */
  433. static void
  434. route_set_metric_free (void *rule)
  435. {
  436. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  437. }
  438. /* Set metric rule structure. */
  439. struct route_map_rule_cmd route_set_metric_cmd =
  440. {
  441. "metric",
  442. route_set_metric,
  443. route_set_metric_compile,
  444. route_set_metric_free,
  445. };
  446. /* `set metric-type TYPE' */
  447. /* Set metric-type to attribute. */
  448. static route_map_result_t
  449. route_set_metric_type (void *rule, struct prefix *prefix,
  450. route_map_object_t type, void *object)
  451. {
  452. u_int32_t *metric_type;
  453. struct external_info *ei;
  454. if (type == RMAP_OSPF)
  455. {
  456. /* Fetch routemap's rule information. */
  457. metric_type = rule;
  458. ei = object;
  459. /* Set metric out value. */
  460. ei->route_map_set.metric_type = *metric_type;
  461. }
  462. return RMAP_OKAY;
  463. }
  464. /* set metric-type compilation. */
  465. static void *
  466. route_set_metric_type_compile (const char *arg)
  467. {
  468. u_int32_t *metric_type;
  469. metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  470. if (strcmp (arg, "type-1") == 0)
  471. *metric_type = EXTERNAL_METRIC_TYPE_1;
  472. else if (strcmp (arg, "type-2") == 0)
  473. *metric_type = EXTERNAL_METRIC_TYPE_2;
  474. if (*metric_type == EXTERNAL_METRIC_TYPE_1 ||
  475. *metric_type == EXTERNAL_METRIC_TYPE_2)
  476. return metric_type;
  477. XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type);
  478. return NULL;
  479. }
  480. /* Free route map's compiled `set metric-type' value. */
  481. static void
  482. route_set_metric_type_free (void *rule)
  483. {
  484. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  485. }
  486. /* Set metric rule structure. */
  487. struct route_map_rule_cmd route_set_metric_type_cmd =
  488. {
  489. "metric-type",
  490. route_set_metric_type,
  491. route_set_metric_type_compile,
  492. route_set_metric_type_free,
  493. };
  494. static route_map_result_t
  495. route_set_tag (void *rule, struct prefix *prefix,
  496. route_map_object_t type, void *object)
  497. {
  498. route_tag_t *tag;
  499. struct external_info *ei;
  500. if (type == RMAP_OSPF)
  501. {
  502. tag = rule;
  503. ei = object;
  504. /* Set tag value */
  505. ei->tag=*tag;
  506. }
  507. return RMAP_OKAY;
  508. }
  509. /* Route map commands for tag set. */
  510. static struct route_map_rule_cmd route_set_tag_cmd =
  511. {
  512. "tag",
  513. route_set_tag,
  514. route_map_rule_tag_compile,
  515. route_map_rule_tag_free,
  516. };
  517. DEFUN (match_ip_nexthop,
  518. match_ip_nexthop_cmd,
  519. "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  520. MATCH_STR
  521. IP_STR
  522. "Match next-hop address of route\n"
  523. "IP access-list number\n"
  524. "IP access-list number (expanded range)\n"
  525. "IP access-list name\n")
  526. {
  527. return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  528. }
  529. DEFUN (no_match_ip_nexthop,
  530. no_match_ip_nexthop_cmd,
  531. "no match ip next-hop",
  532. NO_STR
  533. MATCH_STR
  534. IP_STR
  535. "Match next-hop address of route\n")
  536. {
  537. if (argc == 0)
  538. return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  539. return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  540. }
  541. ALIAS (no_match_ip_nexthop,
  542. no_match_ip_nexthop_val_cmd,
  543. "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  544. NO_STR
  545. MATCH_STR
  546. IP_STR
  547. "Match next-hop address of route\n"
  548. "IP access-list number\n"
  549. "IP access-list number (expanded range)\n"
  550. "IP access-list name\n")
  551. DEFUN (match_ip_next_hop_prefix_list,
  552. match_ip_next_hop_prefix_list_cmd,
  553. "match ip next-hop prefix-list WORD",
  554. MATCH_STR
  555. IP_STR
  556. "Match next-hop address of route\n"
  557. "Match entries of prefix-lists\n"
  558. "IP prefix-list name\n")
  559. {
  560. return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list",
  561. argv[0]);
  562. }
  563. DEFUN (no_match_ip_next_hop_prefix_list,
  564. no_match_ip_next_hop_prefix_list_cmd,
  565. "no match ip next-hop prefix-list",
  566. NO_STR
  567. MATCH_STR
  568. IP_STR
  569. "Match next-hop address of route\n"
  570. "Match entries of prefix-lists\n")
  571. {
  572. if (argc == 0)
  573. return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  574. NULL);
  575. return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  576. argv[0]);
  577. }
  578. ALIAS (no_match_ip_next_hop_prefix_list,
  579. no_match_ip_next_hop_prefix_list_val_cmd,
  580. "no match ip next-hop prefix-list WORD",
  581. NO_STR
  582. MATCH_STR
  583. IP_STR
  584. "Match next-hop address of route\n"
  585. "Match entries of prefix-lists\n"
  586. "IP prefix-list name\n")
  587. DEFUN (match_ip_address,
  588. match_ip_address_cmd,
  589. "match ip address (<1-199>|<1300-2699>|WORD)",
  590. MATCH_STR
  591. IP_STR
  592. "Match address of route\n"
  593. "IP access-list number\n"
  594. "IP access-list number (expanded range)\n"
  595. "IP access-list name\n")
  596. {
  597. return ospf_route_match_add (vty, vty->index, "ip address", argv[0]);
  598. }
  599. DEFUN (no_match_ip_address,
  600. no_match_ip_address_cmd,
  601. "no match ip address",
  602. NO_STR
  603. MATCH_STR
  604. IP_STR
  605. "Match address of route\n")
  606. {
  607. if (argc == 0)
  608. return ospf_route_match_delete (vty, vty->index, "ip address", NULL);
  609. return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]);
  610. }
  611. ALIAS (no_match_ip_address,
  612. no_match_ip_address_val_cmd,
  613. "no match ip address (<1-199>|<1300-2699>|WORD)",
  614. NO_STR
  615. MATCH_STR
  616. IP_STR
  617. "Match address of route\n"
  618. "IP access-list number\n"
  619. "IP access-list number (expanded range)\n"
  620. "IP access-list name\n")
  621. DEFUN (match_ip_address_prefix_list,
  622. match_ip_address_prefix_list_cmd,
  623. "match ip address prefix-list WORD",
  624. MATCH_STR
  625. IP_STR
  626. "Match address of route\n"
  627. "Match entries of prefix-lists\n"
  628. "IP prefix-list name\n")
  629. {
  630. return ospf_route_match_add (vty, vty->index, "ip address prefix-list",
  631. argv[0]);
  632. }
  633. DEFUN (no_match_ip_address_prefix_list,
  634. no_match_ip_address_prefix_list_cmd,
  635. "no match ip address prefix-list",
  636. NO_STR
  637. MATCH_STR
  638. IP_STR
  639. "Match address of route\n"
  640. "Match entries of prefix-lists\n")
  641. {
  642. if (argc == 0)
  643. return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  644. NULL);
  645. return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  646. argv[0]);
  647. }
  648. ALIAS (no_match_ip_address_prefix_list,
  649. no_match_ip_address_prefix_list_val_cmd,
  650. "no match ip address prefix-list WORD",
  651. NO_STR
  652. MATCH_STR
  653. IP_STR
  654. "Match address of route\n"
  655. "Match entries of prefix-lists\n"
  656. "IP prefix-list name\n")
  657. DEFUN (match_interface,
  658. match_interface_cmd,
  659. "match interface WORD",
  660. MATCH_STR
  661. "Match first hop interface of route\n"
  662. "Interface name\n")
  663. {
  664. return ospf_route_match_add (vty, vty->index, "interface", argv[0]);
  665. }
  666. DEFUN (no_match_interface,
  667. no_match_interface_cmd,
  668. "no match interface",
  669. NO_STR
  670. MATCH_STR
  671. "Match first hop interface of route\n")
  672. {
  673. if (argc == 0)
  674. return ospf_route_match_delete (vty, vty->index, "interface", NULL);
  675. return ospf_route_match_delete (vty, vty->index, "interface", argv[0]);
  676. }
  677. ALIAS (no_match_interface,
  678. no_match_interface_val_cmd,
  679. "no match interface WORD",
  680. NO_STR
  681. MATCH_STR
  682. "Match first hop interface of route\n"
  683. "Interface name\n")
  684. DEFUN (match_tag,
  685. match_tag_cmd,
  686. "match tag <1-4294967295>",
  687. MATCH_STR
  688. "Match tag of route\n"
  689. "Tag value\n")
  690. {
  691. return ospf_route_match_add (vty, vty->index, "tag", argv[0]);
  692. }
  693. DEFUN (no_match_tag,
  694. no_match_tag_cmd,
  695. "no match tag",
  696. NO_STR
  697. MATCH_STR
  698. "Match tag of route\n")
  699. {
  700. if (argc == 0)
  701. return ospf_route_match_delete (vty, vty->index, "tag", NULL);
  702. return ospf_route_match_delete (vty, vty->index, "tag", argv[0]);
  703. }
  704. ALIAS (no_match_tag,
  705. no_match_tag_val_cmd,
  706. "no match tag <1-4294967295>",
  707. NO_STR
  708. MATCH_STR
  709. "Match tag of route\n"
  710. "Tag value\n")
  711. DEFUN (set_metric,
  712. set_metric_cmd,
  713. "set metric <0-4294967295>",
  714. SET_STR
  715. "Metric value for destination routing protocol\n"
  716. "Metric value\n")
  717. {
  718. return ospf_route_set_add (vty, vty->index, "metric", argv[0]);
  719. }
  720. DEFUN (no_set_metric,
  721. no_set_metric_cmd,
  722. "no set metric",
  723. NO_STR
  724. SET_STR
  725. "Metric value for destination routing protocol\n")
  726. {
  727. if (argc == 0)
  728. return ospf_route_set_delete (vty, vty->index, "metric", NULL);
  729. return ospf_route_set_delete (vty, vty->index, "metric", argv[0]);
  730. }
  731. ALIAS (no_set_metric,
  732. no_set_metric_val_cmd,
  733. "no set metric <0-4294967295>",
  734. NO_STR
  735. SET_STR
  736. "Metric value for destination routing protocol\n"
  737. "Metric value\n")
  738. DEFUN (set_metric_type,
  739. set_metric_type_cmd,
  740. "set metric-type (type-1|type-2)",
  741. SET_STR
  742. "Type of metric for destination routing protocol\n"
  743. "OSPF[6] external type 1 metric\n"
  744. "OSPF[6] external type 2 metric\n")
  745. {
  746. if (strcmp (argv[0], "1") == 0)
  747. return ospf_route_set_add (vty, vty->index, "metric-type", "type-1");
  748. if (strcmp (argv[0], "2") == 0)
  749. return ospf_route_set_add (vty, vty->index, "metric-type", "type-2");
  750. return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]);
  751. }
  752. DEFUN (no_set_metric_type,
  753. no_set_metric_type_cmd,
  754. "no set metric-type",
  755. NO_STR
  756. SET_STR
  757. "Type of metric for destination routing protocol\n")
  758. {
  759. if (argc == 0)
  760. return ospf_route_set_delete (vty, vty->index, "metric-type", NULL);
  761. return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]);
  762. }
  763. ALIAS (no_set_metric_type,
  764. no_set_metric_type_val_cmd,
  765. "no set metric-type (type-1|type-2)",
  766. NO_STR
  767. SET_STR
  768. "Type of metric for destination routing protocol\n"
  769. "OSPF[6] external type 1 metric\n"
  770. "OSPF[6] external type 2 metric\n")
  771. DEFUN (set_tag,
  772. set_tag_cmd,
  773. "set tag <1-4294967295>",
  774. SET_STR
  775. "Tag value for routing protocol\n"
  776. "Tag value\n")
  777. {
  778. return ospf_route_set_add (vty, vty->index, "tag", argv[0]);
  779. }
  780. DEFUN (no_set_tag,
  781. no_set_tag_cmd,
  782. "no set tag",
  783. NO_STR
  784. SET_STR
  785. "Tag value for routing protocol\n")
  786. {
  787. if (argc == 0)
  788. ospf_route_set_delete(vty, vty->index, "tag", NULL);
  789. return ospf_route_set_delete (vty, vty->index, "tag", argv[0]);
  790. }
  791. ALIAS (no_set_tag,
  792. no_set_tag_val_cmd,
  793. "no set tag <1-4294967295>",
  794. NO_STR
  795. SET_STR
  796. "Tag value for routing protocol\n"
  797. "Tag value\n")
  798. /* Route-map init */
  799. void
  800. ospf_route_map_init (void)
  801. {
  802. route_map_init ();
  803. route_map_init_vty ();
  804. route_map_add_hook (ospf_route_map_update);
  805. route_map_delete_hook (ospf_route_map_update);
  806. route_map_event_hook (ospf_route_map_event);
  807. route_map_install_match (&route_match_ip_nexthop_cmd);
  808. route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  809. route_map_install_match (&route_match_ip_address_cmd);
  810. route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  811. route_map_install_match (&route_match_interface_cmd);
  812. route_map_install_match (&route_match_tag_cmd);
  813. route_map_install_set (&route_set_metric_cmd);
  814. route_map_install_set (&route_set_metric_type_cmd);
  815. route_map_install_set (&route_set_tag_cmd);
  816. install_element (RMAP_NODE, &match_ip_nexthop_cmd);
  817. install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
  818. install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd);
  819. install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  820. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  821. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  822. install_element (RMAP_NODE, &match_ip_address_cmd);
  823. install_element (RMAP_NODE, &no_match_ip_address_cmd);
  824. install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  825. install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  826. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  827. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  828. install_element (RMAP_NODE, &match_interface_cmd);
  829. install_element (RMAP_NODE, &no_match_interface_cmd);
  830. install_element (RMAP_NODE, &no_match_interface_val_cmd);
  831. install_element (RMAP_NODE, &match_tag_cmd);
  832. install_element (RMAP_NODE, &no_match_tag_cmd);
  833. install_element (RMAP_NODE, &no_match_tag_val_cmd);
  834. install_element (RMAP_NODE, &set_metric_cmd);
  835. install_element (RMAP_NODE, &no_set_metric_cmd);
  836. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  837. install_element (RMAP_NODE, &set_metric_type_cmd);
  838. install_element (RMAP_NODE, &no_set_metric_type_cmd);
  839. install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
  840. install_element (RMAP_NODE, &set_tag_cmd);
  841. install_element (RMAP_NODE, &no_set_tag_cmd);
  842. install_element (RMAP_NODE, &no_set_tag_val_cmd);
  843. }