Line data Source code
1 : /*
2 : * Copyright (C) 2018 Vmware
3 : * Vishal Dhingra
4 : *
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)
8 : * any later version.
9 : *
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
13 : * more details.
14 : *
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
18 : */
19 :
20 : #include <zebra.h>
21 :
22 : #include "northbound.h"
23 : #include "libfrr.h"
24 : #include "vrf.h"
25 : #include "lib_errors.h"
26 : #include "routing_nb.h"
27 :
28 :
29 8 : DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args));
30 :
31 : /*
32 : * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
33 : */
34 :
35 12 : int routing_control_plane_protocols_control_plane_protocol_create(
36 : struct nb_cb_create_args *args)
37 : {
38 12 : struct vrf *vrf;
39 12 : const char *vrfname;
40 :
41 12 : switch (args->event) {
42 4 : case NB_EV_VALIDATE:
43 4 : if (hook_call(routing_conf_event, args))
44 : return NB_ERR_VALIDATION;
45 : break;
46 : case NB_EV_PREPARE:
47 : case NB_EV_ABORT:
48 : break;
49 4 : case NB_EV_APPLY:
50 : /*
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.
58 : */
59 4 : if (nb_node_has_dependency(args->dnode->schema->priv)) {
60 4 : vrfname = yang_dnode_get_string(args->dnode, "./vrf");
61 4 : vrf = vrf_lookup_by_name(vrfname);
62 4 : assert(vrf);
63 4 : nb_running_set_entry(args->dnode, vrf);
64 : }
65 : break;
66 : };
67 :
68 : return NB_OK;
69 : }
70 :
71 0 : int routing_control_plane_protocols_control_plane_protocol_destroy(
72 : struct nb_cb_destroy_args *args)
73 : {
74 0 : if (args->event != NB_EV_APPLY)
75 : return NB_OK;
76 :
77 : /*
78 : * If dependency on VRF module is registered, then VRF
79 : * pointer was stored and must be cleared.
80 : */
81 0 : if (nb_node_has_dependency(args->dnode->schema->priv))
82 0 : nb_running_unset_entry(args->dnode);
83 :
84 : return NB_OK;
85 : }
86 :
87 0 : static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
88 : char *xpath)
89 : {
90 0 : const char *vrf;
91 :
92 0 : vrf = yang_dnode_get_string(dnode, "./name");
93 :
94 0 : snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH_VRF, vrf);
95 0 : }
96 :
97 4 : static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
98 : char *xpath)
99 : {
100 4 : const char *vrf;
101 :
102 4 : vrf = yang_dnode_get_string(dnode, "./vrf");
103 :
104 4 : snprintf(xpath, XPATH_MAXLEN, FRR_VRF_KEY_XPATH, vrf);
105 4 : }
106 :
107 4 : void routing_control_plane_protocols_register_vrf_dependency(void)
108 : {
109 4 : struct nb_dependency_callbacks cbs;
110 :
111 4 : cbs.get_dependant_xpath = vrf_to_control_plane_protocol;
112 4 : cbs.get_dependency_xpath = control_plane_protocol_to_vrf;
113 :
114 4 : nb_node_set_dependency_cbs(FRR_VRF_XPATH, FRR_ROUTING_XPATH, &cbs);
115 4 : }
|