]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 3 | * |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the | |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | * Boston, MA 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "log.h" | |
25 | #include "memory.h" | |
26 | #include "prefix.h" | |
27 | #include "command.h" | |
28 | #include "vty.h" | |
29 | #include "routemap.h" | |
30 | #include "table.h" | |
31 | #include "plist.h" | |
32 | #include "thread.h" | |
508e53e2 | 33 | #include "linklist.h" |
718e3744 | 34 | |
508e53e2 | 35 | #include "ospf6_proto.h" |
36 | #include "ospf6_lsa.h" | |
37 | #include "ospf6_lsdb.h" | |
38 | #include "ospf6_route.h" | |
718e3744 | 39 | #include "ospf6_zebra.h" |
6452df09 | 40 | #include "ospf6_message.h" |
41 | ||
718e3744 | 42 | #include "ospf6_top.h" |
508e53e2 | 43 | #include "ospf6_area.h" |
6452df09 | 44 | #include "ospf6_interface.h" |
45 | #include "ospf6_neighbor.h" | |
508e53e2 | 46 | #include "ospf6_asbr.h" |
47 | #include "ospf6_intra.h" | |
6452df09 | 48 | #include "ospf6_flood.h" |
049207c3 | 49 | #include "ospf6d.h" |
718e3744 | 50 | |
508e53e2 | 51 | unsigned char conf_debug_ospf6_asbr = 0; |
718e3744 | 52 | |
f52d13cb | 53 | #define ZROUTE_NAME(x) zebra_route_string(x) |
508e53e2 | 54 | |
55 | /* AS External LSA origination */ | |
6ac29a51 | 56 | static void |
6452df09 | 57 | ospf6_as_external_lsa_originate (struct ospf6_route *route) |
718e3744 | 58 | { |
508e53e2 | 59 | char buffer[OSPF6_MAX_LSASIZE]; |
60 | struct ospf6_lsa_header *lsa_header; | |
61 | struct ospf6_lsa *old, *lsa; | |
0b26f81b | 62 | struct ospf6_external_info *info = route->route_option; |
718e3744 | 63 | |
508e53e2 | 64 | struct ospf6_as_external_lsa *as_external_lsa; |
65 | char buf[64]; | |
66 | caddr_t p; | |
718e3744 | 67 | |
508e53e2 | 68 | /* find previous LSA */ |
69 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL), | |
6452df09 | 70 | route->path.origin.id, ospf6->router_id, |
508e53e2 | 71 | ospf6->lsdb); |
718e3744 | 72 | |
1e05838a | 73 | if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL)) |
508e53e2 | 74 | { |
75 | prefix2str (&route->prefix, buf, sizeof (buf)); | |
c6487d61 | 76 | zlog_debug ("Originate AS-External-LSA for %s", buf); |
508e53e2 | 77 | } |
78 | ||
79 | /* prepare buffer */ | |
80 | memset (buffer, 0, sizeof (buffer)); | |
81 | lsa_header = (struct ospf6_lsa_header *) buffer; | |
82 | as_external_lsa = (struct ospf6_as_external_lsa *) | |
83 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); | |
84 | p = (caddr_t) | |
85 | ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa)); | |
86 | ||
87 | /* Fill AS-External-LSA */ | |
88 | /* Metric type */ | |
89 | if (route->path.metric_type == 2) | |
90 | SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E); | |
91 | else | |
92 | UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E); | |
93 | ||
94 | /* forwarding address */ | |
0b26f81b | 95 | if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding)) |
508e53e2 | 96 | SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F); |
97 | else | |
98 | UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F); | |
718e3744 | 99 | |
508e53e2 | 100 | /* external route tag */ |
101 | UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T); | |
102 | ||
103 | /* Set metric */ | |
104 | OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost); | |
105 | ||
106 | /* prefixlen */ | |
107 | as_external_lsa->prefix.prefix_length = route->prefix.prefixlen; | |
108 | ||
109 | /* PrefixOptions */ | |
110 | as_external_lsa->prefix.prefix_options = route->path.prefix_options; | |
111 | ||
112 | /* don't use refer LS-type */ | |
113 | as_external_lsa->prefix.prefix_refer_lstype = htons (0); | |
114 | ||
115 | /* set Prefix */ | |
116 | memcpy (p, &route->prefix.u.prefix6, | |
117 | OSPF6_PREFIX_SPACE (route->prefix.prefixlen)); | |
118 | ospf6_prefix_apply_mask (&as_external_lsa->prefix); | |
119 | p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen); | |
120 | ||
121 | /* Forwarding address */ | |
122 | if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F)) | |
123 | { | |
0b26f81b | 124 | memcpy (p, &info->forwarding, sizeof (struct in6_addr)); |
508e53e2 | 125 | p += sizeof (struct in6_addr); |
126 | } | |
127 | ||
128 | /* External Route Tag */ | |
129 | if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T)) | |
130 | { | |
131 | /* xxx */ | |
132 | } | |
133 | ||
134 | /* Fill LSA Header */ | |
135 | lsa_header->age = 0; | |
136 | lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL); | |
6452df09 | 137 | lsa_header->id = route->path.origin.id; |
508e53e2 | 138 | lsa_header->adv_router = ospf6->router_id; |
139 | lsa_header->seqnum = | |
049207c3 | 140 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
141 | lsa_header->adv_router, ospf6->lsdb); | |
508e53e2 | 142 | lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header); |
143 | ||
144 | /* LSA checksum */ | |
145 | ospf6_lsa_checksum (lsa_header); | |
146 | ||
147 | /* create LSA */ | |
148 | lsa = ospf6_lsa_create (lsa_header); | |
508e53e2 | 149 | |
150 | /* Originate */ | |
6452df09 | 151 | ospf6_lsa_originate_process (lsa, ospf6); |
718e3744 | 152 | } |
153 | ||
508e53e2 | 154 | \f |
718e3744 | 155 | void |
508e53e2 | 156 | ospf6_asbr_lsa_add (struct ospf6_lsa *lsa) |
718e3744 | 157 | { |
508e53e2 | 158 | struct ospf6_as_external_lsa *external; |
159 | struct prefix asbr_id; | |
160 | struct ospf6_route *asbr_entry, *route; | |
161 | char buf[64]; | |
718e3744 | 162 | int i; |
508e53e2 | 163 | |
164 | external = (struct ospf6_as_external_lsa *) | |
165 | OSPF6_LSA_HEADER_END (lsa->header); | |
166 | ||
1e05838a | 167 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
c6487d61 | 168 | zlog_debug ("Calculate AS-External route for %s", lsa->name); |
508e53e2 | 169 | |
170 | if (lsa->header->adv_router == ospf6->router_id) | |
718e3744 | 171 | { |
1e05838a | 172 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
c6487d61 | 173 | zlog_debug ("Ignore self-originated AS-External-LSA"); |
508e53e2 | 174 | return; |
718e3744 | 175 | } |
718e3744 | 176 | |
8551e6da | 177 | if (OSPF6_ASBR_METRIC (external) == OSPF_LS_INFINITY) |
508e53e2 | 178 | { |
1e05838a | 179 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
c6487d61 | 180 | zlog_debug ("Ignore LSA with LSInfinity Metric"); |
508e53e2 | 181 | return; |
182 | } | |
718e3744 | 183 | |
ccb59b11 | 184 | ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id); |
6452df09 | 185 | asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table); |
63069ad6 | 186 | if (asbr_entry == NULL || |
187 | ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E)) | |
508e53e2 | 188 | { |
1e05838a | 189 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
508e53e2 | 190 | { |
191 | prefix2str (&asbr_id, buf, sizeof (buf)); | |
c6487d61 | 192 | zlog_debug ("ASBR entry not found: %s", buf); |
508e53e2 | 193 | } |
194 | return; | |
195 | } | |
718e3744 | 196 | |
508e53e2 | 197 | route = ospf6_route_create (); |
198 | route->type = OSPF6_DEST_TYPE_NETWORK; | |
199 | route->prefix.family = AF_INET6; | |
200 | route->prefix.prefixlen = external->prefix.prefix_length; | |
201 | ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix); | |
718e3744 | 202 | |
508e53e2 | 203 | route->path.area_id = asbr_entry->path.area_id; |
204 | route->path.origin.type = lsa->header->type; | |
205 | route->path.origin.id = lsa->header->id; | |
206 | route->path.origin.adv_router = lsa->header->adv_router; | |
718e3744 | 207 | |
508e53e2 | 208 | route->path.prefix_options = external->prefix.prefix_options; |
209 | if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E)) | |
210 | { | |
211 | route->path.type = OSPF6_PATH_TYPE_EXTERNAL2; | |
212 | route->path.metric_type = 2; | |
213 | route->path.cost = asbr_entry->path.cost; | |
214 | route->path.cost_e2 = OSPF6_ASBR_METRIC (external); | |
215 | } | |
216 | else | |
217 | { | |
218 | route->path.type = OSPF6_PATH_TYPE_EXTERNAL1; | |
219 | route->path.metric_type = 1; | |
220 | route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external); | |
221 | route->path.cost_e2 = 0; | |
222 | } | |
223 | ||
224 | for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) | |
225 | ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]); | |
226 | ||
1e05838a | 227 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
508e53e2 | 228 | { |
229 | prefix2str (&route->prefix, buf, sizeof (buf)); | |
c6487d61 | 230 | zlog_debug ("AS-External route add: %s", buf); |
508e53e2 | 231 | } |
232 | ||
233 | ospf6_route_add (route, ospf6->route_table); | |
718e3744 | 234 | } |
235 | ||
508e53e2 | 236 | void |
237 | ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa) | |
718e3744 | 238 | { |
508e53e2 | 239 | struct ospf6_as_external_lsa *external; |
240 | struct prefix prefix; | |
241 | struct ospf6_route *route; | |
242 | char buf[64]; | |
718e3744 | 243 | |
508e53e2 | 244 | external = (struct ospf6_as_external_lsa *) |
245 | OSPF6_LSA_HEADER_END (lsa->header); | |
718e3744 | 246 | |
1e05838a | 247 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
c6487d61 | 248 | zlog_debug ("Withdraw AS-External route for %s", lsa->name); |
718e3744 | 249 | |
508e53e2 | 250 | if (lsa->header->adv_router == ospf6->router_id) |
718e3744 | 251 | { |
1e05838a | 252 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
c6487d61 | 253 | zlog_debug ("Ignore self-originated AS-External-LSA"); |
508e53e2 | 254 | return; |
255 | } | |
256 | ||
257 | memset (&prefix, 0, sizeof (struct prefix)); | |
258 | prefix.family = AF_INET6; | |
259 | prefix.prefixlen = external->prefix.prefix_length; | |
260 | ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix); | |
261 | ||
262 | route = ospf6_route_lookup (&prefix, ospf6->route_table); | |
263 | if (route == NULL) | |
264 | { | |
1e05838a | 265 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
718e3744 | 266 | { |
508e53e2 | 267 | prefix2str (&prefix, buf, sizeof (buf)); |
c6487d61 | 268 | zlog_debug ("AS-External route %s not found", buf); |
718e3744 | 269 | } |
508e53e2 | 270 | return; |
718e3744 | 271 | } |
272 | ||
508e53e2 | 273 | for (ospf6_route_lock (route); |
274 | route && ospf6_route_is_prefix (&prefix, route); | |
275 | route = ospf6_route_next (route)) | |
276 | { | |
277 | if (route->type != OSPF6_DEST_TYPE_NETWORK) | |
278 | continue; | |
279 | if (route->path.origin.type != lsa->header->type) | |
280 | continue; | |
281 | if (route->path.origin.id != lsa->header->id) | |
282 | continue; | |
283 | if (route->path.origin.adv_router != lsa->header->adv_router) | |
284 | continue; | |
285 | ||
1e05838a | 286 | if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL)) |
508e53e2 | 287 | { |
288 | prefix2str (&route->prefix, buf, sizeof (buf)); | |
c6487d61 | 289 | zlog_debug ("AS-External route remove: %s", buf); |
508e53e2 | 290 | } |
291 | ospf6_route_remove (route, ospf6->route_table); | |
292 | } | |
718e3744 | 293 | } |
294 | ||
508e53e2 | 295 | void |
296 | ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry) | |
297 | { | |
508e53e2 | 298 | struct ospf6_lsa *lsa; |
299 | u_int16_t type; | |
300 | u_int32_t router; | |
301 | ||
cb4b8845 | 302 | if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST)) |
508e53e2 | 303 | { |
cb4b8845 PJ |
304 | char buf[16]; |
305 | inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix), | |
306 | buf, sizeof (buf)); | |
307 | zlog_info ("ignore non-best path: lsentry %s add", buf); | |
308 | return; | |
508e53e2 | 309 | } |
718e3744 | 310 | |
508e53e2 | 311 | type = htons (OSPF6_LSTYPE_AS_EXTERNAL); |
312 | router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix); | |
cb4b8845 PJ |
313 | for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa; |
314 | lsa = ospf6_lsdb_type_router_next (type, router, lsa)) | |
508e53e2 | 315 | { |
316 | if (! OSPF6_LSA_IS_MAXAGE (lsa)) | |
317 | ospf6_asbr_lsa_add (lsa); | |
318 | } | |
508e53e2 | 319 | } |
320 | ||
321 | void | |
322 | ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry) | |
718e3744 | 323 | { |
508e53e2 | 324 | struct ospf6_lsa *lsa; |
325 | u_int16_t type; | |
326 | u_int32_t router; | |
718e3744 | 327 | |
508e53e2 | 328 | type = htons (OSPF6_LSTYPE_AS_EXTERNAL); |
329 | router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix); | |
330 | for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); | |
331 | lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa)) | |
332 | ospf6_asbr_lsa_remove (lsa); | |
508e53e2 | 333 | } |
718e3744 | 334 | |
508e53e2 | 335 | |
336 | \f | |
337 | /* redistribute function */ | |
338 | ||
6ac29a51 | 339 | static void |
0c083ee9 | 340 | ospf6_asbr_routemap_set (int type, const char *mapname) |
508e53e2 | 341 | { |
342 | if (ospf6->rmap[type].name) | |
343 | free (ospf6->rmap[type].name); | |
344 | ospf6->rmap[type].name = strdup (mapname); | |
345 | ospf6->rmap[type].map = route_map_lookup_by_name (mapname); | |
718e3744 | 346 | } |
347 | ||
6ac29a51 | 348 | static void |
508e53e2 | 349 | ospf6_asbr_routemap_unset (int type) |
718e3744 | 350 | { |
508e53e2 | 351 | if (ospf6->rmap[type].name) |
352 | free (ospf6->rmap[type].name); | |
353 | ospf6->rmap[type].name = NULL; | |
354 | ospf6->rmap[type].map = NULL; | |
355 | } | |
356 | ||
6ac29a51 | 357 | static void |
0c083ee9 | 358 | ospf6_asbr_routemap_update (const char *mapname) |
508e53e2 | 359 | { |
360 | int type; | |
718e3744 | 361 | |
508e53e2 | 362 | if (ospf6 == NULL) |
718e3744 | 363 | return; |
364 | ||
508e53e2 | 365 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
718e3744 | 366 | { |
508e53e2 | 367 | if (ospf6->rmap[type].name) |
368 | ospf6->rmap[type].map = | |
369 | route_map_lookup_by_name (ospf6->rmap[type].name); | |
718e3744 | 370 | else |
508e53e2 | 371 | ospf6->rmap[type].map = NULL; |
718e3744 | 372 | } |
373 | } | |
374 | ||
718e3744 | 375 | int |
508e53e2 | 376 | ospf6_asbr_is_asbr (struct ospf6 *o) |
377 | { | |
378 | return o->external_table->count; | |
379 | } | |
380 | ||
6ac29a51 | 381 | static void |
508e53e2 | 382 | ospf6_asbr_redistribute_set (int type) |
718e3744 | 383 | { |
508e53e2 | 384 | ospf6_zebra_redistribute (type); |
385 | } | |
386 | ||
6ac29a51 | 387 | static void |
508e53e2 | 388 | ospf6_asbr_redistribute_unset (int type) |
389 | { | |
390 | struct ospf6_route *route; | |
718e3744 | 391 | struct ospf6_external_info *info; |
718e3744 | 392 | |
508e53e2 | 393 | ospf6_zebra_no_redistribute (type); |
394 | ||
395 | for (route = ospf6_route_head (ospf6->external_table); route; | |
396 | route = ospf6_route_next (route)) | |
397 | { | |
398 | info = route->route_option; | |
399 | if (info->type != type) | |
400 | continue; | |
718e3744 | 401 | |
508e53e2 | 402 | ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex, |
403 | &route->prefix); | |
404 | } | |
405 | } | |
718e3744 | 406 | |
508e53e2 | 407 | void |
408 | ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix, | |
409 | u_int nexthop_num, struct in6_addr *nexthop) | |
410 | { | |
411 | int ret; | |
412 | struct ospf6_route troute; | |
413 | struct ospf6_external_info tinfo; | |
414 | struct ospf6_route *route, *match; | |
415 | struct ospf6_external_info *info; | |
416 | struct prefix prefix_id; | |
417 | struct route_node *node; | |
418 | char pbuf[64], ibuf[16]; | |
1eb8ef25 | 419 | struct listnode *lnode, *lnnode; |
508e53e2 | 420 | struct ospf6_area *oa; |
421 | ||
422 | if (! ospf6_zebra_is_redistribute (type)) | |
423 | return; | |
424 | ||
425 | if (IS_OSPF6_DEBUG_ASBR) | |
426 | { | |
427 | prefix2str (prefix, pbuf, sizeof (pbuf)); | |
c6487d61 | 428 | zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type)); |
508e53e2 | 429 | } |
430 | ||
431 | /* if route-map was specified but not found, do not advertise */ | |
432 | if (ospf6->rmap[type].name) | |
718e3744 | 433 | { |
508e53e2 | 434 | if (ospf6->rmap[type].map == NULL) |
03d52f8d | 435 | ospf6_asbr_routemap_update (NULL); |
508e53e2 | 436 | if (ospf6->rmap[type].map == NULL) |
718e3744 | 437 | { |
508e53e2 | 438 | zlog_warn ("route-map \"%s\" not found, suppress redistributing", |
439 | ospf6->rmap[type].name); | |
440 | return; | |
718e3744 | 441 | } |
718e3744 | 442 | } |
443 | ||
508e53e2 | 444 | /* apply route-map */ |
445 | if (ospf6->rmap[type].map) | |
446 | { | |
447 | memset (&troute, 0, sizeof (troute)); | |
448 | memset (&tinfo, 0, sizeof (tinfo)); | |
449 | troute.route_option = &tinfo; | |
42a7debf | 450 | tinfo.ifindex = ifindex; |
718e3744 | 451 | |
508e53e2 | 452 | ret = route_map_apply (ospf6->rmap[type].map, prefix, |
453 | RMAP_OSPF6, &troute); | |
47828747 | 454 | if (ret == RMAP_DENYMATCH) |
508e53e2 | 455 | { |
456 | if (IS_OSPF6_DEBUG_ASBR) | |
c6487d61 | 457 | zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name); |
508e53e2 | 458 | return; |
459 | } | |
460 | } | |
718e3744 | 461 | |
508e53e2 | 462 | match = ospf6_route_lookup (prefix, ospf6->external_table); |
463 | if (match) | |
464 | { | |
465 | info = match->route_option; | |
718e3744 | 466 | |
508e53e2 | 467 | /* copy result of route-map */ |
468 | if (ospf6->rmap[type].map) | |
469 | { | |
470 | if (troute.path.metric_type) | |
471 | match->path.metric_type = troute.path.metric_type; | |
472 | if (troute.path.cost) | |
473 | match->path.cost = troute.path.cost; | |
474 | if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding)) | |
475 | memcpy (&info->forwarding, &tinfo.forwarding, | |
476 | sizeof (struct in6_addr)); | |
477 | } | |
718e3744 | 478 | |
508e53e2 | 479 | info->type = type; |
480 | match->nexthop[0].ifindex = ifindex; | |
481 | if (nexthop_num && nexthop) | |
482 | memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr)); | |
718e3744 | 483 | |
508e53e2 | 484 | /* create/update binding in external_id_table */ |
485 | prefix_id.family = AF_INET; | |
486 | prefix_id.prefixlen = 32; | |
487 | prefix_id.u.prefix4.s_addr = htonl (info->id); | |
488 | node = route_node_get (ospf6->external_id_table, &prefix_id); | |
489 | node->info = match; | |
718e3744 | 490 | |
508e53e2 | 491 | if (IS_OSPF6_DEBUG_ASBR) |
492 | { | |
493 | inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf)); | |
c6487d61 | 494 | zlog_debug ("Advertise as AS-External Id:%s", ibuf); |
508e53e2 | 495 | } |
718e3744 | 496 | |
3b68735f | 497 | match->path.origin.id = htonl (info->id); |
6452df09 | 498 | ospf6_as_external_lsa_originate (match); |
508e53e2 | 499 | return; |
500 | } | |
718e3744 | 501 | |
508e53e2 | 502 | /* create new entry */ |
503 | route = ospf6_route_create (); | |
504 | route->type = OSPF6_DEST_TYPE_NETWORK; | |
505 | memcpy (&route->prefix, prefix, sizeof (struct prefix)); | |
718e3744 | 506 | |
508e53e2 | 507 | info = (struct ospf6_external_info *) |
393deb9b | 508 | XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info)); |
508e53e2 | 509 | route->route_option = info; |
510 | info->id = ospf6->external_id++; | |
511 | ||
512 | /* copy result of route-map */ | |
513 | if (ospf6->rmap[type].map) | |
718e3744 | 514 | { |
508e53e2 | 515 | if (troute.path.metric_type) |
516 | route->path.metric_type = troute.path.metric_type; | |
517 | if (troute.path.cost) | |
518 | route->path.cost = troute.path.cost; | |
519 | if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding)) | |
520 | memcpy (&info->forwarding, &tinfo.forwarding, | |
521 | sizeof (struct in6_addr)); | |
718e3744 | 522 | } |
523 | ||
508e53e2 | 524 | info->type = type; |
525 | route->nexthop[0].ifindex = ifindex; | |
526 | if (nexthop_num && nexthop) | |
527 | memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr)); | |
528 | ||
529 | /* create/update binding in external_id_table */ | |
530 | prefix_id.family = AF_INET; | |
531 | prefix_id.prefixlen = 32; | |
532 | prefix_id.u.prefix4.s_addr = htonl (info->id); | |
533 | node = route_node_get (ospf6->external_id_table, &prefix_id); | |
534 | node->info = route; | |
535 | ||
536 | route = ospf6_route_add (route, ospf6->external_table); | |
537 | route->route_option = info; | |
538 | ||
539 | if (IS_OSPF6_DEBUG_ASBR) | |
718e3744 | 540 | { |
508e53e2 | 541 | inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf)); |
c6487d61 | 542 | zlog_debug ("Advertise as AS-External Id:%s", ibuf); |
718e3744 | 543 | } |
544 | ||
3b68735f | 545 | route->path.origin.id = htonl (info->id); |
6452df09 | 546 | ospf6_as_external_lsa_originate (route); |
508e53e2 | 547 | |
548 | /* Router-Bit (ASBR Flag) may have to be updated */ | |
1eb8ef25 | 549 | for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa)) |
550 | OSPF6_ROUTER_LSA_SCHEDULE (oa); | |
718e3744 | 551 | } |
552 | ||
508e53e2 | 553 | void |
554 | ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix) | |
718e3744 | 555 | { |
508e53e2 | 556 | struct ospf6_route *match; |
557 | struct ospf6_external_info *info = NULL; | |
558 | struct route_node *node; | |
559 | struct ospf6_lsa *lsa; | |
560 | struct prefix prefix_id; | |
561 | char pbuf[64], ibuf[16]; | |
1eb8ef25 | 562 | struct listnode *lnode, *lnnode; |
508e53e2 | 563 | struct ospf6_area *oa; |
718e3744 | 564 | |
508e53e2 | 565 | match = ospf6_route_lookup (prefix, ospf6->external_table); |
566 | if (match == NULL) | |
718e3744 | 567 | { |
508e53e2 | 568 | if (IS_OSPF6_DEBUG_ASBR) |
718e3744 | 569 | { |
508e53e2 | 570 | prefix2str (prefix, pbuf, sizeof (pbuf)); |
c6487d61 | 571 | zlog_debug ("No such route %s to withdraw", pbuf); |
718e3744 | 572 | } |
508e53e2 | 573 | return; |
718e3744 | 574 | } |
575 | ||
508e53e2 | 576 | info = match->route_option; |
577 | assert (info); | |
718e3744 | 578 | |
508e53e2 | 579 | if (info->type != type) |
718e3744 | 580 | { |
508e53e2 | 581 | if (IS_OSPF6_DEBUG_ASBR) |
582 | { | |
583 | prefix2str (prefix, pbuf, sizeof (pbuf)); | |
c6487d61 | 584 | zlog_debug ("Original protocol mismatch: %s", pbuf); |
508e53e2 | 585 | } |
586 | return; | |
718e3744 | 587 | } |
588 | ||
508e53e2 | 589 | if (IS_OSPF6_DEBUG_ASBR) |
590 | { | |
591 | prefix2str (prefix, pbuf, sizeof (pbuf)); | |
592 | inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf)); | |
c6487d61 | 593 | zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf); |
508e53e2 | 594 | } |
718e3744 | 595 | |
508e53e2 | 596 | lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL), |
597 | htonl (info->id), ospf6->router_id, ospf6->lsdb); | |
718e3744 | 598 | if (lsa) |
6452df09 | 599 | ospf6_lsa_purge (lsa); |
508e53e2 | 600 | |
601 | /* remove binding in external_id_table */ | |
602 | prefix_id.family = AF_INET; | |
603 | prefix_id.prefixlen = 32; | |
604 | prefix_id.u.prefix4.s_addr = htonl (info->id); | |
605 | node = route_node_lookup (ospf6->external_id_table, &prefix_id); | |
606 | assert (node); | |
607 | node->info = NULL; | |
608 | route_unlock_node (node); | |
609 | ||
610 | ospf6_route_remove (match, ospf6->external_table); | |
611 | XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info); | |
612 | ||
613 | /* Router-Bit (ASBR Flag) may have to be updated */ | |
1eb8ef25 | 614 | for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa)) |
615 | OSPF6_ROUTER_LSA_SCHEDULE (oa); | |
718e3744 | 616 | } |
617 | ||
508e53e2 | 618 | DEFUN (ospf6_redistribute, |
619 | ospf6_redistribute_cmd, | |
e0ca5fde | 620 | "redistribute " QUAGGA_REDIST_STR_OSPF6D, |
508e53e2 | 621 | "Redistribute\n" |
e0ca5fde | 622 | QUAGGA_REDIST_HELP_STR_OSPF6D |
508e53e2 | 623 | ) |
718e3744 | 624 | { |
e0ca5fde DL |
625 | int type; |
626 | ||
627 | type = proto_redistnum(AFI_IP6, argv[0]); | |
628 | if (type < 0 || type == ZEBRA_ROUTE_OSPF6) | |
629 | return CMD_WARNING; | |
718e3744 | 630 | |
508e53e2 | 631 | ospf6_asbr_redistribute_unset (type); |
632 | ospf6_asbr_routemap_unset (type); | |
633 | ospf6_asbr_redistribute_set (type); | |
634 | return CMD_SUCCESS; | |
635 | } | |
718e3744 | 636 | |
508e53e2 | 637 | DEFUN (ospf6_redistribute_routemap, |
638 | ospf6_redistribute_routemap_cmd, | |
e0ca5fde | 639 | "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD", |
508e53e2 | 640 | "Redistribute\n" |
e0ca5fde | 641 | QUAGGA_REDIST_HELP_STR_OSPF6D |
508e53e2 | 642 | "Route map reference\n" |
643 | "Route map name\n" | |
644 | ) | |
645 | { | |
e0ca5fde DL |
646 | int type; |
647 | ||
648 | type = proto_redistnum(AFI_IP6, argv[0]); | |
649 | if (type < 0 || type == ZEBRA_ROUTE_OSPF6) | |
650 | return CMD_WARNING; | |
e26bbeba | 651 | |
508e53e2 | 652 | ospf6_asbr_redistribute_unset (type); |
653 | ospf6_asbr_routemap_set (type, argv[1]); | |
654 | ospf6_asbr_redistribute_set (type); | |
655 | return CMD_SUCCESS; | |
656 | } | |
657 | ||
658 | DEFUN (no_ospf6_redistribute, | |
659 | no_ospf6_redistribute_cmd, | |
e0ca5fde | 660 | "no redistribute " QUAGGA_REDIST_STR_OSPF6D, |
508e53e2 | 661 | NO_STR |
662 | "Redistribute\n" | |
e0ca5fde | 663 | QUAGGA_REDIST_HELP_STR_OSPF6D |
508e53e2 | 664 | ) |
665 | { | |
e0ca5fde DL |
666 | int type; |
667 | ||
668 | type = proto_redistnum(AFI_IP6, argv[0]); | |
669 | if (type < 0 || type == ZEBRA_ROUTE_OSPF6) | |
670 | return CMD_WARNING; | |
e26bbeba | 671 | |
508e53e2 | 672 | ospf6_asbr_redistribute_unset (type); |
673 | ospf6_asbr_routemap_unset (type); | |
e26bbeba | 674 | |
508e53e2 | 675 | return CMD_SUCCESS; |
676 | } | |
718e3744 | 677 | |
508e53e2 | 678 | int |
679 | ospf6_redistribute_config_write (struct vty *vty) | |
680 | { | |
681 | int type; | |
718e3744 | 682 | |
508e53e2 | 683 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
718e3744 | 684 | { |
508e53e2 | 685 | if (type == ZEBRA_ROUTE_OSPF6) |
686 | continue; | |
687 | if (! ospf6_zebra_is_redistribute (type)) | |
688 | continue; | |
718e3744 | 689 | |
508e53e2 | 690 | if (ospf6->rmap[type].name) |
691 | vty_out (vty, " redistribute %s route-map %s%s", | |
049207c3 | 692 | ZROUTE_NAME (type), ospf6->rmap[type].name, VNL); |
508e53e2 | 693 | else |
694 | vty_out (vty, " redistribute %s%s", | |
049207c3 | 695 | ZROUTE_NAME (type), VNL); |
508e53e2 | 696 | } |
718e3744 | 697 | |
698 | return 0; | |
699 | } | |
700 | ||
6ac29a51 | 701 | static void |
508e53e2 | 702 | ospf6_redistribute_show_config (struct vty *vty) |
718e3744 | 703 | { |
508e53e2 | 704 | int type; |
705 | int nroute[ZEBRA_ROUTE_MAX]; | |
706 | int total; | |
707 | struct ospf6_route *route; | |
708 | struct ospf6_external_info *info; | |
718e3744 | 709 | |
508e53e2 | 710 | total = 0; |
711 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
712 | nroute[type] = 0; | |
713 | for (route = ospf6_route_head (ospf6->external_table); route; | |
714 | route = ospf6_route_next (route)) | |
718e3744 | 715 | { |
508e53e2 | 716 | info = route->route_option; |
717 | nroute[info->type]++; | |
718 | total++; | |
718e3744 | 719 | } |
720 | ||
049207c3 | 721 | vty_out (vty, "Redistributing External Routes from:%s", VNL); |
508e53e2 | 722 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
718e3744 | 723 | { |
508e53e2 | 724 | if (type == ZEBRA_ROUTE_OSPF6) |
725 | continue; | |
726 | if (! ospf6_zebra_is_redistribute (type)) | |
727 | continue; | |
718e3744 | 728 | |
508e53e2 | 729 | if (ospf6->rmap[type].name) |
730 | vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type], | |
731 | ZROUTE_NAME (type), ospf6->rmap[type].name, | |
732 | (ospf6->rmap[type].map ? "" : " (not found !)"), | |
049207c3 | 733 | VNL); |
718e3744 | 734 | else |
508e53e2 | 735 | vty_out (vty, " %d: %s%s", nroute[type], |
049207c3 | 736 | ZROUTE_NAME (type), VNL); |
718e3744 | 737 | } |
049207c3 | 738 | vty_out (vty, "Total %d routes%s", total, VNL); |
508e53e2 | 739 | } |
718e3744 | 740 | |
718e3744 | 741 | |
508e53e2 | 742 | \f |
743 | /* Routemap Functions */ | |
6ac29a51 | 744 | static route_map_result_t |
508e53e2 | 745 | ospf6_routemap_rule_match_address_prefixlist (void *rule, |
746 | struct prefix *prefix, | |
747 | route_map_object_t type, | |
748 | void *object) | |
749 | { | |
750 | struct prefix_list *plist; | |
718e3744 | 751 | |
508e53e2 | 752 | if (type != RMAP_OSPF6) |
753 | return RMAP_NOMATCH; | |
718e3744 | 754 | |
508e53e2 | 755 | plist = prefix_list_lookup (AFI_IP6, (char *) rule); |
756 | if (plist == NULL) | |
757 | return RMAP_NOMATCH; | |
718e3744 | 758 | |
508e53e2 | 759 | return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? |
760 | RMAP_NOMATCH : RMAP_MATCH); | |
761 | } | |
718e3744 | 762 | |
6ac29a51 | 763 | static void * |
0c083ee9 | 764 | ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg) |
508e53e2 | 765 | { |
766 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 767 | } |
768 | ||
6ac29a51 | 769 | static void |
508e53e2 | 770 | ospf6_routemap_rule_match_address_prefixlist_free (void *rule) |
718e3744 | 771 | { |
508e53e2 | 772 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
773 | } | |
718e3744 | 774 | |
508e53e2 | 775 | struct route_map_rule_cmd |
776 | ospf6_routemap_rule_match_address_prefixlist_cmd = | |
777 | { | |
778 | "ipv6 address prefix-list", | |
779 | ospf6_routemap_rule_match_address_prefixlist, | |
780 | ospf6_routemap_rule_match_address_prefixlist_compile, | |
781 | ospf6_routemap_rule_match_address_prefixlist_free, | |
782 | }; | |
718e3744 | 783 | |
42a7debf VT |
784 | /* `match interface IFNAME' */ |
785 | /* Match function should return 1 if match is success else return | |
786 | zero. */ | |
787 | static route_map_result_t | |
788 | ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix, | |
789 | route_map_object_t type, void *object) | |
790 | { | |
791 | struct interface *ifp; | |
792 | struct ospf6_external_info *ei; | |
793 | ||
794 | if (type == RMAP_OSPF6) | |
795 | { | |
796 | ei = ((struct ospf6_route *) object)->route_option; | |
797 | ifp = if_lookup_by_name ((char *)rule); | |
798 | ||
799 | if (ifp != NULL | |
800 | && ei->ifindex == ifp->ifindex) | |
801 | return RMAP_MATCH; | |
802 | } | |
803 | ||
804 | return RMAP_NOMATCH; | |
805 | } | |
806 | ||
807 | /* Route map `interface' match statement. `arg' should be | |
808 | interface name. */ | |
809 | static void * | |
810 | ospf6_routemap_rule_match_interface_compile (const char *arg) | |
811 | { | |
812 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
813 | } | |
814 | ||
815 | /* Free route map's compiled `interface' value. */ | |
816 | static void | |
817 | ospf6_routemap_rule_match_interface_free (void *rule) | |
818 | { | |
819 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
820 | } | |
821 | ||
822 | /* Route map commands for interface matching. */ | |
823 | struct route_map_rule_cmd | |
824 | ospf6_routemap_rule_match_interface_cmd = | |
825 | { | |
826 | "interface", | |
827 | ospf6_routemap_rule_match_interface, | |
828 | ospf6_routemap_rule_match_interface_compile, | |
829 | ospf6_routemap_rule_match_interface_free | |
830 | }; | |
831 | ||
6ac29a51 | 832 | static route_map_result_t |
508e53e2 | 833 | ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix, |
834 | route_map_object_t type, void *object) | |
835 | { | |
836 | char *metric_type = rule; | |
837 | struct ospf6_route *route = object; | |
718e3744 | 838 | |
508e53e2 | 839 | if (type != RMAP_OSPF6) |
840 | return RMAP_OKAY; | |
718e3744 | 841 | |
508e53e2 | 842 | if (strcmp (metric_type, "type-2") == 0) |
843 | route->path.metric_type = 2; | |
718e3744 | 844 | else |
508e53e2 | 845 | route->path.metric_type = 1; |
718e3744 | 846 | |
508e53e2 | 847 | return RMAP_OKAY; |
848 | } | |
718e3744 | 849 | |
6ac29a51 | 850 | static void * |
0c083ee9 | 851 | ospf6_routemap_rule_set_metric_type_compile (const char *arg) |
508e53e2 | 852 | { |
853 | if (strcmp (arg, "type-2") && strcmp (arg, "type-1")) | |
854 | return NULL; | |
855 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 856 | } |
857 | ||
6ac29a51 | 858 | static void |
508e53e2 | 859 | ospf6_routemap_rule_set_metric_type_free (void *rule) |
718e3744 | 860 | { |
508e53e2 | 861 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
862 | } | |
718e3744 | 863 | |
508e53e2 | 864 | struct route_map_rule_cmd |
865 | ospf6_routemap_rule_set_metric_type_cmd = | |
866 | { | |
867 | "metric-type", | |
868 | ospf6_routemap_rule_set_metric_type, | |
869 | ospf6_routemap_rule_set_metric_type_compile, | |
870 | ospf6_routemap_rule_set_metric_type_free, | |
871 | }; | |
718e3744 | 872 | |
6ac29a51 | 873 | static route_map_result_t |
508e53e2 | 874 | ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix, |
875 | route_map_object_t type, void *object) | |
876 | { | |
877 | char *metric = rule; | |
878 | struct ospf6_route *route = object; | |
718e3744 | 879 | |
508e53e2 | 880 | if (type != RMAP_OSPF6) |
881 | return RMAP_OKAY; | |
718e3744 | 882 | |
508e53e2 | 883 | route->path.cost = atoi (metric); |
884 | return RMAP_OKAY; | |
885 | } | |
718e3744 | 886 | |
6ac29a51 | 887 | static void * |
0c083ee9 | 888 | ospf6_routemap_rule_set_metric_compile (const char *arg) |
508e53e2 | 889 | { |
890 | u_int32_t metric; | |
891 | char *endp; | |
892 | metric = strtoul (arg, &endp, 0); | |
8551e6da | 893 | if (metric > OSPF_LS_INFINITY || *endp != '\0') |
508e53e2 | 894 | return NULL; |
895 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 896 | } |
897 | ||
6ac29a51 | 898 | static void |
508e53e2 | 899 | ospf6_routemap_rule_set_metric_free (void *rule) |
718e3744 | 900 | { |
508e53e2 | 901 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
902 | } | |
718e3744 | 903 | |
508e53e2 | 904 | struct route_map_rule_cmd |
905 | ospf6_routemap_rule_set_metric_cmd = | |
906 | { | |
907 | "metric", | |
908 | ospf6_routemap_rule_set_metric, | |
909 | ospf6_routemap_rule_set_metric_compile, | |
910 | ospf6_routemap_rule_set_metric_free, | |
911 | }; | |
718e3744 | 912 | |
6ac29a51 | 913 | static route_map_result_t |
508e53e2 | 914 | ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix, |
915 | route_map_object_t type, void *object) | |
916 | { | |
917 | char *forwarding = rule; | |
918 | struct ospf6_route *route = object; | |
919 | struct ospf6_external_info *info = route->route_option; | |
718e3744 | 920 | |
508e53e2 | 921 | if (type != RMAP_OSPF6) |
922 | return RMAP_OKAY; | |
718e3744 | 923 | |
508e53e2 | 924 | if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1) |
718e3744 | 925 | { |
508e53e2 | 926 | memset (&info->forwarding, 0, sizeof (struct in6_addr)); |
927 | return RMAP_ERROR; | |
718e3744 | 928 | } |
718e3744 | 929 | |
508e53e2 | 930 | return RMAP_OKAY; |
718e3744 | 931 | } |
932 | ||
6ac29a51 | 933 | static void * |
0c083ee9 | 934 | ospf6_routemap_rule_set_forwarding_compile (const char *arg) |
718e3744 | 935 | { |
508e53e2 | 936 | struct in6_addr a; |
937 | if (inet_pton (AF_INET6, arg, &a) != 1) | |
938 | return NULL; | |
939 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 940 | } |
941 | ||
6ac29a51 | 942 | static void |
508e53e2 | 943 | ospf6_routemap_rule_set_forwarding_free (void *rule) |
718e3744 | 944 | { |
508e53e2 | 945 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
946 | } | |
718e3744 | 947 | |
508e53e2 | 948 | struct route_map_rule_cmd |
949 | ospf6_routemap_rule_set_forwarding_cmd = | |
950 | { | |
951 | "forwarding-address", | |
952 | ospf6_routemap_rule_set_forwarding, | |
953 | ospf6_routemap_rule_set_forwarding_compile, | |
954 | ospf6_routemap_rule_set_forwarding_free, | |
955 | }; | |
718e3744 | 956 | |
6ac29a51 | 957 | static int |
508e53e2 | 958 | route_map_command_status (struct vty *vty, int ret) |
959 | { | |
960 | if (! ret) | |
961 | return CMD_SUCCESS; | |
718e3744 | 962 | |
508e53e2 | 963 | switch (ret) |
718e3744 | 964 | { |
508e53e2 | 965 | case RMAP_RULE_MISSING: |
049207c3 | 966 | vty_out (vty, "Can't find rule.%s", VNL); |
508e53e2 | 967 | break; |
968 | case RMAP_COMPILE_ERROR: | |
049207c3 | 969 | vty_out (vty, "Argument is malformed.%s", VNL); |
508e53e2 | 970 | break; |
971 | default: | |
049207c3 | 972 | vty_out (vty, "route-map add set failed.%s", VNL); |
508e53e2 | 973 | break; |
718e3744 | 974 | } |
508e53e2 | 975 | return CMD_WARNING; |
976 | } | |
718e3744 | 977 | |
508e53e2 | 978 | /* add "match address" */ |
979 | DEFUN (ospf6_routemap_match_address_prefixlist, | |
980 | ospf6_routemap_match_address_prefixlist_cmd, | |
981 | "match ipv6 address prefix-list WORD", | |
982 | "Match values\n" | |
983 | IPV6_STR | |
984 | "Match address of route\n" | |
985 | "Match entries of prefix-lists\n" | |
986 | "IPv6 prefix-list name\n") | |
987 | { | |
988 | int ret = route_map_add_match ((struct route_map_index *) vty->index, | |
989 | "ipv6 address prefix-list", argv[0]); | |
990 | return route_map_command_status (vty, ret); | |
991 | } | |
992 | ||
993 | /* delete "match address" */ | |
994 | DEFUN (ospf6_routemap_no_match_address_prefixlist, | |
995 | ospf6_routemap_no_match_address_prefixlist_cmd, | |
996 | "no match ipv6 address prefix-list WORD", | |
997 | NO_STR | |
998 | "Match values\n" | |
999 | IPV6_STR | |
1000 | "Match address of route\n" | |
1001 | "Match entries of prefix-lists\n" | |
1002 | "IPv6 prefix-list name\n") | |
1003 | { | |
1004 | int ret = route_map_delete_match ((struct route_map_index *) vty->index, | |
1005 | "ipv6 address prefix-list", argv[0]); | |
1006 | return route_map_command_status (vty, ret); | |
1007 | } | |
718e3744 | 1008 | |
42a7debf VT |
1009 | /* "match interface" */ |
1010 | DEFUN (ospf6_routemap_match_interface, | |
1011 | ospf6_routemap_match_interface_cmd, | |
1012 | "match interface WORD", | |
1013 | MATCH_STR | |
1014 | "Match first hop interface of route\n" | |
1015 | "Interface name\n") | |
1016 | { | |
1017 | return route_map_add_match ((struct route_map_index *) vty->index, | |
1018 | "interface", argv[0]); | |
1019 | } | |
1020 | ||
1021 | /* "no match interface WORD" */ | |
1022 | DEFUN (ospf6_routemap_no_match_interface, | |
1023 | ospf6_routemap_no_match_interface_cmd, | |
1024 | "no match interface", | |
1025 | MATCH_STR | |
1026 | NO_STR | |
1027 | "Match first hop interface of route\n") | |
1028 | { | |
1029 | int ret = route_map_delete_match ((struct route_map_index *) vty->index, | |
1030 | "interface", (argc == 0) ? NULL : argv[0]); | |
1031 | return route_map_command_status (vty, ret); | |
1032 | } | |
1033 | ||
1034 | ALIAS (ospf6_routemap_no_match_interface, | |
1035 | ospf6_routemap_no_match_interface_val_cmd, | |
1036 | "no match interface WORD", | |
1037 | MATCH_STR | |
1038 | NO_STR | |
1039 | "Match first hop interface of route\n" | |
1040 | "Interface name\n") | |
1041 | ||
508e53e2 | 1042 | /* add "set metric-type" */ |
1043 | DEFUN (ospf6_routemap_set_metric_type, | |
1044 | ospf6_routemap_set_metric_type_cmd, | |
1045 | "set metric-type (type-1|type-2)", | |
1046 | "Set value\n" | |
1047 | "Type of metric\n" | |
1048 | "OSPF6 external type 1 metric\n" | |
1049 | "OSPF6 external type 2 metric\n") | |
1050 | { | |
1051 | int ret = route_map_add_set ((struct route_map_index *) vty->index, | |
1052 | "metric-type", argv[0]); | |
1053 | return route_map_command_status (vty, ret); | |
718e3744 | 1054 | } |
1055 | ||
508e53e2 | 1056 | /* delete "set metric-type" */ |
1057 | DEFUN (ospf6_routemap_no_set_metric_type, | |
1058 | ospf6_routemap_no_set_metric_type_cmd, | |
1059 | "no set metric-type (type-1|type-2)", | |
1060 | NO_STR | |
1061 | "Set value\n" | |
1062 | "Type of metric\n" | |
1063 | "OSPF6 external type 1 metric\n" | |
1064 | "OSPF6 external type 2 metric\n") | |
718e3744 | 1065 | { |
508e53e2 | 1066 | int ret = route_map_delete_set ((struct route_map_index *) vty->index, |
1067 | "metric-type", argv[0]); | |
1068 | return route_map_command_status (vty, ret); | |
1069 | } | |
718e3744 | 1070 | |
508e53e2 | 1071 | /* add "set metric" */ |
1072 | DEFUN (set_metric, | |
1073 | set_metric_cmd, | |
1074 | "set metric <0-4294967295>", | |
1075 | "Set value\n" | |
1076 | "Metric value\n" | |
1077 | "Metric value\n") | |
1078 | { | |
1079 | int ret = route_map_add_set ((struct route_map_index *) vty->index, | |
1080 | "metric", argv[0]); | |
1081 | return route_map_command_status (vty, ret); | |
1082 | } | |
718e3744 | 1083 | |
508e53e2 | 1084 | /* delete "set metric" */ |
1085 | DEFUN (no_set_metric, | |
1086 | no_set_metric_cmd, | |
1087 | "no set metric <0-4294967295>", | |
1088 | NO_STR | |
1089 | "Set value\n" | |
1090 | "Metric\n" | |
1091 | "METRIC value\n") | |
1092 | { | |
1093 | int ret = route_map_delete_set ((struct route_map_index *) vty->index, | |
1094 | "metric", argv[0]); | |
1095 | return route_map_command_status (vty, ret); | |
1096 | } | |
718e3744 | 1097 | |
508e53e2 | 1098 | /* add "set forwarding-address" */ |
1099 | DEFUN (ospf6_routemap_set_forwarding, | |
1100 | ospf6_routemap_set_forwarding_cmd, | |
1101 | "set forwarding-address X:X::X:X", | |
1102 | "Set value\n" | |
1103 | "Forwarding Address\n" | |
1104 | "IPv6 Address\n") | |
1105 | { | |
1106 | int ret = route_map_add_set ((struct route_map_index *) vty->index, | |
1107 | "forwarding-address", argv[0]); | |
1108 | return route_map_command_status (vty, ret); | |
1109 | } | |
718e3744 | 1110 | |
508e53e2 | 1111 | /* delete "set forwarding-address" */ |
1112 | DEFUN (ospf6_routemap_no_set_forwarding, | |
1113 | ospf6_routemap_no_set_forwarding_cmd, | |
1114 | "no set forwarding-address X:X::X:X", | |
1115 | NO_STR | |
1116 | "Set value\n" | |
1117 | "Forwarding Address\n" | |
1118 | "IPv6 Address\n") | |
1119 | { | |
1120 | int ret = route_map_delete_set ((struct route_map_index *) vty->index, | |
1121 | "forwarding-address", argv[0]); | |
1122 | return route_map_command_status (vty, ret); | |
1123 | } | |
718e3744 | 1124 | |
6ac29a51 PJ |
1125 | static void |
1126 | ospf6_routemap_init (void) | |
508e53e2 | 1127 | { |
1128 | route_map_init (); | |
1129 | route_map_init_vty (); | |
1130 | route_map_add_hook (ospf6_asbr_routemap_update); | |
1131 | route_map_delete_hook (ospf6_asbr_routemap_update); | |
1132 | ||
1133 | route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd); | |
42a7debf VT |
1134 | route_map_install_match (&ospf6_routemap_rule_match_interface_cmd); |
1135 | ||
508e53e2 | 1136 | route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd); |
1137 | route_map_install_set (&ospf6_routemap_rule_set_metric_cmd); | |
1138 | route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd); | |
1139 | ||
1140 | /* Match address prefix-list */ | |
1141 | install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd); | |
1142 | install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd); | |
1143 | ||
42a7debf VT |
1144 | /* Match interface */ |
1145 | install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd); | |
1146 | install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd); | |
1147 | install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd); | |
1148 | ||
508e53e2 | 1149 | /* ASE Metric Type (e.g. Type-1/Type-2) */ |
1150 | install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd); | |
1151 | install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd); | |
1152 | ||
1153 | /* ASE Metric */ | |
1154 | install_element (RMAP_NODE, &set_metric_cmd); | |
1155 | install_element (RMAP_NODE, &no_set_metric_cmd); | |
1156 | ||
1157 | /* ASE Metric */ | |
1158 | install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd); | |
1159 | install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd); | |
718e3744 | 1160 | } |
1161 | ||
508e53e2 | 1162 | \f |
1163 | /* Display functions */ | |
6ac29a51 | 1164 | static int |
508e53e2 | 1165 | ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
718e3744 | 1166 | { |
508e53e2 | 1167 | struct ospf6_as_external_lsa *external; |
1168 | char buf[64]; | |
1169 | struct in6_addr in6, *forwarding; | |
718e3744 | 1170 | |
1171 | assert (lsa->header); | |
508e53e2 | 1172 | external = (struct ospf6_as_external_lsa *) |
1173 | OSPF6_LSA_HEADER_END (lsa->header); | |
718e3744 | 1174 | |
1175 | /* bits */ | |
508e53e2 | 1176 | snprintf (buf, sizeof (buf), "%c%c%c", |
1177 | (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'), | |
1178 | (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'), | |
1179 | (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-')); | |
718e3744 | 1180 | |
049207c3 | 1181 | vty_out (vty, " Bits: %s%s", buf, VNL); |
508e53e2 | 1182 | vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external), |
049207c3 | 1183 | VNL); |
718e3744 | 1184 | |
508e53e2 | 1185 | ospf6_prefix_options_printbuf (external->prefix.prefix_options, |
1186 | buf, sizeof (buf)); | |
1187 | vty_out (vty, " Prefix Options: %s%s", buf, | |
049207c3 | 1188 | VNL); |
718e3744 | 1189 | |
1190 | vty_out (vty, " Referenced LSType: %d%s", | |
508e53e2 | 1191 | ntohs (external->prefix.prefix_refer_lstype), |
049207c3 | 1192 | VNL); |
718e3744 | 1193 | |
508e53e2 | 1194 | ospf6_prefix_in6_addr (&in6, &external->prefix); |
718e3744 | 1195 | inet_ntop (AF_INET6, &in6, buf, sizeof (buf)); |
508e53e2 | 1196 | vty_out (vty, " Prefix: %s/%d%s", buf, |
049207c3 | 1197 | external->prefix.prefix_length, VNL); |
718e3744 | 1198 | |
1199 | /* Forwarding-Address */ | |
1200 | if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F)) | |
1201 | { | |
508e53e2 | 1202 | forwarding = (struct in6_addr *) |
1203 | ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) + | |
1204 | OSPF6_PREFIX_SPACE (external->prefix.prefix_length)); | |
1205 | inet_ntop (AF_INET6, forwarding, buf, sizeof (buf)); | |
049207c3 | 1206 | vty_out (vty, " Forwarding-Address: %s%s", buf, VNL); |
718e3744 | 1207 | } |
1208 | ||
1209 | return 0; | |
1210 | } | |
1211 | ||
6ac29a51 | 1212 | static void |
508e53e2 | 1213 | ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route) |
718e3744 | 1214 | { |
508e53e2 | 1215 | struct ospf6_external_info *info = route->route_option; |
1216 | char prefix[64], id[16], forwarding[64]; | |
1217 | u_int32_t tmp_id; | |
718e3744 | 1218 | |
508e53e2 | 1219 | prefix2str (&route->prefix, prefix, sizeof (prefix)); |
1220 | tmp_id = ntohl (info->id); | |
1221 | inet_ntop (AF_INET, &tmp_id, id, sizeof (id)); | |
1222 | if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding)) | |
1223 | inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding)); | |
1224 | else | |
1225 | snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)", | |
1226 | route->nexthop[0].ifindex); | |
1227 | ||
f52d13cb | 1228 | vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s", |
1229 | zebra_route_char(info->type), | |
508e53e2 | 1230 | prefix, id, route->path.metric_type, |
1231 | (u_long) (route->path.metric_type == 2 ? | |
1232 | route->path.cost_e2 : route->path.cost), | |
049207c3 | 1233 | forwarding, VNL); |
718e3744 | 1234 | } |
1235 | ||
508e53e2 | 1236 | DEFUN (show_ipv6_ospf6_redistribute, |
1237 | show_ipv6_ospf6_redistribute_cmd, | |
1238 | "show ipv6 ospf6 redistribute", | |
1239 | SHOW_STR | |
1240 | IP6_STR | |
1241 | OSPF6_STR | |
1242 | "redistributing External information\n" | |
1243 | ) | |
718e3744 | 1244 | { |
508e53e2 | 1245 | struct ospf6_route *route; |
718e3744 | 1246 | |
508e53e2 | 1247 | ospf6_redistribute_show_config (vty); |
718e3744 | 1248 | |
508e53e2 | 1249 | for (route = ospf6_route_head (ospf6->external_table); route; |
1250 | route = ospf6_route_next (route)) | |
1251 | ospf6_asbr_external_route_show (vty, route); | |
1252 | ||
1253 | return CMD_SUCCESS; | |
718e3744 | 1254 | } |
1255 | ||
6452df09 | 1256 | struct ospf6_lsa_handler as_external_handler = |
718e3744 | 1257 | { |
6452df09 | 1258 | OSPF6_LSTYPE_AS_EXTERNAL, |
1259 | "AS-External", | |
1260 | ospf6_as_external_lsa_show | |
1261 | }; | |
508e53e2 | 1262 | |
718e3744 | 1263 | void |
6ac29a51 | 1264 | ospf6_asbr_init (void) |
718e3744 | 1265 | { |
508e53e2 | 1266 | ospf6_routemap_init (); |
1267 | ||
6452df09 | 1268 | ospf6_install_lsa_handler (&as_external_handler); |
718e3744 | 1269 | |
508e53e2 | 1270 | install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd); |
1271 | install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd); | |
1272 | ||
718e3744 | 1273 | install_element (OSPF6_NODE, &ospf6_redistribute_cmd); |
1274 | install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd); | |
1275 | install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd); | |
1276 | } | |
1277 | ||
ae2254aa TG |
1278 | void |
1279 | ospf6_asbr_terminate (void) | |
1280 | { | |
1281 | route_map_finish (); | |
1282 | } | |
718e3744 | 1283 | |
508e53e2 | 1284 | DEFUN (debug_ospf6_asbr, |
1285 | debug_ospf6_asbr_cmd, | |
1286 | "debug ospf6 asbr", | |
1287 | DEBUG_STR | |
1288 | OSPF6_STR | |
1289 | "Debug OSPFv3 ASBR function\n" | |
1290 | ) | |
1291 | { | |
1292 | OSPF6_DEBUG_ASBR_ON (); | |
1293 | return CMD_SUCCESS; | |
1294 | } | |
1295 | ||
1296 | DEFUN (no_debug_ospf6_asbr, | |
1297 | no_debug_ospf6_asbr_cmd, | |
1298 | "no debug ospf6 asbr", | |
1299 | NO_STR | |
1300 | DEBUG_STR | |
1301 | OSPF6_STR | |
1302 | "Debug OSPFv3 ASBR function\n" | |
1303 | ) | |
1304 | { | |
1305 | OSPF6_DEBUG_ASBR_OFF (); | |
1306 | return CMD_SUCCESS; | |
1307 | } | |
1308 | ||
1309 | int | |
1310 | config_write_ospf6_debug_asbr (struct vty *vty) | |
1311 | { | |
1312 | if (IS_OSPF6_DEBUG_ASBR) | |
049207c3 | 1313 | vty_out (vty, "debug ospf6 asbr%s", VNL); |
508e53e2 | 1314 | return 0; |
1315 | } | |
1316 | ||
1317 | void | |
1318 | install_element_ospf6_debug_asbr () | |
1319 | { | |
1320 | install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd); | |
1321 | install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd); | |
1322 | install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd); | |
1323 | install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd); | |
1324 | } | |
1325 | ||
1326 |