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