/src/frr/zebra/zebra_routemap_nb_config.c
Line | Count | Source |
1 | | #include <zebra.h> |
2 | | |
3 | | #include "lib/command.h" |
4 | | #include "lib/log.h" |
5 | | #include "lib/northbound.h" |
6 | | #include "lib/routemap.h" |
7 | | #include "zebra/rib.h" |
8 | | #include "zebra/zebra_routemap_nb.h" |
9 | | |
10 | | /* |
11 | | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length |
12 | | */ |
13 | | int |
14 | | lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_modify( |
15 | | struct nb_cb_modify_args *args) |
16 | 0 | { |
17 | 0 | struct routemap_hook_context *rhc; |
18 | 0 | const char *length; |
19 | 0 | int rv; |
20 | 0 | const char *condition; |
21 | |
|
22 | 0 | switch (args->event) { |
23 | 0 | case NB_EV_VALIDATE: |
24 | 0 | case NB_EV_PREPARE: |
25 | 0 | case NB_EV_ABORT: |
26 | 0 | return NB_OK; |
27 | 0 | case NB_EV_APPLY: |
28 | | /* Add configuration. */ |
29 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
30 | 0 | length = yang_dnode_get_string(args->dnode, NULL); |
31 | 0 | condition = yang_dnode_get_string(args->dnode, |
32 | 0 | "../../frr-route-map:condition"); |
33 | |
|
34 | 0 | if (IS_MATCH_IPv4_PREFIX_LEN(condition)) |
35 | 0 | rhc->rhc_rule = "ip address prefix-len"; |
36 | 0 | else if (IS_MATCH_IPv4_NH_PREFIX_LEN(condition)) |
37 | 0 | rhc->rhc_rule = "ip next-hop prefix-len"; |
38 | |
|
39 | 0 | rhc->rhc_mhook = generic_match_delete; |
40 | 0 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; |
41 | |
|
42 | 0 | rv = generic_match_add(rhc->rhc_rmi, rhc->rhc_rule, |
43 | 0 | length, RMAP_EVENT_MATCH_ADDED, |
44 | 0 | args->errmsg, args->errmsg_len); |
45 | 0 | if (rv != CMD_SUCCESS) { |
46 | 0 | rhc->rhc_mhook = NULL; |
47 | 0 | return NB_ERR_INCONSISTENCY; |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | 0 | return NB_OK; |
52 | 0 | } |
53 | | |
54 | | int |
55 | | lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_destroy( |
56 | | struct nb_cb_destroy_args *args) |
57 | 0 | { |
58 | 0 | switch (args->event) { |
59 | 0 | case NB_EV_VALIDATE: |
60 | 0 | case NB_EV_PREPARE: |
61 | 0 | case NB_EV_ABORT: |
62 | 0 | break; |
63 | 0 | case NB_EV_APPLY: |
64 | 0 | return lib_route_map_entry_match_destroy(args); |
65 | 0 | } |
66 | | |
67 | 0 | return NB_OK; |
68 | 0 | } |
69 | | |
70 | | /* |
71 | | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length |
72 | | */ |
73 | | int |
74 | | lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_modify( |
75 | | struct nb_cb_modify_args *args) |
76 | 0 | { |
77 | 0 | struct routemap_hook_context *rhc; |
78 | 0 | const char *length; |
79 | 0 | int rv; |
80 | |
|
81 | 0 | switch (args->event) { |
82 | 0 | case NB_EV_VALIDATE: |
83 | 0 | case NB_EV_PREPARE: |
84 | 0 | case NB_EV_ABORT: |
85 | 0 | return NB_OK; |
86 | 0 | case NB_EV_APPLY: |
87 | | /* Add configuration. */ |
88 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
89 | 0 | length = yang_dnode_get_string(args->dnode, NULL); |
90 | | |
91 | | /* Set destroy information. */ |
92 | 0 | rhc->rhc_mhook = generic_match_delete; |
93 | 0 | rhc->rhc_rule = "ipv6 address prefix-len"; |
94 | 0 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; |
95 | |
|
96 | 0 | rv = generic_match_add(rhc->rhc_rmi, "ipv6 address prefix-len", |
97 | 0 | length, RMAP_EVENT_MATCH_ADDED, |
98 | 0 | args->errmsg, args->errmsg_len); |
99 | 0 | if (rv != CMD_SUCCESS) { |
100 | 0 | rhc->rhc_mhook = NULL; |
101 | 0 | return NB_ERR_INCONSISTENCY; |
102 | 0 | } |
103 | 0 | } |
104 | | |
105 | 0 | return NB_OK; |
106 | 0 | } |
107 | | |
108 | | int |
109 | | lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_destroy( |
110 | | struct nb_cb_destroy_args *args) |
111 | 0 | { |
112 | 0 | switch (args->event) { |
113 | 0 | case NB_EV_VALIDATE: |
114 | 0 | case NB_EV_PREPARE: |
115 | 0 | case NB_EV_ABORT: |
116 | 0 | break; |
117 | 0 | case NB_EV_APPLY: |
118 | 0 | return lib_route_map_entry_match_destroy(args); |
119 | 0 | } |
120 | | |
121 | 0 | return NB_OK; |
122 | |
|
123 | 0 | } |
124 | | |
125 | | /* |
126 | | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-instance |
127 | | */ |
128 | | int |
129 | | lib_route_map_entry_match_condition_rmap_match_condition_source_instance_modify( |
130 | | struct nb_cb_modify_args *args) |
131 | 0 | { |
132 | 0 | struct routemap_hook_context *rhc; |
133 | 0 | const char *type; |
134 | 0 | int rv; |
135 | |
|
136 | 0 | switch (args->event) { |
137 | 0 | case NB_EV_VALIDATE: |
138 | 0 | case NB_EV_PREPARE: |
139 | 0 | case NB_EV_ABORT: |
140 | 0 | break; |
141 | 0 | case NB_EV_APPLY: |
142 | | /* Add configuration. */ |
143 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
144 | 0 | type = yang_dnode_get_string(args->dnode, NULL); |
145 | | |
146 | | /* Set destroy information. */ |
147 | 0 | rhc->rhc_mhook = generic_match_delete; |
148 | 0 | rhc->rhc_rule = "source-instance"; |
149 | 0 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; |
150 | |
|
151 | 0 | rv = generic_match_add(rhc->rhc_rmi, "source-instance", |
152 | 0 | type, RMAP_EVENT_MATCH_ADDED, |
153 | 0 | args->errmsg, args->errmsg_len); |
154 | 0 | if (rv != CMD_SUCCESS) { |
155 | 0 | rhc->rhc_mhook = NULL; |
156 | 0 | return NB_ERR_INCONSISTENCY; |
157 | 0 | } |
158 | 0 | } |
159 | | |
160 | 0 | return NB_OK; |
161 | 0 | } |
162 | | |
163 | | int |
164 | | lib_route_map_entry_match_condition_rmap_match_condition_source_instance_destroy( |
165 | | struct nb_cb_destroy_args *args) |
166 | 0 | { |
167 | 0 | switch (args->event) { |
168 | 0 | case NB_EV_VALIDATE: |
169 | 0 | case NB_EV_PREPARE: |
170 | 0 | case NB_EV_ABORT: |
171 | 0 | break; |
172 | 0 | case NB_EV_APPLY: |
173 | 0 | return lib_route_map_entry_match_destroy(args); |
174 | 0 | } |
175 | | |
176 | 0 | return NB_OK; |
177 | 0 | } |
178 | | |
179 | | /* |
180 | | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-protocol |
181 | | */ |
182 | | int |
183 | | lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify( |
184 | | struct nb_cb_modify_args *args) |
185 | 0 | { |
186 | 0 | struct routemap_hook_context *rhc; |
187 | 0 | const char *type; |
188 | 0 | int rv; |
189 | |
|
190 | 0 | switch (args->event) { |
191 | 0 | case NB_EV_VALIDATE: |
192 | 0 | type = yang_dnode_get_string(args->dnode, NULL); |
193 | 0 | if (proto_name2num(type) == -1) { |
194 | 0 | zlog_warn("%s: invalid protocol: %s", __func__, type); |
195 | 0 | return NB_ERR_VALIDATION; |
196 | 0 | } |
197 | 0 | return NB_OK; |
198 | 0 | case NB_EV_PREPARE: |
199 | 0 | case NB_EV_ABORT: |
200 | 0 | return NB_OK; |
201 | 0 | case NB_EV_APPLY: |
202 | | /* NOTHING */ |
203 | 0 | break; |
204 | 0 | } |
205 | | |
206 | | /* Add configuration. */ |
207 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
208 | 0 | type = yang_dnode_get_string(args->dnode, NULL); |
209 | | |
210 | | /* Set destroy information. */ |
211 | 0 | rhc->rhc_mhook = generic_match_delete; |
212 | 0 | rhc->rhc_rule = "source-protocol"; |
213 | 0 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; |
214 | |
|
215 | 0 | rv = generic_match_add(rhc->rhc_rmi, "source-protocol", type, |
216 | 0 | RMAP_EVENT_MATCH_ADDED, |
217 | 0 | args->errmsg, args->errmsg_len); |
218 | 0 | if (rv != CMD_SUCCESS) { |
219 | 0 | rhc->rhc_mhook = NULL; |
220 | 0 | return NB_ERR_INCONSISTENCY; |
221 | 0 | } |
222 | | |
223 | 0 | return NB_OK; |
224 | 0 | } |
225 | | |
226 | | int |
227 | | lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_destroy( |
228 | | struct nb_cb_destroy_args *args) |
229 | 0 | { |
230 | 0 | switch (args->event) { |
231 | 0 | case NB_EV_VALIDATE: |
232 | 0 | case NB_EV_PREPARE: |
233 | 0 | case NB_EV_ABORT: |
234 | 0 | break; |
235 | 0 | case NB_EV_APPLY: |
236 | 0 | return lib_route_map_entry_match_destroy(args); |
237 | 0 | } |
238 | | |
239 | 0 | return NB_OK; |
240 | 0 | } |
241 | | |
242 | | /* |
243 | | * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv4-src-address |
244 | | */ |
245 | | int |
246 | | lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_modify( |
247 | | struct nb_cb_modify_args *args) |
248 | 0 | { |
249 | 0 | struct routemap_hook_context *rhc; |
250 | 0 | const char *source; |
251 | 0 | struct prefix p; |
252 | 0 | int rv; |
253 | |
|
254 | 0 | switch (args->event) { |
255 | 0 | case NB_EV_VALIDATE: |
256 | 0 | memset(&p, 0, sizeof(p)); |
257 | 0 | yang_dnode_get_ipv4p(&p, args->dnode, NULL); |
258 | 0 | if (zebra_check_addr(&p) == 0) { |
259 | 0 | zlog_warn("%s: invalid IPv4 address: %s", __func__, |
260 | 0 | yang_dnode_get_string(args->dnode, NULL)); |
261 | 0 | return NB_ERR_VALIDATION; |
262 | 0 | } |
263 | 0 | return NB_OK; |
264 | 0 | case NB_EV_PREPARE: |
265 | 0 | case NB_EV_ABORT: |
266 | 0 | return NB_OK; |
267 | 0 | case NB_EV_APPLY: |
268 | | /* NOTHING */ |
269 | 0 | break; |
270 | 0 | } |
271 | | |
272 | | /* Add configuration. */ |
273 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
274 | 0 | source = yang_dnode_get_string(args->dnode, NULL); |
275 | | |
276 | | /* Set destroy information. */ |
277 | 0 | rhc->rhc_shook = generic_set_delete; |
278 | 0 | rhc->rhc_rule = "src"; |
279 | |
|
280 | 0 | rv = generic_set_add(rhc->rhc_rmi, "src", source, |
281 | 0 | args->errmsg, args->errmsg_len); |
282 | 0 | if (rv != CMD_SUCCESS) { |
283 | 0 | rhc->rhc_shook = NULL; |
284 | 0 | return NB_ERR_INCONSISTENCY; |
285 | 0 | } |
286 | | |
287 | 0 | return NB_OK; |
288 | 0 | } |
289 | | |
290 | | int |
291 | | lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_destroy( |
292 | | struct nb_cb_destroy_args *args) |
293 | 0 | { |
294 | 0 | switch (args->event) { |
295 | 0 | case NB_EV_VALIDATE: |
296 | 0 | case NB_EV_PREPARE: |
297 | 0 | case NB_EV_ABORT: |
298 | 0 | break; |
299 | 0 | case NB_EV_APPLY: |
300 | 0 | return lib_route_map_entry_set_destroy(args); |
301 | 0 | } |
302 | | |
303 | 0 | return NB_OK; |
304 | 0 | } |
305 | | |
306 | | /* |
307 | | * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv6-src-address |
308 | | */ |
309 | | int |
310 | | lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_modify( |
311 | | struct nb_cb_modify_args *args) |
312 | 0 | { |
313 | 0 | struct routemap_hook_context *rhc; |
314 | 0 | const char *source; |
315 | 0 | struct prefix p; |
316 | 0 | int rv; |
317 | |
|
318 | 0 | switch (args->event) { |
319 | 0 | case NB_EV_VALIDATE: |
320 | 0 | memset(&p, 0, sizeof(p)); |
321 | 0 | yang_dnode_get_ipv6p(&p, args->dnode, NULL); |
322 | 0 | if (zebra_check_addr(&p) == 0) { |
323 | 0 | zlog_warn("%s: invalid IPv6 address: %s", __func__, |
324 | 0 | yang_dnode_get_string(args->dnode, NULL)); |
325 | 0 | return NB_ERR_VALIDATION; |
326 | 0 | } |
327 | 0 | return NB_OK; |
328 | 0 | case NB_EV_PREPARE: |
329 | 0 | case NB_EV_ABORT: |
330 | 0 | return NB_OK; |
331 | 0 | case NB_EV_APPLY: |
332 | | /* NOTHING */ |
333 | 0 | break; |
334 | 0 | } |
335 | | |
336 | | /* Add configuration. */ |
337 | 0 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
338 | 0 | source = yang_dnode_get_string(args->dnode, NULL); |
339 | | |
340 | | /* Set destroy information. */ |
341 | 0 | rhc->rhc_shook = generic_set_delete; |
342 | 0 | rhc->rhc_rule = "src"; |
343 | |
|
344 | 0 | rv = generic_set_add(rhc->rhc_rmi, "src", source, |
345 | 0 | args->errmsg, args->errmsg_len); |
346 | 0 | if (rv != CMD_SUCCESS) { |
347 | 0 | rhc->rhc_shook = NULL; |
348 | 0 | return NB_ERR_INCONSISTENCY; |
349 | 0 | } |
350 | | |
351 | 0 | return NB_OK; |
352 | 0 | } |
353 | | |
354 | | int |
355 | | lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_destroy( |
356 | | struct nb_cb_destroy_args *args) |
357 | 0 | { |
358 | 0 | switch (args->event) { |
359 | 0 | case NB_EV_VALIDATE: |
360 | 0 | case NB_EV_PREPARE: |
361 | 0 | case NB_EV_ABORT: |
362 | 0 | break; |
363 | 0 | case NB_EV_APPLY: |
364 | 0 | return lib_route_map_entry_set_destroy(args); |
365 | 0 | } |
366 | | |
367 | 0 | return NB_OK; |
368 | 0 | } |