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