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