]>
Commit | Line | Data |
---|---|---|
26cd3d66 MR |
1 | /* |
2 | * PIM for IPv6 FRR | |
3 | * Copyright (C) 2022 Vmware, Inc. | |
4 | * Mobashshera Rasool <mrasool@vmware.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "lib/json.h" | |
24 | #include "command.h" | |
25 | #include "if.h" | |
26 | #include "prefix.h" | |
27 | #include "zclient.h" | |
28 | #include "plist.h" | |
29 | #include "hash.h" | |
30 | #include "nexthop.h" | |
31 | #include "vrf.h" | |
32 | #include "ferr.h" | |
63ee25c0 | 33 | #include "lib/srcdest_table.h" |
26cd3d66 MR |
34 | |
35 | #include "pimd.h" | |
36 | #include "pim_vty.h" | |
37 | #include "lib/northbound_cli.h" | |
38 | #include "pim_errors.h" | |
39 | #include "pim_nb.h" | |
c73113ea | 40 | #include "pim_cmd_common.h" |
26cd3d66 | 41 | |
2328b7ef MR |
42 | /** |
43 | * Get current node VRF name. | |
44 | * | |
45 | * NOTE: | |
46 | * In case of failure it will print error message to user. | |
47 | * | |
48 | * \returns name or NULL if failed to get VRF. | |
49 | */ | |
50 | const char *pim_cli_get_vrf_name(struct vty *vty) | |
51 | { | |
52 | const struct lyd_node *vrf_node; | |
53 | ||
54 | /* Not inside any VRF context. */ | |
55 | if (vty->xpath_index == 0) | |
56 | return VRF_DEFAULT_NAME; | |
57 | ||
58 | vrf_node = yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH); | |
59 | if (vrf_node == NULL) { | |
60 | vty_out(vty, "%% Failed to get vrf dnode in configuration\n"); | |
61 | return NULL; | |
62 | } | |
63 | ||
64 | return yang_dnode_get_string(vrf_node, "./name"); | |
65 | } | |
26cd3d66 | 66 | |
c73113ea MR |
67 | int pim_process_join_prune_cmd(struct vty *vty, const char *jpi_str) |
68 | { | |
69 | char xpath[XPATH_MAXLEN]; | |
70 | ||
71 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
72 | FRR_PIM_AF_XPATH_VAL); | |
73 | strlcat(xpath, "/join-prune-interval", sizeof(xpath)); | |
74 | ||
75 | nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, jpi_str); | |
76 | ||
77 | return nb_cli_apply_changes(vty, NULL); | |
78 | } | |
79 | ||
80 | int pim_process_no_join_prune_cmd(struct vty *vty) | |
81 | { | |
82 | char xpath[XPATH_MAXLEN]; | |
83 | ||
84 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
85 | FRR_PIM_AF_XPATH_VAL); | |
86 | strlcat(xpath, "/join-prune-interval", sizeof(xpath)); | |
87 | ||
88 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
89 | ||
90 | return nb_cli_apply_changes(vty, NULL); | |
91 | } | |
fb991ce9 MR |
92 | |
93 | int pim_process_spt_switchover_infinity_cmd(struct vty *vty) | |
94 | { | |
95 | const char *vrfname; | |
96 | char spt_plist_xpath[XPATH_MAXLEN]; | |
97 | char spt_action_xpath[XPATH_MAXLEN]; | |
98 | ||
99 | vrfname = pim_cli_get_vrf_name(vty); | |
100 | if (vrfname == NULL) | |
101 | return CMD_WARNING_CONFIG_FAILED; | |
102 | ||
103 | snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), | |
104 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
105 | FRR_PIM_AF_XPATH_VAL); | |
106 | strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", | |
107 | sizeof(spt_plist_xpath)); | |
108 | ||
109 | snprintf(spt_action_xpath, sizeof(spt_action_xpath), | |
110 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
111 | FRR_PIM_AF_XPATH_VAL); | |
112 | strlcat(spt_action_xpath, "/spt-switchover/spt-action", | |
113 | sizeof(spt_action_xpath)); | |
114 | ||
115 | if (yang_dnode_exists(vty->candidate_config->dnode, spt_plist_xpath)) | |
116 | nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, | |
117 | NULL); | |
118 | nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, | |
119 | "PIM_SPT_INFINITY"); | |
120 | ||
121 | return nb_cli_apply_changes(vty, NULL); | |
122 | } | |
123 | ||
124 | int pim_process_spt_switchover_prefixlist_cmd(struct vty *vty, | |
125 | const char *plist) | |
126 | { | |
127 | const char *vrfname; | |
128 | char spt_plist_xpath[XPATH_MAXLEN]; | |
129 | char spt_action_xpath[XPATH_MAXLEN]; | |
130 | ||
131 | vrfname = pim_cli_get_vrf_name(vty); | |
132 | if (vrfname == NULL) | |
133 | return CMD_WARNING_CONFIG_FAILED; | |
134 | ||
135 | snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), | |
136 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
137 | FRR_PIM_AF_XPATH_VAL); | |
138 | strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", | |
139 | sizeof(spt_plist_xpath)); | |
140 | ||
141 | snprintf(spt_action_xpath, sizeof(spt_action_xpath), | |
142 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
143 | FRR_PIM_AF_XPATH_VAL); | |
144 | strlcat(spt_action_xpath, "/spt-switchover/spt-action", | |
145 | sizeof(spt_action_xpath)); | |
146 | ||
147 | nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, | |
148 | "PIM_SPT_INFINITY"); | |
149 | nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_MODIFY, | |
150 | plist); | |
151 | ||
152 | return nb_cli_apply_changes(vty, NULL); | |
153 | } | |
154 | ||
155 | int pim_process_no_spt_switchover_cmd(struct vty *vty) | |
156 | { | |
157 | const char *vrfname; | |
158 | char spt_plist_xpath[XPATH_MAXLEN]; | |
159 | char spt_action_xpath[XPATH_MAXLEN]; | |
160 | ||
161 | vrfname = pim_cli_get_vrf_name(vty); | |
162 | if (vrfname == NULL) | |
163 | return CMD_WARNING_CONFIG_FAILED; | |
164 | ||
165 | snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), | |
166 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
167 | FRR_PIM_AF_XPATH_VAL); | |
168 | strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", | |
169 | sizeof(spt_plist_xpath)); | |
170 | ||
171 | snprintf(spt_action_xpath, sizeof(spt_action_xpath), | |
172 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
173 | FRR_PIM_AF_XPATH_VAL); | |
174 | strlcat(spt_action_xpath, "/spt-switchover/spt-action", | |
175 | sizeof(spt_action_xpath)); | |
176 | ||
177 | nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, NULL); | |
178 | nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, | |
179 | "PIM_SPT_IMMEDIATE"); | |
180 | ||
181 | return nb_cli_apply_changes(vty, NULL); | |
182 | } | |
0da72f1f MR |
183 | |
184 | int pim_process_pim_packet_cmd(struct vty *vty, const char *packet) | |
185 | { | |
186 | char xpath[XPATH_MAXLEN]; | |
187 | ||
188 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
189 | FRR_PIM_AF_XPATH_VAL); | |
190 | strlcat(xpath, "/packets", sizeof(xpath)); | |
191 | ||
192 | nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, packet); | |
193 | ||
194 | return nb_cli_apply_changes(vty, NULL); | |
195 | } | |
196 | ||
197 | int pim_process_no_pim_packet_cmd(struct vty *vty) | |
198 | { | |
199 | char xpath[XPATH_MAXLEN]; | |
200 | ||
201 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
202 | FRR_PIM_AF_XPATH_VAL); | |
203 | strlcat(xpath, "/packets", sizeof(xpath)); | |
204 | ||
205 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
206 | ||
207 | return nb_cli_apply_changes(vty, NULL); | |
208 | } | |
28e32366 MR |
209 | |
210 | int pim_process_keepalivetimer_cmd(struct vty *vty, const char *kat) | |
211 | { | |
212 | const char *vrfname; | |
213 | char ka_timer_xpath[XPATH_MAXLEN]; | |
214 | ||
215 | vrfname = pim_cli_get_vrf_name(vty); | |
216 | if (vrfname == NULL) | |
217 | return CMD_WARNING_CONFIG_FAILED; | |
218 | ||
219 | snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, | |
220 | "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL); | |
221 | strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); | |
222 | ||
223 | nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_MODIFY, | |
224 | kat); | |
225 | ||
226 | return nb_cli_apply_changes(vty, NULL); | |
227 | } | |
228 | ||
229 | int pim_process_no_keepalivetimer_cmd(struct vty *vty) | |
230 | { | |
231 | const char *vrfname; | |
232 | char ka_timer_xpath[XPATH_MAXLEN]; | |
233 | ||
234 | vrfname = pim_cli_get_vrf_name(vty); | |
235 | if (vrfname == NULL) | |
236 | return CMD_WARNING_CONFIG_FAILED; | |
237 | ||
238 | snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, | |
239 | "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL); | |
240 | strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); | |
241 | ||
242 | nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_DESTROY, NULL); | |
243 | ||
244 | return nb_cli_apply_changes(vty, NULL); | |
245 | } | |
2322b991 MR |
246 | |
247 | int pim_process_rp_kat_cmd(struct vty *vty, const char *rpkat) | |
248 | { | |
249 | const char *vrfname; | |
250 | char rp_ka_timer_xpath[XPATH_MAXLEN]; | |
251 | ||
252 | vrfname = pim_cli_get_vrf_name(vty); | |
253 | if (vrfname == NULL) | |
254 | return CMD_WARNING_CONFIG_FAILED; | |
255 | ||
256 | snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), | |
257 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
258 | FRR_PIM_AF_XPATH_VAL); | |
259 | strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", | |
260 | sizeof(rp_ka_timer_xpath)); | |
261 | ||
262 | nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, | |
263 | rpkat); | |
264 | ||
265 | return nb_cli_apply_changes(vty, NULL); | |
266 | } | |
267 | ||
268 | int pim_process_no_rp_kat_cmd(struct vty *vty) | |
269 | { | |
270 | const char *vrfname; | |
271 | char rp_ka_timer[6]; | |
272 | char rp_ka_timer_xpath[XPATH_MAXLEN]; | |
273 | uint v; | |
274 | char rs_timer_xpath[XPATH_MAXLEN]; | |
275 | ||
276 | snprintf(rs_timer_xpath, sizeof(rs_timer_xpath), | |
277 | FRR_PIM_ROUTER_XPATH, FRR_PIM_AF_XPATH_VAL); | |
278 | strlcat(rs_timer_xpath, "/register-suppress-time", | |
279 | sizeof(rs_timer_xpath)); | |
280 | ||
281 | /* RFC4601 */ | |
282 | v = yang_dnode_get_uint16(vty->candidate_config->dnode, | |
283 | rs_timer_xpath); | |
284 | v = 3 * v + PIM_REGISTER_PROBE_TIME_DEFAULT; | |
285 | if (v > UINT16_MAX) | |
286 | v = UINT16_MAX; | |
287 | snprintf(rp_ka_timer, sizeof(rp_ka_timer), "%u", v); | |
288 | ||
289 | vrfname = pim_cli_get_vrf_name(vty); | |
290 | if (vrfname == NULL) | |
291 | return CMD_WARNING_CONFIG_FAILED; | |
292 | ||
293 | snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), | |
294 | FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, | |
295 | FRR_PIM_AF_XPATH_VAL); | |
296 | strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", | |
297 | sizeof(rp_ka_timer_xpath)); | |
298 | ||
299 | nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, | |
300 | rp_ka_timer); | |
301 | ||
302 | return nb_cli_apply_changes(vty, NULL); | |
303 | } | |
18ca7de5 MR |
304 | |
305 | int pim_process_register_suppress_cmd(struct vty *vty, const char *rst) | |
306 | { | |
307 | char xpath[XPATH_MAXLEN]; | |
308 | ||
309 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
310 | FRR_PIM_AF_XPATH_VAL); | |
311 | strlcat(xpath, "/register-suppress-time", sizeof(xpath)); | |
312 | ||
313 | nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, rst); | |
314 | ||
315 | return nb_cli_apply_changes(vty, NULL); | |
316 | } | |
317 | ||
318 | int pim_process_no_register_suppress_cmd(struct vty *vty) | |
319 | { | |
320 | char xpath[XPATH_MAXLEN]; | |
321 | ||
322 | snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, | |
323 | FRR_PIM_AF_XPATH_VAL); | |
324 | strlcat(xpath, "/register-suppress-time", sizeof(xpath)); | |
325 | ||
326 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
327 | ||
328 | return nb_cli_apply_changes(vty, NULL); | |
329 | } | |
a1caf7a8 | 330 | |
331 | int pim_process_ip_pim_cmd(struct vty *vty) | |
332 | { | |
333 | nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, "true"); | |
334 | ||
335 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
336 | FRR_PIM_AF_XPATH_VAL); | |
337 | } | |
338 | ||
339 | int pim_process_no_ip_pim_cmd(struct vty *vty) | |
340 | { | |
341 | const struct lyd_node *mld_enable_dnode; | |
342 | char mld_if_xpath[XPATH_MAXLEN]; | |
343 | ||
344 | int printed = | |
345 | snprintf(mld_if_xpath, sizeof(mld_if_xpath), | |
346 | "%s/frr-gmp:gmp/address-family[address-family='%s']", | |
347 | VTY_CURR_XPATH, FRR_PIM_AF_XPATH_VAL); | |
348 | ||
349 | if (printed >= (int)(sizeof(mld_if_xpath))) { | |
350 | vty_out(vty, "Xpath too long (%d > %u)", printed + 1, | |
351 | XPATH_MAXLEN); | |
352 | return CMD_WARNING_CONFIG_FAILED; | |
353 | } | |
354 | ||
355 | mld_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, | |
356 | FRR_GMP_ENABLE_XPATH, VTY_CURR_XPATH, | |
357 | FRR_PIM_AF_XPATH_VAL); | |
358 | ||
359 | if (!mld_enable_dnode) { | |
360 | nb_cli_enqueue_change(vty, mld_if_xpath, NB_OP_DESTROY, NULL); | |
361 | nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); | |
362 | } else { | |
363 | if (!yang_dnode_get_bool(mld_enable_dnode, ".")) { | |
364 | nb_cli_enqueue_change(vty, mld_if_xpath, NB_OP_DESTROY, | |
365 | NULL); | |
366 | nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); | |
367 | } else | |
368 | nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, | |
369 | "false"); | |
370 | } | |
371 | ||
372 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
373 | FRR_PIM_AF_XPATH_VAL); | |
374 | } | |
bb387611 | 375 | |
376 | int pim_process_ip_pim_drprio_cmd(struct vty *vty, const char *drpriority_str) | |
377 | { | |
378 | nb_cli_enqueue_change(vty, "./dr-priority", NB_OP_MODIFY, | |
379 | drpriority_str); | |
380 | ||
381 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
382 | FRR_PIM_AF_XPATH_VAL); | |
383 | } | |
384 | ||
385 | int pim_process_no_ip_pim_drprio_cmd(struct vty *vty) | |
386 | { | |
387 | nb_cli_enqueue_change(vty, "./dr-priority", NB_OP_DESTROY, NULL); | |
388 | ||
389 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
390 | FRR_PIM_AF_XPATH_VAL); | |
391 | } | |
e6aab613 | 392 | |
393 | int pim_process_ip_pim_hello_cmd(struct vty *vty, const char *hello_str, | |
394 | const char *hold_str) | |
395 | { | |
396 | const struct lyd_node *mld_enable_dnode; | |
397 | ||
398 | mld_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, | |
399 | FRR_GMP_ENABLE_XPATH, VTY_CURR_XPATH, | |
400 | FRR_PIM_AF_XPATH_VAL); | |
401 | ||
402 | if (!mld_enable_dnode) { | |
403 | nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, | |
404 | "true"); | |
405 | } else { | |
406 | if (!yang_dnode_get_bool(mld_enable_dnode, ".")) | |
407 | nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, | |
408 | "true"); | |
409 | } | |
410 | ||
411 | nb_cli_enqueue_change(vty, "./hello-interval", NB_OP_MODIFY, hello_str); | |
412 | ||
413 | if (hold_str) | |
414 | nb_cli_enqueue_change(vty, "./hello-holdtime", NB_OP_MODIFY, | |
415 | hold_str); | |
416 | ||
417 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
418 | FRR_PIM_AF_XPATH_VAL); | |
419 | } | |
420 | ||
421 | int pim_process_no_ip_pim_hello_cmd(struct vty *vty) | |
422 | { | |
423 | nb_cli_enqueue_change(vty, "./hello-interval", NB_OP_DESTROY, NULL); | |
424 | nb_cli_enqueue_change(vty, "./hello-holdtime", NB_OP_DESTROY, NULL); | |
425 | ||
426 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
427 | FRR_PIM_AF_XPATH_VAL); | |
428 | } | |
7e01b641 | 429 | |
430 | int pim_process_ip_pim_activeactive_cmd(struct vty *vty, const char *no) | |
431 | { | |
432 | if (no) | |
433 | nb_cli_enqueue_change(vty, "./active-active", NB_OP_MODIFY, | |
434 | "false"); | |
435 | else { | |
436 | nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, | |
437 | "true"); | |
438 | ||
439 | nb_cli_enqueue_change(vty, "./active-active", NB_OP_MODIFY, | |
440 | "true"); | |
441 | } | |
442 | ||
443 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
444 | FRR_PIM_AF_XPATH_VAL); | |
445 | } | |
52c52d78 | 446 | |
447 | int pim_process_ip_pim_boundary_oil_cmd(struct vty *vty, const char *oil) | |
448 | { | |
449 | nb_cli_enqueue_change(vty, "./multicast-boundary-oil", NB_OP_MODIFY, | |
450 | oil); | |
451 | ||
452 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
453 | FRR_PIM_AF_XPATH_VAL); | |
454 | } | |
455 | ||
456 | int pim_process_no_ip_pim_boundary_oil_cmd(struct vty *vty) | |
457 | { | |
458 | nb_cli_enqueue_change(vty, "./multicast-boundary-oil", NB_OP_DESTROY, | |
459 | NULL); | |
460 | ||
461 | return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH, | |
462 | FRR_PIM_AF_XPATH_VAL); | |
463 | } | |
63ee25c0 | 464 | |
465 | int pim_process_ip_mroute_cmd(struct vty *vty, const char *interface, | |
466 | const char *group_str, const char *source_str) | |
467 | { | |
468 | nb_cli_enqueue_change(vty, "./oif", NB_OP_MODIFY, interface); | |
469 | ||
470 | if (!source_str) { | |
471 | char buf[SRCDEST2STR_BUFFER]; | |
472 | ||
473 | inet_ntop(AF_INET6, &in6addr_any, buf, sizeof(buf)); | |
474 | return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH, | |
475 | FRR_PIM_AF_XPATH_VAL, buf, | |
476 | group_str); | |
477 | } | |
478 | ||
479 | return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH, | |
480 | FRR_PIM_AF_XPATH_VAL, source_str, | |
481 | group_str); | |
482 | } | |
483 | ||
484 | int pim_process_no_ip_mroute_cmd(struct vty *vty, const char *interface, | |
485 | const char *group_str, const char *source_str) | |
486 | { | |
487 | nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); | |
488 | ||
489 | if (!source_str) { | |
490 | char buf[SRCDEST2STR_BUFFER]; | |
491 | ||
492 | inet_ntop(AF_INET6, &in6addr_any, buf, sizeof(buf)); | |
493 | return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH, | |
494 | FRR_PIM_AF_XPATH_VAL, buf, | |
495 | group_str); | |
496 | } | |
497 | ||
498 | return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH, | |
499 | FRR_PIM_AF_XPATH_VAL, source_str, | |
500 | group_str); | |
501 | } | |
13ddf7cf MR |
502 | |
503 | int pim_process_rp_cmd(struct vty *vty, const char *rp_str, | |
504 | const char *group_str) | |
505 | { | |
506 | const char *vrfname; | |
507 | char rp_group_xpath[XPATH_MAXLEN]; | |
508 | int result = 0; | |
509 | struct prefix group; | |
a96942ca | 510 | pim_addr rp_addr; |
13ddf7cf MR |
511 | |
512 | result = str2prefix(group_str, &group); | |
513 | if (result) { | |
514 | struct prefix temp; | |
515 | ||
516 | prefix_copy(&temp, &group); | |
517 | apply_mask(&temp); | |
518 | if (!prefix_same(&group, &temp)) { | |
519 | vty_out(vty, "%% Inconsistent address and mask: %s\n", | |
520 | group_str); | |
521 | return CMD_WARNING_CONFIG_FAILED; | |
522 | } | |
523 | } | |
524 | ||
525 | if (!result) { | |
526 | vty_out(vty, "%% Bad group address specified: %s\n", group_str); | |
527 | return CMD_WARNING_CONFIG_FAILED; | |
528 | } | |
529 | ||
a96942ca | 530 | result = inet_pton(PIM_AF, rp_str, &rp_addr); |
13ddf7cf MR |
531 | if (result <= 0) { |
532 | vty_out(vty, "%% Bad RP address specified: %s\n", rp_str); | |
533 | return CMD_WARNING_CONFIG_FAILED; | |
534 | } | |
535 | ||
536 | vrfname = pim_cli_get_vrf_name(vty); | |
537 | if (vrfname == NULL) | |
538 | return CMD_WARNING_CONFIG_FAILED; | |
539 | ||
540 | snprintf(rp_group_xpath, sizeof(rp_group_xpath), | |
a96942ca MR |
541 | FRR_PIM_STATIC_RP_XPATH, "frr-pim:pimd", "pim", vrfname, |
542 | FRR_PIM_AF_XPATH_VAL, rp_str); | |
13ddf7cf MR |
543 | strlcat(rp_group_xpath, "/group-list", sizeof(rp_group_xpath)); |
544 | ||
545 | nb_cli_enqueue_change(vty, rp_group_xpath, NB_OP_CREATE, group_str); | |
546 | ||
547 | return nb_cli_apply_changes(vty, NULL); | |
548 | } | |
549 | ||
550 | int pim_process_no_rp_cmd(struct vty *vty, const char *rp_str, | |
551 | const char *group_str) | |
552 | { | |
553 | char group_list_xpath[XPATH_MAXLEN]; | |
554 | char group_xpath[XPATH_MAXLEN]; | |
555 | char rp_xpath[XPATH_MAXLEN]; | |
556 | int printed; | |
557 | const char *vrfname; | |
558 | const struct lyd_node *group_dnode; | |
559 | ||
560 | vrfname = pim_cli_get_vrf_name(vty); | |
561 | if (vrfname == NULL) | |
562 | return CMD_WARNING_CONFIG_FAILED; | |
563 | ||
564 | snprintf(rp_xpath, sizeof(rp_xpath), FRR_PIM_STATIC_RP_XPATH, | |
a96942ca | 565 | "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL, rp_str); |
13ddf7cf MR |
566 | |
567 | printed = snprintf(group_list_xpath, sizeof(group_list_xpath), | |
568 | "%s/group-list", rp_xpath); | |
569 | ||
570 | if (printed >= (int)(sizeof(group_list_xpath))) { | |
571 | vty_out(vty, "Xpath too long (%d > %u)", printed + 1, | |
572 | XPATH_MAXLEN); | |
573 | return CMD_WARNING_CONFIG_FAILED; | |
574 | } | |
575 | ||
576 | printed = snprintf(group_xpath, sizeof(group_xpath), "%s[.='%s']", | |
577 | group_list_xpath, group_str); | |
578 | ||
579 | if (printed >= (int)(sizeof(group_xpath))) { | |
580 | vty_out(vty, "Xpath too long (%d > %u)", printed + 1, | |
581 | XPATH_MAXLEN); | |
582 | return CMD_WARNING_CONFIG_FAILED; | |
583 | } | |
584 | ||
ea5f4c4c MR |
585 | group_dnode = yang_dnode_get(vty->candidate_config->dnode, group_xpath); |
586 | if (!group_dnode) { | |
13ddf7cf MR |
587 | vty_out(vty, "%% Unable to find specified RP\n"); |
588 | return NB_OK; | |
589 | } | |
590 | ||
13ddf7cf MR |
591 | if (yang_is_last_list_dnode(group_dnode)) |
592 | nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL); | |
593 | else | |
594 | nb_cli_enqueue_change(vty, group_list_xpath, NB_OP_DESTROY, | |
595 | group_str); | |
596 | ||
597 | return nb_cli_apply_changes(vty, NULL); | |
598 | } | |
f39f3497 MR |
599 | |
600 | int pim_process_rp_plist_cmd(struct vty *vty, const char *rp_str, | |
601 | const char *prefix_list) | |
602 | { | |
603 | const char *vrfname; | |
604 | char rp_plist_xpath[XPATH_MAXLEN]; | |
605 | ||
606 | vrfname = pim_cli_get_vrf_name(vty); | |
607 | if (vrfname == NULL) | |
608 | return CMD_WARNING_CONFIG_FAILED; | |
609 | ||
610 | snprintf(rp_plist_xpath, sizeof(rp_plist_xpath), | |
611 | FRR_PIM_STATIC_RP_XPATH, "frr-pim:pimd", "pim", vrfname, | |
612 | FRR_PIM_AF_XPATH_VAL, rp_str); | |
613 | strlcat(rp_plist_xpath, "/prefix-list", sizeof(rp_plist_xpath)); | |
614 | ||
615 | nb_cli_enqueue_change(vty, rp_plist_xpath, NB_OP_MODIFY, prefix_list); | |
616 | ||
617 | return nb_cli_apply_changes(vty, NULL); | |
618 | } | |
619 | ||
620 | int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str, | |
621 | const char *prefix_list) | |
622 | { | |
623 | char rp_xpath[XPATH_MAXLEN]; | |
624 | char plist_xpath[XPATH_MAXLEN]; | |
625 | const char *vrfname; | |
626 | const struct lyd_node *plist_dnode; | |
627 | const char *plist; | |
628 | ||
629 | vrfname = pim_cli_get_vrf_name(vty); | |
630 | if (vrfname == NULL) | |
631 | return CMD_WARNING_CONFIG_FAILED; | |
632 | ||
633 | snprintf(rp_xpath, sizeof(rp_xpath), FRR_PIM_STATIC_RP_XPATH, | |
634 | "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL, rp_str); | |
635 | ||
636 | snprintf(plist_xpath, sizeof(plist_xpath), FRR_PIM_STATIC_RP_XPATH, | |
637 | "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL, rp_str); | |
638 | strlcat(plist_xpath, "/prefix-list", sizeof(plist_xpath)); | |
639 | ||
640 | plist_dnode = yang_dnode_get(vty->candidate_config->dnode, plist_xpath); | |
641 | if (!plist_dnode) { | |
642 | vty_out(vty, "%% Unable to find specified RP\n"); | |
643 | return NB_OK; | |
644 | } | |
645 | ||
646 | plist = yang_dnode_get_string(plist_dnode, plist_xpath); | |
647 | if (strcmp(prefix_list, plist)) { | |
648 | vty_out(vty, "%% Unable to find specified RP\n"); | |
649 | return NB_OK; | |
650 | } | |
651 | ||
652 | nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL); | |
653 | ||
654 | return nb_cli_apply_changes(vty, NULL); | |
655 | } |