hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Area Border Router function. |
| 3 | * Copyright (C) 2004 Yasuhiro Ohara |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "log.h" |
| 26 | #include "prefix.h" |
| 27 | #include "table.h" |
| 28 | #include "vty.h" |
| 29 | #include "linklist.h" |
| 30 | #include "command.h" |
| 31 | |
| 32 | #include "ospf6_proto.h" |
| 33 | #include "ospf6_route.h" |
| 34 | #include "ospf6_lsa.h" |
| 35 | #include "ospf6_route.h" |
| 36 | #include "ospf6_lsdb.h" |
| 37 | #include "ospf6_top.h" |
| 38 | #include "ospf6_area.h" |
| 39 | #include "ospf6_interface.h" |
| 40 | #include "ospf6_abr.h" |
| 41 | #include "ospf6d.h" |
| 42 | |
| 43 | unsigned char conf_debug_ospf6_abr; |
| 44 | |
| 45 | /* RFC 2328 12.4.3. Summary-LSAs */ |
| 46 | void |
| 47 | ospf6_abr_originate_prefix_to_area (struct ospf6_route *route, |
| 48 | struct ospf6_area *area) |
| 49 | { |
| 50 | struct ospf6_lsa *lsa, *old = NULL; |
| 51 | struct ospf6_interface *oi; |
| 52 | struct ospf6_route *summary, *range = NULL; |
| 53 | struct ospf6_area *route_area; |
| 54 | char buffer[OSPF6_MAX_LSASIZE]; |
| 55 | struct ospf6_lsa_header *lsa_header; |
| 56 | caddr_t p; |
| 57 | struct ospf6_inter_prefix_lsa *prefix_lsa; |
| 58 | |
| 59 | summary = ospf6_route_lookup (&route->prefix, area->summary_table); |
| 60 | if (summary) |
| 61 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTER_PREFIX), |
| 62 | summary->path.origin.id, |
| 63 | area->ospf6->router_id, area->lsdb); |
| 64 | |
| 65 | /* if this route has just removed, remove corresponding LSA */ |
| 66 | if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE)) |
| 67 | { |
| 68 | if (old) |
| 69 | ospf6_lsa_premature_aging (old); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | /* Only destination type network and address range are considered */ |
| 74 | if (route->type != OSPF6_DEST_TYPE_NETWORK) |
| 75 | { |
| 76 | if (old) |
| 77 | ospf6_lsa_premature_aging (old); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | /* AS External routes are never considered */ |
| 82 | if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || |
| 83 | route->path.type == OSPF6_PATH_TYPE_EXTERNAL2) |
| 84 | { |
| 85 | if (old) |
| 86 | ospf6_lsa_premature_aging (old); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | /* do not generate if the route cost is greater or equal to LSInfinity */ |
| 91 | if (route->path.cost >= LS_INFINITY) |
| 92 | { |
| 93 | if (old) |
| 94 | ospf6_lsa_premature_aging (old); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | /* if this is an inter-area route */ |
| 99 | if (route->path.type == OSPF6_PATH_TYPE_INTRA) |
| 100 | { |
| 101 | /* search for configured address range for the route's area */ |
| 102 | route_area = ospf6_area_lookup (route->path.area_id, area->ospf6); |
| 103 | assert (route_area); |
| 104 | range = ospf6_route_lookup_bestmatch (&route->prefix, |
| 105 | route_area->summary_table); |
| 106 | } |
| 107 | |
| 108 | /* ranges are ignored when originate backbone routes to transit area. |
| 109 | Otherwise, if ranges are configured, the route is suppressed. */ |
| 110 | if (range && (route->path.area_id != htonl (0) || ! area->transit_capability)) |
| 111 | { |
| 112 | if (old) |
| 113 | ospf6_lsa_premature_aging (old); |
| 114 | if (range->path.cost < route->path.cost) |
| 115 | range->path.cost = route->path.cost; |
| 116 | SET_FLAG (range->flag, OSPF6_ROUTE_HAVE_LONGER); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | /* do not generate if the path's area is the same as target area */ |
| 121 | if (route->path.area_id == area->area_id) |
| 122 | { |
| 123 | if (old) |
| 124 | ospf6_lsa_premature_aging (old); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | /* do not generate if the nexthops belongs to the target area */ |
| 129 | oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex); |
| 130 | if (oi && oi->area && oi->area->area_id == area->area_id) |
| 131 | { |
| 132 | if (old) |
| 133 | ospf6_lsa_premature_aging (old); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | /* the route is going to be originated. store it in area's summary_table */ |
| 138 | if (summary == NULL) |
| 139 | { |
| 140 | summary = ospf6_route_copy (route); |
| 141 | summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX); |
| 142 | summary->path.origin.adv_router = area->ospf6->router_id; |
| 143 | summary->path.origin.id = |
| 144 | ospf6_new_ls_id (summary->path.origin.type, |
| 145 | summary->path.origin.adv_router, area->lsdb); |
| 146 | ospf6_route_add (summary, area->summary_table); |
| 147 | } |
| 148 | |
| 149 | /* prepare buffer */ |
| 150 | memset (buffer, 0, sizeof (buffer)); |
| 151 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 152 | prefix_lsa = (struct ospf6_inter_prefix_lsa *) |
| 153 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 154 | p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa); |
| 155 | |
| 156 | /* Fill Inter-Area-Prefix-LSA */ |
| 157 | OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost); |
| 158 | |
| 159 | /* prefixlen */ |
| 160 | prefix_lsa->prefix.prefix_length = route->prefix.prefixlen; |
| 161 | |
| 162 | /* PrefixOptions */ |
| 163 | prefix_lsa->prefix.prefix_options = route->path.prefix_options; |
| 164 | |
| 165 | /* set Prefix */ |
| 166 | memcpy (p, &route->prefix.u.prefix6, |
| 167 | OSPF6_PREFIX_SPACE (route->prefix.prefixlen)); |
| 168 | ospf6_prefix_apply_mask (&prefix_lsa->prefix); |
| 169 | p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen); |
| 170 | |
| 171 | /* Fill LSA Header */ |
| 172 | lsa_header->age = 0; |
| 173 | lsa_header->type = htons (OSPF6_LSTYPE_INTER_PREFIX); |
| 174 | lsa_header->id = summary->path.origin.id; |
| 175 | lsa_header->adv_router = area->ospf6->router_id; |
| 176 | lsa_header->seqnum = |
| 177 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 178 | lsa_header->adv_router, area->lsdb); |
| 179 | lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header); |
| 180 | |
| 181 | /* LSA checksum */ |
| 182 | ospf6_lsa_checksum (lsa_header); |
| 183 | |
| 184 | /* create LSA */ |
| 185 | lsa = ospf6_lsa_create (lsa_header); |
| 186 | lsa->scope = area; |
| 187 | SET_FLAG (lsa->flag, OSPF6_LSA_REFRESH); /* XXX */ |
| 188 | |
| 189 | /* Originate */ |
| 190 | ospf6_lsa_originate (lsa); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | ospf6_abr_originate_prefix (struct ospf6_route *route, struct ospf6 *o) |
| 195 | { |
| 196 | listnode node; |
| 197 | struct ospf6_area *oa; |
| 198 | |
| 199 | for (node = listhead (o->area_list); node; nextnode (node)) |
| 200 | { |
| 201 | oa = (struct ospf6_area *) getdata (node); |
| 202 | ospf6_abr_originate_prefix_to_area (route, oa); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /* RFC 2328 16.2. Calculating the inter-area routes */ |
| 207 | void |
| 208 | ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa) |
| 209 | { |
| 210 | struct prefix prefix, abr_prefix; |
| 211 | struct ospf6_route_table *table = NULL; |
| 212 | struct ospf6_route *range, *route, *old = NULL; |
| 213 | struct ospf6_route *abr_entry; |
| 214 | u_char type; |
| 215 | char options[3] = {0, 0, 0}; |
| 216 | u_int8_t prefix_options = 0; |
| 217 | u_int32_t cost = 0; |
| 218 | int i; |
| 219 | |
| 220 | if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX)) |
| 221 | { |
| 222 | struct ospf6_inter_prefix_lsa *prefix_lsa; |
| 223 | prefix_lsa = (struct ospf6_inter_prefix_lsa *) |
| 224 | OSPF6_LSA_HEADER_END (lsa->header); |
| 225 | prefix.family = AF_INET6; |
| 226 | prefix.prefixlen = prefix_lsa->prefix.prefix_length; |
| 227 | ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix); |
| 228 | table = oa->ospf6->route_table; |
| 229 | type = OSPF6_DEST_TYPE_NETWORK; |
| 230 | prefix_options = prefix_lsa->prefix.prefix_options; |
| 231 | cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa); |
| 232 | } |
| 233 | else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER)) |
| 234 | { |
| 235 | struct ospf6_inter_router_lsa *router_lsa; |
| 236 | router_lsa = (struct ospf6_inter_router_lsa *) |
| 237 | OSPF6_LSA_HEADER_END (lsa->header); |
| 238 | ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix); |
| 239 | table = oa->ospf6->brouter_table; |
| 240 | type = OSPF6_DEST_TYPE_ROUTER; |
| 241 | options[0] = router_lsa->options[0]; |
| 242 | options[1] = router_lsa->options[1]; |
| 243 | options[2] = router_lsa->options[2]; |
| 244 | cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa); |
| 245 | } |
| 246 | else |
| 247 | assert (0); |
| 248 | |
| 249 | for (route = ospf6_route_lookup (&prefix, table); |
| 250 | route && ospf6_route_is_prefix (&prefix, route); |
| 251 | route = ospf6_route_next (route)) |
| 252 | { |
| 253 | if (route->path.area_id == oa->area_id && |
| 254 | route->path.origin.type == lsa->header->type && |
| 255 | route->path.origin.id == lsa->header->id && |
| 256 | route->path.origin.adv_router == lsa->header->adv_router) |
| 257 | old = route; |
| 258 | } |
| 259 | |
| 260 | /* (1) if cost == LSInfinity or if the LSA is MaxAge */ |
| 261 | if (cost == LS_INFINITY || OSPF6_LSA_IS_MAXAGE (lsa)) |
| 262 | { |
| 263 | if (old) |
| 264 | ospf6_route_remove (old, oa->ospf6->route_table); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | /* (2) if the LSA is self-originated, ignore */ |
| 269 | if (lsa->header->adv_router == oa->ospf6->router_id) |
| 270 | { |
| 271 | if (old) |
| 272 | ospf6_route_remove (old, oa->ospf6->route_table); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | /* (3) if the prefix is equal to an active configured address range */ |
| 277 | range = ospf6_route_lookup (&prefix, oa->summary_table); |
| 278 | if (range && CHECK_FLAG (range->flag, OSPF6_ROUTE_HAVE_LONGER)) |
| 279 | { |
| 280 | if (old) |
| 281 | ospf6_route_remove (old, oa->ospf6->route_table); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | /* (4) if the routing table entry for the ABR does not exist */ |
| 286 | ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix); |
| 287 | abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table); |
| 288 | if (abr_entry == NULL) |
| 289 | { |
| 290 | if (old) |
| 291 | ospf6_route_remove (old, oa->ospf6->route_table); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | /* (5),(6),(7) the path preference is handled by the sorting |
| 296 | in the routing table. Always install the path by substituting |
| 297 | old route (if any). */ |
| 298 | if (old) |
| 299 | route = old; |
| 300 | else |
| 301 | route = ospf6_route_create (); |
| 302 | |
| 303 | route->type = type; |
| 304 | route->prefix = prefix; |
| 305 | route->path.origin.type = lsa->header->type; |
| 306 | route->path.origin.id = lsa->header->id; |
| 307 | route->path.origin.adv_router = lsa->header->adv_router; |
| 308 | route->path.options[0] = options[0]; |
| 309 | route->path.options[1] = options[1]; |
| 310 | route->path.options[2] = options[2]; |
| 311 | route->path.prefix_options = prefix_options; |
| 312 | route->path.area_id = oa->area_id; |
| 313 | route->path.type = OSPF6_PATH_TYPE_INTER; |
| 314 | route->path.cost = abr_entry->path.cost + cost; |
| 315 | for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 316 | route->nexthop[i] = abr_entry->nexthop[i]; |
| 317 | |
| 318 | ospf6_route_add (route, table); |
| 319 | } |
| 320 | |
| 321 | int |
| 322 | dummy (struct ospf6_lsa *lsa) |
| 323 | { |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* Display functions */ |
| 328 | int |
| 329 | ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 330 | { |
| 331 | struct ospf6_inter_prefix_lsa *prefix_lsa; |
| 332 | struct in6_addr in6; |
| 333 | char buf[64]; |
| 334 | |
| 335 | prefix_lsa = (struct ospf6_inter_prefix_lsa *) |
| 336 | OSPF6_LSA_HEADER_END (lsa->header); |
| 337 | |
| 338 | vty_out (vty, " Metric: %lu%s", |
| 339 | (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL); |
| 340 | |
| 341 | ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options, |
| 342 | buf, sizeof (buf)); |
| 343 | vty_out (vty, " Prefix Options: %s%s", buf, VNL); |
| 344 | |
| 345 | ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix); |
| 346 | inet_ntop (AF_INET6, &in6, buf, sizeof (buf)); |
| 347 | vty_out (vty, " Prefix: %s/%d%s", buf, |
| 348 | prefix_lsa->prefix.prefix_length, VNL); |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | int |
| 354 | ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 355 | { |
| 356 | struct ospf6_inter_router_lsa *router_lsa; |
| 357 | char buf[64]; |
| 358 | |
| 359 | router_lsa = (struct ospf6_inter_router_lsa *) |
| 360 | OSPF6_LSA_HEADER_END (lsa->header); |
| 361 | |
| 362 | ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf)); |
| 363 | vty_out (vty, " Options: %s%s", buf, VNL); |
| 364 | vty_out (vty, " Metric: %lu%s", |
| 365 | (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL); |
| 366 | inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf)); |
| 367 | vty_out (vty, " Destination Router ID: %s%s", buf, VNL); |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* Debug commands */ |
| 373 | DEFUN (debug_ospf6_abr, |
| 374 | debug_ospf6_abr_cmd, |
| 375 | "debug ospf6 abr", |
| 376 | DEBUG_STR |
| 377 | OSPF6_STR |
| 378 | "Debug OSPFv3 ABR function\n" |
| 379 | ) |
| 380 | { |
| 381 | OSPF6_DEBUG_ABR_ON (); |
| 382 | return CMD_SUCCESS; |
| 383 | } |
| 384 | |
| 385 | DEFUN (no_debug_ospf6_abr, |
| 386 | no_debug_ospf6_abr_cmd, |
| 387 | "no debug ospf6 abr", |
| 388 | NO_STR |
| 389 | DEBUG_STR |
| 390 | OSPF6_STR |
| 391 | "Debug OSPFv3 ABR function\n" |
| 392 | ) |
| 393 | { |
| 394 | OSPF6_DEBUG_ABR_OFF (); |
| 395 | return CMD_SUCCESS; |
| 396 | } |
| 397 | |
| 398 | int |
| 399 | config_write_ospf6_debug_abr (struct vty *vty) |
| 400 | { |
| 401 | if (IS_OSPF6_DEBUG_ABR) |
| 402 | vty_out (vty, "debug ospf6 abr%s", VNL); |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | void |
| 407 | install_element_ospf6_debug_abr () |
| 408 | { |
| 409 | install_element (ENABLE_NODE, &debug_ospf6_abr_cmd); |
| 410 | install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd); |
| 411 | install_element (CONFIG_NODE, &debug_ospf6_abr_cmd); |
| 412 | install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd); |
| 413 | } |
| 414 | |
| 415 | void |
| 416 | ospf6_abr_init () |
| 417 | { |
| 418 | ospf6_lstype[3].name = "Inter-Area-Prefix-LSA"; |
| 419 | ospf6_lstype[3].reoriginate = dummy; |
| 420 | ospf6_lstype[3].show = ospf6_inter_area_prefix_lsa_show; |
| 421 | ospf6_lstype[4].name = "Inter-Area-Router-LSA"; |
| 422 | ospf6_lstype[4].reoriginate = dummy; |
| 423 | ospf6_lstype[4].show = ospf6_inter_area_router_lsa_show; |
| 424 | } |
| 425 | |
| 426 | |