blob: d1f5cba1c30527edae30f87a38ee8c9ee5988855 [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
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
paul718e3742002-12-13 20:15:29 +000023
hasso508e53e2004-05-18 18:57:06 +000024#include "memory.h"
paul718e3742002-12-13 20:15:29 +000025#include "if.h"
26#include "log.h"
27#include "command.h"
hasso508e53e2004-05-18 18:57:06 +000028#include "thread.h"
29#include "prefix.h"
30#include "plist.h"
paul718e3742002-12-13 20:15:29 +000031
hasso508e53e2004-05-18 18:57:06 +000032#include "ospf6_lsa.h"
paul718e3742002-12-13 20:15:29 +000033#include "ospf6_lsdb.h"
hasso508e53e2004-05-18 18:57:06 +000034#include "ospf6_network.h"
35#include "ospf6_message.h"
36#include "ospf6_route.h"
paul718e3742002-12-13 20:15:29 +000037#include "ospf6_top.h"
38#include "ospf6_area.h"
39#include "ospf6_interface.h"
hasso508e53e2004-05-18 18:57:06 +000040#include "ospf6_neighbor.h"
41#include "ospf6_intra.h"
42#include "ospf6_spf.h"
hasso049207c2004-08-04 20:02:13 +000043#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000044
hasso508e53e2004-05-18 18:57:06 +000045unsigned char conf_debug_ospf6_interface = 0;
46
paul0c083ee2004-10-10 12:54:58 +000047const char *ospf6_interface_state_str[] =
paul718e3742002-12-13 20:15:29 +000048{
hasso508e53e2004-05-18 18:57:06 +000049 "None",
50 "Down",
51 "Loopback",
52 "Waiting",
53 "PointToPoint",
54 "DROther",
55 "BDR",
56 "DR",
57 NULL
paul718e3742002-12-13 20:15:29 +000058};
59
hasso508e53e2004-05-18 18:57:06 +000060struct ospf6_interface *
61ospf6_interface_lookup_by_ifindex (int ifindex)
paul718e3742002-12-13 20:15:29 +000062{
hasso508e53e2004-05-18 18:57:06 +000063 struct ospf6_interface *oi;
64 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +000065
hasso508e53e2004-05-18 18:57:06 +000066 ifp = if_lookup_by_index (ifindex);
67 if (ifp == NULL)
68 return (struct ospf6_interface *) NULL;
69
70 oi = (struct ospf6_interface *) ifp->info;
71 return oi;
paul718e3742002-12-13 20:15:29 +000072}
73
hasso508e53e2004-05-18 18:57:06 +000074/* schedule routing table recalculation */
Paul Jakma6ac29a52008-08-15 13:45:30 +010075static void
hasso508e53e2004-05-18 18:57:06 +000076ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +000077{
Dinesh Dutt3810e062013-08-24 07:54:09 +000078 struct ospf6_interface *oi;
79
80 if (lsa == NULL)
81 return;
82
83 oi = lsa->lsdb->data;
hasso508e53e2004-05-18 18:57:06 +000084 switch (ntohs (lsa->header->type))
85 {
86 case OSPF6_LSTYPE_LINK:
Dinesh Dutt3810e062013-08-24 07:54:09 +000087 if (oi->state == OSPF6_INTERFACE_DR)
88 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
89 ospf6_spf_schedule (oi->area->ospf6);
hasso508e53e2004-05-18 18:57:06 +000090 break;
paul718e3742002-12-13 20:15:29 +000091
hasso508e53e2004-05-18 18:57:06 +000092 default:
hasso508e53e2004-05-18 18:57:06 +000093 break;
94 }
paul718e3742002-12-13 20:15:29 +000095}
96
Dinesh Duttc5926a92013-08-24 07:55:00 +000097static u_char
98ospf6_default_iftype(struct interface *ifp)
99{
100 if (if_is_pointopoint (ifp))
101 return OSPF_IFTYPE_POINTOPOINT;
102 else if (if_is_loopback (ifp))
103 return OSPF_IFTYPE_LOOPBACK;
104 else
105 return OSPF_IFTYPE_BROADCAST;
106}
107
paul718e3742002-12-13 20:15:29 +0000108/* Create new ospf6 interface structure */
109struct ospf6_interface *
110ospf6_interface_create (struct interface *ifp)
111{
hasso508e53e2004-05-18 18:57:06 +0000112 struct ospf6_interface *oi;
paul0c083ee2004-10-10 12:54:58 +0000113 unsigned int iobuflen;
paul718e3742002-12-13 20:15:29 +0000114
hasso508e53e2004-05-18 18:57:06 +0000115 oi = (struct ospf6_interface *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700116 XCALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
paul718e3742002-12-13 20:15:29 +0000117
Stephen Hemminger393deb92008-08-18 14:13:29 -0700118 if (!oi)
paul718e3742002-12-13 20:15:29 +0000119 {
120 zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
121 return (struct ospf6_interface *) NULL;
122 }
123
hasso508e53e2004-05-18 18:57:06 +0000124 oi->area = (struct ospf6_area *) NULL;
125 oi->neighbor_list = list_new ();
126 oi->neighbor_list->cmp = ospf6_neighbor_cmp;
127 oi->linklocal_addr = (struct in6_addr *) NULL;
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +0400128 oi->instance_id = OSPF6_INTERFACE_INSTANCE_ID;
129 oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
130 oi->priority = OSPF6_INTERFACE_PRIORITY;
paul718e3742002-12-13 20:15:29 +0000131
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700132 oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
133 oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
134 oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +0400135 oi->cost = OSPF6_INTERFACE_COST;
Dinesh Duttc5926a92013-08-24 07:55:00 +0000136 oi->type = ospf6_default_iftype (ifp);
hasso508e53e2004-05-18 18:57:06 +0000137 oi->state = OSPF6_INTERFACE_DOWN;
138 oi->flag = 0;
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +0400139 oi->mtu_ignore = 0;
paul718e3742002-12-13 20:15:29 +0000140
hassob596c712004-07-09 18:33:43 +0000141 /* Try to adjust I/O buffer size with IfMtu */
hasso1203e1c2004-07-23 21:34:27 +0000142 oi->ifmtu = ifp->mtu6;
143 iobuflen = ospf6_iobuf_size (ifp->mtu6);
hassob596c712004-07-09 18:33:43 +0000144 if (oi->ifmtu > iobuflen)
hasso3b4cd3a2004-05-18 19:28:32 +0000145 {
hasso1e058382004-09-01 21:36:14 +0000146 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000147 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
148 ifp->name, iobuflen);
hasso3b4cd3a2004-05-18 19:28:32 +0000149 oi->ifmtu = iobuflen;
150 }
hasso3b4cd3a2004-05-18 19:28:32 +0000151
hasso6452df02004-08-15 05:52:07 +0000152 oi->lsupdate_list = ospf6_lsdb_create (oi);
153 oi->lsack_list = ospf6_lsdb_create (oi);
154 oi->lsdb = ospf6_lsdb_create (oi);
hasso508e53e2004-05-18 18:57:06 +0000155 oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
156 oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
hasso6452df02004-08-15 05:52:07 +0000157 oi->lsdb_self = ospf6_lsdb_create (oi);
paul718e3742002-12-13 20:15:29 +0000158
Paul Jakmacf1ce252006-05-15 10:46:07 +0000159 oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
160 oi->route_connected->scope = oi;
paul718e3742002-12-13 20:15:29 +0000161
162 /* link both */
hasso508e53e2004-05-18 18:57:06 +0000163 oi->interface = ifp;
164 ifp->info = oi;
paul718e3742002-12-13 20:15:29 +0000165
hasso508e53e2004-05-18 18:57:06 +0000166 return oi;
paul718e3742002-12-13 20:15:29 +0000167}
168
169void
hasso508e53e2004-05-18 18:57:06 +0000170ospf6_interface_delete (struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +0000171{
paul1eb8ef22005-04-07 07:30:20 +0000172 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000173 struct ospf6_neighbor *on;
paul718e3742002-12-13 20:15:29 +0000174
paul1eb8ef22005-04-07 07:30:20 +0000175 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso508e53e2004-05-18 18:57:06 +0000176 ospf6_neighbor_delete (on);
paul1eb8ef22005-04-07 07:30:20 +0000177
hasso508e53e2004-05-18 18:57:06 +0000178 list_delete (oi->neighbor_list);
paul718e3742002-12-13 20:15:29 +0000179
hasso508e53e2004-05-18 18:57:06 +0000180 THREAD_OFF (oi->thread_send_hello);
181 THREAD_OFF (oi->thread_send_lsupdate);
182 THREAD_OFF (oi->thread_send_lsack);
paul718e3742002-12-13 20:15:29 +0000183
hasso508e53e2004-05-18 18:57:06 +0000184 ospf6_lsdb_remove_all (oi->lsdb);
185 ospf6_lsdb_remove_all (oi->lsupdate_list);
186 ospf6_lsdb_remove_all (oi->lsack_list);
187
188 ospf6_lsdb_delete (oi->lsdb);
hasso6452df02004-08-15 05:52:07 +0000189 ospf6_lsdb_delete (oi->lsdb_self);
190
hasso508e53e2004-05-18 18:57:06 +0000191 ospf6_lsdb_delete (oi->lsupdate_list);
192 ospf6_lsdb_delete (oi->lsack_list);
193
194 ospf6_route_table_delete (oi->route_connected);
paul718e3742002-12-13 20:15:29 +0000195
196 /* cut link */
hasso508e53e2004-05-18 18:57:06 +0000197 oi->interface->info = NULL;
paul718e3742002-12-13 20:15:29 +0000198
199 /* plist_name */
hasso508e53e2004-05-18 18:57:06 +0000200 if (oi->plist_name)
201 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
paul718e3742002-12-13 20:15:29 +0000202
hasso508e53e2004-05-18 18:57:06 +0000203 XFREE (MTYPE_OSPF6_IF, oi);
204}
205
206void
207ospf6_interface_enable (struct ospf6_interface *oi)
208{
209 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
210
211 oi->thread_send_hello =
212 thread_add_event (master, ospf6_hello_send, oi, 0);
213}
214
215void
216ospf6_interface_disable (struct ospf6_interface *oi)
217{
paul1eb8ef22005-04-07 07:30:20 +0000218 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000219 struct ospf6_neighbor *on;
220
221 SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
222
paul1eb8ef22005-04-07 07:30:20 +0000223 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso508e53e2004-05-18 18:57:06 +0000224 ospf6_neighbor_delete (on);
paul1eb8ef22005-04-07 07:30:20 +0000225
hasso508e53e2004-05-18 18:57:06 +0000226 list_delete_all_node (oi->neighbor_list);
227
228 ospf6_lsdb_remove_all (oi->lsdb);
229 ospf6_lsdb_remove_all (oi->lsupdate_list);
230 ospf6_lsdb_remove_all (oi->lsack_list);
231
232 THREAD_OFF (oi->thread_send_hello);
233 THREAD_OFF (oi->thread_send_lsupdate);
234 THREAD_OFF (oi->thread_send_lsack);
paul718e3742002-12-13 20:15:29 +0000235}
236
237static struct in6_addr *
hasso508e53e2004-05-18 18:57:06 +0000238ospf6_interface_get_linklocal_address (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000239{
hasso52dc7ee2004-09-23 19:18:23 +0000240 struct listnode *n;
paul718e3742002-12-13 20:15:29 +0000241 struct connected *c;
242 struct in6_addr *l = (struct in6_addr *) NULL;
243
244 /* for each connected address */
paul1eb8ef22005-04-07 07:30:20 +0000245 for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
paul718e3742002-12-13 20:15:29 +0000246 {
paul718e3742002-12-13 20:15:29 +0000247 /* if family not AF_INET6, ignore */
248 if (c->address->family != AF_INET6)
249 continue;
250
251 /* linklocal scope check */
252 if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
253 l = &c->address->u.prefix6;
254 }
255 return l;
256}
257
258void
259ospf6_interface_if_add (struct interface *ifp)
260{
hasso508e53e2004-05-18 18:57:06 +0000261 struct ospf6_interface *oi;
paul0c083ee2004-10-10 12:54:58 +0000262 unsigned int iobuflen;
paul718e3742002-12-13 20:15:29 +0000263
hasso508e53e2004-05-18 18:57:06 +0000264 oi = (struct ospf6_interface *) ifp->info;
265 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000266 return;
267
hassob596c712004-07-09 18:33:43 +0000268 /* Try to adjust I/O buffer size with IfMtu */
269 if (oi->ifmtu == 0)
hasso1203e1c2004-07-23 21:34:27 +0000270 oi->ifmtu = ifp->mtu6;
271 iobuflen = ospf6_iobuf_size (ifp->mtu6);
hassob596c712004-07-09 18:33:43 +0000272 if (oi->ifmtu > iobuflen)
hasso3b4cd3a2004-05-18 19:28:32 +0000273 {
hasso1e058382004-09-01 21:36:14 +0000274 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000275 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
276 ifp->name, iobuflen);
hasso3b4cd3a2004-05-18 19:28:32 +0000277 oi->ifmtu = iobuflen;
278 }
paul718e3742002-12-13 20:15:29 +0000279
280 /* interface start */
hasso508e53e2004-05-18 18:57:06 +0000281 if (oi->area)
282 thread_add_event (master, interface_up, oi, 0);
paul718e3742002-12-13 20:15:29 +0000283}
284
285void
286ospf6_interface_if_del (struct interface *ifp)
287{
hasso508e53e2004-05-18 18:57:06 +0000288 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000289
hasso508e53e2004-05-18 18:57:06 +0000290 oi = (struct ospf6_interface *) ifp->info;
291 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000292 return;
293
294 /* interface stop */
hasso508e53e2004-05-18 18:57:06 +0000295 if (oi->area)
296 thread_execute (master, interface_down, oi, 0);
paul718e3742002-12-13 20:15:29 +0000297
hasso508e53e2004-05-18 18:57:06 +0000298 listnode_delete (oi->area->if_list, oi);
299 oi->area = (struct ospf6_area *) NULL;
paul718e3742002-12-13 20:15:29 +0000300
301 /* cut link */
hasso508e53e2004-05-18 18:57:06 +0000302 oi->interface = NULL;
paul718e3742002-12-13 20:15:29 +0000303 ifp->info = NULL;
304
hasso508e53e2004-05-18 18:57:06 +0000305 ospf6_interface_delete (oi);
paul718e3742002-12-13 20:15:29 +0000306}
307
308void
309ospf6_interface_state_update (struct interface *ifp)
310{
hasso508e53e2004-05-18 18:57:06 +0000311 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000312
hasso508e53e2004-05-18 18:57:06 +0000313 oi = (struct ospf6_interface *) ifp->info;
314 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000315 return;
hasso508e53e2004-05-18 18:57:06 +0000316 if (oi->area == NULL)
paul718e3742002-12-13 20:15:29 +0000317 return;
318
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000319 if (if_is_operative (ifp))
hasso508e53e2004-05-18 18:57:06 +0000320 thread_add_event (master, interface_up, oi, 0);
paul718e3742002-12-13 20:15:29 +0000321 else
hasso508e53e2004-05-18 18:57:06 +0000322 thread_add_event (master, interface_down, oi, 0);
paul718e3742002-12-13 20:15:29 +0000323
324 return;
325}
326
327void
hasso508e53e2004-05-18 18:57:06 +0000328ospf6_interface_connected_route_update (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000329{
hasso508e53e2004-05-18 18:57:06 +0000330 struct ospf6_interface *oi;
331 struct ospf6_route *route;
332 struct connected *c;
paul1eb8ef22005-04-07 07:30:20 +0000333 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000334
hasso508e53e2004-05-18 18:57:06 +0000335 oi = (struct ospf6_interface *) ifp->info;
336 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000337 return;
338
339 /* reset linklocal pointer */
hasso508e53e2004-05-18 18:57:06 +0000340 oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
paul718e3742002-12-13 20:15:29 +0000341
hasso508e53e2004-05-18 18:57:06 +0000342 /* if area is null, do not make connected-route list */
343 if (oi->area == NULL)
paul718e3742002-12-13 20:15:29 +0000344 return;
345
hasso508e53e2004-05-18 18:57:06 +0000346 /* update "route to advertise" interface route table */
347 ospf6_route_remove_all (oi->route_connected);
hasso508e53e2004-05-18 18:57:06 +0000348
paul1eb8ef22005-04-07 07:30:20 +0000349 for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
350 {
hasso508e53e2004-05-18 18:57:06 +0000351 if (c->address->family != AF_INET6)
352 continue;
353
hasso1e058382004-09-01 21:36:14 +0000354 CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
355 CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
356 CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
357 CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
358 CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
hasso508e53e2004-05-18 18:57:06 +0000359
360 /* apply filter */
361 if (oi->plist_name)
362 {
363 struct prefix_list *plist;
364 enum prefix_list_type ret;
365 char buf[128];
366
367 prefix2str (c->address, buf, sizeof (buf));
368 plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
369 ret = prefix_list_apply (plist, (void *) c->address);
370 if (ret == PREFIX_DENY)
371 {
hasso1e058382004-09-01 21:36:14 +0000372 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000373 zlog_debug ("%s on %s filtered by prefix-list %s ",
374 buf, oi->interface->name, oi->plist_name);
hasso508e53e2004-05-18 18:57:06 +0000375 continue;
376 }
377 }
378
379 route = ospf6_route_create ();
380 memcpy (&route->prefix, c->address, sizeof (struct prefix));
381 apply_mask (&route->prefix);
382 route->type = OSPF6_DEST_TYPE_NETWORK;
383 route->path.area_id = oi->area->area_id;
384 route->path.type = OSPF6_PATH_TYPE_INTRA;
385 route->path.cost = oi->cost;
386 route->nexthop[0].ifindex = oi->interface->ifindex;
387 inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
388 ospf6_route_add (route, oi->route_connected);
389 }
390
paul718e3742002-12-13 20:15:29 +0000391 /* create new Link-LSA */
hasso508e53e2004-05-18 18:57:06 +0000392 OSPF6_LINK_LSA_SCHEDULE (oi);
393 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
394 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
paul718e3742002-12-13 20:15:29 +0000395}
396
hasso508e53e2004-05-18 18:57:06 +0000397static void
398ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +0000399{
hasso508e53e2004-05-18 18:57:06 +0000400 u_char prev_state;
paul718e3742002-12-13 20:15:29 +0000401
hasso508e53e2004-05-18 18:57:06 +0000402 prev_state = oi->state;
403 oi->state = next_state;
paul718e3742002-12-13 20:15:29 +0000404
hasso508e53e2004-05-18 18:57:06 +0000405 if (prev_state == next_state)
406 return;
paul718e3742002-12-13 20:15:29 +0000407
hasso508e53e2004-05-18 18:57:06 +0000408 /* log */
409 if (IS_OSPF6_DEBUG_INTERFACE)
paul718e3742002-12-13 20:15:29 +0000410 {
hassoc6487d62004-12-24 06:00:11 +0000411 zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
412 ospf6_interface_state_str[prev_state],
413 ospf6_interface_state_str[next_state]);
paul718e3742002-12-13 20:15:29 +0000414 }
Vincent Bernat3bc4f842012-06-04 11:40:04 +0200415 oi->state_change++;
paul718e3742002-12-13 20:15:29 +0000416
hasso508e53e2004-05-18 18:57:06 +0000417 if ((prev_state == OSPF6_INTERFACE_DR ||
418 prev_state == OSPF6_INTERFACE_BDR) &&
419 (next_state != OSPF6_INTERFACE_DR &&
420 next_state != OSPF6_INTERFACE_BDR))
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400421 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP);
Dinesh Duttc5926a92013-08-24 07:55:00 +0000422
hasso508e53e2004-05-18 18:57:06 +0000423 if ((prev_state != OSPF6_INTERFACE_DR &&
424 prev_state != OSPF6_INTERFACE_BDR) &&
425 (next_state == OSPF6_INTERFACE_DR ||
426 next_state == OSPF6_INTERFACE_BDR))
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400427 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP);
paul718e3742002-12-13 20:15:29 +0000428
hasso508e53e2004-05-18 18:57:06 +0000429 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
hasso6452df02004-08-15 05:52:07 +0000430 if (next_state == OSPF6_INTERFACE_DOWN)
431 {
432 OSPF6_NETWORK_LSA_EXECUTE (oi);
433 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
434 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
435 }
436 else if (prev_state == OSPF6_INTERFACE_DR ||
437 next_state == OSPF6_INTERFACE_DR)
paul718e3742002-12-13 20:15:29 +0000438 {
hasso508e53e2004-05-18 18:57:06 +0000439 OSPF6_NETWORK_LSA_SCHEDULE (oi);
440 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
441 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
paul718e3742002-12-13 20:15:29 +0000442 }
Vincent Bernatbf836662012-06-04 14:36:12 +0200443
444#ifdef HAVE_SNMP
445 /* Terminal state or regression */
446 if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
447 (next_state == OSPF6_INTERFACE_DROTHER) ||
448 (next_state == OSPF6_INTERFACE_BDR) ||
449 (next_state == OSPF6_INTERFACE_DR) ||
450 (next_state < prev_state))
451 ospf6TrapIfStateChange (oi);
452#endif
453
hasso508e53e2004-05-18 18:57:06 +0000454}
455
456
457/* DR Election, RFC2328 section 9.4 */
458
459#define IS_ELIGIBLE(n) \
460 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
461
462static struct ospf6_neighbor *
463better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
464{
465 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
466 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
467 return NULL;
468 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
469 return b;
470 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
471 return a;
472
473 if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
474 return a;
475 if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
476 return b;
477
478 if (a->priority > b->priority)
479 return a;
480 if (a->priority < b->priority)
481 return b;
482
483 if (ntohl (a->router_id) > ntohl (b->router_id))
484 return a;
485 if (ntohl (a->router_id) < ntohl (b->router_id))
486 return b;
487
488 zlog_warn ("Router-ID duplicate ?");
489 return a;
490}
491
492static struct ospf6_neighbor *
493better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
494{
495 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
496 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
497 return NULL;
498 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
499 return b;
500 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
501 return a;
502
503 if (a->drouter == a->router_id && b->drouter != b->router_id)
504 return a;
505 if (a->drouter != a->router_id && b->drouter == b->router_id)
506 return b;
507
508 if (a->priority > b->priority)
509 return a;
510 if (a->priority < b->priority)
511 return b;
512
513 if (ntohl (a->router_id) > ntohl (b->router_id))
514 return a;
515 if (ntohl (a->router_id) < ntohl (b->router_id))
516 return b;
517
518 zlog_warn ("Router-ID duplicate ?");
519 return a;
520}
521
522static u_char
523dr_election (struct ospf6_interface *oi)
524{
paul1eb8ef22005-04-07 07:30:20 +0000525 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000526 struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
527 struct ospf6_neighbor *best_drouter, *best_bdrouter;
528 u_char next_state = 0;
529
530 drouter = bdrouter = NULL;
531 best_drouter = best_bdrouter = NULL;
532
533 /* pseudo neighbor myself, including noting current DR/BDR (1) */
534 memset (&myself, 0, sizeof (myself));
535 inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
536 sizeof (myself.name));
537 myself.state = OSPF6_NEIGHBOR_TWOWAY;
538 myself.drouter = oi->drouter;
539 myself.bdrouter = oi->bdrouter;
540 myself.priority = oi->priority;
541 myself.router_id = oi->area->ospf6->router_id;
542
543 /* Electing BDR (2) */
paul1eb8ef22005-04-07 07:30:20 +0000544 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
545 bdrouter = better_bdrouter (bdrouter, on);
546
hasso508e53e2004-05-18 18:57:06 +0000547 best_bdrouter = bdrouter;
548 bdrouter = better_bdrouter (best_bdrouter, &myself);
549
550 /* Electing DR (3) */
paul1eb8ef22005-04-07 07:30:20 +0000551 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
552 drouter = better_drouter (drouter, on);
553
hasso508e53e2004-05-18 18:57:06 +0000554 best_drouter = drouter;
555 drouter = better_drouter (best_drouter, &myself);
556 if (drouter == NULL)
557 drouter = bdrouter;
558
559 /* the router itself is newly/no longer DR/BDR (4) */
560 if ((drouter == &myself && myself.drouter != myself.router_id) ||
561 (drouter != &myself && myself.drouter == myself.router_id) ||
562 (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
563 (bdrouter != &myself && myself.bdrouter == myself.router_id))
564 {
565 myself.drouter = (drouter ? drouter->router_id : htonl (0));
566 myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
567
568 /* compatible to Electing BDR (2) */
569 bdrouter = better_bdrouter (best_bdrouter, &myself);
570
571 /* compatible to Electing DR (3) */
572 drouter = better_drouter (best_drouter, &myself);
573 if (drouter == NULL)
574 drouter = bdrouter;
575 }
576
577 /* Set interface state accordingly (5) */
578 if (drouter && drouter == &myself)
579 next_state = OSPF6_INTERFACE_DR;
580 else if (bdrouter && bdrouter == &myself)
581 next_state = OSPF6_INTERFACE_BDR;
582 else
583 next_state = OSPF6_INTERFACE_DROTHER;
584
585 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
586 /* XXX */
587
588 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
589 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
590 accordingly after AdjOK */
591 if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
592 oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
593 {
594 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000595 zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
596 (drouter ? drouter->name : "0.0.0.0"),
597 (bdrouter ? bdrouter->name : "0.0.0.0"));
hasso508e53e2004-05-18 18:57:06 +0000598
paul1eb8ef22005-04-07 07:30:20 +0000599 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
hasso508e53e2004-05-18 18:57:06 +0000600 {
hasso508e53e2004-05-18 18:57:06 +0000601 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
602 continue;
603 /* Schedule AdjOK. */
604 thread_add_event (master, adj_ok, on, 0);
605 }
606 }
607
608 oi->drouter = (drouter ? drouter->router_id : htonl (0));
609 oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
610 return next_state;
611}
612
613
614/* Interface State Machine */
615int
616interface_up (struct thread *thread)
617{
618 struct ospf6_interface *oi;
619
620 oi = (struct ospf6_interface *) THREAD_ARG (thread);
621 assert (oi && oi->interface);
622
623 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000624 zlog_debug ("Interface Event %s: [InterfaceUp]",
625 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000626
627 /* check physical interface is up */
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000628 if (! if_is_operative (oi->interface))
hasso508e53e2004-05-18 18:57:06 +0000629 {
630 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000631 zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
632 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000633 return 0;
634 }
635
636 /* if already enabled, do nothing */
637 if (oi->state > OSPF6_INTERFACE_DOWN)
638 {
639 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000640 zlog_debug ("Interface %s already enabled",
641 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000642 return 0;
643 }
644
645 /* Join AllSPFRouters */
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400646 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP);
hasso508e53e2004-05-18 18:57:06 +0000647
648 /* Update interface route */
649 ospf6_interface_connected_route_update (oi->interface);
650
651 /* Schedule Hello */
652 if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
653 thread_add_event (master, ospf6_hello_send, oi, 0);
654
655 /* decide next interface state */
Dinesh Duttc5926a92013-08-24 07:55:00 +0000656 if ((if_is_pointopoint (oi->interface)) ||
657 (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
hasso508e53e2004-05-18 18:57:06 +0000658 ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
Dinesh Duttc5926a92013-08-24 07:55:00 +0000659 }
hasso508e53e2004-05-18 18:57:06 +0000660 else if (oi->priority == 0)
661 ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
662 else
663 {
664 ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
665 thread_add_timer (master, wait_timer, oi, oi->dead_interval);
666 }
667
668 return 0;
paul718e3742002-12-13 20:15:29 +0000669}
670
671int
hasso508e53e2004-05-18 18:57:06 +0000672wait_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000673{
hasso508e53e2004-05-18 18:57:06 +0000674 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000675
hasso508e53e2004-05-18 18:57:06 +0000676 oi = (struct ospf6_interface *) THREAD_ARG (thread);
677 assert (oi && oi->interface);
paul718e3742002-12-13 20:15:29 +0000678
hasso508e53e2004-05-18 18:57:06 +0000679 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000680 zlog_debug ("Interface Event %s: [WaitTimer]",
681 oi->interface->name);
paul718e3742002-12-13 20:15:29 +0000682
hasso508e53e2004-05-18 18:57:06 +0000683 if (oi->state == OSPF6_INTERFACE_WAITING)
684 ospf6_interface_state_change (dr_election (oi), oi);
paul718e3742002-12-13 20:15:29 +0000685
hasso508e53e2004-05-18 18:57:06 +0000686 return 0;
paul718e3742002-12-13 20:15:29 +0000687}
688
hasso508e53e2004-05-18 18:57:06 +0000689int
690backup_seen (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000691{
hasso508e53e2004-05-18 18:57:06 +0000692 struct ospf6_interface *oi;
693
694 oi = (struct ospf6_interface *) THREAD_ARG (thread);
695 assert (oi && oi->interface);
696
697 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000698 zlog_debug ("Interface Event %s: [BackupSeen]",
699 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000700
701 if (oi->state == OSPF6_INTERFACE_WAITING)
702 ospf6_interface_state_change (dr_election (oi), oi);
703
704 return 0;
paul718e3742002-12-13 20:15:29 +0000705}
706
hasso508e53e2004-05-18 18:57:06 +0000707int
708neighbor_change (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000709{
hasso508e53e2004-05-18 18:57:06 +0000710 struct ospf6_interface *oi;
711
712 oi = (struct ospf6_interface *) THREAD_ARG (thread);
713 assert (oi && oi->interface);
714
715 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000716 zlog_debug ("Interface Event %s: [NeighborChange]",
717 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000718
719 if (oi->state == OSPF6_INTERFACE_DROTHER ||
720 oi->state == OSPF6_INTERFACE_BDR ||
721 oi->state == OSPF6_INTERFACE_DR)
722 ospf6_interface_state_change (dr_election (oi), oi);
723
724 return 0;
paul718e3742002-12-13 20:15:29 +0000725}
726
hasso508e53e2004-05-18 18:57:06 +0000727int
728interface_down (struct thread *thread)
729{
730 struct ospf6_interface *oi;
paul1eb8ef22005-04-07 07:30:20 +0000731 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000732 struct ospf6_neighbor *on;
733
734 oi = (struct ospf6_interface *) THREAD_ARG (thread);
735 assert (oi && oi->interface);
736
737 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000738 zlog_debug ("Interface Event %s: [InterfaceDown]",
739 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000740
741 /* Leave AllSPFRouters */
742 if (oi->state > OSPF6_INTERFACE_DOWN)
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400743 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_LEAVE_GROUP);
hasso508e53e2004-05-18 18:57:06 +0000744
745 ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
746
paul1eb8ef22005-04-07 07:30:20 +0000747 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
748 ospf6_neighbor_delete (on);
749
hasso508e53e2004-05-18 18:57:06 +0000750 list_delete_all_node (oi->neighbor_list);
751
752 return 0;
753}
754
755
paul718e3742002-12-13 20:15:29 +0000756/* show specified interface structure */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100757static int
hasso508e53e2004-05-18 18:57:06 +0000758ospf6_interface_show (struct vty *vty, struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000759{
hasso508e53e2004-05-18 18:57:06 +0000760 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000761 struct connected *c;
762 struct prefix *p;
hasso52dc7ee2004-09-23 19:18:23 +0000763 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000764 char strbuf[64], drouter[32], bdrouter[32];
paul0c083ee2004-10-10 12:54:58 +0000765 const char *updown[3] = {"down", "up", NULL};
766 const char *type;
hasso508e53e2004-05-18 18:57:06 +0000767 struct timeval res, now;
768 char duration[32];
769 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000770
771 /* check physical interface type */
hasso508e53e2004-05-18 18:57:06 +0000772 if (if_is_loopback (ifp))
paul718e3742002-12-13 20:15:29 +0000773 type = "LOOPBACK";
hasso508e53e2004-05-18 18:57:06 +0000774 else if (if_is_broadcast (ifp))
paul718e3742002-12-13 20:15:29 +0000775 type = "BROADCAST";
hasso508e53e2004-05-18 18:57:06 +0000776 else if (if_is_pointopoint (ifp))
paul718e3742002-12-13 20:15:29 +0000777 type = "POINTOPOINT";
778 else
779 type = "UNKNOWN";
780
781 vty_out (vty, "%s is %s, type %s%s",
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000782 ifp->name, updown[if_is_operative (ifp)], type,
hasso049207c2004-08-04 20:02:13 +0000783 VNL);
784 vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
paul718e3742002-12-13 20:15:29 +0000785
hasso508e53e2004-05-18 18:57:06 +0000786 if (ifp->info == NULL)
paul718e3742002-12-13 20:15:29 +0000787 {
hasso049207c2004-08-04 20:02:13 +0000788 vty_out (vty, " OSPF not enabled on this interface%s", VNL);
paul718e3742002-12-13 20:15:29 +0000789 return 0;
790 }
791 else
hasso508e53e2004-05-18 18:57:06 +0000792 oi = (struct ospf6_interface *) ifp->info;
paul718e3742002-12-13 20:15:29 +0000793
hasso049207c2004-08-04 20:02:13 +0000794 vty_out (vty, " Internet Address:%s", VNL);
paul1eb8ef22005-04-07 07:30:20 +0000795
796 for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
paul718e3742002-12-13 20:15:29 +0000797 {
paul718e3742002-12-13 20:15:29 +0000798 p = c->address;
799 prefix2str (p, strbuf, sizeof (strbuf));
800 switch (p->family)
801 {
802 case AF_INET:
hasso508e53e2004-05-18 18:57:06 +0000803 vty_out (vty, " inet : %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000804 VNL);
paul718e3742002-12-13 20:15:29 +0000805 break;
806 case AF_INET6:
hasso508e53e2004-05-18 18:57:06 +0000807 vty_out (vty, " inet6: %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000808 VNL);
paul718e3742002-12-13 20:15:29 +0000809 break;
810 default:
hasso508e53e2004-05-18 18:57:06 +0000811 vty_out (vty, " ??? : %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000812 VNL);
paul718e3742002-12-13 20:15:29 +0000813 break;
814 }
815 }
816
hasso508e53e2004-05-18 18:57:06 +0000817 if (oi->area)
paul718e3742002-12-13 20:15:29 +0000818 {
hasso508e53e2004-05-18 18:57:06 +0000819 vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
hasso049207c2004-08-04 20:02:13 +0000820 oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +0400821 vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ?
822 "disabled" : "enabled", VNL);
hasso508e53e2004-05-18 18:57:06 +0000823 inet_ntop (AF_INET, &oi->area->area_id,
paul718e3742002-12-13 20:15:29 +0000824 strbuf, sizeof (strbuf));
hasso508e53e2004-05-18 18:57:06 +0000825 vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
hasso049207c2004-08-04 20:02:13 +0000826 VNL);
paul718e3742002-12-13 20:15:29 +0000827 }
828 else
hasso049207c2004-08-04 20:02:13 +0000829 vty_out (vty, " Not Attached to Area%s", VNL);
paul718e3742002-12-13 20:15:29 +0000830
831 vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
hasso508e53e2004-05-18 18:57:06 +0000832 ospf6_interface_state_str[oi->state],
833 oi->transdelay, oi->priority,
hasso049207c2004-08-04 20:02:13 +0000834 VNL);
835 vty_out (vty, " Timer intervals configured:%s", VNL);
paul718e3742002-12-13 20:15:29 +0000836 vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
hasso508e53e2004-05-18 18:57:06 +0000837 oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
hasso049207c2004-08-04 20:02:13 +0000838 VNL);
paul718e3742002-12-13 20:15:29 +0000839
hasso508e53e2004-05-18 18:57:06 +0000840 inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
841 inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
hasso049207c2004-08-04 20:02:13 +0000842 vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
paul718e3742002-12-13 20:15:29 +0000843
844 vty_out (vty, " Number of I/F scoped LSAs is %u%s",
hasso049207c2004-08-04 20:02:13 +0000845 oi->lsdb->count, VNL);
paul718e3742002-12-13 20:15:29 +0000846
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900847 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
paul718e3742002-12-13 20:15:29 +0000848
hasso508e53e2004-05-18 18:57:06 +0000849 timerclear (&res);
850 if (oi->thread_send_lsupdate)
851 timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
852 timerstring (&res, duration, sizeof (duration));
853 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
854 oi->lsupdate_list->count, duration,
855 (oi->thread_send_lsupdate ? "on" : "off"),
hasso049207c2004-08-04 20:02:13 +0000856 VNL);
hasso508e53e2004-05-18 18:57:06 +0000857 for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
858 lsa = ospf6_lsdb_next (lsa))
hasso049207c2004-08-04 20:02:13 +0000859 vty_out (vty, " %s%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000860
hasso508e53e2004-05-18 18:57:06 +0000861 timerclear (&res);
862 if (oi->thread_send_lsack)
863 timersub (&oi->thread_send_lsack->u.sands, &now, &res);
864 timerstring (&res, duration, sizeof (duration));
865 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
866 oi->lsack_list->count, duration,
867 (oi->thread_send_lsack ? "on" : "off"),
hasso049207c2004-08-04 20:02:13 +0000868 VNL);
hasso508e53e2004-05-18 18:57:06 +0000869 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
870 lsa = ospf6_lsdb_next (lsa))
hasso049207c2004-08-04 20:02:13 +0000871 vty_out (vty, " %s%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000872
hasso508e53e2004-05-18 18:57:06 +0000873 return 0;
paul718e3742002-12-13 20:15:29 +0000874}
875
876/* show interface */
877DEFUN (show_ipv6_ospf6_interface,
878 show_ipv6_ospf6_interface_ifname_cmd,
879 "show ipv6 ospf6 interface IFNAME",
880 SHOW_STR
881 IP6_STR
882 OSPF6_STR
883 INTERFACE_STR
884 IFNAME_STR
885 )
886{
887 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000888 struct listnode *i;
paul718e3742002-12-13 20:15:29 +0000889
890 if (argc)
891 {
892 ifp = if_lookup_by_name (argv[0]);
hasso508e53e2004-05-18 18:57:06 +0000893 if (ifp == NULL)
paul718e3742002-12-13 20:15:29 +0000894 {
895 vty_out (vty, "No such Interface: %s%s", argv[0],
hasso049207c2004-08-04 20:02:13 +0000896 VNL);
paul718e3742002-12-13 20:15:29 +0000897 return CMD_WARNING;
898 }
899 ospf6_interface_show (vty, ifp);
900 }
901 else
902 {
paul1eb8ef22005-04-07 07:30:20 +0000903 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
904 ospf6_interface_show (vty, ifp);
paul718e3742002-12-13 20:15:29 +0000905 }
hasso508e53e2004-05-18 18:57:06 +0000906
paul718e3742002-12-13 20:15:29 +0000907 return CMD_SUCCESS;
908}
909
910ALIAS (show_ipv6_ospf6_interface,
911 show_ipv6_ospf6_interface_cmd,
912 "show ipv6 ospf6 interface",
913 SHOW_STR
914 IP6_STR
915 OSPF6_STR
916 INTERFACE_STR
Paul Jakma6ac29a52008-08-15 13:45:30 +0100917 )
paul718e3742002-12-13 20:15:29 +0000918
hasso508e53e2004-05-18 18:57:06 +0000919DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
920 show_ipv6_ospf6_interface_ifname_prefix_cmd,
921 "show ipv6 ospf6 interface IFNAME prefix",
922 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000923 IP6_STR
924 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +0000925 INTERFACE_STR
926 IFNAME_STR
927 "Display connected prefixes to advertise\n"
paul718e3742002-12-13 20:15:29 +0000928 )
929{
paul718e3742002-12-13 20:15:29 +0000930 struct interface *ifp;
hasso508e53e2004-05-18 18:57:06 +0000931 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000932
hasso508e53e2004-05-18 18:57:06 +0000933 ifp = if_lookup_by_name (argv[0]);
934 if (ifp == NULL)
935 {
hasso049207c2004-08-04 20:02:13 +0000936 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000937 return CMD_WARNING;
938 }
paul718e3742002-12-13 20:15:29 +0000939
hasso508e53e2004-05-18 18:57:06 +0000940 oi = ifp->info;
941 if (oi == NULL)
942 {
hasso049207c2004-08-04 20:02:13 +0000943 vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000944 return CMD_WARNING;
945 }
paul718e3742002-12-13 20:15:29 +0000946
hasso508e53e2004-05-18 18:57:06 +0000947 argc--;
948 argv++;
949 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
paul718e3742002-12-13 20:15:29 +0000950
951 return CMD_SUCCESS;
952}
953
hasso508e53e2004-05-18 18:57:06 +0000954ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
955 show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
956 "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
957 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000958 IP6_STR
959 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +0000960 INTERFACE_STR
961 IFNAME_STR
962 "Display connected prefixes to advertise\n"
963 OSPF6_ROUTE_ADDRESS_STR
964 OSPF6_ROUTE_PREFIX_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +0400965 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100966 )
hasso508e53e2004-05-18 18:57:06 +0000967
968ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
969 show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
970 "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
971 SHOW_STR
972 IP6_STR
973 OSPF6_STR
974 INTERFACE_STR
975 IFNAME_STR
976 "Display connected prefixes to advertise\n"
977 OSPF6_ROUTE_PREFIX_STR
978 OSPF6_ROUTE_MATCH_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +0400979 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100980 )
hasso508e53e2004-05-18 18:57:06 +0000981
982DEFUN (show_ipv6_ospf6_interface_prefix,
983 show_ipv6_ospf6_interface_prefix_cmd,
984 "show ipv6 ospf6 interface prefix",
985 SHOW_STR
986 IP6_STR
987 OSPF6_STR
988 INTERFACE_STR
989 "Display connected prefixes to advertise\n"
paul718e3742002-12-13 20:15:29 +0000990 )
991{
hasso52dc7ee2004-09-23 19:18:23 +0000992 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000993 struct ospf6_interface *oi;
994 struct interface *ifp;
995
paul1eb8ef22005-04-07 07:30:20 +0000996 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
hasso508e53e2004-05-18 18:57:06 +0000997 {
hasso508e53e2004-05-18 18:57:06 +0000998 oi = (struct ospf6_interface *) ifp->info;
999 if (oi == NULL)
1000 continue;
1001
1002 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1003 }
1004
1005 return CMD_SUCCESS;
1006}
1007
1008ALIAS (show_ipv6_ospf6_interface_prefix,
1009 show_ipv6_ospf6_interface_prefix_detail_cmd,
1010 "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
1011 SHOW_STR
1012 IP6_STR
1013 OSPF6_STR
1014 INTERFACE_STR
1015 "Display connected prefixes to advertise\n"
1016 OSPF6_ROUTE_ADDRESS_STR
1017 OSPF6_ROUTE_PREFIX_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +04001018 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +01001019 )
hasso508e53e2004-05-18 18:57:06 +00001020
1021ALIAS (show_ipv6_ospf6_interface_prefix,
1022 show_ipv6_ospf6_interface_prefix_match_cmd,
1023 "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
1024 SHOW_STR
1025 IP6_STR
1026 OSPF6_STR
1027 INTERFACE_STR
1028 "Display connected prefixes to advertise\n"
1029 OSPF6_ROUTE_PREFIX_STR
1030 OSPF6_ROUTE_MATCH_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +04001031 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +01001032 )
hasso508e53e2004-05-18 18:57:06 +00001033
1034
1035/* interface variable set command */
hassob596c712004-07-09 18:33:43 +00001036DEFUN (ipv6_ospf6_ifmtu,
1037 ipv6_ospf6_ifmtu_cmd,
1038 "ipv6 ospf6 ifmtu <1-65535>",
1039 IP6_STR
1040 OSPF6_STR
1041 "Interface MTU\n"
1042 "OSPFv3 Interface MTU\n"
1043 )
1044{
1045 struct ospf6_interface *oi;
1046 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001047 unsigned int ifmtu, iobuflen;
paul1eb8ef22005-04-07 07:30:20 +00001048 struct listnode *node, *nnode;
hassob596c712004-07-09 18:33:43 +00001049 struct ospf6_neighbor *on;
1050
1051 ifp = (struct interface *) vty->index;
1052 assert (ifp);
1053
1054 oi = (struct ospf6_interface *) ifp->info;
1055 if (oi == NULL)
1056 oi = ospf6_interface_create (ifp);
1057 assert (oi);
1058
1059 ifmtu = strtol (argv[0], NULL, 10);
1060
1061 if (oi->ifmtu == ifmtu)
1062 return CMD_SUCCESS;
1063
hasso1203e1c2004-07-23 21:34:27 +00001064 if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
hassob596c712004-07-09 18:33:43 +00001065 {
1066 vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
hasso049207c2004-08-04 20:02:13 +00001067 ifp->name, ifp->mtu6, VNL);
hassob596c712004-07-09 18:33:43 +00001068 return CMD_WARNING;
1069 }
1070
1071 if (oi->ifmtu < ifmtu)
1072 {
1073 iobuflen = ospf6_iobuf_size (ifmtu);
1074 if (iobuflen < ifmtu)
1075 {
1076 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
hasso049207c2004-08-04 20:02:13 +00001077 ifp->name, iobuflen, VNL);
hassob596c712004-07-09 18:33:43 +00001078 oi->ifmtu = iobuflen;
1079 }
1080 else
1081 oi->ifmtu = ifmtu;
1082 }
1083 else
1084 oi->ifmtu = ifmtu;
1085
1086 /* re-establish adjacencies */
paul1eb8ef22005-04-07 07:30:20 +00001087 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hassob596c712004-07-09 18:33:43 +00001088 {
hassob596c712004-07-09 18:33:43 +00001089 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001090 thread_add_event (master, inactivity_timer, on, 0);
hassob596c712004-07-09 18:33:43 +00001091 }
1092
1093 return CMD_SUCCESS;
1094}
1095
hasso049207c2004-08-04 20:02:13 +00001096DEFUN (no_ipv6_ospf6_ifmtu,
1097 no_ipv6_ospf6_ifmtu_cmd,
1098 "no ipv6 ospf6 ifmtu",
1099 NO_STR
1100 IP6_STR
1101 OSPF6_STR
1102 "Interface MTU\n"
1103 )
1104{
1105 struct ospf6_interface *oi;
1106 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001107 unsigned int iobuflen;
paul1eb8ef22005-04-07 07:30:20 +00001108 struct listnode *node, *nnode;
hasso049207c2004-08-04 20:02:13 +00001109 struct ospf6_neighbor *on;
1110
1111 ifp = (struct interface *) vty->index;
1112 assert (ifp);
1113
1114 oi = (struct ospf6_interface *) ifp->info;
1115 if (oi == NULL)
1116 oi = ospf6_interface_create (ifp);
1117 assert (oi);
1118
1119 if (oi->ifmtu < ifp->mtu)
1120 {
1121 iobuflen = ospf6_iobuf_size (ifp->mtu);
1122 if (iobuflen < ifp->mtu)
1123 {
1124 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1125 ifp->name, iobuflen, VNL);
1126 oi->ifmtu = iobuflen;
1127 }
1128 else
1129 oi->ifmtu = ifp->mtu;
1130 }
1131 else
1132 oi->ifmtu = ifp->mtu;
1133
1134 /* re-establish adjacencies */
paul1eb8ef22005-04-07 07:30:20 +00001135 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso049207c2004-08-04 20:02:13 +00001136 {
hasso049207c2004-08-04 20:02:13 +00001137 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001138 thread_add_event (master, inactivity_timer, on, 0);
hasso049207c2004-08-04 20:02:13 +00001139 }
1140
1141 return CMD_SUCCESS;
1142}
1143
hasso508e53e2004-05-18 18:57:06 +00001144DEFUN (ipv6_ospf6_cost,
1145 ipv6_ospf6_cost_cmd,
1146 "ipv6 ospf6 cost <1-65535>",
1147 IP6_STR
1148 OSPF6_STR
1149 "Interface cost\n"
1150 "Outgoing metric of this interface\n"
1151 )
1152{
1153 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001154 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001155 unsigned long int lcost;
paul718e3742002-12-13 20:15:29 +00001156
1157 ifp = (struct interface *) vty->index;
1158 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001159
hasso508e53e2004-05-18 18:57:06 +00001160 oi = (struct ospf6_interface *) ifp->info;
1161 if (oi == NULL)
1162 oi = ospf6_interface_create (ifp);
1163 assert (oi);
1164
paul0c083ee2004-10-10 12:54:58 +00001165 lcost = strtol (argv[0], NULL, 10);
1166
1167 if (lcost > UINT32_MAX)
1168 {
1169 vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
1170 return CMD_WARNING;
1171 }
1172
1173 if (oi->cost == lcost)
hasso508e53e2004-05-18 18:57:06 +00001174 return CMD_SUCCESS;
paul0c083ee2004-10-10 12:54:58 +00001175
1176 oi->cost = lcost;
1177
hasso508e53e2004-05-18 18:57:06 +00001178 /* update cost held in route_connected list in ospf6_interface */
1179 ospf6_interface_connected_route_update (oi->interface);
1180
1181 /* execute LSA hooks */
1182 if (oi->area)
1183 {
1184 OSPF6_LINK_LSA_SCHEDULE (oi);
1185 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
1186 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1187 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1188 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1189 }
1190
1191 return CMD_SUCCESS;
1192}
1193
1194DEFUN (ipv6_ospf6_hellointerval,
1195 ipv6_ospf6_hellointerval_cmd,
1196 "ipv6 ospf6 hello-interval <1-65535>",
1197 IP6_STR
1198 OSPF6_STR
1199 "Interval time of Hello packets\n"
1200 SECONDS_STR
1201 )
1202{
1203 struct ospf6_interface *oi;
1204 struct interface *ifp;
1205
1206 ifp = (struct interface *) vty->index;
1207 assert (ifp);
1208
1209 oi = (struct ospf6_interface *) ifp->info;
1210 if (oi == NULL)
1211 oi = ospf6_interface_create (ifp);
1212 assert (oi);
1213
1214 oi->hello_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001215 return CMD_SUCCESS;
1216}
1217
1218/* interface variable set command */
1219DEFUN (ipv6_ospf6_deadinterval,
1220 ipv6_ospf6_deadinterval_cmd,
hasso508e53e2004-05-18 18:57:06 +00001221 "ipv6 ospf6 dead-interval <1-65535>",
paul718e3742002-12-13 20:15:29 +00001222 IP6_STR
1223 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001224 "Interval time after which a neighbor is declared down\n"
paul718e3742002-12-13 20:15:29 +00001225 SECONDS_STR
1226 )
1227{
hasso508e53e2004-05-18 18:57:06 +00001228 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001229 struct interface *ifp;
1230
1231 ifp = (struct interface *) vty->index;
1232 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001233
hasso508e53e2004-05-18 18:57:06 +00001234 oi = (struct ospf6_interface *) ifp->info;
1235 if (oi == NULL)
1236 oi = ospf6_interface_create (ifp);
1237 assert (oi);
1238
1239 oi->dead_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001240 return CMD_SUCCESS;
1241}
1242
1243/* interface variable set command */
1244DEFUN (ipv6_ospf6_transmitdelay,
1245 ipv6_ospf6_transmitdelay_cmd,
hasso508e53e2004-05-18 18:57:06 +00001246 "ipv6 ospf6 transmit-delay <1-3600>",
paul718e3742002-12-13 20:15:29 +00001247 IP6_STR
1248 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001249 "Transmit delay of this interface\n"
paul718e3742002-12-13 20:15:29 +00001250 SECONDS_STR
1251 )
1252{
hasso508e53e2004-05-18 18:57:06 +00001253 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001254 struct interface *ifp;
1255
1256 ifp = (struct interface *) vty->index;
1257 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001258
hasso508e53e2004-05-18 18:57:06 +00001259 oi = (struct ospf6_interface *) ifp->info;
1260 if (oi == NULL)
1261 oi = ospf6_interface_create (ifp);
1262 assert (oi);
1263
1264 oi->transdelay = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001265 return CMD_SUCCESS;
1266}
1267
1268/* interface variable set command */
1269DEFUN (ipv6_ospf6_retransmitinterval,
1270 ipv6_ospf6_retransmitinterval_cmd,
hasso508e53e2004-05-18 18:57:06 +00001271 "ipv6 ospf6 retransmit-interval <1-65535>",
paul718e3742002-12-13 20:15:29 +00001272 IP6_STR
1273 OSPF6_STR
1274 "Time between retransmitting lost link state advertisements\n"
1275 SECONDS_STR
1276 )
1277{
hasso508e53e2004-05-18 18:57:06 +00001278 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001279 struct interface *ifp;
1280
1281 ifp = (struct interface *) vty->index;
1282 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001283
hasso508e53e2004-05-18 18:57:06 +00001284 oi = (struct ospf6_interface *) ifp->info;
1285 if (oi == NULL)
1286 oi = ospf6_interface_create (ifp);
1287 assert (oi);
1288
1289 oi->rxmt_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001290 return CMD_SUCCESS;
1291}
1292
1293/* interface variable set command */
1294DEFUN (ipv6_ospf6_priority,
1295 ipv6_ospf6_priority_cmd,
hasso508e53e2004-05-18 18:57:06 +00001296 "ipv6 ospf6 priority <0-255>",
paul718e3742002-12-13 20:15:29 +00001297 IP6_STR
1298 OSPF6_STR
1299 "Router priority\n"
hasso508e53e2004-05-18 18:57:06 +00001300 "Priority value\n"
paul718e3742002-12-13 20:15:29 +00001301 )
1302{
hasso508e53e2004-05-18 18:57:06 +00001303 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001304 struct interface *ifp;
1305
1306 ifp = (struct interface *) vty->index;
1307 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001308
hasso508e53e2004-05-18 18:57:06 +00001309 oi = (struct ospf6_interface *) ifp->info;
1310 if (oi == NULL)
1311 oi = ospf6_interface_create (ifp);
1312 assert (oi);
paul718e3742002-12-13 20:15:29 +00001313
hasso508e53e2004-05-18 18:57:06 +00001314 oi->priority = strtol (argv[0], NULL, 10);
1315
1316 if (oi->area)
1317 ospf6_interface_state_change (dr_election (oi), oi);
paul718e3742002-12-13 20:15:29 +00001318
1319 return CMD_SUCCESS;
1320}
1321
1322DEFUN (ipv6_ospf6_instance,
1323 ipv6_ospf6_instance_cmd,
hasso508e53e2004-05-18 18:57:06 +00001324 "ipv6 ospf6 instance-id <0-255>",
paul718e3742002-12-13 20:15:29 +00001325 IP6_STR
1326 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001327 "Instance ID for this interface\n"
1328 "Instance ID value\n"
paul718e3742002-12-13 20:15:29 +00001329 )
1330{
hasso508e53e2004-05-18 18:57:06 +00001331 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001332 struct interface *ifp;
1333
1334 ifp = (struct interface *)vty->index;
1335 assert (ifp);
1336
hasso508e53e2004-05-18 18:57:06 +00001337 oi = (struct ospf6_interface *)ifp->info;
1338 if (oi == NULL)
1339 oi = ospf6_interface_create (ifp);
1340 assert (oi);
paul718e3742002-12-13 20:15:29 +00001341
hasso508e53e2004-05-18 18:57:06 +00001342 oi->instance_id = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001343 return CMD_SUCCESS;
1344}
1345
1346DEFUN (ipv6_ospf6_passive,
1347 ipv6_ospf6_passive_cmd,
1348 "ipv6 ospf6 passive",
1349 IP6_STR
1350 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001351 "passive interface, No adjacency will be formed on this interface\n"
paul718e3742002-12-13 20:15:29 +00001352 )
1353{
hasso508e53e2004-05-18 18:57:06 +00001354 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001355 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +00001356 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +00001357 struct ospf6_neighbor *on;
paul718e3742002-12-13 20:15:29 +00001358
1359 ifp = (struct interface *) vty->index;
1360 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001361
hasso508e53e2004-05-18 18:57:06 +00001362 oi = (struct ospf6_interface *) ifp->info;
1363 if (oi == NULL)
1364 oi = ospf6_interface_create (ifp);
1365 assert (oi);
paul718e3742002-12-13 20:15:29 +00001366
hasso508e53e2004-05-18 18:57:06 +00001367 SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1368 THREAD_OFF (oi->thread_send_hello);
1369
paul1eb8ef22005-04-07 07:30:20 +00001370 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
paul718e3742002-12-13 20:15:29 +00001371 {
hasso508e53e2004-05-18 18:57:06 +00001372 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001373 thread_add_event (master, inactivity_timer, on, 0);
paul718e3742002-12-13 20:15:29 +00001374 }
1375
1376 return CMD_SUCCESS;
1377}
1378
1379DEFUN (no_ipv6_ospf6_passive,
1380 no_ipv6_ospf6_passive_cmd,
1381 "no ipv6 ospf6 passive",
1382 NO_STR
1383 IP6_STR
1384 OSPF6_STR
1385 "passive interface: No Adjacency will be formed on this I/F\n"
1386 )
1387{
hasso508e53e2004-05-18 18:57:06 +00001388 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001389 struct interface *ifp;
1390
1391 ifp = (struct interface *) vty->index;
1392 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001393
hasso508e53e2004-05-18 18:57:06 +00001394 oi = (struct ospf6_interface *) ifp->info;
1395 if (oi == NULL)
1396 oi = ospf6_interface_create (ifp);
1397 assert (oi);
paul718e3742002-12-13 20:15:29 +00001398
hasso508e53e2004-05-18 18:57:06 +00001399 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1400 THREAD_OFF (oi->thread_send_hello);
1401 oi->thread_send_hello =
1402 thread_add_event (master, ospf6_hello_send, oi, 0);
paul718e3742002-12-13 20:15:29 +00001403
1404 return CMD_SUCCESS;
1405}
1406
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001407DEFUN (ipv6_ospf6_mtu_ignore,
1408 ipv6_ospf6_mtu_ignore_cmd,
1409 "ipv6 ospf6 mtu-ignore",
1410 IP6_STR
1411 OSPF6_STR
1412 "Ignore MTU mismatch on this interface\n"
1413 )
1414{
1415 struct ospf6_interface *oi;
1416 struct interface *ifp;
1417
1418 ifp = (struct interface *) vty->index;
1419 assert (ifp);
1420
1421 oi = (struct ospf6_interface *) ifp->info;
1422 if (oi == NULL)
1423 oi = ospf6_interface_create (ifp);
1424 assert (oi);
1425
1426 oi->mtu_ignore = 1;
1427
1428 return CMD_SUCCESS;
1429}
1430
1431DEFUN (no_ipv6_ospf6_mtu_ignore,
1432 no_ipv6_ospf6_mtu_ignore_cmd,
1433 "no ipv6 ospf6 mtu-ignore",
1434 NO_STR
1435 IP6_STR
1436 OSPF6_STR
1437 "Ignore MTU mismatch on this interface\n"
1438 )
1439{
1440 struct ospf6_interface *oi;
1441 struct interface *ifp;
1442
1443 ifp = (struct interface *) vty->index;
1444 assert (ifp);
1445
1446 oi = (struct ospf6_interface *) ifp->info;
1447 if (oi == NULL)
1448 oi = ospf6_interface_create (ifp);
1449 assert (oi);
1450
1451 oi->mtu_ignore = 0;
1452
1453 return CMD_SUCCESS;
1454}
1455
paul718e3742002-12-13 20:15:29 +00001456DEFUN (ipv6_ospf6_advertise_prefix_list,
1457 ipv6_ospf6_advertise_prefix_list_cmd,
1458 "ipv6 ospf6 advertise prefix-list WORD",
1459 IP6_STR
1460 OSPF6_STR
1461 "Advertising options\n"
1462 "Filter prefix using prefix-list\n"
1463 "Prefix list name\n"
1464 )
1465{
hasso508e53e2004-05-18 18:57:06 +00001466 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001467 struct interface *ifp;
1468
1469 ifp = (struct interface *) vty->index;
1470 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001471
hasso508e53e2004-05-18 18:57:06 +00001472 oi = (struct ospf6_interface *) ifp->info;
1473 if (oi == NULL)
1474 oi = ospf6_interface_create (ifp);
1475 assert (oi);
paul718e3742002-12-13 20:15:29 +00001476
hasso508e53e2004-05-18 18:57:06 +00001477 if (oi->plist_name)
1478 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1479 oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
paul718e3742002-12-13 20:15:29 +00001480
hasso508e53e2004-05-18 18:57:06 +00001481 ospf6_interface_connected_route_update (oi->interface);
David Ward2470e992010-01-05 02:45:39 +00001482
1483 if (oi->area)
hasso508e53e2004-05-18 18:57:06 +00001484 {
David Ward2470e992010-01-05 02:45:39 +00001485 OSPF6_LINK_LSA_SCHEDULE (oi);
1486 if (oi->state == OSPF6_INTERFACE_DR)
1487 {
1488 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1489 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1490 }
1491 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
hasso508e53e2004-05-18 18:57:06 +00001492 }
paul718e3742002-12-13 20:15:29 +00001493
1494 return CMD_SUCCESS;
1495}
1496
1497DEFUN (no_ipv6_ospf6_advertise_prefix_list,
1498 no_ipv6_ospf6_advertise_prefix_list_cmd,
1499 "no ipv6 ospf6 advertise prefix-list",
1500 NO_STR
1501 IP6_STR
1502 OSPF6_STR
1503 "Advertising options\n"
1504 "Filter prefix using prefix-list\n"
1505 )
1506{
hasso508e53e2004-05-18 18:57:06 +00001507 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001508 struct interface *ifp;
1509
1510 ifp = (struct interface *) vty->index;
1511 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001512
hasso508e53e2004-05-18 18:57:06 +00001513 oi = (struct ospf6_interface *) ifp->info;
1514 if (oi == NULL)
1515 oi = ospf6_interface_create (ifp);
1516 assert (oi);
1517
1518 if (oi->plist_name)
paul718e3742002-12-13 20:15:29 +00001519 {
hasso508e53e2004-05-18 18:57:06 +00001520 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1521 oi->plist_name = NULL;
paul718e3742002-12-13 20:15:29 +00001522 }
1523
hasso508e53e2004-05-18 18:57:06 +00001524 ospf6_interface_connected_route_update (oi->interface);
David Ward2470e992010-01-05 02:45:39 +00001525
1526 if (oi->area)
hasso508e53e2004-05-18 18:57:06 +00001527 {
David Ward2470e992010-01-05 02:45:39 +00001528 OSPF6_LINK_LSA_SCHEDULE (oi);
1529 if (oi->state == OSPF6_INTERFACE_DR)
1530 {
1531 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1532 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1533 }
1534 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
hasso508e53e2004-05-18 18:57:06 +00001535 }
paul718e3742002-12-13 20:15:29 +00001536
1537 return CMD_SUCCESS;
1538}
1539
Dinesh Duttc5926a92013-08-24 07:55:00 +00001540DEFUN (ipv6_ospf6_network,
1541 ipv6_ospf6_network_cmd,
1542 "ipv6 ospf6 network (broadcast|point-to-point)",
1543 IP6_STR
1544 OSPF6_STR
1545 "Network Type\n"
1546 "Specify OSPFv6 broadcast network\n"
1547 "Specify OSPF6 point-to-point network\n"
1548 )
1549{
1550 struct ospf6_interface *oi;
1551 struct interface *ifp;
1552
1553 ifp = (struct interface *) vty->index;
1554 assert (ifp);
1555
1556 oi = (struct ospf6_interface *) ifp->info;
1557 if (oi == NULL) {
1558 oi = ospf6_interface_create (ifp);
1559 }
1560 assert (oi);
1561
1562 if (strncmp (argv[0], "b", 1) == 0)
1563 {
1564 if (oi->type == OSPF_IFTYPE_BROADCAST)
1565 return CMD_SUCCESS;
1566
1567 oi->type = OSPF_IFTYPE_BROADCAST;
1568 }
1569 else if (strncmp (argv[0], "point-to-p", 10) == 0)
1570 {
1571 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
1572 return CMD_SUCCESS;
1573 }
1574 oi->type = OSPF_IFTYPE_POINTOPOINT;
1575 }
1576
1577 /* Reset the interface */
1578 thread_add_event (master, interface_down, oi, 0);
1579 thread_add_event (master, interface_up, oi, 0);
1580
1581 return CMD_SUCCESS;
1582}
1583
1584DEFUN (no_ipv6_ospf6_network,
1585 no_ipv6_ospf6_network_cmd,
1586 "no ipv6 ospf6 network",
1587 NO_STR
1588 IP6_STR
1589 OSPF6_STR
1590 "Network Type\n"
1591 "Default to whatever interface type system specifies"
1592 )
1593{
1594 struct ospf6_interface *oi;
1595 struct interface *ifp;
1596 int type;
1597
1598 ifp = (struct interface *) vty->index;
1599 assert (ifp);
1600
1601 oi = (struct ospf6_interface *) ifp->info;
1602 if (oi == NULL) {
1603 return CMD_SUCCESS;
1604 }
1605
1606 type = ospf6_default_iftype (ifp);
1607 if (oi->type == type)
1608 {
1609 return CMD_SUCCESS;
1610 }
1611 oi->type = type;
1612
1613 /* Reset the interface */
1614 thread_add_event (master, interface_down, oi, 0);
1615 thread_add_event (master, interface_up, oi, 0);
1616
1617 return CMD_SUCCESS;
1618}
1619
Paul Jakma6ac29a52008-08-15 13:45:30 +01001620static int
hasso508e53e2004-05-18 18:57:06 +00001621config_write_ospf6_interface (struct vty *vty)
paul718e3742002-12-13 20:15:29 +00001622{
hasso52dc7ee2004-09-23 19:18:23 +00001623 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +00001624 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001625 struct interface *ifp;
1626
paul1eb8ef22005-04-07 07:30:20 +00001627 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
paul718e3742002-12-13 20:15:29 +00001628 {
hasso508e53e2004-05-18 18:57:06 +00001629 oi = (struct ospf6_interface *) ifp->info;
1630 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +00001631 continue;
1632
1633 vty_out (vty, "interface %s%s",
hasso049207c2004-08-04 20:02:13 +00001634 oi->interface->name, VNL);
hasso508e53e2004-05-18 18:57:06 +00001635
1636 if (ifp->desc)
hasso049207c2004-08-04 20:02:13 +00001637 vty_out (vty, " description %s%s", ifp->desc, VNL);
hasso1203e1c2004-07-23 21:34:27 +00001638 if (ifp->mtu6 != oi->ifmtu)
hasso049207c2004-08-04 20:02:13 +00001639 vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +04001640
1641 if (oi->cost != OSPF6_INTERFACE_COST)
1642 vty_out (vty, " ipv6 ospf6 cost %d%s",
1643 oi->cost, VNL);
1644
1645 if (oi->hello_interval != OSPF6_INTERFACE_HELLO_INTERVAL)
1646 vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
1647 oi->hello_interval, VNL);
1648
1649 if (oi->dead_interval != OSPF6_INTERFACE_DEAD_INTERVAL)
1650 vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
1651 oi->dead_interval, VNL);
1652
1653 if (oi->rxmt_interval != OSPF6_INTERFACE_RXMT_INTERVAL)
1654 vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
1655 oi->rxmt_interval, VNL);
1656
1657 if (oi->priority != OSPF6_INTERFACE_PRIORITY)
1658 vty_out (vty, " ipv6 ospf6 priority %d%s",
1659 oi->priority, VNL);
1660
1661 if (oi->transdelay != OSPF6_INTERFACE_TRANSDELAY)
1662 vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
1663 oi->transdelay, VNL);
1664
1665 if (oi->instance_id != OSPF6_INTERFACE_INSTANCE_ID)
1666 vty_out (vty, " ipv6 ospf6 instance-id %d%s",
1667 oi->instance_id, VNL);
paul718e3742002-12-13 20:15:29 +00001668
hasso508e53e2004-05-18 18:57:06 +00001669 if (oi->plist_name)
paul718e3742002-12-13 20:15:29 +00001670 vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
hasso049207c2004-08-04 20:02:13 +00001671 oi->plist_name, VNL);
paul718e3742002-12-13 20:15:29 +00001672
hasso508e53e2004-05-18 18:57:06 +00001673 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
hasso049207c2004-08-04 20:02:13 +00001674 vty_out (vty, " ipv6 ospf6 passive%s", VNL);
paul718e3742002-12-13 20:15:29 +00001675
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001676 if (oi->mtu_ignore)
1677 vty_out (vty, " ipv6 ospf6 mtu-ignore%s", VNL);
1678
Dinesh Duttc5926a92013-08-24 07:55:00 +00001679 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
1680 vty_out (vty, " ipv6 ospf6 network point-to-point%s", VNL);
1681 else if (oi->type == OSPF_IFTYPE_BROADCAST)
1682 vty_out (vty, " ipv6 ospf6 network broadcast%s", VNL);
1683
hasso049207c2004-08-04 20:02:13 +00001684 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +00001685 }
1686 return 0;
1687}
1688
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08001689static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +00001690{
1691 INTERFACE_NODE,
1692 "%s(config-if)# ",
hasso69b4a812004-08-26 18:10:36 +00001693 1 /* VTYSH */
paul718e3742002-12-13 20:15:29 +00001694};
1695
1696void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001697ospf6_interface_init (void)
paul718e3742002-12-13 20:15:29 +00001698{
1699 /* Install interface node. */
hasso508e53e2004-05-18 18:57:06 +00001700 install_node (&interface_node, config_write_ospf6_interface);
paul718e3742002-12-13 20:15:29 +00001701
1702 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
hasso508e53e2004-05-18 18:57:06 +00001703 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1704 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1705 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001706 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
hasso508e53e2004-05-18 18:57:06 +00001707 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1708 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1709 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001710 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
hasso508e53e2004-05-18 18:57:06 +00001711 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1712 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1713 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001714 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
hasso508e53e2004-05-18 18:57:06 +00001715 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1716 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1717 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001718
hasso508e53e2004-05-18 18:57:06 +00001719 install_element (CONFIG_NODE, &interface_cmd);
paul718e3742002-12-13 20:15:29 +00001720 install_default (INTERFACE_NODE);
1721 install_element (INTERFACE_NODE, &interface_desc_cmd);
1722 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1723 install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
hassob596c712004-07-09 18:33:43 +00001724 install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
hasso049207c2004-08-04 20:02:13 +00001725 install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
paul718e3742002-12-13 20:15:29 +00001726 install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
1727 install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
1728 install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
1729 install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
1730 install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
1731 install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
hasso508e53e2004-05-18 18:57:06 +00001732
paul718e3742002-12-13 20:15:29 +00001733 install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
1734 install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
hasso508e53e2004-05-18 18:57:06 +00001735
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001736 install_element (INTERFACE_NODE, &ipv6_ospf6_mtu_ignore_cmd);
1737 install_element (INTERFACE_NODE, &no_ipv6_ospf6_mtu_ignore_cmd);
1738
hasso508e53e2004-05-18 18:57:06 +00001739 install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
1740 install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
Dinesh Duttc5926a92013-08-24 07:55:00 +00001741
1742 install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
1743 install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
hasso508e53e2004-05-18 18:57:06 +00001744}
1745
1746DEFUN (debug_ospf6_interface,
1747 debug_ospf6_interface_cmd,
1748 "debug ospf6 interface",
1749 DEBUG_STR
1750 OSPF6_STR
1751 "Debug OSPFv3 Interface\n"
1752 )
1753{
1754 OSPF6_DEBUG_INTERFACE_ON ();
1755 return CMD_SUCCESS;
1756}
1757
1758DEFUN (no_debug_ospf6_interface,
1759 no_debug_ospf6_interface_cmd,
1760 "no debug ospf6 interface",
1761 NO_STR
1762 DEBUG_STR
1763 OSPF6_STR
1764 "Debug OSPFv3 Interface\n"
1765 )
1766{
hasso3b687352004-08-19 06:56:53 +00001767 OSPF6_DEBUG_INTERFACE_OFF ();
hasso508e53e2004-05-18 18:57:06 +00001768 return CMD_SUCCESS;
1769}
1770
1771int
1772config_write_ospf6_debug_interface (struct vty *vty)
1773{
1774 if (IS_OSPF6_DEBUG_INTERFACE)
hasso049207c2004-08-04 20:02:13 +00001775 vty_out (vty, "debug ospf6 interface%s", VNL);
hasso508e53e2004-05-18 18:57:06 +00001776 return 0;
1777}
1778
1779void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001780install_element_ospf6_debug_interface (void)
hasso508e53e2004-05-18 18:57:06 +00001781{
1782 install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
1783 install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
1784 install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
1785 install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
paul718e3742002-12-13 20:15:29 +00001786}
1787
1788