2 * Copyright (C) 2018 Vmware
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "northbound.h"
25 #include "lib_errors.h"
26 #include "routing_nb.h"
29 DEFINE_HOOK(routing_conf_event
, (struct nb_cb_create_args
*args
), (args
));
32 * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
35 int routing_control_plane_protocols_control_plane_protocol_create(
36 struct nb_cb_create_args
*args
)
41 switch (args
->event
) {
43 if (hook_call(routing_conf_event
, args
))
44 return NB_ERR_VALIDATION
;
51 * If the daemon relies on the VRF pointer stored in this
52 * dnode, then it should register the dependency between this
53 * module and the VRF module using
54 * routing_control_plane_protocols_register_vrf_dependency.
55 * If such dependency is not registered, then nothing is
56 * stored in the dnode. If the dependency is registered,
57 * find the vrf and store the pointer.
59 if (nb_node_has_dependency(args
->dnode
->schema
->priv
)) {
60 vrfname
= yang_dnode_get_string(args
->dnode
, "./vrf");
61 vrf
= vrf_lookup_by_name(vrfname
);
63 nb_running_set_entry(args
->dnode
, vrf
);
71 int routing_control_plane_protocols_control_plane_protocol_destroy(
72 struct nb_cb_destroy_args
*args
)
74 if (args
->event
!= NB_EV_APPLY
)
78 * If dependency on VRF module is registered, then VRF
79 * pointer was stored and must be cleared.
81 if (nb_node_has_dependency(args
->dnode
->schema
->priv
))
82 nb_running_unset_entry(args
->dnode
);
87 static void vrf_to_control_plane_protocol(const struct lyd_node
*dnode
,
92 vrf
= yang_dnode_get_string(dnode
, "./name");
94 snprintf(xpath
, XPATH_MAXLEN
, FRR_ROUTING_KEY_XPATH_VRF
, vrf
);
97 static void control_plane_protocol_to_vrf(const struct lyd_node
*dnode
,
102 vrf
= yang_dnode_get_string(dnode
, "./vrf");
104 snprintf(xpath
, XPATH_MAXLEN
, FRR_VRF_KEY_XPATH
, vrf
);
107 void routing_control_plane_protocols_register_vrf_dependency(void)
109 struct nb_dependency_callbacks cbs
;
111 cbs
.get_dependant_xpath
= vrf_to_control_plane_protocol
;
112 cbs
.get_dependency_xpath
= control_plane_protocol_to_vrf
;
114 nb_node_set_dependency_cbs(FRR_VRF_XPATH
, FRR_ROUTING_XPATH
, &cbs
);