]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
718e3744 | 2 | /* |
3 | * Route map function of ospfd. | |
4 | * Copyright (C) 2000 IP Infusion Inc. | |
5 | * | |
6 | * Written by Toshiaki Takada. | |
718e3744 | 7 | */ |
8 | ||
9 | #include <zebra.h> | |
10 | ||
11 | #include "memory.h" | |
12 | #include "prefix.h" | |
13 | #include "table.h" | |
82f97584 | 14 | #include "vty.h" |
718e3744 | 15 | #include "routemap.h" |
16 | #include "command.h" | |
17 | #include "log.h" | |
18 | #include "plist.h" | |
1306c09a | 19 | #include "vrf.h" |
5d5ba018 | 20 | #include "frrstr.h" |
a623b526 | 21 | #include "northbound_cli.h" |
718e3744 | 22 | |
23 | #include "ospfd/ospfd.h" | |
24 | #include "ospfd/ospf_asbr.h" | |
25 | #include "ospfd/ospf_interface.h" | |
26 | #include "ospfd/ospf_lsa.h" | |
27 | #include "ospfd/ospf_route.h" | |
28 | #include "ospfd/ospf_zebra.h" | |
45301f8c | 29 | #include "ospfd/ospf_errors.h" |
718e3744 | 30 | |
31 | /* Hook function for updating route_map assignment. */ | |
d62a17ae | 32 | static void ospf_route_map_update(const char *name) |
33 | { | |
34 | struct ospf *ospf; | |
35 | int type; | |
b5a8894d | 36 | struct listnode *n1 = NULL; |
d62a17ae | 37 | |
38 | /* If OSPF instatnce does not exist, return right now. */ | |
b5a8894d | 39 | if (listcount(om->ospf) == 0) |
d62a17ae | 40 | return; |
41 | ||
43b8d1d8 | 42 | for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { |
b5a8894d CS |
43 | /* Update route-map */ |
44 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { | |
45 | struct list *red_list; | |
46 | struct listnode *node; | |
47 | struct ospf_redist *red; | |
48 | ||
49 | red_list = ospf->redist[type]; | |
50 | if (!red_list) | |
51 | continue; | |
52 | ||
53 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { | |
54 | if (ROUTEMAP_NAME(red) | |
55 | && strcmp(ROUTEMAP_NAME(red), name) == 0) { | |
56 | /* Keep old route-map. */ | |
57 | struct route_map *old = ROUTEMAP(red); | |
58 | ||
0fddd864 IR |
59 | ROUTEMAP(red) = |
60 | route_map_lookup_by_name( | |
61 | ROUTEMAP_NAME(red)); | |
62 | ||
63 | if (!old) | |
64 | route_map_counter_increment( | |
65 | ROUTEMAP(red)); | |
66 | ||
996c9314 LB |
67 | /* No update for this distribute type. |
68 | */ | |
69 | if (old == NULL | |
70 | && ROUTEMAP(red) == NULL) | |
b5a8894d CS |
71 | continue; |
72 | ||
996c9314 LB |
73 | ospf_distribute_list_update( |
74 | ospf, type, red->instance); | |
b5a8894d | 75 | } |
d62a17ae | 76 | } |
77 | } | |
78 | } | |
718e3744 | 79 | } |
80 | ||
097b5973 | 81 | static void ospf_route_map_event(const char *name) |
718e3744 | 82 | { |
d62a17ae | 83 | struct ospf *ospf; |
84 | int type; | |
b5a8894d CS |
85 | struct listnode *n1 = NULL; |
86 | ||
87 | for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { | |
88 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { | |
89 | struct list *red_list; | |
90 | struct listnode *node; | |
91 | struct ospf_redist *red; | |
92 | ||
93 | red_list = ospf->redist[type]; | |
94 | if (!red_list) | |
95 | continue; | |
96 | ||
97 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { | |
98 | if (ROUTEMAP_NAME(red) && ROUTEMAP(red) | |
99 | && !strcmp(ROUTEMAP_NAME(red), name)) { | |
996c9314 LB |
100 | ospf_distribute_list_update( |
101 | ospf, type, red->instance); | |
b5a8894d | 102 | } |
d62a17ae | 103 | } |
104 | } | |
105 | } | |
718e3744 | 106 | } |
107 | ||
718e3744 | 108 | /* `match ip netxthop ' */ |
109 | /* Match function return 1 if match is success else return zero. */ | |
b68885f9 | 110 | static enum route_map_cmd_result_t |
1782514f | 111 | route_match_ip_nexthop(void *rule, const struct prefix *prefix, void *object) |
d62a17ae | 112 | { |
113 | struct access_list *alist; | |
114 | struct external_info *ei = object; | |
115 | struct prefix_ipv4 p; | |
116 | ||
1782514f DS |
117 | p.family = AF_INET; |
118 | p.prefix = ei->nexthop; | |
119 | p.prefixlen = IPV4_MAX_BITLEN; | |
d62a17ae | 120 | |
1782514f | 121 | alist = access_list_lookup(AFI_IP, (char *)rule); |
46b2a036 DS |
122 | if (alist == NULL) { |
123 | if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) | |
124 | zlog_debug( | |
125 | "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", | |
126 | __func__, (char *)rule); | |
1782514f | 127 | return RMAP_NOMATCH; |
46b2a036 | 128 | } |
d62a17ae | 129 | |
1782514f DS |
130 | return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH |
131 | : RMAP_MATCH); | |
718e3744 | 132 | } |
133 | ||
134 | /* Route map `ip next-hop' match statement. `arg' should be | |
135 | access-list name. */ | |
d62a17ae | 136 | static void *route_match_ip_nexthop_compile(const char *arg) |
718e3744 | 137 | { |
d62a17ae | 138 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 139 | } |
140 | ||
141 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 142 | static void route_match_ip_nexthop_free(void *rule) |
718e3744 | 143 | { |
d62a17ae | 144 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 145 | } |
146 | ||
147 | /* Route map commands for metric matching. */ | |
364deb04 DL |
148 | static const struct route_map_rule_cmd route_match_ip_nexthop_cmd = { |
149 | "ip next-hop", | |
150 | route_match_ip_nexthop, | |
151 | route_match_ip_nexthop_compile, | |
152 | route_match_ip_nexthop_free | |
153 | }; | |
718e3744 | 154 | |
155 | /* `match ip next-hop prefix-list PREFIX_LIST' */ | |
156 | ||
b68885f9 | 157 | static enum route_map_cmd_result_t |
123214ef | 158 | route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, |
1782514f | 159 | void *object) |
718e3744 | 160 | { |
d62a17ae | 161 | struct prefix_list *plist; |
162 | struct external_info *ei = object; | |
163 | struct prefix_ipv4 p; | |
164 | ||
1782514f DS |
165 | p.family = AF_INET; |
166 | p.prefix = ei->nexthop; | |
167 | p.prefixlen = IPV4_MAX_BITLEN; | |
d62a17ae | 168 | |
1782514f | 169 | plist = prefix_list_lookup(AFI_IP, (char *)rule); |
1df4bd18 DS |
170 | if (plist == NULL) { |
171 | if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) | |
172 | zlog_debug( | |
173 | "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", | |
174 | __func__, (char *)rule); | |
1782514f | 175 | return RMAP_NOMATCH; |
1df4bd18 | 176 | } |
d62a17ae | 177 | |
1782514f DS |
178 | return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH |
179 | : RMAP_MATCH); | |
718e3744 | 180 | } |
181 | ||
d62a17ae | 182 | static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) |
718e3744 | 183 | { |
d62a17ae | 184 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 185 | } |
186 | ||
d62a17ae | 187 | static void route_match_ip_next_hop_prefix_list_free(void *rule) |
718e3744 | 188 | { |
d62a17ae | 189 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 190 | } |
191 | ||
364deb04 DL |
192 | static const struct route_map_rule_cmd |
193 | route_match_ip_next_hop_prefix_list_cmd = { | |
194 | "ip next-hop prefix-list", | |
195 | route_match_ip_next_hop_prefix_list, | |
d62a17ae | 196 | route_match_ip_next_hop_prefix_list_compile, |
364deb04 DL |
197 | route_match_ip_next_hop_prefix_list_free |
198 | }; | |
718e3744 | 199 | |
b6c0e913 DA |
200 | /* `match ip next-hop type <blackhole>' */ |
201 | ||
b68885f9 | 202 | static enum route_map_cmd_result_t |
b6c0e913 | 203 | route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, |
1782514f | 204 | void *object) |
b6c0e913 DA |
205 | { |
206 | struct external_info *ei = object; | |
207 | ||
1782514f | 208 | if (prefix->family == AF_INET) { |
b6c0e913 DA |
209 | ei = (struct external_info *)object; |
210 | if (!ei) | |
b68885f9 | 211 | return RMAP_NOMATCH; |
b6c0e913 DA |
212 | |
213 | if (ei->nexthop.s_addr == INADDR_ANY && !ei->ifindex) | |
214 | return RMAP_MATCH; | |
215 | } | |
216 | return RMAP_NOMATCH; | |
217 | } | |
218 | ||
219 | static void *route_match_ip_next_hop_type_compile(const char *arg) | |
220 | { | |
221 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
222 | } | |
223 | ||
224 | static void route_match_ip_next_hop_type_free(void *rule) | |
225 | { | |
226 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
227 | } | |
228 | ||
364deb04 DL |
229 | static const struct route_map_rule_cmd |
230 | route_match_ip_next_hop_type_cmd = { | |
231 | "ip next-hop type", | |
232 | route_match_ip_next_hop_type, | |
b6c0e913 | 233 | route_match_ip_next_hop_type_compile, |
364deb04 DL |
234 | route_match_ip_next_hop_type_free |
235 | }; | |
b6c0e913 | 236 | |
718e3744 | 237 | /* `match ip address IP_ACCESS_LIST' */ |
238 | /* Match function should return 1 if match is success else return | |
239 | zero. */ | |
b68885f9 | 240 | static enum route_map_cmd_result_t |
1782514f | 241 | route_match_ip_address(void *rule, const struct prefix *prefix, void *object) |
d62a17ae | 242 | { |
243 | struct access_list *alist; | |
244 | /* struct prefix_ipv4 match; */ | |
245 | ||
1782514f | 246 | alist = access_list_lookup(AFI_IP, (char *)rule); |
46b2a036 DS |
247 | if (alist == NULL) { |
248 | if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) | |
249 | zlog_debug( | |
250 | "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", | |
251 | __func__, (char *)rule); | |
1782514f | 252 | return RMAP_NOMATCH; |
46b2a036 | 253 | } |
d62a17ae | 254 | |
1782514f DS |
255 | return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH |
256 | : RMAP_MATCH); | |
718e3744 | 257 | } |
258 | ||
259 | /* Route map `ip address' match statement. `arg' should be | |
260 | access-list name. */ | |
d62a17ae | 261 | static void *route_match_ip_address_compile(const char *arg) |
718e3744 | 262 | { |
d62a17ae | 263 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 264 | } |
265 | ||
266 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 267 | static void route_match_ip_address_free(void *rule) |
718e3744 | 268 | { |
d62a17ae | 269 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 270 | } |
271 | ||
272 | /* Route map commands for ip address matching. */ | |
364deb04 DL |
273 | static const struct route_map_rule_cmd route_match_ip_address_cmd = { |
274 | "ip address", | |
275 | route_match_ip_address, | |
276 | route_match_ip_address_compile, | |
277 | route_match_ip_address_free | |
278 | }; | |
718e3744 | 279 | |
280 | /* `match ip address prefix-list PREFIX_LIST' */ | |
b68885f9 | 281 | static enum route_map_cmd_result_t |
123214ef | 282 | route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, |
1782514f | 283 | void *object) |
718e3744 | 284 | { |
d62a17ae | 285 | struct prefix_list *plist; |
286 | ||
1782514f | 287 | plist = prefix_list_lookup(AFI_IP, (char *)rule); |
1df4bd18 DS |
288 | if (plist == NULL) { |
289 | if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) | |
290 | zlog_debug( | |
291 | "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", | |
292 | __func__, (char *)rule); | |
293 | ||
1782514f | 294 | return RMAP_NOMATCH; |
1df4bd18 | 295 | } |
d62a17ae | 296 | |
1782514f DS |
297 | return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH |
298 | : RMAP_MATCH); | |
718e3744 | 299 | } |
300 | ||
d62a17ae | 301 | static void *route_match_ip_address_prefix_list_compile(const char *arg) |
718e3744 | 302 | { |
d62a17ae | 303 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 304 | } |
305 | ||
d62a17ae | 306 | static void route_match_ip_address_prefix_list_free(void *rule) |
718e3744 | 307 | { |
d62a17ae | 308 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 309 | } |
310 | ||
364deb04 DL |
311 | static const struct route_map_rule_cmd |
312 | route_match_ip_address_prefix_list_cmd = { | |
313 | "ip address prefix-list", | |
314 | route_match_ip_address_prefix_list, | |
d62a17ae | 315 | route_match_ip_address_prefix_list_compile, |
364deb04 DL |
316 | route_match_ip_address_prefix_list_free |
317 | }; | |
718e3744 | 318 | |
319 | /* `match interface IFNAME' */ | |
320 | /* Match function should return 1 if match is success else return | |
321 | zero. */ | |
b68885f9 | 322 | static enum route_map_cmd_result_t |
1782514f | 323 | route_match_interface(void *rule, const struct prefix *prefix, void *object) |
718e3744 | 324 | { |
d62a17ae | 325 | struct interface *ifp; |
326 | struct external_info *ei; | |
718e3744 | 327 | |
1782514f | 328 | ei = object; |
4030e186 | 329 | ifp = if_lookup_by_name((char *)rule, ei->ospf->vrf_id); |
718e3744 | 330 | |
1782514f DS |
331 | if (ifp == NULL || ifp->ifindex != ei->ifindex) |
332 | return RMAP_NOMATCH; | |
718e3744 | 333 | |
1782514f | 334 | return RMAP_MATCH; |
718e3744 | 335 | } |
336 | ||
337 | /* Route map `interface' match statement. `arg' should be | |
338 | interface name. */ | |
d62a17ae | 339 | static void *route_match_interface_compile(const char *arg) |
718e3744 | 340 | { |
d62a17ae | 341 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 342 | } |
343 | ||
344 | /* Free route map's compiled `interface' value. */ | |
d62a17ae | 345 | static void route_match_interface_free(void *rule) |
718e3744 | 346 | { |
d62a17ae | 347 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 348 | } |
349 | ||
350 | /* Route map commands for ip address matching. */ | |
364deb04 DL |
351 | static const struct route_map_rule_cmd route_match_interface_cmd = { |
352 | "interface", | |
353 | route_match_interface, | |
354 | route_match_interface_compile, | |
355 | route_match_interface_free | |
356 | }; | |
718e3744 | 357 | |
0d9551dc | 358 | /* Match function return 1 if match is success else return zero. */ |
b68885f9 | 359 | static enum route_map_cmd_result_t |
1782514f | 360 | route_match_tag(void *rule, const struct prefix *prefix, void *object) |
0d9551dc | 361 | { |
d62a17ae | 362 | route_tag_t *tag; |
363 | struct external_info *ei; | |
0d9551dc | 364 | |
1782514f DS |
365 | tag = rule; |
366 | ei = object; | |
0d9551dc | 367 | |
1782514f | 368 | return ((ei->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); |
0d9551dc DS |
369 | } |
370 | ||
0d9551dc | 371 | /* Route map commands for tag matching. */ |
364deb04 DL |
372 | static const struct route_map_rule_cmd route_match_tag_cmd = { |
373 | "tag", | |
374 | route_match_tag, | |
375 | route_map_rule_tag_compile, | |
d62a17ae | 376 | route_map_rule_tag_free, |
0d9551dc DS |
377 | }; |
378 | ||
6a74c5f9 | 379 | struct ospf_metric { |
7a5e6e46 | 380 | enum { metric_increment, metric_decrement, metric_absolute } type; |
6a74c5f9 | 381 | bool used; |
d7c0a89a | 382 | uint32_t metric; |
6a74c5f9 | 383 | }; |
0d9551dc | 384 | |
718e3744 | 385 | /* `set metric METRIC' */ |
386 | /* Set metric to attribute. */ | |
b68885f9 | 387 | static enum route_map_cmd_result_t |
1782514f | 388 | route_set_metric(void *rule, const struct prefix *prefix, void *object) |
718e3744 | 389 | { |
6a74c5f9 | 390 | struct ospf_metric *metric; |
d62a17ae | 391 | struct external_info *ei; |
392 | ||
1782514f DS |
393 | /* Fetch routemap's rule information. */ |
394 | metric = rule; | |
395 | ei = object; | |
d62a17ae | 396 | |
1782514f DS |
397 | /* Set metric out value. */ |
398 | if (!metric->used) | |
399 | return RMAP_OKAY; | |
236e900c | 400 | |
1782514f | 401 | ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC; |
236e900c | 402 | |
1782514f DS |
403 | if (metric->type == metric_increment) |
404 | ei->route_map_set.metric += metric->metric; | |
405 | else if (metric->type == metric_decrement) | |
406 | ei->route_map_set.metric -= metric->metric; | |
407 | else if (metric->type == metric_absolute) | |
408 | ei->route_map_set.metric = metric->metric; | |
409 | ||
410 | if (ei->route_map_set.metric > OSPF_LS_INFINITY) | |
411 | ei->route_map_set.metric = OSPF_LS_INFINITY; | |
7a5e6e46 | 412 | |
d62a17ae | 413 | return RMAP_OKAY; |
718e3744 | 414 | } |
415 | ||
416 | /* set metric compilation. */ | |
d62a17ae | 417 | static void *route_set_metric_compile(const char *arg) |
418 | { | |
6a74c5f9 DS |
419 | struct ospf_metric *metric; |
420 | ||
cf0f13de | 421 | metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(*metric)); |
6a74c5f9 | 422 | metric->used = false; |
d62a17ae | 423 | |
7a5e6e46 | 424 | if (all_digit(arg)) |
425 | metric->type = metric_absolute; | |
426 | ||
427 | if (strmatch(arg, "+rtt") || strmatch(arg, "-rtt")) { | |
cf444bcf | 428 | flog_warn(EC_OSPF_SET_METRIC_PLUS, |
45301f8c | 429 | "OSPF does not support 'set metric +rtt / -rtt'"); |
7a5e6e46 | 430 | return metric; |
431 | } | |
432 | ||
433 | if ((arg[0] == '+') && all_digit(arg + 1)) { | |
434 | metric->type = metric_increment; | |
435 | arg++; | |
ed2eb093 | 436 | } |
7a5e6e46 | 437 | |
438 | if ((arg[0] == '-') && all_digit(arg + 1)) { | |
439 | metric->type = metric_decrement; | |
440 | arg++; | |
441 | } | |
442 | ||
6a74c5f9 | 443 | metric->metric = strtoul(arg, NULL, 10); |
7a5e6e46 | 444 | |
445 | if (metric->metric) | |
446 | metric->used = true; | |
d62a17ae | 447 | |
448 | return metric; | |
718e3744 | 449 | } |
450 | ||
451 | /* Free route map's compiled `set metric' value. */ | |
d62a17ae | 452 | static void route_set_metric_free(void *rule) |
718e3744 | 453 | { |
d62a17ae | 454 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 455 | } |
456 | ||
457 | /* Set metric rule structure. */ | |
364deb04 DL |
458 | static const struct route_map_rule_cmd route_set_metric_cmd = { |
459 | "metric", | |
460 | route_set_metric, | |
461 | route_set_metric_compile, | |
d62a17ae | 462 | route_set_metric_free, |
718e3744 | 463 | }; |
464 | ||
465 | /* `set metric-type TYPE' */ | |
466 | /* Set metric-type to attribute. */ | |
b68885f9 | 467 | static enum route_map_cmd_result_t |
1782514f | 468 | route_set_metric_type(void *rule, const struct prefix *prefix, void *object) |
718e3744 | 469 | { |
d7c0a89a | 470 | uint32_t *metric_type; |
d62a17ae | 471 | struct external_info *ei; |
472 | ||
1782514f DS |
473 | /* Fetch routemap's rule information. */ |
474 | metric_type = rule; | |
475 | ei = object; | |
476 | ||
477 | /* Set metric out value. */ | |
478 | ei->route_map_set.metric_type = *metric_type; | |
d62a17ae | 479 | |
d62a17ae | 480 | return RMAP_OKAY; |
718e3744 | 481 | } |
482 | ||
483 | /* set metric-type compilation. */ | |
d62a17ae | 484 | static void *route_set_metric_type_compile(const char *arg) |
718e3744 | 485 | { |
d7c0a89a | 486 | uint32_t *metric_type; |
718e3744 | 487 | |
d7c0a89a | 488 | metric_type = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); |
d62a17ae | 489 | if (strcmp(arg, "type-1") == 0) |
490 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
491 | else if (strcmp(arg, "type-2") == 0) | |
492 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
718e3744 | 493 | |
d62a17ae | 494 | if (*metric_type == EXTERNAL_METRIC_TYPE_1 |
495 | || *metric_type == EXTERNAL_METRIC_TYPE_2) | |
496 | return metric_type; | |
718e3744 | 497 | |
d62a17ae | 498 | XFREE(MTYPE_ROUTE_MAP_COMPILED, metric_type); |
499 | return NULL; | |
718e3744 | 500 | } |
501 | ||
502 | /* Free route map's compiled `set metric-type' value. */ | |
d62a17ae | 503 | static void route_set_metric_type_free(void *rule) |
718e3744 | 504 | { |
d62a17ae | 505 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 506 | } |
507 | ||
508 | /* Set metric rule structure. */ | |
364deb04 DL |
509 | static const struct route_map_rule_cmd route_set_metric_type_cmd = { |
510 | "metric-type", | |
511 | route_set_metric_type, | |
512 | route_set_metric_type_compile, | |
d62a17ae | 513 | route_set_metric_type_free, |
718e3744 | 514 | }; |
515 | ||
b68885f9 | 516 | static enum route_map_cmd_result_t |
1782514f | 517 | route_set_tag(void *rule, const struct prefix *prefix, void *object) |
0d9551dc | 518 | { |
d62a17ae | 519 | route_tag_t *tag; |
520 | struct external_info *ei; | |
0d9551dc | 521 | |
1782514f DS |
522 | tag = rule; |
523 | ei = object; | |
0d9551dc | 524 | |
1782514f DS |
525 | /* Set tag value */ |
526 | ei->tag = *tag; | |
0d9551dc | 527 | |
d62a17ae | 528 | return RMAP_OKAY; |
0d9551dc DS |
529 | } |
530 | ||
0d9551dc | 531 | /* Route map commands for tag set. */ |
364deb04 DL |
532 | static const struct route_map_rule_cmd route_set_tag_cmd = { |
533 | "tag", | |
534 | route_set_tag, | |
535 | route_map_rule_tag_compile, | |
d62a17ae | 536 | route_map_rule_tag_free, |
0d9551dc DS |
537 | }; |
538 | ||
a623b526 | 539 | DEFUN_YANG (set_metric_type, |
718e3744 | 540 | set_metric_type_cmd, |
6147e2c6 | 541 | "set metric-type <type-1|type-2>", |
718e3744 | 542 | SET_STR |
543 | "Type of metric for destination routing protocol\n" | |
73ffb25b | 544 | "OSPF[6] external type 1 metric\n" |
545 | "OSPF[6] external type 2 metric\n") | |
718e3744 | 546 | { |
d62a17ae | 547 | char *ext = argv[2]->text; |
a623b526 SP |
548 | |
549 | const char *xpath = | |
550 | "./set-action[action='frr-ospf-route-map:metric-type']"; | |
551 | char xpath_value[XPATH_MAXLEN]; | |
552 | ||
553 | nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | |
554 | snprintf(xpath_value, sizeof(xpath_value), | |
555 | "%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath); | |
556 | nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ext); | |
557 | return nb_cli_apply_changes(vty, NULL); | |
718e3744 | 558 | } |
559 | ||
a623b526 | 560 | DEFUN_YANG (no_set_metric_type, |
718e3744 | 561 | no_set_metric_type_cmd, |
692b4c65 | 562 | "no set metric-type [<type-1|type-2>]", |
718e3744 | 563 | NO_STR |
564 | SET_STR | |
ff788d08 | 565 | "Type of metric for destination routing protocol\n" |
692b4c65 | 566 | "OSPF[6] external type 1 metric\n" |
ff788d08 | 567 | "OSPF[6] external type 2 metric\n") |
718e3744 | 568 | { |
a623b526 SP |
569 | const char *xpath = |
570 | "./set-action[action='frr-ospf-route-map:metric-type']"; | |
571 | ||
572 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
573 | return nb_cli_apply_changes(vty, NULL); | |
0d9551dc DS |
574 | } |
575 | ||
718e3744 | 576 | /* Route-map init */ |
d62a17ae | 577 | void ospf_route_map_init(void) |
718e3744 | 578 | { |
d62a17ae | 579 | route_map_init(); |
580 | ||
581 | route_map_add_hook(ospf_route_map_update); | |
582 | route_map_delete_hook(ospf_route_map_update); | |
583 | route_map_event_hook(ospf_route_map_event); | |
718e3744 | 584 | |
d62a17ae | 585 | route_map_set_metric_hook(generic_set_add); |
586 | route_map_no_set_metric_hook(generic_set_delete); | |
82f97584 | 587 | |
d62a17ae | 588 | route_map_match_ip_next_hop_hook(generic_match_add); |
589 | route_map_no_match_ip_next_hop_hook(generic_match_delete); | |
58b0878a | 590 | |
d62a17ae | 591 | route_map_match_interface_hook(generic_match_add); |
592 | route_map_no_match_interface_hook(generic_match_delete); | |
58b0878a | 593 | |
d62a17ae | 594 | route_map_match_ip_address_hook(generic_match_add); |
595 | route_map_no_match_ip_address_hook(generic_match_delete); | |
82f97584 | 596 | |
d62a17ae | 597 | route_map_match_ip_address_prefix_list_hook(generic_match_add); |
598 | route_map_no_match_ip_address_prefix_list_hook(generic_match_delete); | |
82f97584 | 599 | |
d62a17ae | 600 | route_map_match_ip_next_hop_prefix_list_hook(generic_match_add); |
601 | route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete); | |
82f97584 | 602 | |
b6c0e913 DA |
603 | route_map_match_ip_next_hop_type_hook(generic_match_add); |
604 | route_map_no_match_ip_next_hop_type_hook(generic_match_delete); | |
605 | ||
d62a17ae | 606 | route_map_match_tag_hook(generic_match_add); |
607 | route_map_no_match_tag_hook(generic_match_delete); | |
82f97584 | 608 | |
d62a17ae | 609 | route_map_set_metric_hook(generic_set_add); |
610 | route_map_no_set_metric_hook(generic_set_delete); | |
82f97584 | 611 | |
d62a17ae | 612 | route_map_set_tag_hook(generic_set_add); |
613 | route_map_no_set_tag_hook(generic_set_delete); | |
82f97584 | 614 | |
d62a17ae | 615 | route_map_install_match(&route_match_ip_nexthop_cmd); |
616 | route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd); | |
617 | route_map_install_match(&route_match_ip_address_cmd); | |
618 | route_map_install_match(&route_match_ip_address_prefix_list_cmd); | |
b6c0e913 | 619 | route_map_install_match(&route_match_ip_next_hop_type_cmd); |
d62a17ae | 620 | route_map_install_match(&route_match_interface_cmd); |
621 | route_map_install_match(&route_match_tag_cmd); | |
718e3744 | 622 | |
d62a17ae | 623 | route_map_install_set(&route_set_metric_cmd); |
624 | route_map_install_set(&route_set_metric_type_cmd); | |
625 | route_map_install_set(&route_set_tag_cmd); | |
718e3744 | 626 | |
d62a17ae | 627 | install_element(RMAP_NODE, &set_metric_type_cmd); |
628 | install_element(RMAP_NODE, &no_set_metric_type_cmd); | |
718e3744 | 629 | } |