blob: 265a178b02b64940dce3b7338d96529f371709c9 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
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"
hasso508e53e2004-05-18 18:57:06 +000033#include "linklist.h"
paul718e3742002-12-13 20:15:29 +000034
paul718e3742002-12-13 20:15:29 +000035#include "ospf6_proto.h"
hasso508e53e2004-05-18 18:57:06 +000036#include "ospf6_lsa.h"
37#include "ospf6_lsdb.h"
38#include "ospf6_route.h"
39#include "ospf6_zebra.h"
hasso6452df02004-08-15 05:52:07 +000040#include "ospf6_message.h"
41
hasso508e53e2004-05-18 18:57:06 +000042#include "ospf6_top.h"
43#include "ospf6_area.h"
hasso6452df02004-08-15 05:52:07 +000044#include "ospf6_interface.h"
45#include "ospf6_neighbor.h"
hasso508e53e2004-05-18 18:57:06 +000046#include "ospf6_asbr.h"
47#include "ospf6_intra.h"
hasso6452df02004-08-15 05:52:07 +000048#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000049#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000050
hasso508e53e2004-05-18 18:57:06 +000051unsigned char conf_debug_ospf6_asbr = 0;
paul718e3742002-12-13 20:15:29 +000052
ajsf52d13c2005-10-01 17:38:06 +000053#define ZROUTE_NAME(x) zebra_route_string(x)
hasso508e53e2004-05-18 18:57:06 +000054
55/* AS External LSA origination */
Paul Jakma6ac29a52008-08-15 13:45:30 +010056static void
hasso6452df02004-08-15 05:52:07 +000057ospf6_as_external_lsa_originate (struct ospf6_route *route)
paul718e3742002-12-13 20:15:29 +000058{
hasso508e53e2004-05-18 18:57:06 +000059 char buffer[OSPF6_MAX_LSASIZE];
60 struct ospf6_lsa_header *lsa_header;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010061 struct ospf6_lsa *lsa;
Paul Jakma0b26f812006-05-15 10:47:53 +000062 struct ospf6_external_info *info = route->route_option;
paul718e3742002-12-13 20:15:29 +000063
hasso508e53e2004-05-18 18:57:06 +000064 struct ospf6_as_external_lsa *as_external_lsa;
65 char buf[64];
66 caddr_t p;
paul718e3742002-12-13 20:15:29 +000067
hasso1e058382004-09-01 21:36:14 +000068 if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +000069 {
70 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +000071 zlog_debug ("Originate AS-External-LSA for %s", buf);
hasso508e53e2004-05-18 18:57:06 +000072 }
73
74 /* prepare buffer */
75 memset (buffer, 0, sizeof (buffer));
76 lsa_header = (struct ospf6_lsa_header *) buffer;
77 as_external_lsa = (struct ospf6_as_external_lsa *)
78 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
79 p = (caddr_t)
80 ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa));
81
82 /* Fill AS-External-LSA */
83 /* Metric type */
84 if (route->path.metric_type == 2)
85 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
86 else
87 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
88
89 /* forwarding address */
Paul Jakma0b26f812006-05-15 10:47:53 +000090 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
hasso508e53e2004-05-18 18:57:06 +000091 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
92 else
93 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
94
95 /* external route tag */
96 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
97
98 /* Set metric */
99 OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost);
100
101 /* prefixlen */
102 as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
103
104 /* PrefixOptions */
105 as_external_lsa->prefix.prefix_options = route->path.prefix_options;
106
107 /* don't use refer LS-type */
108 as_external_lsa->prefix.prefix_refer_lstype = htons (0);
109
110 /* set Prefix */
111 memcpy (p, &route->prefix.u.prefix6,
112 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
113 ospf6_prefix_apply_mask (&as_external_lsa->prefix);
114 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
115
116 /* Forwarding address */
117 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
118 {
Paul Jakma0b26f812006-05-15 10:47:53 +0000119 memcpy (p, &info->forwarding, sizeof (struct in6_addr));
hasso508e53e2004-05-18 18:57:06 +0000120 p += sizeof (struct in6_addr);
121 }
122
123 /* External Route Tag */
124 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
125 {
126 /* xxx */
127 }
128
129 /* Fill LSA Header */
130 lsa_header->age = 0;
131 lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
hasso6452df02004-08-15 05:52:07 +0000132 lsa_header->id = route->path.origin.id;
hasso508e53e2004-05-18 18:57:06 +0000133 lsa_header->adv_router = ospf6->router_id;
134 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000135 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
136 lsa_header->adv_router, ospf6->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000137 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
138
139 /* LSA checksum */
140 ospf6_lsa_checksum (lsa_header);
141
142 /* create LSA */
143 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000144
145 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000146 ospf6_lsa_originate_process (lsa, ospf6);
hasso508e53e2004-05-18 18:57:06 +0000147}
148
David Lamparter6b0655a2014-06-04 06:53:35 +0200149
hasso508e53e2004-05-18 18:57:06 +0000150void
151ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
152{
153 struct ospf6_as_external_lsa *external;
154 struct prefix asbr_id;
155 struct ospf6_route *asbr_entry, *route;
156 char buf[64];
157 int i;
158
159 external = (struct ospf6_as_external_lsa *)
160 OSPF6_LSA_HEADER_END (lsa->header);
161
hasso1e058382004-09-01 21:36:14 +0000162 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000163 zlog_debug ("Calculate AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000164
165 if (lsa->header->adv_router == ospf6->router_id)
166 {
hasso1e058382004-09-01 21:36:14 +0000167 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000168 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000169 return;
170 }
171
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700172 if (OSPF6_ASBR_METRIC (external) == OSPF_LS_INFINITY)
hasso508e53e2004-05-18 18:57:06 +0000173 {
hasso1e058382004-09-01 21:36:14 +0000174 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000175 zlog_debug ("Ignore LSA with LSInfinity Metric");
hasso508e53e2004-05-18 18:57:06 +0000176 return;
177 }
178
Dinesh Dutt01879112013-08-25 03:03:31 +0000179 if (CHECK_FLAG(external->prefix.prefix_options, OSPF6_PREFIX_OPTION_NU))
180 {
181 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
182 zlog_debug ("Ignore LSA with NU bit set Metric");
183 return;
184 }
185
hassoccb59b12004-08-25 09:10:37 +0000186 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
hasso6452df02004-08-15 05:52:07 +0000187 asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
hasso63069ad2004-09-02 13:01:01 +0000188 if (asbr_entry == NULL ||
189 ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
hasso508e53e2004-05-18 18:57:06 +0000190 {
hasso1e058382004-09-01 21:36:14 +0000191 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000192 {
193 prefix2str (&asbr_id, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000194 zlog_debug ("ASBR entry not found: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000195 }
196 return;
197 }
198
199 route = ospf6_route_create ();
200 route->type = OSPF6_DEST_TYPE_NETWORK;
201 route->prefix.family = AF_INET6;
202 route->prefix.prefixlen = external->prefix.prefix_length;
203 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
204
205 route->path.area_id = asbr_entry->path.area_id;
206 route->path.origin.type = lsa->header->type;
207 route->path.origin.id = lsa->header->id;
208 route->path.origin.adv_router = lsa->header->adv_router;
209
210 route->path.prefix_options = external->prefix.prefix_options;
211 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
212 {
213 route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
214 route->path.metric_type = 2;
215 route->path.cost = asbr_entry->path.cost;
216 route->path.cost_e2 = OSPF6_ASBR_METRIC (external);
217 }
218 else
219 {
220 route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
221 route->path.metric_type = 1;
222 route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
223 route->path.cost_e2 = 0;
224 }
225
226 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
227 ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]);
228
hasso1e058382004-09-01 21:36:14 +0000229 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000230 {
231 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000232 zlog_debug ("AS-External route add: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000233 }
234
235 ospf6_route_add (route, ospf6->route_table);
236}
237
238void
239ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
240{
241 struct ospf6_as_external_lsa *external;
242 struct prefix prefix;
243 struct ospf6_route *route;
244 char buf[64];
245
246 external = (struct ospf6_as_external_lsa *)
247 OSPF6_LSA_HEADER_END (lsa->header);
248
hasso1e058382004-09-01 21:36:14 +0000249 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000250 zlog_debug ("Withdraw AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000251
252 if (lsa->header->adv_router == ospf6->router_id)
253 {
hasso1e058382004-09-01 21:36:14 +0000254 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000255 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000256 return;
257 }
258
259 memset (&prefix, 0, sizeof (struct prefix));
260 prefix.family = AF_INET6;
261 prefix.prefixlen = external->prefix.prefix_length;
262 ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
263
264 route = ospf6_route_lookup (&prefix, ospf6->route_table);
265 if (route == NULL)
266 {
hasso1e058382004-09-01 21:36:14 +0000267 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000268 {
269 prefix2str (&prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000270 zlog_debug ("AS-External route %s not found", buf);
hasso508e53e2004-05-18 18:57:06 +0000271 }
272 return;
273 }
274
275 for (ospf6_route_lock (route);
276 route && ospf6_route_is_prefix (&prefix, route);
277 route = ospf6_route_next (route))
278 {
279 if (route->type != OSPF6_DEST_TYPE_NETWORK)
280 continue;
281 if (route->path.origin.type != lsa->header->type)
282 continue;
283 if (route->path.origin.id != lsa->header->id)
284 continue;
285 if (route->path.origin.adv_router != lsa->header->adv_router)
286 continue;
287
hasso1e058382004-09-01 21:36:14 +0000288 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000289 {
290 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000291 zlog_debug ("AS-External route remove: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000292 }
293 ospf6_route_remove (route, ospf6->route_table);
294 }
Christian Frankec78a46c2013-03-20 10:50:09 +0000295 if (route != NULL)
296 ospf6_route_unlock (route);
hasso508e53e2004-05-18 18:57:06 +0000297}
298
299void
300ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
301{
hasso508e53e2004-05-18 18:57:06 +0000302 struct ospf6_lsa *lsa;
303 u_int16_t type;
304 u_int32_t router;
305
Paul Jakmacb4b8842006-05-15 10:39:30 +0000306 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
hasso508e53e2004-05-18 18:57:06 +0000307 {
Paul Jakmacb4b8842006-05-15 10:39:30 +0000308 char buf[16];
309 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
310 buf, sizeof (buf));
311 zlog_info ("ignore non-best path: lsentry %s add", buf);
312 return;
hasso508e53e2004-05-18 18:57:06 +0000313 }
314
315 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
316 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
Paul Jakmacb4b8842006-05-15 10:39:30 +0000317 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
318 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
hasso508e53e2004-05-18 18:57:06 +0000319 {
320 if (! OSPF6_LSA_IS_MAXAGE (lsa))
321 ospf6_asbr_lsa_add (lsa);
322 }
hasso508e53e2004-05-18 18:57:06 +0000323}
324
325void
326ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
327{
hasso508e53e2004-05-18 18:57:06 +0000328 struct ospf6_lsa *lsa;
329 u_int16_t type;
330 u_int32_t router;
331
hasso508e53e2004-05-18 18:57:06 +0000332 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
333 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
334 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
335 lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
336 ospf6_asbr_lsa_remove (lsa);
hasso508e53e2004-05-18 18:57:06 +0000337}
338
339
David Lamparter6b0655a2014-06-04 06:53:35 +0200340
paul718e3742002-12-13 20:15:29 +0000341/* redistribute function */
hasso508e53e2004-05-18 18:57:06 +0000342
Paul Jakma6ac29a52008-08-15 13:45:30 +0100343static void
paul0c083ee2004-10-10 12:54:58 +0000344ospf6_asbr_routemap_set (int type, const char *mapname)
paul718e3742002-12-13 20:15:29 +0000345{
hasso508e53e2004-05-18 18:57:06 +0000346 if (ospf6->rmap[type].name)
347 free (ospf6->rmap[type].name);
348 ospf6->rmap[type].name = strdup (mapname);
349 ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
paul718e3742002-12-13 20:15:29 +0000350}
351
Paul Jakma6ac29a52008-08-15 13:45:30 +0100352static void
paul718e3742002-12-13 20:15:29 +0000353ospf6_asbr_routemap_unset (int type)
354{
hasso508e53e2004-05-18 18:57:06 +0000355 if (ospf6->rmap[type].name)
356 free (ospf6->rmap[type].name);
357 ospf6->rmap[type].name = NULL;
358 ospf6->rmap[type].map = NULL;
paul718e3742002-12-13 20:15:29 +0000359}
360
Paul Jakma6ac29a52008-08-15 13:45:30 +0100361static void
paul0c083ee2004-10-10 12:54:58 +0000362ospf6_asbr_routemap_update (const char *mapname)
paul718e3742002-12-13 20:15:29 +0000363{
hasso508e53e2004-05-18 18:57:06 +0000364 int type;
365
366 if (ospf6 == NULL)
367 return;
368
369 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000370 {
hasso508e53e2004-05-18 18:57:06 +0000371 if (ospf6->rmap[type].name)
372 ospf6->rmap[type].map =
373 route_map_lookup_by_name (ospf6->rmap[type].name);
paul718e3742002-12-13 20:15:29 +0000374 else
hasso508e53e2004-05-18 18:57:06 +0000375 ospf6->rmap[type].map = NULL;
376 }
377}
378
379int
380ospf6_asbr_is_asbr (struct ospf6 *o)
381{
382 return o->external_table->count;
383}
384
Paul Jakma6ac29a52008-08-15 13:45:30 +0100385static void
hasso508e53e2004-05-18 18:57:06 +0000386ospf6_asbr_redistribute_set (int type)
387{
388 ospf6_zebra_redistribute (type);
389}
390
Paul Jakma6ac29a52008-08-15 13:45:30 +0100391static void
hasso508e53e2004-05-18 18:57:06 +0000392ospf6_asbr_redistribute_unset (int type)
393{
394 struct ospf6_route *route;
395 struct ospf6_external_info *info;
396
397 ospf6_zebra_no_redistribute (type);
398
399 for (route = ospf6_route_head (ospf6->external_table); route;
400 route = ospf6_route_next (route))
401 {
402 info = route->route_option;
403 if (info->type != type)
404 continue;
405
406 ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex,
407 &route->prefix);
408 }
Christian Franked9628722013-03-08 21:47:35 +0100409
410 ospf6_asbr_routemap_unset (type);
hasso508e53e2004-05-18 18:57:06 +0000411}
412
413void
Paul Jakma9099f9b2016-01-18 10:12:10 +0000414ospf6_asbr_redistribute_add (int type, ifindex_t ifindex, struct prefix *prefix,
hasso508e53e2004-05-18 18:57:06 +0000415 u_int nexthop_num, struct in6_addr *nexthop)
416{
417 int ret;
418 struct ospf6_route troute;
419 struct ospf6_external_info tinfo;
420 struct ospf6_route *route, *match;
421 struct ospf6_external_info *info;
422 struct prefix prefix_id;
423 struct route_node *node;
424 char pbuf[64], ibuf[16];
paul1eb8ef22005-04-07 07:30:20 +0000425 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000426 struct ospf6_area *oa;
427
428 if (! ospf6_zebra_is_redistribute (type))
429 return;
430
431 if (IS_OSPF6_DEBUG_ASBR)
432 {
433 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000434 zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
hasso508e53e2004-05-18 18:57:06 +0000435 }
436
437 /* if route-map was specified but not found, do not advertise */
438 if (ospf6->rmap[type].name)
439 {
440 if (ospf6->rmap[type].map == NULL)
hasso03d52f82004-09-29 00:26:19 +0000441 ospf6_asbr_routemap_update (NULL);
hasso508e53e2004-05-18 18:57:06 +0000442 if (ospf6->rmap[type].map == NULL)
443 {
444 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
445 ospf6->rmap[type].name);
446 return;
447 }
448 }
449
450 /* apply route-map */
451 if (ospf6->rmap[type].map)
452 {
453 memset (&troute, 0, sizeof (troute));
454 memset (&tinfo, 0, sizeof (tinfo));
455 troute.route_option = &tinfo;
Vyacheslav Trushkin42a7deb2011-11-16 14:22:03 +0400456 tinfo.ifindex = ifindex;
hasso508e53e2004-05-18 18:57:06 +0000457
458 ret = route_map_apply (ospf6->rmap[type].map, prefix,
459 RMAP_OSPF6, &troute);
paul47828742005-08-10 15:46:11 +0000460 if (ret == RMAP_DENYMATCH)
hasso508e53e2004-05-18 18:57:06 +0000461 {
462 if (IS_OSPF6_DEBUG_ASBR)
hassoc6487d62004-12-24 06:00:11 +0000463 zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
hasso508e53e2004-05-18 18:57:06 +0000464 return;
465 }
466 }
467
468 match = ospf6_route_lookup (prefix, ospf6->external_table);
469 if (match)
470 {
471 info = match->route_option;
472
473 /* copy result of route-map */
474 if (ospf6->rmap[type].map)
475 {
476 if (troute.path.metric_type)
477 match->path.metric_type = troute.path.metric_type;
478 if (troute.path.cost)
479 match->path.cost = troute.path.cost;
480 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
481 memcpy (&info->forwarding, &tinfo.forwarding,
482 sizeof (struct in6_addr));
483 }
484
485 info->type = type;
486 match->nexthop[0].ifindex = ifindex;
487 if (nexthop_num && nexthop)
488 memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr));
489
490 /* create/update binding in external_id_table */
491 prefix_id.family = AF_INET;
492 prefix_id.prefixlen = 32;
493 prefix_id.u.prefix4.s_addr = htonl (info->id);
494 node = route_node_get (ospf6->external_id_table, &prefix_id);
495 node->info = match;
496
497 if (IS_OSPF6_DEBUG_ASBR)
498 {
499 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000500 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000501 }
502
hasso3b687352004-08-19 06:56:53 +0000503 match->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000504 ospf6_as_external_lsa_originate (match);
hasso508e53e2004-05-18 18:57:06 +0000505 return;
506 }
507
508 /* create new entry */
509 route = ospf6_route_create ();
510 route->type = OSPF6_DEST_TYPE_NETWORK;
511 memcpy (&route->prefix, prefix, sizeof (struct prefix));
512
513 info = (struct ospf6_external_info *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700514 XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
hasso508e53e2004-05-18 18:57:06 +0000515 route->route_option = info;
516 info->id = ospf6->external_id++;
517
518 /* copy result of route-map */
519 if (ospf6->rmap[type].map)
520 {
521 if (troute.path.metric_type)
522 route->path.metric_type = troute.path.metric_type;
523 if (troute.path.cost)
524 route->path.cost = troute.path.cost;
525 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
526 memcpy (&info->forwarding, &tinfo.forwarding,
527 sizeof (struct in6_addr));
528 }
529
530 info->type = type;
531 route->nexthop[0].ifindex = ifindex;
532 if (nexthop_num && nexthop)
533 memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr));
534
535 /* create/update binding in external_id_table */
536 prefix_id.family = AF_INET;
537 prefix_id.prefixlen = 32;
538 prefix_id.u.prefix4.s_addr = htonl (info->id);
539 node = route_node_get (ospf6->external_id_table, &prefix_id);
540 node->info = route;
541
542 route = ospf6_route_add (route, ospf6->external_table);
543 route->route_option = info;
544
545 if (IS_OSPF6_DEBUG_ASBR)
546 {
547 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000548 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000549 }
550
hasso3b687352004-08-19 06:56:53 +0000551 route->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000552 ospf6_as_external_lsa_originate (route);
hasso508e53e2004-05-18 18:57:06 +0000553
554 /* Router-Bit (ASBR Flag) may have to be updated */
paul1eb8ef22005-04-07 07:30:20 +0000555 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
556 OSPF6_ROUTER_LSA_SCHEDULE (oa);
hasso508e53e2004-05-18 18:57:06 +0000557}
558
559void
Paul Jakma9099f9b2016-01-18 10:12:10 +0000560ospf6_asbr_redistribute_remove (int type, ifindex_t ifindex,
561 struct prefix *prefix)
hasso508e53e2004-05-18 18:57:06 +0000562{
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];
paul1eb8ef22005-04-07 07:30:20 +0000569 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000570 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));
hassoc6487d62004-12-24 06:00:11 +0000578 zlog_debug ("No such route %s to withdraw", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000579 }
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));
hassoc6487d62004-12-24 06:00:11 +0000591 zlog_debug ("Original protocol mismatch: %s", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000592 }
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));
hassoc6487d62004-12-24 06:00:11 +0000600 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
hasso508e53e2004-05-18 18:57:06 +0000601 }
602
603 lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
604 htonl (info->id), ospf6->router_id, ospf6->lsdb);
605 if (lsa)
hasso6452df02004-08-15 05:52:07 +0000606 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000607
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 */
paul1eb8ef22005-04-07 07:30:20 +0000621 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
622 OSPF6_ROUTER_LSA_SCHEDULE (oa);
paul718e3742002-12-13 20:15:29 +0000623}
624
625DEFUN (ospf6_redistribute,
626 ospf6_redistribute_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200627 "redistribute " QUAGGA_REDIST_STR_OSPF6D,
paul718e3742002-12-13 20:15:29 +0000628 "Redistribute\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200629 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000630 )
631{
David Lampartere0ca5fd2009-09-16 01:52:42 +0200632 int type;
paul718e3742002-12-13 20:15:29 +0000633
David Lampartere0ca5fd2009-09-16 01:52:42 +0200634 type = proto_redistnum(AFI_IP6, argv[0]);
635 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
636 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000637
hasso508e53e2004-05-18 18:57:06 +0000638 ospf6_asbr_redistribute_unset (type);
hasso508e53e2004-05-18 18:57:06 +0000639 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000640 return CMD_SUCCESS;
641}
642
643DEFUN (ospf6_redistribute_routemap,
644 ospf6_redistribute_routemap_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200645 "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000646 "Redistribute\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200647 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000648 "Route map reference\n"
649 "Route map name\n"
650 )
651{
David Lampartere0ca5fd2009-09-16 01:52:42 +0200652 int type;
paul718e3742002-12-13 20:15:29 +0000653
David Lampartere0ca5fd2009-09-16 01:52:42 +0200654 type = proto_redistnum(AFI_IP6, argv[0]);
655 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
656 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000657
hasso508e53e2004-05-18 18:57:06 +0000658 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000659 ospf6_asbr_routemap_set (type, argv[1]);
hasso508e53e2004-05-18 18:57:06 +0000660 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000661 return CMD_SUCCESS;
662}
663
664DEFUN (no_ospf6_redistribute,
665 no_ospf6_redistribute_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200666 "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
paul718e3742002-12-13 20:15:29 +0000667 NO_STR
668 "Redistribute\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200669 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000670 )
671{
David Lampartere0ca5fd2009-09-16 01:52:42 +0200672 int type;
paul718e3742002-12-13 20:15:29 +0000673
David Lampartere0ca5fd2009-09-16 01:52:42 +0200674 type = proto_redistnum(AFI_IP6, argv[0]);
675 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
676 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000677
hasso508e53e2004-05-18 18:57:06 +0000678 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000679
paul718e3742002-12-13 20:15:29 +0000680 return CMD_SUCCESS;
681}
682
paul718e3742002-12-13 20:15:29 +0000683int
684ospf6_redistribute_config_write (struct vty *vty)
685{
hasso508e53e2004-05-18 18:57:06 +0000686 int type;
paul718e3742002-12-13 20:15:29 +0000687
hasso508e53e2004-05-18 18:57:06 +0000688 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000689 {
hasso508e53e2004-05-18 18:57:06 +0000690 if (type == ZEBRA_ROUTE_OSPF6)
691 continue;
692 if (! ospf6_zebra_is_redistribute (type))
paul718e3742002-12-13 20:15:29 +0000693 continue;
694
hasso508e53e2004-05-18 18:57:06 +0000695 if (ospf6->rmap[type].name)
paul718e3742002-12-13 20:15:29 +0000696 vty_out (vty, " redistribute %s route-map %s%s",
hasso049207c2004-08-04 20:02:13 +0000697 ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
paul718e3742002-12-13 20:15:29 +0000698 else
699 vty_out (vty, " redistribute %s%s",
hasso049207c2004-08-04 20:02:13 +0000700 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000701 }
702
703 return 0;
704}
705
Paul Jakma6ac29a52008-08-15 13:45:30 +0100706static void
paul718e3742002-12-13 20:15:29 +0000707ospf6_redistribute_show_config (struct vty *vty)
708{
hasso508e53e2004-05-18 18:57:06 +0000709 int type;
710 int nroute[ZEBRA_ROUTE_MAX];
711 int total;
712 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +0000713 struct ospf6_external_info *info;
paul718e3742002-12-13 20:15:29 +0000714
hasso508e53e2004-05-18 18:57:06 +0000715 total = 0;
716 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
717 nroute[type] = 0;
718 for (route = ospf6_route_head (ospf6->external_table); route;
719 route = ospf6_route_next (route))
paul718e3742002-12-13 20:15:29 +0000720 {
hasso508e53e2004-05-18 18:57:06 +0000721 info = route->route_option;
722 nroute[info->type]++;
723 total++;
paul718e3742002-12-13 20:15:29 +0000724 }
725
hasso049207c2004-08-04 20:02:13 +0000726 vty_out (vty, "Redistributing External Routes from:%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000727 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000728 {
hasso508e53e2004-05-18 18:57:06 +0000729 if (type == ZEBRA_ROUTE_OSPF6)
730 continue;
731 if (! ospf6_zebra_is_redistribute (type))
hassoe26bbeb2003-05-25 21:39:29 +0000732 continue;
733
hasso508e53e2004-05-18 18:57:06 +0000734 if (ospf6->rmap[type].name)
735 vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
736 ZROUTE_NAME (type), ospf6->rmap[type].name,
737 (ospf6->rmap[type].map ? "" : " (not found !)"),
hasso049207c2004-08-04 20:02:13 +0000738 VNL);
paul718e3742002-12-13 20:15:29 +0000739 else
hasso508e53e2004-05-18 18:57:06 +0000740 vty_out (vty, " %d: %s%s", nroute[type],
hasso049207c2004-08-04 20:02:13 +0000741 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000742 }
hasso049207c2004-08-04 20:02:13 +0000743 vty_out (vty, "Total %d routes%s", total, VNL);
hasso508e53e2004-05-18 18:57:06 +0000744}
paul718e3742002-12-13 20:15:29 +0000745
paul718e3742002-12-13 20:15:29 +0000746
David Lamparter6b0655a2014-06-04 06:53:35 +0200747
hasso508e53e2004-05-18 18:57:06 +0000748/* Routemap Functions */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100749static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000750ospf6_routemap_rule_match_address_prefixlist (void *rule,
751 struct prefix *prefix,
752 route_map_object_t type,
753 void *object)
754{
755 struct prefix_list *plist;
paul718e3742002-12-13 20:15:29 +0000756
hasso508e53e2004-05-18 18:57:06 +0000757 if (type != RMAP_OSPF6)
758 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000759
hasso508e53e2004-05-18 18:57:06 +0000760 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
761 if (plist == NULL)
762 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000763
hasso508e53e2004-05-18 18:57:06 +0000764 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
765 RMAP_NOMATCH : RMAP_MATCH);
766}
paul718e3742002-12-13 20:15:29 +0000767
Paul Jakma6ac29a52008-08-15 13:45:30 +0100768static void *
paul0c083ee2004-10-10 12:54:58 +0000769ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000770{
771 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000772}
773
Paul Jakma6ac29a52008-08-15 13:45:30 +0100774static void
hasso508e53e2004-05-18 18:57:06 +0000775ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000776{
hasso508e53e2004-05-18 18:57:06 +0000777 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
778}
paul718e3742002-12-13 20:15:29 +0000779
hasso508e53e2004-05-18 18:57:06 +0000780struct route_map_rule_cmd
781ospf6_routemap_rule_match_address_prefixlist_cmd =
782{
783 "ipv6 address prefix-list",
784 ospf6_routemap_rule_match_address_prefixlist,
785 ospf6_routemap_rule_match_address_prefixlist_compile,
786 ospf6_routemap_rule_match_address_prefixlist_free,
787};
hassoe26bbeb2003-05-25 21:39:29 +0000788
Vyacheslav Trushkin42a7deb2011-11-16 14:22:03 +0400789/* `match interface IFNAME' */
790/* Match function should return 1 if match is success else return
791 zero. */
792static route_map_result_t
793ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix,
794 route_map_object_t type, void *object)
795{
796 struct interface *ifp;
797 struct ospf6_external_info *ei;
798
799 if (type == RMAP_OSPF6)
800 {
801 ei = ((struct ospf6_route *) object)->route_option;
802 ifp = if_lookup_by_name ((char *)rule);
803
804 if (ifp != NULL
805 && ei->ifindex == ifp->ifindex)
806 return RMAP_MATCH;
807 }
808
809 return RMAP_NOMATCH;
810}
811
812/* Route map `interface' match statement. `arg' should be
813 interface name. */
814static void *
815ospf6_routemap_rule_match_interface_compile (const char *arg)
816{
817 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
818}
819
820/* Free route map's compiled `interface' value. */
821static void
822ospf6_routemap_rule_match_interface_free (void *rule)
823{
824 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
825}
826
827/* Route map commands for interface matching. */
828struct route_map_rule_cmd
829ospf6_routemap_rule_match_interface_cmd =
830{
831 "interface",
832 ospf6_routemap_rule_match_interface,
833 ospf6_routemap_rule_match_interface_compile,
834 ospf6_routemap_rule_match_interface_free
835};
836
Paul Jakma6ac29a52008-08-15 13:45:30 +0100837static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000838ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
839 route_map_object_t type, void *object)
840{
841 char *metric_type = rule;
842 struct ospf6_route *route = object;
hassoe26bbeb2003-05-25 21:39:29 +0000843
hasso508e53e2004-05-18 18:57:06 +0000844 if (type != RMAP_OSPF6)
845 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000846
hasso508e53e2004-05-18 18:57:06 +0000847 if (strcmp (metric_type, "type-2") == 0)
848 route->path.metric_type = 2;
paul718e3742002-12-13 20:15:29 +0000849 else
hasso508e53e2004-05-18 18:57:06 +0000850 route->path.metric_type = 1;
paul718e3742002-12-13 20:15:29 +0000851
hasso508e53e2004-05-18 18:57:06 +0000852 return RMAP_OKAY;
853}
paul718e3742002-12-13 20:15:29 +0000854
Paul Jakma6ac29a52008-08-15 13:45:30 +0100855static void *
paul0c083ee2004-10-10 12:54:58 +0000856ospf6_routemap_rule_set_metric_type_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000857{
858 if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
859 return NULL;
860 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000861}
862
Paul Jakma6ac29a52008-08-15 13:45:30 +0100863static void
hasso508e53e2004-05-18 18:57:06 +0000864ospf6_routemap_rule_set_metric_type_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000865{
hasso508e53e2004-05-18 18:57:06 +0000866 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
867}
paul718e3742002-12-13 20:15:29 +0000868
hasso508e53e2004-05-18 18:57:06 +0000869struct route_map_rule_cmd
870ospf6_routemap_rule_set_metric_type_cmd =
871{
872 "metric-type",
873 ospf6_routemap_rule_set_metric_type,
874 ospf6_routemap_rule_set_metric_type_compile,
875 ospf6_routemap_rule_set_metric_type_free,
876};
paul718e3742002-12-13 20:15:29 +0000877
Paul Jakma6ac29a52008-08-15 13:45:30 +0100878static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000879ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
880 route_map_object_t type, void *object)
881{
882 char *metric = rule;
883 struct ospf6_route *route = object;
paul718e3742002-12-13 20:15:29 +0000884
hasso508e53e2004-05-18 18:57:06 +0000885 if (type != RMAP_OSPF6)
886 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000887
hasso508e53e2004-05-18 18:57:06 +0000888 route->path.cost = atoi (metric);
889 return RMAP_OKAY;
890}
paul718e3742002-12-13 20:15:29 +0000891
Paul Jakma6ac29a52008-08-15 13:45:30 +0100892static void *
paul0c083ee2004-10-10 12:54:58 +0000893ospf6_routemap_rule_set_metric_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000894{
895 u_int32_t metric;
896 char *endp;
897 metric = strtoul (arg, &endp, 0);
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700898 if (metric > OSPF_LS_INFINITY || *endp != '\0')
hasso508e53e2004-05-18 18:57:06 +0000899 return NULL;
900 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000901}
902
Paul Jakma6ac29a52008-08-15 13:45:30 +0100903static void
hasso508e53e2004-05-18 18:57:06 +0000904ospf6_routemap_rule_set_metric_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000905{
hasso508e53e2004-05-18 18:57:06 +0000906 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
907}
908
909struct route_map_rule_cmd
910ospf6_routemap_rule_set_metric_cmd =
911{
912 "metric",
913 ospf6_routemap_rule_set_metric,
914 ospf6_routemap_rule_set_metric_compile,
915 ospf6_routemap_rule_set_metric_free,
916};
917
Paul Jakma6ac29a52008-08-15 13:45:30 +0100918static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000919ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
920 route_map_object_t type, void *object)
921{
922 char *forwarding = rule;
923 struct ospf6_route *route = object;
924 struct ospf6_external_info *info = route->route_option;
925
926 if (type != RMAP_OSPF6)
927 return RMAP_OKAY;
928
929 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
930 {
931 memset (&info->forwarding, 0, sizeof (struct in6_addr));
932 return RMAP_ERROR;
933 }
934
935 return RMAP_OKAY;
936}
937
Paul Jakma6ac29a52008-08-15 13:45:30 +0100938static void *
paul0c083ee2004-10-10 12:54:58 +0000939ospf6_routemap_rule_set_forwarding_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000940{
941 struct in6_addr a;
942 if (inet_pton (AF_INET6, arg, &a) != 1)
943 return NULL;
944 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
945}
946
Paul Jakma6ac29a52008-08-15 13:45:30 +0100947static void
hasso508e53e2004-05-18 18:57:06 +0000948ospf6_routemap_rule_set_forwarding_free (void *rule)
949{
950 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
951}
952
953struct route_map_rule_cmd
954ospf6_routemap_rule_set_forwarding_cmd =
955{
956 "forwarding-address",
957 ospf6_routemap_rule_set_forwarding,
958 ospf6_routemap_rule_set_forwarding_compile,
959 ospf6_routemap_rule_set_forwarding_free,
960};
961
Paul Jakma6ac29a52008-08-15 13:45:30 +0100962static int
hasso508e53e2004-05-18 18:57:06 +0000963route_map_command_status (struct vty *vty, int ret)
964{
965 if (! ret)
966 return CMD_SUCCESS;
967
968 switch (ret)
969 {
970 case RMAP_RULE_MISSING:
hasso049207c2004-08-04 20:02:13 +0000971 vty_out (vty, "Can't find rule.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000972 break;
973 case RMAP_COMPILE_ERROR:
hasso049207c2004-08-04 20:02:13 +0000974 vty_out (vty, "Argument is malformed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000975 break;
976 default:
hasso049207c2004-08-04 20:02:13 +0000977 vty_out (vty, "route-map add set failed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000978 break;
979 }
980 return CMD_WARNING;
981}
982
983/* add "match address" */
984DEFUN (ospf6_routemap_match_address_prefixlist,
985 ospf6_routemap_match_address_prefixlist_cmd,
986 "match ipv6 address prefix-list WORD",
987 "Match values\n"
988 IPV6_STR
989 "Match address of route\n"
990 "Match entries of prefix-lists\n"
991 "IPv6 prefix-list name\n")
992{
993 int ret = route_map_add_match ((struct route_map_index *) vty->index,
994 "ipv6 address prefix-list", argv[0]);
995 return route_map_command_status (vty, ret);
996}
997
998/* delete "match address" */
999DEFUN (ospf6_routemap_no_match_address_prefixlist,
1000 ospf6_routemap_no_match_address_prefixlist_cmd,
1001 "no match ipv6 address prefix-list WORD",
1002 NO_STR
1003 "Match values\n"
1004 IPV6_STR
1005 "Match address of route\n"
1006 "Match entries of prefix-lists\n"
1007 "IPv6 prefix-list name\n")
1008{
1009 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
1010 "ipv6 address prefix-list", argv[0]);
1011 return route_map_command_status (vty, ret);
1012}
1013
Vyacheslav Trushkin42a7deb2011-11-16 14:22:03 +04001014/* "match interface" */
1015DEFUN (ospf6_routemap_match_interface,
1016 ospf6_routemap_match_interface_cmd,
1017 "match interface WORD",
1018 MATCH_STR
1019 "Match first hop interface of route\n"
1020 "Interface name\n")
1021{
1022 return route_map_add_match ((struct route_map_index *) vty->index,
1023 "interface", argv[0]);
1024}
1025
1026/* "no match interface WORD" */
1027DEFUN (ospf6_routemap_no_match_interface,
1028 ospf6_routemap_no_match_interface_cmd,
1029 "no match interface",
1030 MATCH_STR
1031 NO_STR
1032 "Match first hop interface of route\n")
1033{
1034 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
1035 "interface", (argc == 0) ? NULL : argv[0]);
1036 return route_map_command_status (vty, ret);
1037}
1038
1039ALIAS (ospf6_routemap_no_match_interface,
1040 ospf6_routemap_no_match_interface_val_cmd,
1041 "no match interface WORD",
1042 MATCH_STR
1043 NO_STR
1044 "Match first hop interface of route\n"
1045 "Interface name\n")
1046
hasso508e53e2004-05-18 18:57:06 +00001047/* add "set metric-type" */
1048DEFUN (ospf6_routemap_set_metric_type,
1049 ospf6_routemap_set_metric_type_cmd,
1050 "set metric-type (type-1|type-2)",
1051 "Set value\n"
1052 "Type of metric\n"
1053 "OSPF6 external type 1 metric\n"
1054 "OSPF6 external type 2 metric\n")
1055{
1056 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1057 "metric-type", argv[0]);
1058 return route_map_command_status (vty, ret);
1059}
1060
1061/* delete "set metric-type" */
1062DEFUN (ospf6_routemap_no_set_metric_type,
1063 ospf6_routemap_no_set_metric_type_cmd,
1064 "no set metric-type (type-1|type-2)",
1065 NO_STR
1066 "Set value\n"
1067 "Type of metric\n"
1068 "OSPF6 external type 1 metric\n"
1069 "OSPF6 external type 2 metric\n")
1070{
1071 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1072 "metric-type", argv[0]);
1073 return route_map_command_status (vty, ret);
1074}
1075
1076/* add "set metric" */
1077DEFUN (set_metric,
1078 set_metric_cmd,
1079 "set metric <0-4294967295>",
1080 "Set value\n"
1081 "Metric value\n"
1082 "Metric value\n")
1083{
1084 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1085 "metric", argv[0]);
1086 return route_map_command_status (vty, ret);
1087}
1088
1089/* delete "set metric" */
1090DEFUN (no_set_metric,
1091 no_set_metric_cmd,
Daniel Walton62f936e2015-11-09 20:21:59 -05001092 "no set metric",
hasso508e53e2004-05-18 18:57:06 +00001093 NO_STR
Daniel Walton62f936e2015-11-09 20:21:59 -05001094 SET_STR
1095 "Metric value for destination routing protocol\n")
hasso508e53e2004-05-18 18:57:06 +00001096{
Daniel Walton62f936e2015-11-09 20:21:59 -05001097 int ret = 0;
1098
1099 if (argc == 0)
1100 ret = route_map_delete_set ((struct route_map_index *) vty->index,
1101 "metric", NULL);
1102 else
1103 ret = route_map_delete_set ((struct route_map_index *) vty->index,
1104 "metric", argv[0]);
hasso508e53e2004-05-18 18:57:06 +00001105 return route_map_command_status (vty, ret);
1106}
1107
Daniel Walton62f936e2015-11-09 20:21:59 -05001108ALIAS (no_set_metric,
1109 no_set_metric_val_cmd,
1110 "no set metric <0-4294967295>",
1111 NO_STR
1112 SET_STR
1113 "Metric value for destination routing protocol\n"
1114 "Metric value\n")
1115
hasso508e53e2004-05-18 18:57:06 +00001116/* add "set forwarding-address" */
1117DEFUN (ospf6_routemap_set_forwarding,
1118 ospf6_routemap_set_forwarding_cmd,
1119 "set forwarding-address X:X::X:X",
1120 "Set value\n"
1121 "Forwarding Address\n"
1122 "IPv6 Address\n")
1123{
1124 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1125 "forwarding-address", argv[0]);
1126 return route_map_command_status (vty, ret);
1127}
1128
1129/* delete "set forwarding-address" */
1130DEFUN (ospf6_routemap_no_set_forwarding,
1131 ospf6_routemap_no_set_forwarding_cmd,
1132 "no set forwarding-address X:X::X:X",
1133 NO_STR
1134 "Set value\n"
1135 "Forwarding Address\n"
1136 "IPv6 Address\n")
1137{
1138 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1139 "forwarding-address", argv[0]);
1140 return route_map_command_status (vty, ret);
1141}
1142
Paul Jakma6ac29a52008-08-15 13:45:30 +01001143static void
1144ospf6_routemap_init (void)
hasso508e53e2004-05-18 18:57:06 +00001145{
1146 route_map_init ();
1147 route_map_init_vty ();
1148 route_map_add_hook (ospf6_asbr_routemap_update);
1149 route_map_delete_hook (ospf6_asbr_routemap_update);
1150
1151 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
Vyacheslav Trushkin42a7deb2011-11-16 14:22:03 +04001152 route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
1153
hasso508e53e2004-05-18 18:57:06 +00001154 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
1155 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
1156 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
1157
1158 /* Match address prefix-list */
1159 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
1160 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
1161
Vyacheslav Trushkin42a7deb2011-11-16 14:22:03 +04001162 /* Match interface */
1163 install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
1164 install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
1165 install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd);
1166
hasso508e53e2004-05-18 18:57:06 +00001167 /* ASE Metric Type (e.g. Type-1/Type-2) */
1168 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
1169 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
1170
1171 /* ASE Metric */
1172 install_element (RMAP_NODE, &set_metric_cmd);
1173 install_element (RMAP_NODE, &no_set_metric_cmd);
Daniel Walton62f936e2015-11-09 20:21:59 -05001174 install_element (RMAP_NODE, &no_set_metric_val_cmd);
hasso508e53e2004-05-18 18:57:06 +00001175
1176 /* ASE Metric */
1177 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
1178 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
1179}
1180
David Lamparter6b0655a2014-06-04 06:53:35 +02001181
hasso508e53e2004-05-18 18:57:06 +00001182/* Display functions */
Dinesh Dutte68a6762013-08-25 03:03:23 +00001183static char *
1184ospf6_as_external_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
1185 int buflen, int pos)
1186{
1187 struct ospf6_as_external_lsa *external;
1188 struct in6_addr in6;
1189 int prefix_length = 0;
1190
1191 if (lsa)
1192 {
1193 external = (struct ospf6_as_external_lsa *)
1194 OSPF6_LSA_HEADER_END (lsa->header);
1195
1196 if (pos == 0)
1197 {
1198 ospf6_prefix_in6_addr (&in6, &external->prefix);
1199 prefix_length = external->prefix.prefix_length;
1200 }
1201 else {
1202 in6 = *((struct in6_addr *)
1203 ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
1204 OSPF6_PREFIX_SPACE (external->prefix.prefix_length)));
1205 }
1206 if (buf)
1207 {
1208 inet_ntop (AF_INET6, &in6, buf, buflen);
1209 if (prefix_length)
1210 sprintf (&buf[strlen(buf)], "/%d", prefix_length);
1211 }
1212 }
1213 return (buf);
1214}
1215
Paul Jakma6ac29a52008-08-15 13:45:30 +01001216static int
hasso508e53e2004-05-18 18:57:06 +00001217ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
1218{
1219 struct ospf6_as_external_lsa *external;
paul718e3742002-12-13 20:15:29 +00001220 char buf[64];
paul718e3742002-12-13 20:15:29 +00001221
1222 assert (lsa->header);
hasso508e53e2004-05-18 18:57:06 +00001223 external = (struct ospf6_as_external_lsa *)
1224 OSPF6_LSA_HEADER_END (lsa->header);
paul718e3742002-12-13 20:15:29 +00001225
1226 /* bits */
hasso508e53e2004-05-18 18:57:06 +00001227 snprintf (buf, sizeof (buf), "%c%c%c",
1228 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
1229 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
1230 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
paul718e3742002-12-13 20:15:29 +00001231
hasso049207c2004-08-04 20:02:13 +00001232 vty_out (vty, " Bits: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +00001233 vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
hasso049207c2004-08-04 20:02:13 +00001234 VNL);
paul718e3742002-12-13 20:15:29 +00001235
hasso508e53e2004-05-18 18:57:06 +00001236 ospf6_prefix_options_printbuf (external->prefix.prefix_options,
1237 buf, sizeof (buf));
1238 vty_out (vty, " Prefix Options: %s%s", buf,
hasso049207c2004-08-04 20:02:13 +00001239 VNL);
paul718e3742002-12-13 20:15:29 +00001240
1241 vty_out (vty, " Referenced LSType: %d%s",
hasso508e53e2004-05-18 18:57:06 +00001242 ntohs (external->prefix.prefix_refer_lstype),
hasso049207c2004-08-04 20:02:13 +00001243 VNL);
paul718e3742002-12-13 20:15:29 +00001244
Dinesh Dutte68a6762013-08-25 03:03:23 +00001245 vty_out (vty, " Prefix: %s%s",
1246 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 0), VNL);
paul718e3742002-12-13 20:15:29 +00001247
1248 /* Forwarding-Address */
1249 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
1250 {
Dinesh Dutte68a6762013-08-25 03:03:23 +00001251 vty_out (vty, " Forwarding-Address: %s%s",
1252 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 1),
1253 VNL);
paul718e3742002-12-13 20:15:29 +00001254 }
1255
1256 return 0;
1257}
1258
Paul Jakma6ac29a52008-08-15 13:45:30 +01001259static void
hasso508e53e2004-05-18 18:57:06 +00001260ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
paul718e3742002-12-13 20:15:29 +00001261{
hasso508e53e2004-05-18 18:57:06 +00001262 struct ospf6_external_info *info = route->route_option;
1263 char prefix[64], id[16], forwarding[64];
1264 u_int32_t tmp_id;
1265
1266 prefix2str (&route->prefix, prefix, sizeof (prefix));
1267 tmp_id = ntohl (info->id);
1268 inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
1269 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
1270 inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
1271 else
1272 snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
1273 route->nexthop[0].ifindex);
1274
ajsf52d13c2005-10-01 17:38:06 +00001275 vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
1276 zebra_route_char(info->type),
hasso508e53e2004-05-18 18:57:06 +00001277 prefix, id, route->path.metric_type,
1278 (u_long) (route->path.metric_type == 2 ?
1279 route->path.cost_e2 : route->path.cost),
hasso049207c2004-08-04 20:02:13 +00001280 forwarding, VNL);
paul718e3742002-12-13 20:15:29 +00001281}
1282
hasso508e53e2004-05-18 18:57:06 +00001283DEFUN (show_ipv6_ospf6_redistribute,
1284 show_ipv6_ospf6_redistribute_cmd,
1285 "show ipv6 ospf6 redistribute",
paul718e3742002-12-13 20:15:29 +00001286 SHOW_STR
1287 IP6_STR
paul718e3742002-12-13 20:15:29 +00001288 OSPF6_STR
1289 "redistributing External information\n"
1290 )
1291{
hasso508e53e2004-05-18 18:57:06 +00001292 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +00001293
Vipin Kumarf972dec2015-05-19 18:03:41 -07001294 OSPF6_CMD_CHECK_RUNNING ();
1295
hasso508e53e2004-05-18 18:57:06 +00001296 ospf6_redistribute_show_config (vty);
1297
1298 for (route = ospf6_route_head (ospf6->external_table); route;
1299 route = ospf6_route_next (route))
1300 ospf6_asbr_external_route_show (vty, route);
1301
paul718e3742002-12-13 20:15:29 +00001302 return CMD_SUCCESS;
1303}
1304
hasso6452df02004-08-15 05:52:07 +00001305struct ospf6_lsa_handler as_external_handler =
hasso508e53e2004-05-18 18:57:06 +00001306{
hasso6452df02004-08-15 05:52:07 +00001307 OSPF6_LSTYPE_AS_EXTERNAL,
1308 "AS-External",
Dinesh Dutte68a6762013-08-25 03:03:23 +00001309 "ASE",
1310 ospf6_as_external_lsa_show,
1311 ospf6_as_external_lsa_get_prefix_str
hasso6452df02004-08-15 05:52:07 +00001312};
hasso508e53e2004-05-18 18:57:06 +00001313
paul718e3742002-12-13 20:15:29 +00001314void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001315ospf6_asbr_init (void)
paul718e3742002-12-13 20:15:29 +00001316{
hasso508e53e2004-05-18 18:57:06 +00001317 ospf6_routemap_init ();
paul718e3742002-12-13 20:15:29 +00001318
hasso6452df02004-08-15 05:52:07 +00001319 ospf6_install_lsa_handler (&as_external_handler);
paul718e3742002-12-13 20:15:29 +00001320
hasso508e53e2004-05-18 18:57:06 +00001321 install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
hasso508e53e2004-05-18 18:57:06 +00001322
paul718e3742002-12-13 20:15:29 +00001323 install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
1324 install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
1325 install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
1326}
1327
Tom Goffae2254a2010-11-10 13:01:41 -08001328void
Christian Franked9628722013-03-08 21:47:35 +01001329ospf6_asbr_redistribute_reset (void)
1330{
1331 int type;
1332
1333 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
1334 {
1335 if (type == ZEBRA_ROUTE_OSPF6)
1336 continue;
1337 if (ospf6_zebra_is_redistribute (type))
1338 ospf6_asbr_redistribute_unset(type);
1339 }
1340}
1341
1342void
Tom Goffae2254a2010-11-10 13:01:41 -08001343ospf6_asbr_terminate (void)
1344{
1345 route_map_finish ();
1346}
paul718e3742002-12-13 20:15:29 +00001347
hasso508e53e2004-05-18 18:57:06 +00001348DEFUN (debug_ospf6_asbr,
1349 debug_ospf6_asbr_cmd,
1350 "debug ospf6 asbr",
1351 DEBUG_STR
1352 OSPF6_STR
1353 "Debug OSPFv3 ASBR function\n"
1354 )
1355{
1356 OSPF6_DEBUG_ASBR_ON ();
1357 return CMD_SUCCESS;
1358}
1359
1360DEFUN (no_debug_ospf6_asbr,
1361 no_debug_ospf6_asbr_cmd,
1362 "no debug ospf6 asbr",
1363 NO_STR
1364 DEBUG_STR
1365 OSPF6_STR
1366 "Debug OSPFv3 ASBR function\n"
1367 )
1368{
1369 OSPF6_DEBUG_ASBR_OFF ();
1370 return CMD_SUCCESS;
1371}
1372
1373int
1374config_write_ospf6_debug_asbr (struct vty *vty)
1375{
1376 if (IS_OSPF6_DEBUG_ASBR)
hasso049207c2004-08-04 20:02:13 +00001377 vty_out (vty, "debug ospf6 asbr%s", VNL);
hasso508e53e2004-05-18 18:57:06 +00001378 return 0;
1379}
1380
1381void
1382install_element_ospf6_debug_asbr ()
1383{
1384 install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
1385 install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
1386 install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
1387 install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
1388}
1389
1390