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