You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5045 lines
143 KiB

  1. From 0c0e73045b1898610eef9309b9f5927254356710 Mon Sep 17 00:00:00 2001
  2. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  3. Date: Fri, 27 Sep 2019 19:32:10 -0300
  4. Subject: [PATCH 01/10] yang: update route map model
  5. Important changes:
  6. * Rename top container `route-map` to `lib`;
  7. * Rename list `instance` to `route-map`;
  8. * Move route map repeated data to list `entry`;
  9. * Use interface reference instead of typedef'ed string;
  10. * Remove some zebra specific route map conditions;
  11. * Protect `tag` set value with `when "./action = 'tag'"`;
  12. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  13. ---
  14. From a7282663eff6f036a427165b7fa73c75dccd47ff Mon Sep 17 00:00:00 2001
  15. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  16. Date: Mon, 30 Sep 2019 10:17:33 -0300
  17. Subject: [PATCH 02/10] lib: export route map structures and functions
  18. These exported items are going to be used by the new northbound CLI.
  19. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  20. ---
  21. lib/routemap.c | 213 ++-----------------------------------------------
  22. lib/routemap.h | 209 ++++++++++++++++++++++++++++++++++++++++++++++++
  23. 2 files changed, 216 insertions(+), 206 deletions(-)
  24. diff --git a/lib/routemap.c b/lib/routemap.c
  25. index 14fec0283c..a8feebd313 100644
  26. --- a/lib/routemap.c
  27. +++ b/lib/routemap.c
  28. @@ -50,178 +50,7 @@ static vector route_match_vec;
  29. /* Vector for route set rules. */
  30. static vector route_set_vec;
  31. -struct route_map_match_set_hooks {
  32. - /* match interface */
  33. - int (*match_interface)(struct vty *vty, struct route_map_index *index,
  34. - const char *command, const char *arg,
  35. - route_map_event_t type);
  36. -
  37. - /* no match interface */
  38. - int (*no_match_interface)(struct vty *vty,
  39. - struct route_map_index *index,
  40. - const char *command, const char *arg,
  41. - route_map_event_t type);
  42. -
  43. - /* match ip address */
  44. - int (*match_ip_address)(struct vty *vty, struct route_map_index *index,
  45. - const char *command, const char *arg,
  46. - route_map_event_t type);
  47. -
  48. - /* no match ip address */
  49. - int (*no_match_ip_address)(struct vty *vty,
  50. - struct route_map_index *index,
  51. - const char *command, const char *arg,
  52. - route_map_event_t type);
  53. -
  54. - /* match ip address prefix list */
  55. - int (*match_ip_address_prefix_list)(struct vty *vty,
  56. - struct route_map_index *index,
  57. - const char *command,
  58. - const char *arg,
  59. - route_map_event_t type);
  60. -
  61. - /* no match ip address prefix list */
  62. - int (*no_match_ip_address_prefix_list)(struct vty *vty,
  63. - struct route_map_index *index,
  64. - const char *command,
  65. - const char *arg,
  66. - route_map_event_t type);
  67. -
  68. - /* match ip next hop */
  69. - int (*match_ip_next_hop)(struct vty *vty, struct route_map_index *index,
  70. - const char *command, const char *arg,
  71. - route_map_event_t type);
  72. -
  73. - /* no match ip next hop */
  74. - int (*no_match_ip_next_hop)(struct vty *vty,
  75. - struct route_map_index *index,
  76. - const char *command, const char *arg,
  77. - route_map_event_t type);
  78. -
  79. - /* match ip next hop prefix list */
  80. - int (*match_ip_next_hop_prefix_list)(struct vty *vty,
  81. - struct route_map_index *index,
  82. - const char *command,
  83. - const char *arg,
  84. - route_map_event_t type);
  85. -
  86. - /* no match ip next hop prefix list */
  87. - int (*no_match_ip_next_hop_prefix_list)(struct vty *vty,
  88. - struct route_map_index *index,
  89. - const char *command,
  90. - const char *arg,
  91. - route_map_event_t type);
  92. -
  93. - /* match ip next-hop type */
  94. - int (*match_ip_next_hop_type)(struct vty *vty,
  95. - struct route_map_index *index,
  96. - const char *command,
  97. - const char *arg,
  98. - route_map_event_t type);
  99. -
  100. - /* no match ip next-hop type */
  101. - int (*no_match_ip_next_hop_type)(struct vty *vty,
  102. - struct route_map_index *index,
  103. - const char *command,
  104. - const char *arg,
  105. - route_map_event_t type);
  106. -
  107. - /* match ipv6 address */
  108. - int (*match_ipv6_address)(struct vty *vty,
  109. - struct route_map_index *index,
  110. - const char *command, const char *arg,
  111. - route_map_event_t type);
  112. -
  113. - /* no match ipv6 address */
  114. - int (*no_match_ipv6_address)(struct vty *vty,
  115. - struct route_map_index *index,
  116. - const char *command, const char *arg,
  117. - route_map_event_t type);
  118. -
  119. -
  120. - /* match ipv6 address prefix list */
  121. - int (*match_ipv6_address_prefix_list)(struct vty *vty,
  122. - struct route_map_index *index,
  123. - const char *command,
  124. - const char *arg,
  125. - route_map_event_t type);
  126. -
  127. - /* no match ipv6 address prefix list */
  128. - int (*no_match_ipv6_address_prefix_list)(struct vty *vty,
  129. - struct route_map_index *index,
  130. - const char *command,
  131. - const char *arg,
  132. - route_map_event_t type);
  133. -
  134. - /* match ipv6 next-hop type */
  135. - int (*match_ipv6_next_hop_type)(struct vty *vty,
  136. - struct route_map_index *index,
  137. - const char *command,
  138. - const char *arg,
  139. - route_map_event_t type);
  140. -
  141. - /* no match ipv6 next-hop type */
  142. - int (*no_match_ipv6_next_hop_type)(struct vty *vty,
  143. - struct route_map_index *index,
  144. - const char *command, const char *arg,
  145. - route_map_event_t type);
  146. -
  147. - /* match metric */
  148. - int (*match_metric)(struct vty *vty, struct route_map_index *index,
  149. - const char *command, const char *arg,
  150. - route_map_event_t type);
  151. -
  152. - /* no match metric */
  153. - int (*no_match_metric)(struct vty *vty, struct route_map_index *index,
  154. - const char *command, const char *arg,
  155. - route_map_event_t type);
  156. -
  157. - /* match tag */
  158. - int (*match_tag)(struct vty *vty, struct route_map_index *index,
  159. - const char *command, const char *arg,
  160. - route_map_event_t type);
  161. -
  162. - /* no match tag */
  163. - int (*no_match_tag)(struct vty *vty, struct route_map_index *index,
  164. - const char *command, const char *arg,
  165. - route_map_event_t type);
  166. -
  167. - /* set ip nexthop */
  168. - int (*set_ip_nexthop)(struct vty *vty, struct route_map_index *index,
  169. - const char *command, const char *arg);
  170. -
  171. - /* no set ip nexthop */
  172. - int (*no_set_ip_nexthop)(struct vty *vty, struct route_map_index *index,
  173. - const char *command, const char *arg);
  174. -
  175. - /* set ipv6 nexthop local */
  176. - int (*set_ipv6_nexthop_local)(struct vty *vty,
  177. - struct route_map_index *index,
  178. - const char *command, const char *arg);
  179. -
  180. - /* no set ipv6 nexthop local */
  181. - int (*no_set_ipv6_nexthop_local)(struct vty *vty,
  182. - struct route_map_index *index,
  183. - const char *command, const char *arg);
  184. -
  185. - /* set metric */
  186. - int (*set_metric)(struct vty *vty, struct route_map_index *index,
  187. - const char *command, const char *arg);
  188. -
  189. - /* no set metric */
  190. - int (*no_set_metric)(struct vty *vty, struct route_map_index *index,
  191. - const char *command, const char *arg);
  192. -
  193. - /* set tag */
  194. - int (*set_tag)(struct vty *vty, struct route_map_index *index,
  195. - const char *command, const char *arg);
  196. -
  197. - /* no set tag */
  198. - int (*no_set_tag)(struct vty *vty, struct route_map_index *index,
  199. - const char *command, const char *arg);
  200. -};
  201. -
  202. -static struct route_map_match_set_hooks rmap_match_set_hook;
  203. +struct route_map_match_set_hooks rmap_match_set_hook;
  204. /* match interface */
  205. void route_map_match_interface_hook(int (*func)(
  206. @@ -595,35 +424,9 @@ int generic_set_delete(struct vty *vty, struct route_map_index *index,
  207. }
  208. -/* Route map rule. This rule has both `match' rule and `set' rule. */
  209. -struct route_map_rule {
  210. - /* Rule type. */
  211. - const struct route_map_rule_cmd *cmd;
  212. -
  213. - /* For pretty printing. */
  214. - char *rule_str;
  215. -
  216. - /* Pre-compiled match rule. */
  217. - void *value;
  218. -
  219. - /* Linked list. */
  220. - struct route_map_rule *next;
  221. - struct route_map_rule *prev;
  222. -};
  223. -
  224. -/* Making route map list. */
  225. -struct route_map_list {
  226. - struct route_map *head;
  227. - struct route_map *tail;
  228. -
  229. - void (*add_hook)(const char *);
  230. - void (*delete_hook)(const char *);
  231. - void (*event_hook)(const char *);
  232. -};
  233. -
  234. /* Master list of route map. */
  235. -static struct route_map_list route_map_master = {NULL, NULL, NULL, NULL, NULL};
  236. -static struct hash *route_map_master_hash = NULL;
  237. +struct route_map_list route_map_master = {NULL, NULL, NULL, NULL, NULL};
  238. +struct hash *route_map_master_hash = NULL;
  239. static unsigned int route_map_hash_key_make(const void *p)
  240. {
  241. @@ -691,8 +494,6 @@ static void route_map_rule_delete(struct route_map_rule_list *,
  242. struct route_map_rule *);
  243. static bool rmap_debug;
  244. -static void route_map_index_delete(struct route_map_index *, int);
  245. -
  246. /* New route map allocation. Please note route map's name must be
  247. specified. */
  248. static struct route_map *route_map_new(const char *name)
  249. @@ -784,7 +585,7 @@ static void route_map_free_map(struct route_map *map)
  250. }
  251. /* Route map delete from list. */
  252. -static void route_map_delete(struct route_map *map)
  253. +void route_map_delete(struct route_map *map)
  254. {
  255. struct route_map_index *index;
  256. char *name;
  257. @@ -883,7 +684,7 @@ static int route_map_clear_updated(struct route_map *map)
  258. /* Lookup route map. If there isn't route map create one and return
  259. it. */
  260. -static struct route_map *route_map_get(const char *name)
  261. +struct route_map *route_map_get(const char *name)
  262. {
  263. struct route_map *map;
  264. @@ -1097,7 +898,7 @@ static struct route_map_index *route_map_index_new(void)
  265. }
  266. /* Free route map index. */
  267. -static void route_map_index_delete(struct route_map_index *index, int notify)
  268. +void route_map_index_delete(struct route_map_index *index, int notify)
  269. {
  270. struct route_map_rule *rule;
  271. @@ -1202,7 +1003,7 @@ route_map_index_add(struct route_map *map, enum route_map_type type, int pref)
  272. }
  273. /* Get route map index. */
  274. -static struct route_map_index *
  275. +struct route_map_index *
  276. route_map_index_get(struct route_map *map, enum route_map_type type, int pref)
  277. {
  278. struct route_map_index *index;
  279. diff --git a/lib/routemap.h b/lib/routemap.h
  280. index 1ffd0525ae..41959c24e5 100644
  281. --- a/lib/routemap.h
  282. +++ b/lib/routemap.h
  283. @@ -140,6 +140,22 @@ enum rmap_compile_rets {
  284. };
  285. +/* Route map rule. This rule has both `match' rule and `set' rule. */
  286. +struct route_map_rule {
  287. + /* Rule type. */
  288. + const struct route_map_rule_cmd *cmd;
  289. +
  290. + /* For pretty printing. */
  291. + char *rule_str;
  292. +
  293. + /* Pre-compiled match rule. */
  294. + void *value;
  295. +
  296. + /* Linked list. */
  297. + struct route_map_rule *next;
  298. + struct route_map_rule *prev;
  299. +};
  300. +
  301. /* Route map rule list. */
  302. struct route_map_rule_list {
  303. struct route_map_rule *head;
  304. @@ -435,6 +451,199 @@ extern void route_map_counter_increment(struct route_map *map);
  305. /* Decrement the route-map used counter */
  306. extern void route_map_counter_decrement(struct route_map *map);
  307. +/* Route map hooks data structure. */
  308. +struct route_map_match_set_hooks {
  309. + /* match interface */
  310. + int (*match_interface)(struct vty *vty, struct route_map_index *index,
  311. + const char *command, const char *arg,
  312. + route_map_event_t type);
  313. +
  314. + /* no match interface */
  315. + int (*no_match_interface)(struct vty *vty,
  316. + struct route_map_index *index,
  317. + const char *command, const char *arg,
  318. + route_map_event_t type);
  319. +
  320. + /* match ip address */
  321. + int (*match_ip_address)(struct vty *vty, struct route_map_index *index,
  322. + const char *command, const char *arg,
  323. + route_map_event_t type);
  324. +
  325. + /* no match ip address */
  326. + int (*no_match_ip_address)(struct vty *vty,
  327. + struct route_map_index *index,
  328. + const char *command, const char *arg,
  329. + route_map_event_t type);
  330. +
  331. + /* match ip address prefix list */
  332. + int (*match_ip_address_prefix_list)(struct vty *vty,
  333. + struct route_map_index *index,
  334. + const char *command,
  335. + const char *arg,
  336. + route_map_event_t type);
  337. +
  338. + /* no match ip address prefix list */
  339. + int (*no_match_ip_address_prefix_list)(struct vty *vty,
  340. + struct route_map_index *index,
  341. + const char *command,
  342. + const char *arg,
  343. + route_map_event_t type);
  344. +
  345. + /* match ip next hop */
  346. + int (*match_ip_next_hop)(struct vty *vty, struct route_map_index *index,
  347. + const char *command, const char *arg,
  348. + route_map_event_t type);
  349. +
  350. + /* no match ip next hop */
  351. + int (*no_match_ip_next_hop)(struct vty *vty,
  352. + struct route_map_index *index,
  353. + const char *command, const char *arg,
  354. + route_map_event_t type);
  355. +
  356. + /* match ip next hop prefix list */
  357. + int (*match_ip_next_hop_prefix_list)(struct vty *vty,
  358. + struct route_map_index *index,
  359. + const char *command,
  360. + const char *arg,
  361. + route_map_event_t type);
  362. +
  363. + /* no match ip next hop prefix list */
  364. + int (*no_match_ip_next_hop_prefix_list)(struct vty *vty,
  365. + struct route_map_index *index,
  366. + const char *command,
  367. + const char *arg,
  368. + route_map_event_t type);
  369. +
  370. + /* match ip next-hop type */
  371. + int (*match_ip_next_hop_type)(struct vty *vty,
  372. + struct route_map_index *index,
  373. + const char *command,
  374. + const char *arg,
  375. + route_map_event_t type);
  376. +
  377. + /* no match ip next-hop type */
  378. + int (*no_match_ip_next_hop_type)(struct vty *vty,
  379. + struct route_map_index *index,
  380. + const char *command,
  381. + const char *arg,
  382. + route_map_event_t type);
  383. +
  384. + /* match ipv6 address */
  385. + int (*match_ipv6_address)(struct vty *vty,
  386. + struct route_map_index *index,
  387. + const char *command, const char *arg,
  388. + route_map_event_t type);
  389. +
  390. + /* no match ipv6 address */
  391. + int (*no_match_ipv6_address)(struct vty *vty,
  392. + struct route_map_index *index,
  393. + const char *command, const char *arg,
  394. + route_map_event_t type);
  395. +
  396. +
  397. + /* match ipv6 address prefix list */
  398. + int (*match_ipv6_address_prefix_list)(struct vty *vty,
  399. + struct route_map_index *index,
  400. + const char *command,
  401. + const char *arg,
  402. + route_map_event_t type);
  403. +
  404. + /* no match ipv6 address prefix list */
  405. + int (*no_match_ipv6_address_prefix_list)(struct vty *vty,
  406. + struct route_map_index *index,
  407. + const char *command,
  408. + const char *arg,
  409. + route_map_event_t type);
  410. +
  411. + /* match ipv6 next-hop type */
  412. + int (*match_ipv6_next_hop_type)(struct vty *vty,
  413. + struct route_map_index *index,
  414. + const char *command,
  415. + const char *arg,
  416. + route_map_event_t type);
  417. +
  418. + /* no match ipv6 next-hop type */
  419. + int (*no_match_ipv6_next_hop_type)(struct vty *vty,
  420. + struct route_map_index *index,
  421. + const char *command, const char *arg,
  422. + route_map_event_t type);
  423. +
  424. + /* match metric */
  425. + int (*match_metric)(struct vty *vty, struct route_map_index *index,
  426. + const char *command, const char *arg,
  427. + route_map_event_t type);
  428. +
  429. + /* no match metric */
  430. + int (*no_match_metric)(struct vty *vty, struct route_map_index *index,
  431. + const char *command, const char *arg,
  432. + route_map_event_t type);
  433. +
  434. + /* match tag */
  435. + int (*match_tag)(struct vty *vty, struct route_map_index *index,
  436. + const char *command, const char *arg,
  437. + route_map_event_t type);
  438. +
  439. + /* no match tag */
  440. + int (*no_match_tag)(struct vty *vty, struct route_map_index *index,
  441. + const char *command, const char *arg,
  442. + route_map_event_t type);
  443. +
  444. + /* set ip nexthop */
  445. + int (*set_ip_nexthop)(struct vty *vty, struct route_map_index *index,
  446. + const char *command, const char *arg);
  447. +
  448. + /* no set ip nexthop */
  449. + int (*no_set_ip_nexthop)(struct vty *vty, struct route_map_index *index,
  450. + const char *command, const char *arg);
  451. +
  452. + /* set ipv6 nexthop local */
  453. + int (*set_ipv6_nexthop_local)(struct vty *vty,
  454. + struct route_map_index *index,
  455. + const char *command, const char *arg);
  456. +
  457. + /* no set ipv6 nexthop local */
  458. + int (*no_set_ipv6_nexthop_local)(struct vty *vty,
  459. + struct route_map_index *index,
  460. + const char *command, const char *arg);
  461. +
  462. + /* set metric */
  463. + int (*set_metric)(struct vty *vty, struct route_map_index *index,
  464. + const char *command, const char *arg);
  465. +
  466. + /* no set metric */
  467. + int (*no_set_metric)(struct vty *vty, struct route_map_index *index,
  468. + const char *command, const char *arg);
  469. +
  470. + /* set tag */
  471. + int (*set_tag)(struct vty *vty, struct route_map_index *index,
  472. + const char *command, const char *arg);
  473. +
  474. + /* no set tag */
  475. + int (*no_set_tag)(struct vty *vty, struct route_map_index *index,
  476. + const char *command, const char *arg);
  477. +};
  478. +
  479. +extern struct route_map_match_set_hooks rmap_match_set_hook;
  480. +
  481. +/* Making route map list. */
  482. +struct route_map_list {
  483. + struct route_map *head;
  484. + struct route_map *tail;
  485. +
  486. + void (*add_hook)(const char *);
  487. + void (*delete_hook)(const char *);
  488. + void (*event_hook)(const char *);
  489. +};
  490. +
  491. +extern struct route_map_list route_map_master;
  492. +
  493. +extern struct route_map *route_map_get(const char *name);
  494. +extern void route_map_delete(struct route_map *map);
  495. +extern struct route_map_index *route_map_index_get(struct route_map *map,
  496. + enum route_map_type type,
  497. + int pref);
  498. +extern void route_map_index_delete(struct route_map_index *index, int notify);
  499. +
  500. #ifdef __cplusplus
  501. }
  502. #endif
  503. From 686d244f00d87fa0b76c8e4644550d413fc3400b Mon Sep 17 00:00:00 2001
  504. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  505. Date: Mon, 30 Sep 2019 10:34:49 -0300
  506. Subject: [PATCH 03/10] lib: implement route map northbound
  507. Based on the route map old CLI, implement the route map handling using
  508. the exported functions.
  509. Use a curry-like programming pattern avoid code repetition when
  510. destroying match/set entries. This is needed by other daemons that
  511. implement custom route map functions and need to pass to lib their
  512. specific destroy functions.
  513. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  514. ---
  515. lib/routemap.h | 24 +
  516. lib/routemap_northbound.c | 1393 +++++++++++++++++++++++++++++++++++++
  517. lib/subdir.am | 2 +
  518. yang/subdir.am | 1 +
  519. 4 files changed, 1420 insertions(+)
  520. create mode 100644 lib/routemap_northbound.c
  521. diff --git a/lib/routemap.h b/lib/routemap.h
  522. index 41959c24e5..d9e7f73f81 100644
  523. --- a/lib/routemap.h
  524. +++ b/lib/routemap.h
  525. @@ -644,6 +644,30 @@ extern struct route_map_index *route_map_index_get(struct route_map *map,
  526. int pref);
  527. extern void route_map_index_delete(struct route_map_index *index, int notify);
  528. +/* routemap_northbound.c */
  529. +typedef int (*routemap_match_hook_fun)(struct vty *vty,
  530. + struct route_map_index *rmi,
  531. + const char *command, const char *arg,
  532. + route_map_event_t event);
  533. +
  534. +typedef int (*routemap_set_hook_fun)(struct vty *vty,
  535. + struct route_map_index *rmi,
  536. + const char *command, const char *arg);
  537. +
  538. +struct routemap_hook_context {
  539. + struct route_map_index *rhc_rmi;
  540. + const char *rhc_rule;
  541. + route_map_event_t rhc_event;
  542. + routemap_set_hook_fun rhc_shook;
  543. + routemap_match_hook_fun rhc_mhook;
  544. +};
  545. +
  546. +int lib_route_map_entry_match_destroy(enum nb_event event,
  547. + const struct lyd_node *dnode);
  548. +int lib_route_map_entry_set_destroy(enum nb_event event,
  549. + const struct lyd_node *dnode);
  550. +extern const struct frr_yang_module_info frr_route_map_info;
  551. +
  552. #ifdef __cplusplus
  553. }
  554. #endif
  555. diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
  556. new file mode 100644
  557. index 0000000000..02eb756334
  558. --- /dev/null
  559. +++ b/lib/routemap_northbound.c
  560. @@ -0,0 +1,1393 @@
  561. +/*
  562. + * Route map northbound implementation.
  563. + *
  564. + * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
  565. + * Rafael Zalamena
  566. + *
  567. + * This program is free software; you can redistribute it and/or modify
  568. + * it under the terms of the GNU General Public License as published by
  569. + * the Free Software Foundation; either version 2 of the License, or
  570. + * (at your option) any later version.
  571. + *
  572. + * This program is distributed in the hope that it will be useful,
  573. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  574. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  575. + * GNU General Public License for more details.
  576. + *
  577. + * You should have received a copy of the GNU General Public License
  578. + * along with this program; if not, write to the Free Software
  579. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  580. + * 02110-1301 USA.
  581. + */
  582. +
  583. +#include <zebra.h>
  584. +
  585. +#include "lib/command.h"
  586. +#include "lib/log.h"
  587. +#include "lib/northbound.h"
  588. +#include "lib/routemap.h"
  589. +
  590. +/*
  591. + * Auxiliary functions to avoid code duplication:
  592. + *
  593. + * lib_route_map_entry_set_destroy: unset `set` commands.
  594. + * lib_route_map_entry_match_destroy: unset `match` commands.
  595. + */
  596. +int lib_route_map_entry_match_destroy(enum nb_event event,
  597. + const struct lyd_node *dnode)
  598. +{
  599. + struct routemap_hook_context *rhc;
  600. + int rv;
  601. +
  602. + if (event != NB_EV_APPLY)
  603. + return NB_OK;
  604. +
  605. + rhc = nb_running_get_entry(dnode, NULL, true);
  606. + if (rhc->rhc_mhook == NULL)
  607. + return NB_OK;
  608. +
  609. + rv = rhc->rhc_mhook(NULL, rhc->rhc_rmi, rhc->rhc_rule, NULL,
  610. + rhc->rhc_event);
  611. + if (rv != CMD_SUCCESS)
  612. + return NB_ERR_INCONSISTENCY;
  613. +
  614. + return NB_OK;
  615. +}
  616. +
  617. +int lib_route_map_entry_set_destroy(enum nb_event event,
  618. + const struct lyd_node *dnode)
  619. +{
  620. + struct routemap_hook_context *rhc;
  621. + int rv;
  622. +
  623. + if (event != NB_EV_APPLY)
  624. + return NB_OK;
  625. +
  626. + rhc = nb_running_get_entry(dnode, NULL, true);
  627. + if (rhc->rhc_shook == NULL)
  628. + return NB_OK;
  629. +
  630. + rv = rhc->rhc_shook(NULL, rhc->rhc_rmi, rhc->rhc_rule, NULL);
  631. + if (rv != CMD_SUCCESS)
  632. + return NB_ERR_INCONSISTENCY;
  633. +
  634. + return NB_OK;
  635. +}
  636. +
  637. +/*
  638. + * XPath: /frr-route-map:lib/route-map
  639. + */
  640. +static int lib_route_map_create(enum nb_event event,
  641. + const struct lyd_node *dnode,
  642. + union nb_resource *resource)
  643. +{
  644. + struct route_map *rm;
  645. + const char *rm_name;
  646. +
  647. + switch (event) {
  648. + case NB_EV_VALIDATE:
  649. + case NB_EV_PREPARE:
  650. + case NB_EV_ABORT:
  651. + /* NOTHING */
  652. + break;
  653. + case NB_EV_APPLY:
  654. + rm_name = yang_dnode_get_string(dnode, "./name");
  655. + rm = route_map_get(rm_name);
  656. + nb_running_set_entry(dnode, rm);
  657. + break;
  658. + }
  659. +
  660. + return NB_OK;
  661. +}
  662. +
  663. +static int lib_route_map_destroy(enum nb_event event,
  664. + const struct lyd_node *dnode)
  665. +{
  666. + struct route_map *rm;
  667. +
  668. + switch (event) {
  669. + case NB_EV_VALIDATE:
  670. + case NB_EV_PREPARE:
  671. + case NB_EV_ABORT:
  672. + /* NOTHING */
  673. + break;
  674. + case NB_EV_APPLY:
  675. + rm = nb_running_unset_entry(dnode);
  676. + route_map_delete(rm);
  677. + break;
  678. + }
  679. +
  680. + return NB_OK;
  681. +}
  682. +
  683. +/*
  684. + * XPath: /frr-route-map:lib/route-map/entry
  685. + */
  686. +static int lib_route_map_entry_create(enum nb_event event,
  687. + const struct lyd_node *dnode,
  688. + union nb_resource *resource)
  689. +{
  690. + struct route_map_index *rmi;
  691. + struct route_map *rm;
  692. + uint16_t sequence;
  693. + int action;
  694. +
  695. + switch (event) {
  696. + case NB_EV_VALIDATE:
  697. + case NB_EV_PREPARE:
  698. + case NB_EV_ABORT:
  699. + /* NOTHING */
  700. + break;
  701. + case NB_EV_APPLY:
  702. + sequence = yang_dnode_get_uint16(dnode, "./sequence");
  703. + action = yang_dnode_get_enum(dnode, "./action") == 0
  704. + ? RMAP_PERMIT
  705. + : RMAP_DENY;
  706. + rm = nb_running_get_entry(dnode, NULL, true);
  707. + rmi = route_map_index_get(rm, action, sequence);
  708. + nb_running_set_entry(dnode, rmi);
  709. + break;
  710. + }
  711. +
  712. + return NB_OK;
  713. +}
  714. +
  715. +static int lib_route_map_entry_destroy(enum nb_event event,
  716. + const struct lyd_node *dnode)
  717. +{
  718. + struct route_map_index *rmi;
  719. +
  720. + switch (event) {
  721. + case NB_EV_VALIDATE:
  722. + case NB_EV_PREPARE:
  723. + case NB_EV_ABORT:
  724. + /* NOTHING */
  725. + break;
  726. + case NB_EV_APPLY:
  727. + rmi = nb_running_unset_entry(dnode);
  728. + route_map_index_delete(rmi, 1);
  729. + break;
  730. + }
  731. +
  732. + return NB_OK;
  733. +}
  734. +
  735. +/*
  736. + * XPath: /frr-route-map:lib/route-map/entry/description
  737. + */
  738. +static int lib_route_map_entry_description_modify(enum nb_event event,
  739. + const struct lyd_node *dnode,
  740. + union nb_resource *resource)
  741. +{
  742. + struct route_map_index *rmi;
  743. + const char *description;
  744. +
  745. + switch (event) {
  746. + case NB_EV_VALIDATE:
  747. + /* NOTHING */
  748. + break;
  749. + case NB_EV_PREPARE:
  750. + description = yang_dnode_get_string(dnode, NULL);
  751. + resource->ptr = XSTRDUP(MTYPE_TMP, description);
  752. + if (resource->ptr == NULL)
  753. + return NB_ERR_RESOURCE;
  754. + break;
  755. + case NB_EV_ABORT:
  756. + XFREE(MTYPE_TMP, resource->ptr);
  757. + break;
  758. + case NB_EV_APPLY:
  759. + rmi = nb_running_get_entry(dnode, NULL, true);
  760. + if (rmi->description != NULL)
  761. + XFREE(MTYPE_TMP, rmi->description);
  762. + rmi->description = resource->ptr;
  763. + break;
  764. + }
  765. +
  766. + return NB_OK;
  767. +}
  768. +
  769. +static int lib_route_map_entry_description_destroy(enum nb_event event,
  770. + const struct lyd_node *dnode)
  771. +{
  772. + struct route_map_index *rmi;
  773. +
  774. + switch (event) {
  775. + case NB_EV_VALIDATE:
  776. + case NB_EV_PREPARE:
  777. + case NB_EV_ABORT:
  778. + /* NOTHING */
  779. + break;
  780. + case NB_EV_APPLY:
  781. + rmi = nb_running_get_entry(dnode, NULL, true);
  782. + if (rmi->description != NULL)
  783. + XFREE(MTYPE_TMP, rmi->description);
  784. + rmi->description = NULL;
  785. + break;
  786. + }
  787. +
  788. + return NB_OK;
  789. +}
  790. +
  791. +/*
  792. + * XPath: /frr-route-map:lib/route-map/entry/action
  793. + */
  794. +static int lib_route_map_entry_action_modify(enum nb_event event,
  795. + const struct lyd_node *dnode,
  796. + union nb_resource *resource)
  797. +{
  798. + struct route_map_index *rmi;
  799. +
  800. + switch (event) {
  801. + case NB_EV_VALIDATE:
  802. + case NB_EV_PREPARE:
  803. + case NB_EV_ABORT:
  804. + /* NOTHING */
  805. + break;
  806. + case NB_EV_APPLY:
  807. + rmi = nb_running_get_entry(dnode, NULL, true);
  808. + rmi->type = yang_dnode_get_enum(dnode, NULL);
  809. + /* TODO: notify? */
  810. + break;
  811. + }
  812. +
  813. + return NB_OK;
  814. +}
  815. +
  816. +/*
  817. + * XPath: /frr-route-map:lib/route-map/entry/call
  818. + */
  819. +static int lib_route_map_entry_call_modify(enum nb_event event,
  820. + const struct lyd_node *dnode,
  821. + union nb_resource *resource)
  822. +{
  823. + struct route_map_index *rmi;
  824. + const char *rm_name, *rmn_name;
  825. +
  826. + switch (event) {
  827. + case NB_EV_VALIDATE:
  828. + rm_name = yang_dnode_get_string(dnode, "../../name");
  829. + rmn_name = yang_dnode_get_string(dnode, NULL);
  830. + /* Don't allow to jump to the same route map instance. */
  831. + if (strcmp(rm_name, rmn_name) == 0)
  832. + return NB_ERR_VALIDATION;
  833. +
  834. + /* TODO: detect circular route map sequences. */
  835. + break;
  836. + case NB_EV_PREPARE:
  837. + rmn_name = yang_dnode_get_string(dnode, NULL);
  838. + resource->ptr = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmn_name);
  839. + break;
  840. + case NB_EV_ABORT:
  841. + XFREE(MTYPE_ROUTE_MAP_NAME, resource->ptr);
  842. + break;
  843. + case NB_EV_APPLY:
  844. + rmi = nb_running_get_entry(dnode, NULL, true);
  845. + if (rmi->nextrm) {
  846. + route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED,
  847. + rmi->nextrm, rmi->map->name);
  848. + XFREE(MTYPE_ROUTE_MAP_NAME, rmi->nextrm);
  849. + }
  850. + rmi->nextrm = resource->ptr;
  851. + route_map_upd8_dependency(RMAP_EVENT_CALL_ADDED, rmi->nextrm,
  852. + rmi->map->name);
  853. + break;
  854. + }
  855. +
  856. + return NB_OK;
  857. +}
  858. +
  859. +static int lib_route_map_entry_call_destroy(enum nb_event event,
  860. + const struct lyd_node *dnode)
  861. +{
  862. + struct route_map_index *rmi;
  863. +
  864. + switch (event) {
  865. + case NB_EV_VALIDATE:
  866. + case NB_EV_PREPARE:
  867. + case NB_EV_ABORT:
  868. + /* NOTHING */
  869. + break;
  870. + case NB_EV_APPLY:
  871. + rmi = nb_running_get_entry(dnode, NULL, true);
  872. + route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED, rmi->nextrm,
  873. + rmi->map->name);
  874. + XFREE(MTYPE_ROUTE_MAP_NAME, rmi->nextrm);
  875. + rmi->nextrm = NULL;
  876. + break;
  877. + }
  878. +
  879. + return NB_OK;
  880. +}
  881. +
  882. +/*
  883. + * XPath: /frr-route-map:lib/route-map/entry/exit-policy
  884. + */
  885. +static int lib_route_map_entry_exit_policy_modify(enum nb_event event,
  886. + const struct lyd_node *dnode,
  887. + union nb_resource *resource)
  888. +{
  889. + struct route_map_index *rmi;
  890. + int rm_action;
  891. + int policy;
  892. +
  893. + switch (event) {
  894. + case NB_EV_VALIDATE:
  895. + policy = yang_dnode_get_enum(dnode, NULL);
  896. + switch (policy) {
  897. + case 0: /* permit-or-deny */
  898. + break;
  899. + case 1: /* next */
  900. + /* FALLTHROUGH */
  901. + case 2: /* goto */
  902. + rm_action = yang_dnode_get_enum(dnode, "../action");
  903. + if (rm_action == 1 /* deny */) {
  904. + /*
  905. + * On deny it is not possible to 'goto'
  906. + * anywhere.
  907. + */
  908. + return NB_ERR_VALIDATION;
  909. + }
  910. + break;
  911. + }
  912. + break;
  913. + case NB_EV_PREPARE:
  914. + case NB_EV_ABORT:
  915. + break;
  916. + case NB_EV_APPLY:
  917. + rmi = nb_running_get_entry(dnode, NULL, true);
  918. + policy = yang_dnode_get_enum(dnode, NULL);
  919. +
  920. + switch (policy) {
  921. + case 0: /* permit-or-deny */
  922. + rmi->exitpolicy = RMAP_EXIT;
  923. + break;
  924. + case 1: /* next */
  925. + rmi->exitpolicy = RMAP_NEXT;
  926. + break;
  927. + case 2: /* goto */
  928. + rmi->exitpolicy = RMAP_GOTO;
  929. + break;
  930. + }
  931. + break;
  932. + }
  933. +
  934. + return NB_OK;
  935. +}
  936. +
  937. +/*
  938. + * XPath: /frr-route-map:lib/route-map/entry/goto-value
  939. + */
  940. +static int lib_route_map_entry_goto_value_modify(enum nb_event event,
  941. + const struct lyd_node *dnode,
  942. + union nb_resource *resource)
  943. +{
  944. + struct route_map_index *rmi;
  945. + uint16_t rmi_index;
  946. + uint16_t rmi_next;
  947. +
  948. + switch (event) {
  949. + case NB_EV_VALIDATE:
  950. + rmi_index = yang_dnode_get_uint16(dnode, "../sequence");
  951. + rmi_next = yang_dnode_get_uint16(dnode, NULL);
  952. + if (rmi_next <= rmi_index) {
  953. + /* Can't jump backwards on a route map. */
  954. + return NB_ERR_VALIDATION;
  955. + }
  956. + break;
  957. + case NB_EV_PREPARE:
  958. + case NB_EV_ABORT:
  959. + /* NOTHING */
  960. + break;
  961. + case NB_EV_APPLY:
  962. + rmi = nb_running_get_entry(dnode, NULL, true);
  963. + rmi->nextpref = yang_dnode_get_uint16(dnode, NULL);
  964. + break;
  965. + }
  966. +
  967. + return NB_OK;
  968. +}
  969. +
  970. +static int lib_route_map_entry_goto_value_destroy(enum nb_event event,
  971. + const struct lyd_node *dnode)
  972. +{
  973. + struct route_map_index *rmi;
  974. +
  975. + switch (event) {
  976. + case NB_EV_VALIDATE:
  977. + case NB_EV_PREPARE:
  978. + case NB_EV_ABORT:
  979. + /* NOTHING */
  980. + break;
  981. + case NB_EV_APPLY:
  982. + rmi = nb_running_get_entry(dnode, NULL, true);
  983. + rmi->nextpref = 0;
  984. + break;
  985. + }
  986. +
  987. + return NB_OK;
  988. +}
  989. +
  990. +/*
  991. + * XPath: /frr-route-map:lib/route-map/entry/match-condition
  992. + */
  993. +static int
  994. +lib_route_map_entry_match_condition_create(enum nb_event event,
  995. + const struct lyd_node *dnode,
  996. + union nb_resource *resource)
  997. +{
  998. + struct routemap_hook_context *rhc;
  999. +
  1000. + switch (event) {
  1001. + case NB_EV_VALIDATE:
  1002. + /* NOTHING */
  1003. + break;
  1004. + case NB_EV_PREPARE:
  1005. + resource->ptr = XCALLOC(MTYPE_TMP, sizeof(*rhc));
  1006. + break;
  1007. + case NB_EV_ABORT:
  1008. + XFREE(MTYPE_TMP, resource->ptr);
  1009. + break;
  1010. + case NB_EV_APPLY:
  1011. + rhc = resource->ptr;
  1012. + rhc->rhc_rmi = nb_running_get_entry(dnode, NULL, true);
  1013. + nb_running_set_entry(dnode, rhc);
  1014. + break;
  1015. + }
  1016. +
  1017. + return NB_OK;
  1018. +}
  1019. +
  1020. +static int
  1021. +lib_route_map_entry_match_condition_destroy(enum nb_event event,
  1022. + const struct lyd_node *dnode)
  1023. +{
  1024. + struct routemap_hook_context *rhc;
  1025. + int rv;
  1026. +
  1027. + if (event != NB_EV_APPLY)
  1028. + return NB_OK;
  1029. +
  1030. + rv = lib_route_map_entry_match_destroy(event, dnode);
  1031. + rhc = nb_running_unset_entry(dnode);
  1032. + XFREE(MTYPE_TMP, rhc);
  1033. +
  1034. + return rv;
  1035. +}
  1036. +
  1037. +/*
  1038. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/interface
  1039. + */
  1040. +static int lib_route_map_entry_match_condition_interface_modify(
  1041. + enum nb_event event, const struct lyd_node *dnode,
  1042. + union nb_resource *resource)
  1043. +{
  1044. + struct routemap_hook_context *rhc;
  1045. + const char *ifname;
  1046. + int rv;
  1047. +
  1048. + if (event != NB_EV_APPLY)
  1049. + return NB_OK;
  1050. +
  1051. + /* Check for hook function. */
  1052. + if (rmap_match_set_hook.match_interface == NULL)
  1053. + return NB_OK;
  1054. +
  1055. + /* Add configuration. */
  1056. + rhc = nb_running_get_entry(dnode, NULL, true);
  1057. + ifname = yang_dnode_get_string(dnode, NULL);
  1058. +
  1059. + /* Set destroy information. */
  1060. + rhc->rhc_mhook = rmap_match_set_hook.no_match_interface;
  1061. + rhc->rhc_rule = "interface";
  1062. + rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
  1063. +
  1064. + rv = rmap_match_set_hook.match_interface(NULL, rhc->rhc_rmi,
  1065. + "interface", ifname,
  1066. + RMAP_EVENT_MATCH_ADDED);
  1067. + if (rv != CMD_SUCCESS) {
  1068. + rhc->rhc_mhook = NULL;
  1069. + return NB_ERR_INCONSISTENCY;
  1070. + }
  1071. +
  1072. + return NB_OK;
  1073. +}
  1074. +
  1075. +static int lib_route_map_entry_match_condition_interface_destroy(
  1076. + enum nb_event event, const struct lyd_node *dnode)
  1077. +{
  1078. + return lib_route_map_entry_match_destroy(event, dnode);
  1079. +}
  1080. +
  1081. +/*
  1082. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/access-list-num
  1083. + */
  1084. +static int lib_route_map_entry_match_condition_access_list_num_modify(
  1085. + enum nb_event event, const struct lyd_node *dnode,
  1086. + union nb_resource *resource)
  1087. +{
  1088. + struct routemap_hook_context *rhc;
  1089. + const char *acl;
  1090. + int condition, rv;
  1091. +
  1092. + if (event != NB_EV_APPLY)
  1093. + return NB_OK;
  1094. +
  1095. + /* Check for hook function. */
  1096. + rv = CMD_SUCCESS;
  1097. + acl = yang_dnode_get_string(dnode, NULL);
  1098. + rhc = nb_running_get_entry(dnode, NULL, true);
  1099. + condition = yang_dnode_get_enum(dnode, "../condition");
  1100. + switch (condition) {
  1101. + case 1: /* ipv4-address-list */
  1102. + if (rmap_match_set_hook.match_ip_address == NULL)
  1103. + break;
  1104. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_address;
  1105. + rhc->rhc_rule = "ip address";
  1106. + rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
  1107. + rv = rmap_match_set_hook.match_ip_address(
  1108. + NULL, rhc->rhc_rmi, "ip address", acl,
  1109. + RMAP_EVENT_FILTER_ADDED);
  1110. + break;
  1111. + case 3: /* ipv4-next-hop-list */
  1112. + if (rmap_match_set_hook.match_ip_next_hop == NULL)
  1113. + break;
  1114. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop;
  1115. + rhc->rhc_rule = "ip next-hop";
  1116. + rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
  1117. + rv = rmap_match_set_hook.match_ip_next_hop(
  1118. + NULL, rhc->rhc_rmi, "ip next-hop", acl,
  1119. + RMAP_EVENT_FILTER_ADDED);
  1120. + break;
  1121. + }
  1122. + if (rv != CMD_SUCCESS) {
  1123. + rhc->rhc_mhook = NULL;
  1124. + return NB_ERR_INCONSISTENCY;
  1125. + }
  1126. +
  1127. + return NB_OK;
  1128. +}
  1129. +
  1130. +static int lib_route_map_entry_match_condition_access_list_num_destroy(
  1131. + enum nb_event event, const struct lyd_node *dnode)
  1132. +{
  1133. + return lib_route_map_entry_match_destroy(event, dnode);
  1134. +}
  1135. +
  1136. +/*
  1137. + * XPath:
  1138. + * /frr-route-map:lib/route-map/entry/match-condition/access-list-num-extended
  1139. + */
  1140. +static int lib_route_map_entry_match_condition_access_list_num_extended_modify(
  1141. + enum nb_event event, const struct lyd_node *dnode,
  1142. + union nb_resource *resource)
  1143. +{
  1144. + return lib_route_map_entry_match_condition_access_list_num_modify(
  1145. + event, dnode, resource);
  1146. +}
  1147. +
  1148. +static int lib_route_map_entry_match_condition_access_list_num_extended_destroy(
  1149. + enum nb_event event, const struct lyd_node *dnode)
  1150. +{
  1151. + return lib_route_map_entry_match_condition_access_list_num_destroy(
  1152. + event, dnode);
  1153. +}
  1154. +
  1155. +/*
  1156. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/list-name
  1157. + */
  1158. +static int lib_route_map_entry_match_condition_list_name_modify(
  1159. + enum nb_event event, const struct lyd_node *dnode,
  1160. + union nb_resource *resource)
  1161. +{
  1162. + struct routemap_hook_context *rhc;
  1163. + const char *acl;
  1164. + int condition;
  1165. + int rv;
  1166. +
  1167. + if (event != NB_EV_APPLY)
  1168. + return NB_OK;
  1169. +
  1170. + /* Check for hook installation, otherwise we can just stop. */
  1171. + acl = yang_dnode_get_string(dnode, NULL);
  1172. + rhc = nb_running_get_entry(dnode, NULL, true);
  1173. + condition = yang_dnode_get_enum(dnode, "../condition");
  1174. + switch (condition) {
  1175. + case 1: /* ipv4-address-list */
  1176. + if (rmap_match_set_hook.match_ip_address == NULL)
  1177. + return NB_OK;
  1178. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_address;
  1179. + rhc->rhc_rule = "ip address";
  1180. + rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
  1181. + rv = rmap_match_set_hook.match_ip_address(
  1182. + NULL, rhc->rhc_rmi, "ip address", acl,
  1183. + RMAP_EVENT_FILTER_ADDED);
  1184. + break;
  1185. + case 2: /* ipv4-prefix-list */
  1186. + if (rmap_match_set_hook.match_ip_address_prefix_list == NULL)
  1187. + return NB_OK;
  1188. + rhc->rhc_mhook =
  1189. + rmap_match_set_hook.no_match_ip_address_prefix_list;
  1190. + rhc->rhc_rule = "ip address prefix-list";
  1191. + rhc->rhc_event = RMAP_EVENT_PLIST_DELETED;
  1192. + rv = rmap_match_set_hook.match_ip_address_prefix_list(
  1193. + NULL, rhc->rhc_rmi, "ip address prefix-list", acl,
  1194. + RMAP_EVENT_PLIST_ADDED);
  1195. + break;
  1196. + case 3: /* ipv4-next-hop-list */
  1197. + if (rmap_match_set_hook.match_ip_next_hop == NULL)
  1198. + return NB_OK;
  1199. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop;
  1200. + rhc->rhc_rule = "ip next-hop";
  1201. + rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
  1202. + rv = rmap_match_set_hook.match_ip_next_hop(
  1203. + NULL, rhc->rhc_rmi, "ip next-hop", acl,
  1204. + RMAP_EVENT_FILTER_ADDED);
  1205. + break;
  1206. + case 4: /* ipv4-next-hop-prefix-list */
  1207. + if (rmap_match_set_hook.match_ip_next_hop_prefix_list == NULL)
  1208. + return NB_OK;
  1209. + rhc->rhc_mhook =
  1210. + rmap_match_set_hook.no_match_ip_next_hop_prefix_list;
  1211. + rhc->rhc_rule = "ip next-hop prefix-list";
  1212. + rhc->rhc_event = RMAP_EVENT_PLIST_DELETED;
  1213. + rv = rmap_match_set_hook.match_ip_next_hop_prefix_list(
  1214. + NULL, rhc->rhc_rmi, "ip next-hop prefix-list", acl,
  1215. + RMAP_EVENT_PLIST_ADDED);
  1216. + break;
  1217. + case 6: /* ipv6-address-list */
  1218. + if (rmap_match_set_hook.match_ipv6_address == NULL)
  1219. + return NB_OK;
  1220. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ipv6_address;
  1221. + rhc->rhc_rule = "ipv6 address";
  1222. + rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
  1223. + rv = rmap_match_set_hook.match_ipv6_address(
  1224. + NULL, rhc->rhc_rmi, "ipv6 address", acl,
  1225. + RMAP_EVENT_FILTER_ADDED);
  1226. + break;
  1227. + case 7: /* ipv6-prefix-list */
  1228. + if (rmap_match_set_hook.match_ipv6_address_prefix_list == NULL)
  1229. + return NB_OK;
  1230. + rhc->rhc_mhook =
  1231. + rmap_match_set_hook.no_match_ipv6_address_prefix_list;
  1232. + rhc->rhc_rule = "ipv6 address prefix-list";
  1233. + rhc->rhc_event = RMAP_EVENT_PLIST_DELETED;
  1234. + rv = rmap_match_set_hook.match_ipv6_address_prefix_list(
  1235. + NULL, rhc->rhc_rmi, "ipv6 address prefix-list", acl,
  1236. + RMAP_EVENT_PLIST_ADDED);
  1237. + break;
  1238. + default:
  1239. + rv = CMD_ERR_NO_MATCH;
  1240. + break;
  1241. + }
  1242. + if (rv != CMD_SUCCESS) {
  1243. + rhc->rhc_mhook = NULL;
  1244. + return NB_ERR_INCONSISTENCY;
  1245. + }
  1246. +
  1247. + return NB_OK;
  1248. +}
  1249. +
  1250. +static int lib_route_map_entry_match_condition_list_name_destroy(
  1251. + enum nb_event event, const struct lyd_node *dnode)
  1252. +{
  1253. + return lib_route_map_entry_match_destroy(event, dnode);
  1254. +}
  1255. +
  1256. +/*
  1257. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/ipv4-next-hop-type
  1258. + */
  1259. +static int lib_route_map_entry_match_condition_ipv4_next_hop_type_modify(
  1260. + enum nb_event event, const struct lyd_node *dnode,
  1261. + union nb_resource *resource)
  1262. +{
  1263. + struct routemap_hook_context *rhc;
  1264. + const char *type;
  1265. + int rv;
  1266. +
  1267. + if (event != NB_EV_APPLY)
  1268. + return NB_OK;
  1269. +
  1270. + /* Check for hook function. */
  1271. + if (rmap_match_set_hook.match_ip_next_hop_type == NULL)
  1272. + return NB_OK;
  1273. +
  1274. + /* Add configuration. */
  1275. + rhc = nb_running_get_entry(dnode, NULL, true);
  1276. + type = yang_dnode_get_string(dnode, NULL);
  1277. +
  1278. + /* Set destroy information. */
  1279. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop_type;
  1280. + rhc->rhc_rule = "ip next-hop type";
  1281. + rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
  1282. +
  1283. + rv = rmap_match_set_hook.match_ip_next_hop_type(
  1284. + NULL, rhc->rhc_rmi, "ip next-hop type", type,
  1285. + RMAP_EVENT_MATCH_ADDED);
  1286. + if (rv != CMD_SUCCESS) {
  1287. + rhc->rhc_mhook = NULL;
  1288. + return NB_ERR_INCONSISTENCY;
  1289. + }
  1290. +
  1291. + return NB_OK;
  1292. +}
  1293. +
  1294. +static int lib_route_map_entry_match_condition_ipv4_next_hop_type_destroy(
  1295. + enum nb_event event, const struct lyd_node *dnode)
  1296. +{
  1297. + return lib_route_map_entry_match_destroy(event, dnode);
  1298. +}
  1299. +
  1300. +/*
  1301. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/ipv6-next-hop-type
  1302. + */
  1303. +static int lib_route_map_entry_match_condition_ipv6_next_hop_type_modify(
  1304. + enum nb_event event, const struct lyd_node *dnode,
  1305. + union nb_resource *resource)
  1306. +{
  1307. + struct routemap_hook_context *rhc;
  1308. + const char *type;
  1309. + int rv;
  1310. +
  1311. + if (event != NB_EV_APPLY)
  1312. + return NB_OK;
  1313. +
  1314. + /* Check for hook function. */
  1315. + if (rmap_match_set_hook.match_ipv6_next_hop_type == NULL)
  1316. + return NB_OK;
  1317. +
  1318. + /* Add configuration. */
  1319. + rhc = nb_running_get_entry(dnode, NULL, true);
  1320. + type = yang_dnode_get_string(dnode, NULL);
  1321. +
  1322. + /* Set destroy information. */
  1323. + rhc->rhc_mhook = rmap_match_set_hook.no_match_ipv6_next_hop_type;
  1324. + rhc->rhc_rule = "ipv6 next-hop type";
  1325. + rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
  1326. +
  1327. + rv = rmap_match_set_hook.match_ipv6_next_hop_type(
  1328. + NULL, rhc->rhc_rmi, "ipv6 next-hop type", type,
  1329. + RMAP_EVENT_MATCH_ADDED);
  1330. + if (rv != CMD_SUCCESS) {
  1331. + rhc->rhc_mhook = NULL;
  1332. + return NB_ERR_INCONSISTENCY;
  1333. + }
  1334. +
  1335. + return NB_OK;
  1336. +}
  1337. +
  1338. +static int lib_route_map_entry_match_condition_ipv6_next_hop_type_destroy(
  1339. + enum nb_event event, const struct lyd_node *dnode)
  1340. +{
  1341. + return lib_route_map_entry_match_destroy(event, dnode);
  1342. +}
  1343. +
  1344. +/*
  1345. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/metric
  1346. + */
  1347. +static int
  1348. +lib_route_map_entry_match_condition_metric_modify(enum nb_event event,
  1349. + const struct lyd_node *dnode,
  1350. + union nb_resource *resource)
  1351. +{
  1352. + struct routemap_hook_context *rhc;
  1353. + const char *type;
  1354. + int rv;
  1355. +
  1356. + if (event != NB_EV_APPLY)
  1357. + return NB_OK;
  1358. +
  1359. + /* Check for hook function. */
  1360. + if (rmap_match_set_hook.match_metric == NULL)
  1361. + return NB_OK;
  1362. +
  1363. + /* Add configuration. */
  1364. + rhc = nb_running_get_entry(dnode, NULL, true);
  1365. + type = yang_dnode_get_string(dnode, NULL);
  1366. +
  1367. + /* Set destroy information. */
  1368. + rhc->rhc_mhook = rmap_match_set_hook.no_match_metric;
  1369. + rhc->rhc_rule = "metric";
  1370. + rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
  1371. +
  1372. + rv = rmap_match_set_hook.match_metric(NULL, rhc->rhc_rmi, "metric",
  1373. + type, RMAP_EVENT_MATCH_ADDED);
  1374. + if (rv != CMD_SUCCESS) {
  1375. + rhc->rhc_mhook = NULL;
  1376. + return NB_ERR_INCONSISTENCY;
  1377. + }
  1378. +
  1379. + return NB_OK;
  1380. +}
  1381. +
  1382. +static int
  1383. +lib_route_map_entry_match_condition_metric_destroy(enum nb_event event,
  1384. + const struct lyd_node *dnode)
  1385. +{
  1386. + return lib_route_map_entry_match_destroy(event, dnode);
  1387. +}
  1388. +
  1389. +/*
  1390. + * XPath: /frr-route-map:lib/route-map/entry/match-condition/tag
  1391. + */
  1392. +static int
  1393. +lib_route_map_entry_match_condition_tag_modify(enum nb_event event,
  1394. + const struct lyd_node *dnode,
  1395. + union nb_resource *resource)
  1396. +{
  1397. + struct routemap_hook_context *rhc;
  1398. + const char *tag;
  1399. + int rv;
  1400. +
  1401. + if (event != NB_EV_APPLY)
  1402. + return NB_OK;
  1403. +
  1404. + /* Check for hook function. */
  1405. + if (rmap_match_set_hook.match_tag == NULL)
  1406. + return NB_OK;
  1407. +
  1408. + /* Add configuration. */
  1409. + rhc = nb_running_get_entry(dnode, NULL, true);
  1410. + tag = yang_dnode_get_string(dnode, NULL);
  1411. +
  1412. + /* Set destroy information. */
  1413. + rhc->rhc_mhook = rmap_match_set_hook.no_match_tag;
  1414. + rhc->rhc_rule = "tag";
  1415. + rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
  1416. +
  1417. + rv = rmap_match_set_hook.match_tag(NULL, rhc->rhc_rmi, "tag", tag,
  1418. + RMAP_EVENT_MATCH_ADDED);
  1419. + if (rv != CMD_SUCCESS) {
  1420. + rhc->rhc_mhook = NULL;
  1421. + return NB_ERR_INCONSISTENCY;
  1422. + }
  1423. +
  1424. + return NB_OK;
  1425. +}
  1426. +
  1427. +static int
  1428. +lib_route_map_entry_match_condition_tag_destroy(enum nb_event event,
  1429. + const struct lyd_node *dnode)
  1430. +{
  1431. + return lib_route_map_entry_match_destroy(event, dnode);
  1432. +}
  1433. +
  1434. +/*
  1435. + * XPath: /frr-route-map:lib/route-map/entry/set-action
  1436. + */
  1437. +static int lib_route_map_entry_set_action_create(enum nb_event event,
  1438. + const struct lyd_node *dnode,
  1439. + union nb_resource *resource)
  1440. +{
  1441. + return lib_route_map_entry_match_condition_create(event, dnode,
  1442. + resource);
  1443. +}
  1444. +
  1445. +static int lib_route_map_entry_set_action_destroy(enum nb_event event,
  1446. + const struct lyd_node *dnode)
  1447. +{
  1448. + struct routemap_hook_context *rhc;
  1449. + int rv;
  1450. +
  1451. + if (event != NB_EV_APPLY)
  1452. + return NB_OK;
  1453. +
  1454. + rv = lib_route_map_entry_set_destroy(event, dnode);
  1455. + rhc = nb_running_unset_entry(dnode);
  1456. + XFREE(MTYPE_TMP, rhc);
  1457. +
  1458. + return rv;
  1459. +}
  1460. +
  1461. +/*
  1462. + * XPath: /frr-route-map:lib/route-map/entry/set-action/ipv4-address
  1463. + */
  1464. +static int
  1465. +lib_route_map_entry_set_action_ipv4_address_modify(enum nb_event event,
  1466. + const struct lyd_node *dnode,
  1467. + union nb_resource *resource)
  1468. +{
  1469. + struct routemap_hook_context *rhc;
  1470. + const char *address;
  1471. + struct in_addr ia;
  1472. + int rv;
  1473. +
  1474. + switch (event) {
  1475. + case NB_EV_VALIDATE:
  1476. + /*
  1477. + * NOTE: validate if 'action' is 'ipv4-next-hop',
  1478. + * currently it is not necessary because this is the
  1479. + * only implemented action.
  1480. + */
  1481. + yang_dnode_get_ipv4(&ia, dnode, NULL);
  1482. + if (ia.s_addr == 0 || IPV4_CLASS_DE(ntohl(ia.s_addr)))
  1483. + return NB_ERR_VALIDATION;
  1484. + /* FALLTHROUGH */
  1485. + case NB_EV_PREPARE:
  1486. + case NB_EV_ABORT:
  1487. + return NB_OK;
  1488. + case NB_EV_APPLY:
  1489. + break;
  1490. + }
  1491. +
  1492. + /* Check for hook function. */
  1493. + if (rmap_match_set_hook.set_ip_nexthop == NULL)
  1494. + return NB_OK;
  1495. +
  1496. + /* Add configuration. */
  1497. + rhc = nb_running_get_entry(dnode, NULL, true);
  1498. + address = yang_dnode_get_string(dnode, NULL);
  1499. +
  1500. + /* Set destroy information. */
  1501. + rhc->rhc_shook = rmap_match_set_hook.no_set_ip_nexthop;
  1502. + rhc->rhc_rule = "ip next-hop";
  1503. +
  1504. + rv = rmap_match_set_hook.set_ip_nexthop(NULL, rhc->rhc_rmi,
  1505. + "ip next-hop", address);
  1506. + if (rv != CMD_SUCCESS) {
  1507. + rhc->rhc_shook = NULL;
  1508. + return NB_ERR_INCONSISTENCY;
  1509. + }
  1510. +
  1511. + return NB_OK;
  1512. +}
  1513. +
  1514. +static int lib_route_map_entry_set_action_ipv4_address_destroy(
  1515. + enum nb_event event, const struct lyd_node *dnode)
  1516. +{
  1517. + return lib_route_map_entry_set_destroy(event, dnode);
  1518. +}
  1519. +
  1520. +/*
  1521. + * XPath: /frr-route-map:lib/route-map/entry/set-action/ipv6-address
  1522. + */
  1523. +static int
  1524. +lib_route_map_entry_set_action_ipv6_address_modify(enum nb_event event,
  1525. + const struct lyd_node *dnode,
  1526. + union nb_resource *resource)
  1527. +{
  1528. + struct routemap_hook_context *rhc;
  1529. + const char *address;
  1530. + struct in6_addr i6a;
  1531. + int rv;
  1532. +
  1533. + switch (event) {
  1534. + case NB_EV_VALIDATE:
  1535. + /*
  1536. + * NOTE: validate if 'action' is 'ipv6-next-hop',
  1537. + * currently it is not necessary because this is the
  1538. + * only implemented action. Other actions might have
  1539. + * different validations.
  1540. + */
  1541. + yang_dnode_get_ipv6(&i6a, dnode, NULL);
  1542. + if (!IN6_IS_ADDR_LINKLOCAL(&i6a))
  1543. + return NB_ERR_VALIDATION;
  1544. + /* FALLTHROUGH */
  1545. + case NB_EV_PREPARE:
  1546. + case NB_EV_ABORT:
  1547. + return NB_OK;
  1548. + case NB_EV_APPLY:
  1549. + break;
  1550. + }
  1551. +
  1552. + /* Check for hook function. */
  1553. + if (rmap_match_set_hook.set_ipv6_nexthop_local == NULL)
  1554. + return NB_OK;
  1555. +
  1556. + /* Add configuration. */
  1557. + rhc = nb_running_get_entry(dnode, NULL, true);
  1558. + address = yang_dnode_get_string(dnode, NULL);
  1559. +
  1560. + /* Set destroy information. */
  1561. + rhc->rhc_shook = rmap_match_set_hook.no_set_ipv6_nexthop_local;
  1562. + rhc->rhc_rule = "ipv6 next-hop local";
  1563. +
  1564. + rv = rmap_match_set_hook.set_ipv6_nexthop_local(
  1565. + NULL, rhc->rhc_rmi, "ipv6 next-hop local", address);
  1566. + if (rv != CMD_SUCCESS) {
  1567. + rhc->rhc_shook = NULL;
  1568. + return NB_ERR_INCONSISTENCY;
  1569. + }
  1570. +
  1571. + return NB_OK;
  1572. +}
  1573. +
  1574. +static int lib_route_map_entry_set_action_ipv6_address_destroy(
  1575. + enum nb_event event, const struct lyd_node *dnode)
  1576. +{
  1577. + return lib_route_map_entry_set_destroy(event, dnode);
  1578. +}
  1579. +
  1580. +/*
  1581. + * XPath: /frr-route-map:lib/route-map/entry/set-action/value
  1582. + */
  1583. +static int set_action_modify(enum nb_event event, const struct lyd_node *dnode,
  1584. + union nb_resource *resource, const char *value)
  1585. +{
  1586. + struct routemap_hook_context *rhc;
  1587. + int rv;
  1588. +
  1589. + /*
  1590. + * NOTE: validate if 'action' is 'metric', currently it is not
  1591. + * necessary because this is the only implemented action. Other
  1592. + * actions might have different validations.
  1593. + */
  1594. + if (event != NB_EV_APPLY)
  1595. + return NB_OK;
  1596. +
  1597. + /* Check for hook function. */
  1598. + if (rmap_match_set_hook.set_metric == NULL)
  1599. + return NB_OK;
  1600. +
  1601. + /* Add configuration. */
  1602. + rhc = nb_running_get_entry(dnode, NULL, true);
  1603. +
  1604. + /* Set destroy information. */
  1605. + rhc->rhc_shook = rmap_match_set_hook.no_set_metric;
  1606. + rhc->rhc_rule = "metric";
  1607. +
  1608. + rv = rmap_match_set_hook.set_metric(NULL, rhc->rhc_rmi, "metric",
  1609. + value);
  1610. + if (rv != CMD_SUCCESS) {
  1611. + rhc->rhc_shook = NULL;
  1612. + return NB_ERR_INCONSISTENCY;
  1613. + }
  1614. +
  1615. + return NB_OK;
  1616. +}
  1617. +
  1618. +static int
  1619. +lib_route_map_entry_set_action_value_modify(enum nb_event event,
  1620. + const struct lyd_node *dnode,
  1621. + union nb_resource *resource)
  1622. +{
  1623. + const char *metric = yang_dnode_get_string(dnode, NULL);
  1624. +
  1625. + return set_action_modify(event, dnode, resource, metric);
  1626. +}
  1627. +
  1628. +static int
  1629. +lib_route_map_entry_set_action_value_destroy(enum nb_event event,
  1630. + const struct lyd_node *dnode)
  1631. +{
  1632. + return lib_route_map_entry_set_destroy(event, dnode);
  1633. +}
  1634. +
  1635. +/*
  1636. + * XPath: /frr-route-map:lib/route-map/entry/set-action/add-metric
  1637. + */
  1638. +static int
  1639. +lib_route_map_entry_set_action_add_metric_modify(enum nb_event event,
  1640. + const struct lyd_node *dnode,
  1641. + union nb_resource *resource)
  1642. +{
  1643. + return set_action_modify(event, dnode, resource, "+metric");
  1644. +}
  1645. +
  1646. +static int
  1647. +lib_route_map_entry_set_action_add_metric_destroy(enum nb_event event,
  1648. + const struct lyd_node *dnode)
  1649. +{
  1650. + return lib_route_map_entry_set_action_value_destroy(event, dnode);
  1651. +}
  1652. +
  1653. +/*
  1654. + * XPath: /frr-route-map:lib/route-map/entry/set-action/subtract-metric
  1655. + */
  1656. +static int lib_route_map_entry_set_action_subtract_metric_modify(
  1657. + enum nb_event event, const struct lyd_node *dnode,
  1658. + union nb_resource *resource)
  1659. +{
  1660. + return set_action_modify(event, dnode, resource, "-metric");
  1661. +}
  1662. +
  1663. +static int lib_route_map_entry_set_action_subtract_metric_destroy(
  1664. + enum nb_event event, const struct lyd_node *dnode)
  1665. +{
  1666. + return lib_route_map_entry_set_action_value_destroy(event, dnode);
  1667. +}
  1668. +
  1669. +/*
  1670. + * XPath: /frr-route-map:lib/route-map/entry/set-action/use-round-trip-time
  1671. + */
  1672. +static int lib_route_map_entry_set_action_use_round_trip_time_modify(
  1673. + enum nb_event event, const struct lyd_node *dnode,
  1674. + union nb_resource *resource)
  1675. +{
  1676. + return set_action_modify(event, dnode, resource, "rtt");
  1677. +}
  1678. +
  1679. +static int lib_route_map_entry_set_action_use_round_trip_time_destroy(
  1680. + enum nb_event event, const struct lyd_node *dnode)
  1681. +{
  1682. + return lib_route_map_entry_set_action_value_destroy(event, dnode);
  1683. +}
  1684. +
  1685. +/*
  1686. + * XPath: /frr-route-map:lib/route-map/entry/set-action/add-round-trip-time
  1687. + */
  1688. +static int lib_route_map_entry_set_action_add_round_trip_time_modify(
  1689. + enum nb_event event, const struct lyd_node *dnode,
  1690. + union nb_resource *resource)
  1691. +{
  1692. + return set_action_modify(event, dnode, resource, "+rtt");
  1693. +}
  1694. +
  1695. +static int lib_route_map_entry_set_action_add_round_trip_time_destroy(
  1696. + enum nb_event event, const struct lyd_node *dnode)
  1697. +{
  1698. + return lib_route_map_entry_set_action_value_destroy(event, dnode);
  1699. +}
  1700. +
  1701. +/*
  1702. + * XPath: /frr-route-map:lib/route-map/entry/set-action/subtract-round-trip-time
  1703. + */
  1704. +static int lib_route_map_entry_set_action_subtract_round_trip_time_modify(
  1705. + enum nb_event event, const struct lyd_node *dnode,
  1706. + union nb_resource *resource)
  1707. +{
  1708. + return set_action_modify(event, dnode, resource, "-rtt");
  1709. +}
  1710. +
  1711. +static int lib_route_map_entry_set_action_subtract_round_trip_time_destroy(
  1712. + enum nb_event event, const struct lyd_node *dnode)
  1713. +{
  1714. + return lib_route_map_entry_set_action_value_destroy(event, dnode);
  1715. +}
  1716. +
  1717. +/*
  1718. + * XPath: /frr-route-map:lib/route-map/entry/set-action/tag
  1719. + */
  1720. +static int
  1721. +lib_route_map_entry_set_action_tag_modify(enum nb_event event,
  1722. + const struct lyd_node *dnode,
  1723. + union nb_resource *resource)
  1724. +{
  1725. + struct routemap_hook_context *rhc;
  1726. + const char *tag;
  1727. + int rv;
  1728. +
  1729. + /*
  1730. + * NOTE: validate if 'action' is 'tag', currently it is not
  1731. + * necessary because this is the only implemented action. Other
  1732. + * actions might have different validations.
  1733. + */
  1734. + if (event != NB_EV_APPLY)
  1735. + return NB_OK;
  1736. +
  1737. + /* Check for hook function. */
  1738. + if (rmap_match_set_hook.set_tag == NULL)
  1739. + return NB_OK;
  1740. +
  1741. + /* Add configuration. */
  1742. + rhc = nb_running_get_entry(dnode, NULL, true);
  1743. + tag = yang_dnode_get_string(dnode, NULL);
  1744. +
  1745. + /* Set destroy information. */
  1746. + rhc->rhc_shook = rmap_match_set_hook.no_set_tag;
  1747. + rhc->rhc_rule = "tag";
  1748. +
  1749. + rv = rmap_match_set_hook.set_tag(NULL, rhc->rhc_rmi, "tag", tag);
  1750. + if (rv != CMD_SUCCESS) {
  1751. + rhc->rhc_shook = NULL;
  1752. + return NB_ERR_INCONSISTENCY;
  1753. + }
  1754. +
  1755. + return NB_OK;
  1756. +}
  1757. +
  1758. +static int
  1759. +lib_route_map_entry_set_action_tag_destroy(enum nb_event event,
  1760. + const struct lyd_node *dnode)
  1761. +{
  1762. + return lib_route_map_entry_set_destroy(event, dnode);
  1763. +}
  1764. +
  1765. +/* clang-format off */
  1766. +const struct frr_yang_module_info frr_route_map_info = {
  1767. + .name = "frr-route-map",
  1768. + .nodes = {
  1769. + {
  1770. + .xpath = "/frr-route-map:lib/route-map",
  1771. + .cbs = {
  1772. + .create = lib_route_map_create,
  1773. + .destroy = lib_route_map_destroy,
  1774. + }
  1775. + },
  1776. + {
  1777. + .xpath = "/frr-route-map:lib/route-map/entry",
  1778. + .cbs = {
  1779. + .create = lib_route_map_entry_create,
  1780. + .destroy = lib_route_map_entry_destroy,
  1781. + }
  1782. + },
  1783. + {
  1784. + .xpath = "/frr-route-map:lib/route-map/entry/description",
  1785. + .cbs = {
  1786. + .modify = lib_route_map_entry_description_modify,
  1787. + .destroy = lib_route_map_entry_description_destroy,
  1788. + }
  1789. + },
  1790. + {
  1791. + .xpath = "/frr-route-map:lib/route-map/entry/action",
  1792. + .cbs = {
  1793. + .modify = lib_route_map_entry_action_modify,
  1794. + }
  1795. + },
  1796. + {
  1797. + .xpath = "/frr-route-map:lib/route-map/entry/call",
  1798. + .cbs = {
  1799. + .modify = lib_route_map_entry_call_modify,
  1800. + .destroy = lib_route_map_entry_call_destroy,
  1801. + }
  1802. + },
  1803. + {
  1804. + .xpath = "/frr-route-map:lib/route-map/entry/exit-policy",
  1805. + .cbs = {
  1806. + .modify = lib_route_map_entry_exit_policy_modify,
  1807. + }
  1808. + },
  1809. + {
  1810. + .xpath = "/frr-route-map:lib/route-map/entry/goto-value",
  1811. + .cbs = {
  1812. + .modify = lib_route_map_entry_goto_value_modify,
  1813. + .destroy = lib_route_map_entry_goto_value_destroy,
  1814. + }
  1815. + },
  1816. + {
  1817. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition",
  1818. + .cbs = {
  1819. + .create = lib_route_map_entry_match_condition_create,
  1820. + .destroy = lib_route_map_entry_match_condition_destroy,
  1821. + }
  1822. + },
  1823. + {
  1824. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/interface",
  1825. + .cbs = {
  1826. + .modify = lib_route_map_entry_match_condition_interface_modify,
  1827. + .destroy = lib_route_map_entry_match_condition_interface_destroy,
  1828. + }
  1829. + },
  1830. + {
  1831. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num",
  1832. + .cbs = {
  1833. + .modify = lib_route_map_entry_match_condition_access_list_num_modify,
  1834. + .destroy = lib_route_map_entry_match_condition_access_list_num_destroy,
  1835. + }
  1836. + },
  1837. + {
  1838. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num-extended",
  1839. + .cbs = {
  1840. + .modify = lib_route_map_entry_match_condition_access_list_num_extended_modify,
  1841. + .destroy = lib_route_map_entry_match_condition_access_list_num_extended_destroy,
  1842. + }
  1843. + },
  1844. + {
  1845. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/list-name",
  1846. + .cbs = {
  1847. + .modify = lib_route_map_entry_match_condition_list_name_modify,
  1848. + .destroy = lib_route_map_entry_match_condition_list_name_destroy,
  1849. + }
  1850. + },
  1851. + {
  1852. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/ipv4-next-hop-type",
  1853. + .cbs = {
  1854. + .modify = lib_route_map_entry_match_condition_ipv4_next_hop_type_modify,
  1855. + .destroy = lib_route_map_entry_match_condition_ipv4_next_hop_type_destroy,
  1856. + }
  1857. + },
  1858. + {
  1859. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/ipv6-next-hop-type",
  1860. + .cbs = {
  1861. + .modify = lib_route_map_entry_match_condition_ipv6_next_hop_type_modify,
  1862. + .destroy = lib_route_map_entry_match_condition_ipv6_next_hop_type_destroy,
  1863. + }
  1864. + },
  1865. + {
  1866. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/metric",
  1867. + .cbs = {
  1868. + .modify = lib_route_map_entry_match_condition_metric_modify,
  1869. + .destroy = lib_route_map_entry_match_condition_metric_destroy,
  1870. + }
  1871. + },
  1872. + {
  1873. + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/tag",
  1874. + .cbs = {
  1875. + .modify = lib_route_map_entry_match_condition_tag_modify,
  1876. + .destroy = lib_route_map_entry_match_condition_tag_destroy,
  1877. + }
  1878. + },
  1879. + {
  1880. + .xpath = "/frr-route-map:lib/route-map/entry/set-action",
  1881. + .cbs = {
  1882. + .create = lib_route_map_entry_set_action_create,
  1883. + .destroy = lib_route_map_entry_set_action_destroy,
  1884. + }
  1885. + },
  1886. + {
  1887. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/ipv4-address",
  1888. + .cbs = {
  1889. + .modify = lib_route_map_entry_set_action_ipv4_address_modify,
  1890. + .destroy = lib_route_map_entry_set_action_ipv4_address_destroy,
  1891. + }
  1892. + },
  1893. + {
  1894. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/ipv6-address",
  1895. + .cbs = {
  1896. + .modify = lib_route_map_entry_set_action_ipv6_address_modify,
  1897. + .destroy = lib_route_map_entry_set_action_ipv6_address_destroy,
  1898. + }
  1899. + },
  1900. + {
  1901. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/value",
  1902. + .cbs = {
  1903. + .modify = lib_route_map_entry_set_action_value_modify,
  1904. + .destroy = lib_route_map_entry_set_action_value_destroy,
  1905. + }
  1906. + },
  1907. + {
  1908. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/add-metric",
  1909. + .cbs = {
  1910. + .modify = lib_route_map_entry_set_action_add_metric_modify,
  1911. + .destroy = lib_route_map_entry_set_action_add_metric_destroy,
  1912. + }
  1913. + },
  1914. + {
  1915. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/subtract-metric",
  1916. + .cbs = {
  1917. + .modify = lib_route_map_entry_set_action_subtract_metric_modify,
  1918. + .destroy = lib_route_map_entry_set_action_subtract_metric_destroy,
  1919. + }
  1920. + },
  1921. + {
  1922. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/use-round-trip-time",
  1923. + .cbs = {
  1924. + .modify = lib_route_map_entry_set_action_use_round_trip_time_modify,
  1925. + .destroy = lib_route_map_entry_set_action_use_round_trip_time_destroy,
  1926. + }
  1927. + },
  1928. + {
  1929. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/add-round-trip-time",
  1930. + .cbs = {
  1931. + .modify = lib_route_map_entry_set_action_add_round_trip_time_modify,
  1932. + .destroy = lib_route_map_entry_set_action_add_round_trip_time_destroy,
  1933. + }
  1934. + },
  1935. + {
  1936. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/subtract-round-trip-time",
  1937. + .cbs = {
  1938. + .modify = lib_route_map_entry_set_action_subtract_round_trip_time_modify,
  1939. + .destroy = lib_route_map_entry_set_action_subtract_round_trip_time_destroy,
  1940. + }
  1941. + },
  1942. + {
  1943. + .xpath = "/frr-route-map:lib/route-map/entry/set-action/tag",
  1944. + .cbs = {
  1945. + .modify = lib_route_map_entry_set_action_tag_modify,
  1946. + .destroy = lib_route_map_entry_set_action_tag_destroy,
  1947. + }
  1948. + },
  1949. + {
  1950. + .xpath = NULL,
  1951. + },
  1952. + }
  1953. +};
  1954. diff --git a/lib/subdir.am b/lib/subdir.am
  1955. index d804d839db..94b3d933ac 100644
  1956. --- a/lib/subdir.am
  1957. +++ b/lib/subdir.am
  1958. @@ -71,6 +71,7 @@ lib_libfrr_la_SOURCES = \
  1959. lib/qobj.c \
  1960. lib/ringbuf.c \
  1961. lib/routemap.c \
  1962. + lib/routemap_northbound.c \
  1963. lib/sbuf.c \
  1964. lib/seqlock.c \
  1965. lib/sha256.c \
  1966. @@ -105,6 +106,7 @@ lib_libfrr_la_SOURCES = \
  1967. nodist_lib_libfrr_la_SOURCES = \
  1968. yang/frr-interface.yang.c \
  1969. + yang/frr-route-map.yang.c \
  1970. yang/frr-route-types.yang.c \
  1971. yang/ietf/ietf-routing-types.yang.c \
  1972. yang/frr-module-translator.yang.c \
  1973. diff --git a/yang/subdir.am b/yang/subdir.am
  1974. index cfaf1a6401..7a15a6a309 100644
  1975. --- a/yang/subdir.am
  1976. +++ b/yang/subdir.am
  1977. @@ -22,6 +22,7 @@ EXTRA_DIST += yang/embedmodel.py
  1978. dist_yangmodels_DATA += yang/frr-module-translator.yang
  1979. dist_yangmodels_DATA += yang/frr-test-module.yang
  1980. dist_yangmodels_DATA += yang/frr-interface.yang
  1981. +dist_yangmodels_DATA += yang/frr-route-map.yang
  1982. dist_yangmodels_DATA += yang/frr-route-types.yang
  1983. dist_yangmodels_DATA += yang/ietf/ietf-routing-types.yang
  1984. From 2b3e4807ecf4d2586fe4d651b904967ea8d759c0 Mon Sep 17 00:00:00 2001
  1985. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  1986. Date: Mon, 30 Sep 2019 15:01:46 -0300
  1987. Subject: [PATCH 04/10] lib: implement new route map CLI
  1988. Use the northbound back-end instead of the old route map CLI.
  1989. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  1990. ---
  1991. lib/routemap.c | 1103 +------------------------------------
  1992. lib/routemap.h | 19 +
  1993. lib/routemap_cli.c | 1075 ++++++++++++++++++++++++++++++++++++
  1994. lib/routemap_northbound.c | 7 +
  1995. lib/subdir.am | 4 +
  1996. vtysh/extract.pl.in | 2 +-
  1997. 6 files changed, 1108 insertions(+), 1102 deletions(-)
  1998. create mode 100644 lib/routemap_cli.c
  1999. diff --git a/lib/routemap.c b/lib/routemap.c
  2000. index a8feebd313..e07ad08123 100644
  2001. --- a/lib/routemap.c
  2002. +++ b/lib/routemap.c
  2003. @@ -759,14 +759,6 @@ static const char *route_map_result_str(route_map_result_t res)
  2004. return "invalid";
  2005. }
  2006. -static int route_map_empty(struct route_map *map)
  2007. -{
  2008. - if (map->head == NULL && map->tail == NULL)
  2009. - return 1;
  2010. - else
  2011. - return 0;
  2012. -}
  2013. -
  2014. /* show route-map */
  2015. static void vty_show_route_map_entry(struct vty *vty, struct route_map *map)
  2016. {
  2017. @@ -2010,871 +2002,6 @@ void route_map_notify_dependencies(const char *affected_name,
  2018. /* VTY related functions. */
  2019. -DEFUN (match_interface,
  2020. - match_interface_cmd,
  2021. - "match interface WORD",
  2022. - MATCH_STR
  2023. - "match first hop interface of route\n"
  2024. - "Interface name\n")
  2025. -{
  2026. - int idx_word = 2;
  2027. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2028. -
  2029. - if (rmap_match_set_hook.match_interface)
  2030. - return rmap_match_set_hook.match_interface(
  2031. - vty, index, "interface", argv[idx_word]->arg,
  2032. - RMAP_EVENT_MATCH_ADDED);
  2033. - return CMD_SUCCESS;
  2034. -}
  2035. -
  2036. -DEFUN (no_match_interface,
  2037. - no_match_interface_cmd,
  2038. - "no match interface [WORD]",
  2039. - NO_STR
  2040. - MATCH_STR
  2041. - "Match first hop interface of route\n"
  2042. - "Interface name\n")
  2043. -{
  2044. - char *iface = (argc == 4) ? argv[3]->arg : NULL;
  2045. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2046. -
  2047. - if (rmap_match_set_hook.no_match_interface)
  2048. - return rmap_match_set_hook.no_match_interface(
  2049. - vty, index, "interface", iface,
  2050. - RMAP_EVENT_MATCH_DELETED);
  2051. - return CMD_SUCCESS;
  2052. -}
  2053. -
  2054. -
  2055. -DEFUN (match_ip_address,
  2056. - match_ip_address_cmd,
  2057. - "match ip address <(1-199)|(1300-2699)|WORD>",
  2058. - MATCH_STR
  2059. - IP_STR
  2060. - "Match address of route\n"
  2061. - "IP access-list number\n"
  2062. - "IP access-list number (expanded range)\n"
  2063. - "IP Access-list name\n")
  2064. -{
  2065. - int idx_acl = 3;
  2066. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2067. -
  2068. - if (rmap_match_set_hook.match_ip_address)
  2069. - return rmap_match_set_hook.match_ip_address(
  2070. - vty, index, "ip address", argv[idx_acl]->arg,
  2071. - RMAP_EVENT_FILTER_ADDED);
  2072. - return CMD_SUCCESS;
  2073. -}
  2074. -
  2075. -
  2076. -DEFUN (no_match_ip_address,
  2077. - no_match_ip_address_cmd,
  2078. - "no match ip address [<(1-199)|(1300-2699)|WORD>]",
  2079. - NO_STR
  2080. - MATCH_STR
  2081. - IP_STR
  2082. - "Match address of route\n"
  2083. - "IP access-list number\n"
  2084. - "IP access-list number (expanded range)\n"
  2085. - "IP Access-list name\n")
  2086. -{
  2087. - int idx_word = 4;
  2088. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2089. -
  2090. - if (rmap_match_set_hook.no_match_ip_address) {
  2091. - if (argc <= idx_word)
  2092. - return rmap_match_set_hook.no_match_ip_address(
  2093. - vty, index, "ip address", NULL,
  2094. - RMAP_EVENT_FILTER_DELETED);
  2095. - return rmap_match_set_hook.no_match_ip_address(
  2096. - vty, index, "ip address", argv[idx_word]->arg,
  2097. - RMAP_EVENT_FILTER_DELETED);
  2098. - }
  2099. - return CMD_SUCCESS;
  2100. -}
  2101. -
  2102. -
  2103. -DEFUN (match_ip_address_prefix_list,
  2104. - match_ip_address_prefix_list_cmd,
  2105. - "match ip address prefix-list WORD",
  2106. - MATCH_STR
  2107. - IP_STR
  2108. - "Match address of route\n"
  2109. - "Match entries of prefix-lists\n"
  2110. - "IP prefix-list name\n")
  2111. -{
  2112. - int idx_word = 4;
  2113. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2114. -
  2115. - if (rmap_match_set_hook.match_ip_address_prefix_list)
  2116. - return rmap_match_set_hook.match_ip_address_prefix_list(
  2117. - vty, index, "ip address prefix-list",
  2118. - argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
  2119. - return CMD_SUCCESS;
  2120. -}
  2121. -
  2122. -
  2123. -DEFUN (no_match_ip_address_prefix_list,
  2124. - no_match_ip_address_prefix_list_cmd,
  2125. - "no match ip address prefix-list [WORD]",
  2126. - NO_STR
  2127. - MATCH_STR
  2128. - IP_STR
  2129. - "Match address of route\n"
  2130. - "Match entries of prefix-lists\n"
  2131. - "IP prefix-list name\n")
  2132. -{
  2133. - int idx_word = 5;
  2134. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2135. -
  2136. - if (rmap_match_set_hook.no_match_ip_address_prefix_list) {
  2137. - if (argc <= idx_word)
  2138. - return rmap_match_set_hook
  2139. - .no_match_ip_address_prefix_list(
  2140. - vty, index, "ip address prefix-list",
  2141. - NULL, RMAP_EVENT_PLIST_DELETED);
  2142. - return rmap_match_set_hook.no_match_ip_address_prefix_list(
  2143. - vty, index, "ip address prefix-list",
  2144. - argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
  2145. - }
  2146. - return CMD_SUCCESS;
  2147. -}
  2148. -
  2149. -
  2150. -DEFUN (match_ip_next_hop,
  2151. - match_ip_next_hop_cmd,
  2152. - "match ip next-hop <(1-199)|(1300-2699)|WORD>",
  2153. - MATCH_STR
  2154. - IP_STR
  2155. - "Match next-hop address of route\n"
  2156. - "IP access-list number\n"
  2157. - "IP access-list number (expanded range)\n"
  2158. - "IP Access-list name\n")
  2159. -{
  2160. - int idx_acl = 3;
  2161. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2162. -
  2163. - if (rmap_match_set_hook.match_ip_next_hop)
  2164. - return rmap_match_set_hook.match_ip_next_hop(
  2165. - vty, index, "ip next-hop", argv[idx_acl]->arg,
  2166. - RMAP_EVENT_FILTER_ADDED);
  2167. - return CMD_SUCCESS;
  2168. -}
  2169. -
  2170. -
  2171. -DEFUN (no_match_ip_next_hop,
  2172. - no_match_ip_next_hop_cmd,
  2173. - "no match ip next-hop [<(1-199)|(1300-2699)|WORD>]",
  2174. - NO_STR
  2175. - MATCH_STR
  2176. - IP_STR
  2177. - "Match next-hop address of route\n"
  2178. - "IP access-list number\n"
  2179. - "IP access-list number (expanded range)\n"
  2180. - "IP Access-list name\n")
  2181. -{
  2182. - int idx_word = 4;
  2183. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2184. -
  2185. - if (rmap_match_set_hook.no_match_ip_next_hop) {
  2186. - if (argc <= idx_word)
  2187. - return rmap_match_set_hook.no_match_ip_next_hop(
  2188. - vty, index, "ip next-hop", NULL,
  2189. - RMAP_EVENT_FILTER_DELETED);
  2190. - return rmap_match_set_hook.no_match_ip_next_hop(
  2191. - vty, index, "ip next-hop", argv[idx_word]->arg,
  2192. - RMAP_EVENT_FILTER_DELETED);
  2193. - }
  2194. - return CMD_SUCCESS;
  2195. -}
  2196. -
  2197. -
  2198. -DEFUN (match_ip_next_hop_prefix_list,
  2199. - match_ip_next_hop_prefix_list_cmd,
  2200. - "match ip next-hop prefix-list WORD",
  2201. - MATCH_STR
  2202. - IP_STR
  2203. - "Match next-hop address of route\n"
  2204. - "Match entries of prefix-lists\n"
  2205. - "IP prefix-list name\n")
  2206. -{
  2207. - int idx_word = 4;
  2208. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2209. -
  2210. - if (rmap_match_set_hook.match_ip_next_hop_prefix_list)
  2211. - return rmap_match_set_hook.match_ip_next_hop_prefix_list(
  2212. - vty, index, "ip next-hop prefix-list",
  2213. - argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
  2214. - return CMD_SUCCESS;
  2215. -}
  2216. -
  2217. -DEFUN (no_match_ip_next_hop_prefix_list,
  2218. - no_match_ip_next_hop_prefix_list_cmd,
  2219. - "no match ip next-hop prefix-list [WORD]",
  2220. - NO_STR
  2221. - MATCH_STR
  2222. - IP_STR
  2223. - "Match next-hop address of route\n"
  2224. - "Match entries of prefix-lists\n"
  2225. - "IP prefix-list name\n")
  2226. -{
  2227. - int idx_word = 5;
  2228. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2229. -
  2230. - if (rmap_match_set_hook.no_match_ip_next_hop) {
  2231. - if (argc <= idx_word)
  2232. - return rmap_match_set_hook.no_match_ip_next_hop(
  2233. - vty, index, "ip next-hop prefix-list", NULL,
  2234. - RMAP_EVENT_PLIST_DELETED);
  2235. - return rmap_match_set_hook.no_match_ip_next_hop(
  2236. - vty, index, "ip next-hop prefix-list",
  2237. - argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
  2238. - }
  2239. - return CMD_SUCCESS;
  2240. -}
  2241. -
  2242. -DEFUN(match_ip_next_hop_type, match_ip_next_hop_type_cmd,
  2243. - "match ip next-hop type <blackhole>",
  2244. - MATCH_STR IP_STR
  2245. - "Match next-hop address of route\n"
  2246. - "Match entries by type\n"
  2247. - "Blackhole\n")
  2248. -{
  2249. - int idx_word = 4;
  2250. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2251. -
  2252. - if (rmap_match_set_hook.match_ip_next_hop_type)
  2253. - return rmap_match_set_hook.match_ip_next_hop_type(
  2254. - vty, index, "ip next-hop type", argv[idx_word]->arg,
  2255. - RMAP_EVENT_MATCH_ADDED);
  2256. - return CMD_SUCCESS;
  2257. -}
  2258. -
  2259. -DEFUN(no_match_ip_next_hop_type, no_match_ip_next_hop_type_cmd,
  2260. - "no match ip next-hop type [<blackhole>]",
  2261. - NO_STR MATCH_STR IP_STR
  2262. - "Match next-hop address of route\n"
  2263. - "Match entries by type\n"
  2264. - "Blackhole\n")
  2265. -{
  2266. - int idx_word = 5;
  2267. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2268. -
  2269. - if (rmap_match_set_hook.no_match_ip_next_hop) {
  2270. - if (argc <= idx_word)
  2271. - return rmap_match_set_hook.no_match_ip_next_hop(
  2272. - vty, index, "ip next-hop type", NULL,
  2273. - RMAP_EVENT_MATCH_DELETED);
  2274. - return rmap_match_set_hook.no_match_ip_next_hop(
  2275. - vty, index, "ip next-hop type", argv[idx_word]->arg,
  2276. - RMAP_EVENT_MATCH_DELETED);
  2277. - }
  2278. - return CMD_SUCCESS;
  2279. -}
  2280. -
  2281. -
  2282. -DEFUN (match_ipv6_address,
  2283. - match_ipv6_address_cmd,
  2284. - "match ipv6 address WORD",
  2285. - MATCH_STR
  2286. - IPV6_STR
  2287. - "Match IPv6 address of route\n"
  2288. - "IPv6 access-list name\n")
  2289. -{
  2290. - int idx_word = 3;
  2291. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2292. -
  2293. - if (rmap_match_set_hook.match_ipv6_address)
  2294. - return rmap_match_set_hook.match_ipv6_address(
  2295. - vty, index, "ipv6 address", argv[idx_word]->arg,
  2296. - RMAP_EVENT_FILTER_ADDED);
  2297. - return CMD_SUCCESS;
  2298. -}
  2299. -
  2300. -DEFUN (no_match_ipv6_address,
  2301. - no_match_ipv6_address_cmd,
  2302. - "no match ipv6 address WORD",
  2303. - NO_STR
  2304. - MATCH_STR
  2305. - IPV6_STR
  2306. - "Match IPv6 address of route\n"
  2307. - "IPv6 access-list name\n")
  2308. -{
  2309. - int idx_word = 4;
  2310. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2311. -
  2312. - if (rmap_match_set_hook.no_match_ipv6_address)
  2313. - return rmap_match_set_hook.no_match_ipv6_address(
  2314. - vty, index, "ipv6 address", argv[idx_word]->arg,
  2315. - RMAP_EVENT_FILTER_DELETED);
  2316. - return CMD_SUCCESS;
  2317. -}
  2318. -
  2319. -
  2320. -DEFUN (match_ipv6_address_prefix_list,
  2321. - match_ipv6_address_prefix_list_cmd,
  2322. - "match ipv6 address prefix-list WORD",
  2323. - MATCH_STR
  2324. - IPV6_STR
  2325. - "Match address of route\n"
  2326. - "Match entries of prefix-lists\n"
  2327. - "IP prefix-list name\n")
  2328. -{
  2329. - int idx_word = 4;
  2330. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2331. -
  2332. - if (rmap_match_set_hook.match_ipv6_address_prefix_list)
  2333. - return rmap_match_set_hook.match_ipv6_address_prefix_list(
  2334. - vty, index, "ipv6 address prefix-list",
  2335. - argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
  2336. - return CMD_SUCCESS;
  2337. -}
  2338. -
  2339. -DEFUN (no_match_ipv6_address_prefix_list,
  2340. - no_match_ipv6_address_prefix_list_cmd,
  2341. - "no match ipv6 address prefix-list WORD",
  2342. - NO_STR
  2343. - MATCH_STR
  2344. - IPV6_STR
  2345. - "Match address of route\n"
  2346. - "Match entries of prefix-lists\n"
  2347. - "IP prefix-list name\n")
  2348. -{
  2349. - int idx_word = 5;
  2350. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2351. -
  2352. - if (rmap_match_set_hook.no_match_ipv6_address_prefix_list)
  2353. - return rmap_match_set_hook.no_match_ipv6_address_prefix_list(
  2354. - vty, index, "ipv6 address prefix-list",
  2355. - argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
  2356. - return CMD_SUCCESS;
  2357. -}
  2358. -
  2359. -DEFUN(match_ipv6_next_hop_type, match_ipv6_next_hop_type_cmd,
  2360. - "match ipv6 next-hop type <blackhole>",
  2361. - MATCH_STR IPV6_STR
  2362. - "Match next-hop address of route\n"
  2363. - "Match entries by type\n"
  2364. - "Blackhole\n")
  2365. -{
  2366. - int idx_word = 4;
  2367. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2368. -
  2369. - if (rmap_match_set_hook.match_ipv6_next_hop_type)
  2370. - return rmap_match_set_hook.match_ipv6_next_hop_type(
  2371. - vty, index, "ipv6 next-hop type", argv[idx_word]->arg,
  2372. - RMAP_EVENT_MATCH_ADDED);
  2373. - return CMD_SUCCESS;
  2374. -}
  2375. -
  2376. -DEFUN(no_match_ipv6_next_hop_type, no_match_ipv6_next_hop_type_cmd,
  2377. - "no match ipv6 next-hop type [<blackhole>]",
  2378. - NO_STR MATCH_STR IPV6_STR
  2379. - "Match address of route\n"
  2380. - "Match entries by type\n"
  2381. - "Blackhole\n")
  2382. -{
  2383. - int idx_word = 5;
  2384. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2385. -
  2386. - if (rmap_match_set_hook.no_match_ipv6_next_hop_type)
  2387. - return rmap_match_set_hook.no_match_ipv6_next_hop_type(
  2388. - vty, index, "ipv6 next-hop type",
  2389. - (argc <= idx_word) ? NULL : argv[idx_word]->arg,
  2390. - RMAP_EVENT_MATCH_DELETED);
  2391. - return CMD_SUCCESS;
  2392. -}
  2393. -
  2394. -DEFUN (match_metric,
  2395. - match_metric_cmd,
  2396. - "match metric (0-4294967295)",
  2397. - MATCH_STR
  2398. - "Match metric of route\n"
  2399. - "Metric value\n")
  2400. -{
  2401. - int idx_number = 2;
  2402. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2403. -
  2404. - if (rmap_match_set_hook.match_metric)
  2405. - return rmap_match_set_hook.match_metric(vty, index, "metric",
  2406. - argv[idx_number]->arg,
  2407. - RMAP_EVENT_MATCH_ADDED);
  2408. - return CMD_SUCCESS;
  2409. -}
  2410. -
  2411. -
  2412. -DEFUN (no_match_metric,
  2413. - no_match_metric_cmd,
  2414. - "no match metric [(0-4294967295)]",
  2415. - NO_STR
  2416. - MATCH_STR
  2417. - "Match metric of route\n"
  2418. - "Metric value\n")
  2419. -{
  2420. - int idx_number = 3;
  2421. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2422. -
  2423. - if (rmap_match_set_hook.no_match_metric) {
  2424. - if (argc <= idx_number)
  2425. - return rmap_match_set_hook.no_match_metric(
  2426. - vty, index, "metric", NULL,
  2427. - RMAP_EVENT_MATCH_DELETED);
  2428. - return rmap_match_set_hook.no_match_metric(
  2429. - vty, index, "metric", argv[idx_number]->arg,
  2430. - RMAP_EVENT_MATCH_DELETED);
  2431. - }
  2432. - return CMD_SUCCESS;
  2433. -}
  2434. -
  2435. -
  2436. -DEFUN (match_tag,
  2437. - match_tag_cmd,
  2438. - "match tag (1-4294967295)",
  2439. - MATCH_STR
  2440. - "Match tag of route\n"
  2441. - "Tag value\n")
  2442. -{
  2443. - int idx_number = 2;
  2444. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2445. -
  2446. - if (rmap_match_set_hook.match_tag)
  2447. - return rmap_match_set_hook.match_tag(vty, index, "tag",
  2448. - argv[idx_number]->arg,
  2449. - RMAP_EVENT_MATCH_ADDED);
  2450. - return CMD_SUCCESS;
  2451. -}
  2452. -
  2453. -
  2454. -DEFUN (no_match_tag,
  2455. - no_match_tag_cmd,
  2456. - "no match tag [(1-4294967295)]",
  2457. - NO_STR
  2458. - MATCH_STR
  2459. - "Match tag of route\n"
  2460. - "Tag value\n")
  2461. -{
  2462. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2463. -
  2464. - int idx = 0;
  2465. - char *arg = argv_find(argv, argc, "(1-4294967295)", &idx)
  2466. - ? argv[idx]->arg
  2467. - : NULL;
  2468. -
  2469. - if (rmap_match_set_hook.no_match_tag)
  2470. - return rmap_match_set_hook.no_match_tag(
  2471. - vty, index, "tag", arg, RMAP_EVENT_MATCH_DELETED);
  2472. - return CMD_SUCCESS;
  2473. -}
  2474. -
  2475. -
  2476. -DEFUN (set_ip_nexthop,
  2477. - set_ip_nexthop_cmd,
  2478. - "set ip next-hop A.B.C.D",
  2479. - SET_STR
  2480. - IP_STR
  2481. - "Next hop address\n"
  2482. - "IP address of next hop\n")
  2483. -{
  2484. - int idx_ipv4 = 3;
  2485. - union sockunion su;
  2486. - int ret;
  2487. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2488. -
  2489. - ret = str2sockunion(argv[idx_ipv4]->arg, &su);
  2490. - if (ret < 0) {
  2491. - vty_out(vty, "%% Malformed nexthop address\n");
  2492. - return CMD_WARNING_CONFIG_FAILED;
  2493. - }
  2494. - if (su.sin.sin_addr.s_addr == 0
  2495. - || IPV4_CLASS_DE(ntohl(su.sin.sin_addr.s_addr))) {
  2496. - vty_out(vty,
  2497. - "%% nexthop address cannot be 0.0.0.0, multicast or reserved\n");
  2498. - return CMD_WARNING_CONFIG_FAILED;
  2499. - }
  2500. -
  2501. - if (rmap_match_set_hook.set_ip_nexthop)
  2502. - return rmap_match_set_hook.set_ip_nexthop(
  2503. - vty, index, "ip next-hop", argv[idx_ipv4]->arg);
  2504. - return CMD_SUCCESS;
  2505. -}
  2506. -
  2507. -
  2508. -DEFUN (no_set_ip_nexthop,
  2509. - no_set_ip_nexthop_cmd,
  2510. - "no set ip next-hop [A.B.C.D]",
  2511. - NO_STR
  2512. - SET_STR
  2513. - IP_STR
  2514. - "Next hop address\n"
  2515. - "IP address of next hop\n")
  2516. -{
  2517. - int idx = 0;
  2518. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2519. - const char *arg = NULL;
  2520. -
  2521. - if (argv_find(argv, argc, "A.B.C.D", &idx))
  2522. - arg = argv[idx]->arg;
  2523. -
  2524. - if (rmap_match_set_hook.no_set_ip_nexthop)
  2525. - return rmap_match_set_hook.no_set_ip_nexthop(
  2526. - vty, index, "ip next-hop", arg);
  2527. -
  2528. - return CMD_SUCCESS;
  2529. -}
  2530. -
  2531. -
  2532. -DEFUN (set_ipv6_nexthop_local,
  2533. - set_ipv6_nexthop_local_cmd,
  2534. - "set ipv6 next-hop local X:X::X:X",
  2535. - SET_STR
  2536. - IPV6_STR
  2537. - "IPv6 next-hop address\n"
  2538. - "IPv6 local address\n"
  2539. - "IPv6 address of next hop\n")
  2540. -{
  2541. - int idx_ipv6 = 4;
  2542. - struct in6_addr addr;
  2543. - int ret;
  2544. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2545. -
  2546. - ret = inet_pton(AF_INET6, argv[idx_ipv6]->arg, &addr);
  2547. - if (!ret) {
  2548. - vty_out(vty, "%% Malformed nexthop address\n");
  2549. - return CMD_WARNING_CONFIG_FAILED;
  2550. - }
  2551. - if (!IN6_IS_ADDR_LINKLOCAL(&addr)) {
  2552. - vty_out(vty, "%% Invalid link-local nexthop address\n");
  2553. - return CMD_WARNING_CONFIG_FAILED;
  2554. - }
  2555. -
  2556. - if (rmap_match_set_hook.set_ipv6_nexthop_local)
  2557. - return rmap_match_set_hook.set_ipv6_nexthop_local(
  2558. - vty, index, "ipv6 next-hop local", argv[idx_ipv6]->arg);
  2559. - return CMD_SUCCESS;
  2560. -}
  2561. -
  2562. -
  2563. -DEFUN (no_set_ipv6_nexthop_local,
  2564. - no_set_ipv6_nexthop_local_cmd,
  2565. - "no set ipv6 next-hop local [X:X::X:X]",
  2566. - NO_STR
  2567. - SET_STR
  2568. - IPV6_STR
  2569. - "IPv6 next-hop address\n"
  2570. - "IPv6 local address\n"
  2571. - "IPv6 address of next hop\n")
  2572. -{
  2573. - int idx_ipv6 = 5;
  2574. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2575. -
  2576. - if (rmap_match_set_hook.no_set_ipv6_nexthop_local) {
  2577. - if (argc <= idx_ipv6)
  2578. - return rmap_match_set_hook.no_set_ipv6_nexthop_local(
  2579. - vty, index, "ipv6 next-hop local", NULL);
  2580. - return rmap_match_set_hook.no_set_ipv6_nexthop_local(
  2581. - vty, index, "ipv6 next-hop local", argv[5]->arg);
  2582. - }
  2583. - return CMD_SUCCESS;
  2584. -}
  2585. -
  2586. -DEFUN (set_metric,
  2587. - set_metric_cmd,
  2588. - "set metric <(0-4294967295)|rtt|+rtt|-rtt|+metric|-metric>",
  2589. - SET_STR
  2590. - "Metric value for destination routing protocol\n"
  2591. - "Metric value\n"
  2592. - "Assign round trip time\n"
  2593. - "Add round trip time\n"
  2594. - "Subtract round trip time\n"
  2595. - "Add metric\n"
  2596. - "Subtract metric\n")
  2597. -{
  2598. - int idx_number = 2;
  2599. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2600. -
  2601. - const char *pass = (argv[idx_number]->type == RANGE_TKN)
  2602. - ? argv[idx_number]->arg
  2603. - : argv[idx_number]->text;
  2604. -
  2605. - if (rmap_match_set_hook.set_metric)
  2606. - return rmap_match_set_hook.set_metric(vty, index, "metric",
  2607. - pass);
  2608. - return CMD_SUCCESS;
  2609. -}
  2610. -
  2611. -
  2612. -DEFUN (no_set_metric,
  2613. - no_set_metric_cmd,
  2614. - "no set metric [(0-4294967295)]",
  2615. - NO_STR
  2616. - SET_STR
  2617. - "Metric value for destination routing protocol\n"
  2618. - "Metric value\n")
  2619. -{
  2620. - int idx_number = 3;
  2621. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2622. -
  2623. - if (rmap_match_set_hook.no_set_metric) {
  2624. - if (argc <= idx_number)
  2625. - return rmap_match_set_hook.no_set_metric(
  2626. - vty, index, "metric", NULL);
  2627. - return rmap_match_set_hook.no_set_metric(vty, index, "metric",
  2628. - argv[idx_number]->arg);
  2629. - }
  2630. - return CMD_SUCCESS;
  2631. -}
  2632. -
  2633. -
  2634. -DEFUN (set_tag,
  2635. - set_tag_cmd,
  2636. - "set tag (1-4294967295)",
  2637. - SET_STR
  2638. - "Tag value for routing protocol\n"
  2639. - "Tag value\n")
  2640. -{
  2641. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2642. -
  2643. - int idx_number = 2;
  2644. - if (rmap_match_set_hook.set_tag)
  2645. - return rmap_match_set_hook.set_tag(vty, index, "tag",
  2646. - argv[idx_number]->arg);
  2647. - return CMD_SUCCESS;
  2648. -}
  2649. -
  2650. -
  2651. -DEFUN (no_set_tag,
  2652. - no_set_tag_cmd,
  2653. - "no set tag [(1-4294967295)]",
  2654. - NO_STR
  2655. - SET_STR
  2656. - "Tag value for routing protocol\n"
  2657. - "Tag value\n")
  2658. -{
  2659. - VTY_DECLVAR_CONTEXT(route_map_index, index);
  2660. -
  2661. - int idx_number = 3;
  2662. - if (rmap_match_set_hook.no_set_tag) {
  2663. - if (argc <= idx_number)
  2664. - return rmap_match_set_hook.no_set_tag(vty, index, "tag",
  2665. - NULL);
  2666. - return rmap_match_set_hook.no_set_tag(vty, index, "tag",
  2667. - argv[idx_number]->arg);
  2668. - }
  2669. - return CMD_SUCCESS;
  2670. -}
  2671. -
  2672. -
  2673. -DEFUN_NOSH (route_map,
  2674. - route_map_cmd,
  2675. - "route-map WORD <deny|permit> (1-65535)",
  2676. - "Create route-map or enter route-map command mode\n"
  2677. - "Route map tag\n"
  2678. - "Route map denies set operations\n"
  2679. - "Route map permits set operations\n"
  2680. - "Sequence to insert to/delete from existing route-map entry\n")
  2681. -{
  2682. - int idx_word = 1;
  2683. - int idx_permit_deny = 2;
  2684. - int idx_number = 3;
  2685. - struct route_map *map;
  2686. - struct route_map_index *index;
  2687. - char *endptr = NULL;
  2688. - int permit =
  2689. - argv[idx_permit_deny]->arg[0] == 'p' ? RMAP_PERMIT : RMAP_DENY;
  2690. - unsigned long pref = strtoul(argv[idx_number]->arg, &endptr, 10);
  2691. - const char *mapname = argv[idx_word]->arg;
  2692. -
  2693. - /* Get route map. */
  2694. - map = route_map_get(mapname);
  2695. - index = route_map_index_get(map, permit, pref);
  2696. -
  2697. - VTY_PUSH_CONTEXT(RMAP_NODE, index);
  2698. - return CMD_SUCCESS;
  2699. -}
  2700. -
  2701. -DEFUN (no_route_map_all,
  2702. - no_route_map_all_cmd,
  2703. - "no route-map WORD",
  2704. - NO_STR
  2705. - "Create route-map or enter route-map command mode\n"
  2706. - "Route map tag\n")
  2707. -{
  2708. - int idx_word = 2;
  2709. - const char *mapname = argv[idx_word]->arg;
  2710. - struct route_map *map;
  2711. -
  2712. - map = route_map_lookup_by_name(mapname);
  2713. - if (map == NULL) {
  2714. - vty_out(vty, "%% Could not find route-map %s\n", mapname);
  2715. - return CMD_WARNING_CONFIG_FAILED;
  2716. - }
  2717. -
  2718. - route_map_delete(map);
  2719. -
  2720. - return CMD_SUCCESS;
  2721. -}
  2722. -
  2723. -DEFUN (no_route_map,
  2724. - no_route_map_cmd,
  2725. - "no route-map WORD <deny|permit> (1-65535)",
  2726. - NO_STR
  2727. - "Create route-map or enter route-map command mode\n"
  2728. - "Route map tag\n"
  2729. - "Route map denies set operations\n"
  2730. - "Route map permits set operations\n"
  2731. - "Sequence to insert to/delete from existing route-map entry\n")
  2732. -{
  2733. - int idx_word = 2;
  2734. - int idx_permit_deny = 3;
  2735. - int idx_number = 4;
  2736. - struct route_map *map;
  2737. - struct route_map_index *index;
  2738. - char *endptr = NULL;
  2739. - int permit = strmatch(argv[idx_permit_deny]->text, "permit")
  2740. - ? RMAP_PERMIT
  2741. - : RMAP_DENY;
  2742. - const char *prefstr = argv[idx_number]->arg;
  2743. - const char *mapname = argv[idx_word]->arg;
  2744. - unsigned long pref = strtoul(prefstr, &endptr, 10);
  2745. -
  2746. - /* Existence check. */
  2747. - map = route_map_lookup_by_name(mapname);
  2748. - if (map == NULL) {
  2749. - vty_out(vty, "%% Could not find route-map %s\n", mapname);
  2750. - return CMD_WARNING_CONFIG_FAILED;
  2751. - }
  2752. -
  2753. - /* Lookup route map index. */
  2754. - index = route_map_index_lookup(map, permit, pref);
  2755. - if (index == NULL) {
  2756. - vty_out(vty, "%% Could not find route-map entry %s %s\n",
  2757. - mapname, prefstr);
  2758. - return CMD_WARNING_CONFIG_FAILED;
  2759. - }
  2760. -
  2761. - /* Delete index from route map. */
  2762. - route_map_index_delete(index, 1);
  2763. -
  2764. - /* If this route rule is the last one, delete route map itself. */
  2765. - if (route_map_empty(map))
  2766. - route_map_delete(map);
  2767. -
  2768. - return CMD_SUCCESS;
  2769. -}
  2770. -
  2771. -DEFUN (rmap_onmatch_next,
  2772. - rmap_onmatch_next_cmd,
  2773. - "on-match next",
  2774. - "Exit policy on matches\n"
  2775. - "Next clause\n")
  2776. -{
  2777. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2778. -
  2779. - if (index) {
  2780. - if (index->type == RMAP_DENY) {
  2781. - /* Under a deny clause, match means it's finished. No
  2782. - * need to set next */
  2783. - vty_out(vty,
  2784. - "on-match next not supported under route-map deny\n");
  2785. - return CMD_WARNING_CONFIG_FAILED;
  2786. - }
  2787. - index->exitpolicy = RMAP_NEXT;
  2788. - }
  2789. - return CMD_SUCCESS;
  2790. -}
  2791. -
  2792. -DEFUN (no_rmap_onmatch_next,
  2793. - no_rmap_onmatch_next_cmd,
  2794. - "no on-match next",
  2795. - NO_STR
  2796. - "Exit policy on matches\n"
  2797. - "Next clause\n")
  2798. -{
  2799. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2800. -
  2801. - if (index)
  2802. - index->exitpolicy = RMAP_EXIT;
  2803. -
  2804. - return CMD_SUCCESS;
  2805. -}
  2806. -
  2807. -DEFUN (rmap_onmatch_goto,
  2808. - rmap_onmatch_goto_cmd,
  2809. - "on-match goto (1-65535)",
  2810. - "Exit policy on matches\n"
  2811. - "Goto Clause number\n"
  2812. - "Number\n")
  2813. -{
  2814. - int idx = 0;
  2815. - char *num = argv_find(argv, argc, "(1-65535)", &idx) ? argv[idx]->arg
  2816. - : NULL;
  2817. -
  2818. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2819. - int d = 0;
  2820. -
  2821. - if (index) {
  2822. - if (index->type == RMAP_DENY) {
  2823. - /* Under a deny clause, match means it's finished. No
  2824. - * need to go anywhere */
  2825. - vty_out(vty,
  2826. - "on-match goto not supported under route-map deny\n");
  2827. - return CMD_WARNING_CONFIG_FAILED;
  2828. - }
  2829. -
  2830. - if (num)
  2831. - d = strtoul(num, NULL, 10);
  2832. - else
  2833. - d = index->pref + 1;
  2834. -
  2835. - if (d <= index->pref) {
  2836. - /* Can't allow you to do that, Dave */
  2837. - vty_out(vty, "can't jump backwards in route-maps\n");
  2838. - return CMD_WARNING_CONFIG_FAILED;
  2839. - } else {
  2840. - index->exitpolicy = RMAP_GOTO;
  2841. - index->nextpref = d;
  2842. - }
  2843. - }
  2844. - return CMD_SUCCESS;
  2845. -}
  2846. -
  2847. -DEFUN (no_rmap_onmatch_goto,
  2848. - no_rmap_onmatch_goto_cmd,
  2849. - "no on-match goto",
  2850. - NO_STR
  2851. - "Exit policy on matches\n"
  2852. - "Goto Clause number\n")
  2853. -{
  2854. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2855. -
  2856. - if (index)
  2857. - index->exitpolicy = RMAP_EXIT;
  2858. -
  2859. - return CMD_SUCCESS;
  2860. -}
  2861. -
  2862. -/* Cisco/GNU Zebra compatibility aliases */
  2863. -/* ALIAS_FIXME */
  2864. -DEFUN (rmap_continue,
  2865. - rmap_continue_cmd,
  2866. - "continue (1-65535)",
  2867. - "Continue on a different entry within the route-map\n"
  2868. - "Route-map entry sequence number\n")
  2869. -{
  2870. - return rmap_onmatch_goto(self, vty, argc, argv);
  2871. -}
  2872. -
  2873. -/* ALIAS_FIXME */
  2874. -DEFUN (no_rmap_continue,
  2875. - no_rmap_continue_cmd,
  2876. - "no continue [(1-65535)]",
  2877. - NO_STR
  2878. - "Continue on a different entry within the route-map\n"
  2879. - "Route-map entry sequence number\n")
  2880. -{
  2881. - return no_rmap_onmatch_goto(self, vty, argc, argv);
  2882. -}
  2883. -
  2884. static void clear_route_map_helper(struct route_map *map)
  2885. {
  2886. struct route_map_index *index;
  2887. @@ -2937,89 +2064,6 @@ DEFUN (rmap_show_unused,
  2888. return vty_show_unused_route_map(vty);
  2889. }
  2890. -DEFUN (rmap_call,
  2891. - rmap_call_cmd,
  2892. - "call WORD",
  2893. - "Jump to another Route-Map after match+set\n"
  2894. - "Target route-map name\n")
  2895. -{
  2896. - int idx_word = 1;
  2897. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2898. - const char *rmap = argv[idx_word]->arg;
  2899. -
  2900. - assert(index);
  2901. -
  2902. - /* If "call" is invoked with the same route-map name as
  2903. - * the one previously configured then, ignore the duplicate
  2904. - * configuration.
  2905. - */
  2906. - if (index->nextrm && (strcmp(index->nextrm, rmap) == 0))
  2907. - return CMD_SUCCESS;
  2908. -
  2909. - if (index->nextrm) {
  2910. - route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED,
  2911. - index->nextrm, index->map->name);
  2912. - XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm);
  2913. - }
  2914. - index->nextrm = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
  2915. -
  2916. - /* Execute event hook. */
  2917. - route_map_upd8_dependency(RMAP_EVENT_CALL_ADDED, index->nextrm,
  2918. - index->map->name);
  2919. - return CMD_SUCCESS;
  2920. -}
  2921. -
  2922. -DEFUN (no_rmap_call,
  2923. - no_rmap_call_cmd,
  2924. - "no call",
  2925. - NO_STR
  2926. - "Jump to another Route-Map after match+set\n")
  2927. -{
  2928. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2929. -
  2930. - if (index->nextrm) {
  2931. - route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED,
  2932. - index->nextrm, index->map->name);
  2933. - XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm);
  2934. - index->nextrm = NULL;
  2935. - }
  2936. -
  2937. - return CMD_SUCCESS;
  2938. -}
  2939. -
  2940. -DEFUN (rmap_description,
  2941. - rmap_description_cmd,
  2942. - "description LINE...",
  2943. - "Route-map comment\n"
  2944. - "Comment describing this route-map rule\n")
  2945. -{
  2946. - int idx_line = 1;
  2947. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2948. -
  2949. - if (index) {
  2950. - if (index->description)
  2951. - XFREE(MTYPE_TMP, index->description);
  2952. - index->description = argv_concat(argv, argc, idx_line);
  2953. - }
  2954. - return CMD_SUCCESS;
  2955. -}
  2956. -
  2957. -DEFUN (no_rmap_description,
  2958. - no_rmap_description_cmd,
  2959. - "no description",
  2960. - NO_STR
  2961. - "Route-map comment\n")
  2962. -{
  2963. - struct route_map_index *index = VTY_GET_CONTEXT(route_map_index);
  2964. -
  2965. - if (index) {
  2966. - if (index->description)
  2967. - XFREE(MTYPE_TMP, index->description);
  2968. - index->description = NULL;
  2969. - }
  2970. - return CMD_SUCCESS;
  2971. -}
  2972. -
  2973. DEFUN (debug_rmap,
  2974. debug_rmap_cmd,
  2975. "debug route-map",
  2976. @@ -3045,59 +2089,6 @@ DEFUN (no_debug_rmap,
  2977. static struct cmd_node rmap_debug_node = {RMAP_DEBUG_NODE, "", 1};
  2978. /* Configuration write function. */
  2979. -static int route_map_config_write(struct vty *vty)
  2980. -{
  2981. - struct route_map *map;
  2982. - struct route_map_index *index;
  2983. - struct route_map_rule *rule;
  2984. - int first = 1;
  2985. - int write = 0;
  2986. - struct listnode *ln;
  2987. - struct list *maplist = list_new();
  2988. -
  2989. - for (map = route_map_master.head; map; map = map->next)
  2990. - listnode_add(maplist, map);
  2991. -
  2992. - list_sort(maplist, sort_route_map);
  2993. -
  2994. - for (ALL_LIST_ELEMENTS_RO(maplist, ln, map))
  2995. - for (index = map->head; index; index = index->next) {
  2996. - if (!first)
  2997. - vty_out(vty, "!\n");
  2998. - else
  2999. - first = 0;
  3000. -
  3001. - vty_out(vty, "route-map %s %s %d\n", map->name,
  3002. - route_map_type_str(index->type), index->pref);
  3003. -
  3004. - if (index->description)
  3005. - vty_out(vty, " description %s\n",
  3006. - index->description);
  3007. -
  3008. - for (rule = index->match_list.head; rule;
  3009. - rule = rule->next)
  3010. - vty_out(vty, " match %s %s\n", rule->cmd->str,
  3011. - rule->rule_str ? rule->rule_str : "");
  3012. -
  3013. - for (rule = index->set_list.head; rule;
  3014. - rule = rule->next)
  3015. - vty_out(vty, " set %s %s\n", rule->cmd->str,
  3016. - rule->rule_str ? rule->rule_str : "");
  3017. - if (index->nextrm)
  3018. - vty_out(vty, " call %s\n", index->nextrm);
  3019. - if (index->exitpolicy == RMAP_GOTO)
  3020. - vty_out(vty, " on-match goto %d\n",
  3021. - index->nextpref);
  3022. - if (index->exitpolicy == RMAP_NEXT)
  3023. - vty_out(vty, " on-match next\n");
  3024. -
  3025. - write++;
  3026. - }
  3027. -
  3028. - list_delete(&maplist);
  3029. - return write;
  3030. -}
  3031. -
  3032. static int rmap_config_write_debug(struct vty *vty)
  3033. {
  3034. int write = 0;
  3035. @@ -3110,9 +2101,6 @@ static int rmap_config_write_debug(struct vty *vty)
  3036. return write;
  3037. }
  3038. -/* Route map node structure. */
  3039. -static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# ", 1};
  3040. -
  3041. /* Common route map rules */
  3042. void *route_map_rule_tag_compile(const char *arg)
  3043. @@ -3171,14 +2159,6 @@ void route_map_finish(void)
  3044. route_map_master_hash = NULL;
  3045. }
  3046. -static void rmap_autocomplete(vector comps, struct cmd_token *token)
  3047. -{
  3048. - struct route_map *map;
  3049. -
  3050. - for (map = route_map_master.head; map; map = map->next)
  3051. - vector_set(comps, XSTRDUP(MTYPE_COMPLETION, map->name));
  3052. -}
  3053. -
  3054. /* Increment the use_count counter while attaching the route map */
  3055. void route_map_counter_increment(struct route_map *map)
  3056. {
  3057. @@ -3196,14 +2176,6 @@ void route_map_counter_decrement(struct route_map *map)
  3058. }
  3059. }
  3060. -static const struct cmd_variable_handler rmap_var_handlers[] = {
  3061. - {/* "route-map WORD" */
  3062. - .varname = "route_map",
  3063. - .completions = rmap_autocomplete},
  3064. - {.tokenname = "ROUTEMAP_NAME", .completions = rmap_autocomplete},
  3065. - {.tokenname = "RMAP_NAME", .completions = rmap_autocomplete},
  3066. - {.completions = NULL}};
  3067. -
  3068. /* Initialization of route map vector. */
  3069. void route_map_init(void)
  3070. {
  3071. @@ -3221,43 +2193,17 @@ void route_map_init(void)
  3072. 8, route_map_dep_hash_make_key, route_map_dep_hash_cmp,
  3073. "Route Map Dep Hash");
  3074. - cmd_variable_handler_register(rmap_var_handlers);
  3075. -
  3076. rmap_debug = false;
  3077. - /* Install route map top node. */
  3078. - install_node(&rmap_node, route_map_config_write);
  3079. + route_map_cli_init();
  3080. + /* Install route map top node. */
  3081. install_node(&rmap_debug_node, rmap_config_write_debug);
  3082. /* Install route map commands. */
  3083. - install_default(RMAP_NODE);
  3084. - install_element(CONFIG_NODE, &route_map_cmd);
  3085. - install_element(CONFIG_NODE, &no_route_map_cmd);
  3086. - install_element(CONFIG_NODE, &no_route_map_all_cmd);
  3087. -
  3088. install_element(CONFIG_NODE, &debug_rmap_cmd);
  3089. install_element(CONFIG_NODE, &no_debug_rmap_cmd);
  3090. - /* Install the on-match stuff */
  3091. - install_element(RMAP_NODE, &route_map_cmd);
  3092. - install_element(RMAP_NODE, &rmap_onmatch_next_cmd);
  3093. - install_element(RMAP_NODE, &no_rmap_onmatch_next_cmd);
  3094. - install_element(RMAP_NODE, &rmap_onmatch_goto_cmd);
  3095. - install_element(RMAP_NODE, &no_rmap_onmatch_goto_cmd);
  3096. - install_element(RMAP_NODE, &rmap_continue_cmd);
  3097. - install_element(RMAP_NODE, &no_rmap_continue_cmd);
  3098. -
  3099. - /* Install the continue stuff (ALIAS of on-match). */
  3100. -
  3101. - /* Install the call stuff. */
  3102. - install_element(RMAP_NODE, &rmap_call_cmd);
  3103. - install_element(RMAP_NODE, &no_rmap_call_cmd);
  3104. -
  3105. - /* Install description commands. */
  3106. - install_element(RMAP_NODE, &rmap_description_cmd);
  3107. - install_element(RMAP_NODE, &no_rmap_description_cmd);
  3108. -
  3109. /* Install show command */
  3110. install_element(ENABLE_NODE, &rmap_clear_counters_cmd);
  3111. @@ -3266,49 +2212,4 @@ void route_map_init(void)
  3112. install_element(ENABLE_NODE, &debug_rmap_cmd);
  3113. install_element(ENABLE_NODE, &no_debug_rmap_cmd);
  3114. -
  3115. - install_element(RMAP_NODE, &match_interface_cmd);
  3116. - install_element(RMAP_NODE, &no_match_interface_cmd);
  3117. -
  3118. - install_element(RMAP_NODE, &match_ip_address_cmd);
  3119. - install_element(RMAP_NODE, &no_match_ip_address_cmd);
  3120. -
  3121. - install_element(RMAP_NODE, &match_ip_address_prefix_list_cmd);
  3122. - install_element(RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  3123. -
  3124. - install_element(RMAP_NODE, &match_ip_next_hop_cmd);
  3125. - install_element(RMAP_NODE, &no_match_ip_next_hop_cmd);
  3126. -
  3127. - install_element(RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  3128. - install_element(RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  3129. -
  3130. - install_element(RMAP_NODE, &match_ip_next_hop_type_cmd);
  3131. - install_element(RMAP_NODE, &no_match_ip_next_hop_type_cmd);
  3132. -
  3133. - install_element(RMAP_NODE, &match_ipv6_address_cmd);
  3134. - install_element(RMAP_NODE, &no_match_ipv6_address_cmd);
  3135. -
  3136. - install_element(RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
  3137. - install_element(RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
  3138. -
  3139. - install_element(RMAP_NODE, &match_ipv6_next_hop_type_cmd);
  3140. - install_element(RMAP_NODE, &no_match_ipv6_next_hop_type_cmd);
  3141. -
  3142. - install_element(RMAP_NODE, &match_metric_cmd);
  3143. - install_element(RMAP_NODE, &no_match_metric_cmd);
  3144. -
  3145. - install_element(RMAP_NODE, &match_tag_cmd);
  3146. - install_element(RMAP_NODE, &no_match_tag_cmd);
  3147. -
  3148. - install_element(RMAP_NODE, &set_ip_nexthop_cmd);
  3149. - install_element(RMAP_NODE, &no_set_ip_nexthop_cmd);
  3150. -
  3151. - install_element(RMAP_NODE, &set_ipv6_nexthop_local_cmd);
  3152. - install_element(RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
  3153. -
  3154. - install_element(RMAP_NODE, &set_metric_cmd);
  3155. - install_element(RMAP_NODE, &no_set_metric_cmd);
  3156. -
  3157. - install_element(RMAP_NODE, &set_tag_cmd);
  3158. - install_element(RMAP_NODE, &no_set_tag_cmd);
  3159. }
  3160. diff --git a/lib/routemap.h b/lib/routemap.h
  3161. index d9e7f73f81..70e150c981 100644
  3162. --- a/lib/routemap.h
  3163. +++ b/lib/routemap.h
  3164. @@ -666,8 +666,27 @@ int lib_route_map_entry_match_destroy(enum nb_event event,
  3165. const struct lyd_node *dnode);
  3166. int lib_route_map_entry_set_destroy(enum nb_event event,
  3167. const struct lyd_node *dnode);
  3168. +
  3169. extern const struct frr_yang_module_info frr_route_map_info;
  3170. +/* routemap_cli.c */
  3171. +extern void route_map_instance_show(struct vty *vty, struct lyd_node *dnode,
  3172. + bool show_defaults);
  3173. +extern void route_map_instance_show_end(struct vty *vty,
  3174. + struct lyd_node *dnode);
  3175. +extern void route_map_condition_show(struct vty *vty, struct lyd_node *dnode,
  3176. + bool show_defaults);
  3177. +extern void route_map_action_show(struct vty *vty, struct lyd_node *dnode,
  3178. + bool show_defaults);
  3179. +extern void route_map_exit_policy_show(struct vty *vty, struct lyd_node *dnode,
  3180. + bool show_defaults);
  3181. +extern void route_map_call_show(struct vty *vty, struct lyd_node *dnode,
  3182. + bool show_defaults);
  3183. +extern void route_map_description_show(struct vty *vty,
  3184. + struct lyd_node *dnode,
  3185. + bool show_defaults);
  3186. +extern void route_map_cli_init(void);
  3187. +
  3188. #ifdef __cplusplus
  3189. }
  3190. #endif
  3191. diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c
  3192. new file mode 100644
  3193. index 0000000000..987693c961
  3194. --- /dev/null
  3195. +++ b/lib/routemap_cli.c
  3196. @@ -0,0 +1,1075 @@
  3197. +/*
  3198. + * Route map northbound CLI implementation.
  3199. + *
  3200. + * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
  3201. + * Rafael Zalamena
  3202. + *
  3203. + * This program is free software; you can redistribute it and/or modify
  3204. + * it under the terms of the GNU General Public License as published by
  3205. + * the Free Software Foundation; either version 2 of the License, or
  3206. + * (at your option) any later version.
  3207. + *
  3208. + * This program is distributed in the hope that it will be useful,
  3209. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3210. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3211. + * GNU General Public License for more details.
  3212. + *
  3213. + * You should have received a copy of the GNU General Public License
  3214. + * along with this program; if not, write to the Free Software
  3215. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  3216. + * 02110-1301 USA.
  3217. + */
  3218. +
  3219. +#include <zebra.h>
  3220. +
  3221. +#include "lib/command.h"
  3222. +#include "lib/northbound_cli.h"
  3223. +#include "lib/routemap.h"
  3224. +
  3225. +#ifndef VTYSH_EXTRACT_PL
  3226. +#include "lib/routemap_cli_clippy.c"
  3227. +#endif /* VTYSH_EXTRACT_PL */
  3228. +
  3229. +#define ROUTE_MAP_CMD_STR \
  3230. + "Create route-map or enter route-map command mode\n" \
  3231. + "Route map tag\n"
  3232. +#define ROUTE_MAP_OP_CMD_STR \
  3233. + "Route map denies set operations\n" \
  3234. + "Route map permits set operations\n"
  3235. +#define ROUTE_MAP_SEQUENCE_CMD_STR \
  3236. + "Sequence to insert to/delete from existing route-map entry\n"
  3237. +
  3238. +DEFPY_NOSH(
  3239. + route_map, route_map_cmd,
  3240. + "route-map WORD$name <deny|permit>$action (1-65535)$sequence",
  3241. + ROUTE_MAP_CMD_STR
  3242. + ROUTE_MAP_OP_CMD_STR
  3243. + ROUTE_MAP_SEQUENCE_CMD_STR)
  3244. +{
  3245. + char xpath_action[XPATH_MAXLEN + 64];
  3246. + char xpath_index[XPATH_MAXLEN + 32];
  3247. + char xpath[XPATH_MAXLEN];
  3248. + int rv;
  3249. +
  3250. + snprintf(xpath, sizeof(xpath),
  3251. + "/frr-route-map:lib/route-map[name='%s']", name);
  3252. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3253. +
  3254. + snprintf(xpath_index, sizeof(xpath_index), "%s/entry[sequence='%lu']",
  3255. + xpath, sequence);
  3256. + nb_cli_enqueue_change(vty, xpath_index, NB_OP_CREATE, NULL);
  3257. +
  3258. + snprintf(xpath_action, sizeof(xpath_action), "%s/action", xpath_index);
  3259. + nb_cli_enqueue_change(vty, xpath_action, NB_OP_MODIFY, action);
  3260. +
  3261. + rv = nb_cli_apply_changes(vty, NULL);
  3262. + if (rv == CMD_SUCCESS)
  3263. + VTY_PUSH_XPATH(RMAP_NODE, xpath_index);
  3264. +
  3265. + return rv;
  3266. +}
  3267. +
  3268. +DEFPY(
  3269. + no_route_map_all, no_route_map_all_cmd,
  3270. + "no route-map WORD$name",
  3271. + NO_STR
  3272. + ROUTE_MAP_CMD_STR)
  3273. +{
  3274. + char xpath[XPATH_MAXLEN];
  3275. +
  3276. + snprintf(xpath, sizeof(xpath),
  3277. + "/frr-route-map:lib/route-map[name='%s']", name);
  3278. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3279. +
  3280. + return nb_cli_apply_changes(vty, NULL);
  3281. +}
  3282. +
  3283. +DEFPY(
  3284. + no_route_map, no_route_map_cmd,
  3285. + "no route-map WORD$name <deny|permit>$action (1-65535)$sequence",
  3286. + NO_STR
  3287. + ROUTE_MAP_CMD_STR
  3288. + ROUTE_MAP_OP_CMD_STR
  3289. + ROUTE_MAP_SEQUENCE_CMD_STR)
  3290. +{
  3291. + char xpath[XPATH_MAXLEN];
  3292. +
  3293. + snprintf(xpath, sizeof(xpath),
  3294. + "/frr-route-map:lib/route-map[name='%s']/entry[sequence='%lu']",
  3295. + name, sequence);
  3296. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3297. +
  3298. + return nb_cli_apply_changes(vty, NULL);
  3299. +}
  3300. +
  3301. +void route_map_instance_show(struct vty *vty, struct lyd_node *dnode,
  3302. + bool show_defaults)
  3303. +{
  3304. + const char *name = yang_dnode_get_string(dnode, "../name");
  3305. + const char *action = yang_dnode_get_string(dnode, "./action");
  3306. + const char *sequence = yang_dnode_get_string(dnode, "./sequence");
  3307. +
  3308. + vty_out(vty, "route-map %s %s %s\n", name, action, sequence);
  3309. +}
  3310. +
  3311. +void route_map_instance_show_end(struct vty *vty, struct lyd_node *dnode)
  3312. +{
  3313. + vty_out(vty, "!\n");
  3314. +}
  3315. +
  3316. +DEFPY(
  3317. + match_interface, match_interface_cmd,
  3318. + "match interface IFNAME",
  3319. + MATCH_STR
  3320. + "Match first hop interface of route\n"
  3321. + INTERFACE_STR)
  3322. +{
  3323. + const char *xpath = "./match-condition[condition='interface']";
  3324. + char xpath_value[XPATH_MAXLEN];
  3325. +
  3326. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3327. + snprintf(xpath_value, sizeof(xpath_value), "%s/interface", xpath);
  3328. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ifname);
  3329. +
  3330. + return nb_cli_apply_changes(vty, NULL);
  3331. +}
  3332. +
  3333. +DEFPY(
  3334. + no_match_interface, no_match_interface_cmd,
  3335. + "no match interface [IFNAME]",
  3336. + NO_STR
  3337. + MATCH_STR
  3338. + "Match first hop interface of route\n"
  3339. + INTERFACE_STR)
  3340. +{
  3341. + const char *xpath = "./match-condition[condition='interface']";
  3342. +
  3343. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3344. +
  3345. + return nb_cli_apply_changes(vty, NULL);
  3346. +}
  3347. +
  3348. +DEFPY(
  3349. + match_ip_address, match_ip_address_cmd,
  3350. + "match ip address <(1-199)$acll|(1300-2699)$aclh|WORD$name>",
  3351. + MATCH_STR
  3352. + IP_STR
  3353. + "Match address of route\n"
  3354. + "IP access-list number\n"
  3355. + "IP access-list number (expanded range)\n"
  3356. + "IP Access-list name\n")
  3357. +{
  3358. + const char *xpath = "./match-condition[condition='ipv4-address-list']";
  3359. + char xpath_value[XPATH_MAXLEN + 32];
  3360. + int acln = acll ? acll : aclh;
  3361. +
  3362. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3363. + if (name) {
  3364. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name",
  3365. + xpath);
  3366. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3367. + } else /* if (acll || aclh) */ {
  3368. + if ((acln >= 1 && acln <= 99)
  3369. + || (acln >= 1300 && acln <= 1999)) {
  3370. + snprintf(xpath_value, sizeof(xpath_value),
  3371. + "%s/access-list-num", xpath);
  3372. + } else {
  3373. + /*
  3374. + * if ((acln >= 100 && acln <= 199)
  3375. + * || (acln >= 2000 && acln <= 2699))
  3376. + */
  3377. + snprintf(xpath_value, sizeof(xpath_value),
  3378. + "%s/access-list-num-extended", xpath);
  3379. + }
  3380. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
  3381. + acll_str ? acll_str : aclh_str);
  3382. + }
  3383. +
  3384. + return nb_cli_apply_changes(vty, NULL);
  3385. +}
  3386. +
  3387. +DEFPY(
  3388. + no_match_ip_address, no_match_ip_address_cmd,
  3389. + "no match ip address [<(1-199)|(1300-2699)|WORD>]",
  3390. + NO_STR
  3391. + MATCH_STR
  3392. + IP_STR
  3393. + "Match address of route\n"
  3394. + "IP access-list number\n"
  3395. + "IP access-list number (expanded range)\n"
  3396. + "IP Access-list name\n")
  3397. +{
  3398. + const char *xpath = "./match-condition[condition='ipv4-address-list']";
  3399. +
  3400. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3401. +
  3402. + return nb_cli_apply_changes(vty, NULL);
  3403. +}
  3404. +
  3405. +DEFPY(
  3406. + match_ip_address_prefix_list,
  3407. + match_ip_address_prefix_list_cmd,
  3408. + "match ip address prefix-list WORD$name",
  3409. + MATCH_STR
  3410. + IP_STR
  3411. + "Match address of route\n"
  3412. + "Match entries of prefix-lists\n"
  3413. + "IP prefix-list name\n")
  3414. +{
  3415. + const char *xpath = "./match-condition[condition='ipv4-prefix-list']";
  3416. + char xpath_value[XPATH_MAXLEN];
  3417. +
  3418. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3419. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
  3420. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3421. +
  3422. + return nb_cli_apply_changes(vty, NULL);
  3423. +}
  3424. +
  3425. +DEFPY(
  3426. + no_match_ip_address_prefix_list, no_match_ip_address_prefix_list_cmd,
  3427. + "no match ip address prefix-list [WORD]",
  3428. + NO_STR
  3429. + MATCH_STR
  3430. + IP_STR
  3431. + "Match address of route\n"
  3432. + "Match entries of prefix-lists\n"
  3433. + "IP prefix-list name\n")
  3434. +{
  3435. + const char *xpath = "./match-condition[condition='ipv4-prefix-list']";
  3436. +
  3437. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3438. +
  3439. + return nb_cli_apply_changes(vty, NULL);
  3440. +}
  3441. +
  3442. +DEFPY(
  3443. + match_ip_next_hop, match_ip_next_hop_cmd,
  3444. + "match ip next-hop <(1-199)$acll|(1300-2699)$aclh|WORD$name>",
  3445. + MATCH_STR
  3446. + IP_STR
  3447. + "Match next-hop address of route\n"
  3448. + "IP access-list number\n"
  3449. + "IP access-list number (expanded range)\n"
  3450. + "IP Access-list name\n")
  3451. +{
  3452. + const char *xpath = "./match-condition[condition='ipv4-next-hop-list']";
  3453. + char xpath_value[XPATH_MAXLEN + 32];
  3454. + int acln = acll ? acll : aclh;
  3455. +
  3456. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3457. + if (name) {
  3458. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name",
  3459. + xpath);
  3460. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3461. + } else /* if (acll || aclh) */ {
  3462. + if ((acln >= 1 && acln <= 99)
  3463. + || (acln >= 1300 && acln <= 1999)) {
  3464. + snprintf(xpath_value, sizeof(xpath_value),
  3465. + "%s/access-list-num", xpath);
  3466. + } else {
  3467. + /*
  3468. + * if ((acln >= 100 && acln <= 199)
  3469. + * || (acln >= 2000 && acln <= 2699))
  3470. + */
  3471. + snprintf(xpath_value, sizeof(xpath_value),
  3472. + "%s/access-list-num-extended", xpath);
  3473. + }
  3474. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
  3475. + acll_str ? acll_str : aclh_str);
  3476. + }
  3477. +
  3478. + return nb_cli_apply_changes(vty, NULL);
  3479. +}
  3480. +
  3481. +DEFPY(
  3482. + no_match_ip_next_hop, no_match_ip_next_hop_cmd,
  3483. + "no match ip next-hop [<(1-199)|(1300-2699)|WORD>]",
  3484. + NO_STR
  3485. + MATCH_STR
  3486. + IP_STR
  3487. + "Match address of route\n"
  3488. + "IP access-list number\n"
  3489. + "IP access-list number (expanded range)\n"
  3490. + "IP Access-list name\n")
  3491. +{
  3492. + const char *xpath = "./match-condition[condition='ipv4-next-hop-list']";
  3493. +
  3494. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3495. +
  3496. + return nb_cli_apply_changes(vty, NULL);
  3497. +}
  3498. +
  3499. +DEFPY(
  3500. + match_ip_next_hop_prefix_list,
  3501. + match_ip_next_hop_prefix_list_cmd,
  3502. + "match ip next-hop prefix-list WORD$name",
  3503. + MATCH_STR
  3504. + IP_STR
  3505. + "Match next-hop address of route\n"
  3506. + "Match entries of prefix-lists\n"
  3507. + "IP prefix-list name\n")
  3508. +{
  3509. + const char *xpath =
  3510. + "./match-condition[condition='ipv4-next-hop-prefix-list']";
  3511. + char xpath_value[XPATH_MAXLEN];
  3512. +
  3513. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3514. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
  3515. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3516. +
  3517. + return nb_cli_apply_changes(vty, NULL);
  3518. +}
  3519. +
  3520. +DEFPY(
  3521. + no_match_ip_next_hop_prefix_list,
  3522. + no_match_ip_next_hop_prefix_list_cmd,
  3523. + "no match ip next-hop prefix-list [WORD]",
  3524. + NO_STR
  3525. + MATCH_STR
  3526. + IP_STR
  3527. + "Match next-hop address of route\n"
  3528. + "Match entries of prefix-lists\n"
  3529. + "IP prefix-list name\n")
  3530. +{
  3531. + const char *xpath =
  3532. + "./match-condition[condition='ipv4-next-hop-prefix-list']";
  3533. +
  3534. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3535. +
  3536. + return nb_cli_apply_changes(vty, NULL);
  3537. +}
  3538. +
  3539. +DEFPY(
  3540. + match_ip_next_hop_type, match_ip_next_hop_type_cmd,
  3541. + "match ip next-hop type <blackhole>$type",
  3542. + MATCH_STR
  3543. + IP_STR
  3544. + "Match next-hop address of route\n"
  3545. + "Match entries by type\n"
  3546. + "Blackhole\n")
  3547. +{
  3548. + const char *xpath = "./match-condition[condition='ipv4-next-hop-type']";
  3549. + char xpath_value[XPATH_MAXLEN];
  3550. +
  3551. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3552. + snprintf(xpath_value, sizeof(xpath_value), "%s/ipv4-next-hop-type",
  3553. + xpath);
  3554. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, type);
  3555. +
  3556. + return nb_cli_apply_changes(vty, NULL);
  3557. +}
  3558. +
  3559. +DEFPY(
  3560. + no_match_ip_next_hop_type, no_match_ip_next_hop_type_cmd,
  3561. + "no match ip next-hop type [<blackhole>]",
  3562. + NO_STR MATCH_STR IP_STR
  3563. + "Match next-hop address of route\n"
  3564. + "Match entries by type\n"
  3565. + "Blackhole\n")
  3566. +{
  3567. + const char *xpath = "./match-condition[condition='ipv4-next-hop-type']";
  3568. +
  3569. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3570. +
  3571. + return nb_cli_apply_changes(vty, NULL);
  3572. +}
  3573. +
  3574. +DEFPY(
  3575. + match_ipv6_address, match_ipv6_address_cmd,
  3576. + "match ipv6 address WORD$name",
  3577. + MATCH_STR
  3578. + IPV6_STR
  3579. + "Match IPv6 address of route\n"
  3580. + "IPv6 access-list name\n")
  3581. +{
  3582. + const char *xpath = "./match-condition[condition='ipv6-address-list']";
  3583. + char xpath_value[XPATH_MAXLEN];
  3584. +
  3585. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3586. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
  3587. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3588. +
  3589. + return nb_cli_apply_changes(vty, NULL);
  3590. +}
  3591. +
  3592. +DEFPY(
  3593. + no_match_ipv6_address, no_match_ipv6_address_cmd,
  3594. + "no match ipv6 address [WORD]",
  3595. + NO_STR
  3596. + MATCH_STR
  3597. + IPV6_STR
  3598. + "Match IPv6 address of route\n"
  3599. + "IPv6 access-list name\n")
  3600. +{
  3601. + const char *xpath = "./match-condition[condition='ipv6-address-list']";
  3602. +
  3603. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3604. +
  3605. + return nb_cli_apply_changes(vty, NULL);
  3606. +}
  3607. +
  3608. +DEFPY(
  3609. + match_ipv6_address_prefix_list, match_ipv6_address_prefix_list_cmd,
  3610. + "match ipv6 address prefix-list WORD$name",
  3611. + MATCH_STR
  3612. + IPV6_STR
  3613. + "Match address of route\n"
  3614. + "Match entries of prefix-lists\n"
  3615. + "IP prefix-list name\n")
  3616. +{
  3617. + const char *xpath = "./match-condition[condition='ipv6-prefix-list']";
  3618. + char xpath_value[XPATH_MAXLEN];
  3619. +
  3620. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3621. + snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
  3622. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
  3623. +
  3624. + return nb_cli_apply_changes(vty, NULL);
  3625. +}
  3626. +
  3627. +DEFPY(
  3628. + no_match_ipv6_address_prefix_list,
  3629. + no_match_ipv6_address_prefix_list_cmd,
  3630. + "no match ipv6 address prefix-list [WORD]",
  3631. + NO_STR
  3632. + MATCH_STR
  3633. + IPV6_STR
  3634. + "Match address of route\n"
  3635. + "Match entries of prefix-lists\n"
  3636. + "IP prefix-list name\n")
  3637. +{
  3638. + const char *xpath = "./match-condition[condition='ipv6-prefix-list']";
  3639. +
  3640. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3641. +
  3642. + return nb_cli_apply_changes(vty, NULL);
  3643. +}
  3644. +
  3645. +DEFPY(
  3646. + match_ipv6_next_hop_type, match_ipv6_next_hop_type_cmd,
  3647. + "match ipv6 next-hop type <blackhole>$type",
  3648. + MATCH_STR IPV6_STR
  3649. + "Match next-hop address of route\n"
  3650. + "Match entries by type\n"
  3651. + "Blackhole\n")
  3652. +{
  3653. + const char *xpath = "./match-condition[condition='ipv6-next-hop-type']";
  3654. + char xpath_value[XPATH_MAXLEN];
  3655. +
  3656. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3657. + snprintf(xpath_value, sizeof(xpath_value), "%s/ipv6-next-hop-type",
  3658. + xpath);
  3659. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, type);
  3660. +
  3661. + return nb_cli_apply_changes(vty, NULL);
  3662. +}
  3663. +
  3664. +DEFPY(
  3665. + no_match_ipv6_next_hop_type, no_match_ipv6_next_hop_type_cmd,
  3666. + "no match ipv6 next-hop type [<blackhole>]",
  3667. + NO_STR MATCH_STR IPV6_STR
  3668. + "Match address of route\n"
  3669. + "Match entries by type\n"
  3670. + "Blackhole\n")
  3671. +{
  3672. + const char *xpath = "./match-condition[condition='ipv6-next-hop-type']";
  3673. +
  3674. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3675. +
  3676. + return nb_cli_apply_changes(vty, NULL);
  3677. +}
  3678. +
  3679. +DEFPY(
  3680. + match_metric, match_metric_cmd,
  3681. + "match metric (0-4294967295)$metric",
  3682. + MATCH_STR
  3683. + "Match metric of route\n"
  3684. + "Metric value\n")
  3685. +{
  3686. + const char *xpath = "./match-condition[condition='metric']";
  3687. + char xpath_value[XPATH_MAXLEN];
  3688. +
  3689. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3690. + snprintf(xpath_value, sizeof(xpath_value), "%s/metric", xpath);
  3691. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, metric_str);
  3692. +
  3693. + return nb_cli_apply_changes(vty, NULL);
  3694. +}
  3695. +
  3696. +DEFPY(
  3697. + no_match_metric, no_match_metric_cmd,
  3698. + "no match metric [(0-4294967295)]",
  3699. + NO_STR
  3700. + MATCH_STR
  3701. + "Match metric of route\n"
  3702. + "Metric value\n")
  3703. +{
  3704. + const char *xpath = "./match-condition[condition='metric']";
  3705. +
  3706. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3707. +
  3708. + return nb_cli_apply_changes(vty, NULL);
  3709. +}
  3710. +
  3711. +DEFPY(
  3712. + match_tag, match_tag_cmd,
  3713. + "match tag (1-4294967295)$tag",
  3714. + MATCH_STR
  3715. + "Match tag of route\n"
  3716. + "Tag value\n")
  3717. +{
  3718. + const char *xpath = "./match-condition[condition='tag']";
  3719. + char xpath_value[XPATH_MAXLEN];
  3720. +
  3721. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3722. + snprintf(xpath_value, sizeof(xpath_value), "%s/tag", xpath);
  3723. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, tag_str);
  3724. +
  3725. + return nb_cli_apply_changes(vty, NULL);
  3726. +}
  3727. +
  3728. +DEFPY(
  3729. + no_match_tag, no_match_tag_cmd,
  3730. + "no match tag [(1-4294967295)]",
  3731. + NO_STR
  3732. + MATCH_STR
  3733. + "Match tag of route\n"
  3734. + "Tag value\n")
  3735. +{
  3736. + const char *xpath = "./match-condition[condition='tag']";
  3737. +
  3738. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3739. +
  3740. + return nb_cli_apply_changes(vty, NULL);
  3741. +}
  3742. +
  3743. +void route_map_condition_show(struct vty *vty, struct lyd_node *dnode,
  3744. + bool show_defaults)
  3745. +{
  3746. + int condition = yang_dnode_get_enum(dnode, "./condition");
  3747. + struct lyd_node *ln;
  3748. + const char *acl;
  3749. +
  3750. + switch (condition) {
  3751. + case 0: /* interface */
  3752. + vty_out(vty, " match interface %s\n",
  3753. + yang_dnode_get_string(dnode, "./interface"));
  3754. + break;
  3755. + case 1: /* ipv4-address-list */
  3756. + case 3: /* ipv4-next-hop-list */
  3757. + acl = NULL;
  3758. + if ((ln = yang_dnode_get(dnode, "./list-name")) != NULL)
  3759. + acl = yang_dnode_get_string(ln, NULL);
  3760. + else if ((ln = yang_dnode_get(dnode, "./access-list-num"))
  3761. + != NULL)
  3762. + acl = yang_dnode_get_string(ln, NULL);
  3763. + else if ((ln = yang_dnode_get(dnode,
  3764. + "./access-list-num-extended"))
  3765. + != NULL)
  3766. + acl = yang_dnode_get_string(ln, NULL);
  3767. +
  3768. + assert(acl);
  3769. +
  3770. + switch (condition) {
  3771. + case 1:
  3772. + vty_out(vty, " match ip address %s\n", acl);
  3773. + break;
  3774. + case 3:
  3775. + vty_out(vty, " match ip next-hop %s\n", acl);
  3776. + break;
  3777. + }
  3778. + break;
  3779. + case 2: /* ipv4-prefix-list */
  3780. + vty_out(vty, " match ip address prefix-list %s\n",
  3781. + yang_dnode_get_string(dnode, "./list-name"));
  3782. + break;
  3783. + case 4: /* ipv4-next-hop-prefix-list */
  3784. + vty_out(vty, " match ip next-hop prefix-list %s\n",
  3785. + yang_dnode_get_string(dnode, "./list-name"));
  3786. + break;
  3787. + case 5: /* ipv4-next-hop-type */
  3788. + vty_out(vty, " match ip next-hop type %s\n",
  3789. + yang_dnode_get_string(dnode, "./ipv4-next-hop-type"));
  3790. + break;
  3791. + case 6: /* ipv6-address-list */
  3792. + vty_out(vty, " match ipv6 address %s\n",
  3793. + yang_dnode_get_string(dnode, "./list-name"));
  3794. + break;
  3795. + case 7: /* ipv6-prefix-list */
  3796. + vty_out(vty, " match ipv6 address prefix-list %s\n",
  3797. + yang_dnode_get_string(dnode, "./list-name"));
  3798. + break;
  3799. + case 8: /* ipv6-next-hop-type */
  3800. + vty_out(vty, " match ipv6 next-hop type %s\n",
  3801. + yang_dnode_get_string(dnode, "./ipv6-next-hop-type"));
  3802. + break;
  3803. + case 9: /* metric */
  3804. + vty_out(vty, " match metric %s\n",
  3805. + yang_dnode_get_string(dnode, "./metric"));
  3806. + break;
  3807. + case 10: /* tag */
  3808. + vty_out(vty, " match tag %s\n",
  3809. + yang_dnode_get_string(dnode, "./tag"));
  3810. + break;
  3811. + case 100:
  3812. + /* NOTHING: custom field, should be handled by daemon. */
  3813. + break;
  3814. + }
  3815. +}
  3816. +
  3817. +DEFPY(
  3818. + set_ip_nexthop, set_ip_nexthop_cmd,
  3819. + "set ip next-hop A.B.C.D$addr",
  3820. + SET_STR
  3821. + IP_STR
  3822. + "Next hop address\n"
  3823. + "IP address of next hop\n")
  3824. +{
  3825. + const char *xpath = "./set-action[action='ipv4-next-hop']";
  3826. + char xpath_value[XPATH_MAXLEN];
  3827. +
  3828. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3829. + snprintf(xpath_value, sizeof(xpath_value), "%s/ipv4-address", xpath);
  3830. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, addr_str);
  3831. +
  3832. + return nb_cli_apply_changes(vty, NULL);
  3833. +}
  3834. +
  3835. +DEFPY(
  3836. + no_set_ip_nexthop, no_set_ip_nexthop_cmd,
  3837. + "no set ip next-hop [A.B.C.D]",
  3838. + NO_STR
  3839. + SET_STR
  3840. + IP_STR
  3841. + "Next hop address\n"
  3842. + "IP address of next hop\n")
  3843. +{
  3844. + const char *xpath = "./set-action[action='ipv4-next-hop']";
  3845. +
  3846. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3847. +
  3848. + return nb_cli_apply_changes(vty, NULL);
  3849. +}
  3850. +
  3851. +DEFPY(
  3852. + set_ipv6_nexthop_local, set_ipv6_nexthop_local_cmd,
  3853. + "set ipv6 next-hop local X:X::X:X$addr",
  3854. + SET_STR
  3855. + IPV6_STR
  3856. + "IPv6 next-hop address\n"
  3857. + "IPv6 local address\n"
  3858. + "IPv6 address of next hop\n")
  3859. +{
  3860. + const char *xpath = "./set-action[action='ipv6-next-hop']";
  3861. + char xpath_value[XPATH_MAXLEN];
  3862. +
  3863. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3864. + snprintf(xpath_value, sizeof(xpath_value), "%s/ipv6-address", xpath);
  3865. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, addr_str);
  3866. +
  3867. + return nb_cli_apply_changes(vty, NULL);
  3868. +}
  3869. +
  3870. +DEFPY(
  3871. + no_set_ipv6_nexthop_local, no_set_ipv6_nexthop_local_cmd,
  3872. + "no set ipv6 next-hop local [X:X::X:X]",
  3873. + NO_STR
  3874. + SET_STR
  3875. + IPV6_STR
  3876. + "IPv6 next-hop address\n"
  3877. + "IPv6 local address\n"
  3878. + "IPv6 address of next hop\n")
  3879. +{
  3880. + const char *xpath = "./set-action[action='ipv6-next-hop']";
  3881. +
  3882. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3883. +
  3884. + return nb_cli_apply_changes(vty, NULL);
  3885. +}
  3886. +
  3887. +DEFPY(
  3888. + set_metric, set_metric_cmd,
  3889. + "set metric <(0-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt|+metric$ametric|-metric$smetric>",
  3890. + SET_STR
  3891. + "Metric value for destination routing protocol\n"
  3892. + "Metric value\n"
  3893. + "Assign round trip time\n"
  3894. + "Add round trip time\n"
  3895. + "Subtract round trip time\n"
  3896. + "Add metric\n"
  3897. + "Subtract metric\n")
  3898. +{
  3899. + const char *xpath = "./set-action[action='metric']";
  3900. + char xpath_value[XPATH_MAXLEN];
  3901. + char value[64];
  3902. +
  3903. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3904. + if (rtt) {
  3905. + snprintf(xpath_value, sizeof(xpath_value),
  3906. + "%s/use-round-trip-time", xpath);
  3907. + snprintf(value, sizeof(value), "true");
  3908. + } else if (artt) {
  3909. + snprintf(xpath_value, sizeof(xpath_value),
  3910. + "%s/add-round-trip-time", xpath);
  3911. + snprintf(value, sizeof(value), "true");
  3912. + } else if (srtt) {
  3913. + snprintf(xpath_value, sizeof(xpath_value),
  3914. + "%s/subtract-round-trip-time", xpath);
  3915. + snprintf(value, sizeof(value), "true");
  3916. + } else if (ametric) {
  3917. + snprintf(xpath_value, sizeof(xpath_value), "%s/add-metric",
  3918. + xpath);
  3919. + snprintf(value, sizeof(value), "true");
  3920. + } else if (smetric) {
  3921. + snprintf(xpath_value, sizeof(xpath_value), "%s/subtract-metric",
  3922. + xpath);
  3923. + snprintf(value, sizeof(value), "true");
  3924. + } else {
  3925. + snprintf(xpath_value, sizeof(xpath_value), "%s/value", xpath);
  3926. + snprintf(value, sizeof(value), "%lu", metric);
  3927. + }
  3928. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value);
  3929. +
  3930. + return nb_cli_apply_changes(vty, NULL);
  3931. +}
  3932. +
  3933. +DEFPY(
  3934. + no_set_metric, no_set_metric_cmd,
  3935. + "no set metric [(0-4294967295)]",
  3936. + NO_STR
  3937. + SET_STR
  3938. + "Metric value for destination routing protocol\n"
  3939. + "Metric value\n")
  3940. +{
  3941. + const char *xpath = "./set-action[action='metric']";
  3942. +
  3943. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3944. + return nb_cli_apply_changes(vty, NULL);
  3945. +}
  3946. +
  3947. +DEFPY(
  3948. + set_tag, set_tag_cmd,
  3949. + "set tag (1-4294967295)$tag",
  3950. + SET_STR
  3951. + "Tag value for routing protocol\n"
  3952. + "Tag value\n")
  3953. +{
  3954. + const char *xpath = "./set-action[action='tag']";
  3955. + char xpath_value[XPATH_MAXLEN];
  3956. +
  3957. + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
  3958. + snprintf(xpath_value, sizeof(xpath_value), "%s/tag", xpath);
  3959. + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, tag_str);
  3960. +
  3961. + return nb_cli_apply_changes(vty, NULL);
  3962. +}
  3963. +
  3964. +DEFPY(
  3965. + no_set_tag, no_set_tag_cmd,
  3966. + "no set tag [(1-4294967295)]",
  3967. + NO_STR
  3968. + SET_STR
  3969. + "Tag value for routing protocol\n"
  3970. + "Tag value\n")
  3971. +{
  3972. + const char *xpath = "./set-action[action='tag']";
  3973. +
  3974. + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
  3975. +
  3976. + return nb_cli_apply_changes(vty, NULL);
  3977. +}
  3978. +
  3979. +void route_map_action_show(struct vty *vty, struct lyd_node *dnode,
  3980. + bool show_defaults)
  3981. +{
  3982. + int action = yang_dnode_get_enum(dnode, "./action");
  3983. +
  3984. + switch (action) {
  3985. + case 0: /* ipv4-next-hop */
  3986. + vty_out(vty, " set ip next-hop %s\n",
  3987. + yang_dnode_get_string(dnode, "./ipv4-address"));
  3988. + break;
  3989. + case 1: /* ipv6-next-hop */
  3990. + vty_out(vty, " set ipv6 next-hop local %s\n",
  3991. + yang_dnode_get_string(dnode, "./ipv6-address"));
  3992. + break;
  3993. + case 2: /* metric */
  3994. + if (yang_dnode_get(dnode, "./use-round-trip-time")) {
  3995. + vty_out(vty, " set metric rtt\n");
  3996. + } else if (yang_dnode_get(dnode, "./add-round-trip-time")) {
  3997. + vty_out(vty, " set metric +rtt\n");
  3998. + } else if (yang_dnode_get(dnode, "./subtract-round-trip-time")) {
  3999. + vty_out(vty, " set metric -rtt\n");
  4000. + } else if (yang_dnode_get(dnode, "./add-metric")) {
  4001. + vty_out(vty, " set metric +metric\n");
  4002. + } else if (yang_dnode_get(dnode, "./subtract-metric")) {
  4003. + vty_out(vty, " set metric -metric\n");
  4004. + } else {
  4005. + vty_out(vty, " set metric %s\n",
  4006. + yang_dnode_get_string(dnode, "./value"));
  4007. + }
  4008. + break;
  4009. + case 3: /* tag */
  4010. + vty_out(vty, " set tag %s\n",
  4011. + yang_dnode_get_string(dnode, "./tag"));
  4012. + break;
  4013. + case 100:
  4014. + /* NOTHING: custom field, should be handled by daemon. */
  4015. + break;
  4016. + }
  4017. +}
  4018. +
  4019. +DEFPY(
  4020. + rmap_onmatch_next, rmap_onmatch_next_cmd,
  4021. + "on-match next",
  4022. + "Exit policy on matches\n"
  4023. + "Next clause\n")
  4024. +{
  4025. + nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_MODIFY, "next");
  4026. +
  4027. + return nb_cli_apply_changes(vty, NULL);
  4028. +}
  4029. +
  4030. +DEFPY(
  4031. + no_rmap_onmatch_next,
  4032. + no_rmap_onmatch_next_cmd,
  4033. + "no on-match next",
  4034. + NO_STR
  4035. + "Exit policy on matches\n"
  4036. + "Next clause\n")
  4037. +{
  4038. + nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_DESTROY, NULL);
  4039. +
  4040. + return nb_cli_apply_changes(vty, NULL);
  4041. +}
  4042. +
  4043. +DEFPY(
  4044. + rmap_onmatch_goto, rmap_onmatch_goto_cmd,
  4045. + "on-match goto (1-65535)$rm_num",
  4046. + "Exit policy on matches\n"
  4047. + "Goto Clause number\n"
  4048. + "Number\n")
  4049. +{
  4050. + nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_MODIFY, "goto");
  4051. + nb_cli_enqueue_change(vty, "./goto-value", NB_OP_MODIFY, rm_num_str);
  4052. +
  4053. + return nb_cli_apply_changes(vty, NULL);
  4054. +}
  4055. +
  4056. +DEFPY(
  4057. + no_rmap_onmatch_goto, no_rmap_onmatch_goto_cmd,
  4058. + "no on-match goto",
  4059. + NO_STR
  4060. + "Exit policy on matches\n"
  4061. + "Goto Clause number\n")
  4062. +{
  4063. + nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_DESTROY, NULL);
  4064. +
  4065. + return nb_cli_apply_changes(vty, NULL);
  4066. +}
  4067. +
  4068. +/* Cisco/GNU Zebra compatibility aliases */
  4069. +ALIAS(
  4070. + rmap_onmatch_goto, rmap_continue_cmd,
  4071. + "continue (1-65535)$rm_num",
  4072. + "Continue on a different entry within the route-map\n"
  4073. + "Route-map entry sequence number\n")
  4074. +
  4075. +ALIAS(
  4076. + no_rmap_onmatch_goto, no_rmap_continue_cmd,
  4077. + "no continue [(1-65535)]",
  4078. + NO_STR
  4079. + "Continue on a different entry within the route-map\n"
  4080. + "Route-map entry sequence number\n")
  4081. +
  4082. +void route_map_exit_policy_show(struct vty *vty, struct lyd_node *dnode,
  4083. + bool show_defaults)
  4084. +{
  4085. + int exit_policy = yang_dnode_get_enum(dnode, NULL);
  4086. +
  4087. + switch (exit_policy) {
  4088. + case 0: /* permit-or-deny */
  4089. + /* NOTHING: default option. */
  4090. + break;
  4091. + case 1: /* next */
  4092. + vty_out(vty, " on-match next\n");
  4093. + break;
  4094. + case 2: /* goto */
  4095. + vty_out(vty, " on-match goto %s\n",
  4096. + yang_dnode_get_string(dnode, "../goto-value"));
  4097. + break;
  4098. + }
  4099. +}
  4100. +
  4101. +DEFPY(
  4102. + rmap_call, rmap_call_cmd,
  4103. + "call WORD$name",
  4104. + "Jump to another Route-Map after match+set\n"
  4105. + "Target route-map name\n")
  4106. +{
  4107. + nb_cli_enqueue_change(vty, "./call", NB_OP_MODIFY, name);
  4108. +
  4109. + return nb_cli_apply_changes(vty, NULL);
  4110. +}
  4111. +
  4112. +DEFPY(
  4113. + no_rmap_call, no_rmap_call_cmd,
  4114. + "no call",
  4115. + NO_STR
  4116. + "Jump to another Route-Map after match+set\n")
  4117. +{
  4118. + nb_cli_enqueue_change(vty, "./call", NB_OP_DESTROY, NULL);
  4119. +
  4120. + return nb_cli_apply_changes(vty, NULL);
  4121. +}
  4122. +
  4123. +void route_map_call_show(struct vty *vty, struct lyd_node *dnode,
  4124. + bool show_defaults)
  4125. +{
  4126. + vty_out(vty, " call %s\n", yang_dnode_get_string(dnode, NULL));
  4127. +}
  4128. +
  4129. +DEFPY(
  4130. + rmap_description, rmap_description_cmd,
  4131. + "description LINE...",
  4132. + "Route-map comment\n"
  4133. + "Comment describing this route-map rule\n")
  4134. +{
  4135. + char *desc;
  4136. + int rv;
  4137. +
  4138. + desc = argv_concat(argv, argc, 1);
  4139. + nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, desc);
  4140. + rv = nb_cli_apply_changes(vty, NULL);
  4141. + XFREE(MTYPE_TMP, desc);
  4142. +
  4143. + return rv;
  4144. +}
  4145. +
  4146. +DEFUN (no_rmap_description,
  4147. + no_rmap_description_cmd,
  4148. + "no description",
  4149. + NO_STR
  4150. + "Route-map comment\n")
  4151. +{
  4152. + nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
  4153. +
  4154. + return nb_cli_apply_changes(vty, NULL);
  4155. +}
  4156. +
  4157. +void route_map_description_show(struct vty *vty, struct lyd_node *dnode,
  4158. + bool show_defaults)
  4159. +{
  4160. + vty_out(vty, " description %s\n", yang_dnode_get_string(dnode, NULL));
  4161. +}
  4162. +
  4163. +static int route_map_config_write(struct vty *vty)
  4164. +{
  4165. + struct lyd_node *dnode;
  4166. + int written = 0;
  4167. +
  4168. + dnode = yang_dnode_get(running_config->dnode,
  4169. + "/frr-route-map:lib");
  4170. + if (dnode) {
  4171. + nb_cli_show_dnode_cmds(vty, dnode, false);
  4172. + written = 1;
  4173. + }
  4174. +
  4175. + return written;
  4176. +}
  4177. +
  4178. +/* Route map node structure. */
  4179. +static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# ", 1};
  4180. +
  4181. +static void rmap_autocomplete(vector comps, struct cmd_token *token)
  4182. +{
  4183. + struct route_map *map;
  4184. +
  4185. + for (map = route_map_master.head; map; map = map->next)
  4186. + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, map->name));
  4187. +}
  4188. +
  4189. +static const struct cmd_variable_handler rmap_var_handlers[] = {
  4190. + {.varname = "route_map", .completions = rmap_autocomplete},
  4191. + {.tokenname = "ROUTEMAP_NAME", .completions = rmap_autocomplete},
  4192. + {.tokenname = "RMAP_NAME", .completions = rmap_autocomplete},
  4193. + {.completions = NULL}
  4194. +};
  4195. +
  4196. +void route_map_cli_init(void)
  4197. +{
  4198. + /* Auto complete handler. */
  4199. + cmd_variable_handler_register(rmap_var_handlers);
  4200. +
  4201. + /* CLI commands. */
  4202. + install_node(&rmap_node, route_map_config_write);
  4203. + install_default(RMAP_NODE);
  4204. + install_element(CONFIG_NODE, &route_map_cmd);
  4205. + install_element(CONFIG_NODE, &no_route_map_cmd);
  4206. + install_element(CONFIG_NODE, &no_route_map_all_cmd);
  4207. +
  4208. + /* Install the on-match stuff */
  4209. + install_element(RMAP_NODE, &route_map_cmd);
  4210. + install_element(RMAP_NODE, &rmap_onmatch_next_cmd);
  4211. + install_element(RMAP_NODE, &no_rmap_onmatch_next_cmd);
  4212. + install_element(RMAP_NODE, &rmap_onmatch_goto_cmd);
  4213. + install_element(RMAP_NODE, &no_rmap_onmatch_goto_cmd);
  4214. + install_element(RMAP_NODE, &rmap_continue_cmd);
  4215. + install_element(RMAP_NODE, &no_rmap_continue_cmd);
  4216. +
  4217. + /* Install the call stuff. */
  4218. + install_element(RMAP_NODE, &rmap_call_cmd);
  4219. + install_element(RMAP_NODE, &no_rmap_call_cmd);
  4220. +
  4221. + /* Install description commands. */
  4222. + install_element(RMAP_NODE, &rmap_description_cmd);
  4223. + install_element(RMAP_NODE, &no_rmap_description_cmd);
  4224. +
  4225. + /* Install 'match' commands. */
  4226. + install_element(RMAP_NODE, &match_interface_cmd);
  4227. + install_element(RMAP_NODE, &no_match_interface_cmd);
  4228. +
  4229. + install_element(RMAP_NODE, &match_ip_address_cmd);
  4230. + install_element(RMAP_NODE, &no_match_ip_address_cmd);
  4231. +
  4232. + install_element(RMAP_NODE, &match_ip_address_prefix_list_cmd);
  4233. + install_element(RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  4234. +
  4235. + install_element(RMAP_NODE, &match_ip_next_hop_cmd);
  4236. + install_element(RMAP_NODE, &no_match_ip_next_hop_cmd);
  4237. +
  4238. + install_element(RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  4239. + install_element(RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  4240. +
  4241. + install_element(RMAP_NODE, &match_ip_next_hop_type_cmd);
  4242. + install_element(RMAP_NODE, &no_match_ip_next_hop_type_cmd);
  4243. +
  4244. + install_element(RMAP_NODE, &match_ipv6_address_cmd);
  4245. + install_element(RMAP_NODE, &no_match_ipv6_address_cmd);
  4246. +
  4247. + install_element(RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
  4248. + install_element(RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
  4249. +
  4250. + install_element(RMAP_NODE, &match_ipv6_next_hop_type_cmd);
  4251. + install_element(RMAP_NODE, &no_match_ipv6_next_hop_type_cmd);
  4252. +
  4253. + install_element(RMAP_NODE, &match_metric_cmd);
  4254. + install_element(RMAP_NODE, &no_match_metric_cmd);
  4255. +
  4256. + install_element(RMAP_NODE, &match_tag_cmd);
  4257. + install_element(RMAP_NODE, &no_match_tag_cmd);
  4258. +
  4259. + /* Install 'set' commands. */
  4260. + install_element(RMAP_NODE, &set_ip_nexthop_cmd);
  4261. + install_element(RMAP_NODE, &no_set_ip_nexthop_cmd);
  4262. +
  4263. + install_element(RMAP_NODE, &set_ipv6_nexthop_local_cmd);
  4264. + install_element(RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
  4265. +
  4266. + install_element(RMAP_NODE, &set_metric_cmd);
  4267. + install_element(RMAP_NODE, &no_set_metric_cmd);
  4268. +
  4269. + install_element(RMAP_NODE, &set_tag_cmd);
  4270. + install_element(RMAP_NODE, &no_set_tag_cmd);
  4271. +}
  4272. diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
  4273. index 02eb756334..b9ac01e865 100644
  4274. --- a/lib/routemap_northbound.c
  4275. +++ b/lib/routemap_northbound.c
  4276. @@ -1218,6 +1218,8 @@ const struct frr_yang_module_info frr_route_map_info = {
  4277. .cbs = {
  4278. .create = lib_route_map_entry_create,
  4279. .destroy = lib_route_map_entry_destroy,
  4280. + .cli_show = route_map_instance_show,
  4281. + .cli_show_end = route_map_instance_show_end,
  4282. }
  4283. },
  4284. {
  4285. @@ -1225,6 +1227,7 @@ const struct frr_yang_module_info frr_route_map_info = {
  4286. .cbs = {
  4287. .modify = lib_route_map_entry_description_modify,
  4288. .destroy = lib_route_map_entry_description_destroy,
  4289. + .cli_show = route_map_description_show,
  4290. }
  4291. },
  4292. {
  4293. @@ -1238,12 +1241,14 @@ const struct frr_yang_module_info frr_route_map_info = {
  4294. .cbs = {
  4295. .modify = lib_route_map_entry_call_modify,
  4296. .destroy = lib_route_map_entry_call_destroy,
  4297. + .cli_show = route_map_call_show,
  4298. }
  4299. },
  4300. {
  4301. .xpath = "/frr-route-map:lib/route-map/entry/exit-policy",
  4302. .cbs = {
  4303. .modify = lib_route_map_entry_exit_policy_modify,
  4304. + .cli_show = route_map_exit_policy_show,
  4305. }
  4306. },
  4307. {
  4308. @@ -1258,6 +1263,7 @@ const struct frr_yang_module_info frr_route_map_info = {
  4309. .cbs = {
  4310. .create = lib_route_map_entry_match_condition_create,
  4311. .destroy = lib_route_map_entry_match_condition_destroy,
  4312. + .cli_show = route_map_condition_show,
  4313. }
  4314. },
  4315. {
  4316. @@ -1321,6 +1327,7 @@ const struct frr_yang_module_info frr_route_map_info = {
  4317. .cbs = {
  4318. .create = lib_route_map_entry_set_action_create,
  4319. .destroy = lib_route_map_entry_set_action_destroy,
  4320. + .cli_show = route_map_action_show,
  4321. }
  4322. },
  4323. {
  4324. diff --git a/lib/subdir.am b/lib/subdir.am
  4325. index 94b3d933ac..ffac721256 100644
  4326. --- a/lib/subdir.am
  4327. +++ b/lib/subdir.am
  4328. @@ -71,6 +71,7 @@ lib_libfrr_la_SOURCES = \
  4329. lib/qobj.c \
  4330. lib/ringbuf.c \
  4331. lib/routemap.c \
  4332. + lib/routemap_cli.c \
  4333. lib/routemap_northbound.c \
  4334. lib/sbuf.c \
  4335. lib/seqlock.c \
  4336. @@ -122,6 +123,7 @@ vtysh_scan += \
  4337. $(top_srcdir)/lib/nexthop_group.c \
  4338. $(top_srcdir)/lib/plist.c \
  4339. $(top_srcdir)/lib/routemap.c \
  4340. + $(top_srcdir)/lib/routemap_cli.c \
  4341. $(top_srcdir)/lib/vrf.c \
  4342. $(top_srcdir)/lib/vty.c \
  4343. # end
  4344. @@ -141,6 +143,8 @@ lib/nexthop_group_clippy.c: $(CLIPPY_DEPS)
  4345. lib/nexthop_group.lo: lib/nexthop_group_clippy.c
  4346. lib/northbound_cli_clippy.c: $(CLIPPY_DEPS)
  4347. lib/northbound_cli.lo: lib/northbound_cli_clippy.c
  4348. +lib/routemap_cli_clippy.c: $(CLIPPY_DEPS)
  4349. +lib/routemap_cli.lo: lib/routemap_cli_clippy.c
  4350. lib/vty_clippy.c: $(CLIPPY_DEPS)
  4351. lib/vty.lo: lib/vty_clippy.c
  4352. lib/log_vty_clippy.c: $(CLIPPY_DEPS)
  4353. diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in
  4354. index 13413888bf..b7ac0abe02 100755
  4355. --- a/vtysh/extract.pl.in
  4356. +++ b/vtysh/extract.pl.in
  4357. @@ -87,7 +87,7 @@ sub scan_file {
  4358. if ($file =~ /lib\/keychain\.c$/) {
  4359. $protocol = "VTYSH_RIPD|VTYSH_EIGRPD";
  4360. }
  4361. - elsif ($file =~ /lib\/routemap\.c$/) {
  4362. + elsif ($file =~ /lib\/routemap\.c$/ || $file =~ /lib\/routemap_cli\.c$/) {
  4363. $protocol = "VTYSH_RMAP";
  4364. }
  4365. elsif ($file =~ /lib\/vrf\.c$/) {
  4366. From a513824c343971e51603471948c958430b602371 Mon Sep 17 00:00:00 2001
  4367. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4368. Date: Tue, 1 Oct 2019 17:56:16 -0300
  4369. Subject: [PATCH 05/10] yang/lib: add filter model to code
  4370. This fixes a warning on daemons that use route map about filter yang
  4371. model not being included in the binary.
  4372. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4373. ---
  4374. lib/subdir.am | 1 +
  4375. yang/subdir.am | 1 +
  4376. 2 files changed, 2 insertions(+)
  4377. diff --git a/lib/subdir.am b/lib/subdir.am
  4378. index ffac721256..4f62eb2264 100644
  4379. --- a/lib/subdir.am
  4380. +++ b/lib/subdir.am
  4381. @@ -106,6 +106,7 @@ lib_libfrr_la_SOURCES = \
  4382. # end
  4383. nodist_lib_libfrr_la_SOURCES = \
  4384. + yang/frr-filter.yang.c \
  4385. yang/frr-interface.yang.c \
  4386. yang/frr-route-map.yang.c \
  4387. yang/frr-route-types.yang.c \
  4388. diff --git a/yang/subdir.am b/yang/subdir.am
  4389. index 7a15a6a309..c1297dafd5 100644
  4390. --- a/yang/subdir.am
  4391. +++ b/yang/subdir.am
  4392. @@ -19,6 +19,7 @@ EXTRA_DIST += yang/embedmodel.py
  4393. # global symbols :(. Just put it in the daemon. Dynamic libraries.so work
  4394. # without problems, as seen in libfrr.
  4395. +dist_yangmodels_DATA += yang/frr-filter.yang
  4396. dist_yangmodels_DATA += yang/frr-module-translator.yang
  4397. dist_yangmodels_DATA += yang/frr-test-module.yang
  4398. dist_yangmodels_DATA += yang/frr-interface.yang
  4399. From a162869ef0798ef98d756238c6b89108a69f5a5d Mon Sep 17 00:00:00 2001
  4400. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4401. Date: Mon, 30 Sep 2019 15:02:15 -0300
  4402. Subject: [PATCH 06/10] lib: fix route map generic error output
  4403. Two fixes here:
  4404. * Don't attempt to use `vty` pointer in vty;
  4405. * When `vty` is unavailable output to log;
  4406. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4407. ---
  4408. lib/routemap.c | 68 ++++++++++++++++++++++++++++++++++----------------
  4409. 1 file changed, 46 insertions(+), 22 deletions(-)
  4410. diff --git a/lib/routemap.c b/lib/routemap.c
  4411. index e07ad08123..5369fa771f 100644
  4412. --- a/lib/routemap.c
  4413. +++ b/lib/routemap.c
  4414. @@ -308,15 +308,21 @@ int generic_match_add(struct vty *vty, struct route_map_index *index,
  4415. ret = route_map_add_match(index, command, arg, type);
  4416. switch (ret) {
  4417. case RMAP_RULE_MISSING:
  4418. - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4419. + if (vty)
  4420. + vty_out(vty, "%% [%s] Can't find rule.\n",
  4421. + frr_protonameinst);
  4422. + else
  4423. + zlog_warn("Can't find rule: %s", command);
  4424. return CMD_WARNING_CONFIG_FAILED;
  4425. - break;
  4426. case RMAP_COMPILE_ERROR:
  4427. - vty_out(vty,
  4428. - "%% [%s] Argument form is unsupported or malformed.\n",
  4429. - frr_protonameinst);
  4430. + if (vty)
  4431. + vty_out(vty,
  4432. + "%% [%s] Argument form is unsupported or malformed.\n",
  4433. + frr_protonameinst);
  4434. + else
  4435. + zlog_warn("Argument form is unsupported or malformed: "
  4436. + "%s %s", command, arg);
  4437. return CMD_WARNING_CONFIG_FAILED;
  4438. - break;
  4439. case RMAP_COMPILE_SUCCESS:
  4440. /*
  4441. * Nothing to do here move along
  4442. @@ -353,13 +359,21 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index,
  4443. ret = route_map_delete_match(index, command, dep_name, type);
  4444. switch (ret) {
  4445. case RMAP_RULE_MISSING:
  4446. - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4447. + if (vty)
  4448. + vty_out(vty, "%% [%s] Can't find rule.\n",
  4449. + frr_protonameinst);
  4450. + else
  4451. + zlog_warn("Can't find rule: %s", command);
  4452. retval = CMD_WARNING_CONFIG_FAILED;
  4453. break;
  4454. case RMAP_COMPILE_ERROR:
  4455. - vty_out(vty,
  4456. - "%% [%s] Argument form is unsupported or malformed.\n",
  4457. - frr_protonameinst);
  4458. + if (vty)
  4459. + vty_out(vty,
  4460. + "%% [%s] Argument form is unsupported or malformed.\n",
  4461. + frr_protonameinst);
  4462. + else
  4463. + zlog_warn("Argument form is unsupported or malformed: "
  4464. + "%s %s", command, arg);
  4465. retval = CMD_WARNING_CONFIG_FAILED;
  4466. break;
  4467. case RMAP_COMPILE_SUCCESS:
  4468. @@ -383,15 +397,20 @@ int generic_set_add(struct vty *vty, struct route_map_index *index,
  4469. ret = route_map_add_set(index, command, arg);
  4470. switch (ret) {
  4471. case RMAP_RULE_MISSING:
  4472. - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4473. + if (vty)
  4474. + vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4475. + else
  4476. + zlog_warn("Can't find rule: %s", command);
  4477. return CMD_WARNING_CONFIG_FAILED;
  4478. - break;
  4479. case RMAP_COMPILE_ERROR:
  4480. - vty_out(vty,
  4481. - "%% [%s] Argument form is unsupported or malformed.\n",
  4482. - frr_protonameinst);
  4483. + if (vty)
  4484. + vty_out(vty,
  4485. + "%% [%s] Argument form is unsupported or malformed.\n",
  4486. + frr_protonameinst);
  4487. + else
  4488. + zlog_warn("Argument form is unsupported or malformed: "
  4489. + "%s %s", command, arg);
  4490. return CMD_WARNING_CONFIG_FAILED;
  4491. - break;
  4492. case RMAP_COMPILE_SUCCESS:
  4493. break;
  4494. }
  4495. @@ -407,15 +426,20 @@ int generic_set_delete(struct vty *vty, struct route_map_index *index,
  4496. ret = route_map_delete_set(index, command, arg);
  4497. switch (ret) {
  4498. case RMAP_RULE_MISSING:
  4499. - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4500. + if (vty)
  4501. + vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
  4502. + else
  4503. + zlog_warn("Can't find rule: %s", command);
  4504. return CMD_WARNING_CONFIG_FAILED;
  4505. - break;
  4506. case RMAP_COMPILE_ERROR:
  4507. - vty_out(vty,
  4508. - "%% [%s] Argument form is unsupported or malformed.\n",
  4509. - frr_protonameinst);
  4510. + if (vty)
  4511. + vty_out(vty,
  4512. + "%% [%s] Argument form is unsupported or malformed.\n",
  4513. + frr_protonameinst);
  4514. + else
  4515. + zlog_warn("Argument form is unsupported or malformed: "
  4516. + "%s %s", command, arg);
  4517. return CMD_WARNING_CONFIG_FAILED;
  4518. - break;
  4519. case RMAP_COMPILE_SUCCESS:
  4520. break;
  4521. }
  4522. From e324ef433ca611ddf8274015c0b36c8de1fb3075 Mon Sep 17 00:00:00 2001
  4523. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4524. Date: Tue, 1 Oct 2019 15:52:51 -0300
  4525. Subject: [PATCH 07/10] lib: add backward compatibility for route map
  4526. Allow old CLI users to still print their configuration without migrating
  4527. to northbound.
  4528. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4529. ---
  4530. lib/routemap_cli.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-
  4531. 1 file changed, 55 insertions(+), 1 deletion(-)
  4532. diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c
  4533. index 987693c961..7023710564 100644
  4534. --- a/lib/routemap_cli.c
  4535. +++ b/lib/routemap_cli.c
  4536. @@ -46,6 +46,9 @@ DEFPY_NOSH(
  4537. ROUTE_MAP_OP_CMD_STR
  4538. ROUTE_MAP_SEQUENCE_CMD_STR)
  4539. {
  4540. + struct route_map_index *rmi;
  4541. + struct route_map *rm;
  4542. + int action_type;
  4543. char xpath_action[XPATH_MAXLEN + 64];
  4544. char xpath_index[XPATH_MAXLEN + 32];
  4545. char xpath[XPATH_MAXLEN];
  4546. @@ -63,9 +66,16 @@ DEFPY_NOSH(
  4547. nb_cli_enqueue_change(vty, xpath_action, NB_OP_MODIFY, action);
  4548. rv = nb_cli_apply_changes(vty, NULL);
  4549. - if (rv == CMD_SUCCESS)
  4550. + if (rv == CMD_SUCCESS) {
  4551. VTY_PUSH_XPATH(RMAP_NODE, xpath_index);
  4552. + /* Add support for non-migrated route map users. */
  4553. + rm = route_map_get(name);
  4554. + action_type = (action[0] == 'p') ? RMAP_PERMIT : RMAP_DENY;
  4555. + rmi = route_map_index_get(rm, action_type, sequence);
  4556. + VTY_PUSH_CONTEXT(RMAP_NODE, rmi);
  4557. + }
  4558. +
  4559. return rv;
  4560. }
  4561. @@ -105,11 +115,55 @@ DEFPY(
  4562. void route_map_instance_show(struct vty *vty, struct lyd_node *dnode,
  4563. bool show_defaults)
  4564. {
  4565. + const struct route_map_rule *rmr;
  4566. + const struct route_map_index *rmi;
  4567. const char *name = yang_dnode_get_string(dnode, "../name");
  4568. const char *action = yang_dnode_get_string(dnode, "./action");
  4569. const char *sequence = yang_dnode_get_string(dnode, "./sequence");
  4570. vty_out(vty, "route-map %s %s %s\n", name, action, sequence);
  4571. +
  4572. + rmi = nb_running_get_entry(dnode, NULL, false);
  4573. + if (rmi == NULL) {
  4574. + /*
  4575. + * We can't have outdated rules if route map hasn't
  4576. + * been created yet.
  4577. + */
  4578. + return;
  4579. + }
  4580. +
  4581. +#define SKIP_RULE(name) if (strcmp((name), rmr->cmd->str) == 0) continue
  4582. +
  4583. + /* Print route map `match` for old CLI users. */
  4584. + for (rmr = rmi->match_list.head; rmr; rmr = rmr->next) {
  4585. + /* Skip all matches implemented by northbound. */
  4586. + SKIP_RULE("interface");
  4587. + SKIP_RULE("ip address");
  4588. + SKIP_RULE("ip address prefix-list");
  4589. + SKIP_RULE("ip next-hop");
  4590. + SKIP_RULE("ip next-hop prefix-list");
  4591. + SKIP_RULE("ip next-hop type");
  4592. + SKIP_RULE("ipv6 address");
  4593. + SKIP_RULE("ipv6 address prefix-list");
  4594. + SKIP_RULE("ipv6 next-hop type");
  4595. + SKIP_RULE("metric");
  4596. + SKIP_RULE("tag");
  4597. +
  4598. + vty_out(vty, " match %s %s\n", rmr->cmd->str,
  4599. + rmr->rule_str ? rmr->rule_str : "");
  4600. + }
  4601. +
  4602. + /* Print route map `set` for old CLI users. */
  4603. + for (rmr = rmi->set_list.head; rmr; rmr = rmr->next) {
  4604. + /* Skip all sets implemented by northbound. */
  4605. + SKIP_RULE("metric");
  4606. + SKIP_RULE("tag");
  4607. +
  4608. + vty_out(vty, " set %s %s\n", rmr->cmd->str,
  4609. + rmr->rule_str ? rmr->rule_str : "");
  4610. + }
  4611. +
  4612. +#undef SKIP_RULE
  4613. }
  4614. void route_map_instance_show_end(struct vty *vty, struct lyd_node *dnode)
  4615. From 91835f1fd2a8dd05a5ba03c8961b699aaabed7e7 Mon Sep 17 00:00:00 2001
  4616. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4617. Date: Tue, 1 Oct 2019 17:56:41 -0300
  4618. Subject: [PATCH 08/10] *: fix route map integration
  4619. Add the appropriated code to bootstrap route map northbound for all
  4620. daemons.
  4621. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4622. ---
  4623. bgpd/bgp_main.c | 2 ++
  4624. eigrpd/eigrp_main.c | 1 +
  4625. isisd/isis_main.c | 2 ++
  4626. ospf6d/ospf6_main.c | 1 +
  4627. ospfd/ospf_main.c | 2 ++
  4628. ripd/rip_main.c | 2 ++
  4629. ripngd/ripng_main.c | 2 ++
  4630. zebra/main.c | 1 +
  4631. 8 files changed, 13 insertions(+)
  4632. diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
  4633. index fab2a584c0..0b33f7e9d9 100644
  4634. --- a/bgpd/bgp_main.c
  4635. +++ b/bgpd/bgp_main.c
  4636. @@ -360,6 +360,8 @@ static void bgp_vrf_terminate(void)
  4637. }
  4638. static const struct frr_yang_module_info *const bgpd_yang_modules[] = {
  4639. + &frr_interface_info,
  4640. + &frr_route_map_info,
  4641. };
  4642. FRR_DAEMON_INFO(bgpd, BGP, .vty_port = BGP_VTY_PORT,
  4643. diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c
  4644. index 0746b04edb..922c0fe3e7 100644
  4645. --- a/eigrpd/eigrp_main.c
  4646. +++ b/eigrpd/eigrp_main.c
  4647. @@ -140,6 +140,7 @@ struct quagga_signal_t eigrp_signals[] = {
  4648. static const struct frr_yang_module_info *const eigrpd_yang_modules[] = {
  4649. &frr_eigrpd_info,
  4650. &frr_interface_info,
  4651. + &frr_route_map_info,
  4652. };
  4653. FRR_DAEMON_INFO(eigrpd, EIGRP, .vty_port = EIGRP_VTY_PORT,
  4654. diff --git a/isisd/isis_main.c b/isisd/isis_main.c
  4655. index 364441f79d..f7fe089b99 100644
  4656. --- a/isisd/isis_main.c
  4657. +++ b/isisd/isis_main.c
  4658. @@ -39,6 +39,7 @@
  4659. #include "vrf.h"
  4660. #include "qobj.h"
  4661. #include "libfrr.h"
  4662. +#include "routemap.h"
  4663. #include "isisd/isis_constants.h"
  4664. #include "isisd/isis_common.h"
  4665. @@ -166,6 +167,7 @@ static const struct frr_yang_module_info *const isisd_yang_modules[] = {
  4666. #ifndef FABRICD
  4667. &frr_isisd_info,
  4668. #endif /* ifndef FABRICD */
  4669. + &frr_route_map_info,
  4670. };
  4671. #ifdef FABRICD
  4672. diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
  4673. index 0aaefeb3c2..e4bed7a79d 100644
  4674. --- a/ospf6d/ospf6_main.c
  4675. +++ b/ospf6d/ospf6_main.c
  4676. @@ -167,6 +167,7 @@ struct quagga_signal_t ospf6_signals[] = {
  4677. static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
  4678. &frr_interface_info,
  4679. + &frr_route_map_info,
  4680. };
  4681. FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
  4682. diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
  4683. index d02ffe0448..7caa79d207 100644
  4684. --- a/ospfd/ospf_main.c
  4685. +++ b/ospfd/ospf_main.c
  4686. @@ -40,6 +40,7 @@
  4687. #include "zclient.h"
  4688. #include "vrf.h"
  4689. #include "libfrr.h"
  4690. +#include "routemap.h"
  4691. #include "ospfd/ospfd.h"
  4692. #include "ospfd/ospf_interface.h"
  4693. @@ -126,6 +127,7 @@ struct quagga_signal_t ospf_signals[] = {
  4694. static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
  4695. &frr_interface_info,
  4696. + &frr_route_map_info,
  4697. };
  4698. FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
  4699. diff --git a/ripd/rip_main.c b/ripd/rip_main.c
  4700. index 060bb76585..ca41afaea6 100644
  4701. --- a/ripd/rip_main.c
  4702. +++ b/ripd/rip_main.c
  4703. @@ -35,6 +35,7 @@
  4704. #include "vrf.h"
  4705. #include "if_rmap.h"
  4706. #include "libfrr.h"
  4707. +#include "routemap.h"
  4708. #include "ripd/ripd.h"
  4709. #include "ripd/rip_nb.h"
  4710. @@ -115,6 +116,7 @@ static struct quagga_signal_t ripd_signals[] = {
  4711. static const struct frr_yang_module_info *const ripd_yang_modules[] = {
  4712. &frr_interface_info,
  4713. &frr_ripd_info,
  4714. + &frr_route_map_info,
  4715. };
  4716. FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
  4717. diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
  4718. index 9daeeb9580..99adb2cba7 100644
  4719. --- a/ripngd/ripng_main.c
  4720. +++ b/ripngd/ripng_main.c
  4721. @@ -36,6 +36,7 @@
  4722. #include "vrf.h"
  4723. #include "if_rmap.h"
  4724. #include "libfrr.h"
  4725. +#include "routemap.h"
  4726. #include "ripngd/ripngd.h"
  4727. #include "ripngd/ripng_nb.h"
  4728. @@ -115,6 +116,7 @@ struct quagga_signal_t ripng_signals[] = {
  4729. static const struct frr_yang_module_info *const ripngd_yang_modules[] = {
  4730. &frr_interface_info,
  4731. &frr_ripngd_info,
  4732. + &frr_route_map_info,
  4733. };
  4734. FRR_DAEMON_INFO(ripngd, RIPNG, .vty_port = RIPNG_VTY_PORT,
  4735. diff --git a/zebra/main.c b/zebra/main.c
  4736. index f23702d878..5951c7e280 100644
  4737. --- a/zebra/main.c
  4738. +++ b/zebra/main.c
  4739. @@ -237,6 +237,7 @@ struct quagga_signal_t zebra_signals[] = {
  4740. static const struct frr_yang_module_info *const zebra_yang_modules[] = {
  4741. &frr_interface_info,
  4742. + &frr_route_map_info,
  4743. };
  4744. FRR_DAEMON_INFO(
  4745. From 54a35ff48b600cd59b715b6e5aea4e69de1b995f Mon Sep 17 00:00:00 2001
  4746. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4747. Date: Mon, 14 Oct 2019 23:29:19 -0300
  4748. Subject: [PATCH 09/10] lib: fix route map northbound memory leak
  4749. Keep a list of hook contexts used by northbound so we don't lose the
  4750. pointer when free()ing the route map index entry data.
  4751. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4752. ---
  4753. lib/routemap.c | 5 +++++
  4754. lib/routemap.h | 11 +++++++++++
  4755. lib/routemap_northbound.c | 39 ++++++++++++++++++++++++++++++---------
  4756. 3 files changed, 46 insertions(+), 9 deletions(-)
  4757. diff --git a/lib/routemap.c b/lib/routemap.c
  4758. index 5369fa771f..912cf28202 100644
  4759. --- a/lib/routemap.c
  4760. +++ b/lib/routemap.c
  4761. @@ -909,6 +909,7 @@ static struct route_map_index *route_map_index_new(void)
  4762. new = XCALLOC(MTYPE_ROUTE_MAP_INDEX, sizeof(struct route_map_index));
  4763. new->exitpolicy = RMAP_EXIT; /* Default to Cisco-style */
  4764. + TAILQ_INIT(&new->rhclist);
  4765. QOBJ_REG(new, route_map_index);
  4766. return new;
  4767. }
  4768. @@ -924,6 +925,10 @@ void route_map_index_delete(struct route_map_index *index, int notify)
  4769. zlog_debug("Deleting route-map %s sequence %d",
  4770. index->map->name, index->pref);
  4771. + /* Free route map northbound hook contexts. */
  4772. + while (!TAILQ_EMPTY(&index->rhclist))
  4773. + routemap_hook_context_free(TAILQ_FIRST(&index->rhclist));
  4774. +
  4775. /* Free route match. */
  4776. while ((rule = index->match_list.head) != NULL)
  4777. route_map_rule_delete(&index->match_list, rule);
  4778. diff --git a/lib/routemap.h b/lib/routemap.h
  4779. index 70e150c981..05c958967c 100644
  4780. --- a/lib/routemap.h
  4781. +++ b/lib/routemap.h
  4782. @@ -162,6 +162,9 @@ struct route_map_rule_list {
  4783. struct route_map_rule *tail;
  4784. };
  4785. +/* Forward struct declaration: the complete can be found later this file. */
  4786. +struct routemap_hook_context;
  4787. +
  4788. /* Route map index structure. */
  4789. struct route_map_index {
  4790. struct route_map *map;
  4791. @@ -194,6 +197,9 @@ struct route_map_index {
  4792. uint64_t applied;
  4793. uint64_t applied_clear;
  4794. + /* List of match/sets contexts. */
  4795. + TAILQ_HEAD(, routemap_hook_context) rhclist;
  4796. +
  4797. QOBJ_FIELDS
  4798. };
  4799. DECLARE_QOBJ_TYPE(route_map_index)
  4800. @@ -660,6 +666,7 @@ struct routemap_hook_context {
  4801. route_map_event_t rhc_event;
  4802. routemap_set_hook_fun rhc_shook;
  4803. routemap_match_hook_fun rhc_mhook;
  4804. + TAILQ_ENTRY(routemap_hook_context) rhc_entry;
  4805. };
  4806. int lib_route_map_entry_match_destroy(enum nb_event event,
  4807. @@ -667,6 +674,10 @@ int lib_route_map_entry_match_destroy(enum nb_event event,
  4808. int lib_route_map_entry_set_destroy(enum nb_event event,
  4809. const struct lyd_node *dnode);
  4810. +struct routemap_hook_context *
  4811. +routemap_hook_context_insert(struct route_map_index *rmi);
  4812. +void routemap_hook_context_free(struct routemap_hook_context *rhc);
  4813. +
  4814. extern const struct frr_yang_module_info frr_route_map_info;
  4815. /* routemap_cli.c */
  4816. diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
  4817. index b9ac01e865..3173a708e4 100644
  4818. --- a/lib/routemap_northbound.c
  4819. +++ b/lib/routemap_northbound.c
  4820. @@ -74,6 +74,30 @@ int lib_route_map_entry_set_destroy(enum nb_event event,
  4821. return NB_OK;
  4822. }
  4823. +/*
  4824. + * Auxiliary hook context list manipulation functions.
  4825. + */
  4826. +struct routemap_hook_context *
  4827. +routemap_hook_context_insert(struct route_map_index *rmi)
  4828. +{
  4829. + struct routemap_hook_context *rhc;
  4830. +
  4831. + rhc = XCALLOC(MTYPE_TMP, sizeof(*rhc));
  4832. + rhc->rhc_rmi = rmi;
  4833. + TAILQ_INSERT_TAIL(&rmi->rhclist, rhc, rhc_entry);
  4834. +
  4835. + return rhc;
  4836. +}
  4837. +
  4838. +void
  4839. +routemap_hook_context_free(struct routemap_hook_context *rhc)
  4840. +{
  4841. + struct route_map_index *rmi = rhc->rhc_rmi;
  4842. +
  4843. + TAILQ_REMOVE(&rmi->rhclist, rhc, rhc_entry);
  4844. + XFREE(MTYPE_TMP, rhc);
  4845. +}
  4846. +
  4847. /*
  4848. * XPath: /frr-route-map:lib/route-map
  4849. */
  4850. @@ -436,20 +460,17 @@ lib_route_map_entry_match_condition_create(enum nb_event event,
  4851. union nb_resource *resource)
  4852. {
  4853. struct routemap_hook_context *rhc;
  4854. + struct route_map_index *rmi;
  4855. switch (event) {
  4856. case NB_EV_VALIDATE:
  4857. - /* NOTHING */
  4858. - break;
  4859. case NB_EV_PREPARE:
  4860. - resource->ptr = XCALLOC(MTYPE_TMP, sizeof(*rhc));
  4861. - break;
  4862. case NB_EV_ABORT:
  4863. - XFREE(MTYPE_TMP, resource->ptr);
  4864. + /* NOTHING */
  4865. break;
  4866. case NB_EV_APPLY:
  4867. - rhc = resource->ptr;
  4868. - rhc->rhc_rmi = nb_running_get_entry(dnode, NULL, true);
  4869. + rmi = nb_running_get_entry(dnode, NULL, true);
  4870. + rhc = routemap_hook_context_insert(rmi);
  4871. nb_running_set_entry(dnode, rhc);
  4872. break;
  4873. }
  4874. @@ -469,7 +490,7 @@ lib_route_map_entry_match_condition_destroy(enum nb_event event,
  4875. rv = lib_route_map_entry_match_destroy(event, dnode);
  4876. rhc = nb_running_unset_entry(dnode);
  4877. - XFREE(MTYPE_TMP, rhc);
  4878. + routemap_hook_context_free(rhc);
  4879. return rv;
  4880. }
  4881. @@ -893,7 +914,7 @@ static int lib_route_map_entry_set_action_destroy(enum nb_event event,
  4882. rv = lib_route_map_entry_set_destroy(event, dnode);
  4883. rhc = nb_running_unset_entry(dnode);
  4884. - XFREE(MTYPE_TMP, rhc);
  4885. + routemap_hook_context_free(rhc);
  4886. return rv;
  4887. }
  4888. From 79661106763d4f6d9c200a4f4d25439f1cfecf3a Mon Sep 17 00:00:00 2001
  4889. From: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4890. Date: Wed, 5 Feb 2020 11:09:31 -0300
  4891. Subject: [PATCH 10/10] lib: fix route-map YANG module on old gcc versions
  4892. Copy the fix made in 'lib/if.c' to 'lib/routemap_northbound.c' so we can
  4893. have a working YANG model when compiled with GCC version less than 5.
  4894. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  4895. ---
  4896. lib/routemap_northbound.c | 25 +++++++++++++++++++++++++
  4897. 1 file changed, 25 insertions(+)
  4898. diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
  4899. index 3173a708e4..78f2a5a018 100644
  4900. --- a/lib/routemap_northbound.c
  4901. +++ b/lib/routemap_northbound.c
  4902. @@ -1224,7 +1224,32 @@ lib_route_map_entry_set_action_tag_destroy(enum nb_event event,
  4903. }
  4904. /* clang-format off */
  4905. +#if defined(__GNUC__) && ((__GNUC__ - 0) < 5) && !defined(__clang__)
  4906. +/*
  4907. + * gcc versions before 5.x miscalculate the size for structs with variable
  4908. + * length arrays (they just count it as size 0)
  4909. + */
  4910. +struct frr_yang_module_info_sizen {
  4911. + /* YANG module name. */
  4912. + const char *name;
  4913. +
  4914. + /* Northbound callbacks. */
  4915. + const struct {
  4916. + /* Data path of this YANG node. */
  4917. + const char *xpath;
  4918. +
  4919. + /* Callbacks implemented for this node. */
  4920. + struct nb_callbacks cbs;
  4921. +
  4922. + /* Priority - lower priorities are processed first. */
  4923. + uint32_t priority;
  4924. + } nodes[28];
  4925. +};
  4926. +
  4927. +const struct frr_yang_module_info_sizen frr_route_map_info_sizen asm("frr_route_map_info") = {
  4928. +#else
  4929. const struct frr_yang_module_info frr_route_map_info = {
  4930. +#endif
  4931. .name = "frr-route-map",
  4932. .nodes = {
  4933. {