]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_routemap_nb_config.c
3 #include "lib/command.h"
5 #include "lib/northbound.h"
6 #include "lib/routemap.h"
8 #include "zebra/zebra_routemap_nb.h"
11 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length
14 lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_modify(
15 struct nb_cb_modify_args
*args
)
17 struct routemap_hook_context
*rhc
;
20 const char *condition
;
22 switch (args
->event
) {
28 /* Add configuration. */
29 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
30 length
= yang_dnode_get_string(args
->dnode
, NULL
);
31 condition
= yang_dnode_get_string(args
->dnode
,
32 "../../frr-route-map:condition");
34 if (IS_MATCH_IPv4_PREFIX_LEN(condition
))
35 rhc
->rhc_rule
= "ip address prefix-len";
36 else if (IS_MATCH_IPv4_NH_PREFIX_LEN(condition
))
37 rhc
->rhc_rule
= "ip next-hop prefix-len";
39 rhc
->rhc_mhook
= generic_match_delete
;
40 rhc
->rhc_event
= RMAP_EVENT_MATCH_DELETED
;
42 rv
= generic_match_add(rhc
->rhc_rmi
, rhc
->rhc_rule
,
43 length
, RMAP_EVENT_MATCH_ADDED
,
44 args
->errmsg
, args
->errmsg_len
);
45 if (rv
!= CMD_SUCCESS
) {
46 rhc
->rhc_mhook
= NULL
;
47 return NB_ERR_INCONSISTENCY
;
55 lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_destroy(
56 struct nb_cb_destroy_args
*args
)
58 switch (args
->event
) {
64 return lib_route_map_entry_match_destroy(args
);
71 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length
74 lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_modify(
75 struct nb_cb_modify_args
*args
)
77 struct routemap_hook_context
*rhc
;
81 switch (args
->event
) {
87 /* Add configuration. */
88 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
89 length
= yang_dnode_get_string(args
->dnode
, NULL
);
91 /* Set destroy information. */
92 rhc
->rhc_mhook
= generic_match_delete
;
93 rhc
->rhc_rule
= "ipv6 address prefix-len";
94 rhc
->rhc_event
= RMAP_EVENT_MATCH_DELETED
;
96 rv
= generic_match_add(rhc
->rhc_rmi
, "ipv6 address prefix-len",
97 length
, RMAP_EVENT_MATCH_ADDED
,
98 args
->errmsg
, args
->errmsg_len
);
99 if (rv
!= CMD_SUCCESS
) {
100 rhc
->rhc_mhook
= NULL
;
101 return NB_ERR_INCONSISTENCY
;
109 lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_destroy(
110 struct nb_cb_destroy_args
*args
)
112 switch (args
->event
) {
118 return lib_route_map_entry_match_destroy(args
);
126 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-instance
129 lib_route_map_entry_match_condition_rmap_match_condition_source_instance_modify(
130 struct nb_cb_modify_args
*args
)
132 struct routemap_hook_context
*rhc
;
136 switch (args
->event
) {
142 /* Add configuration. */
143 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
144 type
= yang_dnode_get_string(args
->dnode
, NULL
);
146 /* Set destroy information. */
147 rhc
->rhc_mhook
= generic_match_delete
;
148 rhc
->rhc_rule
= "source-instance";
149 rhc
->rhc_event
= RMAP_EVENT_MATCH_DELETED
;
151 rv
= generic_match_add(rhc
->rhc_rmi
, "source-instance",
152 type
, RMAP_EVENT_MATCH_ADDED
,
153 args
->errmsg
, args
->errmsg_len
);
154 if (rv
!= CMD_SUCCESS
) {
155 rhc
->rhc_mhook
= NULL
;
156 return NB_ERR_INCONSISTENCY
;
164 lib_route_map_entry_match_condition_rmap_match_condition_source_instance_destroy(
165 struct nb_cb_destroy_args
*args
)
167 switch (args
->event
) {
173 return lib_route_map_entry_match_destroy(args
);
180 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-protocol
183 lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify(
184 struct nb_cb_modify_args
*args
)
186 struct routemap_hook_context
*rhc
;
190 switch (args
->event
) {
192 type
= yang_dnode_get_string(args
->dnode
, NULL
);
193 if (proto_name2num(type
) == -1) {
194 zlog_warn("%s: invalid protocol: %s", __func__
, type
);
195 return NB_ERR_VALIDATION
;
206 /* Add configuration. */
207 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
208 type
= yang_dnode_get_string(args
->dnode
, NULL
);
210 /* Set destroy information. */
211 rhc
->rhc_mhook
= generic_match_delete
;
212 rhc
->rhc_rule
= "source-protocol";
213 rhc
->rhc_event
= RMAP_EVENT_MATCH_DELETED
;
215 rv
= generic_match_add(rhc
->rhc_rmi
, "source-protocol", type
,
216 RMAP_EVENT_MATCH_ADDED
,
217 args
->errmsg
, args
->errmsg_len
);
218 if (rv
!= CMD_SUCCESS
) {
219 rhc
->rhc_mhook
= NULL
;
220 return NB_ERR_INCONSISTENCY
;
227 lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_destroy(
228 struct nb_cb_destroy_args
*args
)
230 switch (args
->event
) {
236 return lib_route_map_entry_match_destroy(args
);
243 * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv4-src-address
246 lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_modify(
247 struct nb_cb_modify_args
*args
)
249 struct routemap_hook_context
*rhc
;
254 switch (args
->event
) {
256 memset(&p
, 0, sizeof(p
));
257 yang_dnode_get_ipv4p(&p
, args
->dnode
, NULL
);
258 if (zebra_check_addr(&p
) == 0) {
259 zlog_warn("%s: invalid IPv4 address: %s", __func__
,
260 yang_dnode_get_string(args
->dnode
, NULL
));
261 return NB_ERR_VALIDATION
;
272 /* Add configuration. */
273 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
274 source
= yang_dnode_get_string(args
->dnode
, NULL
);
276 /* Set destroy information. */
277 rhc
->rhc_shook
= generic_set_delete
;
278 rhc
->rhc_rule
= "src";
280 rv
= generic_set_add(rhc
->rhc_rmi
, "src", source
,
281 args
->errmsg
, args
->errmsg_len
);
282 if (rv
!= CMD_SUCCESS
) {
283 rhc
->rhc_shook
= NULL
;
284 return NB_ERR_INCONSISTENCY
;
291 lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_destroy(
292 struct nb_cb_destroy_args
*args
)
294 switch (args
->event
) {
300 return lib_route_map_entry_set_destroy(args
);
307 * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv6-src-address
310 lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_modify(
311 struct nb_cb_modify_args
*args
)
313 struct routemap_hook_context
*rhc
;
318 switch (args
->event
) {
320 memset(&p
, 0, sizeof(p
));
321 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
322 if (zebra_check_addr(&p
) == 0) {
323 zlog_warn("%s: invalid IPv6 address: %s", __func__
,
324 yang_dnode_get_string(args
->dnode
, NULL
));
325 return NB_ERR_VALIDATION
;
336 /* Add configuration. */
337 rhc
= nb_running_get_entry(args
->dnode
, NULL
, true);
338 source
= yang_dnode_get_string(args
->dnode
, NULL
);
340 /* Set destroy information. */
341 rhc
->rhc_shook
= generic_set_delete
;
342 rhc
->rhc_rule
= "src";
344 rv
= generic_set_add(rhc
->rhc_rmi
, "src", source
,
345 args
->errmsg
, args
->errmsg_len
);
346 if (rv
!= CMD_SUCCESS
) {
347 rhc
->rhc_shook
= NULL
;
348 return NB_ERR_INCONSISTENCY
;
355 lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_destroy(
356 struct nb_cb_destroy_args
*args
)
358 switch (args
->event
) {
364 return lib_route_map_entry_set_destroy(args
);