]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_routemap_nb_config.c
Merge pull request #8358 from idryzhov/fix-nb-vrf-crash
[mirror_frr.git] / ospf6d / ospf6_routemap_nb_config.c
1 /*
2 * Copyright (C) 2020 Vmware
3 * Sarita Patra
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 "lib/command.h"
21 #include "lib/log.h"
22 #include "lib/northbound.h"
23 #include "lib/routemap.h"
24 #include "ospf6_routemap_nb.h"
25
26 /*
27 * XPath:
28 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type
29 */
30 int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(
31 struct nb_cb_modify_args *args)
32 {
33 struct routemap_hook_context *rhc;
34 const char *type;
35 int rv;
36
37 switch (args->event) {
38 case NB_EV_VALIDATE:
39 case NB_EV_PREPARE:
40 case NB_EV_ABORT:
41 break;
42 case NB_EV_APPLY:
43 /* Add configuration. */
44 rhc = nb_running_get_entry(args->dnode, NULL, true);
45 type = yang_dnode_get_string(args->dnode, NULL);
46
47 /* Set destroy information. */
48 rhc->rhc_shook = generic_set_delete;
49 rhc->rhc_rule = "metric-type";
50 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
51
52 rv = generic_set_add(rhc->rhc_rmi, "metric-type", type,
53 args->errmsg, args->errmsg_len);
54 if (rv != CMD_SUCCESS) {
55 rhc->rhc_mhook = NULL;
56 return NB_ERR_INCONSISTENCY;
57 }
58 }
59
60 return NB_OK;
61 }
62
63 int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(
64 struct nb_cb_destroy_args *args)
65 {
66 switch (args->event) {
67 case NB_EV_VALIDATE:
68 case NB_EV_PREPARE:
69 case NB_EV_ABORT:
70 break;
71 case NB_EV_APPLY:
72 return lib_route_map_entry_set_destroy(args);
73 }
74
75 return NB_OK;
76 }
77
78 /*
79 * XPath:
80 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf6-route-map:ipv6-address
81 */
82 int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(
83 struct nb_cb_modify_args *args)
84 {
85 struct routemap_hook_context *rhc;
86 const char *ipv6_addr;
87 int rv;
88
89 switch (args->event) {
90 case NB_EV_VALIDATE:
91 case NB_EV_PREPARE:
92 case NB_EV_ABORT:
93 break;
94 case NB_EV_APPLY:
95 /* Add configuration. */
96 rhc = nb_running_get_entry(args->dnode, NULL, true);
97 ipv6_addr = yang_dnode_get_string(args->dnode, NULL);
98
99 /* Set destroy information. */
100 rhc->rhc_shook = generic_set_delete;
101 rhc->rhc_rule = "forwarding-address";
102 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
103
104 rv = generic_set_add(rhc->rhc_rmi, "forwarding-address",
105 ipv6_addr,
106 args->errmsg, args->errmsg_len);
107 if (rv != CMD_SUCCESS) {
108 rhc->rhc_mhook = NULL;
109 return NB_ERR_INCONSISTENCY;
110 }
111 }
112
113 return NB_OK;
114 }
115
116 int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy(
117 struct nb_cb_destroy_args *args)
118 {
119 switch (args->event) {
120 case NB_EV_VALIDATE:
121 case NB_EV_PREPARE:
122 case NB_EV_ABORT:
123 break;
124 case NB_EV_APPLY:
125 return lib_route_map_entry_set_destroy(args);
126 }
127
128 return NB_OK;
129 }