]>
Commit | Line | Data |
---|---|---|
f495425b QY |
1 | /* |
2 | * VRRP northbound bindings. | |
3 | * Copyright (C) 2019 Cumulus Networks, Inc. | |
4 | * Quentin Young | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation; either version 2 of the License, or (at your option) | |
9 | * any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * 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 "if.h" | |
24 | #include "log.h" | |
25 | #include "prefix.h" | |
26 | #include "table.h" | |
27 | #include "command.h" | |
28 | #include "northbound.h" | |
29 | #include "libfrr.h" | |
30 | #include "vrrp.h" | |
31 | #include "vrrp_vty.h" | |
32 | ||
33 | /* | |
34 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group | |
35 | */ | |
60ee8be1 | 36 | static int lib_interface_vrrp_vrrp_group_create(struct nb_cb_create_args *args) |
f495425b QY |
37 | { |
38 | struct interface *ifp; | |
39 | uint8_t vrid; | |
40 | uint8_t version = 3; | |
41 | struct vrrp_vrouter *vr; | |
42 | ||
60ee8be1 | 43 | if (args->event != NB_EV_APPLY) |
f495425b QY |
44 | return NB_OK; |
45 | ||
60ee8be1 RW |
46 | ifp = nb_running_get_entry(args->dnode, NULL, true); |
47 | vrid = yang_dnode_get_uint8(args->dnode, "./virtual-router-id"); | |
48 | version = yang_dnode_get_enum(args->dnode, "./version"); | |
f495425b | 49 | vr = vrrp_vrouter_create(ifp, vrid, version); |
60ee8be1 | 50 | nb_running_set_entry(args->dnode, vr); |
f495425b QY |
51 | |
52 | return NB_OK; | |
53 | } | |
54 | ||
60ee8be1 RW |
55 | static int |
56 | lib_interface_vrrp_vrrp_group_destroy(struct nb_cb_destroy_args *args) | |
f495425b QY |
57 | { |
58 | struct vrrp_vrouter *vr; | |
59 | ||
60ee8be1 | 60 | if (args->event != NB_EV_APPLY) |
f495425b QY |
61 | return NB_OK; |
62 | ||
60ee8be1 | 63 | vr = nb_running_unset_entry(args->dnode); |
f495425b QY |
64 | vrrp_vrouter_destroy(vr); |
65 | ||
66 | return NB_OK; | |
67 | } | |
68 | ||
69 | static const void * | |
60ee8be1 | 70 | lib_interface_vrrp_vrrp_group_get_next(struct nb_cb_get_next_args *args) |
f495425b QY |
71 | { |
72 | struct list *l = hash_to_list(vrrp_vrouters_hash); | |
73 | struct listnode *ln; | |
6356b286 | 74 | const struct vrrp_vrouter *curr; |
60ee8be1 | 75 | const struct interface *ifp = args->parent_list_entry; |
f495425b | 76 | |
f495425b QY |
77 | /* |
78 | * If list_entry is null, we return the first vrrp instance with a | |
79 | * matching interface | |
80 | */ | |
60ee8be1 | 81 | bool nextone = args->list_entry ? false : true; |
f495425b QY |
82 | |
83 | for (ALL_LIST_ELEMENTS_RO(l, ln, curr)) { | |
60ee8be1 | 84 | if (curr == args->list_entry) { |
f495425b QY |
85 | nextone = true; |
86 | continue; | |
87 | } | |
88 | ||
89 | if (nextone && curr->ifp == ifp) | |
90 | goto done; | |
f495425b QY |
91 | } |
92 | ||
93 | curr = NULL; | |
94 | ||
95 | done: | |
96 | list_delete(&l); | |
97 | return curr; | |
98 | } | |
99 | ||
60ee8be1 RW |
100 | static int |
101 | lib_interface_vrrp_vrrp_group_get_keys(struct nb_cb_get_keys_args *args) | |
f495425b | 102 | { |
60ee8be1 | 103 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 104 | |
60ee8be1 RW |
105 | args->keys->num = 1; |
106 | snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%" PRIu32, | |
107 | vr->vrid); | |
f495425b QY |
108 | |
109 | return NB_OK; | |
110 | } | |
111 | ||
112 | static const void * | |
60ee8be1 | 113 | lib_interface_vrrp_vrrp_group_lookup_entry(struct nb_cb_lookup_entry_args *args) |
f495425b | 114 | { |
60ee8be1 RW |
115 | uint32_t vrid = strtoul(args->keys->key[0], NULL, 10); |
116 | const struct interface *ifp = args->parent_list_entry; | |
f495425b | 117 | |
534b98f9 | 118 | return vrrp_lookup(ifp, vrid); |
f495425b QY |
119 | } |
120 | ||
121 | /* | |
122 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/version | |
123 | */ | |
124 | static int | |
60ee8be1 | 125 | lib_interface_vrrp_vrrp_group_version_modify(struct nb_cb_modify_args *args) |
f495425b | 126 | { |
60ee8be1 | 127 | if (args->event != NB_EV_APPLY) |
f495425b QY |
128 | return NB_OK; |
129 | ||
130 | struct vrrp_vrouter *vr; | |
131 | uint8_t version; | |
132 | ||
60ee8be1 | 133 | vr = nb_running_get_entry(args->dnode, NULL, true); |
f495425b QY |
134 | vrrp_event(vr->v4, VRRP_EVENT_SHUTDOWN); |
135 | vrrp_event(vr->v6, VRRP_EVENT_SHUTDOWN); | |
60ee8be1 | 136 | version = yang_dnode_get_enum(args->dnode, NULL); |
f495425b QY |
137 | vr->version = version; |
138 | ||
139 | vrrp_check_start(vr); | |
140 | ||
141 | return NB_OK; | |
142 | } | |
143 | ||
534b98f9 QY |
144 | /* |
145 | * Helper function for address list OP_MODIFY callbacks. | |
146 | */ | |
f495425b QY |
147 | static void vrrp_yang_add_del_virtual_address(const struct lyd_node *dnode, |
148 | bool add) | |
149 | { | |
150 | struct vrrp_vrouter *vr; | |
151 | struct ipaddr ip; | |
152 | ||
153 | vr = nb_running_get_entry(dnode, NULL, true); | |
154 | yang_dnode_get_ip(&ip, dnode, NULL); | |
155 | if (add) | |
156 | vrrp_add_ip(vr, &ip); | |
157 | else | |
158 | vrrp_del_ip(vr, &ip); | |
159 | ||
160 | vrrp_check_start(vr); | |
161 | } | |
162 | ||
f495425b QY |
163 | /* |
164 | * XPath: | |
165 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/virtual-address | |
166 | */ | |
167 | static int lib_interface_vrrp_vrrp_group_v4_virtual_address_create( | |
60ee8be1 | 168 | struct nb_cb_create_args *args) |
f495425b | 169 | { |
60ee8be1 | 170 | if (args->event != NB_EV_APPLY) |
f495425b QY |
171 | return NB_OK; |
172 | ||
60ee8be1 | 173 | vrrp_yang_add_del_virtual_address(args->dnode, true); |
f495425b QY |
174 | |
175 | return NB_OK; | |
176 | } | |
177 | ||
178 | static int lib_interface_vrrp_vrrp_group_v4_virtual_address_destroy( | |
60ee8be1 | 179 | struct nb_cb_destroy_args *args) |
f495425b | 180 | { |
60ee8be1 | 181 | if (args->event != NB_EV_APPLY) |
f495425b QY |
182 | return NB_OK; |
183 | ||
60ee8be1 | 184 | vrrp_yang_add_del_virtual_address(args->dnode, false); |
f495425b QY |
185 | |
186 | return NB_OK; | |
187 | } | |
188 | ||
189 | /* | |
190 | * XPath: | |
191 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/current-priority | |
192 | */ | |
193 | static struct yang_data * | |
194 | lib_interface_vrrp_vrrp_group_v4_current_priority_get_elem( | |
60ee8be1 | 195 | struct nb_cb_get_elem_args *args) |
f495425b | 196 | { |
60ee8be1 | 197 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 198 | |
60ee8be1 | 199 | return yang_data_new_uint8(args->xpath, vr->v4->priority); |
f495425b QY |
200 | } |
201 | ||
202 | /* | |
203 | * XPath: | |
204 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/vrrp-interface | |
205 | */ | |
206 | static struct yang_data * | |
60ee8be1 RW |
207 | lib_interface_vrrp_vrrp_group_v4_vrrp_interface_get_elem( |
208 | struct nb_cb_get_elem_args *args) | |
f495425b | 209 | { |
60ee8be1 | 210 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b QY |
211 | |
212 | struct yang_data *val = NULL; | |
213 | ||
214 | if (vr->v4->mvl_ifp) | |
60ee8be1 | 215 | val = yang_data_new_string(args->xpath, vr->v4->mvl_ifp->name); |
f495425b QY |
216 | |
217 | return val; | |
218 | } | |
219 | ||
220 | /* | |
221 | * XPath: | |
222 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/source-address | |
223 | */ | |
224 | static struct yang_data * | |
60ee8be1 RW |
225 | lib_interface_vrrp_vrrp_group_v4_source_address_get_elem( |
226 | struct nb_cb_get_elem_args *args) | |
f495425b | 227 | { |
60ee8be1 | 228 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b QY |
229 | struct yang_data *val = NULL; |
230 | struct ipaddr ip; | |
231 | ||
232 | memset(&ip, 0x00, sizeof(ip)); | |
233 | ||
234 | if (memcmp(&vr->v4->src.ipaddr_v4, &ip.ipaddr_v4, sizeof(ip.ipaddr_v4))) | |
60ee8be1 | 235 | val = yang_data_new_ip(args->xpath, &vr->v4->src); |
f495425b QY |
236 | |
237 | return val; | |
238 | } | |
239 | ||
240 | /* | |
241 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/state | |
242 | */ | |
60ee8be1 RW |
243 | static struct yang_data *lib_interface_vrrp_vrrp_group_v4_state_get_elem( |
244 | struct nb_cb_get_elem_args *args) | |
f495425b | 245 | { |
60ee8be1 | 246 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 247 | |
60ee8be1 | 248 | return yang_data_new_enum(args->xpath, vr->v4->fsm.state); |
f495425b QY |
249 | } |
250 | ||
251 | /* | |
252 | * XPath: | |
253 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/master-advertisement-interval | |
254 | */ | |
255 | static struct yang_data * | |
256 | lib_interface_vrrp_vrrp_group_v4_master_advertisement_interval_get_elem( | |
60ee8be1 | 257 | struct nb_cb_get_elem_args *args) |
f495425b | 258 | { |
60ee8be1 | 259 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 260 | |
60ee8be1 | 261 | return yang_data_new_uint16(args->xpath, vr->v4->master_adver_interval); |
f495425b QY |
262 | } |
263 | ||
264 | /* | |
265 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/skew-time | |
266 | */ | |
60ee8be1 RW |
267 | static struct yang_data *lib_interface_vrrp_vrrp_group_v4_skew_time_get_elem( |
268 | struct nb_cb_get_elem_args *args) | |
f495425b | 269 | { |
60ee8be1 | 270 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 271 | |
60ee8be1 | 272 | return yang_data_new_uint16(args->xpath, vr->v4->skew_time); |
f495425b QY |
273 | } |
274 | ||
275 | /* | |
276 | * XPath: | |
277 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/state-transition | |
278 | */ | |
279 | static struct yang_data * | |
280 | lib_interface_vrrp_vrrp_group_v4_counter_state_transition_get_elem( | |
60ee8be1 | 281 | struct nb_cb_get_elem_args *args) |
f495425b | 282 | { |
60ee8be1 | 283 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 284 | |
60ee8be1 | 285 | return yang_data_new_uint32(args->xpath, vr->v4->stats.trans_cnt); |
f495425b QY |
286 | } |
287 | ||
288 | /* | |
289 | * XPath: | |
290 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/tx/advertisement | |
291 | */ | |
292 | static struct yang_data * | |
293 | lib_interface_vrrp_vrrp_group_v4_counter_tx_advertisement_get_elem( | |
60ee8be1 | 294 | struct nb_cb_get_elem_args *args) |
f495425b | 295 | { |
60ee8be1 | 296 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 297 | |
60ee8be1 | 298 | return yang_data_new_uint32(args->xpath, vr->v4->stats.adver_tx_cnt); |
f495425b QY |
299 | } |
300 | ||
301 | /* | |
302 | * XPath: | |
303 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/tx/gratuitous-arp | |
304 | */ | |
305 | static struct yang_data * | |
306 | lib_interface_vrrp_vrrp_group_v4_counter_tx_gratuitous_arp_get_elem( | |
60ee8be1 | 307 | struct nb_cb_get_elem_args *args) |
f495425b | 308 | { |
60ee8be1 | 309 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 310 | |
60ee8be1 | 311 | return yang_data_new_uint32(args->xpath, vr->v4->stats.garp_tx_cnt); |
f495425b QY |
312 | } |
313 | ||
314 | /* | |
315 | * XPath: | |
316 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/rx/advertisement | |
317 | */ | |
318 | static struct yang_data * | |
319 | lib_interface_vrrp_vrrp_group_v4_counter_rx_advertisement_get_elem( | |
60ee8be1 | 320 | struct nb_cb_get_elem_args *args) |
f495425b | 321 | { |
60ee8be1 | 322 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 323 | |
60ee8be1 | 324 | return yang_data_new_uint32(args->xpath, vr->v4->stats.adver_rx_cnt); |
f495425b QY |
325 | } |
326 | ||
327 | /* | |
328 | * XPath: | |
329 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/virtual-address | |
330 | */ | |
331 | static int lib_interface_vrrp_vrrp_group_v6_virtual_address_create( | |
60ee8be1 | 332 | struct nb_cb_create_args *args) |
f495425b | 333 | { |
60ee8be1 | 334 | if (args->event != NB_EV_APPLY) |
f495425b QY |
335 | return NB_OK; |
336 | ||
60ee8be1 | 337 | vrrp_yang_add_del_virtual_address(args->dnode, true); |
f495425b QY |
338 | |
339 | return NB_OK; | |
340 | } | |
341 | ||
342 | static int lib_interface_vrrp_vrrp_group_v6_virtual_address_destroy( | |
60ee8be1 | 343 | struct nb_cb_destroy_args *args) |
f495425b | 344 | { |
60ee8be1 | 345 | if (args->event != NB_EV_APPLY) |
f495425b QY |
346 | return NB_OK; |
347 | ||
60ee8be1 | 348 | vrrp_yang_add_del_virtual_address(args->dnode, false); |
f495425b QY |
349 | |
350 | return NB_OK; | |
351 | } | |
352 | ||
353 | /* | |
354 | * XPath: | |
355 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/current-priority | |
356 | */ | |
357 | static struct yang_data * | |
358 | lib_interface_vrrp_vrrp_group_v6_current_priority_get_elem( | |
60ee8be1 | 359 | struct nb_cb_get_elem_args *args) |
f495425b | 360 | { |
60ee8be1 | 361 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 362 | |
60ee8be1 | 363 | return yang_data_new_uint8(args->xpath, vr->v6->priority); |
f495425b QY |
364 | } |
365 | ||
366 | /* | |
367 | * XPath: | |
368 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/vrrp-interface | |
369 | */ | |
370 | static struct yang_data * | |
60ee8be1 RW |
371 | lib_interface_vrrp_vrrp_group_v6_vrrp_interface_get_elem( |
372 | struct nb_cb_get_elem_args *args) | |
f495425b | 373 | { |
60ee8be1 | 374 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b QY |
375 | struct yang_data *val = NULL; |
376 | ||
377 | if (vr->v6->mvl_ifp) | |
60ee8be1 | 378 | val = yang_data_new_string(args->xpath, vr->v6->mvl_ifp->name); |
f495425b QY |
379 | |
380 | return val; | |
381 | } | |
382 | ||
383 | /* | |
384 | * XPath: | |
385 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/source-address | |
386 | */ | |
387 | static struct yang_data * | |
60ee8be1 RW |
388 | lib_interface_vrrp_vrrp_group_v6_source_address_get_elem( |
389 | struct nb_cb_get_elem_args *args) | |
f495425b | 390 | { |
60ee8be1 | 391 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 392 | struct yang_data *val = NULL; |
f495425b | 393 | |
534b98f9 | 394 | if (ipaddr_isset(&vr->v6->src)) |
60ee8be1 | 395 | val = yang_data_new_ip(args->xpath, &vr->v6->src); |
f495425b QY |
396 | |
397 | return val; | |
398 | } | |
399 | ||
400 | /* | |
401 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/state | |
402 | */ | |
60ee8be1 RW |
403 | static struct yang_data *lib_interface_vrrp_vrrp_group_v6_state_get_elem( |
404 | struct nb_cb_get_elem_args *args) | |
f495425b | 405 | { |
60ee8be1 | 406 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 407 | |
60ee8be1 | 408 | return yang_data_new_enum(args->xpath, vr->v6->fsm.state); |
f495425b QY |
409 | } |
410 | ||
411 | /* | |
412 | * XPath: | |
413 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/master-advertisement-interval | |
414 | */ | |
415 | static struct yang_data * | |
416 | lib_interface_vrrp_vrrp_group_v6_master_advertisement_interval_get_elem( | |
60ee8be1 | 417 | struct nb_cb_get_elem_args *args) |
f495425b | 418 | { |
60ee8be1 | 419 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 420 | |
60ee8be1 | 421 | return yang_data_new_uint16(args->xpath, vr->v6->master_adver_interval); |
f495425b QY |
422 | } |
423 | ||
424 | /* | |
425 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/skew-time | |
426 | */ | |
60ee8be1 RW |
427 | static struct yang_data *lib_interface_vrrp_vrrp_group_v6_skew_time_get_elem( |
428 | struct nb_cb_get_elem_args *args) | |
f495425b | 429 | { |
60ee8be1 | 430 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 431 | |
60ee8be1 | 432 | return yang_data_new_uint16(args->xpath, vr->v6->skew_time); |
f495425b QY |
433 | } |
434 | ||
435 | /* | |
436 | * XPath: | |
437 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/state-transition | |
438 | */ | |
439 | static struct yang_data * | |
440 | lib_interface_vrrp_vrrp_group_v6_counter_state_transition_get_elem( | |
60ee8be1 | 441 | struct nb_cb_get_elem_args *args) |
f495425b | 442 | { |
60ee8be1 | 443 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 444 | |
60ee8be1 | 445 | return yang_data_new_uint32(args->xpath, vr->v6->stats.trans_cnt); |
f495425b QY |
446 | } |
447 | ||
448 | /* | |
449 | * XPath: | |
450 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/tx/advertisement | |
451 | */ | |
452 | static struct yang_data * | |
453 | lib_interface_vrrp_vrrp_group_v6_counter_tx_advertisement_get_elem( | |
60ee8be1 | 454 | struct nb_cb_get_elem_args *args) |
f495425b | 455 | { |
60ee8be1 | 456 | const struct vrrp_vrouter *vr = args->list_entry; |
f495425b | 457 | |
60ee8be1 | 458 | return yang_data_new_uint32(args->xpath, vr->v6->stats.adver_tx_cnt); |
f495425b QY |
459 | } |
460 | ||
461 | /* | |
462 | * XPath: | |
463 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/tx/neighbor-advertisement | |
464 | */ | |
465 | static struct yang_data * | |
466 | lib_interface_vrrp_vrrp_group_v6_counter_tx_neighbor_advertisement_get_elem( | |
60ee8be1 | 467 | struct nb_cb_get_elem_args *args) |
f495425b QY |
468 | { |
469 | /* TODO: implement me. */ | |
470 | return NULL; | |
471 | } | |
472 | ||
473 | /* | |
474 | * XPath: | |
475 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/rx/advertisement | |
476 | */ | |
477 | static struct yang_data * | |
478 | lib_interface_vrrp_vrrp_group_v6_counter_rx_advertisement_get_elem( | |
60ee8be1 | 479 | struct nb_cb_get_elem_args *args) |
f495425b QY |
480 | { |
481 | /* TODO: implement me. */ | |
482 | return NULL; | |
483 | } | |
484 | ||
485 | /* | |
486 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority | |
487 | */ | |
488 | static int | |
60ee8be1 | 489 | lib_interface_vrrp_vrrp_group_priority_modify(struct nb_cb_modify_args *args) |
f495425b | 490 | { |
60ee8be1 | 491 | if (args->event != NB_EV_APPLY) |
f495425b QY |
492 | return NB_OK; |
493 | ||
494 | struct vrrp_vrouter *vr; | |
495 | uint8_t priority; | |
496 | ||
60ee8be1 RW |
497 | vr = nb_running_get_entry(args->dnode, NULL, true); |
498 | priority = yang_dnode_get_uint8(args->dnode, NULL); | |
f495425b QY |
499 | vrrp_set_priority(vr, priority); |
500 | ||
501 | return NB_OK; | |
502 | } | |
503 | ||
504 | /* | |
505 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/preempt | |
506 | */ | |
507 | static int | |
60ee8be1 | 508 | lib_interface_vrrp_vrrp_group_preempt_modify(struct nb_cb_modify_args *args) |
f495425b | 509 | { |
60ee8be1 | 510 | if (args->event != NB_EV_APPLY) |
f495425b QY |
511 | return NB_OK; |
512 | ||
513 | struct vrrp_vrouter *vr; | |
514 | bool preempt; | |
515 | ||
60ee8be1 RW |
516 | vr = nb_running_get_entry(args->dnode, NULL, true); |
517 | preempt = yang_dnode_get_bool(args->dnode, NULL); | |
f495425b QY |
518 | vr->preempt_mode = preempt; |
519 | ||
520 | return NB_OK; | |
521 | } | |
522 | ||
523 | /* | |
524 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/accept-mode | |
525 | */ | |
526 | static int | |
60ee8be1 | 527 | lib_interface_vrrp_vrrp_group_accept_mode_modify(struct nb_cb_modify_args *args) |
f495425b | 528 | { |
60ee8be1 | 529 | if (args->event != NB_EV_APPLY) |
f495425b QY |
530 | return NB_OK; |
531 | ||
532 | struct vrrp_vrouter *vr; | |
533 | bool accept; | |
534 | ||
60ee8be1 RW |
535 | vr = nb_running_get_entry(args->dnode, NULL, true); |
536 | accept = yang_dnode_get_bool(args->dnode, NULL); | |
f495425b QY |
537 | vr->accept_mode = accept; |
538 | ||
539 | return NB_OK; | |
540 | } | |
541 | ||
542 | /* | |
543 | * XPath: | |
544 | * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval | |
545 | */ | |
546 | static int lib_interface_vrrp_vrrp_group_advertisement_interval_modify( | |
60ee8be1 | 547 | struct nb_cb_modify_args *args) |
f495425b | 548 | { |
60ee8be1 | 549 | if (args->event != NB_EV_APPLY) |
f495425b QY |
550 | return NB_OK; |
551 | ||
552 | struct vrrp_vrouter *vr; | |
553 | uint16_t advert_int; | |
554 | ||
60ee8be1 RW |
555 | vr = nb_running_get_entry(args->dnode, NULL, true); |
556 | advert_int = yang_dnode_get_uint16(args->dnode, NULL); | |
f495425b QY |
557 | vrrp_set_advertisement_interval(vr, advert_int); |
558 | ||
559 | return NB_OK; | |
560 | } | |
561 | ||
562 | /* | |
563 | * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/shutdown | |
564 | */ | |
565 | static int | |
60ee8be1 | 566 | lib_interface_vrrp_vrrp_group_shutdown_modify(struct nb_cb_modify_args *args) |
f495425b | 567 | { |
60ee8be1 | 568 | if (args->event != NB_EV_APPLY) |
f495425b QY |
569 | return NB_OK; |
570 | ||
571 | struct vrrp_vrouter *vr; | |
572 | bool shutdown; | |
573 | ||
60ee8be1 RW |
574 | vr = nb_running_get_entry(args->dnode, NULL, true); |
575 | shutdown = yang_dnode_get_bool(args->dnode, NULL); | |
f495425b QY |
576 | |
577 | vr->shutdown = shutdown; | |
578 | ||
579 | if (shutdown) { | |
580 | vrrp_event(vr->v4, VRRP_EVENT_SHUTDOWN); | |
581 | vrrp_event(vr->v6, VRRP_EVENT_SHUTDOWN); | |
582 | } else { | |
583 | vrrp_check_start(vr); | |
584 | } | |
585 | ||
586 | return NB_OK; | |
587 | } | |
588 | ||
589 | /* clang-format off */ | |
590 | const struct frr_yang_module_info frr_vrrpd_info = { | |
591 | .name = "frr-vrrpd", | |
592 | .nodes = { | |
593 | { | |
594 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group", | |
595 | .cbs = { | |
596 | .create = lib_interface_vrrp_vrrp_group_create, | |
597 | .destroy = lib_interface_vrrp_vrrp_group_destroy, | |
598 | .get_next = lib_interface_vrrp_vrrp_group_get_next, | |
599 | .get_keys = lib_interface_vrrp_vrrp_group_get_keys, | |
600 | .lookup_entry = lib_interface_vrrp_vrrp_group_lookup_entry, | |
601 | .cli_show = cli_show_vrrp, | |
602 | } | |
603 | }, | |
604 | { | |
605 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/version", | |
606 | .cbs = { | |
607 | .modify = lib_interface_vrrp_vrrp_group_version_modify, | |
608 | } | |
609 | }, | |
610 | { | |
611 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority", | |
612 | .cbs = { | |
613 | .modify = lib_interface_vrrp_vrrp_group_priority_modify, | |
614 | .cli_show = cli_show_priority, | |
615 | } | |
616 | }, | |
617 | { | |
618 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/preempt", | |
619 | .cbs = { | |
620 | .modify = lib_interface_vrrp_vrrp_group_preempt_modify, | |
621 | .cli_show = cli_show_preempt, | |
622 | } | |
623 | }, | |
624 | { | |
625 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/accept-mode", | |
626 | .cbs = { | |
627 | .modify = lib_interface_vrrp_vrrp_group_accept_mode_modify, | |
628 | } | |
629 | }, | |
630 | { | |
631 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval", | |
632 | .cbs = { | |
633 | .modify = lib_interface_vrrp_vrrp_group_advertisement_interval_modify, | |
634 | .cli_show = cli_show_advertisement_interval, | |
635 | } | |
636 | }, | |
637 | { | |
638 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/shutdown", | |
639 | .cbs = { | |
640 | .modify = lib_interface_vrrp_vrrp_group_shutdown_modify, | |
641 | .cli_show = cli_show_shutdown, | |
642 | } | |
643 | }, | |
644 | { | |
645 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/virtual-address", | |
646 | .cbs = { | |
647 | .create = lib_interface_vrrp_vrrp_group_v4_virtual_address_create, | |
648 | .destroy = lib_interface_vrrp_vrrp_group_v4_virtual_address_destroy, | |
649 | .cli_show = cli_show_ip, | |
650 | } | |
651 | }, | |
652 | { | |
653 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/current-priority", | |
654 | .cbs = { | |
655 | .get_elem = lib_interface_vrrp_vrrp_group_v4_current_priority_get_elem, | |
656 | } | |
657 | }, | |
658 | { | |
659 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/vrrp-interface", | |
660 | .cbs = { | |
661 | .get_elem = lib_interface_vrrp_vrrp_group_v4_vrrp_interface_get_elem, | |
662 | } | |
663 | }, | |
664 | { | |
665 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/source-address", | |
666 | .cbs = { | |
667 | .get_elem = lib_interface_vrrp_vrrp_group_v4_source_address_get_elem, | |
668 | } | |
669 | }, | |
670 | { | |
671 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/state", | |
672 | .cbs = { | |
673 | .get_elem = lib_interface_vrrp_vrrp_group_v4_state_get_elem, | |
674 | } | |
675 | }, | |
676 | { | |
677 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/master-advertisement-interval", | |
678 | .cbs = { | |
679 | .get_elem = lib_interface_vrrp_vrrp_group_v4_master_advertisement_interval_get_elem, | |
680 | } | |
681 | }, | |
682 | { | |
683 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/skew-time", | |
684 | .cbs = { | |
685 | .get_elem = lib_interface_vrrp_vrrp_group_v4_skew_time_get_elem, | |
686 | } | |
687 | }, | |
688 | { | |
689 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/state-transition", | |
690 | .cbs = { | |
691 | .get_elem = lib_interface_vrrp_vrrp_group_v4_counter_state_transition_get_elem, | |
692 | } | |
693 | }, | |
694 | { | |
695 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/tx/advertisement", | |
696 | .cbs = { | |
697 | .get_elem = lib_interface_vrrp_vrrp_group_v4_counter_tx_advertisement_get_elem, | |
698 | } | |
699 | }, | |
700 | { | |
701 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/tx/gratuitous-arp", | |
702 | .cbs = { | |
703 | .get_elem = lib_interface_vrrp_vrrp_group_v4_counter_tx_gratuitous_arp_get_elem, | |
704 | } | |
705 | }, | |
706 | { | |
707 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/counter/rx/advertisement", | |
708 | .cbs = { | |
709 | .get_elem = lib_interface_vrrp_vrrp_group_v4_counter_rx_advertisement_get_elem, | |
710 | } | |
711 | }, | |
712 | { | |
713 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/virtual-address", | |
714 | .cbs = { | |
715 | .create = lib_interface_vrrp_vrrp_group_v6_virtual_address_create, | |
716 | .destroy = lib_interface_vrrp_vrrp_group_v6_virtual_address_destroy, | |
717 | .cli_show = cli_show_ipv6, | |
718 | } | |
719 | }, | |
720 | { | |
721 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/current-priority", | |
722 | .cbs = { | |
723 | .get_elem = lib_interface_vrrp_vrrp_group_v6_current_priority_get_elem, | |
724 | } | |
725 | }, | |
726 | { | |
727 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/vrrp-interface", | |
728 | .cbs = { | |
729 | .get_elem = lib_interface_vrrp_vrrp_group_v6_vrrp_interface_get_elem, | |
730 | } | |
731 | }, | |
732 | { | |
733 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/source-address", | |
734 | .cbs = { | |
735 | .get_elem = lib_interface_vrrp_vrrp_group_v6_source_address_get_elem, | |
736 | } | |
737 | }, | |
738 | { | |
739 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/state", | |
740 | .cbs = { | |
741 | .get_elem = lib_interface_vrrp_vrrp_group_v6_state_get_elem, | |
742 | } | |
743 | }, | |
744 | { | |
745 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/master-advertisement-interval", | |
746 | .cbs = { | |
747 | .get_elem = lib_interface_vrrp_vrrp_group_v6_master_advertisement_interval_get_elem, | |
748 | } | |
749 | }, | |
750 | { | |
751 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/skew-time", | |
752 | .cbs = { | |
753 | .get_elem = lib_interface_vrrp_vrrp_group_v6_skew_time_get_elem, | |
754 | } | |
755 | }, | |
756 | { | |
757 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/state-transition", | |
758 | .cbs = { | |
759 | .get_elem = lib_interface_vrrp_vrrp_group_v6_counter_state_transition_get_elem, | |
760 | } | |
761 | }, | |
762 | { | |
763 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/tx/advertisement", | |
764 | .cbs = { | |
765 | .get_elem = lib_interface_vrrp_vrrp_group_v6_counter_tx_advertisement_get_elem, | |
766 | } | |
767 | }, | |
768 | { | |
769 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/tx/neighbor-advertisement", | |
770 | .cbs = { | |
771 | .get_elem = lib_interface_vrrp_vrrp_group_v6_counter_tx_neighbor_advertisement_get_elem, | |
772 | } | |
773 | }, | |
774 | { | |
775 | .xpath = "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/counter/rx/advertisement", | |
776 | .cbs = { | |
777 | .get_elem = lib_interface_vrrp_vrrp_group_v6_counter_rx_advertisement_get_elem, | |
778 | } | |
779 | }, | |
780 | { | |
781 | .xpath = NULL, | |
782 | }, | |
783 | } | |
784 | }; |