rip_routemap.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. /* RIPv2 routemap.
  2. * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * 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 Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "memory.h"
  23. #include "prefix.h"
  24. #include "routemap.h"
  25. #include "command.h"
  26. #include "filter.h"
  27. #include "log.h"
  28. #include "sockunion.h" /* for inet_aton () */
  29. #include "plist.h"
  30. #include "ripd/ripd.h"
  31. struct rip_metric_modifier
  32. {
  33. enum
  34. {
  35. metric_increment,
  36. metric_decrement,
  37. metric_absolute
  38. } type;
  39. u_char metric;
  40. };
  41. /* Add rip route map rule. */
  42. int
  43. rip_route_match_add (struct vty *vty, struct route_map_index *index,
  44. const char *command, char *arg)
  45. {
  46. int ret;
  47. ret = route_map_add_match (index, command, arg);
  48. if (ret)
  49. {
  50. switch (ret)
  51. {
  52. case RMAP_RULE_MISSING:
  53. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  54. return CMD_WARNING;
  55. case RMAP_COMPILE_ERROR:
  56. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  57. return CMD_WARNING;
  58. }
  59. }
  60. return CMD_SUCCESS;
  61. }
  62. /* Delete rip route map rule. */
  63. int
  64. rip_route_match_delete (struct vty *vty, struct route_map_index *index,
  65. const char *command, char *arg)
  66. {
  67. int ret;
  68. ret = route_map_delete_match (index, command, arg);
  69. if (ret)
  70. {
  71. switch (ret)
  72. {
  73. case RMAP_RULE_MISSING:
  74. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  75. return CMD_WARNING;
  76. case RMAP_COMPILE_ERROR:
  77. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  78. return CMD_WARNING;
  79. }
  80. }
  81. return CMD_SUCCESS;
  82. }
  83. /* Add rip route map rule. */
  84. int
  85. rip_route_set_add (struct vty *vty, struct route_map_index *index,
  86. const char *command, char *arg)
  87. {
  88. int ret;
  89. ret = route_map_add_set (index, command, arg);
  90. if (ret)
  91. {
  92. switch (ret)
  93. {
  94. case RMAP_RULE_MISSING:
  95. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  96. return CMD_WARNING;
  97. case RMAP_COMPILE_ERROR:
  98. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  99. return CMD_WARNING;
  100. }
  101. }
  102. return CMD_SUCCESS;
  103. }
  104. /* Delete rip route map rule. */
  105. int
  106. rip_route_set_delete (struct vty *vty, struct route_map_index *index,
  107. const char *command, char *arg)
  108. {
  109. int ret;
  110. ret = route_map_delete_set (index, command, arg);
  111. if (ret)
  112. {
  113. switch (ret)
  114. {
  115. case RMAP_RULE_MISSING:
  116. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  117. return CMD_WARNING;
  118. case RMAP_COMPILE_ERROR:
  119. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  120. return CMD_WARNING;
  121. }
  122. }
  123. return CMD_SUCCESS;
  124. }
  125. /* Hook function for updating route_map assignment. */
  126. /* ARGSUSED */
  127. void
  128. rip_route_map_update (char *notused)
  129. {
  130. int i;
  131. if (rip)
  132. {
  133. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  134. {
  135. if (rip->route_map[i].name)
  136. rip->route_map[i].map =
  137. route_map_lookup_by_name (rip->route_map[i].name);
  138. }
  139. }
  140. }
  141. /* `match metric METRIC' */
  142. /* Match function return 1 if match is success else return zero. */
  143. route_map_result_t
  144. route_match_metric (void *rule, struct prefix *prefix,
  145. route_map_object_t type, void *object)
  146. {
  147. u_int32_t *metric;
  148. struct rip_info *rinfo;
  149. if (type == RMAP_RIP)
  150. {
  151. metric = rule;
  152. rinfo = object;
  153. if (rinfo->metric == *metric)
  154. return RMAP_MATCH;
  155. else
  156. return RMAP_NOMATCH;
  157. }
  158. return RMAP_NOMATCH;
  159. }
  160. /* Route map `match metric' match statement. `arg' is METRIC value */
  161. void *
  162. route_match_metric_compile (char *arg)
  163. {
  164. u_int32_t *metric;
  165. metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  166. *metric = atoi (arg);
  167. if(*metric > 0)
  168. return metric;
  169. XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
  170. return NULL;
  171. }
  172. /* Free route map's compiled `match metric' value. */
  173. void
  174. route_match_metric_free (void *rule)
  175. {
  176. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  177. }
  178. /* Route map commands for metric matching. */
  179. struct route_map_rule_cmd route_match_metric_cmd =
  180. {
  181. "metric",
  182. route_match_metric,
  183. route_match_metric_compile,
  184. route_match_metric_free
  185. };
  186. /* `match interface IFNAME' */
  187. /* Match function return 1 if match is success else return zero. */
  188. route_map_result_t
  189. route_match_interface (void *rule, struct prefix *prefix,
  190. route_map_object_t type, void *object)
  191. {
  192. struct rip_info *rinfo;
  193. struct interface *ifp;
  194. char *ifname;
  195. if (type == RMAP_RIP)
  196. {
  197. ifname = rule;
  198. ifp = if_lookup_by_name(ifname);
  199. if (!ifp)
  200. return RMAP_NOMATCH;
  201. rinfo = object;
  202. if (rinfo->ifindex_out == ifp->ifindex)
  203. return RMAP_MATCH;
  204. else
  205. return RMAP_NOMATCH;
  206. }
  207. return RMAP_NOMATCH;
  208. }
  209. /* Route map `match interface' match statement. `arg' is IFNAME value */
  210. /* XXX I don`t know if I need to check does interface exist? */
  211. void *
  212. route_match_interface_compile (char *arg)
  213. {
  214. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  215. }
  216. /* Free route map's compiled `match interface' value. */
  217. void
  218. route_match_interface_free (void *rule)
  219. {
  220. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  221. }
  222. /* Route map commands for interface matching. */
  223. struct route_map_rule_cmd route_match_interface_cmd =
  224. {
  225. "interface",
  226. route_match_interface,
  227. route_match_interface_compile,
  228. route_match_interface_free
  229. };
  230. /* `match ip next-hop IP_ACCESS_LIST' */
  231. /* Match function return 1 if match is success else return zero. */
  232. route_map_result_t
  233. route_match_ip_next_hop (void *rule, struct prefix *prefix,
  234. route_map_object_t type, void *object)
  235. {
  236. struct access_list *alist;
  237. struct rip_info *rinfo;
  238. struct prefix_ipv4 p;
  239. if (type == RMAP_RIP)
  240. {
  241. rinfo = object;
  242. p.family = AF_INET;
  243. p.prefix = rinfo->nexthop;
  244. p.prefixlen = IPV4_MAX_BITLEN;
  245. alist = access_list_lookup (AFI_IP, (char *) rule);
  246. if (alist == NULL)
  247. return RMAP_NOMATCH;
  248. return (access_list_apply (alist, &p) == FILTER_DENY ?
  249. RMAP_NOMATCH : RMAP_MATCH);
  250. }
  251. return RMAP_NOMATCH;
  252. }
  253. /* Route map `ip next-hop' match statement. `arg' should be
  254. access-list name. */
  255. void *
  256. route_match_ip_next_hop_compile (char *arg)
  257. {
  258. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  259. }
  260. /* Free route map's compiled `. */
  261. void
  262. route_match_ip_next_hop_free (void *rule)
  263. {
  264. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  265. }
  266. /* Route map commands for ip next-hop matching. */
  267. struct route_map_rule_cmd route_match_ip_next_hop_cmd =
  268. {
  269. "ip next-hop",
  270. route_match_ip_next_hop,
  271. route_match_ip_next_hop_compile,
  272. route_match_ip_next_hop_free
  273. };
  274. /* `match ip next-hop prefix-list PREFIX_LIST' */
  275. route_map_result_t
  276. route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
  277. route_map_object_t type, void *object)
  278. {
  279. struct prefix_list *plist;
  280. struct rip_info *rinfo;
  281. struct prefix_ipv4 p;
  282. if (type == RMAP_RIP)
  283. {
  284. rinfo = object;
  285. p.family = AF_INET;
  286. p.prefix = rinfo->nexthop;
  287. p.prefixlen = IPV4_MAX_BITLEN;
  288. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  289. if (plist == NULL)
  290. return RMAP_NOMATCH;
  291. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  292. RMAP_NOMATCH : RMAP_MATCH);
  293. }
  294. return RMAP_NOMATCH;
  295. }
  296. void *
  297. route_match_ip_next_hop_prefix_list_compile (char *arg)
  298. {
  299. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  300. }
  301. void
  302. route_match_ip_next_hop_prefix_list_free (void *rule)
  303. {
  304. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  305. }
  306. struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
  307. {
  308. "ip next-hop prefix-list",
  309. route_match_ip_next_hop_prefix_list,
  310. route_match_ip_next_hop_prefix_list_compile,
  311. route_match_ip_next_hop_prefix_list_free
  312. };
  313. /* `match ip address IP_ACCESS_LIST' */
  314. /* Match function should return 1 if match is success else return
  315. zero. */
  316. route_map_result_t
  317. route_match_ip_address (void *rule, struct prefix *prefix,
  318. route_map_object_t type, void *object)
  319. {
  320. struct access_list *alist;
  321. if (type == RMAP_RIP)
  322. {
  323. alist = access_list_lookup (AFI_IP, (char *) rule);
  324. if (alist == NULL)
  325. return RMAP_NOMATCH;
  326. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  327. RMAP_NOMATCH : RMAP_MATCH);
  328. }
  329. return RMAP_NOMATCH;
  330. }
  331. /* Route map `ip address' match statement. `arg' should be
  332. access-list name. */
  333. void *
  334. route_match_ip_address_compile (char *arg)
  335. {
  336. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  337. }
  338. /* Free route map's compiled `ip address' value. */
  339. void
  340. route_match_ip_address_free (void *rule)
  341. {
  342. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  343. }
  344. /* Route map commands for ip address matching. */
  345. struct route_map_rule_cmd route_match_ip_address_cmd =
  346. {
  347. "ip address",
  348. route_match_ip_address,
  349. route_match_ip_address_compile,
  350. route_match_ip_address_free
  351. };
  352. /* `match ip address prefix-list PREFIX_LIST' */
  353. route_map_result_t
  354. route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
  355. route_map_object_t type, void *object)
  356. {
  357. struct prefix_list *plist;
  358. if (type == RMAP_RIP)
  359. {
  360. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  361. if (plist == NULL)
  362. return RMAP_NOMATCH;
  363. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  364. RMAP_NOMATCH : RMAP_MATCH);
  365. }
  366. return RMAP_NOMATCH;
  367. }
  368. void *
  369. route_match_ip_address_prefix_list_compile (char *arg)
  370. {
  371. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  372. }
  373. void
  374. route_match_ip_address_prefix_list_free (void *rule)
  375. {
  376. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  377. }
  378. struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
  379. {
  380. "ip address prefix-list",
  381. route_match_ip_address_prefix_list,
  382. route_match_ip_address_prefix_list_compile,
  383. route_match_ip_address_prefix_list_free
  384. };
  385. /* `match tag TAG' */
  386. /* Match function return 1 if match is success else return zero. */
  387. route_map_result_t
  388. route_match_tag (void *rule, struct prefix *prefix,
  389. route_map_object_t type, void *object)
  390. {
  391. u_short *tag;
  392. struct rip_info *rinfo;
  393. if (type == RMAP_RIP)
  394. {
  395. tag = rule;
  396. rinfo = object;
  397. /* The information stored by rinfo is host ordered. */
  398. if (rinfo->tag == *tag)
  399. return RMAP_MATCH;
  400. else
  401. return RMAP_NOMATCH;
  402. }
  403. return RMAP_NOMATCH;
  404. }
  405. /* Route map `match tag' match statement. `arg' is TAG value */
  406. void *
  407. route_match_tag_compile (char *arg)
  408. {
  409. u_short *tag;
  410. tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
  411. *tag = atoi (arg);
  412. return tag;
  413. }
  414. /* Free route map's compiled `match tag' value. */
  415. void
  416. route_match_tag_free (void *rule)
  417. {
  418. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  419. }
  420. /* Route map commands for tag matching. */
  421. struct route_map_rule_cmd route_match_tag_cmd =
  422. {
  423. "tag",
  424. route_match_tag,
  425. route_match_tag_compile,
  426. route_match_tag_free
  427. };
  428. /* `set metric METRIC' */
  429. /* Set metric to attribute. */
  430. route_map_result_t
  431. route_set_metric (void *rule, struct prefix *prefix,
  432. route_map_object_t type, void *object)
  433. {
  434. if (type == RMAP_RIP)
  435. {
  436. struct rip_metric_modifier *mod;
  437. struct rip_info *rinfo;
  438. mod = rule;
  439. rinfo = object;
  440. if (mod->type == metric_increment)
  441. rinfo->metric_out += mod->metric;
  442. else if (mod->type == metric_decrement)
  443. rinfo->metric_out -= mod->metric;
  444. else if (mod->type == metric_absolute)
  445. rinfo->metric_out = mod->metric;
  446. if (rinfo->metric_out < 1)
  447. rinfo->metric_out = 1;
  448. if (rinfo->metric_out > RIP_METRIC_INFINITY)
  449. rinfo->metric_out = RIP_METRIC_INFINITY;
  450. rinfo->metric_set = 1;
  451. }
  452. return RMAP_OKAY;
  453. }
  454. /* set metric compilation. */
  455. void *
  456. route_set_metric_compile (char *arg)
  457. {
  458. int len;
  459. char *pnt;
  460. int type;
  461. long metric;
  462. char *endptr = NULL;
  463. struct rip_metric_modifier *mod;
  464. len = strlen (arg);
  465. pnt = arg;
  466. if (len == 0)
  467. return NULL;
  468. /* Examine first character. */
  469. if (arg[0] == '+')
  470. {
  471. type = metric_increment;
  472. pnt++;
  473. }
  474. else if (arg[0] == '-')
  475. {
  476. type = metric_decrement;
  477. pnt++;
  478. }
  479. else
  480. type = metric_absolute;
  481. /* Check beginning with digit string. */
  482. if (*pnt < '0' || *pnt > '9')
  483. return NULL;
  484. /* Convert string to integer. */
  485. metric = strtol (pnt, &endptr, 10);
  486. if (metric == LONG_MAX || *endptr != '\0')
  487. return NULL;
  488. if (metric < 0 || metric > RIP_METRIC_INFINITY)
  489. return NULL;
  490. mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  491. sizeof (struct rip_metric_modifier));
  492. mod->type = type;
  493. mod->metric = metric;
  494. return mod;
  495. }
  496. /* Free route map's compiled `set metric' value. */
  497. void
  498. route_set_metric_free (void *rule)
  499. {
  500. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  501. }
  502. /* Set metric rule structure. */
  503. struct route_map_rule_cmd route_set_metric_cmd =
  504. {
  505. "metric",
  506. route_set_metric,
  507. route_set_metric_compile,
  508. route_set_metric_free,
  509. };
  510. /* `set ip next-hop IP_ADDRESS' */
  511. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  512. route_map_result_t
  513. route_set_ip_nexthop (void *rule, struct prefix *prefix,
  514. route_map_object_t type, void *object)
  515. {
  516. struct in_addr *address;
  517. struct rip_info *rinfo;
  518. if(type == RMAP_RIP)
  519. {
  520. /* Fetch routemap's rule information. */
  521. address = rule;
  522. rinfo = object;
  523. /* Set next hop value. */
  524. rinfo->nexthop_out = *address;
  525. }
  526. return RMAP_OKAY;
  527. }
  528. /* Route map `ip nexthop' compile function. Given string is converted
  529. to struct in_addr structure. */
  530. void *
  531. route_set_ip_nexthop_compile (char *arg)
  532. {
  533. int ret;
  534. struct in_addr *address;
  535. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  536. ret = inet_aton (arg, address);
  537. if (ret == 0)
  538. {
  539. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  540. return NULL;
  541. }
  542. return address;
  543. }
  544. /* Free route map's compiled `ip nexthop' value. */
  545. void
  546. route_set_ip_nexthop_free (void *rule)
  547. {
  548. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  549. }
  550. /* Route map commands for ip nexthop set. */
  551. struct route_map_rule_cmd route_set_ip_nexthop_cmd =
  552. {
  553. "ip next-hop",
  554. route_set_ip_nexthop,
  555. route_set_ip_nexthop_compile,
  556. route_set_ip_nexthop_free
  557. };
  558. /* `set tag TAG' */
  559. /* Set tag to object. ojbect must be pointer to struct attr. */
  560. route_map_result_t
  561. route_set_tag (void *rule, struct prefix *prefix,
  562. route_map_object_t type, void *object)
  563. {
  564. u_short *tag;
  565. struct rip_info *rinfo;
  566. if(type == RMAP_RIP)
  567. {
  568. /* Fetch routemap's rule information. */
  569. tag = rule;
  570. rinfo = object;
  571. /* Set next hop value. */
  572. rinfo->tag_out = *tag;
  573. }
  574. return RMAP_OKAY;
  575. }
  576. /* Route map `tag' compile function. Given string is converted
  577. to u_short. */
  578. void *
  579. route_set_tag_compile (char *arg)
  580. {
  581. u_short *tag;
  582. tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
  583. *tag = atoi (arg);
  584. return tag;
  585. }
  586. /* Free route map's compiled `ip nexthop' value. */
  587. void
  588. route_set_tag_free (void *rule)
  589. {
  590. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  591. }
  592. /* Route map commands for tag set. */
  593. struct route_map_rule_cmd route_set_tag_cmd =
  594. {
  595. "tag",
  596. route_set_tag,
  597. route_set_tag_compile,
  598. route_set_tag_free
  599. };
  600. #define MATCH_STR "Match values from routing table\n"
  601. #define SET_STR "Set values in destination routing protocol\n"
  602. DEFUN (match_metric,
  603. match_metric_cmd,
  604. "match metric <0-4294967295>",
  605. MATCH_STR
  606. "Match metric of route\n"
  607. "Metric value\n")
  608. {
  609. return rip_route_match_add (vty, vty->index, "metric", argv[0]);
  610. }
  611. DEFUN (no_match_metric,
  612. no_match_metric_cmd,
  613. "no match metric",
  614. NO_STR
  615. MATCH_STR
  616. "Match metric of route\n")
  617. {
  618. if (argc == 0)
  619. return rip_route_match_delete (vty, vty->index, "metric", NULL);
  620. return rip_route_match_delete (vty, vty->index, "metric", argv[0]);
  621. }
  622. ALIAS (no_match_metric,
  623. no_match_metric_val_cmd,
  624. "no match metric <0-4294967295>",
  625. NO_STR
  626. MATCH_STR
  627. "Match metric of route\n"
  628. "Metric value\n")
  629. DEFUN (match_interface,
  630. match_interface_cmd,
  631. "match interface WORD",
  632. MATCH_STR
  633. "Match first hop interface of route\n"
  634. "Interface name\n")
  635. {
  636. return rip_route_match_add (vty, vty->index, "interface", argv[0]);
  637. }
  638. DEFUN (no_match_interface,
  639. no_match_interface_cmd,
  640. "no match interface",
  641. NO_STR
  642. MATCH_STR
  643. "Match first hop interface of route\n")
  644. {
  645. if (argc == 0)
  646. return rip_route_match_delete (vty, vty->index, "interface", NULL);
  647. return rip_route_match_delete (vty, vty->index, "interface", argv[0]);
  648. }
  649. ALIAS (no_match_interface,
  650. no_match_interface_val_cmd,
  651. "no match interface WORD",
  652. NO_STR
  653. MATCH_STR
  654. "Match first hop interface of route\n"
  655. "Interface name\n")
  656. DEFUN (match_ip_next_hop,
  657. match_ip_next_hop_cmd,
  658. "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  659. MATCH_STR
  660. IP_STR
  661. "Match next-hop address of route\n"
  662. "IP access-list number\n"
  663. "IP access-list number (expanded range)\n"
  664. "IP Access-list name\n")
  665. {
  666. return rip_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  667. }
  668. DEFUN (no_match_ip_next_hop,
  669. no_match_ip_next_hop_cmd,
  670. "no match ip next-hop",
  671. NO_STR
  672. MATCH_STR
  673. IP_STR
  674. "Match next-hop address of route\n")
  675. {
  676. if (argc == 0)
  677. return rip_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  678. return rip_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  679. }
  680. ALIAS (no_match_ip_next_hop,
  681. no_match_ip_next_hop_val_cmd,
  682. "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  683. NO_STR
  684. MATCH_STR
  685. IP_STR
  686. "Match next-hop address of route\n"
  687. "IP access-list number\n"
  688. "IP access-list number (expanded range)\n"
  689. "IP Access-list name\n")
  690. DEFUN (match_ip_next_hop_prefix_list,
  691. match_ip_next_hop_prefix_list_cmd,
  692. "match ip next-hop prefix-list WORD",
  693. MATCH_STR
  694. IP_STR
  695. "Match next-hop address of route\n"
  696. "Match entries of prefix-lists\n"
  697. "IP prefix-list name\n")
  698. {
  699. return rip_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  700. }
  701. DEFUN (no_match_ip_next_hop_prefix_list,
  702. no_match_ip_next_hop_prefix_list_cmd,
  703. "no match ip next-hop prefix-list",
  704. NO_STR
  705. MATCH_STR
  706. IP_STR
  707. "Match next-hop address of route\n"
  708. "Match entries of prefix-lists\n")
  709. {
  710. if (argc == 0)
  711. return rip_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
  712. return rip_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  713. }
  714. ALIAS (no_match_ip_next_hop_prefix_list,
  715. no_match_ip_next_hop_prefix_list_val_cmd,
  716. "no match ip next-hop prefix-list WORD",
  717. NO_STR
  718. MATCH_STR
  719. IP_STR
  720. "Match next-hop address of route\n"
  721. "Match entries of prefix-lists\n"
  722. "IP prefix-list name\n")
  723. DEFUN (match_ip_address,
  724. match_ip_address_cmd,
  725. "match ip address (<1-199>|<1300-2699>|WORD)",
  726. MATCH_STR
  727. IP_STR
  728. "Match address of route\n"
  729. "IP access-list number\n"
  730. "IP access-list number (expanded range)\n"
  731. "IP Access-list name\n")
  732. {
  733. return rip_route_match_add (vty, vty->index, "ip address", argv[0]);
  734. }
  735. DEFUN (no_match_ip_address,
  736. no_match_ip_address_cmd,
  737. "no match ip address",
  738. NO_STR
  739. MATCH_STR
  740. IP_STR
  741. "Match address of route\n")
  742. {
  743. if (argc == 0)
  744. return rip_route_match_delete (vty, vty->index, "ip address", NULL);
  745. return rip_route_match_delete (vty, vty->index, "ip address", argv[0]);
  746. }
  747. ALIAS (no_match_ip_address,
  748. no_match_ip_address_val_cmd,
  749. "no match ip address (<1-199>|<1300-2699>|WORD)",
  750. NO_STR
  751. MATCH_STR
  752. IP_STR
  753. "Match address of route\n"
  754. "IP access-list number\n"
  755. "IP access-list number (expanded range)\n"
  756. "IP Access-list name\n")
  757. DEFUN (match_ip_address_prefix_list,
  758. match_ip_address_prefix_list_cmd,
  759. "match ip address prefix-list WORD",
  760. MATCH_STR
  761. IP_STR
  762. "Match address of route\n"
  763. "Match entries of prefix-lists\n"
  764. "IP prefix-list name\n")
  765. {
  766. return rip_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
  767. }
  768. DEFUN (no_match_ip_address_prefix_list,
  769. no_match_ip_address_prefix_list_cmd,
  770. "no match ip address prefix-list",
  771. NO_STR
  772. MATCH_STR
  773. IP_STR
  774. "Match address of route\n"
  775. "Match entries of prefix-lists\n")
  776. {
  777. if (argc == 0)
  778. return rip_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
  779. return rip_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
  780. }
  781. ALIAS (no_match_ip_address_prefix_list,
  782. no_match_ip_address_prefix_list_val_cmd,
  783. "no match ip address prefix-list WORD",
  784. NO_STR
  785. MATCH_STR
  786. IP_STR
  787. "Match address of route\n"
  788. "Match entries of prefix-lists\n"
  789. "IP prefix-list name\n")
  790. DEFUN (match_tag,
  791. match_tag_cmd,
  792. "match tag <0-65535>",
  793. MATCH_STR
  794. "Match tag of route\n"
  795. "Metric value\n")
  796. {
  797. return rip_route_match_add (vty, vty->index, "tag", argv[0]);
  798. }
  799. DEFUN (no_match_tag,
  800. no_match_tag_cmd,
  801. "no match tag",
  802. NO_STR
  803. MATCH_STR
  804. "Match tag of route\n")
  805. {
  806. if (argc == 0)
  807. return rip_route_match_delete (vty, vty->index, "tag", NULL);
  808. return rip_route_match_delete (vty, vty->index, "tag", argv[0]);
  809. }
  810. ALIAS (no_match_tag,
  811. no_match_tag_val_cmd,
  812. "no match tag <0-65535>",
  813. NO_STR
  814. MATCH_STR
  815. "Match tag of route\n"
  816. "Metric value\n")
  817. /* set functions */
  818. DEFUN (set_metric,
  819. set_metric_cmd,
  820. "set metric <0-4294967295>",
  821. SET_STR
  822. "Metric value for destination routing protocol\n"
  823. "Metric value\n")
  824. {
  825. return rip_route_set_add (vty, vty->index, "metric", argv[0]);
  826. }
  827. ALIAS (set_metric,
  828. set_metric_addsub_cmd,
  829. "set metric <+/-metric>",
  830. SET_STR
  831. "Metric value for destination routing protocol\n"
  832. "Add or subtract BGP metric\n")
  833. DEFUN (no_set_metric,
  834. no_set_metric_cmd,
  835. "no set metric",
  836. NO_STR
  837. SET_STR
  838. "Metric value for destination routing protocol\n")
  839. {
  840. if (argc == 0)
  841. return rip_route_set_delete (vty, vty->index, "metric", NULL);
  842. return rip_route_set_delete (vty, vty->index, "metric", argv[0]);
  843. }
  844. ALIAS (no_set_metric,
  845. no_set_metric_val_cmd,
  846. "no set metric (<0-4294967295>|<+/-metric>)",
  847. NO_STR
  848. SET_STR
  849. "Metric value for destination routing protocol\n"
  850. "Metric value\n"
  851. "Add or subtract metric\n")
  852. DEFUN (set_ip_nexthop,
  853. set_ip_nexthop_cmd,
  854. "set ip next-hop A.B.C.D",
  855. SET_STR
  856. IP_STR
  857. "Next hop address\n"
  858. "IP address of next hop\n")
  859. {
  860. union sockunion su;
  861. int ret;
  862. ret = str2sockunion (argv[0], &su);
  863. if (ret < 0)
  864. {
  865. vty_out (vty, "%% Malformed next-hop address%s", VTY_NEWLINE);
  866. return CMD_WARNING;
  867. }
  868. return rip_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
  869. }
  870. DEFUN (no_set_ip_nexthop,
  871. no_set_ip_nexthop_cmd,
  872. "no set ip next-hop",
  873. NO_STR
  874. SET_STR
  875. IP_STR
  876. "Next hop address\n")
  877. {
  878. if (argc == 0)
  879. return rip_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  880. return rip_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
  881. }
  882. ALIAS (no_set_ip_nexthop,
  883. no_set_ip_nexthop_val_cmd,
  884. "no set ip next-hop A.B.C.D",
  885. NO_STR
  886. SET_STR
  887. IP_STR
  888. "Next hop address\n"
  889. "IP address of next hop\n")
  890. DEFUN (set_tag,
  891. set_tag_cmd,
  892. "set tag <0-65535>",
  893. SET_STR
  894. "Tag value for routing protocol\n"
  895. "Tag value\n")
  896. {
  897. return rip_route_set_add (vty, vty->index, "tag", argv[0]);
  898. }
  899. DEFUN (no_set_tag,
  900. no_set_tag_cmd,
  901. "no set tag",
  902. NO_STR
  903. SET_STR
  904. "Tag value for routing protocol\n")
  905. {
  906. if (argc == 0)
  907. return rip_route_set_delete (vty, vty->index, "tag", NULL);
  908. return rip_route_set_delete (vty, vty->index, "tag", argv[0]);
  909. }
  910. ALIAS (no_set_tag,
  911. no_set_tag_val_cmd,
  912. "no set tag <0-65535>",
  913. NO_STR
  914. SET_STR
  915. "Tag value for routing protocol\n"
  916. "Tag value\n")
  917. void
  918. rip_route_map_reset ()
  919. {
  920. ;
  921. }
  922. /* Route-map init */
  923. void
  924. rip_route_map_init ()
  925. {
  926. route_map_init ();
  927. route_map_init_vty ();
  928. route_map_add_hook (rip_route_map_update);
  929. route_map_delete_hook (rip_route_map_update);
  930. route_map_install_match (&route_match_metric_cmd);
  931. route_map_install_match (&route_match_interface_cmd);
  932. route_map_install_match (&route_match_ip_next_hop_cmd);
  933. route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  934. route_map_install_match (&route_match_ip_address_cmd);
  935. route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  936. route_map_install_match (&route_match_tag_cmd);
  937. route_map_install_set (&route_set_metric_cmd);
  938. route_map_install_set (&route_set_ip_nexthop_cmd);
  939. route_map_install_set (&route_set_tag_cmd);
  940. install_element (RMAP_NODE, &match_metric_cmd);
  941. install_element (RMAP_NODE, &no_match_metric_cmd);
  942. install_element (RMAP_NODE, &no_match_metric_val_cmd);
  943. install_element (RMAP_NODE, &match_interface_cmd);
  944. install_element (RMAP_NODE, &no_match_interface_cmd);
  945. install_element (RMAP_NODE, &no_match_interface_val_cmd);
  946. install_element (RMAP_NODE, &match_ip_next_hop_cmd);
  947. install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
  948. install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
  949. install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  950. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  951. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  952. install_element (RMAP_NODE, &match_ip_address_cmd);
  953. install_element (RMAP_NODE, &no_match_ip_address_cmd);
  954. install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  955. install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  956. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  957. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  958. install_element (RMAP_NODE, &match_tag_cmd);
  959. install_element (RMAP_NODE, &no_match_tag_cmd);
  960. install_element (RMAP_NODE, &no_match_tag_val_cmd);
  961. install_element (RMAP_NODE, &set_metric_cmd);
  962. install_element (RMAP_NODE, &set_metric_addsub_cmd);
  963. install_element (RMAP_NODE, &no_set_metric_cmd);
  964. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  965. install_element (RMAP_NODE, &set_ip_nexthop_cmd);
  966. install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
  967. install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
  968. install_element (RMAP_NODE, &set_tag_cmd);
  969. install_element (RMAP_NODE, &no_set_tag_cmd);
  970. install_element (RMAP_NODE, &no_set_tag_val_cmd);
  971. }