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