]>
Commit | Line | Data |
---|---|---|
2b3e4807 RZ |
1 | /* |
2 | * Route map northbound CLI implementation. | |
3 | * | |
4 | * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF") | |
5 | * Rafael Zalamena | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA. | |
21 | */ | |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "lib/command.h" | |
26 | #include "lib/northbound_cli.h" | |
27 | #include "lib/routemap.h" | |
28 | ||
29 | #ifndef VTYSH_EXTRACT_PL | |
30 | #include "lib/routemap_cli_clippy.c" | |
31 | #endif /* VTYSH_EXTRACT_PL */ | |
32 | ||
33 | #define ROUTE_MAP_CMD_STR \ | |
34 | "Create route-map or enter route-map command mode\n" \ | |
35 | "Route map tag\n" | |
36 | #define ROUTE_MAP_OP_CMD_STR \ | |
37 | "Route map denies set operations\n" \ | |
38 | "Route map permits set operations\n" | |
39 | #define ROUTE_MAP_SEQUENCE_CMD_STR \ | |
40 | "Sequence to insert to/delete from existing route-map entry\n" | |
41 | ||
ca77b518 | 42 | DEFPY_YANG_NOSH( |
2b3e4807 | 43 | route_map, route_map_cmd, |
8f241168 | 44 | "route-map RMAP_NAME$name <deny|permit>$action (1-65535)$sequence", |
2b3e4807 RZ |
45 | ROUTE_MAP_CMD_STR |
46 | ROUTE_MAP_OP_CMD_STR | |
47 | ROUTE_MAP_SEQUENCE_CMD_STR) | |
48 | { | |
49 | char xpath_action[XPATH_MAXLEN + 64]; | |
50 | char xpath_index[XPATH_MAXLEN + 32]; | |
51 | char xpath[XPATH_MAXLEN]; | |
52 | int rv; | |
53 | ||
54 | snprintf(xpath, sizeof(xpath), | |
55 | "/frr-route-map:lib/route-map[name='%s']", name); | |
56 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
57 | ||
58 | snprintf(xpath_index, sizeof(xpath_index), "%s/entry[sequence='%lu']", | |
59 | xpath, sequence); | |
60 | nb_cli_enqueue_change(vty, xpath_index, NB_OP_CREATE, NULL); | |
61 | ||
62 | snprintf(xpath_action, sizeof(xpath_action), "%s/action", xpath_index); | |
63 | nb_cli_enqueue_change(vty, xpath_action, NB_OP_MODIFY, action); | |
64 | ||
65 | rv = nb_cli_apply_changes(vty, NULL); | |
d5d737a2 | 66 | if (rv == CMD_SUCCESS) |
2b3e4807 RZ |
67 | VTY_PUSH_XPATH(RMAP_NODE, xpath_index); |
68 | ||
69 | return rv; | |
70 | } | |
71 | ||
ca77b518 | 72 | DEFPY_YANG( |
2b3e4807 | 73 | no_route_map_all, no_route_map_all_cmd, |
8f241168 | 74 | "no route-map RMAP_NAME$name", |
2b3e4807 RZ |
75 | NO_STR |
76 | ROUTE_MAP_CMD_STR) | |
77 | { | |
78 | char xpath[XPATH_MAXLEN]; | |
79 | ||
80 | snprintf(xpath, sizeof(xpath), | |
81 | "/frr-route-map:lib/route-map[name='%s']", name); | |
82 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
83 | ||
84 | return nb_cli_apply_changes(vty, NULL); | |
85 | } | |
86 | ||
ca77b518 | 87 | DEFPY_YANG( |
2b3e4807 | 88 | no_route_map, no_route_map_cmd, |
8f241168 | 89 | "no route-map RMAP_NAME$name <deny|permit>$action (1-65535)$sequence", |
2b3e4807 RZ |
90 | NO_STR |
91 | ROUTE_MAP_CMD_STR | |
92 | ROUTE_MAP_OP_CMD_STR | |
93 | ROUTE_MAP_SEQUENCE_CMD_STR) | |
94 | { | |
95 | char xpath[XPATH_MAXLEN]; | |
96 | ||
97 | snprintf(xpath, sizeof(xpath), | |
98 | "/frr-route-map:lib/route-map[name='%s']/entry[sequence='%lu']", | |
99 | name, sequence); | |
d5d737a2 | 100 | |
2b3e4807 RZ |
101 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); |
102 | ||
103 | return nb_cli_apply_changes(vty, NULL); | |
104 | } | |
105 | ||
25605051 IR |
106 | int route_map_instance_cmp(const struct lyd_node *dnode1, |
107 | const struct lyd_node *dnode2) | |
de8936be IR |
108 | { |
109 | uint16_t seq1 = yang_dnode_get_uint16(dnode1, "./sequence"); | |
110 | uint16_t seq2 = yang_dnode_get_uint16(dnode2, "./sequence"); | |
111 | ||
112 | return seq1 - seq2; | |
113 | } | |
114 | ||
25605051 | 115 | void route_map_instance_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
116 | bool show_defaults) |
117 | { | |
118 | const char *name = yang_dnode_get_string(dnode, "../name"); | |
119 | const char *action = yang_dnode_get_string(dnode, "./action"); | |
120 | const char *sequence = yang_dnode_get_string(dnode, "./sequence"); | |
121 | ||
122 | vty_out(vty, "route-map %s %s %s\n", name, action, sequence); | |
e324ef43 | 123 | |
2b3e4807 RZ |
124 | } |
125 | ||
25605051 | 126 | void route_map_instance_show_end(struct vty *vty, const struct lyd_node *dnode) |
2b3e4807 | 127 | { |
07679ad9 | 128 | vty_out(vty, "exit\n"); |
2b3e4807 RZ |
129 | vty_out(vty, "!\n"); |
130 | } | |
131 | ||
ca77b518 | 132 | DEFPY_YANG( |
2b3e4807 RZ |
133 | match_interface, match_interface_cmd, |
134 | "match interface IFNAME", | |
135 | MATCH_STR | |
136 | "Match first hop interface of route\n" | |
137 | INTERFACE_STR) | |
138 | { | |
d5d737a2 SP |
139 | const char *xpath = |
140 | "./match-condition[condition='frr-route-map:interface']"; | |
2b3e4807 RZ |
141 | char xpath_value[XPATH_MAXLEN]; |
142 | ||
143 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
144 | snprintf(xpath_value, sizeof(xpath_value), |
145 | "%s/rmap-match-condition/interface", xpath); | |
2b3e4807 RZ |
146 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ifname); |
147 | ||
148 | return nb_cli_apply_changes(vty, NULL); | |
149 | } | |
150 | ||
ca77b518 | 151 | DEFPY_YANG( |
2b3e4807 RZ |
152 | no_match_interface, no_match_interface_cmd, |
153 | "no match interface [IFNAME]", | |
154 | NO_STR | |
155 | MATCH_STR | |
156 | "Match first hop interface of route\n" | |
157 | INTERFACE_STR) | |
158 | { | |
d5d737a2 SP |
159 | const char *xpath = |
160 | "./match-condition[condition='frr-route-map:interface']"; | |
2b3e4807 RZ |
161 | |
162 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
163 | ||
164 | return nb_cli_apply_changes(vty, NULL); | |
165 | } | |
166 | ||
ca77b518 | 167 | DEFPY_YANG( |
2b3e4807 | 168 | match_ip_address, match_ip_address_cmd, |
c60dec36 | 169 | "match ip address ACCESSLIST4_NAME$name", |
2b3e4807 RZ |
170 | MATCH_STR |
171 | IP_STR | |
172 | "Match address of route\n" | |
2b3e4807 RZ |
173 | "IP Access-list name\n") |
174 | { | |
d5d737a2 SP |
175 | const char *xpath = |
176 | "./match-condition[condition='frr-route-map:ipv4-address-list']"; | |
2b3e4807 | 177 | char xpath_value[XPATH_MAXLEN + 32]; |
2b3e4807 RZ |
178 | |
179 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
180 | snprintf(xpath_value, sizeof(xpath_value), |
181 | "%s/rmap-match-condition/list-name", xpath); | |
375d157f | 182 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
2b3e4807 RZ |
183 | |
184 | return nb_cli_apply_changes(vty, NULL); | |
185 | } | |
186 | ||
ca77b518 | 187 | DEFPY_YANG( |
2b3e4807 | 188 | no_match_ip_address, no_match_ip_address_cmd, |
c60dec36 | 189 | "no match ip address [ACCESSLIST4_NAME]", |
2b3e4807 RZ |
190 | NO_STR |
191 | MATCH_STR | |
192 | IP_STR | |
193 | "Match address of route\n" | |
2b3e4807 RZ |
194 | "IP Access-list name\n") |
195 | { | |
d5d737a2 SP |
196 | const char *xpath = |
197 | "./match-condition[condition='frr-route-map:ipv4-address-list']"; | |
2b3e4807 RZ |
198 | |
199 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
200 | ||
201 | return nb_cli_apply_changes(vty, NULL); | |
202 | } | |
203 | ||
ca77b518 | 204 | DEFPY_YANG( |
2b3e4807 RZ |
205 | match_ip_address_prefix_list, |
206 | match_ip_address_prefix_list_cmd, | |
943224a1 | 207 | "match ip address prefix-list PREFIXLIST_NAME$name", |
2b3e4807 RZ |
208 | MATCH_STR |
209 | IP_STR | |
210 | "Match address of route\n" | |
211 | "Match entries of prefix-lists\n" | |
212 | "IP prefix-list name\n") | |
213 | { | |
d5d737a2 SP |
214 | const char *xpath = |
215 | "./match-condition[condition='frr-route-map:ipv4-prefix-list']"; | |
2b3e4807 RZ |
216 | char xpath_value[XPATH_MAXLEN]; |
217 | ||
218 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
219 | snprintf(xpath_value, sizeof(xpath_value), |
220 | "%s/rmap-match-condition/list-name", xpath); | |
2b3e4807 RZ |
221 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
222 | ||
223 | return nb_cli_apply_changes(vty, NULL); | |
224 | } | |
225 | ||
ca77b518 | 226 | DEFPY_YANG( |
2b3e4807 | 227 | no_match_ip_address_prefix_list, no_match_ip_address_prefix_list_cmd, |
943224a1 | 228 | "no match ip address prefix-list [PREFIXLIST_NAME]", |
2b3e4807 RZ |
229 | NO_STR |
230 | MATCH_STR | |
231 | IP_STR | |
232 | "Match address of route\n" | |
233 | "Match entries of prefix-lists\n" | |
234 | "IP prefix-list name\n") | |
235 | { | |
d5d737a2 SP |
236 | const char *xpath = |
237 | "./match-condition[condition='frr-route-map:ipv4-prefix-list']"; | |
2b3e4807 RZ |
238 | |
239 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
240 | ||
241 | return nb_cli_apply_changes(vty, NULL); | |
242 | } | |
243 | ||
ca77b518 | 244 | DEFPY_YANG( |
2b3e4807 | 245 | match_ip_next_hop, match_ip_next_hop_cmd, |
c60dec36 | 246 | "match ip next-hop ACCESSLIST4_NAME$name", |
2b3e4807 RZ |
247 | MATCH_STR |
248 | IP_STR | |
249 | "Match next-hop address of route\n" | |
2b3e4807 RZ |
250 | "IP Access-list name\n") |
251 | { | |
d5d737a2 SP |
252 | const char *xpath = |
253 | "./match-condition[condition='frr-route-map:ipv4-next-hop-list']"; | |
2b3e4807 | 254 | char xpath_value[XPATH_MAXLEN + 32]; |
2b3e4807 RZ |
255 | |
256 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
257 | snprintf(xpath_value, sizeof(xpath_value), |
258 | "%s/rmap-match-condition/list-name", xpath); | |
375d157f | 259 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
2b3e4807 RZ |
260 | |
261 | return nb_cli_apply_changes(vty, NULL); | |
262 | } | |
263 | ||
ca77b518 | 264 | DEFPY_YANG( |
2b3e4807 | 265 | no_match_ip_next_hop, no_match_ip_next_hop_cmd, |
c60dec36 | 266 | "no match ip next-hop [ACCESSLIST4_NAME]", |
2b3e4807 RZ |
267 | NO_STR |
268 | MATCH_STR | |
269 | IP_STR | |
270 | "Match address of route\n" | |
2b3e4807 RZ |
271 | "IP Access-list name\n") |
272 | { | |
d5d737a2 SP |
273 | const char *xpath = |
274 | "./match-condition[condition='frr-route-map:ipv4-next-hop-list']"; | |
2b3e4807 RZ |
275 | |
276 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
277 | ||
278 | return nb_cli_apply_changes(vty, NULL); | |
279 | } | |
280 | ||
ca77b518 | 281 | DEFPY_YANG( |
2b3e4807 RZ |
282 | match_ip_next_hop_prefix_list, |
283 | match_ip_next_hop_prefix_list_cmd, | |
943224a1 | 284 | "match ip next-hop prefix-list PREFIXLIST_NAME$name", |
2b3e4807 RZ |
285 | MATCH_STR |
286 | IP_STR | |
287 | "Match next-hop address of route\n" | |
288 | "Match entries of prefix-lists\n" | |
289 | "IP prefix-list name\n") | |
290 | { | |
291 | const char *xpath = | |
d5d737a2 | 292 | "./match-condition[condition='frr-route-map:ipv4-next-hop-prefix-list']"; |
2b3e4807 RZ |
293 | char xpath_value[XPATH_MAXLEN]; |
294 | ||
295 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
296 | snprintf(xpath_value, sizeof(xpath_value), |
297 | "%s/rmap-match-condition/list-name", xpath); | |
2b3e4807 RZ |
298 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
299 | ||
300 | return nb_cli_apply_changes(vty, NULL); | |
301 | } | |
302 | ||
ca77b518 | 303 | DEFPY_YANG( |
2b3e4807 RZ |
304 | no_match_ip_next_hop_prefix_list, |
305 | no_match_ip_next_hop_prefix_list_cmd, | |
943224a1 | 306 | "no match ip next-hop prefix-list [PREFIXLIST_NAME]", |
2b3e4807 RZ |
307 | NO_STR |
308 | MATCH_STR | |
309 | IP_STR | |
310 | "Match next-hop address of route\n" | |
311 | "Match entries of prefix-lists\n" | |
312 | "IP prefix-list name\n") | |
313 | { | |
314 | const char *xpath = | |
d5d737a2 | 315 | "./match-condition[condition='frr-route-map:ipv4-next-hop-prefix-list']"; |
2b3e4807 RZ |
316 | |
317 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
318 | ||
319 | return nb_cli_apply_changes(vty, NULL); | |
320 | } | |
321 | ||
ca77b518 | 322 | DEFPY_YANG( |
2b3e4807 RZ |
323 | match_ip_next_hop_type, match_ip_next_hop_type_cmd, |
324 | "match ip next-hop type <blackhole>$type", | |
325 | MATCH_STR | |
326 | IP_STR | |
327 | "Match next-hop address of route\n" | |
328 | "Match entries by type\n" | |
329 | "Blackhole\n") | |
330 | { | |
d5d737a2 SP |
331 | const char *xpath = |
332 | "./match-condition[condition='frr-route-map:ipv4-next-hop-type']"; | |
2b3e4807 RZ |
333 | char xpath_value[XPATH_MAXLEN]; |
334 | ||
335 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
336 | snprintf(xpath_value, sizeof(xpath_value), |
337 | "%s/rmap-match-condition/ipv4-next-hop-type", xpath); | |
2b3e4807 RZ |
338 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, type); |
339 | ||
340 | return nb_cli_apply_changes(vty, NULL); | |
341 | } | |
342 | ||
ca77b518 | 343 | DEFPY_YANG( |
2b3e4807 RZ |
344 | no_match_ip_next_hop_type, no_match_ip_next_hop_type_cmd, |
345 | "no match ip next-hop type [<blackhole>]", | |
346 | NO_STR MATCH_STR IP_STR | |
347 | "Match next-hop address of route\n" | |
348 | "Match entries by type\n" | |
349 | "Blackhole\n") | |
350 | { | |
d5d737a2 SP |
351 | const char *xpath = |
352 | "./match-condition[condition='frr-route-map:ipv4-next-hop-type']"; | |
2b3e4807 RZ |
353 | |
354 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
355 | ||
356 | return nb_cli_apply_changes(vty, NULL); | |
357 | } | |
358 | ||
ca77b518 | 359 | DEFPY_YANG( |
2b3e4807 | 360 | match_ipv6_address, match_ipv6_address_cmd, |
c60dec36 | 361 | "match ipv6 address ACCESSLIST6_NAME$name", |
2b3e4807 RZ |
362 | MATCH_STR |
363 | IPV6_STR | |
364 | "Match IPv6 address of route\n" | |
365 | "IPv6 access-list name\n") | |
366 | { | |
d5d737a2 SP |
367 | const char *xpath = |
368 | "./match-condition[condition='frr-route-map:ipv6-address-list']"; | |
2b3e4807 RZ |
369 | char xpath_value[XPATH_MAXLEN]; |
370 | ||
371 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
372 | snprintf(xpath_value, sizeof(xpath_value), |
373 | "%s/rmap-match-condition/list-name", xpath); | |
2b3e4807 RZ |
374 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
375 | ||
376 | return nb_cli_apply_changes(vty, NULL); | |
377 | } | |
378 | ||
ca77b518 | 379 | DEFPY_YANG( |
2b3e4807 | 380 | no_match_ipv6_address, no_match_ipv6_address_cmd, |
c60dec36 | 381 | "no match ipv6 address [ACCESSLIST6_NAME]", |
2b3e4807 RZ |
382 | NO_STR |
383 | MATCH_STR | |
384 | IPV6_STR | |
385 | "Match IPv6 address of route\n" | |
386 | "IPv6 access-list name\n") | |
387 | { | |
d5d737a2 SP |
388 | const char *xpath = |
389 | "./match-condition[condition='frr-route-map:ipv6-address-list']"; | |
2b3e4807 RZ |
390 | |
391 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
392 | ||
393 | return nb_cli_apply_changes(vty, NULL); | |
394 | } | |
395 | ||
ca77b518 | 396 | DEFPY_YANG( |
2b3e4807 | 397 | match_ipv6_address_prefix_list, match_ipv6_address_prefix_list_cmd, |
943224a1 | 398 | "match ipv6 address prefix-list PREFIXLIST_NAME$name", |
2b3e4807 RZ |
399 | MATCH_STR |
400 | IPV6_STR | |
401 | "Match address of route\n" | |
402 | "Match entries of prefix-lists\n" | |
403 | "IP prefix-list name\n") | |
404 | { | |
d5d737a2 SP |
405 | const char *xpath = |
406 | "./match-condition[condition='frr-route-map:ipv6-prefix-list']"; | |
2b3e4807 RZ |
407 | char xpath_value[XPATH_MAXLEN]; |
408 | ||
409 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
410 | snprintf(xpath_value, sizeof(xpath_value), |
411 | "%s/rmap-match-condition/list-name", xpath); | |
2b3e4807 RZ |
412 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name); |
413 | ||
414 | return nb_cli_apply_changes(vty, NULL); | |
415 | } | |
416 | ||
ca77b518 | 417 | DEFPY_YANG( |
2b3e4807 RZ |
418 | no_match_ipv6_address_prefix_list, |
419 | no_match_ipv6_address_prefix_list_cmd, | |
943224a1 | 420 | "no match ipv6 address prefix-list [PREFIXLIST_NAME]", |
2b3e4807 RZ |
421 | NO_STR |
422 | MATCH_STR | |
423 | IPV6_STR | |
424 | "Match address of route\n" | |
425 | "Match entries of prefix-lists\n" | |
426 | "IP prefix-list name\n") | |
427 | { | |
d5d737a2 SP |
428 | const char *xpath = |
429 | "./match-condition[condition='frr-route-map:ipv6-prefix-list']"; | |
2b3e4807 RZ |
430 | |
431 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
432 | ||
433 | return nb_cli_apply_changes(vty, NULL); | |
434 | } | |
435 | ||
ca77b518 | 436 | DEFPY_YANG( |
2b3e4807 RZ |
437 | match_ipv6_next_hop_type, match_ipv6_next_hop_type_cmd, |
438 | "match ipv6 next-hop type <blackhole>$type", | |
439 | MATCH_STR IPV6_STR | |
440 | "Match next-hop address of route\n" | |
441 | "Match entries by type\n" | |
442 | "Blackhole\n") | |
443 | { | |
d5d737a2 SP |
444 | const char *xpath = |
445 | "./match-condition[condition='frr-route-map:ipv6-next-hop-type']"; | |
2b3e4807 RZ |
446 | char xpath_value[XPATH_MAXLEN]; |
447 | ||
448 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
449 | snprintf(xpath_value, sizeof(xpath_value), |
450 | "%s/rmap-match-condition/ipv6-next-hop-type", xpath); | |
2b3e4807 RZ |
451 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, type); |
452 | ||
453 | return nb_cli_apply_changes(vty, NULL); | |
454 | } | |
455 | ||
ca77b518 | 456 | DEFPY_YANG( |
2b3e4807 RZ |
457 | no_match_ipv6_next_hop_type, no_match_ipv6_next_hop_type_cmd, |
458 | "no match ipv6 next-hop type [<blackhole>]", | |
459 | NO_STR MATCH_STR IPV6_STR | |
460 | "Match address of route\n" | |
461 | "Match entries by type\n" | |
462 | "Blackhole\n") | |
463 | { | |
d5d737a2 SP |
464 | const char *xpath = |
465 | "./match-condition[condition='frr-route-map:ipv6-next-hop-type']"; | |
2b3e4807 RZ |
466 | |
467 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
468 | ||
469 | return nb_cli_apply_changes(vty, NULL); | |
470 | } | |
471 | ||
ca77b518 | 472 | DEFPY_YANG( |
2b3e4807 RZ |
473 | match_metric, match_metric_cmd, |
474 | "match metric (0-4294967295)$metric", | |
475 | MATCH_STR | |
476 | "Match metric of route\n" | |
477 | "Metric value\n") | |
478 | { | |
d5d737a2 SP |
479 | const char *xpath = |
480 | "./match-condition[condition='frr-route-map:match-metric']"; | |
2b3e4807 RZ |
481 | char xpath_value[XPATH_MAXLEN]; |
482 | ||
483 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
484 | snprintf(xpath_value, sizeof(xpath_value), |
485 | "%s/rmap-match-condition/metric", xpath); | |
2b3e4807 RZ |
486 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, metric_str); |
487 | ||
488 | return nb_cli_apply_changes(vty, NULL); | |
489 | } | |
490 | ||
ca77b518 | 491 | DEFPY_YANG( |
2b3e4807 RZ |
492 | no_match_metric, no_match_metric_cmd, |
493 | "no match metric [(0-4294967295)]", | |
494 | NO_STR | |
495 | MATCH_STR | |
496 | "Match metric of route\n" | |
497 | "Metric value\n") | |
498 | { | |
d5d737a2 SP |
499 | const char *xpath = |
500 | "./match-condition[condition='frr-route-map:match-metric']"; | |
2b3e4807 RZ |
501 | |
502 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
503 | ||
504 | return nb_cli_apply_changes(vty, NULL); | |
505 | } | |
506 | ||
ca77b518 | 507 | DEFPY_YANG( |
2b3e4807 RZ |
508 | match_tag, match_tag_cmd, |
509 | "match tag (1-4294967295)$tag", | |
510 | MATCH_STR | |
511 | "Match tag of route\n" | |
512 | "Tag value\n") | |
513 | { | |
d5d737a2 SP |
514 | const char *xpath = |
515 | "./match-condition[condition='frr-route-map:match-tag']"; | |
2b3e4807 RZ |
516 | char xpath_value[XPATH_MAXLEN]; |
517 | ||
518 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
519 | snprintf(xpath_value, sizeof(xpath_value), |
520 | "%s/rmap-match-condition/tag", xpath); | |
2b3e4807 RZ |
521 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, tag_str); |
522 | ||
523 | return nb_cli_apply_changes(vty, NULL); | |
524 | } | |
525 | ||
ca77b518 | 526 | DEFPY_YANG( |
2b3e4807 RZ |
527 | no_match_tag, no_match_tag_cmd, |
528 | "no match tag [(1-4294967295)]", | |
529 | NO_STR | |
530 | MATCH_STR | |
531 | "Match tag of route\n" | |
532 | "Tag value\n") | |
533 | { | |
d5d737a2 SP |
534 | const char *xpath = |
535 | "./match-condition[condition='frr-route-map:match-tag']"; | |
2b3e4807 RZ |
536 | |
537 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
538 | ||
539 | return nb_cli_apply_changes(vty, NULL); | |
540 | } | |
541 | ||
25605051 | 542 | void route_map_condition_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
543 | bool show_defaults) |
544 | { | |
d5d737a2 | 545 | const char *condition = yang_dnode_get_string(dnode, "./condition"); |
25605051 | 546 | const struct lyd_node *ln; |
d5d737a2 | 547 | const char *acl; |
2b3e4807 | 548 | |
d5d737a2 | 549 | if (IS_MATCH_INTERFACE(condition)) { |
2b3e4807 | 550 | vty_out(vty, " match interface %s\n", |
d5d737a2 SP |
551 | yang_dnode_get_string( |
552 | dnode, "./rmap-match-condition/interface")); | |
553 | } else if (IS_MATCH_IPv4_ADDRESS_LIST(condition) | |
bc63ba98 | 554 | || IS_MATCH_IPv6_NEXTHOP_LIST(condition) |
d5d737a2 SP |
555 | || IS_MATCH_IPv4_NEXTHOP_LIST(condition)) { |
556 | acl = NULL; | |
557 | if ((ln = yang_dnode_get(dnode, | |
558 | "./rmap-match-condition/list-name")) | |
559 | != NULL) | |
560 | acl = yang_dnode_get_string(ln, NULL); | |
561 | ||
562 | assert(acl); | |
563 | ||
564 | if (IS_MATCH_IPv4_ADDRESS_LIST(condition)) | |
565 | vty_out(vty, " match ip address %s\n", acl); | |
bc63ba98 | 566 | else if (IS_MATCH_IPv4_NEXTHOP_LIST(condition)) |
d5d737a2 | 567 | vty_out(vty, " match ip next-hop %s\n", acl); |
bc63ba98 DA |
568 | else |
569 | vty_out(vty, " match ipv6 next-hop %s\n", acl); | |
d5d737a2 | 570 | } else if (IS_MATCH_IPv4_PREFIX_LIST(condition)) { |
2b3e4807 | 571 | vty_out(vty, " match ip address prefix-list %s\n", |
d5d737a2 SP |
572 | yang_dnode_get_string( |
573 | dnode, "./rmap-match-condition/list-name")); | |
574 | } else if (IS_MATCH_IPv4_NEXTHOP_PREFIX_LIST(condition)) { | |
2b3e4807 | 575 | vty_out(vty, " match ip next-hop prefix-list %s\n", |
d5d737a2 SP |
576 | yang_dnode_get_string( |
577 | dnode, "./rmap-match-condition/list-name")); | |
82f191a2 DA |
578 | } else if (IS_MATCH_IPv6_NEXTHOP_PREFIX_LIST(condition)) { |
579 | vty_out(vty, " match ipv6 next-hop prefix-list %s\n", | |
580 | yang_dnode_get_string( | |
581 | dnode, "./rmap-match-condition/list-name")); | |
d5d737a2 | 582 | } else if (IS_MATCH_IPv6_ADDRESS_LIST(condition)) { |
2b3e4807 | 583 | vty_out(vty, " match ipv6 address %s\n", |
d5d737a2 SP |
584 | yang_dnode_get_string( |
585 | dnode, "./rmap-match-condition/list-name")); | |
586 | } else if (IS_MATCH_IPv6_PREFIX_LIST(condition)) { | |
2b3e4807 | 587 | vty_out(vty, " match ipv6 address prefix-list %s\n", |
d5d737a2 SP |
588 | yang_dnode_get_string( |
589 | dnode, "./rmap-match-condition/list-name")); | |
590 | } else if (IS_MATCH_IPv4_NEXTHOP_TYPE(condition)) { | |
591 | vty_out(vty, " match ip next-hop type %s\n", | |
592 | yang_dnode_get_string( | |
593 | dnode, | |
594 | "./rmap-match-condition/ipv4-next-hop-type")); | |
595 | } else if (IS_MATCH_IPv6_NEXTHOP_TYPE(condition)) { | |
2b3e4807 | 596 | vty_out(vty, " match ipv6 next-hop type %s\n", |
d5d737a2 SP |
597 | yang_dnode_get_string( |
598 | dnode, | |
599 | "./rmap-match-condition/ipv6-next-hop-type")); | |
600 | } else if (IS_MATCH_METRIC(condition)) { | |
2b3e4807 | 601 | vty_out(vty, " match metric %s\n", |
d5d737a2 SP |
602 | yang_dnode_get_string(dnode, |
603 | "./rmap-match-condition/metric")); | |
604 | } else if (IS_MATCH_TAG(condition)) { | |
2b3e4807 | 605 | vty_out(vty, " match tag %s\n", |
d5d737a2 SP |
606 | yang_dnode_get_string(dnode, |
607 | "./rmap-match-condition/tag")); | |
608 | } else if (IS_MATCH_IPv4_PREFIX_LEN(condition)) { | |
f42cc965 | 609 | vty_out(vty, " match ip address prefix-len %s\n", |
d5d737a2 SP |
610 | yang_dnode_get_string( |
611 | dnode, | |
612 | "./rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length")); | |
613 | } else if (IS_MATCH_IPv6_PREFIX_LEN(condition)) { | |
f42cc965 | 614 | vty_out(vty, " match ipv6 address prefix-len %s\n", |
d5d737a2 SP |
615 | yang_dnode_get_string( |
616 | dnode, | |
617 | "./rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length")); | |
618 | } else if (IS_MATCH_IPv4_NH_PREFIX_LEN(condition)) { | |
f42cc965 | 619 | vty_out(vty, " match ip next-hop prefix-len %s\n", |
d5d737a2 SP |
620 | yang_dnode_get_string( |
621 | dnode, | |
622 | "./rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length")); | |
623 | } else if (IS_MATCH_SRC_PROTO(condition)) { | |
f42cc965 | 624 | vty_out(vty, " match source-protocol %s\n", |
d5d737a2 SP |
625 | yang_dnode_get_string( |
626 | dnode, | |
627 | "./rmap-match-condition/frr-zebra-route-map:source-protocol")); | |
628 | } else if (IS_MATCH_SRC_INSTANCE(condition)) { | |
f42cc965 | 629 | vty_out(vty, " match source-instance %s\n", |
d5d737a2 SP |
630 | yang_dnode_get_string( |
631 | dnode, | |
632 | "./rmap-match-condition/frr-zebra-route-map:source-instance")); | |
633 | } else if (IS_MATCH_LOCAL_PREF(condition)) { | |
634 | vty_out(vty, " match local-preference %s\n", | |
635 | yang_dnode_get_string( | |
636 | dnode, | |
637 | "./rmap-match-condition/frr-bgp-route-map:local-preference")); | |
2690f18c DA |
638 | } else if (IS_MATCH_ALIAS(condition)) { |
639 | vty_out(vty, " match alias %s\n", | |
640 | yang_dnode_get_string( | |
641 | dnode, | |
642 | "./rmap-match-condition/frr-bgp-route-map:alias")); | |
d5d737a2 SP |
643 | } else if (IS_MATCH_ORIGIN(condition)) { |
644 | vty_out(vty, " match origin %s\n", | |
645 | yang_dnode_get_string( | |
646 | dnode, | |
647 | "./rmap-match-condition/frr-bgp-route-map:origin")); | |
648 | } else if (IS_MATCH_RPKI(condition)) { | |
649 | vty_out(vty, " match rpki %s\n", | |
650 | yang_dnode_get_string( | |
651 | dnode, | |
652 | "./rmap-match-condition/frr-bgp-route-map:rpki")); | |
653 | } else if (IS_MATCH_PROBABILITY(condition)) { | |
654 | vty_out(vty, " match probability %s\n", | |
655 | yang_dnode_get_string( | |
656 | dnode, | |
657 | "./rmap-match-condition/frr-bgp-route-map:probability")); | |
658 | } else if (IS_MATCH_SRC_VRF(condition)) { | |
659 | vty_out(vty, " match source-vrf %s\n", | |
660 | yang_dnode_get_string( | |
661 | dnode, | |
662 | "./rmap-match-condition/frr-bgp-route-map:source-vrf")); | |
663 | } else if (IS_MATCH_PEER(condition)) { | |
664 | acl = NULL; | |
665 | if ((ln = yang_dnode_get( | |
666 | dnode, | |
667 | "./rmap-match-condition/frr-bgp-route-map:peer-ipv4-address")) | |
668 | != NULL) | |
669 | acl = yang_dnode_get_string(ln, NULL); | |
670 | else if ( | |
671 | (ln = yang_dnode_get( | |
672 | dnode, | |
673 | "./rmap-match-condition/frr-bgp-route-map:peer-ipv6-address")) | |
674 | != NULL) | |
675 | acl = yang_dnode_get_string(ln, NULL); | |
676 | else if ( | |
677 | (ln = yang_dnode_get( | |
678 | dnode, | |
679 | "./rmap-match-condition/frr-bgp-route-map:peer-interface")) | |
680 | != NULL) | |
681 | acl = yang_dnode_get_string(ln, NULL); | |
682 | else if (yang_dnode_get( | |
683 | dnode, | |
684 | "./rmap-match-condition/frr-bgp-route-map:peer-local") | |
685 | != NULL) | |
686 | acl = "local"; | |
687 | ||
688 | vty_out(vty, " match peer %s\n", acl); | |
689 | } else if (IS_MATCH_AS_LIST(condition)) { | |
690 | vty_out(vty, " match as-path %s\n", | |
691 | yang_dnode_get_string( | |
692 | dnode, | |
693 | "./rmap-match-condition/frr-bgp-route-map:list-name")); | |
694 | } else if (IS_MATCH_EVPN_ROUTE_TYPE(condition)) { | |
695 | vty_out(vty, " match evpn route-type %s\n", | |
696 | yang_dnode_get_string( | |
697 | dnode, | |
698 | "./rmap-match-condition/frr-bgp-route-map:evpn-route-type")); | |
699 | } else if (IS_MATCH_EVPN_DEFAULT_ROUTE(condition)) { | |
700 | vty_out(vty, " match evpn default-route\n"); | |
701 | } else if (IS_MATCH_EVPN_VNI(condition)) { | |
702 | vty_out(vty, " match evpn vni %s\n", | |
703 | yang_dnode_get_string( | |
704 | dnode, | |
705 | "./rmap-match-condition/frr-bgp-route-map:evpn-vni")); | |
706 | } else if (IS_MATCH_EVPN_DEFAULT_ROUTE(condition)) { | |
707 | vty_out(vty, " match evpn default-route %s\n", | |
708 | yang_dnode_get_string( | |
709 | dnode, | |
710 | "./rmap-match-condition/frr-bgp-route-map:evpn-default-route")); | |
711 | } else if (IS_MATCH_EVPN_RD(condition)) { | |
712 | vty_out(vty, " match evpn rd %s\n", | |
713 | yang_dnode_get_string( | |
714 | dnode, | |
715 | "./rmap-match-condition/frr-bgp-route-map:route-distinguisher")); | |
716 | } else if (IS_MATCH_MAC_LIST(condition)) { | |
717 | vty_out(vty, " match mac address %s\n", | |
718 | yang_dnode_get_string( | |
719 | dnode, | |
720 | "./rmap-match-condition/frr-bgp-route-map:list-name")); | |
721 | } else if (IS_MATCH_ROUTE_SRC(condition)) { | |
722 | acl = NULL; | |
723 | if ((ln = yang_dnode_get( | |
724 | dnode, | |
725 | "./rmap-match-condition/frr-bgp-route-map:list-name")) | |
726 | != NULL) | |
727 | acl = yang_dnode_get_string(ln, NULL); | |
728 | ||
729 | assert(acl); | |
730 | ||
731 | vty_out(vty, " match ip route-source %s\n", acl); | |
732 | } else if (IS_MATCH_ROUTE_SRC_PL(condition)) { | |
733 | vty_out(vty, " match ip route-source prefix-list %s\n", | |
734 | yang_dnode_get_string( | |
735 | dnode, | |
736 | "./rmap-match-condition/frr-bgp-route-map:list-name")); | |
737 | } else if (IS_MATCH_ROUTE_SRC(condition)) { | |
738 | acl = NULL; | |
739 | if ((ln = yang_dnode_get( | |
740 | dnode, | |
741 | "./rmap-match-condition/frr-bgp-route-map:list-name")) | |
742 | != NULL) | |
743 | acl = yang_dnode_get_string(ln, NULL); | |
744 | ||
745 | assert(acl); | |
746 | ||
747 | vty_out(vty, " match ip route-source %s\n", acl); | |
748 | } else if (IS_MATCH_COMMUNITY(condition)) { | |
749 | acl = NULL; | |
750 | if ((ln = yang_dnode_get( | |
751 | dnode, | |
752 | "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name")) | |
753 | != NULL) { | |
754 | acl = yang_dnode_get_string(ln, NULL); | |
755 | ||
756 | if (true | |
757 | == yang_dnode_get_bool( | |
758 | dnode, | |
759 | "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match")) | |
760 | vty_out(vty, | |
761 | " match community %s exact-match\n", | |
762 | acl); | |
763 | else | |
764 | vty_out(vty, " match community %s\n", acl); | |
765 | } | |
766 | ||
767 | assert(acl); | |
768 | } else if (IS_MATCH_LCOMMUNITY(condition)) { | |
769 | acl = NULL; | |
770 | if ((ln = yang_dnode_get( | |
771 | dnode, | |
772 | "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name")) | |
773 | != NULL) { | |
774 | acl = yang_dnode_get_string(ln, NULL); | |
775 | ||
776 | if (true | |
777 | == yang_dnode_get_bool( | |
778 | dnode, | |
779 | "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match")) | |
780 | vty_out(vty, | |
781 | " match large-community %s exact-match\n", | |
782 | acl); | |
783 | else | |
784 | vty_out(vty, " match large-community %s\n", | |
785 | acl); | |
786 | } | |
787 | ||
788 | assert(acl); | |
789 | } else if (IS_MATCH_EXTCOMMUNITY(condition)) { | |
790 | acl = NULL; | |
791 | if ((ln = yang_dnode_get( | |
792 | dnode, | |
793 | "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name")) | |
794 | != NULL) | |
795 | acl = yang_dnode_get_string(ln, NULL); | |
796 | ||
797 | assert(acl); | |
798 | ||
799 | vty_out(vty, " match extcommunity %s\n", acl); | |
800 | } else if (IS_MATCH_IPV4_NH(condition)) { | |
03030106 | 801 | vty_out(vty, " match ip next-hop address %s\n", |
d5d737a2 SP |
802 | yang_dnode_get_string( |
803 | dnode, | |
804 | "./rmap-match-condition/frr-bgp-route-map:ipv4-address")); | |
805 | } else if (IS_MATCH_IPV6_NH(condition)) { | |
03030106 | 806 | vty_out(vty, " match ipv6 next-hop address %s\n", |
d5d737a2 SP |
807 | yang_dnode_get_string( |
808 | dnode, | |
809 | "./rmap-match-condition/frr-bgp-route-map:ipv6-address")); | |
2b3e4807 RZ |
810 | } |
811 | } | |
812 | ||
ca77b518 | 813 | DEFPY_YANG( |
2b3e4807 RZ |
814 | set_ip_nexthop, set_ip_nexthop_cmd, |
815 | "set ip next-hop A.B.C.D$addr", | |
816 | SET_STR | |
817 | IP_STR | |
818 | "Next hop address\n" | |
819 | "IP address of next hop\n") | |
820 | { | |
d5d737a2 SP |
821 | const char *xpath = |
822 | "./set-action[action='frr-route-map:ipv4-next-hop']"; | |
2b3e4807 RZ |
823 | char xpath_value[XPATH_MAXLEN]; |
824 | ||
825 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
826 | snprintf(xpath_value, sizeof(xpath_value), |
827 | "%s/rmap-set-action/ipv4-address", xpath); | |
2b3e4807 RZ |
828 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, addr_str); |
829 | ||
830 | return nb_cli_apply_changes(vty, NULL); | |
831 | } | |
832 | ||
ca77b518 | 833 | DEFPY_YANG( |
2b3e4807 RZ |
834 | no_set_ip_nexthop, no_set_ip_nexthop_cmd, |
835 | "no set ip next-hop [A.B.C.D]", | |
836 | NO_STR | |
837 | SET_STR | |
838 | IP_STR | |
839 | "Next hop address\n" | |
840 | "IP address of next hop\n") | |
841 | { | |
d5d737a2 SP |
842 | const char *xpath = |
843 | "./set-action[action='frr-route-map:ipv4-next-hop']"; | |
2b3e4807 RZ |
844 | |
845 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
846 | ||
847 | return nb_cli_apply_changes(vty, NULL); | |
848 | } | |
849 | ||
ca77b518 | 850 | DEFPY_YANG( |
2b3e4807 RZ |
851 | set_ipv6_nexthop_local, set_ipv6_nexthop_local_cmd, |
852 | "set ipv6 next-hop local X:X::X:X$addr", | |
853 | SET_STR | |
854 | IPV6_STR | |
855 | "IPv6 next-hop address\n" | |
856 | "IPv6 local address\n" | |
857 | "IPv6 address of next hop\n") | |
858 | { | |
d5d737a2 SP |
859 | const char *xpath = |
860 | "./set-action[action='frr-route-map:ipv6-next-hop']"; | |
2b3e4807 RZ |
861 | char xpath_value[XPATH_MAXLEN]; |
862 | ||
863 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
864 | snprintf(xpath_value, sizeof(xpath_value), |
865 | "%s/rmap-set-action/ipv6-address", xpath); | |
2b3e4807 RZ |
866 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, addr_str); |
867 | ||
868 | return nb_cli_apply_changes(vty, NULL); | |
869 | } | |
870 | ||
ca77b518 | 871 | DEFPY_YANG( |
2b3e4807 RZ |
872 | no_set_ipv6_nexthop_local, no_set_ipv6_nexthop_local_cmd, |
873 | "no set ipv6 next-hop local [X:X::X:X]", | |
874 | NO_STR | |
875 | SET_STR | |
876 | IPV6_STR | |
877 | "IPv6 next-hop address\n" | |
878 | "IPv6 local address\n" | |
879 | "IPv6 address of next hop\n") | |
880 | { | |
d5d737a2 SP |
881 | const char *xpath = |
882 | "./set-action[action='frr-route-map:ipv6-next-hop']"; | |
2b3e4807 RZ |
883 | |
884 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
885 | ||
886 | return nb_cli_apply_changes(vty, NULL); | |
887 | } | |
888 | ||
ca77b518 | 889 | DEFPY_YANG( |
2b3e4807 | 890 | set_metric, set_metric_cmd, |
add39cde | 891 | "set metric <(-4294967295-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt>", |
2b3e4807 RZ |
892 | SET_STR |
893 | "Metric value for destination routing protocol\n" | |
add39cde | 894 | "Metric value (use +/- for additions or subtractions)\n" |
2b3e4807 RZ |
895 | "Assign round trip time\n" |
896 | "Add round trip time\n" | |
add39cde | 897 | "Subtract round trip time\n") |
2b3e4807 | 898 | { |
d5d737a2 | 899 | const char *xpath = "./set-action[action='frr-route-map:set-metric']"; |
2b3e4807 RZ |
900 | char xpath_value[XPATH_MAXLEN]; |
901 | char value[64]; | |
902 | ||
903 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
904 | if (rtt) { | |
905 | snprintf(xpath_value, sizeof(xpath_value), | |
d5d737a2 | 906 | "%s/rmap-set-action/use-round-trip-time", xpath); |
2b3e4807 RZ |
907 | snprintf(value, sizeof(value), "true"); |
908 | } else if (artt) { | |
909 | snprintf(xpath_value, sizeof(xpath_value), | |
d5d737a2 | 910 | "%s/rmap-set-action/add-round-trip-time", xpath); |
2b3e4807 RZ |
911 | snprintf(value, sizeof(value), "true"); |
912 | } else if (srtt) { | |
913 | snprintf(xpath_value, sizeof(xpath_value), | |
d5d737a2 | 914 | "%s/rmap-set-action/subtract-round-trip-time", xpath); |
2b3e4807 | 915 | snprintf(value, sizeof(value), "true"); |
add39cde | 916 | } else if (metric_str && metric_str[0] == '+') { |
d5d737a2 SP |
917 | snprintf(xpath_value, sizeof(xpath_value), |
918 | "%s/rmap-set-action/add-metric", xpath); | |
add39cde RW |
919 | snprintf(value, sizeof(value), "%s", ++metric_str); |
920 | } else if (metric_str && metric_str[0] == '-') { | |
d5d737a2 SP |
921 | snprintf(xpath_value, sizeof(xpath_value), |
922 | "%s/rmap-set-action/subtract-metric", xpath); | |
add39cde | 923 | snprintf(value, sizeof(value), "%s", ++metric_str); |
2b3e4807 | 924 | } else { |
d5d737a2 SP |
925 | snprintf(xpath_value, sizeof(xpath_value), |
926 | "%s/rmap-set-action/value", xpath); | |
add39cde | 927 | snprintf(value, sizeof(value), "%s", metric_str); |
2b3e4807 RZ |
928 | } |
929 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value); | |
930 | ||
931 | return nb_cli_apply_changes(vty, NULL); | |
932 | } | |
933 | ||
ca77b518 | 934 | DEFPY_YANG( |
2b3e4807 | 935 | no_set_metric, no_set_metric_cmd, |
12488d7c | 936 | "no set metric [OPTVAL]", |
2b3e4807 RZ |
937 | NO_STR |
938 | SET_STR | |
939 | "Metric value for destination routing protocol\n" | |
940 | "Metric value\n") | |
941 | { | |
d5d737a2 | 942 | const char *xpath = "./set-action[action='frr-route-map:set-metric']"; |
2b3e4807 RZ |
943 | |
944 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
945 | return nb_cli_apply_changes(vty, NULL); | |
946 | } | |
947 | ||
ca77b518 | 948 | DEFPY_YANG( |
2b3e4807 RZ |
949 | set_tag, set_tag_cmd, |
950 | "set tag (1-4294967295)$tag", | |
951 | SET_STR | |
952 | "Tag value for routing protocol\n" | |
953 | "Tag value\n") | |
954 | { | |
d5d737a2 | 955 | const char *xpath = "./set-action[action='frr-route-map:set-tag']"; |
2b3e4807 RZ |
956 | char xpath_value[XPATH_MAXLEN]; |
957 | ||
958 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
d5d737a2 SP |
959 | snprintf(xpath_value, sizeof(xpath_value), "%s/rmap-set-action/tag", |
960 | xpath); | |
2b3e4807 RZ |
961 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, tag_str); |
962 | ||
963 | return nb_cli_apply_changes(vty, NULL); | |
964 | } | |
965 | ||
ca77b518 | 966 | DEFPY_YANG( |
2b3e4807 RZ |
967 | no_set_tag, no_set_tag_cmd, |
968 | "no set tag [(1-4294967295)]", | |
969 | NO_STR | |
970 | SET_STR | |
971 | "Tag value for routing protocol\n" | |
972 | "Tag value\n") | |
973 | { | |
d5d737a2 SP |
974 | const char *xpath = "./set-action[action='frr-route-map:set-tag']"; |
975 | ||
976 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
977 | ||
978 | return nb_cli_apply_changes(vty, NULL); | |
979 | } | |
980 | ||
981 | DEFUN_YANG (set_srte_color, | |
982 | set_srte_color_cmd, | |
983 | "set sr-te color (1-4294967295)", | |
984 | SET_STR | |
985 | SRTE_STR | |
986 | SRTE_COLOR_STR | |
987 | "Color of the SR-TE Policies to match with\n") | |
988 | { | |
989 | const char *xpath = | |
990 | "./set-action[action='frr-route-map:set-sr-te-color']"; | |
991 | char xpath_value[XPATH_MAXLEN]; | |
992 | int idx = 0; | |
993 | ||
994 | char *arg = argv_find(argv, argc, "(1-4294967295)", &idx) | |
995 | ? argv[idx]->arg | |
996 | : NULL; | |
997 | ||
998 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
999 | snprintf(xpath_value, sizeof(xpath_value), | |
1000 | "%s/rmap-set-action/policy", xpath); | |
1001 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, arg); | |
1002 | ||
1003 | return nb_cli_apply_changes(vty, NULL); | |
1004 | } | |
1005 | ||
1006 | DEFUN_YANG (no_set_srte_color, | |
1007 | no_set_srte_color_cmd, | |
1008 | "no set sr-te color [(1-4294967295)]", | |
1009 | NO_STR | |
1010 | SET_STR | |
1011 | SRTE_STR | |
1012 | SRTE_COLOR_STR | |
1013 | "Color of the SR-TE Policies to match with\n") | |
1014 | { | |
1015 | const char *xpath = | |
1016 | "./set-action[action='frr-route-map:set-sr-te-color']"; | |
2b3e4807 RZ |
1017 | |
1018 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
1019 | ||
1020 | return nb_cli_apply_changes(vty, NULL); | |
1021 | } | |
1022 | ||
d5d737a2 | 1023 | |
25605051 | 1024 | void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
1025 | bool show_defaults) |
1026 | { | |
d5d737a2 | 1027 | const char *action = yang_dnode_get_string(dnode, "./action"); |
25605051 | 1028 | const struct lyd_node *ln; |
d5d737a2 | 1029 | const char *acl; |
2b3e4807 | 1030 | |
d5d737a2 | 1031 | if (IS_SET_IPv4_NH(action)) { |
2b3e4807 | 1032 | vty_out(vty, " set ip next-hop %s\n", |
d5d737a2 SP |
1033 | yang_dnode_get_string( |
1034 | dnode, "./rmap-set-action/ipv4-address")); | |
1035 | } else if (IS_SET_IPv6_NH(action)) { | |
2b3e4807 | 1036 | vty_out(vty, " set ipv6 next-hop local %s\n", |
d5d737a2 SP |
1037 | yang_dnode_get_string( |
1038 | dnode, "./rmap-set-action/ipv6-address")); | |
1039 | } else if (IS_SET_METRIC(action)) { | |
1040 | if (yang_dnode_get(dnode, | |
1041 | "./rmap-set-action/use-round-trip-time")) { | |
2b3e4807 | 1042 | vty_out(vty, " set metric rtt\n"); |
d5d737a2 SP |
1043 | } else if (yang_dnode_get( |
1044 | dnode, | |
1045 | "./rmap-set-action/add-round-trip-time")) { | |
2b3e4807 | 1046 | vty_out(vty, " set metric +rtt\n"); |
d5d737a2 SP |
1047 | } else if ( |
1048 | yang_dnode_get( | |
1049 | dnode, | |
1050 | "./rmap-set-action/subtract-round-trip-time")) { | |
2b3e4807 | 1051 | vty_out(vty, " set metric -rtt\n"); |
d5d737a2 SP |
1052 | } else if (yang_dnode_get(dnode, |
1053 | "./rmap-set-action/add-metric")) { | |
add39cde | 1054 | vty_out(vty, " set metric +%s\n", |
d5d737a2 SP |
1055 | yang_dnode_get_string( |
1056 | dnode, "./rmap-set-action/add-metric")); | |
1057 | } else if (yang_dnode_get( | |
1058 | dnode, | |
1059 | "./rmap-set-action/subtract-metric")) { | |
add39cde | 1060 | vty_out(vty, " set metric -%s\n", |
d5d737a2 SP |
1061 | yang_dnode_get_string( |
1062 | dnode, | |
1063 | "./rmap-set-action/subtract-metric")); | |
2b3e4807 RZ |
1064 | } else { |
1065 | vty_out(vty, " set metric %s\n", | |
d5d737a2 SP |
1066 | yang_dnode_get_string( |
1067 | dnode, "./rmap-set-action/value")); | |
2b3e4807 | 1068 | } |
d5d737a2 | 1069 | } else if (IS_SET_TAG(action)) { |
2b3e4807 | 1070 | vty_out(vty, " set tag %s\n", |
d5d737a2 SP |
1071 | yang_dnode_get_string(dnode, "./rmap-set-action/tag")); |
1072 | } else if (IS_SET_SR_TE_COLOR(action)) { | |
1073 | vty_out(vty, " set sr-te color %s\n", | |
1074 | yang_dnode_get_string(dnode, | |
1075 | "./rmap-set-action/policy")); | |
1076 | } else if (IS_SET_SRC(action)) { | |
1077 | if (yang_dnode_exists( | |
1078 | dnode, | |
1079 | "./rmap-set-action/frr-zebra-route-map:ipv4-src-address")) | |
f42cc965 | 1080 | vty_out(vty, " set src %s\n", |
d5d737a2 SP |
1081 | yang_dnode_get_string( |
1082 | dnode, | |
1083 | "./rmap-set-action/frr-zebra-route-map:ipv4-src-address")); | |
f42cc965 RZ |
1084 | else |
1085 | vty_out(vty, " set src %s\n", | |
d5d737a2 SP |
1086 | yang_dnode_get_string( |
1087 | dnode, | |
1088 | "./rmap-set-action/frr-zebra-route-map:ipv6-src-address")); | |
1089 | } else if (IS_SET_METRIC_TYPE(action)) { | |
1090 | vty_out(vty, " set metric-type %s\n", | |
1091 | yang_dnode_get_string( | |
1092 | dnode, | |
1093 | "./rmap-set-action/frr-ospf-route-map:metric-type")); | |
1094 | } else if (IS_SET_FORWARDING_ADDR(action)) { | |
1095 | vty_out(vty, " set forwarding-address %s\n", | |
1096 | yang_dnode_get_string( | |
1097 | dnode, | |
1098 | "./rmap-set-action/frr-ospf6-route-map:ipv6-address")); | |
1099 | } else if (IS_SET_WEIGHT(action)) { | |
1100 | vty_out(vty, " set weight %s\n", | |
1101 | yang_dnode_get_string( | |
1102 | dnode, | |
1103 | "./rmap-set-action/frr-bgp-route-map:weight")); | |
1104 | } else if (IS_SET_TABLE(action)) { | |
1105 | vty_out(vty, " set table %s\n", | |
1106 | yang_dnode_get_string( | |
1107 | dnode, | |
1108 | "./rmap-set-action/frr-bgp-route-map:table")); | |
1109 | } else if (IS_SET_LOCAL_PREF(action)) { | |
1110 | vty_out(vty, " set local-preference %s\n", | |
1111 | yang_dnode_get_string( | |
1112 | dnode, | |
1113 | "./rmap-set-action/frr-bgp-route-map:local-pref")); | |
1114 | } else if (IS_SET_LABEL_INDEX(action)) { | |
1115 | vty_out(vty, " set label-index %s\n", | |
1116 | yang_dnode_get_string( | |
1117 | dnode, | |
1118 | "./rmap-set-action/frr-bgp-route-map:label-index")); | |
1119 | } else if (IS_SET_DISTANCE(action)) { | |
1120 | vty_out(vty, " set distance %s\n", | |
1121 | yang_dnode_get_string( | |
1122 | dnode, | |
1123 | "./rmap-set-action/frr-bgp-route-map:distance")); | |
1124 | } else if (IS_SET_ORIGIN(action)) { | |
1125 | vty_out(vty, " set origin %s\n", | |
1126 | yang_dnode_get_string( | |
1127 | dnode, | |
1128 | "./rmap-set-action/frr-bgp-route-map:origin")); | |
1129 | } else if (IS_SET_ATOMIC_AGGREGATE(action)) { | |
1130 | vty_out(vty, " set atomic-aggregate\n"); | |
1131 | } else if (IS_SET_ORIGINATOR_ID(action)) { | |
1132 | vty_out(vty, " set originator-id %s\n", | |
1133 | yang_dnode_get_string( | |
1134 | dnode, | |
1135 | "./rmap-set-action/frr-bgp-route-map:originator-id")); | |
1136 | } else if (IS_SET_COMM_LIST_DEL(action)) { | |
1137 | acl = NULL; | |
1138 | if ((ln = yang_dnode_get( | |
1139 | dnode, | |
1140 | "./rmap-set-action/frr-bgp-route-map:comm-list-name")) | |
1141 | != NULL) | |
1142 | acl = yang_dnode_get_string(ln, NULL); | |
1143 | ||
1144 | assert(acl); | |
1145 | ||
1146 | vty_out(vty, " set comm-list %s delete\n", acl); | |
1147 | } else if (IS_SET_LCOMM_LIST_DEL(action)) { | |
1148 | acl = NULL; | |
1149 | if ((ln = yang_dnode_get( | |
1150 | dnode, | |
1151 | "./rmap-set-action/frr-bgp-route-map:comm-list-name")) | |
1152 | != NULL) | |
1153 | acl = yang_dnode_get_string(ln, NULL); | |
1154 | ||
1155 | assert(acl); | |
1156 | ||
1157 | vty_out(vty, " set large-comm-list %s delete\n", acl); | |
1158 | } else if (IS_SET_LCOMMUNITY(action)) { | |
1159 | if (yang_dnode_exists( | |
1160 | dnode, | |
1161 | "./rmap-set-action/frr-bgp-route-map:large-community-string")) | |
1162 | vty_out(vty, " set large-community %s\n", | |
1163 | yang_dnode_get_string( | |
1164 | dnode, | |
1165 | "./rmap-set-action/frr-bgp-route-map:large-community-string")); | |
1166 | else { | |
1167 | if (true | |
1168 | == yang_dnode_get_bool( | |
1169 | dnode, | |
1170 | "./rmap-set-action/frr-bgp-route-map:large-community-none")) | |
1171 | vty_out(vty, " set large-community none\n"); | |
1172 | } | |
1173 | } else if (IS_SET_COMMUNITY(action)) { | |
1174 | if (yang_dnode_exists( | |
1175 | dnode, | |
1176 | "./rmap-set-action/frr-bgp-route-map:community-string")) | |
1177 | vty_out(vty, " set community %s\n", | |
1178 | yang_dnode_get_string( | |
1179 | dnode, | |
1180 | "./rmap-set-action/frr-bgp-route-map:community-string")); | |
1181 | else { | |
1182 | if (true | |
1183 | == yang_dnode_get_bool( | |
1184 | dnode, | |
1185 | "./rmap-set-action/frr-bgp-route-map:community-none")) | |
1186 | vty_out(vty, " set community none\n"); | |
1187 | } | |
1188 | } else if (IS_SET_EXTCOMMUNITY_RT(action)) { | |
1189 | vty_out(vty, " set extcommunity rt %s\n", | |
1190 | yang_dnode_get_string( | |
1191 | dnode, | |
1192 | "./rmap-set-action/frr-bgp-route-map:extcommunity-rt")); | |
1193 | } else if (IS_SET_EXTCOMMUNITY_SOO(action)) { | |
1194 | vty_out(vty, " set extcommunity soo %s\n", | |
1195 | yang_dnode_get_string( | |
1196 | dnode, | |
1197 | "./rmap-set-action/frr-bgp-route-map:extcommunity-soo")); | |
71bdae66 DA |
1198 | } else if (IS_SET_EXTCOMMUNITY_LB(action)) { |
1199 | enum ecommunity_lb_type lb_type; | |
1200 | char str[VTY_BUFSIZ]; | |
1201 | uint16_t bandwidth; | |
1202 | ||
1203 | lb_type = yang_dnode_get_enum( | |
1204 | dnode, | |
1205 | "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type"); | |
1206 | switch (lb_type) { | |
1207 | case EXPLICIT_BANDWIDTH: | |
1208 | bandwidth = yang_dnode_get_uint16( | |
1209 | dnode, | |
1210 | "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth"); | |
1211 | snprintf(str, sizeof(str), "%d", bandwidth); | |
1212 | break; | |
1213 | case CUMULATIVE_BANDWIDTH: | |
1214 | snprintf(str, sizeof(str), "%s", "cumulative"); | |
1215 | break; | |
1216 | case COMPUTED_BANDWIDTH: | |
1217 | snprintf(str, sizeof(str), "%s", "num-multipaths"); | |
1218 | } | |
1219 | ||
1220 | if (yang_dnode_get_bool( | |
1221 | dnode, | |
1222 | "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific")) | |
1223 | strlcat(str, " non-transitive", sizeof(str)); | |
1224 | ||
1225 | vty_out(vty, " set extcommunity bandwidth %s\n", str); | |
bb4dcdd1 DA |
1226 | } else if (IS_SET_EXTCOMMUNITY_NONE(action)) { |
1227 | if (yang_dnode_get_bool( | |
1228 | dnode, | |
1229 | "./rmap-set-action/frr-bgp-route-map:extcommunity-none")) | |
1230 | vty_out(vty, " set extcommunity none\n"); | |
d5d737a2 SP |
1231 | } else if (IS_SET_AGGREGATOR(action)) { |
1232 | vty_out(vty, " set aggregator as %s %s\n", | |
1233 | yang_dnode_get_string( | |
1234 | dnode, | |
1235 | "./rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn"), | |
1236 | yang_dnode_get_string( | |
1237 | dnode, | |
1238 | "./rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address")); | |
1239 | } else if (IS_SET_AS_EXCLUDE(action)) { | |
1240 | vty_out(vty, " set as-path exclude %s\n", | |
1241 | yang_dnode_get_string( | |
1242 | dnode, | |
1243 | "./rmap-set-action/frr-bgp-route-map:exclude-as-path")); | |
1244 | } else if (IS_SET_AS_PREPEND(action)) { | |
1245 | if (yang_dnode_exists( | |
1246 | dnode, | |
1247 | "./rmap-set-action/frr-bgp-route-map:prepend-as-path")) | |
1248 | vty_out(vty, " set as-path prepend %s\n", | |
1249 | yang_dnode_get_string( | |
1250 | dnode, | |
1251 | "./rmap-set-action/frr-bgp-route-map:prepend-as-path")); | |
1252 | else { | |
1253 | vty_out(vty, " set as-path prepend last-as %u\n", | |
1254 | yang_dnode_get_uint8( | |
1255 | dnode, | |
1256 | "./rmap-set-action/frr-bgp-route-map:last-as")); | |
1257 | } | |
1258 | } else if (IS_SET_IPV6_NH_GLOBAL(action)) { | |
1259 | vty_out(vty, " set ipv6 next-hop global %s\n", | |
1260 | yang_dnode_get_string( | |
1261 | dnode, | |
1262 | "./rmap-set-action/frr-bgp-route-map:ipv6-address")); | |
1263 | } else if (IS_SET_IPV6_VPN_NH(action)) { | |
1264 | vty_out(vty, " set ipv6 vpn next-hop %s\n", | |
1265 | yang_dnode_get_string( | |
1266 | dnode, | |
1267 | "./rmap-set-action/frr-bgp-route-map:ipv6-address")); | |
1268 | } else if (IS_SET_IPV6_PEER_ADDR(action)) { | |
1269 | if (true | |
1270 | == yang_dnode_get_bool( | |
1271 | dnode, | |
1272 | "./rmap-set-action/frr-bgp-route-map:preference")) | |
1273 | vty_out(vty, " set ipv6 next-hop peer-address\n"); | |
1274 | } else if (IS_SET_IPV6_PREFER_GLOBAL(action)) { | |
1275 | if (true | |
1276 | == yang_dnode_get_bool( | |
1277 | dnode, | |
1278 | "./rmap-set-action/frr-bgp-route-map:preference")) | |
1279 | vty_out(vty, " set ipv6 next-hop prefer-global\n"); | |
1280 | } else if (IS_SET_IPV4_VPN_NH(action)) { | |
1281 | vty_out(vty, " set ipv4 vpn next-hop %s\n", | |
1282 | yang_dnode_get_string( | |
1283 | dnode, | |
1284 | "./rmap-set-action/frr-bgp-route-map:ipv4-address")); | |
1285 | } else if (IS_SET_BGP_IPV4_NH(action)) { | |
1286 | vty_out(vty, " set ip next-hop %s\n", | |
1287 | yang_dnode_get_string( | |
1288 | dnode, | |
1289 | "./rmap-set-action/frr-bgp-route-map:ipv4-nexthop")); | |
d0a4ee60 AD |
1290 | } else if (IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(action)) { |
1291 | vty_out(vty, " set evpn gateway-ip ipv4 %s\n", | |
1292 | yang_dnode_get_string( | |
1293 | dnode, | |
1294 | "./rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4")); | |
1295 | } else if (IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(action)) { | |
1296 | vty_out(vty, " set evpn gateway-ip ipv6 %s\n", | |
1297 | yang_dnode_get_string( | |
1298 | dnode, | |
1299 | "./rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6")); | |
2b3e4807 RZ |
1300 | } |
1301 | } | |
1302 | ||
ca77b518 | 1303 | DEFPY_YANG( |
2b3e4807 RZ |
1304 | rmap_onmatch_next, rmap_onmatch_next_cmd, |
1305 | "on-match next", | |
1306 | "Exit policy on matches\n" | |
1307 | "Next clause\n") | |
1308 | { | |
1309 | nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_MODIFY, "next"); | |
1310 | ||
1311 | return nb_cli_apply_changes(vty, NULL); | |
1312 | } | |
1313 | ||
ca77b518 | 1314 | DEFPY_YANG( |
2b3e4807 RZ |
1315 | no_rmap_onmatch_next, |
1316 | no_rmap_onmatch_next_cmd, | |
1317 | "no on-match next", | |
1318 | NO_STR | |
1319 | "Exit policy on matches\n" | |
1320 | "Next clause\n") | |
1321 | { | |
1322 | nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_DESTROY, NULL); | |
1323 | ||
1324 | return nb_cli_apply_changes(vty, NULL); | |
1325 | } | |
1326 | ||
ca77b518 | 1327 | DEFPY_YANG( |
2b3e4807 RZ |
1328 | rmap_onmatch_goto, rmap_onmatch_goto_cmd, |
1329 | "on-match goto (1-65535)$rm_num", | |
1330 | "Exit policy on matches\n" | |
1331 | "Goto Clause number\n" | |
1332 | "Number\n") | |
1333 | { | |
1334 | nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_MODIFY, "goto"); | |
1335 | nb_cli_enqueue_change(vty, "./goto-value", NB_OP_MODIFY, rm_num_str); | |
1336 | ||
1337 | return nb_cli_apply_changes(vty, NULL); | |
1338 | } | |
1339 | ||
ca77b518 | 1340 | DEFPY_YANG( |
2b3e4807 RZ |
1341 | no_rmap_onmatch_goto, no_rmap_onmatch_goto_cmd, |
1342 | "no on-match goto", | |
1343 | NO_STR | |
1344 | "Exit policy on matches\n" | |
1345 | "Goto Clause number\n") | |
1346 | { | |
1347 | nb_cli_enqueue_change(vty, "./exit-policy", NB_OP_DESTROY, NULL); | |
1348 | ||
1349 | return nb_cli_apply_changes(vty, NULL); | |
1350 | } | |
1351 | ||
1352 | /* Cisco/GNU Zebra compatibility aliases */ | |
ca77b518 | 1353 | ALIAS_YANG( |
2b3e4807 RZ |
1354 | rmap_onmatch_goto, rmap_continue_cmd, |
1355 | "continue (1-65535)$rm_num", | |
1356 | "Continue on a different entry within the route-map\n" | |
1357 | "Route-map entry sequence number\n") | |
1358 | ||
ca77b518 | 1359 | ALIAS_YANG( |
2b3e4807 RZ |
1360 | no_rmap_onmatch_goto, no_rmap_continue_cmd, |
1361 | "no continue [(1-65535)]", | |
1362 | NO_STR | |
1363 | "Continue on a different entry within the route-map\n" | |
1364 | "Route-map entry sequence number\n") | |
1365 | ||
25605051 | 1366 | void route_map_exit_policy_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
1367 | bool show_defaults) |
1368 | { | |
1369 | int exit_policy = yang_dnode_get_enum(dnode, NULL); | |
1370 | ||
1371 | switch (exit_policy) { | |
1372 | case 0: /* permit-or-deny */ | |
1373 | /* NOTHING: default option. */ | |
1374 | break; | |
1375 | case 1: /* next */ | |
1376 | vty_out(vty, " on-match next\n"); | |
1377 | break; | |
1378 | case 2: /* goto */ | |
1379 | vty_out(vty, " on-match goto %s\n", | |
1380 | yang_dnode_get_string(dnode, "../goto-value")); | |
1381 | break; | |
1382 | } | |
1383 | } | |
1384 | ||
ca77b518 | 1385 | DEFPY_YANG( |
2b3e4807 RZ |
1386 | rmap_call, rmap_call_cmd, |
1387 | "call WORD$name", | |
1388 | "Jump to another Route-Map after match+set\n" | |
1389 | "Target route-map name\n") | |
1390 | { | |
1391 | nb_cli_enqueue_change(vty, "./call", NB_OP_MODIFY, name); | |
1392 | ||
1393 | return nb_cli_apply_changes(vty, NULL); | |
1394 | } | |
1395 | ||
ca77b518 | 1396 | DEFPY_YANG( |
2b3e4807 | 1397 | no_rmap_call, no_rmap_call_cmd, |
680b9b62 | 1398 | "no call [NAME]", |
2b3e4807 | 1399 | NO_STR |
20684537 RZ |
1400 | "Jump to another Route-Map after match+set\n" |
1401 | "Target route-map name\n") | |
2b3e4807 RZ |
1402 | { |
1403 | nb_cli_enqueue_change(vty, "./call", NB_OP_DESTROY, NULL); | |
1404 | ||
1405 | return nb_cli_apply_changes(vty, NULL); | |
1406 | } | |
1407 | ||
25605051 | 1408 | void route_map_call_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
1409 | bool show_defaults) |
1410 | { | |
1411 | vty_out(vty, " call %s\n", yang_dnode_get_string(dnode, NULL)); | |
1412 | } | |
1413 | ||
ca77b518 | 1414 | DEFPY_YANG( |
2b3e4807 RZ |
1415 | rmap_description, rmap_description_cmd, |
1416 | "description LINE...", | |
1417 | "Route-map comment\n" | |
1418 | "Comment describing this route-map rule\n") | |
1419 | { | |
1420 | char *desc; | |
1421 | int rv; | |
1422 | ||
1423 | desc = argv_concat(argv, argc, 1); | |
1424 | nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, desc); | |
1425 | rv = nb_cli_apply_changes(vty, NULL); | |
1426 | XFREE(MTYPE_TMP, desc); | |
1427 | ||
1428 | return rv; | |
1429 | } | |
1430 | ||
ca77b518 | 1431 | DEFUN_YANG (no_rmap_description, |
2b3e4807 RZ |
1432 | no_rmap_description_cmd, |
1433 | "no description", | |
1434 | NO_STR | |
1435 | "Route-map comment\n") | |
1436 | { | |
1437 | nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL); | |
1438 | ||
1439 | return nb_cli_apply_changes(vty, NULL); | |
1440 | } | |
1441 | ||
25605051 | 1442 | void route_map_description_show(struct vty *vty, const struct lyd_node *dnode, |
2b3e4807 RZ |
1443 | bool show_defaults) |
1444 | { | |
1445 | vty_out(vty, " description %s\n", yang_dnode_get_string(dnode, NULL)); | |
1446 | } | |
1447 | ||
38133c4a IR |
1448 | DEFPY_YANG( |
1449 | route_map_optimization, route_map_optimization_cmd, | |
8f241168 | 1450 | "[no] route-map RMAP_NAME$name optimization", |
38133c4a IR |
1451 | NO_STR |
1452 | ROUTE_MAP_CMD_STR | |
1453 | "Configure route-map optimization\n") | |
1454 | { | |
1455 | char xpath[XPATH_MAXLEN]; | |
1456 | ||
1457 | snprintf(xpath, sizeof(xpath), | |
1458 | "/frr-route-map:lib/route-map[name='%s']", name); | |
1459 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
1460 | ||
1461 | snprintf( | |
1462 | xpath, sizeof(xpath), | |
1463 | "/frr-route-map:lib/route-map[name='%s']/optimization-disabled", | |
1464 | name); | |
1465 | nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, no ? "true" : "false"); | |
1466 | ||
1467 | return nb_cli_apply_changes(vty, NULL); | |
1468 | } | |
1469 | ||
1470 | void route_map_optimization_disabled_show(struct vty *vty, | |
25605051 | 1471 | const struct lyd_node *dnode, |
38133c4a IR |
1472 | bool show_defaults) |
1473 | { | |
1474 | const char *name = yang_dnode_get_string(dnode, "../name"); | |
1475 | const bool disabled = yang_dnode_get_bool(dnode, NULL); | |
1476 | ||
1477 | vty_out(vty, "%sroute-map %s optimization\n", disabled ? "no " : "", | |
1478 | name); | |
1479 | } | |
1480 | ||
1481 | #if CONFDATE > 20220409 | |
1482 | CPP_NOTICE("Time to remove old route-map optimization command") | |
1483 | #endif | |
1484 | ||
1485 | DEFPY_HIDDEN( | |
1486 | routemap_optimization, routemap_optimization_cmd, | |
1487 | "[no] route-map optimization", | |
1488 | NO_STR | |
1489 | "route-map\n" | |
1490 | "optimization\n") | |
3ebeec94 IR |
1491 | { |
1492 | const struct lyd_node *rmi_dnode; | |
1493 | const char *rm_name; | |
1494 | char xpath[XPATH_MAXLEN]; | |
1495 | ||
38133c4a IR |
1496 | vty_out(vty, |
1497 | "%% This command is deprecated. Please, use `route-map NAME optimization` from the config node.\n"); | |
1498 | ||
3ebeec94 IR |
1499 | rmi_dnode = |
1500 | yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH); | |
1501 | if (!rmi_dnode) { | |
1502 | vty_out(vty, "%% Failed to get RMI dnode in candidate DB\n"); | |
1503 | return CMD_WARNING_CONFIG_FAILED; | |
1504 | } | |
1505 | ||
1506 | rm_name = yang_dnode_get_string(rmi_dnode, "../name"); | |
1507 | ||
1508 | snprintf( | |
1509 | xpath, sizeof(xpath), | |
1510 | "/frr-route-map:lib/route-map[name='%s']/optimization-disabled", | |
1511 | rm_name); | |
1512 | nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, no ? "true" : "false"); | |
1513 | return nb_cli_apply_changes(vty, NULL); | |
1514 | } | |
1515 | ||
2b3e4807 RZ |
1516 | static int route_map_config_write(struct vty *vty) |
1517 | { | |
25605051 | 1518 | const struct lyd_node *dnode; |
2b3e4807 RZ |
1519 | int written = 0; |
1520 | ||
1521 | dnode = yang_dnode_get(running_config->dnode, | |
1522 | "/frr-route-map:lib"); | |
1523 | if (dnode) { | |
1524 | nb_cli_show_dnode_cmds(vty, dnode, false); | |
1525 | written = 1; | |
1526 | } | |
1527 | ||
1528 | return written; | |
1529 | } | |
1530 | ||
1531 | /* Route map node structure. */ | |
612c2c15 | 1532 | static int route_map_config_write(struct vty *vty); |
62b346ee | 1533 | static struct cmd_node rmap_node = { |
f4b8291f | 1534 | .name = "routemap", |
62b346ee | 1535 | .node = RMAP_NODE, |
24389580 | 1536 | .parent_node = CONFIG_NODE, |
62b346ee | 1537 | .prompt = "%s(config-route-map)# ", |
612c2c15 | 1538 | .config_write = route_map_config_write, |
62b346ee | 1539 | }; |
2b3e4807 RZ |
1540 | |
1541 | static void rmap_autocomplete(vector comps, struct cmd_token *token) | |
1542 | { | |
1543 | struct route_map *map; | |
1544 | ||
1545 | for (map = route_map_master.head; map; map = map->next) | |
1546 | vector_set(comps, XSTRDUP(MTYPE_COMPLETION, map->name)); | |
1547 | } | |
1548 | ||
1549 | static const struct cmd_variable_handler rmap_var_handlers[] = { | |
1550 | {.varname = "route_map", .completions = rmap_autocomplete}, | |
1551 | {.tokenname = "ROUTEMAP_NAME", .completions = rmap_autocomplete}, | |
1552 | {.tokenname = "RMAP_NAME", .completions = rmap_autocomplete}, | |
1553 | {.completions = NULL} | |
1554 | }; | |
1555 | ||
1556 | void route_map_cli_init(void) | |
1557 | { | |
1558 | /* Auto complete handler. */ | |
1559 | cmd_variable_handler_register(rmap_var_handlers); | |
1560 | ||
1561 | /* CLI commands. */ | |
612c2c15 | 1562 | install_node(&rmap_node); |
2b3e4807 RZ |
1563 | install_default(RMAP_NODE); |
1564 | install_element(CONFIG_NODE, &route_map_cmd); | |
1565 | install_element(CONFIG_NODE, &no_route_map_cmd); | |
1566 | install_element(CONFIG_NODE, &no_route_map_all_cmd); | |
38133c4a | 1567 | install_element(CONFIG_NODE, &route_map_optimization_cmd); |
2b3e4807 RZ |
1568 | |
1569 | /* Install the on-match stuff */ | |
2b3e4807 RZ |
1570 | install_element(RMAP_NODE, &rmap_onmatch_next_cmd); |
1571 | install_element(RMAP_NODE, &no_rmap_onmatch_next_cmd); | |
1572 | install_element(RMAP_NODE, &rmap_onmatch_goto_cmd); | |
1573 | install_element(RMAP_NODE, &no_rmap_onmatch_goto_cmd); | |
1574 | install_element(RMAP_NODE, &rmap_continue_cmd); | |
1575 | install_element(RMAP_NODE, &no_rmap_continue_cmd); | |
1576 | ||
1577 | /* Install the call stuff. */ | |
1578 | install_element(RMAP_NODE, &rmap_call_cmd); | |
1579 | install_element(RMAP_NODE, &no_rmap_call_cmd); | |
1580 | ||
1581 | /* Install description commands. */ | |
1582 | install_element(RMAP_NODE, &rmap_description_cmd); | |
1583 | install_element(RMAP_NODE, &no_rmap_description_cmd); | |
1584 | ||
1585 | /* Install 'match' commands. */ | |
1586 | install_element(RMAP_NODE, &match_interface_cmd); | |
1587 | install_element(RMAP_NODE, &no_match_interface_cmd); | |
1588 | ||
1589 | install_element(RMAP_NODE, &match_ip_address_cmd); | |
1590 | install_element(RMAP_NODE, &no_match_ip_address_cmd); | |
1591 | ||
1592 | install_element(RMAP_NODE, &match_ip_address_prefix_list_cmd); | |
1593 | install_element(RMAP_NODE, &no_match_ip_address_prefix_list_cmd); | |
1594 | ||
1595 | install_element(RMAP_NODE, &match_ip_next_hop_cmd); | |
1596 | install_element(RMAP_NODE, &no_match_ip_next_hop_cmd); | |
1597 | ||
1598 | install_element(RMAP_NODE, &match_ip_next_hop_prefix_list_cmd); | |
1599 | install_element(RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd); | |
1600 | ||
1601 | install_element(RMAP_NODE, &match_ip_next_hop_type_cmd); | |
1602 | install_element(RMAP_NODE, &no_match_ip_next_hop_type_cmd); | |
1603 | ||
1604 | install_element(RMAP_NODE, &match_ipv6_address_cmd); | |
1605 | install_element(RMAP_NODE, &no_match_ipv6_address_cmd); | |
1606 | ||
1607 | install_element(RMAP_NODE, &match_ipv6_address_prefix_list_cmd); | |
1608 | install_element(RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd); | |
1609 | ||
1610 | install_element(RMAP_NODE, &match_ipv6_next_hop_type_cmd); | |
1611 | install_element(RMAP_NODE, &no_match_ipv6_next_hop_type_cmd); | |
1612 | ||
1613 | install_element(RMAP_NODE, &match_metric_cmd); | |
1614 | install_element(RMAP_NODE, &no_match_metric_cmd); | |
1615 | ||
1616 | install_element(RMAP_NODE, &match_tag_cmd); | |
1617 | install_element(RMAP_NODE, &no_match_tag_cmd); | |
1618 | ||
1619 | /* Install 'set' commands. */ | |
1620 | install_element(RMAP_NODE, &set_ip_nexthop_cmd); | |
1621 | install_element(RMAP_NODE, &no_set_ip_nexthop_cmd); | |
1622 | ||
1623 | install_element(RMAP_NODE, &set_ipv6_nexthop_local_cmd); | |
1624 | install_element(RMAP_NODE, &no_set_ipv6_nexthop_local_cmd); | |
1625 | ||
1626 | install_element(RMAP_NODE, &set_metric_cmd); | |
1627 | install_element(RMAP_NODE, &no_set_metric_cmd); | |
1628 | ||
1629 | install_element(RMAP_NODE, &set_tag_cmd); | |
1630 | install_element(RMAP_NODE, &no_set_tag_cmd); | |
d5d737a2 SP |
1631 | |
1632 | install_element(RMAP_NODE, &set_srte_color_cmd); | |
1633 | install_element(RMAP_NODE, &no_set_srte_color_cmd); | |
3ebeec94 IR |
1634 | |
1635 | install_element(RMAP_NODE, &routemap_optimization_cmd); | |
2b3e4807 | 1636 | } |