]> git.proxmox.com Git - mirror_frr.git/blob - lib/routing_nb_config.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / routing_nb_config.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2018 Vmware
4 * Vishal Dhingra
5 */
6
7 #include <zebra.h>
8
9 #include "northbound.h"
10 #include "libfrr.h"
11 #include "vrf.h"
12 #include "lib_errors.h"
13 #include "routing_nb.h"
14
15
16 DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args));
17
18 /*
19 * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
20 */
21
22 int routing_control_plane_protocols_control_plane_protocol_create(
23 struct nb_cb_create_args *args)
24 {
25 struct vrf *vrf;
26 const char *vrfname;
27
28 switch (args->event) {
29 case NB_EV_VALIDATE:
30 if (hook_call(routing_conf_event, args))
31 return NB_ERR_VALIDATION;
32 break;
33 case NB_EV_PREPARE:
34 case NB_EV_ABORT:
35 break;
36 case NB_EV_APPLY:
37 /*
38 * If the daemon relies on the VRF pointer stored in this
39 * dnode, then it should register the dependency between this
40 * module and the VRF module using
41 * routing_control_plane_protocols_register_vrf_dependency.
42 * If such dependency is not registered, then nothing is
43 * stored in the dnode. If the dependency is registered,
44 * find the vrf and store the pointer.
45 */
46 if (nb_node_has_dependency(args->dnode->schema->priv)) {
47 vrfname = yang_dnode_get_string(args->dnode, "./vrf");
48 vrf = vrf_lookup_by_name(vrfname);
49 assert(vrf);
50 nb_running_set_entry(args->dnode, vrf);
51 }
52 break;
53 };
54
55 return NB_OK;
56 }
57
58 int routing_control_plane_protocols_control_plane_protocol_destroy(
59 struct nb_cb_destroy_args *args)
60 {
61 if (args->event != NB_EV_APPLY)
62 return NB_OK;
63
64 /*
65 * If dependency on VRF module is registered, then VRF
66 * pointer was stored and must be cleared.
67 */
68 if (nb_node_has_dependency(args->dnode->schema->priv))
69 nb_running_unset_entry(args->dnode);
70
71 return NB_OK;
72 }
73
74 static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
75 char *xpath)
76 {
77 const char *vrf;
78
79 vrf = yang_dnode_get_string(dnode, "./name");
80
81 snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH_VRF, vrf);
82 }
83
84 static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
85 char *xpath)
86 {
87 const char *vrf;
88
89 vrf = yang_dnode_get_string(dnode, "./vrf");
90
91 snprintf(xpath, XPATH_MAXLEN, FRR_VRF_KEY_XPATH, vrf);
92 }
93
94 void routing_control_plane_protocols_register_vrf_dependency(void)
95 {
96 struct nb_dependency_callbacks cbs;
97
98 cbs.get_dependant_xpath = vrf_to_control_plane_protocol;
99 cbs.get_dependency_xpath = control_plane_protocol_to_vrf;
100
101 nb_node_set_dependency_cbs(FRR_VRF_XPATH, FRR_ROUTING_XPATH, &cbs);
102 }