]>
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. */ | |
d62a17ae | 167 | struct route_map_rule_cmd route_match_ip_nexthop_cmd = { |
168 | "ip next-hop", route_match_ip_nexthop, route_match_ip_nexthop_compile, | |
169 | route_match_ip_nexthop_free}; | |
718e3744 | 170 | |
171 | /* `match ip next-hop prefix-list PREFIX_LIST' */ | |
172 | ||
b68885f9 | 173 | static enum route_map_cmd_result_t |
123214ef | 174 | route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, |
d62a17ae | 175 | route_map_object_t type, void *object) |
718e3744 | 176 | { |
d62a17ae | 177 | struct prefix_list *plist; |
178 | struct external_info *ei = object; | |
179 | struct prefix_ipv4 p; | |
180 | ||
181 | if (type == RMAP_OSPF) { | |
182 | p.family = AF_INET; | |
183 | p.prefix = ei->nexthop; | |
184 | p.prefixlen = IPV4_MAX_BITLEN; | |
185 | ||
186 | plist = prefix_list_lookup(AFI_IP, (char *)rule); | |
187 | if (plist == NULL) | |
188 | return RMAP_NOMATCH; | |
189 | ||
190 | return (prefix_list_apply(plist, &p) == PREFIX_DENY | |
191 | ? RMAP_NOMATCH | |
192 | : RMAP_MATCH); | |
193 | } | |
194 | return RMAP_NOMATCH; | |
718e3744 | 195 | } |
196 | ||
d62a17ae | 197 | static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) |
718e3744 | 198 | { |
d62a17ae | 199 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 200 | } |
201 | ||
d62a17ae | 202 | static void route_match_ip_next_hop_prefix_list_free(void *rule) |
718e3744 | 203 | { |
d62a17ae | 204 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 205 | } |
206 | ||
d62a17ae | 207 | struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = { |
208 | "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list, | |
209 | route_match_ip_next_hop_prefix_list_compile, | |
210 | route_match_ip_next_hop_prefix_list_free}; | |
718e3744 | 211 | |
b6c0e913 DA |
212 | /* `match ip next-hop type <blackhole>' */ |
213 | ||
b68885f9 | 214 | static enum route_map_cmd_result_t |
b6c0e913 DA |
215 | route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, |
216 | route_map_object_t type, void *object) | |
217 | { | |
218 | struct external_info *ei = object; | |
219 | ||
220 | if (type == RMAP_OSPF && prefix->family == AF_INET) { | |
221 | ei = (struct external_info *)object; | |
222 | if (!ei) | |
b68885f9 | 223 | return RMAP_NOMATCH; |
b6c0e913 DA |
224 | |
225 | if (ei->nexthop.s_addr == INADDR_ANY && !ei->ifindex) | |
226 | return RMAP_MATCH; | |
227 | } | |
228 | return RMAP_NOMATCH; | |
229 | } | |
230 | ||
231 | static void *route_match_ip_next_hop_type_compile(const char *arg) | |
232 | { | |
233 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
234 | } | |
235 | ||
236 | static void route_match_ip_next_hop_type_free(void *rule) | |
237 | { | |
238 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
239 | } | |
240 | ||
241 | static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd = { | |
242 | "ip next-hop type", route_match_ip_next_hop_type, | |
243 | route_match_ip_next_hop_type_compile, | |
244 | route_match_ip_next_hop_type_free}; | |
245 | ||
718e3744 | 246 | /* `match ip address IP_ACCESS_LIST' */ |
247 | /* Match function should return 1 if match is success else return | |
248 | zero. */ | |
b68885f9 LK |
249 | static enum route_map_cmd_result_t |
250 | route_match_ip_address(void *rule, const struct prefix *prefix, | |
251 | route_map_object_t type, void *object) | |
d62a17ae | 252 | { |
253 | struct access_list *alist; | |
254 | /* struct prefix_ipv4 match; */ | |
255 | ||
256 | if (type == RMAP_OSPF) { | |
257 | alist = access_list_lookup(AFI_IP, (char *)rule); | |
258 | if (alist == NULL) | |
259 | return RMAP_NOMATCH; | |
260 | ||
261 | return (access_list_apply(alist, prefix) == FILTER_DENY | |
262 | ? RMAP_NOMATCH | |
263 | : RMAP_MATCH); | |
264 | } | |
265 | return RMAP_NOMATCH; | |
718e3744 | 266 | } |
267 | ||
268 | /* Route map `ip address' match statement. `arg' should be | |
269 | access-list name. */ | |
d62a17ae | 270 | static void *route_match_ip_address_compile(const char *arg) |
718e3744 | 271 | { |
d62a17ae | 272 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 273 | } |
274 | ||
275 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 276 | static void route_match_ip_address_free(void *rule) |
718e3744 | 277 | { |
d62a17ae | 278 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 279 | } |
280 | ||
281 | /* Route map commands for ip address matching. */ | |
d62a17ae | 282 | struct route_map_rule_cmd route_match_ip_address_cmd = { |
283 | "ip address", route_match_ip_address, route_match_ip_address_compile, | |
284 | route_match_ip_address_free}; | |
718e3744 | 285 | |
286 | /* `match ip address prefix-list PREFIX_LIST' */ | |
b68885f9 | 287 | static enum route_map_cmd_result_t |
123214ef | 288 | route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, |
d62a17ae | 289 | route_map_object_t type, void *object) |
718e3744 | 290 | { |
d62a17ae | 291 | struct prefix_list *plist; |
292 | ||
293 | if (type == RMAP_OSPF) { | |
294 | plist = prefix_list_lookup(AFI_IP, (char *)rule); | |
295 | if (plist == NULL) | |
296 | return RMAP_NOMATCH; | |
297 | ||
298 | return (prefix_list_apply(plist, prefix) == PREFIX_DENY | |
299 | ? RMAP_NOMATCH | |
300 | : RMAP_MATCH); | |
301 | } | |
302 | return RMAP_NOMATCH; | |
718e3744 | 303 | } |
304 | ||
d62a17ae | 305 | static void *route_match_ip_address_prefix_list_compile(const char *arg) |
718e3744 | 306 | { |
d62a17ae | 307 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 308 | } |
309 | ||
d62a17ae | 310 | static void route_match_ip_address_prefix_list_free(void *rule) |
718e3744 | 311 | { |
d62a17ae | 312 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 313 | } |
314 | ||
d62a17ae | 315 | struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = { |
316 | "ip address prefix-list", route_match_ip_address_prefix_list, | |
317 | route_match_ip_address_prefix_list_compile, | |
318 | route_match_ip_address_prefix_list_free}; | |
718e3744 | 319 | |
320 | /* `match interface IFNAME' */ | |
321 | /* Match function should return 1 if match is success else return | |
322 | zero. */ | |
b68885f9 LK |
323 | static enum route_map_cmd_result_t |
324 | route_match_interface(void *rule, const struct prefix *prefix, | |
325 | route_map_object_t type, void *object) | |
718e3744 | 326 | { |
d62a17ae | 327 | struct interface *ifp; |
328 | struct external_info *ei; | |
718e3744 | 329 | |
d62a17ae | 330 | if (type == RMAP_OSPF) { |
331 | ei = object; | |
b5a8894d | 332 | ifp = if_lookup_by_name_all_vrf((char *)rule); |
718e3744 | 333 | |
d62a17ae | 334 | if (ifp == NULL || ifp->ifindex != ei->ifindex) |
335 | return RMAP_NOMATCH; | |
718e3744 | 336 | |
d62a17ae | 337 | return RMAP_MATCH; |
338 | } | |
339 | return RMAP_NOMATCH; | |
718e3744 | 340 | } |
341 | ||
342 | /* Route map `interface' match statement. `arg' should be | |
343 | interface name. */ | |
d62a17ae | 344 | static void *route_match_interface_compile(const char *arg) |
718e3744 | 345 | { |
d62a17ae | 346 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 347 | } |
348 | ||
349 | /* Free route map's compiled `interface' value. */ | |
d62a17ae | 350 | static void route_match_interface_free(void *rule) |
718e3744 | 351 | { |
d62a17ae | 352 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 353 | } |
354 | ||
355 | /* Route map commands for ip address matching. */ | |
d62a17ae | 356 | struct route_map_rule_cmd route_match_interface_cmd = { |
357 | "interface", route_match_interface, route_match_interface_compile, | |
358 | route_match_interface_free}; | |
718e3744 | 359 | |
0d9551dc | 360 | /* Match function return 1 if match is success else return zero. */ |
b68885f9 LK |
361 | static enum route_map_cmd_result_t |
362 | route_match_tag(void *rule, const struct prefix *prefix, | |
363 | route_map_object_t type, void *object) | |
0d9551dc | 364 | { |
d62a17ae | 365 | route_tag_t *tag; |
366 | struct external_info *ei; | |
0d9551dc | 367 | |
d62a17ae | 368 | if (type == RMAP_OSPF) { |
369 | tag = rule; | |
370 | ei = object; | |
0d9551dc | 371 | |
d62a17ae | 372 | return ((ei->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); |
373 | } | |
0d9551dc | 374 | |
d62a17ae | 375 | return RMAP_NOMATCH; |
0d9551dc DS |
376 | } |
377 | ||
0d9551dc | 378 | /* Route map commands for tag matching. */ |
d62a17ae | 379 | static struct route_map_rule_cmd route_match_tag_cmd = { |
9d303b37 | 380 | "tag", route_match_tag, route_map_rule_tag_compile, |
d62a17ae | 381 | route_map_rule_tag_free, |
0d9551dc DS |
382 | }; |
383 | ||
6a74c5f9 | 384 | struct ospf_metric { |
7a5e6e46 | 385 | enum { metric_increment, metric_decrement, metric_absolute } type; |
6a74c5f9 | 386 | bool used; |
d7c0a89a | 387 | uint32_t metric; |
6a74c5f9 | 388 | }; |
0d9551dc | 389 | |
718e3744 | 390 | /* `set metric METRIC' */ |
391 | /* Set metric to attribute. */ | |
b68885f9 LK |
392 | static enum route_map_cmd_result_t |
393 | route_set_metric(void *rule, const struct prefix *prefix, | |
394 | route_map_object_t type, void *object) | |
718e3744 | 395 | { |
6a74c5f9 | 396 | struct ospf_metric *metric; |
d62a17ae | 397 | struct external_info *ei; |
398 | ||
399 | if (type == RMAP_OSPF) { | |
400 | /* Fetch routemap's rule information. */ | |
401 | metric = rule; | |
402 | ei = object; | |
403 | ||
404 | /* Set metric out value. */ | |
7a5e6e46 | 405 | if (!metric->used) |
406 | return RMAP_OKAY; | |
236e900c QY |
407 | |
408 | ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC; | |
409 | ||
7a5e6e46 | 410 | if (metric->type == metric_increment) |
411 | ei->route_map_set.metric += metric->metric; | |
236e900c | 412 | else if (metric->type == metric_decrement) |
7a5e6e46 | 413 | ei->route_map_set.metric -= metric->metric; |
236e900c | 414 | else if (metric->type == metric_absolute) |
6a74c5f9 | 415 | ei->route_map_set.metric = metric->metric; |
7a5e6e46 | 416 | |
7a5e6e46 | 417 | if (ei->route_map_set.metric > OSPF_LS_INFINITY) |
418 | ei->route_map_set.metric = OSPF_LS_INFINITY; | |
d62a17ae | 419 | } |
420 | return RMAP_OKAY; | |
718e3744 | 421 | } |
422 | ||
423 | /* set metric compilation. */ | |
d62a17ae | 424 | static void *route_set_metric_compile(const char *arg) |
425 | { | |
6a74c5f9 DS |
426 | struct ospf_metric *metric; |
427 | ||
d7c0a89a | 428 | metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); |
6a74c5f9 | 429 | metric->used = false; |
d62a17ae | 430 | |
7a5e6e46 | 431 | if (all_digit(arg)) |
432 | metric->type = metric_absolute; | |
433 | ||
434 | if (strmatch(arg, "+rtt") || strmatch(arg, "-rtt")) { | |
cf444bcf | 435 | flog_warn(EC_OSPF_SET_METRIC_PLUS, |
45301f8c | 436 | "OSPF does not support 'set metric +rtt / -rtt'"); |
7a5e6e46 | 437 | return metric; |
438 | } | |
439 | ||
440 | if ((arg[0] == '+') && all_digit(arg + 1)) { | |
441 | metric->type = metric_increment; | |
442 | arg++; | |
ed2eb093 | 443 | } |
7a5e6e46 | 444 | |
445 | if ((arg[0] == '-') && all_digit(arg + 1)) { | |
446 | metric->type = metric_decrement; | |
447 | arg++; | |
448 | } | |
449 | ||
6a74c5f9 | 450 | metric->metric = strtoul(arg, NULL, 10); |
7a5e6e46 | 451 | |
452 | if (metric->metric) | |
453 | metric->used = true; | |
d62a17ae | 454 | |
455 | return metric; | |
718e3744 | 456 | } |
457 | ||
458 | /* Free route map's compiled `set metric' value. */ | |
d62a17ae | 459 | static void route_set_metric_free(void *rule) |
718e3744 | 460 | { |
d62a17ae | 461 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 462 | } |
463 | ||
464 | /* Set metric rule structure. */ | |
d62a17ae | 465 | struct route_map_rule_cmd route_set_metric_cmd = { |
9d303b37 | 466 | "metric", route_set_metric, route_set_metric_compile, |
d62a17ae | 467 | route_set_metric_free, |
718e3744 | 468 | }; |
469 | ||
470 | /* `set metric-type TYPE' */ | |
471 | /* Set metric-type to attribute. */ | |
b68885f9 LK |
472 | static enum route_map_cmd_result_t |
473 | route_set_metric_type(void *rule, const struct prefix *prefix, | |
474 | route_map_object_t type, void *object) | |
718e3744 | 475 | { |
d7c0a89a | 476 | uint32_t *metric_type; |
d62a17ae | 477 | struct external_info *ei; |
478 | ||
479 | if (type == RMAP_OSPF) { | |
480 | /* Fetch routemap's rule information. */ | |
481 | metric_type = rule; | |
482 | ei = object; | |
483 | ||
484 | /* Set metric out value. */ | |
485 | ei->route_map_set.metric_type = *metric_type; | |
486 | } | |
487 | return RMAP_OKAY; | |
718e3744 | 488 | } |
489 | ||
490 | /* set metric-type compilation. */ | |
d62a17ae | 491 | static void *route_set_metric_type_compile(const char *arg) |
718e3744 | 492 | { |
d7c0a89a | 493 | uint32_t *metric_type; |
718e3744 | 494 | |
d7c0a89a | 495 | metric_type = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); |
d62a17ae | 496 | if (strcmp(arg, "type-1") == 0) |
497 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
498 | else if (strcmp(arg, "type-2") == 0) | |
499 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
718e3744 | 500 | |
d62a17ae | 501 | if (*metric_type == EXTERNAL_METRIC_TYPE_1 |
502 | || *metric_type == EXTERNAL_METRIC_TYPE_2) | |
503 | return metric_type; | |
718e3744 | 504 | |
d62a17ae | 505 | XFREE(MTYPE_ROUTE_MAP_COMPILED, metric_type); |
506 | return NULL; | |
718e3744 | 507 | } |
508 | ||
509 | /* Free route map's compiled `set metric-type' value. */ | |
d62a17ae | 510 | static void route_set_metric_type_free(void *rule) |
718e3744 | 511 | { |
d62a17ae | 512 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 513 | } |
514 | ||
515 | /* Set metric rule structure. */ | |
d62a17ae | 516 | struct route_map_rule_cmd route_set_metric_type_cmd = { |
9d303b37 | 517 | "metric-type", route_set_metric_type, route_set_metric_type_compile, |
d62a17ae | 518 | route_set_metric_type_free, |
718e3744 | 519 | }; |
520 | ||
b68885f9 LK |
521 | static enum route_map_cmd_result_t |
522 | route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type, | |
523 | void *object) | |
0d9551dc | 524 | { |
d62a17ae | 525 | route_tag_t *tag; |
526 | struct external_info *ei; | |
0d9551dc | 527 | |
d62a17ae | 528 | if (type == RMAP_OSPF) { |
529 | tag = rule; | |
530 | ei = object; | |
0d9551dc | 531 | |
d62a17ae | 532 | /* Set tag value */ |
533 | ei->tag = *tag; | |
534 | } | |
0d9551dc | 535 | |
d62a17ae | 536 | return RMAP_OKAY; |
0d9551dc DS |
537 | } |
538 | ||
0d9551dc | 539 | /* Route map commands for tag set. */ |
d62a17ae | 540 | static struct route_map_rule_cmd route_set_tag_cmd = { |
9d303b37 | 541 | "tag", route_set_tag, route_map_rule_tag_compile, |
d62a17ae | 542 | route_map_rule_tag_free, |
0d9551dc DS |
543 | }; |
544 | ||
718e3744 | 545 | DEFUN (set_metric_type, |
546 | set_metric_type_cmd, | |
6147e2c6 | 547 | "set metric-type <type-1|type-2>", |
718e3744 | 548 | SET_STR |
549 | "Type of metric for destination routing protocol\n" | |
73ffb25b | 550 | "OSPF[6] external type 1 metric\n" |
551 | "OSPF[6] external type 2 metric\n") | |
718e3744 | 552 | { |
d62a17ae | 553 | char *ext = argv[2]->text; |
554 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
555 | "metric-type", ext); | |
718e3744 | 556 | } |
557 | ||
558 | DEFUN (no_set_metric_type, | |
559 | no_set_metric_type_cmd, | |
692b4c65 | 560 | "no set metric-type [<type-1|type-2>]", |
718e3744 | 561 | NO_STR |
562 | SET_STR | |
ff788d08 | 563 | "Type of metric for destination routing protocol\n" |
692b4c65 | 564 | "OSPF[6] external type 1 metric\n" |
ff788d08 | 565 | "OSPF[6] external type 2 metric\n") |
718e3744 | 566 | { |
d62a17ae | 567 | char *ext = (argc == 4) ? argv[3]->text : NULL; |
568 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
569 | "metric-type", ext); | |
0d9551dc DS |
570 | } |
571 | ||
718e3744 | 572 | /* Route-map init */ |
d62a17ae | 573 | void ospf_route_map_init(void) |
718e3744 | 574 | { |
d62a17ae | 575 | route_map_init(); |
576 | ||
577 | route_map_add_hook(ospf_route_map_update); | |
578 | route_map_delete_hook(ospf_route_map_update); | |
579 | route_map_event_hook(ospf_route_map_event); | |
718e3744 | 580 | |
d62a17ae | 581 | route_map_set_metric_hook(generic_set_add); |
582 | route_map_no_set_metric_hook(generic_set_delete); | |
82f97584 | 583 | |
d62a17ae | 584 | route_map_match_ip_next_hop_hook(generic_match_add); |
585 | route_map_no_match_ip_next_hop_hook(generic_match_delete); | |
58b0878a | 586 | |
d62a17ae | 587 | route_map_match_interface_hook(generic_match_add); |
588 | route_map_no_match_interface_hook(generic_match_delete); | |
58b0878a | 589 | |
d62a17ae | 590 | route_map_match_ip_address_hook(generic_match_add); |
591 | route_map_no_match_ip_address_hook(generic_match_delete); | |
82f97584 | 592 | |
d62a17ae | 593 | route_map_match_ip_address_prefix_list_hook(generic_match_add); |
594 | route_map_no_match_ip_address_prefix_list_hook(generic_match_delete); | |
82f97584 | 595 | |
d62a17ae | 596 | route_map_match_ip_next_hop_prefix_list_hook(generic_match_add); |
597 | route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete); | |
82f97584 | 598 | |
b6c0e913 DA |
599 | route_map_match_ip_next_hop_type_hook(generic_match_add); |
600 | route_map_no_match_ip_next_hop_type_hook(generic_match_delete); | |
601 | ||
d62a17ae | 602 | route_map_match_tag_hook(generic_match_add); |
603 | route_map_no_match_tag_hook(generic_match_delete); | |
82f97584 | 604 | |
d62a17ae | 605 | route_map_set_metric_hook(generic_set_add); |
606 | route_map_no_set_metric_hook(generic_set_delete); | |
82f97584 | 607 | |
d62a17ae | 608 | route_map_set_tag_hook(generic_set_add); |
609 | route_map_no_set_tag_hook(generic_set_delete); | |
82f97584 | 610 | |
d62a17ae | 611 | route_map_install_match(&route_match_ip_nexthop_cmd); |
612 | route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd); | |
613 | route_map_install_match(&route_match_ip_address_cmd); | |
614 | route_map_install_match(&route_match_ip_address_prefix_list_cmd); | |
b6c0e913 | 615 | route_map_install_match(&route_match_ip_next_hop_type_cmd); |
d62a17ae | 616 | route_map_install_match(&route_match_interface_cmd); |
617 | route_map_install_match(&route_match_tag_cmd); | |
718e3744 | 618 | |
d62a17ae | 619 | route_map_install_set(&route_set_metric_cmd); |
620 | route_map_install_set(&route_set_metric_type_cmd); | |
621 | route_map_install_set(&route_set_tag_cmd); | |
718e3744 | 622 | |
d62a17ae | 623 | install_element(RMAP_NODE, &set_metric_type_cmd); |
624 | install_element(RMAP_NODE, &no_set_metric_type_cmd); | |
718e3744 | 625 | } |