ospf_routemap.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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 `match tag' match statement. `arg' is TAG value */
  377. static void *
  378. route_match_tag_compile (const char *arg)
  379. {
  380. route_tag_t *tag;
  381. route_tag_t tmp;
  382. /* tag value shoud be integer. */
  383. if (! all_digit (arg))
  384. return NULL;
  385. tmp = atoi(arg);
  386. if (tmp < 1)
  387. return NULL;
  388. tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
  389. if (!tag)
  390. return tag;
  391. *tag = tmp;
  392. return tag;
  393. }
  394. /* Free route map's compiled 'match tag' value. */
  395. static void
  396. route_match_tag_free (void *rule)
  397. {
  398. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  399. }
  400. /* Route map commands for tag matching. */
  401. struct route_map_rule_cmd route_match_tag_cmd =
  402. {
  403. "tag",
  404. route_match_tag,
  405. route_match_tag_compile,
  406. route_match_tag_free,
  407. };
  408. /* `set metric METRIC' */
  409. /* Set metric to attribute. */
  410. static route_map_result_t
  411. route_set_metric (void *rule, struct prefix *prefix,
  412. route_map_object_t type, void *object)
  413. {
  414. u_int32_t *metric;
  415. struct external_info *ei;
  416. if (type == RMAP_OSPF)
  417. {
  418. /* Fetch routemap's rule information. */
  419. metric = rule;
  420. ei = object;
  421. /* Set metric out value. */
  422. ei->route_map_set.metric = *metric;
  423. }
  424. return RMAP_OKAY;
  425. }
  426. /* set metric compilation. */
  427. static void *
  428. route_set_metric_compile (const char *arg)
  429. {
  430. u_int32_t *metric;
  431. int32_t ret;
  432. /* OSPF doesn't support the +/- in
  433. set metric <+/-metric> check
  434. Ignore the +/- component */
  435. if (! all_digit (arg))
  436. {
  437. if ((strncmp (arg, "+", 1) == 0 || strncmp (arg, "-", 1) == 0) &&
  438. all_digit (arg+1))
  439. {
  440. zlog_warn ("OSPF does not support 'set metric +/-'");
  441. arg++;
  442. }
  443. else
  444. return NULL;
  445. }
  446. metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  447. ret = atoi (arg);
  448. if (ret >= 0)
  449. {
  450. *metric = (u_int32_t)ret;
  451. return metric;
  452. }
  453. XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
  454. return NULL;
  455. }
  456. /* Free route map's compiled `set metric' value. */
  457. static void
  458. route_set_metric_free (void *rule)
  459. {
  460. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  461. }
  462. /* Set metric rule structure. */
  463. struct route_map_rule_cmd route_set_metric_cmd =
  464. {
  465. "metric",
  466. route_set_metric,
  467. route_set_metric_compile,
  468. route_set_metric_free,
  469. };
  470. /* `set metric-type TYPE' */
  471. /* Set metric-type to attribute. */
  472. static route_map_result_t
  473. route_set_metric_type (void *rule, struct prefix *prefix,
  474. route_map_object_t type, void *object)
  475. {
  476. u_int32_t *metric_type;
  477. struct external_info *ei;
  478. if (type == RMAP_OSPF)
  479. {
  480. /* Fetch routemap's rule information. */
  481. metric_type = rule;
  482. ei = object;
  483. /* Set metric out value. */
  484. ei->route_map_set.metric_type = *metric_type;
  485. }
  486. return RMAP_OKAY;
  487. }
  488. /* set metric-type compilation. */
  489. static void *
  490. route_set_metric_type_compile (const char *arg)
  491. {
  492. u_int32_t *metric_type;
  493. metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  494. if (strcmp (arg, "type-1") == 0)
  495. *metric_type = EXTERNAL_METRIC_TYPE_1;
  496. else if (strcmp (arg, "type-2") == 0)
  497. *metric_type = EXTERNAL_METRIC_TYPE_2;
  498. if (*metric_type == EXTERNAL_METRIC_TYPE_1 ||
  499. *metric_type == EXTERNAL_METRIC_TYPE_2)
  500. return metric_type;
  501. XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type);
  502. return NULL;
  503. }
  504. /* Free route map's compiled `set metric-type' value. */
  505. static void
  506. route_set_metric_type_free (void *rule)
  507. {
  508. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  509. }
  510. /* Set metric rule structure. */
  511. struct route_map_rule_cmd route_set_metric_type_cmd =
  512. {
  513. "metric-type",
  514. route_set_metric_type,
  515. route_set_metric_type_compile,
  516. route_set_metric_type_free,
  517. };
  518. static route_map_result_t
  519. route_set_tag (void *rule, struct prefix *prefix,
  520. route_map_object_t type, void *object)
  521. {
  522. route_tag_t *tag;
  523. struct external_info *ei;
  524. if (type == RMAP_OSPF)
  525. {
  526. tag = rule;
  527. ei = object;
  528. /* Set tag value */
  529. ei->tag=*tag;
  530. }
  531. return RMAP_OKAY;
  532. }
  533. /* Route map `tag' compile function. Given string is converted to u_short. */
  534. static void *
  535. route_set_tag_compile (const char *arg)
  536. {
  537. route_tag_t *tag;
  538. route_tag_t tmp;
  539. /* tag value shoud be integer. */
  540. if (! all_digit (arg))
  541. return NULL;
  542. tmp = atoi(arg);
  543. if (tmp < 1)
  544. return NULL;
  545. tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
  546. if (!tag)
  547. return tag;
  548. *tag = tmp;
  549. return tag;
  550. }
  551. /* Free route map's tag value. */
  552. static void
  553. route_set_tag_free (void *rule)
  554. {
  555. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  556. }
  557. /* Route map commands for tag set. */
  558. struct route_map_rule_cmd route_set_tag_cmd =
  559. {
  560. "tag",
  561. route_set_tag,
  562. route_set_tag_compile,
  563. route_set_tag_free,
  564. };
  565. DEFUN (match_ip_nexthop,
  566. match_ip_nexthop_cmd,
  567. "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  568. MATCH_STR
  569. IP_STR
  570. "Match next-hop address of route\n"
  571. "IP access-list number\n"
  572. "IP access-list number (expanded range)\n"
  573. "IP access-list name\n")
  574. {
  575. return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  576. }
  577. DEFUN (no_match_ip_nexthop,
  578. no_match_ip_nexthop_cmd,
  579. "no match ip next-hop",
  580. NO_STR
  581. MATCH_STR
  582. IP_STR
  583. "Match next-hop address of route\n")
  584. {
  585. if (argc == 0)
  586. return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  587. return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  588. }
  589. ALIAS (no_match_ip_nexthop,
  590. no_match_ip_nexthop_val_cmd,
  591. "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  592. NO_STR
  593. MATCH_STR
  594. IP_STR
  595. "Match next-hop address of route\n"
  596. "IP access-list number\n"
  597. "IP access-list number (expanded range)\n"
  598. "IP access-list name\n")
  599. DEFUN (match_ip_next_hop_prefix_list,
  600. match_ip_next_hop_prefix_list_cmd,
  601. "match ip next-hop prefix-list WORD",
  602. MATCH_STR
  603. IP_STR
  604. "Match next-hop address of route\n"
  605. "Match entries of prefix-lists\n"
  606. "IP prefix-list name\n")
  607. {
  608. return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list",
  609. argv[0]);
  610. }
  611. DEFUN (no_match_ip_next_hop_prefix_list,
  612. no_match_ip_next_hop_prefix_list_cmd,
  613. "no match ip next-hop prefix-list",
  614. NO_STR
  615. MATCH_STR
  616. IP_STR
  617. "Match next-hop address of route\n"
  618. "Match entries of prefix-lists\n")
  619. {
  620. if (argc == 0)
  621. return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  622. NULL);
  623. return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  624. argv[0]);
  625. }
  626. ALIAS (no_match_ip_next_hop_prefix_list,
  627. no_match_ip_next_hop_prefix_list_val_cmd,
  628. "no match ip next-hop prefix-list WORD",
  629. NO_STR
  630. MATCH_STR
  631. IP_STR
  632. "Match next-hop address of route\n"
  633. "Match entries of prefix-lists\n"
  634. "IP prefix-list name\n")
  635. DEFUN (match_ip_address,
  636. match_ip_address_cmd,
  637. "match ip address (<1-199>|<1300-2699>|WORD)",
  638. MATCH_STR
  639. IP_STR
  640. "Match address of route\n"
  641. "IP access-list number\n"
  642. "IP access-list number (expanded range)\n"
  643. "IP access-list name\n")
  644. {
  645. return ospf_route_match_add (vty, vty->index, "ip address", argv[0]);
  646. }
  647. DEFUN (no_match_ip_address,
  648. no_match_ip_address_cmd,
  649. "no match ip address",
  650. NO_STR
  651. MATCH_STR
  652. IP_STR
  653. "Match address of route\n")
  654. {
  655. if (argc == 0)
  656. return ospf_route_match_delete (vty, vty->index, "ip address", NULL);
  657. return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]);
  658. }
  659. ALIAS (no_match_ip_address,
  660. no_match_ip_address_val_cmd,
  661. "no match ip address (<1-199>|<1300-2699>|WORD)",
  662. NO_STR
  663. MATCH_STR
  664. IP_STR
  665. "Match address of route\n"
  666. "IP access-list number\n"
  667. "IP access-list number (expanded range)\n"
  668. "IP access-list name\n")
  669. DEFUN (match_ip_address_prefix_list,
  670. match_ip_address_prefix_list_cmd,
  671. "match ip address prefix-list WORD",
  672. MATCH_STR
  673. IP_STR
  674. "Match address of route\n"
  675. "Match entries of prefix-lists\n"
  676. "IP prefix-list name\n")
  677. {
  678. return ospf_route_match_add (vty, vty->index, "ip address prefix-list",
  679. argv[0]);
  680. }
  681. DEFUN (no_match_ip_address_prefix_list,
  682. no_match_ip_address_prefix_list_cmd,
  683. "no match ip address prefix-list",
  684. NO_STR
  685. MATCH_STR
  686. IP_STR
  687. "Match address of route\n"
  688. "Match entries of prefix-lists\n")
  689. {
  690. if (argc == 0)
  691. return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  692. NULL);
  693. return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  694. argv[0]);
  695. }
  696. ALIAS (no_match_ip_address_prefix_list,
  697. no_match_ip_address_prefix_list_val_cmd,
  698. "no match ip address prefix-list WORD",
  699. NO_STR
  700. MATCH_STR
  701. IP_STR
  702. "Match address of route\n"
  703. "Match entries of prefix-lists\n"
  704. "IP prefix-list name\n")
  705. DEFUN (match_interface,
  706. match_interface_cmd,
  707. "match interface WORD",
  708. MATCH_STR
  709. "Match first hop interface of route\n"
  710. "Interface name\n")
  711. {
  712. return ospf_route_match_add (vty, vty->index, "interface", argv[0]);
  713. }
  714. DEFUN (no_match_interface,
  715. no_match_interface_cmd,
  716. "no match interface",
  717. NO_STR
  718. MATCH_STR
  719. "Match first hop interface of route\n")
  720. {
  721. if (argc == 0)
  722. return ospf_route_match_delete (vty, vty->index, "interface", NULL);
  723. return ospf_route_match_delete (vty, vty->index, "interface", argv[0]);
  724. }
  725. ALIAS (no_match_interface,
  726. no_match_interface_val_cmd,
  727. "no match interface WORD",
  728. NO_STR
  729. MATCH_STR
  730. "Match first hop interface of route\n"
  731. "Interface name\n")
  732. DEFUN (match_tag,
  733. match_tag_cmd,
  734. "match tag <1-65535>",
  735. MATCH_STR
  736. "Match tag of route\n"
  737. "Tag value\n")
  738. {
  739. return ospf_route_match_add (vty, vty->index, "tag", argv[0]);
  740. }
  741. DEFUN (no_match_tag,
  742. no_match_tag_cmd,
  743. "no match tag",
  744. NO_STR
  745. MATCH_STR
  746. "Match tag of route\n")
  747. {
  748. if (argc == 0)
  749. return ospf_route_match_delete (vty, vty->index, "tag", NULL);
  750. return ospf_route_match_delete (vty, vty->index, "tag", argv[0]);
  751. }
  752. ALIAS (no_match_tag,
  753. no_match_tag_val_cmd,
  754. "no match tag <1-65535>",
  755. NO_STR
  756. MATCH_STR
  757. "Match tag of route\n"
  758. "Tag value\n")
  759. DEFUN (set_metric,
  760. set_metric_cmd,
  761. "set metric <0-4294967295>",
  762. SET_STR
  763. "Metric value for destination routing protocol\n"
  764. "Metric value\n")
  765. {
  766. return ospf_route_set_add (vty, vty->index, "metric", argv[0]);
  767. }
  768. DEFUN (no_set_metric,
  769. no_set_metric_cmd,
  770. "no set metric",
  771. NO_STR
  772. SET_STR
  773. "Metric value for destination routing protocol\n")
  774. {
  775. if (argc == 0)
  776. return ospf_route_set_delete (vty, vty->index, "metric", NULL);
  777. return ospf_route_set_delete (vty, vty->index, "metric", argv[0]);
  778. }
  779. ALIAS (no_set_metric,
  780. no_set_metric_val_cmd,
  781. "no set metric <0-4294967295>",
  782. NO_STR
  783. SET_STR
  784. "Metric value for destination routing protocol\n"
  785. "Metric value\n")
  786. DEFUN (set_metric_type,
  787. set_metric_type_cmd,
  788. "set metric-type (type-1|type-2)",
  789. SET_STR
  790. "Type of metric for destination routing protocol\n"
  791. "OSPF[6] external type 1 metric\n"
  792. "OSPF[6] external type 2 metric\n")
  793. {
  794. if (strcmp (argv[0], "1") == 0)
  795. return ospf_route_set_add (vty, vty->index, "metric-type", "type-1");
  796. if (strcmp (argv[0], "2") == 0)
  797. return ospf_route_set_add (vty, vty->index, "metric-type", "type-2");
  798. return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]);
  799. }
  800. DEFUN (no_set_metric_type,
  801. no_set_metric_type_cmd,
  802. "no set metric-type",
  803. NO_STR
  804. SET_STR
  805. "Type of metric for destination routing protocol\n")
  806. {
  807. if (argc == 0)
  808. return ospf_route_set_delete (vty, vty->index, "metric-type", NULL);
  809. return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]);
  810. }
  811. ALIAS (no_set_metric_type,
  812. no_set_metric_type_val_cmd,
  813. "no set metric-type (type-1|type-2)",
  814. NO_STR
  815. SET_STR
  816. "Type of metric for destination routing protocol\n"
  817. "OSPF[6] external type 1 metric\n"
  818. "OSPF[6] external type 2 metric\n")
  819. DEFUN (set_tag,
  820. set_tag_cmd,
  821. "set tag <1-65535>",
  822. SET_STR
  823. "Tag value for routing protocol\n"
  824. "Tag value\n")
  825. {
  826. return ospf_route_set_add (vty, vty->index, "tag", argv[0]);
  827. }
  828. DEFUN (no_set_tag,
  829. no_set_tag_cmd,
  830. "no set tag",
  831. NO_STR
  832. SET_STR
  833. "Tag value for routing protocol\n")
  834. {
  835. if (argc == 0)
  836. ospf_route_set_delete(vty, vty->index, "tag", NULL);
  837. return ospf_route_set_delete (vty, vty->index, "tag", argv[0]);
  838. }
  839. ALIAS (no_set_tag,
  840. no_set_tag_val_cmd,
  841. "no set tag <1-65535>",
  842. NO_STR
  843. SET_STR
  844. "Tag value for routing protocol\n"
  845. "Tag value\n")
  846. /* Route-map init */
  847. void
  848. ospf_route_map_init (void)
  849. {
  850. route_map_init ();
  851. route_map_init_vty ();
  852. route_map_add_hook (ospf_route_map_update);
  853. route_map_delete_hook (ospf_route_map_update);
  854. route_map_event_hook (ospf_route_map_event);
  855. route_map_install_match (&route_match_ip_nexthop_cmd);
  856. route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  857. route_map_install_match (&route_match_ip_address_cmd);
  858. route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  859. route_map_install_match (&route_match_interface_cmd);
  860. route_map_install_match (&route_match_tag_cmd);
  861. route_map_install_set (&route_set_metric_cmd);
  862. route_map_install_set (&route_set_metric_type_cmd);
  863. route_map_install_set (&route_set_tag_cmd);
  864. install_element (RMAP_NODE, &match_ip_nexthop_cmd);
  865. install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
  866. install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd);
  867. install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  868. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  869. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  870. install_element (RMAP_NODE, &match_ip_address_cmd);
  871. install_element (RMAP_NODE, &no_match_ip_address_cmd);
  872. install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  873. install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  874. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  875. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  876. install_element (RMAP_NODE, &match_interface_cmd);
  877. install_element (RMAP_NODE, &no_match_interface_cmd);
  878. install_element (RMAP_NODE, &no_match_interface_val_cmd);
  879. install_element (RMAP_NODE, &match_tag_cmd);
  880. install_element (RMAP_NODE, &no_match_tag_cmd);
  881. install_element (RMAP_NODE, &no_match_tag_val_cmd);
  882. install_element (RMAP_NODE, &set_metric_cmd);
  883. install_element (RMAP_NODE, &no_set_metric_cmd);
  884. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  885. install_element (RMAP_NODE, &set_metric_type_cmd);
  886. install_element (RMAP_NODE, &no_set_metric_type_cmd);
  887. install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
  888. install_element (RMAP_NODE, &set_tag_cmd);
  889. install_element (RMAP_NODE, &no_set_tag_cmd);
  890. install_element (RMAP_NODE, &no_set_tag_val_cmd);
  891. }