1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 Vmware
9 #include "northbound.h"
12 #include "lib_errors.h"
13 #include "routing_nb.h"
16 DEFINE_HOOK(routing_conf_event
, (struct nb_cb_create_args
*args
), (args
));
19 * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
22 int routing_control_plane_protocols_control_plane_protocol_create(
23 struct nb_cb_create_args
*args
)
28 switch (args
->event
) {
30 if (hook_call(routing_conf_event
, args
))
31 return NB_ERR_VALIDATION
;
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.
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
);
50 nb_running_set_entry(args
->dnode
, vrf
);
58 int routing_control_plane_protocols_control_plane_protocol_destroy(
59 struct nb_cb_destroy_args
*args
)
61 if (args
->event
!= NB_EV_APPLY
)
65 * If dependency on VRF module is registered, then VRF
66 * pointer was stored and must be cleared.
68 if (nb_node_has_dependency(args
->dnode
->schema
->priv
))
69 nb_running_unset_entry(args
->dnode
);
74 static void vrf_to_control_plane_protocol(const struct lyd_node
*dnode
,
79 vrf
= yang_dnode_get_string(dnode
, "./name");
81 snprintf(xpath
, XPATH_MAXLEN
, FRR_ROUTING_KEY_XPATH_VRF
, vrf
);
84 static void control_plane_protocol_to_vrf(const struct lyd_node
*dnode
,
89 vrf
= yang_dnode_get_string(dnode
, "./vrf");
91 snprintf(xpath
, XPATH_MAXLEN
, FRR_VRF_KEY_XPATH
, vrf
);
94 void routing_control_plane_protocols_register_vrf_dependency(void)
96 struct nb_dependency_callbacks cbs
;
98 cbs
.get_dependant_xpath
= vrf_to_control_plane_protocol
;
99 cbs
.get_dependency_xpath
= control_plane_protocol_to_vrf
;
101 nb_node_set_dependency_cbs(FRR_VRF_XPATH
, FRR_ROUTING_XPATH
, &cbs
);