]>
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 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "log.h" | |
24 | #include "memory.h" | |
25 | #include "prefix.h" | |
26 | #include "command.h" | |
27 | #include "vty.h" | |
28 | #include "routemap.h" | |
29 | #include "table.h" | |
30 | #include "plist.h" | |
31 | #include "thread.h" | |
508e53e2 | 32 | #include "linklist.h" |
718e3744 | 33 | |
508e53e2 | 34 | #include "ospf6_proto.h" |
35 | #include "ospf6_lsa.h" | |
36 | #include "ospf6_lsdb.h" | |
37 | #include "ospf6_route.h" | |
718e3744 | 38 | #include "ospf6_zebra.h" |
6452df09 | 39 | #include "ospf6_message.h" |
40 | ||
718e3744 | 41 | #include "ospf6_top.h" |
508e53e2 | 42 | #include "ospf6_area.h" |
6452df09 | 43 | #include "ospf6_interface.h" |
44 | #include "ospf6_neighbor.h" | |
508e53e2 | 45 | #include "ospf6_asbr.h" |
beadc736 | 46 | #include "ospf6_abr.h" |
508e53e2 | 47 | #include "ospf6_intra.h" |
6452df09 | 48 | #include "ospf6_flood.h" |
049207c3 | 49 | #include "ospf6d.h" |
dd726234 | 50 | #include "lib/json.h" |
718e3744 | 51 | |
c5d28568 | 52 | static void ospf6_asbr_redistribute_set(int type, vrf_id_t vrf_id); |
a069482f K |
53 | static void ospf6_asbr_redistribute_unset(struct ospf6 *ospf6, |
54 | struct ospf6_redist *red, int type); | |
780d4bdd | 55 | |
508e53e2 | 56 | unsigned char conf_debug_ospf6_asbr = 0; |
718e3744 | 57 | |
f52d13cb | 58 | #define ZROUTE_NAME(x) zebra_route_string(x) |
508e53e2 | 59 | |
60 | /* AS External LSA origination */ | |
beadc736 | 61 | static void ospf6_as_external_lsa_originate(struct ospf6_route *route, |
62 | struct ospf6 *ospf6) | |
718e3744 | 63 | { |
d62a17ae | 64 | char buffer[OSPF6_MAX_LSASIZE]; |
65 | struct ospf6_lsa_header *lsa_header; | |
66 | struct ospf6_lsa *lsa; | |
67 | struct ospf6_external_info *info = route->route_option; | |
68 | ||
69 | struct ospf6_as_external_lsa *as_external_lsa; | |
d62a17ae | 70 | caddr_t p; |
71 | ||
2dbe669b DA |
72 | if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE(AS_EXTERNAL)) |
73 | zlog_debug("Originate AS-External-LSA for %pFX", | |
74 | &route->prefix); | |
d62a17ae | 75 | |
76 | /* prepare buffer */ | |
77 | memset(buffer, 0, sizeof(buffer)); | |
78 | lsa_header = (struct ospf6_lsa_header *)buffer; | |
79 | as_external_lsa = (struct ospf6_as_external_lsa | |
80 | *)((caddr_t)lsa_header | |
81 | + sizeof(struct ospf6_lsa_header)); | |
82 | p = (caddr_t)((caddr_t)as_external_lsa | |
83 | + sizeof(struct ospf6_as_external_lsa)); | |
84 | ||
85 | /* Fill AS-External-LSA */ | |
86 | /* Metric type */ | |
87 | if (route->path.metric_type == 2) | |
88 | SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E); | |
89 | else | |
90 | UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E); | |
91 | ||
92 | /* forwarding address */ | |
93 | if (!IN6_IS_ADDR_UNSPECIFIED(&info->forwarding)) | |
94 | SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F); | |
95 | else | |
96 | UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F); | |
97 | ||
98 | /* external route tag */ | |
99 | if (info->tag) | |
100 | SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T); | |
101 | else | |
102 | UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T); | |
103 | ||
104 | /* Set metric */ | |
105 | OSPF6_ASBR_METRIC_SET(as_external_lsa, route->path.cost); | |
106 | ||
107 | /* prefixlen */ | |
108 | as_external_lsa->prefix.prefix_length = route->prefix.prefixlen; | |
109 | ||
110 | /* PrefixOptions */ | |
111 | as_external_lsa->prefix.prefix_options = route->path.prefix_options; | |
112 | ||
113 | /* don't use refer LS-type */ | |
114 | as_external_lsa->prefix.prefix_refer_lstype = htons(0); | |
115 | ||
116 | /* set Prefix */ | |
117 | memcpy(p, &route->prefix.u.prefix6, | |
118 | OSPF6_PREFIX_SPACE(route->prefix.prefixlen)); | |
119 | ospf6_prefix_apply_mask(&as_external_lsa->prefix); | |
120 | p += OSPF6_PREFIX_SPACE(route->prefix.prefixlen); | |
121 | ||
122 | /* Forwarding address */ | |
123 | if (CHECK_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F)) { | |
124 | memcpy(p, &info->forwarding, sizeof(struct in6_addr)); | |
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 | route_tag_t network_order = htonl(info->tag); | |
131 | ||
132 | memcpy(p, &network_order, sizeof(network_order)); | |
133 | p += sizeof(network_order); | |
134 | } | |
135 | ||
136 | /* Fill LSA Header */ | |
137 | lsa_header->age = 0; | |
138 | lsa_header->type = htons(OSPF6_LSTYPE_AS_EXTERNAL); | |
139 | lsa_header->id = route->path.origin.id; | |
140 | lsa_header->adv_router = ospf6->router_id; | |
141 | lsa_header->seqnum = | |
142 | ospf6_new_ls_seqnum(lsa_header->type, lsa_header->id, | |
143 | lsa_header->adv_router, ospf6->lsdb); | |
144 | lsa_header->length = htons((caddr_t)p - (caddr_t)lsa_header); | |
145 | ||
146 | /* LSA checksum */ | |
147 | ospf6_lsa_checksum(lsa_header); | |
148 | ||
149 | /* create LSA */ | |
150 | lsa = ospf6_lsa_create(lsa_header); | |
151 | ||
152 | /* Originate */ | |
153 | ospf6_lsa_originate_process(lsa, ospf6); | |
718e3744 | 154 | } |
155 | ||
76249532 CS |
156 | int ospf6_orig_as_external_lsa(struct thread *thread) |
157 | { | |
158 | struct ospf6_interface *oi; | |
159 | struct ospf6_lsa *lsa; | |
160 | uint32_t type, adv_router; | |
161 | ||
162 | oi = (struct ospf6_interface *)THREAD_ARG(thread); | |
163 | oi->thread_as_extern_lsa = NULL; | |
164 | ||
165 | if (oi->state == OSPF6_INTERFACE_DOWN) | |
166 | return 0; | |
167 | ||
168 | type = htons(OSPF6_LSTYPE_AS_EXTERNAL); | |
169 | adv_router = oi->area->ospf6->router_id; | |
beadc736 | 170 | for (ALL_LSDB_TYPED_ADVRTR(oi->area->ospf6->lsdb, type, adv_router, |
171 | lsa)) { | |
76249532 | 172 | if (IS_OSPF6_DEBUG_ASBR) |
996c9314 LB |
173 | zlog_debug( |
174 | "%s: Send update of AS-External LSA %s seq 0x%x", | |
5e81f5dd | 175 | __func__, lsa->name, |
996c9314 | 176 | ntohl(lsa->header->seqnum)); |
76249532 CS |
177 | |
178 | ospf6_flood_interface(NULL, lsa, oi); | |
179 | } | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
d62a17ae | 184 | static route_tag_t ospf6_as_external_lsa_get_tag(struct ospf6_lsa *lsa) |
464015fa | 185 | { |
d62a17ae | 186 | struct ospf6_as_external_lsa *external; |
187 | ptrdiff_t tag_offset; | |
188 | route_tag_t network_order; | |
464015fa | 189 | |
d62a17ae | 190 | if (!lsa) |
191 | return 0; | |
464015fa | 192 | |
d62a17ae | 193 | external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( |
194 | lsa->header); | |
464015fa | 195 | |
d62a17ae | 196 | if (!CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) |
197 | return 0; | |
464015fa | 198 | |
d62a17ae | 199 | tag_offset = sizeof(*external) |
200 | + OSPF6_PREFIX_SPACE(external->prefix.prefix_length); | |
201 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) | |
202 | tag_offset += sizeof(struct in6_addr); | |
464015fa | 203 | |
d62a17ae | 204 | memcpy(&network_order, (caddr_t)external + tag_offset, |
205 | sizeof(network_order)); | |
206 | return ntohl(network_order); | |
464015fa | 207 | } |
6b0655a2 | 208 | |
064d4355 | 209 | void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, |
beadc736 | 210 | struct ospf6_route *route, |
211 | struct ospf6 *ospf6) | |
064d4355 | 212 | { |
aaef26ce | 213 | struct ospf6_route *old_route, *next_route; |
064d4355 | 214 | struct ospf6_path *ecmp_path, *o_path = NULL; |
07b37f93 | 215 | struct listnode *anode, *anext; |
064d4355 CS |
216 | struct listnode *nnode, *rnode, *rnext; |
217 | struct ospf6_nexthop *nh, *rnh; | |
064d4355 CS |
218 | bool route_found = false; |
219 | ||
07b37f93 CS |
220 | /* check for old entry match with new route origin, |
221 | * delete old entry. | |
222 | */ | |
aaef26ce | 223 | for (old_route = old; old_route; old_route = next_route) { |
07b37f93 CS |
224 | bool route_updated = false; |
225 | ||
aaef26ce DS |
226 | next_route = old_route->next; |
227 | ||
996c9314 LB |
228 | if (!ospf6_route_is_same(old_route, route) |
229 | || (old_route->path.type != route->path.type)) | |
07b37f93 CS |
230 | continue; |
231 | ||
232 | /* Current and New route has same origin, | |
233 | * delete old entry. | |
234 | */ | |
235 | for (ALL_LIST_ELEMENTS(old_route->paths, anode, anext, | |
996c9314 | 236 | o_path)) { |
07b37f93 CS |
237 | /* Check old route path and route has same |
238 | * origin. | |
239 | */ | |
996c9314 LB |
240 | if (o_path->area_id != route->path.area_id |
241 | || (memcmp(&(o_path)->origin, &(route)->path.origin, | |
242 | sizeof(struct ospf6_ls_origin)) | |
243 | != 0)) | |
07b37f93 CS |
244 | continue; |
245 | ||
246 | /* Cost is not same then delete current path */ | |
996c9314 LB |
247 | if ((o_path->cost == route->path.cost) |
248 | && (o_path->u.cost_e2 == route->path.u.cost_e2)) | |
07b37f93 | 249 | continue; |
064d4355 CS |
250 | |
251 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
996c9314 | 252 | zlog_debug( |
dc138868 DL |
253 | "%s: route %pFX cost old %u new %u is not same, replace route", |
254 | __func__, &old_route->prefix, o_path->cost, | |
996c9314 | 255 | route->path.cost); |
07b37f93 CS |
256 | } |
257 | ||
258 | /* Remove selected current rout path's nh from | |
259 | * effective nh list. | |
260 | */ | |
261 | for (ALL_LIST_ELEMENTS_RO(o_path->nh_list, nnode, nh)) { | |
262 | for (ALL_LIST_ELEMENTS(old_route->nh_list, | |
996c9314 | 263 | rnode, rnext, rnh)) { |
07b37f93 CS |
264 | if (!ospf6_nexthop_is_same(rnh, nh)) |
265 | continue; | |
266 | listnode_delete(old_route->nh_list, | |
996c9314 | 267 | rnh); |
07b37f93 | 268 | ospf6_nexthop_delete(rnh); |
07b37f93 CS |
269 | } |
270 | } | |
271 | ||
272 | listnode_delete(old_route->paths, o_path); | |
273 | ospf6_path_free(o_path); | |
804a3294 | 274 | route_updated = true; |
07b37f93 CS |
275 | |
276 | /* Current route's path (adv_router info) is similar | |
277 | * to route being added. | |
278 | * Replace current route's path with paths list head. | |
279 | * Update FIB with effective NHs. | |
280 | */ | |
281 | if (listcount(old_route->paths)) { | |
804a3294 CS |
282 | for (ALL_LIST_ELEMENTS(old_route->paths, |
283 | anode, anext, o_path)) { | |
284 | ospf6_merge_nexthops( | |
285 | old_route->nh_list, | |
286 | o_path->nh_list); | |
287 | } | |
288 | /* Update RIB/FIB with effective | |
289 | * nh_list | |
290 | */ | |
291 | if (ospf6->route_table->hook_add) | |
beadc736 | 292 | (*ospf6->route_table->hook_add)( |
e285b70d | 293 | old_route); |
804a3294 | 294 | |
996c9314 LB |
295 | if (old_route->path.origin.id |
296 | == route->path.origin.id | |
297 | && old_route->path.origin.adv_router | |
298 | == route->path.origin | |
299 | .adv_router) { | |
07b37f93 CS |
300 | struct ospf6_path *h_path; |
301 | ||
302 | h_path = (struct ospf6_path *) | |
996c9314 LB |
303 | listgetdata(listhead( |
304 | old_route->paths)); | |
07b37f93 CS |
305 | old_route->path.origin.type = |
306 | h_path->origin.type; | |
307 | old_route->path.origin.id = | |
308 | h_path->origin.id; | |
309 | old_route->path.origin.adv_router = | |
310 | h_path->origin.adv_router; | |
311 | } | |
07b37f93 CS |
312 | } else { |
313 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
996c9314 | 314 | zlog_debug( |
dc138868 DL |
315 | "%s: route %pFX old cost %u new cost %u, delete old entry.", |
316 | __func__, &old_route->prefix, | |
996c9314 LB |
317 | old_route->path.cost, |
318 | route->path.cost); | |
07b37f93 | 319 | } |
aaef26ce DS |
320 | if (old == old_route) |
321 | old = next_route; | |
07b37f93 | 322 | ospf6_route_remove(old_route, |
e285b70d | 323 | ospf6->route_table); |
07b37f93 CS |
324 | } |
325 | } | |
326 | if (route_updated) | |
327 | break; | |
328 | } | |
329 | ||
330 | /* Add new route */ | |
331 | for (old_route = old; old_route; old_route = old_route->next) { | |
332 | ||
333 | /* Current and New Route prefix or route type | |
334 | * is not same skip this current node. | |
335 | */ | |
996c9314 LB |
336 | if (!ospf6_route_is_same(old_route, route) |
337 | || (old_route->path.type != route->path.type)) | |
07b37f93 CS |
338 | continue; |
339 | ||
340 | /* Old Route and New Route have Equal Cost, Merge NHs */ | |
996c9314 LB |
341 | if ((old_route->path.cost == route->path.cost) |
342 | && (old_route->path.u.cost_e2 == route->path.u.cost_e2)) { | |
07b37f93 CS |
343 | |
344 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
996c9314 | 345 | zlog_debug( |
dc138868 DL |
346 | "%s: old route %pFX path cost %u e2 %u", |
347 | __func__, &old_route->prefix, | |
348 | old_route->path.cost, | |
996c9314 | 349 | old_route->path.u.cost_e2); |
064d4355 CS |
350 | } |
351 | route_found = true; | |
352 | /* check if this path exists already in | |
353 | * route->paths list, if so, replace nh_list | |
354 | * from asbr_entry. | |
355 | */ | |
356 | for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode, | |
357 | o_path)) { | |
996c9314 LB |
358 | if (o_path->area_id == route->path.area_id |
359 | && (memcmp(&(o_path)->origin, | |
360 | &(route)->path.origin, | |
361 | sizeof(struct ospf6_ls_origin)) | |
362 | == 0)) | |
064d4355 CS |
363 | break; |
364 | } | |
365 | /* If path is not found in old_route paths's list, | |
366 | * add a new path to route paths list and merge | |
367 | * nexthops in route->path->nh_list. | |
368 | * Otherwise replace existing path's nh_list. | |
369 | */ | |
370 | if (o_path == NULL) { | |
371 | ecmp_path = ospf6_path_dup(&route->path); | |
372 | ||
373 | /* Add a nh_list to new ecmp path */ | |
374 | ospf6_copy_nexthops(ecmp_path->nh_list, | |
375 | route->nh_list); | |
064d4355 CS |
376 | |
377 | /* Add the new path to route's path list */ | |
378 | listnode_add_sort(old_route->paths, ecmp_path); | |
379 | ||
380 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
996c9314 | 381 | zlog_debug( |
2dbe669b DA |
382 | "%s: route %pFX another path added with nh %u, effective paths %u nh %u", |
383 | __func__, &route->prefix, | |
064d4355 | 384 | listcount(ecmp_path->nh_list), |
5e81f5dd DS |
385 | old_route->paths ? listcount( |
386 | old_route->paths) | |
387 | : 0, | |
07b37f93 | 388 | listcount(old_route->nh_list)); |
064d4355 CS |
389 | } |
390 | } else { | |
064d4355 CS |
391 | list_delete_all_node(o_path->nh_list); |
392 | ospf6_copy_nexthops(o_path->nh_list, | |
996c9314 | 393 | route->nh_list); |
804a3294 | 394 | } |
064d4355 | 395 | |
804a3294 CS |
396 | /* Reset nexthop lists, rebuild from brouter table |
397 | * for each adv. router. | |
398 | */ | |
399 | list_delete_all_node(old_route->nh_list); | |
064d4355 | 400 | |
804a3294 CS |
401 | for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode, |
402 | o_path)) { | |
403 | struct ospf6_route *asbr_entry; | |
404 | ||
405 | asbr_entry = ospf6_route_lookup( | |
406 | &o_path->ls_prefix, | |
407 | ospf6->brouter_table); | |
408 | if (asbr_entry == NULL) { | |
2dbe669b | 409 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) |
5e81f5dd | 410 | zlog_debug( |
2dbe669b DA |
411 | "%s: ls_prfix %pFX asbr_entry not found.", |
412 | __func__, | |
413 | &old_route->prefix); | |
804a3294 | 414 | continue; |
064d4355 | 415 | } |
804a3294 CS |
416 | ospf6_route_merge_nexthops(old_route, |
417 | asbr_entry); | |
418 | } | |
064d4355 | 419 | |
2dbe669b | 420 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) |
5e81f5dd | 421 | zlog_debug( |
2dbe669b DA |
422 | "%s: route %pFX with effective paths %u nh %u", |
423 | __func__, &route->prefix, | |
5e81f5dd DS |
424 | old_route->paths |
425 | ? listcount(old_route->paths) | |
426 | : 0, | |
427 | old_route->nh_list | |
428 | ? listcount(old_route->nh_list) | |
429 | : 0); | |
804a3294 CS |
430 | |
431 | /* Update RIB/FIB */ | |
432 | if (ospf6->route_table->hook_add) | |
e285b70d | 433 | (*ospf6->route_table->hook_add)(old_route); |
804a3294 | 434 | |
064d4355 CS |
435 | /* Delete the new route its info added to existing |
436 | * route. | |
437 | */ | |
438 | ospf6_route_delete(route); | |
07b37f93 | 439 | |
064d4355 CS |
440 | break; |
441 | } | |
442 | } | |
443 | ||
444 | if (!route_found) { | |
445 | /* Add new route to existing node in ospf6 route table. */ | |
e285b70d | 446 | ospf6_route_add(route, ospf6->route_table); |
064d4355 CS |
447 | } |
448 | } | |
449 | ||
f5f26b8f | 450 | void ospf6_asbr_lsa_add(struct ospf6_lsa *lsa) |
718e3744 | 451 | { |
d62a17ae | 452 | struct ospf6_as_external_lsa *external; |
453 | struct prefix asbr_id; | |
064d4355 CS |
454 | struct ospf6_route *asbr_entry, *route, *old; |
455 | struct ospf6_path *path; | |
f5f26b8f | 456 | struct ospf6 *ospf6; |
d62a17ae | 457 | |
458 | external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( | |
459 | lsa->header); | |
460 | ||
461 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) | |
462 | zlog_debug("Calculate AS-External route for %s", lsa->name); | |
463 | ||
f5f26b8f IR |
464 | ospf6 = ospf6_get_by_lsdb(lsa); |
465 | ||
d62a17ae | 466 | if (lsa->header->adv_router == ospf6->router_id) { |
467 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) | |
468 | zlog_debug("Ignore self-originated AS-External-LSA"); | |
469 | return; | |
470 | } | |
471 | ||
472 | if (OSPF6_ASBR_METRIC(external) == OSPF_LS_INFINITY) { | |
473 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) | |
474 | zlog_debug("Ignore LSA with LSInfinity Metric"); | |
475 | return; | |
476 | } | |
477 | ||
478 | if (CHECK_FLAG(external->prefix.prefix_options, | |
479 | OSPF6_PREFIX_OPTION_NU)) { | |
480 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) | |
481 | zlog_debug("Ignore LSA with NU bit set Metric"); | |
482 | return; | |
483 | } | |
484 | ||
485 | ospf6_linkstate_prefix(lsa->header->adv_router, htonl(0), &asbr_id); | |
486 | asbr_entry = ospf6_route_lookup(&asbr_id, ospf6->brouter_table); | |
487 | if (asbr_entry == NULL | |
488 | || !CHECK_FLAG(asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E)) { | |
2dbe669b DA |
489 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) |
490 | zlog_debug("ASBR entry not found: %pFX", &asbr_id); | |
d62a17ae | 491 | return; |
492 | } | |
493 | ||
494 | route = ospf6_route_create(); | |
495 | route->type = OSPF6_DEST_TYPE_NETWORK; | |
496 | route->prefix.family = AF_INET6; | |
497 | route->prefix.prefixlen = external->prefix.prefix_length; | |
b8ce0c36 | 498 | ospf6_prefix_in6_addr(&route->prefix.u.prefix6, external, |
499 | &external->prefix); | |
d62a17ae | 500 | |
501 | route->path.area_id = asbr_entry->path.area_id; | |
502 | route->path.origin.type = lsa->header->type; | |
503 | route->path.origin.id = lsa->header->id; | |
504 | route->path.origin.adv_router = lsa->header->adv_router; | |
d62a17ae | 505 | route->path.prefix_options = external->prefix.prefix_options; |
804a3294 CS |
506 | memcpy(&route->path.ls_prefix, &asbr_id, sizeof(struct prefix)); |
507 | ||
d62a17ae | 508 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E)) { |
509 | route->path.type = OSPF6_PATH_TYPE_EXTERNAL2; | |
510 | route->path.metric_type = 2; | |
511 | route->path.cost = asbr_entry->path.cost; | |
512 | route->path.u.cost_e2 = OSPF6_ASBR_METRIC(external); | |
513 | } else { | |
514 | route->path.type = OSPF6_PATH_TYPE_EXTERNAL1; | |
515 | route->path.metric_type = 1; | |
516 | route->path.cost = | |
517 | asbr_entry->path.cost + OSPF6_ASBR_METRIC(external); | |
518 | route->path.u.cost_e2 = 0; | |
519 | } | |
520 | ||
521 | route->path.tag = ospf6_as_external_lsa_get_tag(lsa); | |
522 | ||
523 | ospf6_route_copy_nexthops(route, asbr_entry); | |
524 | ||
064d4355 CS |
525 | path = ospf6_path_dup(&route->path); |
526 | ospf6_copy_nexthops(path->nh_list, asbr_entry->nh_list); | |
527 | listnode_add_sort(route->paths, path); | |
528 | ||
529 | ||
2dbe669b DA |
530 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) |
531 | zlog_debug( | |
532 | "%s: AS-External %u route add %pFX cost %u(%u) nh %u", | |
533 | __func__, | |
534 | (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1) ? 1 : 2, | |
535 | &route->prefix, route->path.cost, route->path.u.cost_e2, | |
536 | listcount(route->nh_list)); | |
064d4355 CS |
537 | |
538 | old = ospf6_route_lookup(&route->prefix, ospf6->route_table); | |
539 | if (!old) { | |
540 | /* Add the new route to ospf6 instance route table. */ | |
e285b70d | 541 | ospf6_route_add(route, ospf6->route_table); |
064d4355 CS |
542 | } else { |
543 | /* RFC 2328 16.4 (6) | |
544 | * ECMP: Keep new equal preference path in current | |
545 | * route's path list, update zebra with new effective | |
546 | * list along with addition of ECMP path. | |
547 | */ | |
beadc736 | 548 | ospf6_asbr_update_route_ecmp_path(old, route, ospf6); |
d62a17ae | 549 | } |
718e3744 | 550 | } |
551 | ||
07b37f93 CS |
552 | void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, |
553 | struct ospf6_route *asbr_entry) | |
718e3744 | 554 | { |
d62a17ae | 555 | struct ospf6_as_external_lsa *external; |
556 | struct prefix prefix; | |
07b37f93 | 557 | struct ospf6_route *route, *nroute, *route_to_del; |
beadc736 | 558 | struct ospf6_area *oa = NULL; |
559 | struct ospf6 *ospf6; | |
d62a17ae | 560 | |
561 | external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( | |
562 | lsa->header); | |
563 | ||
564 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) | |
565 | zlog_debug("Withdraw AS-External route for %s", lsa->name); | |
566 | ||
beadc736 | 567 | ospf6 = ospf6_get_by_lsdb(lsa); |
568 | if (ospf6_is_router_abr(ospf6)) | |
569 | oa = ospf6->backbone; | |
570 | else | |
571 | oa = listgetdata(listhead(ospf6->area_list)); | |
572 | ||
573 | if (oa == NULL) | |
574 | return; | |
575 | ||
576 | if (lsa->header->adv_router == oa->ospf6->router_id) { | |
d62a17ae | 577 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) |
578 | zlog_debug("Ignore self-originated AS-External-LSA"); | |
579 | return; | |
580 | } | |
581 | ||
07b37f93 CS |
582 | route_to_del = ospf6_route_create(); |
583 | route_to_del->type = OSPF6_DEST_TYPE_NETWORK; | |
584 | route_to_del->prefix.family = AF_INET6; | |
585 | route_to_del->prefix.prefixlen = external->prefix.prefix_length; | |
b8ce0c36 | 586 | ospf6_prefix_in6_addr(&route_to_del->prefix.u.prefix6, external, |
07b37f93 CS |
587 | &external->prefix); |
588 | ||
589 | route_to_del->path.origin.type = lsa->header->type; | |
590 | route_to_del->path.origin.id = lsa->header->id; | |
591 | route_to_del->path.origin.adv_router = lsa->header->adv_router; | |
592 | ||
593 | if (asbr_entry) { | |
594 | route_to_del->path.area_id = asbr_entry->path.area_id; | |
595 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E)) { | |
596 | route_to_del->path.type = OSPF6_PATH_TYPE_EXTERNAL2; | |
597 | route_to_del->path.metric_type = 2; | |
598 | route_to_del->path.cost = asbr_entry->path.cost; | |
599 | route_to_del->path.u.cost_e2 = | |
600 | OSPF6_ASBR_METRIC(external); | |
601 | } else { | |
602 | route_to_del->path.type = OSPF6_PATH_TYPE_EXTERNAL1; | |
603 | route_to_del->path.metric_type = 1; | |
996c9314 LB |
604 | route_to_del->path.cost = asbr_entry->path.cost |
605 | + OSPF6_ASBR_METRIC(external); | |
07b37f93 CS |
606 | route_to_del->path.u.cost_e2 = 0; |
607 | } | |
608 | } | |
609 | ||
d62a17ae | 610 | memset(&prefix, 0, sizeof(struct prefix)); |
611 | prefix.family = AF_INET6; | |
612 | prefix.prefixlen = external->prefix.prefix_length; | |
b8ce0c36 | 613 | ospf6_prefix_in6_addr(&prefix.u.prefix6, external, &external->prefix); |
d62a17ae | 614 | |
beadc736 | 615 | route = ospf6_route_lookup(&prefix, oa->ospf6->route_table); |
d62a17ae | 616 | if (route == NULL) { |
617 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
dc138868 | 618 | zlog_debug("AS-External route %pFX not found", &prefix); |
d62a17ae | 619 | } |
267bf505 DS |
620 | |
621 | ospf6_route_delete(route_to_del); | |
d62a17ae | 622 | return; |
623 | } | |
624 | ||
07b37f93 | 625 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { |
996c9314 | 626 | zlog_debug( |
dc138868 DL |
627 | "%s: Current route %pFX cost %u e2 %u, route to del cost %u e2 %u", |
628 | __func__, &prefix, route->path.cost, route->path.u.cost_e2, | |
5e81f5dd | 629 | route_to_del->path.cost, route_to_del->path.u.cost_e2); |
07b37f93 CS |
630 | } |
631 | ||
996c9314 LB |
632 | for (ospf6_route_lock(route); |
633 | route && ospf6_route_is_prefix(&prefix, route); route = nroute) { | |
d62a17ae | 634 | nroute = ospf6_route_next(route); |
07b37f93 | 635 | |
d62a17ae | 636 | if (route->type != OSPF6_DEST_TYPE_NETWORK) |
637 | continue; | |
064d4355 | 638 | |
07b37f93 CS |
639 | /* Route has multiple ECMP paths, remove matching |
640 | * path. Update current route's effective nh list | |
641 | * after removal of one of the path. | |
064d4355 CS |
642 | */ |
643 | if (listcount(route->paths) > 1) { | |
644 | struct listnode *anode, *anext; | |
645 | struct listnode *nnode, *rnode, *rnext; | |
646 | struct ospf6_nexthop *nh, *rnh; | |
647 | struct ospf6_path *o_path; | |
648 | bool nh_updated = false; | |
649 | ||
650 | /* Iterate all paths of route to find maching with LSA | |
651 | * remove from route path list. If route->path is same, | |
652 | * replace from paths list. | |
653 | */ | |
654 | for (ALL_LIST_ELEMENTS(route->paths, anode, anext, | |
996c9314 | 655 | o_path)) { |
07b37f93 | 656 | if ((o_path->origin.type != lsa->header->type) |
996c9314 LB |
657 | || (o_path->origin.adv_router |
658 | != lsa->header->adv_router) | |
659 | || (o_path->origin.id != lsa->header->id)) | |
064d4355 | 660 | continue; |
07b37f93 CS |
661 | |
662 | /* Compare LSA cost with current | |
663 | * route info. | |
664 | */ | |
996c9314 LB |
665 | if (!asbr_entry |
666 | && (o_path->cost != route_to_del->path.cost | |
667 | || o_path->u.cost_e2 | |
668 | != route_to_del->path.u | |
669 | .cost_e2)) { | |
07b37f93 | 670 | if (IS_OSPF6_DEBUG_EXAMIN( |
996c9314 | 671 | AS_EXTERNAL)) { |
07b37f93 | 672 | zlog_debug( |
dc138868 DL |
673 | "%s: route %pFX to delete is not same, cost %u del cost %u. skip", |
674 | __func__, &prefix, | |
5e81f5dd | 675 | route->path.cost, |
996c9314 LB |
676 | route_to_del->path |
677 | .cost); | |
07b37f93 | 678 | } |
064d4355 | 679 | continue; |
07b37f93 | 680 | } |
064d4355 | 681 | |
996c9314 | 682 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { |
064d4355 | 683 | zlog_debug( |
dc138868 DL |
684 | "%s: route %pFX path found with cost %u nh %u to remove.", |
685 | __func__, &prefix, route->path.cost, | |
064d4355 CS |
686 | listcount(o_path->nh_list)); |
687 | } | |
688 | ||
689 | /* Remove found path's nh_list from | |
690 | * the route's nh_list. | |
691 | */ | |
692 | for (ALL_LIST_ELEMENTS_RO(o_path->nh_list, | |
693 | nnode, nh)) { | |
694 | for (ALL_LIST_ELEMENTS(route->nh_list, | |
996c9314 LB |
695 | rnode, rnext, |
696 | rnh)) { | |
064d4355 | 697 | if (!ospf6_nexthop_is_same(rnh, |
996c9314 | 698 | nh)) |
064d4355 CS |
699 | continue; |
700 | listnode_delete(route->nh_list, | |
701 | rnh); | |
702 | ospf6_nexthop_delete(rnh); | |
703 | } | |
704 | } | |
705 | /* Delete the path from route's path list */ | |
706 | listnode_delete(route->paths, o_path); | |
707 | ospf6_path_free(o_path); | |
708 | nh_updated = true; | |
709 | } | |
710 | ||
711 | if (nh_updated) { | |
712 | /* Iterate all paths and merge nexthop, | |
713 | * unlesss any of the nexthop similar to | |
714 | * ones deleted as part of path deletion. | |
715 | */ | |
716 | ||
717 | for (ALL_LIST_ELEMENTS(route->paths, anode, | |
718 | anext, o_path)) { | |
719 | ospf6_merge_nexthops(route->nh_list, | |
720 | o_path->nh_list); | |
721 | } | |
722 | ||
723 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { | |
996c9314 | 724 | zlog_debug( |
dc138868 | 725 | "%s: AS-External %u route %pFX update paths %u nh %u", |
5e81f5dd | 726 | __func__, |
996c9314 LB |
727 | (route->path.type |
728 | == OSPF6_PATH_TYPE_EXTERNAL1) | |
729 | ? 1 | |
730 | : 2, | |
dc138868 | 731 | &route->prefix, listcount(route->paths), |
5e81f5dd DS |
732 | route->nh_list ? listcount( |
733 | route->nh_list) | |
734 | : 0); | |
064d4355 CS |
735 | } |
736 | ||
8873ebd3 CS |
737 | if (listcount(route->paths)) { |
738 | /* Update RIB/FIB with effective | |
739 | * nh_list | |
740 | */ | |
beadc736 | 741 | if (oa->ospf6->route_table->hook_add) |
742 | (*oa->ospf6->route_table | |
e285b70d | 743 | ->hook_add)(route); |
064d4355 | 744 | |
8873ebd3 CS |
745 | /* route's primary path is similar |
746 | * to LSA, replace route's primary | |
747 | * path with route's paths list head. | |
748 | */ | |
749 | if ((route->path.origin.id == | |
750 | lsa->header->id) && | |
751 | (route->path.origin.adv_router | |
752 | == lsa->header->adv_router)) { | |
753 | struct ospf6_path *h_path; | |
064d4355 | 754 | |
8873ebd3 | 755 | h_path = (struct ospf6_path *) |
996c9314 LB |
756 | listgetdata( |
757 | listhead(route->paths)); | |
8873ebd3 CS |
758 | route->path.origin.type = |
759 | h_path->origin.type; | |
760 | route->path.origin.id = | |
761 | h_path->origin.id; | |
762 | route->path.origin.adv_router = | |
064d4355 | 763 | h_path->origin.adv_router; |
8873ebd3 CS |
764 | } |
765 | } else { | |
beadc736 | 766 | ospf6_route_remove( |
e285b70d | 767 | route, oa->ospf6->route_table); |
064d4355 CS |
768 | } |
769 | } | |
d62a17ae | 770 | continue; |
771 | ||
064d4355 | 772 | } else { |
07b37f93 CS |
773 | /* Compare LSA origin and cost with current route info. |
774 | * if any check fails skip del this route node. | |
775 | */ | |
996c9314 LB |
776 | if (asbr_entry |
777 | && (!ospf6_route_is_same_origin(route, route_to_del) | |
778 | || (route->path.type != route_to_del->path.type) | |
779 | || (route->path.cost != route_to_del->path.cost) | |
780 | || (route->path.u.cost_e2 | |
781 | != route_to_del->path.u.cost_e2))) { | |
07b37f93 | 782 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { |
996c9314 | 783 | zlog_debug( |
dc138868 DL |
784 | "%s: route %pFX to delete is not same, cost %u del cost %u. skip", |
785 | __func__, &prefix, route->path.cost, | |
996c9314 | 786 | route_to_del->path.cost); |
07b37f93 | 787 | } |
064d4355 | 788 | continue; |
07b37f93 CS |
789 | } |
790 | ||
996c9314 LB |
791 | if ((route->path.origin.type != lsa->header->type) |
792 | || (route->path.origin.adv_router | |
793 | != lsa->header->adv_router) | |
794 | || (route->path.origin.id != lsa->header->id)) | |
064d4355 CS |
795 | continue; |
796 | } | |
d62a17ae | 797 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { |
996c9314 | 798 | zlog_debug( |
dc138868 | 799 | "%s: AS-External %u route remove %pFX cost %u(%u) nh %u", |
5e81f5dd | 800 | __func__, |
996c9314 LB |
801 | route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 |
802 | ? 1 | |
803 | : 2, | |
dc138868 | 804 | &route->prefix, route->path.cost, route->path.u.cost_e2, |
996c9314 | 805 | listcount(route->nh_list)); |
d62a17ae | 806 | } |
e285b70d | 807 | ospf6_route_remove(route, oa->ospf6->route_table); |
d62a17ae | 808 | } |
809 | if (route != NULL) | |
810 | ospf6_route_unlock(route); | |
07b37f93 CS |
811 | |
812 | ospf6_route_delete(route_to_del); | |
718e3744 | 813 | } |
814 | ||
beadc736 | 815 | void ospf6_asbr_lsentry_add(struct ospf6_route *asbr_entry, struct ospf6 *ospf6) |
508e53e2 | 816 | { |
d62a17ae | 817 | struct ospf6_lsa *lsa; |
d7c0a89a QY |
818 | uint16_t type; |
819 | uint32_t router; | |
d62a17ae | 820 | |
821 | if (!CHECK_FLAG(asbr_entry->flag, OSPF6_ROUTE_BEST)) { | |
822 | char buf[16]; | |
823 | inet_ntop(AF_INET, &ADV_ROUTER_IN_PREFIX(&asbr_entry->prefix), | |
824 | buf, sizeof(buf)); | |
825 | zlog_info("ignore non-best path: lsentry %s add", buf); | |
826 | return; | |
827 | } | |
828 | ||
829 | type = htons(OSPF6_LSTYPE_AS_EXTERNAL); | |
830 | router = ospf6_linkstate_prefix_adv_router(&asbr_entry->prefix); | |
831 | for (ALL_LSDB_TYPED_ADVRTR(ospf6->lsdb, type, router, lsa)) { | |
832 | if (!OSPF6_LSA_IS_MAXAGE(lsa)) | |
f5f26b8f | 833 | ospf6_asbr_lsa_add(lsa); |
d62a17ae | 834 | } |
508e53e2 | 835 | } |
836 | ||
beadc736 | 837 | void ospf6_asbr_lsentry_remove(struct ospf6_route *asbr_entry, |
838 | struct ospf6 *ospf6) | |
718e3744 | 839 | { |
d62a17ae | 840 | struct ospf6_lsa *lsa; |
d7c0a89a QY |
841 | uint16_t type; |
842 | uint32_t router; | |
d62a17ae | 843 | |
844 | type = htons(OSPF6_LSTYPE_AS_EXTERNAL); | |
845 | router = ospf6_linkstate_prefix_adv_router(&asbr_entry->prefix); | |
846 | for (ALL_LSDB_TYPED_ADVRTR(ospf6->lsdb, type, router, lsa)) | |
07b37f93 | 847 | ospf6_asbr_lsa_remove(lsa, asbr_entry); |
508e53e2 | 848 | } |
718e3744 | 849 | |
508e53e2 | 850 | |
508e53e2 | 851 | /* redistribute function */ |
a069482f K |
852 | static void ospf6_asbr_routemap_set(struct ospf6_redist *red, |
853 | const char *mapname) | |
508e53e2 | 854 | { |
a069482f K |
855 | if (ROUTEMAP_NAME(red)) { |
856 | route_map_counter_decrement(ROUTEMAP(red)); | |
857 | free(ROUTEMAP_NAME(red)); | |
64957b27 | 858 | } |
a069482f K |
859 | |
860 | ROUTEMAP_NAME(red) = strdup(mapname); | |
861 | ROUTEMAP(red) = route_map_lookup_by_name(mapname); | |
862 | route_map_counter_increment(ROUTEMAP(red)); | |
718e3744 | 863 | } |
864 | ||
a069482f | 865 | static void ospf6_asbr_routemap_unset(struct ospf6_redist *red) |
718e3744 | 866 | { |
a069482f K |
867 | if (ROUTEMAP_NAME(red)) |
868 | free(ROUTEMAP_NAME(red)); | |
64957b27 | 869 | |
a069482f | 870 | route_map_counter_decrement(ROUTEMAP(red)); |
64957b27 | 871 | |
a069482f K |
872 | ROUTEMAP_NAME(red) = NULL; |
873 | ROUTEMAP(red) = NULL; | |
508e53e2 | 874 | } |
875 | ||
856ae1eb CS |
876 | static int ospf6_asbr_routemap_update_timer(struct thread *thread) |
877 | { | |
878 | void **arg; | |
879 | int arg_type; | |
beadc736 | 880 | struct ospf6 *ospf6; |
a069482f | 881 | struct ospf6_redist *red; |
856ae1eb CS |
882 | |
883 | arg = THREAD_ARG(thread); | |
beadc736 | 884 | ospf6 = (struct ospf6 *)arg[0]; |
856ae1eb CS |
885 | arg_type = (int)(intptr_t)arg[1]; |
886 | ||
887 | ospf6->t_distribute_update = NULL; | |
888 | ||
a069482f K |
889 | red = ospf6_redist_lookup(ospf6, arg_type, 0); |
890 | ||
891 | if (red && ROUTEMAP_NAME(red)) | |
892 | ROUTEMAP(red) = route_map_lookup_by_name(ROUTEMAP_NAME(red)); | |
893 | if (red && ROUTEMAP(red)) { | |
856ae1eb CS |
894 | if (IS_OSPF6_DEBUG_ASBR) |
895 | zlog_debug("%s: route-map %s update, reset redist %s", | |
a069482f | 896 | __func__, ROUTEMAP_NAME(red), |
856ae1eb CS |
897 | ZROUTE_NAME(arg_type)); |
898 | ||
c5d28568 K |
899 | ospf6_zebra_no_redistribute(arg_type, ospf6->vrf_id); |
900 | ospf6_zebra_redistribute(arg_type, ospf6->vrf_id); | |
856ae1eb CS |
901 | } |
902 | ||
903 | XFREE(MTYPE_OSPF6_DIST_ARGS, arg); | |
904 | return 0; | |
905 | } | |
906 | ||
beadc736 | 907 | void ospf6_asbr_distribute_list_update(int type, struct ospf6 *ospf6) |
856ae1eb CS |
908 | { |
909 | void **args = NULL; | |
910 | ||
911 | if (ospf6->t_distribute_update) | |
912 | return; | |
913 | ||
996c9314 | 914 | args = XCALLOC(MTYPE_OSPF6_DIST_ARGS, sizeof(void *) * 2); |
856ae1eb CS |
915 | |
916 | args[0] = ospf6; | |
917 | args[1] = (void *)((ptrdiff_t)type); | |
918 | ||
919 | if (IS_OSPF6_DEBUG_ASBR) | |
15569c58 DA |
920 | zlog_debug("%s: trigger redistribute %s reset thread", __func__, |
921 | ZROUTE_NAME(type)); | |
856ae1eb CS |
922 | |
923 | ospf6->t_distribute_update = NULL; | |
c4efd0f4 DA |
924 | thread_add_timer_msec(master, ospf6_asbr_routemap_update_timer, args, |
925 | OSPF_MIN_LS_INTERVAL, | |
856ae1eb CS |
926 | &ospf6->t_distribute_update); |
927 | } | |
928 | ||
d62a17ae | 929 | static void ospf6_asbr_routemap_update(const char *mapname) |
508e53e2 | 930 | { |
d62a17ae | 931 | int type; |
beadc736 | 932 | struct listnode *node, *nnode; |
933 | struct ospf6 *ospf6 = NULL; | |
a069482f | 934 | struct ospf6_redist *red; |
d62a17ae | 935 | |
beadc736 | 936 | if (om6 == NULL) |
d62a17ae | 937 | return; |
938 | ||
beadc736 | 939 | for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { |
940 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
a069482f K |
941 | red = ospf6_redist_lookup(ospf6, type, 0); |
942 | if (!red || (ROUTEMAP_NAME(red) == NULL)) | |
96117716 | 943 | continue; |
a069482f K |
944 | ROUTEMAP(red) = |
945 | route_map_lookup_by_name(ROUTEMAP_NAME(red)); | |
c600ce45 | 946 | |
a069482f K |
947 | if (mapname == NULL |
948 | || strcmp(ROUTEMAP_NAME(red), mapname)) | |
96117716 | 949 | continue; |
a069482f | 950 | if (ROUTEMAP(red)) { |
96117716 | 951 | if (IS_OSPF6_DEBUG_ASBR) |
952 | zlog_debug( | |
780d4bdd | 953 | "%s: route-map %s update, reset redist %s", |
96117716 | 954 | __func__, |
955 | mapname, | |
956 | ZROUTE_NAME( | |
957 | type)); | |
64957b27 | 958 | |
a069482f | 959 | route_map_counter_increment(ROUTEMAP(red)); |
64957b27 | 960 | |
a069482f | 961 | ospf6_asbr_distribute_list_update(type, ospf6); |
96117716 | 962 | } else { |
963 | /* | |
964 | * if the mapname matches a | |
965 | * route-map on ospf6 but the | |
966 | * map doesn't exist, it is | |
967 | * being deleted. flush and then | |
968 | * readvertise | |
969 | */ | |
970 | if (IS_OSPF6_DEBUG_ASBR) | |
971 | zlog_debug( | |
780d4bdd | 972 | "%s: route-map %s deleted, reset redist %s", |
96117716 | 973 | __func__, |
974 | mapname, | |
975 | ZROUTE_NAME( | |
976 | type)); | |
a069482f K |
977 | ospf6_asbr_redistribute_unset(ospf6, red, type); |
978 | ospf6_asbr_routemap_set(red, mapname); | |
96117716 | 979 | ospf6_asbr_redistribute_set( |
c5d28568 | 980 | type, ospf6->vrf_id); |
c600ce45 | 981 | } |
beadc736 | 982 | } |
d62a17ae | 983 | } |
718e3744 | 984 | } |
985 | ||
097b5973 | 986 | static void ospf6_asbr_routemap_event(const char *name) |
856ae1eb CS |
987 | { |
988 | int type; | |
beadc736 | 989 | struct listnode *node, *nnode; |
990 | struct ospf6 *ospf6; | |
a069482f | 991 | struct ospf6_redist *red; |
856ae1eb | 992 | |
beadc736 | 993 | if (om6 == NULL) |
856ae1eb | 994 | return; |
beadc736 | 995 | for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { |
996 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
a069482f K |
997 | red = ospf6_redist_lookup(ospf6, type, 0); |
998 | if (red && ROUTEMAP_NAME(red) | |
999 | && (strcmp(ROUTEMAP_NAME(red), name) == 0)) | |
beadc736 | 1000 | ospf6_asbr_distribute_list_update(type, ospf6); |
856ae1eb CS |
1001 | } |
1002 | } | |
1003 | } | |
1004 | ||
d62a17ae | 1005 | int ospf6_asbr_is_asbr(struct ospf6 *o) |
508e53e2 | 1006 | { |
d62a17ae | 1007 | return o->external_table->count; |
508e53e2 | 1008 | } |
1009 | ||
a069482f K |
1010 | struct ospf6_redist *ospf6_redist_lookup(struct ospf6 *ospf6, int type, |
1011 | unsigned short instance) | |
1012 | { | |
1013 | struct list *red_list; | |
1014 | struct listnode *node; | |
1015 | struct ospf6_redist *red; | |
1016 | ||
1017 | red_list = ospf6->redist[type]; | |
1018 | if (!red_list) | |
1019 | return (NULL); | |
1020 | ||
1021 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) | |
1022 | if (red->instance == instance) | |
1023 | return red; | |
1024 | ||
1025 | return NULL; | |
1026 | } | |
1027 | ||
1028 | static struct ospf6_redist *ospf6_redist_add(struct ospf6 *ospf6, int type, | |
1029 | uint8_t instance) | |
1030 | { | |
1031 | struct ospf6_redist *red; | |
1032 | ||
1033 | red = ospf6_redist_lookup(ospf6, type, instance); | |
1034 | if (red) | |
1035 | return red; | |
1036 | ||
1037 | if (!ospf6->redist[type]) | |
1038 | ospf6->redist[type] = list_new(); | |
1039 | ||
1040 | red = XCALLOC(MTYPE_OSPF6_REDISTRIBUTE, sizeof(struct ospf6_redist)); | |
1041 | red->instance = instance; | |
1042 | ROUTEMAP_NAME(red) = NULL; | |
1043 | ROUTEMAP(red) = NULL; | |
1044 | ||
1045 | listnode_add(ospf6->redist[type], red); | |
1046 | ||
1047 | return red; | |
1048 | } | |
1049 | ||
1050 | static void ospf6_redist_del(struct ospf6 *ospf6, struct ospf6_redist *red, | |
1051 | int type) | |
1052 | { | |
1053 | if (red) { | |
1054 | listnode_delete(ospf6->redist[type], red); | |
1055 | if (!ospf6->redist[type]->count) { | |
1056 | list_delete(&ospf6->redist[type]); | |
1057 | } | |
1058 | XFREE(MTYPE_OSPF6_REDISTRIBUTE, red); | |
1059 | } | |
1060 | } | |
1061 | ||
c5d28568 | 1062 | static void ospf6_asbr_redistribute_set(int type, vrf_id_t vrf_id) |
718e3744 | 1063 | { |
c5d28568 | 1064 | ospf6_zebra_redistribute(type, vrf_id); |
508e53e2 | 1065 | } |
1066 | ||
a069482f K |
1067 | static void ospf6_asbr_redistribute_unset(struct ospf6 *ospf6, |
1068 | struct ospf6_redist *red, int type) | |
508e53e2 | 1069 | { |
d62a17ae | 1070 | struct ospf6_route *route; |
1071 | struct ospf6_external_info *info; | |
beadc736 | 1072 | |
a069482f | 1073 | ospf6_zebra_no_redistribute(type, ospf6->vrf_id); |
508e53e2 | 1074 | |
d62a17ae | 1075 | for (route = ospf6_route_head(ospf6->external_table); route; |
1076 | route = ospf6_route_next(route)) { | |
1077 | info = route->route_option; | |
1078 | if (info->type != type) | |
1079 | continue; | |
718e3744 | 1080 | |
beadc736 | 1081 | ospf6_asbr_redistribute_remove(info->type, 0, &route->prefix, |
1082 | ospf6); | |
d62a17ae | 1083 | } |
d9628728 | 1084 | |
a069482f | 1085 | ospf6_asbr_routemap_unset(red); |
508e53e2 | 1086 | } |
718e3744 | 1087 | |
ca1f4309 | 1088 | /* When an area is unstubified, flood all the external LSAs in the area */ |
d62a17ae | 1089 | void ospf6_asbr_send_externals_to_area(struct ospf6_area *oa) |
ca1f4309 | 1090 | { |
2e37407f | 1091 | struct ospf6_lsa *lsa, *lsanext; |
d62a17ae | 1092 | |
2e37407f | 1093 | for (ALL_LSDB(oa->ospf6->lsdb, lsa, lsanext)) { |
d62a17ae | 1094 | if (ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL) { |
9165c5f5 | 1095 | zlog_debug("%s: Flooding AS-External LSA %s", |
d62a17ae | 1096 | __func__, lsa->name); |
1097 | ospf6_flood_area(NULL, lsa, oa); | |
1098 | } | |
ca1f4309 | 1099 | } |
ca1f4309 DS |
1100 | } |
1101 | ||
bac66c5c | 1102 | /* When an area is stubified, remove all the external LSAs in the area */ |
1103 | void ospf6_asbr_remove_externals_from_area(struct ospf6_area *oa) | |
1104 | { | |
1105 | struct ospf6_lsa *lsa, *lsanext; | |
1106 | struct listnode *node, *nnode; | |
1107 | struct ospf6_area *area; | |
1108 | struct ospf6 *ospf6 = oa->ospf6; | |
1f4a8543 | 1109 | const struct route_node *iterend; |
bac66c5c | 1110 | |
1111 | /* skip if router is in other non-stub areas */ | |
1112 | for (ALL_LIST_ELEMENTS(ospf6->area_list, node, nnode, area)) | |
1113 | if (!IS_AREA_STUB(area)) | |
1114 | return; | |
1115 | ||
1116 | /* if router is only in a stub area then purge AS-External LSAs */ | |
1f4a8543 | 1117 | iterend = ospf6_lsdb_head(ospf6->lsdb, 0, 0, 0, &lsa); |
1118 | while (lsa != NULL) { | |
1119 | lsanext = ospf6_lsdb_next(iterend, lsa); | |
bac66c5c | 1120 | if (ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL) |
1121 | ospf6_lsdb_remove(lsa, ospf6->lsdb); | |
1f4a8543 | 1122 | lsa = lsanext; |
bac66c5c | 1123 | } |
1124 | } | |
1125 | ||
d62a17ae | 1126 | void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, |
d7c0a89a QY |
1127 | struct prefix *prefix, |
1128 | unsigned int nexthop_num, | |
beadc736 | 1129 | struct in6_addr *nexthop, route_tag_t tag, |
1130 | struct ospf6 *ospf6) | |
508e53e2 | 1131 | { |
b68885f9 | 1132 | route_map_result_t ret; |
d62a17ae | 1133 | struct ospf6_route troute; |
1134 | struct ospf6_external_info tinfo; | |
1135 | struct ospf6_route *route, *match; | |
1136 | struct ospf6_external_info *info; | |
1137 | struct prefix prefix_id; | |
1138 | struct route_node *node; | |
2dbe669b | 1139 | char ibuf[16]; |
d62a17ae | 1140 | struct listnode *lnode, *lnnode; |
1141 | struct ospf6_area *oa; | |
a069482f K |
1142 | struct ospf6_redist *red; |
1143 | ||
1144 | red = ospf6_redist_lookup(ospf6, type, 0); | |
1145 | ||
1146 | if (!red) | |
1147 | return; | |
d62a17ae | 1148 | |
c5d28568 | 1149 | if (!ospf6_zebra_is_redistribute(type, ospf6->vrf_id)) |
d62a17ae | 1150 | return; |
1151 | ||
6e38a9ec VJ |
1152 | memset(&troute, 0, sizeof(troute)); |
1153 | memset(&tinfo, 0, sizeof(tinfo)); | |
1154 | ||
2dbe669b DA |
1155 | if (IS_OSPF6_DEBUG_ASBR) |
1156 | zlog_debug("Redistribute %pFX (%s)", prefix, ZROUTE_NAME(type)); | |
d62a17ae | 1157 | |
1158 | /* if route-map was specified but not found, do not advertise */ | |
a069482f K |
1159 | if (ROUTEMAP_NAME(red)) { |
1160 | if (ROUTEMAP(red) == NULL) | |
d62a17ae | 1161 | ospf6_asbr_routemap_update(NULL); |
a069482f | 1162 | if (ROUTEMAP(red) == NULL) { |
d62a17ae | 1163 | zlog_warn( |
1164 | "route-map \"%s\" not found, suppress redistributing", | |
a069482f | 1165 | ROUTEMAP_NAME(red)); |
d62a17ae | 1166 | return; |
1167 | } | |
1168 | } | |
1169 | ||
1170 | /* apply route-map */ | |
a069482f | 1171 | if (ROUTEMAP(red)) { |
d62a17ae | 1172 | troute.route_option = &tinfo; |
1173 | tinfo.ifindex = ifindex; | |
1174 | tinfo.tag = tag; | |
1175 | ||
a069482f | 1176 | ret = route_map_apply(ROUTEMAP(red), prefix, &troute); |
d62a17ae | 1177 | if (ret == RMAP_DENYMATCH) { |
1178 | if (IS_OSPF6_DEBUG_ASBR) | |
1179 | zlog_debug("Denied by route-map \"%s\"", | |
a069482f | 1180 | ROUTEMAP_NAME(red)); |
beadc736 | 1181 | ospf6_asbr_redistribute_remove(type, ifindex, prefix, |
1182 | ospf6); | |
d62a17ae | 1183 | return; |
1184 | } | |
1185 | } | |
1186 | ||
1187 | match = ospf6_route_lookup(prefix, ospf6->external_table); | |
1188 | if (match) { | |
1189 | info = match->route_option; | |
d62a17ae | 1190 | /* copy result of route-map */ |
a069482f | 1191 | if (ROUTEMAP(red)) { |
d62a17ae | 1192 | if (troute.path.metric_type) |
1193 | match->path.metric_type = | |
1194 | troute.path.metric_type; | |
1195 | if (troute.path.cost) | |
1196 | match->path.cost = troute.path.cost; | |
1197 | if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo.forwarding)) | |
1198 | memcpy(&info->forwarding, &tinfo.forwarding, | |
1199 | sizeof(struct in6_addr)); | |
1200 | info->tag = tinfo.tag; | |
1201 | } else { | |
1202 | /* If there is no route-map, simply update the tag */ | |
1203 | info->tag = tag; | |
1204 | } | |
1205 | ||
1206 | info->type = type; | |
1207 | ||
1208 | if (nexthop_num && nexthop) | |
1209 | ospf6_route_add_nexthop(match, ifindex, nexthop); | |
1210 | else | |
1211 | ospf6_route_add_nexthop(match, ifindex, NULL); | |
1212 | ||
1213 | /* create/update binding in external_id_table */ | |
1214 | prefix_id.family = AF_INET; | |
1215 | prefix_id.prefixlen = 32; | |
1216 | prefix_id.u.prefix4.s_addr = htonl(info->id); | |
1217 | node = route_node_get(ospf6->external_id_table, &prefix_id); | |
1218 | node->info = match; | |
1219 | ||
1220 | if (IS_OSPF6_DEBUG_ASBR) { | |
1221 | inet_ntop(AF_INET, &prefix_id.u.prefix4, ibuf, | |
1222 | sizeof(ibuf)); | |
996c9314 | 1223 | zlog_debug( |
2dbe669b DA |
1224 | "Advertise as AS-External Id:%s prefix %pFX metric %u", |
1225 | ibuf, prefix, match->path.metric_type); | |
d62a17ae | 1226 | } |
1227 | ||
1228 | match->path.origin.id = htonl(info->id); | |
beadc736 | 1229 | ospf6_as_external_lsa_originate(match, ospf6); |
d62a17ae | 1230 | return; |
1231 | } | |
1232 | ||
1233 | /* create new entry */ | |
1234 | route = ospf6_route_create(); | |
1235 | route->type = OSPF6_DEST_TYPE_NETWORK; | |
1236 | memcpy(&route->prefix, prefix, sizeof(struct prefix)); | |
1237 | ||
1238 | info = (struct ospf6_external_info *)XCALLOC( | |
1239 | MTYPE_OSPF6_EXTERNAL_INFO, sizeof(struct ospf6_external_info)); | |
1240 | route->route_option = info; | |
1241 | info->id = ospf6->external_id++; | |
1242 | ||
1243 | /* copy result of route-map */ | |
a069482f | 1244 | if (ROUTEMAP(red)) { |
d62a17ae | 1245 | if (troute.path.metric_type) |
1246 | route->path.metric_type = troute.path.metric_type; | |
1247 | if (troute.path.cost) | |
1248 | route->path.cost = troute.path.cost; | |
1249 | if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo.forwarding)) | |
1250 | memcpy(&info->forwarding, &tinfo.forwarding, | |
1251 | sizeof(struct in6_addr)); | |
1252 | info->tag = tinfo.tag; | |
1253 | } else { | |
1254 | /* If there is no route-map, simply set the tag */ | |
1255 | info->tag = tag; | |
1256 | } | |
1257 | ||
1258 | info->type = type; | |
1259 | if (nexthop_num && nexthop) | |
1260 | ospf6_route_add_nexthop(route, ifindex, nexthop); | |
1261 | else | |
1262 | ospf6_route_add_nexthop(route, ifindex, NULL); | |
1263 | ||
1264 | /* create/update binding in external_id_table */ | |
1265 | prefix_id.family = AF_INET; | |
1266 | prefix_id.prefixlen = 32; | |
1267 | prefix_id.u.prefix4.s_addr = htonl(info->id); | |
1268 | node = route_node_get(ospf6->external_id_table, &prefix_id); | |
1269 | node->info = route; | |
1270 | ||
e285b70d | 1271 | route = ospf6_route_add(route, ospf6->external_table); |
d62a17ae | 1272 | route->route_option = info; |
1273 | ||
1274 | if (IS_OSPF6_DEBUG_ASBR) { | |
1275 | inet_ntop(AF_INET, &prefix_id.u.prefix4, ibuf, sizeof(ibuf)); | |
2dbe669b DA |
1276 | zlog_debug( |
1277 | "Advertise as AS-External Id:%s prefix %pFX metric %u", | |
1278 | ibuf, prefix, route->path.metric_type); | |
d62a17ae | 1279 | } |
1280 | ||
1281 | route->path.origin.id = htonl(info->id); | |
beadc736 | 1282 | ospf6_as_external_lsa_originate(route, ospf6); |
d62a17ae | 1283 | |
1284 | /* Router-Bit (ASBR Flag) may have to be updated */ | |
1285 | for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa)) | |
1286 | OSPF6_ROUTER_LSA_SCHEDULE(oa); | |
718e3744 | 1287 | } |
1288 | ||
d62a17ae | 1289 | void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex, |
beadc736 | 1290 | struct prefix *prefix, struct ospf6 *ospf6) |
718e3744 | 1291 | { |
d62a17ae | 1292 | struct ospf6_route *match; |
1293 | struct ospf6_external_info *info = NULL; | |
1294 | struct route_node *node; | |
1295 | struct ospf6_lsa *lsa; | |
1296 | struct prefix prefix_id; | |
2dbe669b | 1297 | char ibuf[16]; |
d62a17ae | 1298 | struct listnode *lnode, *lnnode; |
1299 | struct ospf6_area *oa; | |
1300 | ||
1301 | match = ospf6_route_lookup(prefix, ospf6->external_table); | |
1302 | if (match == NULL) { | |
2dbe669b DA |
1303 | if (IS_OSPF6_DEBUG_ASBR) |
1304 | zlog_debug("No such route %pFX to withdraw", prefix); | |
d62a17ae | 1305 | return; |
1306 | } | |
1307 | ||
1308 | info = match->route_option; | |
1309 | assert(info); | |
1310 | ||
1311 | if (info->type != type) { | |
2dbe669b DA |
1312 | if (IS_OSPF6_DEBUG_ASBR) |
1313 | zlog_debug("Original protocol mismatch: %pFX", prefix); | |
d62a17ae | 1314 | return; |
1315 | } | |
1316 | ||
1317 | if (IS_OSPF6_DEBUG_ASBR) { | |
d62a17ae | 1318 | inet_ntop(AF_INET, &prefix_id.u.prefix4, ibuf, sizeof(ibuf)); |
2dbe669b | 1319 | zlog_debug("Withdraw %pFX (AS-External Id:%s)", prefix, ibuf); |
d62a17ae | 1320 | } |
1321 | ||
1322 | lsa = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL), | |
1323 | htonl(info->id), ospf6->router_id, ospf6->lsdb); | |
1324 | if (lsa) | |
1325 | ospf6_lsa_purge(lsa); | |
1326 | ||
1327 | /* remove binding in external_id_table */ | |
1328 | prefix_id.family = AF_INET; | |
1329 | prefix_id.prefixlen = 32; | |
1330 | prefix_id.u.prefix4.s_addr = htonl(info->id); | |
1331 | node = route_node_lookup(ospf6->external_id_table, &prefix_id); | |
1332 | assert(node); | |
1333 | node->info = NULL; | |
d107621d CS |
1334 | route_unlock_node(node); /* to free the lookup lock */ |
1335 | route_unlock_node(node); /* to free the original lock */ | |
d62a17ae | 1336 | |
e285b70d | 1337 | ospf6_route_remove(match, ospf6->external_table); |
d62a17ae | 1338 | XFREE(MTYPE_OSPF6_EXTERNAL_INFO, info); |
1339 | ||
1340 | /* Router-Bit (ASBR Flag) may have to be updated */ | |
1341 | for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa)) | |
1342 | OSPF6_ROUTER_LSA_SCHEDULE(oa); | |
718e3744 | 1343 | } |
1344 | ||
508e53e2 | 1345 | DEFUN (ospf6_redistribute, |
1346 | ospf6_redistribute_cmd, | |
40d1cbfb | 1347 | "redistribute " FRR_REDIST_STR_OSPF6D, |
508e53e2 | 1348 | "Redistribute\n" |
3b14d86e | 1349 | FRR_REDIST_HELP_STR_OSPF6D) |
718e3744 | 1350 | { |
d62a17ae | 1351 | int type; |
a069482f | 1352 | struct ospf6_redist *red; |
e0ca5fde | 1353 | |
beadc736 | 1354 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
1355 | OSPF6_CMD_CHECK_RUNNING(ospf6); | |
d62a17ae | 1356 | char *proto = argv[argc - 1]->text; |
1357 | type = proto_redistnum(AFI_IP6, proto); | |
1358 | if (type < 0) | |
1359 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1360 | |
a069482f K |
1361 | red = ospf6_redist_add(ospf6, type, 0); |
1362 | if (!red) | |
1363 | return CMD_SUCCESS; | |
1364 | ||
1365 | ospf6_asbr_redistribute_unset(ospf6, red, type); | |
c5d28568 | 1366 | ospf6_asbr_redistribute_set(type, ospf6->vrf_id); |
a069482f | 1367 | |
d62a17ae | 1368 | return CMD_SUCCESS; |
508e53e2 | 1369 | } |
718e3744 | 1370 | |
508e53e2 | 1371 | DEFUN (ospf6_redistribute_routemap, |
1372 | ospf6_redistribute_routemap_cmd, | |
40d1cbfb | 1373 | "redistribute " FRR_REDIST_STR_OSPF6D " route-map WORD", |
508e53e2 | 1374 | "Redistribute\n" |
ab0181ee | 1375 | FRR_REDIST_HELP_STR_OSPF6D |
508e53e2 | 1376 | "Route map reference\n" |
e52702f2 | 1377 | "Route map name\n") |
508e53e2 | 1378 | { |
d62a17ae | 1379 | int idx_protocol = 1; |
1380 | int idx_word = 3; | |
1381 | int type; | |
a069482f | 1382 | struct ospf6_redist *red; |
d62a17ae | 1383 | |
beadc736 | 1384 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
1385 | OSPF6_CMD_CHECK_RUNNING(ospf6); | |
c5d28568 | 1386 | |
d62a17ae | 1387 | char *proto = argv[idx_protocol]->text; |
1388 | type = proto_redistnum(AFI_IP6, proto); | |
1389 | if (type < 0) | |
1390 | return CMD_WARNING_CONFIG_FAILED; | |
1391 | ||
a069482f K |
1392 | red = ospf6_redist_add(ospf6, type, 0); |
1393 | if (!red) | |
1394 | return CMD_SUCCESS; | |
1395 | ||
1396 | ospf6_asbr_redistribute_unset(ospf6, red, type); | |
1397 | ospf6_asbr_routemap_set(red, argv[idx_word]->arg); | |
c5d28568 | 1398 | ospf6_asbr_redistribute_set(type, ospf6->vrf_id); |
a069482f | 1399 | |
d62a17ae | 1400 | return CMD_SUCCESS; |
508e53e2 | 1401 | } |
1402 | ||
1403 | DEFUN (no_ospf6_redistribute, | |
1404 | no_ospf6_redistribute_cmd, | |
40d1cbfb | 1405 | "no redistribute " FRR_REDIST_STR_OSPF6D " [route-map WORD]", |
508e53e2 | 1406 | NO_STR |
1407 | "Redistribute\n" | |
ab0181ee | 1408 | FRR_REDIST_HELP_STR_OSPF6D |
1d68dbfe DW |
1409 | "Route map reference\n" |
1410 | "Route map name\n") | |
508e53e2 | 1411 | { |
d62a17ae | 1412 | int idx_protocol = 2; |
1413 | int type; | |
a069482f | 1414 | struct ospf6_redist *red; |
e0ca5fde | 1415 | |
beadc736 | 1416 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
1417 | ||
1418 | OSPF6_CMD_CHECK_RUNNING(ospf6); | |
c5d28568 | 1419 | |
d62a17ae | 1420 | char *proto = argv[idx_protocol]->text; |
1421 | type = proto_redistnum(AFI_IP6, proto); | |
1422 | if (type < 0) | |
1423 | return CMD_WARNING_CONFIG_FAILED; | |
e26bbeba | 1424 | |
a069482f K |
1425 | red = ospf6_redist_lookup(ospf6, type, 0); |
1426 | if (!red) | |
1427 | return CMD_SUCCESS; | |
1428 | ||
1429 | ospf6_asbr_redistribute_unset(ospf6, red, type); | |
1430 | ospf6_redist_del(ospf6, red, type); | |
e26bbeba | 1431 | |
d62a17ae | 1432 | return CMD_SUCCESS; |
508e53e2 | 1433 | } |
718e3744 | 1434 | |
beadc736 | 1435 | int ospf6_redistribute_config_write(struct vty *vty, struct ospf6 *ospf6) |
508e53e2 | 1436 | { |
d62a17ae | 1437 | int type; |
a069482f | 1438 | struct ospf6_redist *red; |
d62a17ae | 1439 | |
1440 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
a069482f K |
1441 | red = ospf6_redist_lookup(ospf6, type, 0); |
1442 | if (!red) | |
d62a17ae | 1443 | continue; |
a069482f | 1444 | if (type == ZEBRA_ROUTE_OSPF6) |
d62a17ae | 1445 | continue; |
1446 | ||
a069482f | 1447 | if (ROUTEMAP_NAME(red)) |
d62a17ae | 1448 | vty_out(vty, " redistribute %s route-map %s\n", |
a069482f | 1449 | ZROUTE_NAME(type), ROUTEMAP_NAME(red)); |
d62a17ae | 1450 | else |
1451 | vty_out(vty, " redistribute %s\n", ZROUTE_NAME(type)); | |
1452 | } | |
1453 | ||
1454 | return 0; | |
718e3744 | 1455 | } |
1456 | ||
dd726234 | 1457 | static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6, |
1458 | json_object *json_array, | |
1459 | json_object *json, bool use_json) | |
718e3744 | 1460 | { |
d62a17ae | 1461 | int type; |
1462 | int nroute[ZEBRA_ROUTE_MAX]; | |
1463 | int total; | |
1464 | struct ospf6_route *route; | |
1465 | struct ospf6_external_info *info; | |
dd726234 | 1466 | json_object *json_route; |
a069482f | 1467 | struct ospf6_redist *red; |
d62a17ae | 1468 | |
1469 | total = 0; | |
8f17f6eb | 1470 | memset(nroute, 0, sizeof(nroute)); |
d62a17ae | 1471 | for (route = ospf6_route_head(ospf6->external_table); route; |
1472 | route = ospf6_route_next(route)) { | |
1473 | info = route->route_option; | |
1474 | nroute[info->type]++; | |
1475 | total++; | |
1476 | } | |
718e3744 | 1477 | |
8f17f6eb | 1478 | if (!use_json) |
dd726234 | 1479 | vty_out(vty, "Redistributing External Routes from:\n"); |
1480 | ||
d62a17ae | 1481 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { |
8f17f6eb | 1482 | |
a069482f K |
1483 | red = ospf6_redist_lookup(ospf6, type, 0); |
1484 | ||
1485 | if (!red) | |
d62a17ae | 1486 | continue; |
a069482f | 1487 | if (type == ZEBRA_ROUTE_OSPF6) |
d62a17ae | 1488 | continue; |
1489 | ||
dd726234 | 1490 | if (use_json) { |
8f17f6eb | 1491 | json_route = json_object_new_object(); |
dd726234 | 1492 | json_object_string_add(json_route, "routeType", |
1493 | ZROUTE_NAME(type)); | |
1494 | json_object_int_add(json_route, "numberOfRoutes", | |
1495 | nroute[type]); | |
1496 | json_object_boolean_add(json_route, | |
1497 | "routeMapNamePresent", | |
a069482f | 1498 | ROUTEMAP_NAME(red)); |
dd726234 | 1499 | } |
1500 | ||
a069482f | 1501 | if (ROUTEMAP_NAME(red)) { |
dd726234 | 1502 | if (use_json) { |
1503 | json_object_string_add(json_route, | |
1504 | "routeMapName", | |
a069482f | 1505 | ROUTEMAP_NAME(red)); |
dd726234 | 1506 | json_object_boolean_add(json_route, |
1507 | "routeMapFound", | |
a069482f | 1508 | ROUTEMAP(red)); |
dd726234 | 1509 | } else |
1510 | vty_out(vty, | |
1511 | " %d: %s with route-map \"%s\"%s\n", | |
1512 | nroute[type], ZROUTE_NAME(type), | |
a069482f K |
1513 | ROUTEMAP_NAME(red), |
1514 | (ROUTEMAP(red) ? "" | |
1515 | : " (not found !)")); | |
dd726234 | 1516 | } else { |
1517 | if (!use_json) | |
1518 | vty_out(vty, " %d: %s\n", nroute[type], | |
1519 | ZROUTE_NAME(type)); | |
1520 | } | |
1521 | ||
1522 | if (use_json) | |
1523 | json_object_array_add(json_array, json_route); | |
d62a17ae | 1524 | } |
dd726234 | 1525 | if (use_json) { |
1526 | json_object_object_add(json, "redistributedRoutes", json_array); | |
1527 | json_object_int_add(json, "totalRoutes", total); | |
1528 | } else | |
1529 | vty_out(vty, "Total %d routes\n", total); | |
d62a17ae | 1530 | } |
718e3744 | 1531 | |
6b0655a2 | 1532 | |
508e53e2 | 1533 | /* Routemap Functions */ |
b68885f9 | 1534 | static enum route_map_cmd_result_t |
123214ef MS |
1535 | ospf6_routemap_rule_match_address_prefixlist(void *rule, |
1536 | const struct prefix *prefix, | |
1782514f | 1537 | |
d62a17ae | 1538 | void *object) |
508e53e2 | 1539 | { |
d62a17ae | 1540 | struct prefix_list *plist; |
718e3744 | 1541 | |
d62a17ae | 1542 | plist = prefix_list_lookup(AFI_IP6, (char *)rule); |
1543 | if (plist == NULL) | |
1544 | return RMAP_NOMATCH; | |
718e3744 | 1545 | |
d62a17ae | 1546 | return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH |
1547 | : RMAP_MATCH); | |
508e53e2 | 1548 | } |
718e3744 | 1549 | |
6ac29a51 | 1550 | static void * |
d62a17ae | 1551 | ospf6_routemap_rule_match_address_prefixlist_compile(const char *arg) |
508e53e2 | 1552 | { |
d62a17ae | 1553 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 1554 | } |
1555 | ||
d62a17ae | 1556 | static void ospf6_routemap_rule_match_address_prefixlist_free(void *rule) |
718e3744 | 1557 | { |
d62a17ae | 1558 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
508e53e2 | 1559 | } |
718e3744 | 1560 | |
364deb04 DL |
1561 | static const struct route_map_rule_cmd |
1562 | ospf6_routemap_rule_match_address_prefixlist_cmd = { | |
d62a17ae | 1563 | "ipv6 address prefix-list", |
1564 | ospf6_routemap_rule_match_address_prefixlist, | |
1565 | ospf6_routemap_rule_match_address_prefixlist_compile, | |
1566 | ospf6_routemap_rule_match_address_prefixlist_free, | |
508e53e2 | 1567 | }; |
718e3744 | 1568 | |
42a7debf VT |
1569 | /* `match interface IFNAME' */ |
1570 | /* Match function should return 1 if match is success else return | |
1571 | zero. */ | |
b68885f9 | 1572 | static enum route_map_cmd_result_t |
123214ef | 1573 | ospf6_routemap_rule_match_interface(void *rule, const struct prefix *prefix, |
1782514f | 1574 | void *object) |
42a7debf | 1575 | { |
d62a17ae | 1576 | struct interface *ifp; |
1577 | struct ospf6_external_info *ei; | |
42a7debf | 1578 | |
1782514f DS |
1579 | ei = ((struct ospf6_route *)object)->route_option; |
1580 | ifp = if_lookup_by_name_all_vrf((char *)rule); | |
42a7debf | 1581 | |
1782514f DS |
1582 | if (ifp != NULL && ei->ifindex == ifp->ifindex) |
1583 | return RMAP_MATCH; | |
42a7debf | 1584 | |
d62a17ae | 1585 | return RMAP_NOMATCH; |
42a7debf VT |
1586 | } |
1587 | ||
1588 | /* Route map `interface' match statement. `arg' should be | |
1589 | interface name. */ | |
d62a17ae | 1590 | static void *ospf6_routemap_rule_match_interface_compile(const char *arg) |
42a7debf | 1591 | { |
d62a17ae | 1592 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
42a7debf VT |
1593 | } |
1594 | ||
1595 | /* Free route map's compiled `interface' value. */ | |
d62a17ae | 1596 | static void ospf6_routemap_rule_match_interface_free(void *rule) |
42a7debf | 1597 | { |
d62a17ae | 1598 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
42a7debf VT |
1599 | } |
1600 | ||
1601 | /* Route map commands for interface matching. */ | |
364deb04 DL |
1602 | static const struct route_map_rule_cmd |
1603 | ospf6_routemap_rule_match_interface_cmd = { | |
1604 | "interface", | |
1605 | ospf6_routemap_rule_match_interface, | |
d62a17ae | 1606 | ospf6_routemap_rule_match_interface_compile, |
364deb04 DL |
1607 | ospf6_routemap_rule_match_interface_free |
1608 | }; | |
42a7debf | 1609 | |
464015fa | 1610 | /* Match function for matching route tags */ |
b68885f9 | 1611 | static enum route_map_cmd_result_t |
1782514f | 1612 | ospf6_routemap_rule_match_tag(void *rule, const struct prefix *p, void *object) |
464015fa | 1613 | { |
d62a17ae | 1614 | route_tag_t *tag = rule; |
1615 | struct ospf6_route *route = object; | |
1616 | struct ospf6_external_info *info = route->route_option; | |
464015fa | 1617 | |
1782514f | 1618 | if (info->tag == *tag) |
d62a17ae | 1619 | return RMAP_MATCH; |
464015fa | 1620 | |
d62a17ae | 1621 | return RMAP_NOMATCH; |
464015fa CF |
1622 | } |
1623 | ||
364deb04 DL |
1624 | static const struct route_map_rule_cmd |
1625 | ospf6_routemap_rule_match_tag_cmd = { | |
1626 | "tag", | |
1627 | ospf6_routemap_rule_match_tag, | |
1628 | route_map_rule_tag_compile, | |
d62a17ae | 1629 | route_map_rule_tag_free, |
464015fa CF |
1630 | }; |
1631 | ||
b68885f9 | 1632 | static enum route_map_cmd_result_t |
123214ef | 1633 | ospf6_routemap_rule_set_metric_type(void *rule, const struct prefix *prefix, |
1782514f | 1634 | void *object) |
508e53e2 | 1635 | { |
d62a17ae | 1636 | char *metric_type = rule; |
1637 | struct ospf6_route *route = object; | |
718e3744 | 1638 | |
d62a17ae | 1639 | if (strcmp(metric_type, "type-2") == 0) |
1640 | route->path.metric_type = 2; | |
1641 | else | |
1642 | route->path.metric_type = 1; | |
718e3744 | 1643 | |
d62a17ae | 1644 | return RMAP_OKAY; |
508e53e2 | 1645 | } |
718e3744 | 1646 | |
d62a17ae | 1647 | static void *ospf6_routemap_rule_set_metric_type_compile(const char *arg) |
508e53e2 | 1648 | { |
d62a17ae | 1649 | if (strcmp(arg, "type-2") && strcmp(arg, "type-1")) |
1650 | return NULL; | |
1651 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 1652 | } |
1653 | ||
d62a17ae | 1654 | static void ospf6_routemap_rule_set_metric_type_free(void *rule) |
718e3744 | 1655 | { |
d62a17ae | 1656 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
508e53e2 | 1657 | } |
718e3744 | 1658 | |
364deb04 DL |
1659 | static const struct route_map_rule_cmd |
1660 | ospf6_routemap_rule_set_metric_type_cmd = { | |
1661 | "metric-type", | |
1662 | ospf6_routemap_rule_set_metric_type, | |
d62a17ae | 1663 | ospf6_routemap_rule_set_metric_type_compile, |
1664 | ospf6_routemap_rule_set_metric_type_free, | |
508e53e2 | 1665 | }; |
718e3744 | 1666 | |
b68885f9 | 1667 | static enum route_map_cmd_result_t |
123214ef | 1668 | ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix, |
1782514f | 1669 | void *object) |
508e53e2 | 1670 | { |
d62a17ae | 1671 | char *metric = rule; |
1672 | struct ospf6_route *route = object; | |
718e3744 | 1673 | |
d62a17ae | 1674 | route->path.cost = atoi(metric); |
1675 | return RMAP_OKAY; | |
508e53e2 | 1676 | } |
718e3744 | 1677 | |
d62a17ae | 1678 | static void *ospf6_routemap_rule_set_metric_compile(const char *arg) |
508e53e2 | 1679 | { |
d7c0a89a | 1680 | uint32_t metric; |
d62a17ae | 1681 | char *endp; |
1682 | metric = strtoul(arg, &endp, 0); | |
1683 | if (metric > OSPF_LS_INFINITY || *endp != '\0') | |
1684 | return NULL; | |
1685 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 1686 | } |
1687 | ||
d62a17ae | 1688 | static void ospf6_routemap_rule_set_metric_free(void *rule) |
718e3744 | 1689 | { |
d62a17ae | 1690 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
508e53e2 | 1691 | } |
718e3744 | 1692 | |
364deb04 DL |
1693 | static const struct route_map_rule_cmd |
1694 | ospf6_routemap_rule_set_metric_cmd = { | |
1695 | "metric", | |
1696 | ospf6_routemap_rule_set_metric, | |
d62a17ae | 1697 | ospf6_routemap_rule_set_metric_compile, |
1698 | ospf6_routemap_rule_set_metric_free, | |
508e53e2 | 1699 | }; |
718e3744 | 1700 | |
b68885f9 | 1701 | static enum route_map_cmd_result_t |
123214ef | 1702 | ospf6_routemap_rule_set_forwarding(void *rule, const struct prefix *prefix, |
1782514f | 1703 | void *object) |
508e53e2 | 1704 | { |
d62a17ae | 1705 | char *forwarding = rule; |
1706 | struct ospf6_route *route = object; | |
1707 | struct ospf6_external_info *info = route->route_option; | |
718e3744 | 1708 | |
d62a17ae | 1709 | if (inet_pton(AF_INET6, forwarding, &info->forwarding) != 1) { |
1710 | memset(&info->forwarding, 0, sizeof(struct in6_addr)); | |
1711 | return RMAP_ERROR; | |
1712 | } | |
718e3744 | 1713 | |
d62a17ae | 1714 | return RMAP_OKAY; |
718e3744 | 1715 | } |
1716 | ||
d62a17ae | 1717 | static void *ospf6_routemap_rule_set_forwarding_compile(const char *arg) |
718e3744 | 1718 | { |
d62a17ae | 1719 | struct in6_addr a; |
1720 | if (inet_pton(AF_INET6, arg, &a) != 1) | |
1721 | return NULL; | |
1722 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
718e3744 | 1723 | } |
1724 | ||
d62a17ae | 1725 | static void ospf6_routemap_rule_set_forwarding_free(void *rule) |
718e3744 | 1726 | { |
d62a17ae | 1727 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
508e53e2 | 1728 | } |
718e3744 | 1729 | |
364deb04 DL |
1730 | static const struct route_map_rule_cmd |
1731 | ospf6_routemap_rule_set_forwarding_cmd = { | |
1732 | "forwarding-address", | |
1733 | ospf6_routemap_rule_set_forwarding, | |
d62a17ae | 1734 | ospf6_routemap_rule_set_forwarding_compile, |
1735 | ospf6_routemap_rule_set_forwarding_free, | |
508e53e2 | 1736 | }; |
718e3744 | 1737 | |
b68885f9 | 1738 | static enum route_map_cmd_result_t |
1782514f | 1739 | ospf6_routemap_rule_set_tag(void *rule, const struct prefix *p, void *object) |
464015fa | 1740 | { |
d62a17ae | 1741 | route_tag_t *tag = rule; |
1742 | struct ospf6_route *route = object; | |
1743 | struct ospf6_external_info *info = route->route_option; | |
464015fa | 1744 | |
d62a17ae | 1745 | info->tag = *tag; |
1746 | return RMAP_OKAY; | |
464015fa CF |
1747 | } |
1748 | ||
364deb04 DL |
1749 | static const struct route_map_rule_cmd |
1750 | ospf6_routemap_rule_set_tag_cmd = { | |
1751 | "tag", | |
1752 | ospf6_routemap_rule_set_tag, | |
1753 | route_map_rule_tag_compile, | |
d62a17ae | 1754 | route_map_rule_tag_free, |
464015fa CF |
1755 | }; |
1756 | ||
cda7187d | 1757 | static int route_map_command_status(struct vty *vty, enum rmap_compile_rets ret) |
508e53e2 | 1758 | { |
d62a17ae | 1759 | switch (ret) { |
1760 | case RMAP_RULE_MISSING: | |
1761 | vty_out(vty, "OSPF6 Can't find rule.\n"); | |
9ca25fed | 1762 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 1763 | case RMAP_COMPILE_ERROR: |
1764 | vty_out(vty, "OSPF6 Argument is malformed.\n"); | |
9ca25fed | 1765 | return CMD_WARNING_CONFIG_FAILED; |
9ca25fed | 1766 | case RMAP_COMPILE_SUCCESS: |
d62a17ae | 1767 | break; |
1768 | } | |
9ca25fed DS |
1769 | |
1770 | return CMD_SUCCESS; | |
508e53e2 | 1771 | } |
718e3744 | 1772 | |
508e53e2 | 1773 | /* add "set metric-type" */ |
1774 | DEFUN (ospf6_routemap_set_metric_type, | |
1775 | ospf6_routemap_set_metric_type_cmd, | |
6147e2c6 | 1776 | "set metric-type <type-1|type-2>", |
508e53e2 | 1777 | "Set value\n" |
1778 | "Type of metric\n" | |
1779 | "OSPF6 external type 1 metric\n" | |
1780 | "OSPF6 external type 2 metric\n") | |
1781 | { | |
d62a17ae | 1782 | VTY_DECLVAR_CONTEXT(route_map_index, route_map_index); |
1783 | int idx_external = 2; | |
cda7187d DS |
1784 | enum rmap_compile_rets ret = route_map_add_set(route_map_index, |
1785 | "metric-type", | |
1786 | argv[idx_external]->arg); | |
1787 | ||
d62a17ae | 1788 | return route_map_command_status(vty, ret); |
718e3744 | 1789 | } |
1790 | ||
508e53e2 | 1791 | /* delete "set metric-type" */ |
1792 | DEFUN (ospf6_routemap_no_set_metric_type, | |
1793 | ospf6_routemap_no_set_metric_type_cmd, | |
dab8cd00 | 1794 | "no set metric-type [<type-1|type-2>]", |
508e53e2 | 1795 | NO_STR |
1796 | "Set value\n" | |
1797 | "Type of metric\n" | |
1798 | "OSPF6 external type 1 metric\n" | |
1799 | "OSPF6 external type 2 metric\n") | |
718e3744 | 1800 | { |
d62a17ae | 1801 | VTY_DECLVAR_CONTEXT(route_map_index, route_map_index); |
1802 | char *ext = (argc == 4) ? argv[3]->text : NULL; | |
cda7187d DS |
1803 | enum rmap_compile_rets ret = route_map_delete_set(route_map_index, |
1804 | "metric-type", ext); | |
1805 | ||
d62a17ae | 1806 | return route_map_command_status(vty, ret); |
508e53e2 | 1807 | } |
718e3744 | 1808 | |
508e53e2 | 1809 | /* add "set forwarding-address" */ |
1810 | DEFUN (ospf6_routemap_set_forwarding, | |
1811 | ospf6_routemap_set_forwarding_cmd, | |
1812 | "set forwarding-address X:X::X:X", | |
1813 | "Set value\n" | |
1814 | "Forwarding Address\n" | |
1815 | "IPv6 Address\n") | |
1816 | { | |
d62a17ae | 1817 | VTY_DECLVAR_CONTEXT(route_map_index, route_map_index); |
1818 | int idx_ipv6 = 2; | |
cda7187d DS |
1819 | enum rmap_compile_rets ret = route_map_add_set(route_map_index, |
1820 | "forwarding-address", | |
1821 | argv[idx_ipv6]->arg); | |
1822 | ||
d62a17ae | 1823 | return route_map_command_status(vty, ret); |
508e53e2 | 1824 | } |
718e3744 | 1825 | |
508e53e2 | 1826 | /* delete "set forwarding-address" */ |
1827 | DEFUN (ospf6_routemap_no_set_forwarding, | |
1828 | ospf6_routemap_no_set_forwarding_cmd, | |
1829 | "no set forwarding-address X:X::X:X", | |
1830 | NO_STR | |
1831 | "Set value\n" | |
1832 | "Forwarding Address\n" | |
1833 | "IPv6 Address\n") | |
1834 | { | |
d62a17ae | 1835 | VTY_DECLVAR_CONTEXT(route_map_index, route_map_index); |
1836 | int idx_ipv6 = 3; | |
cda7187d DS |
1837 | enum rmap_compile_rets ret = route_map_delete_set(route_map_index, |
1838 | "forwarding-address", | |
1839 | argv[idx_ipv6]->arg); | |
1840 | ||
d62a17ae | 1841 | return route_map_command_status(vty, ret); |
508e53e2 | 1842 | } |
718e3744 | 1843 | |
d62a17ae | 1844 | static void ospf6_routemap_init(void) |
508e53e2 | 1845 | { |
d62a17ae | 1846 | route_map_init(); |
b2575bc0 | 1847 | |
d62a17ae | 1848 | route_map_add_hook(ospf6_asbr_routemap_update); |
1849 | route_map_delete_hook(ospf6_asbr_routemap_update); | |
856ae1eb | 1850 | route_map_event_hook(ospf6_asbr_routemap_event); |
508e53e2 | 1851 | |
d62a17ae | 1852 | route_map_set_metric_hook(generic_set_add); |
1853 | route_map_no_set_metric_hook(generic_set_delete); | |
82f97584 | 1854 | |
d62a17ae | 1855 | route_map_match_tag_hook(generic_match_add); |
1856 | route_map_no_match_tag_hook(generic_match_delete); | |
e1a1b2ed | 1857 | |
d62a17ae | 1858 | route_map_match_ipv6_address_prefix_list_hook(generic_match_add); |
1859 | route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete); | |
e1a1b2ed | 1860 | |
d62a17ae | 1861 | route_map_match_interface_hook(generic_match_add); |
1862 | route_map_no_match_interface_hook(generic_match_delete); | |
e1a1b2ed | 1863 | |
d62a17ae | 1864 | route_map_install_match( |
1865 | &ospf6_routemap_rule_match_address_prefixlist_cmd); | |
1866 | route_map_install_match(&ospf6_routemap_rule_match_interface_cmd); | |
1867 | route_map_install_match(&ospf6_routemap_rule_match_tag_cmd); | |
42a7debf | 1868 | |
d62a17ae | 1869 | route_map_install_set(&ospf6_routemap_rule_set_metric_type_cmd); |
1870 | route_map_install_set(&ospf6_routemap_rule_set_metric_cmd); | |
1871 | route_map_install_set(&ospf6_routemap_rule_set_forwarding_cmd); | |
1872 | route_map_install_set(&ospf6_routemap_rule_set_tag_cmd); | |
508e53e2 | 1873 | |
d62a17ae | 1874 | /* ASE Metric Type (e.g. Type-1/Type-2) */ |
1875 | install_element(RMAP_NODE, &ospf6_routemap_set_metric_type_cmd); | |
1876 | install_element(RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd); | |
508e53e2 | 1877 | |
d62a17ae | 1878 | /* ASE Metric */ |
1879 | install_element(RMAP_NODE, &ospf6_routemap_set_forwarding_cmd); | |
1880 | install_element(RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd); | |
718e3744 | 1881 | } |
1882 | ||
6b0655a2 | 1883 | |
508e53e2 | 1884 | /* Display functions */ |
d62a17ae | 1885 | static char *ospf6_as_external_lsa_get_prefix_str(struct ospf6_lsa *lsa, |
1886 | char *buf, int buflen, | |
1887 | int pos) | |
e68a6767 | 1888 | { |
d62a17ae | 1889 | struct ospf6_as_external_lsa *external; |
1890 | struct in6_addr in6; | |
1891 | int prefix_length = 0; | |
7533cad7 | 1892 | char tbuf[16]; |
d62a17ae | 1893 | |
1894 | if (lsa) { | |
1895 | external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( | |
1896 | lsa->header); | |
1897 | ||
1898 | if (pos == 0) { | |
b8ce0c36 | 1899 | ospf6_prefix_in6_addr(&in6, external, |
1900 | &external->prefix); | |
d62a17ae | 1901 | prefix_length = external->prefix.prefix_length; |
1902 | } else { | |
1903 | in6 = *((struct in6_addr | |
1904 | *)((caddr_t)external | |
1905 | + sizeof(struct | |
1906 | ospf6_as_external_lsa) | |
1907 | + OSPF6_PREFIX_SPACE( | |
1908 | external->prefix | |
1909 | .prefix_length))); | |
1910 | } | |
1911 | if (buf) { | |
1912 | inet_ntop(AF_INET6, &in6, buf, buflen); | |
7533cad7 QY |
1913 | if (prefix_length) { |
1914 | snprintf(tbuf, sizeof(tbuf), "/%d", | |
1915 | prefix_length); | |
1916 | strlcat(buf, tbuf, buflen); | |
1917 | } | |
d62a17ae | 1918 | } |
e68a6767 | 1919 | } |
d62a17ae | 1920 | return (buf); |
e68a6767 DD |
1921 | } |
1922 | ||
e4bacbaa YR |
1923 | static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, |
1924 | json_object *json_obj, bool use_json) | |
718e3744 | 1925 | { |
d62a17ae | 1926 | struct ospf6_as_external_lsa *external; |
1927 | char buf[64]; | |
1928 | ||
1929 | assert(lsa->header); | |
1930 | external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( | |
1931 | lsa->header); | |
1932 | ||
1933 | /* bits */ | |
1934 | snprintf(buf, sizeof(buf), "%c%c%c", | |
1935 | (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' | |
1936 | : '-'), | |
1937 | (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' | |
1938 | : '-'), | |
1939 | (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' | |
1940 | : '-')); | |
1941 | ||
e4bacbaa YR |
1942 | if (use_json) { |
1943 | json_object_string_add(json_obj, "bits", buf); | |
1944 | json_object_int_add(json_obj, "metric", | |
1945 | (unsigned long)OSPF6_ASBR_METRIC(external)); | |
1946 | ospf6_prefix_options_printbuf(external->prefix.prefix_options, | |
1947 | buf, sizeof(buf)); | |
1948 | json_object_string_add(json_obj, "prefixOptions", buf); | |
1949 | json_object_int_add( | |
1950 | json_obj, "referenceLsType", | |
1951 | ntohs(external->prefix.prefix_refer_lstype)); | |
1952 | json_object_string_add(json_obj, "prefix", | |
1953 | ospf6_as_external_lsa_get_prefix_str( | |
1954 | lsa, buf, sizeof(buf), 0)); | |
1955 | ||
1956 | /* Forwarding-Address */ | |
1957 | json_object_boolean_add( | |
1958 | json_obj, "forwardingAddressPresent", | |
1959 | CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)); | |
1960 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) | |
1961 | json_object_string_add( | |
1962 | json_obj, "forwardingAddress", | |
1963 | ospf6_as_external_lsa_get_prefix_str( | |
1964 | lsa, buf, sizeof(buf), 1)); | |
1965 | ||
1966 | /* Tag */ | |
1967 | json_object_boolean_add( | |
1968 | json_obj, "tagPresent", | |
1969 | CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)); | |
1970 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) | |
1971 | json_object_int_add(json_obj, "tag", | |
1972 | ospf6_as_external_lsa_get_tag(lsa)); | |
1973 | } else { | |
1974 | vty_out(vty, " Bits: %s\n", buf); | |
1975 | vty_out(vty, " Metric: %5lu\n", | |
1976 | (unsigned long)OSPF6_ASBR_METRIC(external)); | |
d62a17ae | 1977 | |
e4bacbaa YR |
1978 | ospf6_prefix_options_printbuf(external->prefix.prefix_options, |
1979 | buf, sizeof(buf)); | |
1980 | vty_out(vty, " Prefix Options: %s\n", buf); | |
d62a17ae | 1981 | |
e4bacbaa YR |
1982 | vty_out(vty, " Referenced LSType: %d\n", |
1983 | ntohs(external->prefix.prefix_refer_lstype)); | |
d62a17ae | 1984 | |
e4bacbaa | 1985 | vty_out(vty, " Prefix: %s\n", |
d62a17ae | 1986 | ospf6_as_external_lsa_get_prefix_str(lsa, buf, |
e4bacbaa | 1987 | sizeof(buf), 0)); |
d62a17ae | 1988 | |
e4bacbaa YR |
1989 | /* Forwarding-Address */ |
1990 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) { | |
1991 | vty_out(vty, " Forwarding-Address: %s\n", | |
1992 | ospf6_as_external_lsa_get_prefix_str( | |
1993 | lsa, buf, sizeof(buf), 1)); | |
1994 | } | |
1995 | ||
1996 | /* Tag */ | |
1997 | if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) { | |
1998 | vty_out(vty, " Tag: %" ROUTE_TAG_PRI "\n", | |
1999 | ospf6_as_external_lsa_get_tag(lsa)); | |
2000 | } | |
d62a17ae | 2001 | } |
2002 | ||
2003 | return 0; | |
718e3744 | 2004 | } |
2005 | ||
d62a17ae | 2006 | static void ospf6_asbr_external_route_show(struct vty *vty, |
dd726234 | 2007 | struct ospf6_route *route, |
2008 | json_object *json_array, | |
2009 | bool use_json) | |
718e3744 | 2010 | { |
d62a17ae | 2011 | struct ospf6_external_info *info = route->route_option; |
dd726234 | 2012 | char prefix[PREFIX2STR_BUFFER], id[16], forwarding[64]; |
d7c0a89a | 2013 | uint32_t tmp_id; |
dd726234 | 2014 | json_object *json_route; |
2015 | char route_type[2]; | |
d62a17ae | 2016 | |
dd726234 | 2017 | prefix2str(&route->prefix, prefix, sizeof(prefix)); |
d62a17ae | 2018 | tmp_id = ntohl(info->id); |
2019 | inet_ntop(AF_INET, &tmp_id, id, sizeof(id)); | |
2020 | if (!IN6_IS_ADDR_UNSPECIFIED(&info->forwarding)) | |
2021 | inet_ntop(AF_INET6, &info->forwarding, forwarding, | |
2022 | sizeof(forwarding)); | |
2023 | else | |
2024 | snprintf(forwarding, sizeof(forwarding), ":: (ifindex %d)", | |
2025 | ospf6_route_get_first_nh_index(route)); | |
2026 | ||
dd726234 | 2027 | if (use_json) { |
2028 | json_route = json_object_new_object(); | |
2029 | snprintf(route_type, sizeof(route_type), "%c", | |
2030 | zebra_route_char(info->type)); | |
2031 | json_object_string_add(json_route, "routeType", route_type); | |
2032 | json_object_string_add(json_route, "destination", prefix); | |
2033 | json_object_string_add(json_route, "id", id); | |
2034 | json_object_int_add(json_route, "metricType", | |
2035 | route->path.metric_type); | |
2036 | json_object_int_add( | |
2037 | json_route, "routeCost", | |
2038 | (unsigned long)(route->path.metric_type == 2 | |
2039 | ? route->path.u.cost_e2 | |
2040 | : route->path.cost)); | |
2041 | json_object_string_add(json_route, "forwarding", forwarding); | |
2042 | ||
2043 | json_object_array_add(json_array, json_route); | |
2044 | } else | |
2045 | ||
2046 | vty_out(vty, "%c %-32pFX %-15s type-%d %5lu %s\n", | |
2047 | zebra_route_char(info->type), &route->prefix, id, | |
2048 | route->path.metric_type, | |
2049 | (unsigned long)(route->path.metric_type == 2 | |
2050 | ? route->path.u.cost_e2 | |
2051 | : route->path.cost), | |
2052 | forwarding); | |
718e3744 | 2053 | } |
2054 | ||
508e53e2 | 2055 | DEFUN (show_ipv6_ospf6_redistribute, |
2056 | show_ipv6_ospf6_redistribute_cmd, | |
dd726234 | 2057 | "show ipv6 ospf6 redistribute [json]", |
508e53e2 | 2058 | SHOW_STR |
2059 | IP6_STR | |
2060 | OSPF6_STR | |
2061 | "redistributing External information\n" | |
dd726234 | 2062 | JSON_STR) |
718e3744 | 2063 | { |
d62a17ae | 2064 | struct ospf6_route *route; |
beadc736 | 2065 | struct ospf6 *ospf6 = NULL; |
dd726234 | 2066 | json_object *json = NULL; |
2067 | bool uj = use_json(argc, argv); | |
2068 | json_object *json_array_routes = NULL; | |
2069 | json_object *json_array_redistribute = NULL; | |
718e3744 | 2070 | |
beadc736 | 2071 | ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); |
2072 | OSPF6_CMD_CHECK_RUNNING(ospf6); | |
b52a8a52 | 2073 | |
dd726234 | 2074 | if (uj) { |
2075 | json = json_object_new_object(); | |
2076 | json_array_routes = json_object_new_array(); | |
2077 | json_array_redistribute = json_object_new_array(); | |
2078 | } | |
2079 | ospf6_redistribute_show_config(vty, ospf6, json_array_redistribute, | |
2080 | json, uj); | |
718e3744 | 2081 | |
d62a17ae | 2082 | for (route = ospf6_route_head(ospf6->external_table); route; |
dd726234 | 2083 | route = ospf6_route_next(route)) { |
2084 | ospf6_asbr_external_route_show(vty, route, json_array_routes, | |
2085 | uj); | |
2086 | } | |
508e53e2 | 2087 | |
dd726234 | 2088 | if (uj) { |
2089 | json_object_object_add(json, "routes", json_array_routes); | |
2090 | vty_out(vty, "%s\n", | |
2091 | json_object_to_json_string_ext( | |
2092 | json, JSON_C_TO_STRING_PRETTY)); | |
2093 | json_object_free(json); | |
2094 | } | |
d62a17ae | 2095 | return CMD_SUCCESS; |
718e3744 | 2096 | } |
2097 | ||
4062abfa | 2098 | static struct ospf6_lsa_handler as_external_handler = { |
3981b5c7 VJ |
2099 | .lh_type = OSPF6_LSTYPE_AS_EXTERNAL, |
2100 | .lh_name = "AS-External", | |
2101 | .lh_short_name = "ASE", | |
2102 | .lh_show = ospf6_as_external_lsa_show, | |
2103 | .lh_get_prefix_str = ospf6_as_external_lsa_get_prefix_str, | |
996c9314 | 2104 | .lh_debug = 0}; |
508e53e2 | 2105 | |
d62a17ae | 2106 | void ospf6_asbr_init(void) |
718e3744 | 2107 | { |
d62a17ae | 2108 | ospf6_routemap_init(); |
508e53e2 | 2109 | |
d62a17ae | 2110 | ospf6_install_lsa_handler(&as_external_handler); |
718e3744 | 2111 | |
d62a17ae | 2112 | install_element(VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd); |
508e53e2 | 2113 | |
d62a17ae | 2114 | install_element(OSPF6_NODE, &ospf6_redistribute_cmd); |
2115 | install_element(OSPF6_NODE, &ospf6_redistribute_routemap_cmd); | |
2116 | install_element(OSPF6_NODE, &no_ospf6_redistribute_cmd); | |
718e3744 | 2117 | } |
2118 | ||
a069482f | 2119 | void ospf6_asbr_redistribute_reset(struct ospf6 *ospf6) |
d9628728 | 2120 | { |
d62a17ae | 2121 | int type; |
a069482f | 2122 | struct ospf6_redist *red; |
d62a17ae | 2123 | |
2124 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
a069482f K |
2125 | red = ospf6_redist_lookup(ospf6, type, 0); |
2126 | if (!red) | |
2127 | continue; | |
d62a17ae | 2128 | if (type == ZEBRA_ROUTE_OSPF6) |
2129 | continue; | |
a069482f K |
2130 | if (ospf6_zebra_is_redistribute(type, ospf6->vrf_id)) { |
2131 | ospf6_asbr_redistribute_unset(ospf6, red, type); | |
2132 | ospf6_redist_del(ospf6, red, type); | |
2133 | } | |
d62a17ae | 2134 | } |
d9628728 CF |
2135 | } |
2136 | ||
d62a17ae | 2137 | void ospf6_asbr_terminate(void) |
ae2254aa | 2138 | { |
856ae1eb | 2139 | /* Cleanup route maps */ |
d62a17ae | 2140 | route_map_finish(); |
ae2254aa | 2141 | } |
718e3744 | 2142 | |
508e53e2 | 2143 | DEFUN (debug_ospf6_asbr, |
2144 | debug_ospf6_asbr_cmd, | |
2145 | "debug ospf6 asbr", | |
2146 | DEBUG_STR | |
2147 | OSPF6_STR | |
2148 | "Debug OSPFv3 ASBR function\n" | |
2149 | ) | |
2150 | { | |
d62a17ae | 2151 | OSPF6_DEBUG_ASBR_ON(); |
2152 | return CMD_SUCCESS; | |
508e53e2 | 2153 | } |
2154 | ||
2155 | DEFUN (no_debug_ospf6_asbr, | |
2156 | no_debug_ospf6_asbr_cmd, | |
2157 | "no debug ospf6 asbr", | |
2158 | NO_STR | |
2159 | DEBUG_STR | |
2160 | OSPF6_STR | |
2161 | "Debug OSPFv3 ASBR function\n" | |
2162 | ) | |
2163 | { | |
d62a17ae | 2164 | OSPF6_DEBUG_ASBR_OFF(); |
2165 | return CMD_SUCCESS; | |
508e53e2 | 2166 | } |
2167 | ||
d62a17ae | 2168 | int config_write_ospf6_debug_asbr(struct vty *vty) |
508e53e2 | 2169 | { |
d62a17ae | 2170 | if (IS_OSPF6_DEBUG_ASBR) |
2171 | vty_out(vty, "debug ospf6 asbr\n"); | |
2172 | return 0; | |
508e53e2 | 2173 | } |
2174 | ||
4d762f26 | 2175 | void install_element_ospf6_debug_asbr(void) |
92300491 | 2176 | { |
d62a17ae | 2177 | install_element(ENABLE_NODE, &debug_ospf6_asbr_cmd); |
2178 | install_element(ENABLE_NODE, &no_debug_ospf6_asbr_cmd); | |
2179 | install_element(CONFIG_NODE, &debug_ospf6_asbr_cmd); | |
2180 | install_element(CONFIG_NODE, &no_debug_ospf6_asbr_cmd); | |
92300491 | 2181 | } |