blob: fee1632a1a557e18702262c3a7174ee337727d3c [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
Dinesh Dutta0edf672013-08-26 03:40:23 +000076ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa, unsigned int reason)
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);
Dinesh Dutta0edf672013-08-26 03:40:23 +000089 ospf6_spf_schedule (oi->area->ospf6, reason);
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 Dutta0edf672013-08-26 03:40:23 +000097static void
98ospf6_interface_lsdb_hook_add (struct ospf6_lsa *lsa)
99{
100 ospf6_interface_lsdb_hook(lsa, ospf6_lsadd_to_spf_reason(lsa));
101}
102
103static void
104ospf6_interface_lsdb_hook_remove (struct ospf6_lsa *lsa)
105{
106 ospf6_interface_lsdb_hook(lsa, ospf6_lsremove_to_spf_reason(lsa));
107}
108
Dinesh Duttc5926a92013-08-24 07:55:00 +0000109static u_char
110ospf6_default_iftype(struct interface *ifp)
111{
112 if (if_is_pointopoint (ifp))
113 return OSPF_IFTYPE_POINTOPOINT;
114 else if (if_is_loopback (ifp))
115 return OSPF_IFTYPE_LOOPBACK;
116 else
117 return OSPF_IFTYPE_BROADCAST;
118}
119
paul718e3742002-12-13 20:15:29 +0000120/* Create new ospf6 interface structure */
121struct ospf6_interface *
122ospf6_interface_create (struct interface *ifp)
123{
hasso508e53e2004-05-18 18:57:06 +0000124 struct ospf6_interface *oi;
paul0c083ee2004-10-10 12:54:58 +0000125 unsigned int iobuflen;
paul718e3742002-12-13 20:15:29 +0000126
hasso508e53e2004-05-18 18:57:06 +0000127 oi = (struct ospf6_interface *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700128 XCALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
paul718e3742002-12-13 20:15:29 +0000129
Stephen Hemminger393deb92008-08-18 14:13:29 -0700130 if (!oi)
paul718e3742002-12-13 20:15:29 +0000131 {
132 zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
133 return (struct ospf6_interface *) NULL;
134 }
135
hasso508e53e2004-05-18 18:57:06 +0000136 oi->area = (struct ospf6_area *) NULL;
137 oi->neighbor_list = list_new ();
138 oi->neighbor_list->cmp = ospf6_neighbor_cmp;
139 oi->linklocal_addr = (struct in6_addr *) NULL;
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +0400140 oi->instance_id = OSPF6_INTERFACE_INSTANCE_ID;
141 oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
142 oi->priority = OSPF6_INTERFACE_PRIORITY;
paul718e3742002-12-13 20:15:29 +0000143
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700144 oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
145 oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
146 oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +0400147 oi->cost = OSPF6_INTERFACE_COST;
Dinesh Duttc5926a92013-08-24 07:55:00 +0000148 oi->type = ospf6_default_iftype (ifp);
hasso508e53e2004-05-18 18:57:06 +0000149 oi->state = OSPF6_INTERFACE_DOWN;
150 oi->flag = 0;
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +0400151 oi->mtu_ignore = 0;
paul718e3742002-12-13 20:15:29 +0000152
hassob596c712004-07-09 18:33:43 +0000153 /* Try to adjust I/O buffer size with IfMtu */
hasso1203e1c2004-07-23 21:34:27 +0000154 oi->ifmtu = ifp->mtu6;
155 iobuflen = ospf6_iobuf_size (ifp->mtu6);
hassob596c712004-07-09 18:33:43 +0000156 if (oi->ifmtu > iobuflen)
hasso3b4cd3a2004-05-18 19:28:32 +0000157 {
hasso1e058382004-09-01 21:36:14 +0000158 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000159 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
160 ifp->name, iobuflen);
hasso3b4cd3a2004-05-18 19:28:32 +0000161 oi->ifmtu = iobuflen;
162 }
hasso3b4cd3a2004-05-18 19:28:32 +0000163
hasso6452df02004-08-15 05:52:07 +0000164 oi->lsupdate_list = ospf6_lsdb_create (oi);
165 oi->lsack_list = ospf6_lsdb_create (oi);
166 oi->lsdb = ospf6_lsdb_create (oi);
Dinesh Dutta0edf672013-08-26 03:40:23 +0000167 oi->lsdb->hook_add = ospf6_interface_lsdb_hook_add;
168 oi->lsdb->hook_remove = ospf6_interface_lsdb_hook_remove;
hasso6452df02004-08-15 05:52:07 +0000169 oi->lsdb_self = ospf6_lsdb_create (oi);
paul718e3742002-12-13 20:15:29 +0000170
Paul Jakmacf1ce252006-05-15 10:46:07 +0000171 oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
172 oi->route_connected->scope = oi;
paul718e3742002-12-13 20:15:29 +0000173
174 /* link both */
hasso508e53e2004-05-18 18:57:06 +0000175 oi->interface = ifp;
176 ifp->info = oi;
paul718e3742002-12-13 20:15:29 +0000177
hasso508e53e2004-05-18 18:57:06 +0000178 return oi;
paul718e3742002-12-13 20:15:29 +0000179}
180
181void
hasso508e53e2004-05-18 18:57:06 +0000182ospf6_interface_delete (struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +0000183{
paul1eb8ef22005-04-07 07:30:20 +0000184 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000185 struct ospf6_neighbor *on;
paul718e3742002-12-13 20:15:29 +0000186
paul1eb8ef22005-04-07 07:30:20 +0000187 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso508e53e2004-05-18 18:57:06 +0000188 ospf6_neighbor_delete (on);
paul1eb8ef22005-04-07 07:30:20 +0000189
hasso508e53e2004-05-18 18:57:06 +0000190 list_delete (oi->neighbor_list);
paul718e3742002-12-13 20:15:29 +0000191
hasso508e53e2004-05-18 18:57:06 +0000192 THREAD_OFF (oi->thread_send_hello);
193 THREAD_OFF (oi->thread_send_lsupdate);
194 THREAD_OFF (oi->thread_send_lsack);
paul718e3742002-12-13 20:15:29 +0000195
hasso508e53e2004-05-18 18:57:06 +0000196 ospf6_lsdb_remove_all (oi->lsdb);
197 ospf6_lsdb_remove_all (oi->lsupdate_list);
198 ospf6_lsdb_remove_all (oi->lsack_list);
199
200 ospf6_lsdb_delete (oi->lsdb);
hasso6452df02004-08-15 05:52:07 +0000201 ospf6_lsdb_delete (oi->lsdb_self);
202
hasso508e53e2004-05-18 18:57:06 +0000203 ospf6_lsdb_delete (oi->lsupdate_list);
204 ospf6_lsdb_delete (oi->lsack_list);
205
206 ospf6_route_table_delete (oi->route_connected);
paul718e3742002-12-13 20:15:29 +0000207
208 /* cut link */
hasso508e53e2004-05-18 18:57:06 +0000209 oi->interface->info = NULL;
paul718e3742002-12-13 20:15:29 +0000210
211 /* plist_name */
hasso508e53e2004-05-18 18:57:06 +0000212 if (oi->plist_name)
213 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
paul718e3742002-12-13 20:15:29 +0000214
hasso508e53e2004-05-18 18:57:06 +0000215 XFREE (MTYPE_OSPF6_IF, oi);
216}
217
218void
219ospf6_interface_enable (struct ospf6_interface *oi)
220{
221 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
222
223 oi->thread_send_hello =
224 thread_add_event (master, ospf6_hello_send, oi, 0);
225}
226
227void
228ospf6_interface_disable (struct ospf6_interface *oi)
229{
paul1eb8ef22005-04-07 07:30:20 +0000230 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000231 struct ospf6_neighbor *on;
232
233 SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
234
paul1eb8ef22005-04-07 07:30:20 +0000235 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso508e53e2004-05-18 18:57:06 +0000236 ospf6_neighbor_delete (on);
paul1eb8ef22005-04-07 07:30:20 +0000237
hasso508e53e2004-05-18 18:57:06 +0000238 list_delete_all_node (oi->neighbor_list);
239
240 ospf6_lsdb_remove_all (oi->lsdb);
241 ospf6_lsdb_remove_all (oi->lsupdate_list);
242 ospf6_lsdb_remove_all (oi->lsack_list);
243
244 THREAD_OFF (oi->thread_send_hello);
245 THREAD_OFF (oi->thread_send_lsupdate);
246 THREAD_OFF (oi->thread_send_lsack);
paul718e3742002-12-13 20:15:29 +0000247}
248
249static struct in6_addr *
hasso508e53e2004-05-18 18:57:06 +0000250ospf6_interface_get_linklocal_address (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000251{
hasso52dc7ee2004-09-23 19:18:23 +0000252 struct listnode *n;
paul718e3742002-12-13 20:15:29 +0000253 struct connected *c;
254 struct in6_addr *l = (struct in6_addr *) NULL;
255
256 /* for each connected address */
paul1eb8ef22005-04-07 07:30:20 +0000257 for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
paul718e3742002-12-13 20:15:29 +0000258 {
paul718e3742002-12-13 20:15:29 +0000259 /* if family not AF_INET6, ignore */
260 if (c->address->family != AF_INET6)
261 continue;
262
263 /* linklocal scope check */
264 if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
265 l = &c->address->u.prefix6;
266 }
267 return l;
268}
269
270void
271ospf6_interface_if_add (struct interface *ifp)
272{
hasso508e53e2004-05-18 18:57:06 +0000273 struct ospf6_interface *oi;
paul0c083ee2004-10-10 12:54:58 +0000274 unsigned int iobuflen;
paul718e3742002-12-13 20:15:29 +0000275
hasso508e53e2004-05-18 18:57:06 +0000276 oi = (struct ospf6_interface *) ifp->info;
277 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000278 return;
279
hassob596c712004-07-09 18:33:43 +0000280 /* Try to adjust I/O buffer size with IfMtu */
281 if (oi->ifmtu == 0)
hasso1203e1c2004-07-23 21:34:27 +0000282 oi->ifmtu = ifp->mtu6;
283 iobuflen = ospf6_iobuf_size (ifp->mtu6);
hassob596c712004-07-09 18:33:43 +0000284 if (oi->ifmtu > iobuflen)
hasso3b4cd3a2004-05-18 19:28:32 +0000285 {
hasso1e058382004-09-01 21:36:14 +0000286 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000287 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
288 ifp->name, iobuflen);
hasso3b4cd3a2004-05-18 19:28:32 +0000289 oi->ifmtu = iobuflen;
290 }
paul718e3742002-12-13 20:15:29 +0000291
292 /* interface start */
hasso508e53e2004-05-18 18:57:06 +0000293 if (oi->area)
294 thread_add_event (master, interface_up, oi, 0);
paul718e3742002-12-13 20:15:29 +0000295}
296
297void
298ospf6_interface_if_del (struct interface *ifp)
299{
hasso508e53e2004-05-18 18:57:06 +0000300 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000301
hasso508e53e2004-05-18 18:57:06 +0000302 oi = (struct ospf6_interface *) ifp->info;
303 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000304 return;
305
306 /* interface stop */
hasso508e53e2004-05-18 18:57:06 +0000307 if (oi->area)
308 thread_execute (master, interface_down, oi, 0);
paul718e3742002-12-13 20:15:29 +0000309
hasso508e53e2004-05-18 18:57:06 +0000310 listnode_delete (oi->area->if_list, oi);
311 oi->area = (struct ospf6_area *) NULL;
paul718e3742002-12-13 20:15:29 +0000312
313 /* cut link */
hasso508e53e2004-05-18 18:57:06 +0000314 oi->interface = NULL;
paul718e3742002-12-13 20:15:29 +0000315 ifp->info = NULL;
316
hasso508e53e2004-05-18 18:57:06 +0000317 ospf6_interface_delete (oi);
paul718e3742002-12-13 20:15:29 +0000318}
319
320void
321ospf6_interface_state_update (struct interface *ifp)
322{
hasso508e53e2004-05-18 18:57:06 +0000323 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000324
hasso508e53e2004-05-18 18:57:06 +0000325 oi = (struct ospf6_interface *) ifp->info;
326 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000327 return;
hasso508e53e2004-05-18 18:57:06 +0000328 if (oi->area == NULL)
paul718e3742002-12-13 20:15:29 +0000329 return;
330
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000331 if (if_is_operative (ifp))
hasso508e53e2004-05-18 18:57:06 +0000332 thread_add_event (master, interface_up, oi, 0);
paul718e3742002-12-13 20:15:29 +0000333 else
hasso508e53e2004-05-18 18:57:06 +0000334 thread_add_event (master, interface_down, oi, 0);
paul718e3742002-12-13 20:15:29 +0000335
336 return;
337}
338
339void
hasso508e53e2004-05-18 18:57:06 +0000340ospf6_interface_connected_route_update (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000341{
hasso508e53e2004-05-18 18:57:06 +0000342 struct ospf6_interface *oi;
343 struct ospf6_route *route;
344 struct connected *c;
paul1eb8ef22005-04-07 07:30:20 +0000345 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000346
hasso508e53e2004-05-18 18:57:06 +0000347 oi = (struct ospf6_interface *) ifp->info;
348 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +0000349 return;
350
351 /* reset linklocal pointer */
hasso508e53e2004-05-18 18:57:06 +0000352 oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
paul718e3742002-12-13 20:15:29 +0000353
hasso508e53e2004-05-18 18:57:06 +0000354 /* if area is null, do not make connected-route list */
355 if (oi->area == NULL)
paul718e3742002-12-13 20:15:29 +0000356 return;
357
hasso508e53e2004-05-18 18:57:06 +0000358 /* update "route to advertise" interface route table */
359 ospf6_route_remove_all (oi->route_connected);
hasso508e53e2004-05-18 18:57:06 +0000360
paul1eb8ef22005-04-07 07:30:20 +0000361 for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
362 {
hasso508e53e2004-05-18 18:57:06 +0000363 if (c->address->family != AF_INET6)
364 continue;
365
hasso1e058382004-09-01 21:36:14 +0000366 CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
367 CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
368 CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
369 CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
370 CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
hasso508e53e2004-05-18 18:57:06 +0000371
372 /* apply filter */
373 if (oi->plist_name)
374 {
375 struct prefix_list *plist;
376 enum prefix_list_type ret;
377 char buf[128];
378
379 prefix2str (c->address, buf, sizeof (buf));
380 plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
381 ret = prefix_list_apply (plist, (void *) c->address);
382 if (ret == PREFIX_DENY)
383 {
hasso1e058382004-09-01 21:36:14 +0000384 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000385 zlog_debug ("%s on %s filtered by prefix-list %s ",
386 buf, oi->interface->name, oi->plist_name);
hasso508e53e2004-05-18 18:57:06 +0000387 continue;
388 }
389 }
390
391 route = ospf6_route_create ();
392 memcpy (&route->prefix, c->address, sizeof (struct prefix));
393 apply_mask (&route->prefix);
394 route->type = OSPF6_DEST_TYPE_NETWORK;
395 route->path.area_id = oi->area->area_id;
396 route->path.type = OSPF6_PATH_TYPE_INTRA;
397 route->path.cost = oi->cost;
398 route->nexthop[0].ifindex = oi->interface->ifindex;
399 inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
400 ospf6_route_add (route, oi->route_connected);
401 }
402
paul718e3742002-12-13 20:15:29 +0000403 /* create new Link-LSA */
hasso508e53e2004-05-18 18:57:06 +0000404 OSPF6_LINK_LSA_SCHEDULE (oi);
405 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
406 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
paul718e3742002-12-13 20:15:29 +0000407}
408
hasso508e53e2004-05-18 18:57:06 +0000409static void
410ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +0000411{
hasso508e53e2004-05-18 18:57:06 +0000412 u_char prev_state;
paul718e3742002-12-13 20:15:29 +0000413
hasso508e53e2004-05-18 18:57:06 +0000414 prev_state = oi->state;
415 oi->state = next_state;
paul718e3742002-12-13 20:15:29 +0000416
hasso508e53e2004-05-18 18:57:06 +0000417 if (prev_state == next_state)
418 return;
paul718e3742002-12-13 20:15:29 +0000419
hasso508e53e2004-05-18 18:57:06 +0000420 /* log */
421 if (IS_OSPF6_DEBUG_INTERFACE)
paul718e3742002-12-13 20:15:29 +0000422 {
hassoc6487d62004-12-24 06:00:11 +0000423 zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
424 ospf6_interface_state_str[prev_state],
425 ospf6_interface_state_str[next_state]);
paul718e3742002-12-13 20:15:29 +0000426 }
Vincent Bernat3bc4f842012-06-04 11:40:04 +0200427 oi->state_change++;
paul718e3742002-12-13 20:15:29 +0000428
hasso508e53e2004-05-18 18:57:06 +0000429 if ((prev_state == OSPF6_INTERFACE_DR ||
430 prev_state == OSPF6_INTERFACE_BDR) &&
431 (next_state != OSPF6_INTERFACE_DR &&
432 next_state != OSPF6_INTERFACE_BDR))
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400433 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP);
Dinesh Duttc5926a92013-08-24 07:55:00 +0000434
hasso508e53e2004-05-18 18:57:06 +0000435 if ((prev_state != OSPF6_INTERFACE_DR &&
436 prev_state != OSPF6_INTERFACE_BDR) &&
437 (next_state == OSPF6_INTERFACE_DR ||
438 next_state == OSPF6_INTERFACE_BDR))
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400439 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP);
paul718e3742002-12-13 20:15:29 +0000440
hasso508e53e2004-05-18 18:57:06 +0000441 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
hasso6452df02004-08-15 05:52:07 +0000442 if (next_state == OSPF6_INTERFACE_DOWN)
443 {
444 OSPF6_NETWORK_LSA_EXECUTE (oi);
445 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
446 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
447 }
448 else if (prev_state == OSPF6_INTERFACE_DR ||
449 next_state == OSPF6_INTERFACE_DR)
paul718e3742002-12-13 20:15:29 +0000450 {
hasso508e53e2004-05-18 18:57:06 +0000451 OSPF6_NETWORK_LSA_SCHEDULE (oi);
452 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
453 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
paul718e3742002-12-13 20:15:29 +0000454 }
Vincent Bernatbf836662012-06-04 14:36:12 +0200455
456#ifdef HAVE_SNMP
457 /* Terminal state or regression */
458 if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
459 (next_state == OSPF6_INTERFACE_DROTHER) ||
460 (next_state == OSPF6_INTERFACE_BDR) ||
461 (next_state == OSPF6_INTERFACE_DR) ||
462 (next_state < prev_state))
463 ospf6TrapIfStateChange (oi);
464#endif
465
hasso508e53e2004-05-18 18:57:06 +0000466}
467
468
469/* DR Election, RFC2328 section 9.4 */
470
471#define IS_ELIGIBLE(n) \
472 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
473
474static struct ospf6_neighbor *
475better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
476{
477 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
478 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
479 return NULL;
480 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
481 return b;
482 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
483 return a;
484
485 if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
486 return a;
487 if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
488 return b;
489
490 if (a->priority > b->priority)
491 return a;
492 if (a->priority < b->priority)
493 return b;
494
495 if (ntohl (a->router_id) > ntohl (b->router_id))
496 return a;
497 if (ntohl (a->router_id) < ntohl (b->router_id))
498 return b;
499
500 zlog_warn ("Router-ID duplicate ?");
501 return a;
502}
503
504static struct ospf6_neighbor *
505better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
506{
507 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
508 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
509 return NULL;
510 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
511 return b;
512 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
513 return a;
514
515 if (a->drouter == a->router_id && b->drouter != b->router_id)
516 return a;
517 if (a->drouter != a->router_id && b->drouter == b->router_id)
518 return b;
519
520 if (a->priority > b->priority)
521 return a;
522 if (a->priority < b->priority)
523 return b;
524
525 if (ntohl (a->router_id) > ntohl (b->router_id))
526 return a;
527 if (ntohl (a->router_id) < ntohl (b->router_id))
528 return b;
529
530 zlog_warn ("Router-ID duplicate ?");
531 return a;
532}
533
534static u_char
535dr_election (struct ospf6_interface *oi)
536{
paul1eb8ef22005-04-07 07:30:20 +0000537 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000538 struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
539 struct ospf6_neighbor *best_drouter, *best_bdrouter;
540 u_char next_state = 0;
541
542 drouter = bdrouter = NULL;
543 best_drouter = best_bdrouter = NULL;
544
545 /* pseudo neighbor myself, including noting current DR/BDR (1) */
546 memset (&myself, 0, sizeof (myself));
547 inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
548 sizeof (myself.name));
549 myself.state = OSPF6_NEIGHBOR_TWOWAY;
550 myself.drouter = oi->drouter;
551 myself.bdrouter = oi->bdrouter;
552 myself.priority = oi->priority;
553 myself.router_id = oi->area->ospf6->router_id;
554
555 /* Electing BDR (2) */
paul1eb8ef22005-04-07 07:30:20 +0000556 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
557 bdrouter = better_bdrouter (bdrouter, on);
558
hasso508e53e2004-05-18 18:57:06 +0000559 best_bdrouter = bdrouter;
560 bdrouter = better_bdrouter (best_bdrouter, &myself);
561
562 /* Electing DR (3) */
paul1eb8ef22005-04-07 07:30:20 +0000563 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
564 drouter = better_drouter (drouter, on);
565
hasso508e53e2004-05-18 18:57:06 +0000566 best_drouter = drouter;
567 drouter = better_drouter (best_drouter, &myself);
568 if (drouter == NULL)
569 drouter = bdrouter;
570
571 /* the router itself is newly/no longer DR/BDR (4) */
572 if ((drouter == &myself && myself.drouter != myself.router_id) ||
573 (drouter != &myself && myself.drouter == myself.router_id) ||
574 (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
575 (bdrouter != &myself && myself.bdrouter == myself.router_id))
576 {
577 myself.drouter = (drouter ? drouter->router_id : htonl (0));
578 myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
579
580 /* compatible to Electing BDR (2) */
581 bdrouter = better_bdrouter (best_bdrouter, &myself);
582
583 /* compatible to Electing DR (3) */
584 drouter = better_drouter (best_drouter, &myself);
585 if (drouter == NULL)
586 drouter = bdrouter;
587 }
588
589 /* Set interface state accordingly (5) */
590 if (drouter && drouter == &myself)
591 next_state = OSPF6_INTERFACE_DR;
592 else if (bdrouter && bdrouter == &myself)
593 next_state = OSPF6_INTERFACE_BDR;
594 else
595 next_state = OSPF6_INTERFACE_DROTHER;
596
597 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
598 /* XXX */
599
600 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
601 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
602 accordingly after AdjOK */
603 if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
604 oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
605 {
606 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000607 zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
608 (drouter ? drouter->name : "0.0.0.0"),
609 (bdrouter ? bdrouter->name : "0.0.0.0"));
hasso508e53e2004-05-18 18:57:06 +0000610
paul1eb8ef22005-04-07 07:30:20 +0000611 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
hasso508e53e2004-05-18 18:57:06 +0000612 {
hasso508e53e2004-05-18 18:57:06 +0000613 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
614 continue;
615 /* Schedule AdjOK. */
616 thread_add_event (master, adj_ok, on, 0);
617 }
618 }
619
620 oi->drouter = (drouter ? drouter->router_id : htonl (0));
621 oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
622 return next_state;
623}
624
625
626/* Interface State Machine */
627int
628interface_up (struct thread *thread)
629{
630 struct ospf6_interface *oi;
631
632 oi = (struct ospf6_interface *) THREAD_ARG (thread);
633 assert (oi && oi->interface);
634
635 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000636 zlog_debug ("Interface Event %s: [InterfaceUp]",
637 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000638
639 /* check physical interface is up */
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000640 if (! if_is_operative (oi->interface))
hasso508e53e2004-05-18 18:57:06 +0000641 {
642 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000643 zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
644 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000645 return 0;
646 }
647
648 /* if already enabled, do nothing */
649 if (oi->state > OSPF6_INTERFACE_DOWN)
650 {
651 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000652 zlog_debug ("Interface %s already enabled",
653 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000654 return 0;
655 }
656
657 /* Join AllSPFRouters */
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400658 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP);
hasso508e53e2004-05-18 18:57:06 +0000659
660 /* Update interface route */
661 ospf6_interface_connected_route_update (oi->interface);
662
663 /* Schedule Hello */
664 if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
665 thread_add_event (master, ospf6_hello_send, oi, 0);
666
667 /* decide next interface state */
Dinesh Duttc5926a92013-08-24 07:55:00 +0000668 if ((if_is_pointopoint (oi->interface)) ||
669 (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
hasso508e53e2004-05-18 18:57:06 +0000670 ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
Dinesh Duttc5926a92013-08-24 07:55:00 +0000671 }
hasso508e53e2004-05-18 18:57:06 +0000672 else if (oi->priority == 0)
673 ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
674 else
675 {
676 ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
677 thread_add_timer (master, wait_timer, oi, oi->dead_interval);
678 }
679
680 return 0;
paul718e3742002-12-13 20:15:29 +0000681}
682
683int
hasso508e53e2004-05-18 18:57:06 +0000684wait_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000685{
hasso508e53e2004-05-18 18:57:06 +0000686 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000687
hasso508e53e2004-05-18 18:57:06 +0000688 oi = (struct ospf6_interface *) THREAD_ARG (thread);
689 assert (oi && oi->interface);
paul718e3742002-12-13 20:15:29 +0000690
hasso508e53e2004-05-18 18:57:06 +0000691 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000692 zlog_debug ("Interface Event %s: [WaitTimer]",
693 oi->interface->name);
paul718e3742002-12-13 20:15:29 +0000694
hasso508e53e2004-05-18 18:57:06 +0000695 if (oi->state == OSPF6_INTERFACE_WAITING)
696 ospf6_interface_state_change (dr_election (oi), oi);
paul718e3742002-12-13 20:15:29 +0000697
hasso508e53e2004-05-18 18:57:06 +0000698 return 0;
paul718e3742002-12-13 20:15:29 +0000699}
700
hasso508e53e2004-05-18 18:57:06 +0000701int
702backup_seen (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000703{
hasso508e53e2004-05-18 18:57:06 +0000704 struct ospf6_interface *oi;
705
706 oi = (struct ospf6_interface *) THREAD_ARG (thread);
707 assert (oi && oi->interface);
708
709 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000710 zlog_debug ("Interface Event %s: [BackupSeen]",
711 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000712
713 if (oi->state == OSPF6_INTERFACE_WAITING)
714 ospf6_interface_state_change (dr_election (oi), oi);
715
716 return 0;
paul718e3742002-12-13 20:15:29 +0000717}
718
hasso508e53e2004-05-18 18:57:06 +0000719int
720neighbor_change (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000721{
hasso508e53e2004-05-18 18:57:06 +0000722 struct ospf6_interface *oi;
723
724 oi = (struct ospf6_interface *) THREAD_ARG (thread);
725 assert (oi && oi->interface);
726
727 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000728 zlog_debug ("Interface Event %s: [NeighborChange]",
729 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000730
731 if (oi->state == OSPF6_INTERFACE_DROTHER ||
732 oi->state == OSPF6_INTERFACE_BDR ||
733 oi->state == OSPF6_INTERFACE_DR)
734 ospf6_interface_state_change (dr_election (oi), oi);
735
736 return 0;
paul718e3742002-12-13 20:15:29 +0000737}
738
hasso508e53e2004-05-18 18:57:06 +0000739int
740interface_down (struct thread *thread)
741{
742 struct ospf6_interface *oi;
paul1eb8ef22005-04-07 07:30:20 +0000743 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000744 struct ospf6_neighbor *on;
745
746 oi = (struct ospf6_interface *) THREAD_ARG (thread);
747 assert (oi && oi->interface);
748
749 if (IS_OSPF6_DEBUG_INTERFACE)
hassoc6487d62004-12-24 06:00:11 +0000750 zlog_debug ("Interface Event %s: [InterfaceDown]",
751 oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000752
753 /* Leave AllSPFRouters */
754 if (oi->state > OSPF6_INTERFACE_DOWN)
Vyacheslav Trushkin9a9446e2011-11-21 20:26:39 +0400755 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_LEAVE_GROUP);
hasso508e53e2004-05-18 18:57:06 +0000756
757 ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
758
paul1eb8ef22005-04-07 07:30:20 +0000759 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
760 ospf6_neighbor_delete (on);
761
hasso508e53e2004-05-18 18:57:06 +0000762 list_delete_all_node (oi->neighbor_list);
763
764 return 0;
765}
766
767
paul718e3742002-12-13 20:15:29 +0000768/* show specified interface structure */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100769static int
hasso508e53e2004-05-18 18:57:06 +0000770ospf6_interface_show (struct vty *vty, struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000771{
hasso508e53e2004-05-18 18:57:06 +0000772 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000773 struct connected *c;
774 struct prefix *p;
hasso52dc7ee2004-09-23 19:18:23 +0000775 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000776 char strbuf[64], drouter[32], bdrouter[32];
paul0c083ee2004-10-10 12:54:58 +0000777 const char *updown[3] = {"down", "up", NULL};
778 const char *type;
hasso508e53e2004-05-18 18:57:06 +0000779 struct timeval res, now;
780 char duration[32];
781 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000782
783 /* check physical interface type */
hasso508e53e2004-05-18 18:57:06 +0000784 if (if_is_loopback (ifp))
paul718e3742002-12-13 20:15:29 +0000785 type = "LOOPBACK";
hasso508e53e2004-05-18 18:57:06 +0000786 else if (if_is_broadcast (ifp))
paul718e3742002-12-13 20:15:29 +0000787 type = "BROADCAST";
hasso508e53e2004-05-18 18:57:06 +0000788 else if (if_is_pointopoint (ifp))
paul718e3742002-12-13 20:15:29 +0000789 type = "POINTOPOINT";
790 else
791 type = "UNKNOWN";
792
793 vty_out (vty, "%s is %s, type %s%s",
Dinesh Dutte7ad6b22013-08-24 07:55:57 +0000794 ifp->name, updown[if_is_operative (ifp)], type,
hasso049207c2004-08-04 20:02:13 +0000795 VNL);
796 vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
paul718e3742002-12-13 20:15:29 +0000797
hasso508e53e2004-05-18 18:57:06 +0000798 if (ifp->info == NULL)
paul718e3742002-12-13 20:15:29 +0000799 {
hasso049207c2004-08-04 20:02:13 +0000800 vty_out (vty, " OSPF not enabled on this interface%s", VNL);
paul718e3742002-12-13 20:15:29 +0000801 return 0;
802 }
803 else
hasso508e53e2004-05-18 18:57:06 +0000804 oi = (struct ospf6_interface *) ifp->info;
paul718e3742002-12-13 20:15:29 +0000805
hasso049207c2004-08-04 20:02:13 +0000806 vty_out (vty, " Internet Address:%s", VNL);
paul1eb8ef22005-04-07 07:30:20 +0000807
808 for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
paul718e3742002-12-13 20:15:29 +0000809 {
paul718e3742002-12-13 20:15:29 +0000810 p = c->address;
811 prefix2str (p, strbuf, sizeof (strbuf));
812 switch (p->family)
813 {
814 case AF_INET:
hasso508e53e2004-05-18 18:57:06 +0000815 vty_out (vty, " inet : %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000816 VNL);
paul718e3742002-12-13 20:15:29 +0000817 break;
818 case AF_INET6:
hasso508e53e2004-05-18 18:57:06 +0000819 vty_out (vty, " inet6: %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000820 VNL);
paul718e3742002-12-13 20:15:29 +0000821 break;
822 default:
hasso508e53e2004-05-18 18:57:06 +0000823 vty_out (vty, " ??? : %s%s", strbuf,
hasso049207c2004-08-04 20:02:13 +0000824 VNL);
paul718e3742002-12-13 20:15:29 +0000825 break;
826 }
827 }
828
hasso508e53e2004-05-18 18:57:06 +0000829 if (oi->area)
paul718e3742002-12-13 20:15:29 +0000830 {
hasso508e53e2004-05-18 18:57:06 +0000831 vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
hasso049207c2004-08-04 20:02:13 +0000832 oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +0400833 vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ?
834 "disabled" : "enabled", VNL);
hasso508e53e2004-05-18 18:57:06 +0000835 inet_ntop (AF_INET, &oi->area->area_id,
paul718e3742002-12-13 20:15:29 +0000836 strbuf, sizeof (strbuf));
hasso508e53e2004-05-18 18:57:06 +0000837 vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
hasso049207c2004-08-04 20:02:13 +0000838 VNL);
paul718e3742002-12-13 20:15:29 +0000839 }
840 else
hasso049207c2004-08-04 20:02:13 +0000841 vty_out (vty, " Not Attached to Area%s", VNL);
paul718e3742002-12-13 20:15:29 +0000842
843 vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
hasso508e53e2004-05-18 18:57:06 +0000844 ospf6_interface_state_str[oi->state],
845 oi->transdelay, oi->priority,
hasso049207c2004-08-04 20:02:13 +0000846 VNL);
847 vty_out (vty, " Timer intervals configured:%s", VNL);
paul718e3742002-12-13 20:15:29 +0000848 vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
hasso508e53e2004-05-18 18:57:06 +0000849 oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
hasso049207c2004-08-04 20:02:13 +0000850 VNL);
paul718e3742002-12-13 20:15:29 +0000851
hasso508e53e2004-05-18 18:57:06 +0000852 inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
853 inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
hasso049207c2004-08-04 20:02:13 +0000854 vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
paul718e3742002-12-13 20:15:29 +0000855
856 vty_out (vty, " Number of I/F scoped LSAs is %u%s",
hasso049207c2004-08-04 20:02:13 +0000857 oi->lsdb->count, VNL);
paul718e3742002-12-13 20:15:29 +0000858
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900859 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
paul718e3742002-12-13 20:15:29 +0000860
hasso508e53e2004-05-18 18:57:06 +0000861 timerclear (&res);
862 if (oi->thread_send_lsupdate)
863 timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
864 timerstring (&res, duration, sizeof (duration));
865 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
866 oi->lsupdate_list->count, duration,
867 (oi->thread_send_lsupdate ? "on" : "off"),
hasso049207c2004-08-04 20:02:13 +0000868 VNL);
hasso508e53e2004-05-18 18:57:06 +0000869 for (lsa = ospf6_lsdb_head (oi->lsupdate_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 timerclear (&res);
874 if (oi->thread_send_lsack)
875 timersub (&oi->thread_send_lsack->u.sands, &now, &res);
876 timerstring (&res, duration, sizeof (duration));
877 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
878 oi->lsack_list->count, duration,
879 (oi->thread_send_lsack ? "on" : "off"),
hasso049207c2004-08-04 20:02:13 +0000880 VNL);
hasso508e53e2004-05-18 18:57:06 +0000881 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
882 lsa = ospf6_lsdb_next (lsa))
hasso049207c2004-08-04 20:02:13 +0000883 vty_out (vty, " %s%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000884
hasso508e53e2004-05-18 18:57:06 +0000885 return 0;
paul718e3742002-12-13 20:15:29 +0000886}
887
888/* show interface */
889DEFUN (show_ipv6_ospf6_interface,
890 show_ipv6_ospf6_interface_ifname_cmd,
891 "show ipv6 ospf6 interface IFNAME",
892 SHOW_STR
893 IP6_STR
894 OSPF6_STR
895 INTERFACE_STR
896 IFNAME_STR
897 )
898{
899 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000900 struct listnode *i;
paul718e3742002-12-13 20:15:29 +0000901
902 if (argc)
903 {
904 ifp = if_lookup_by_name (argv[0]);
hasso508e53e2004-05-18 18:57:06 +0000905 if (ifp == NULL)
paul718e3742002-12-13 20:15:29 +0000906 {
907 vty_out (vty, "No such Interface: %s%s", argv[0],
hasso049207c2004-08-04 20:02:13 +0000908 VNL);
paul718e3742002-12-13 20:15:29 +0000909 return CMD_WARNING;
910 }
911 ospf6_interface_show (vty, ifp);
912 }
913 else
914 {
paul1eb8ef22005-04-07 07:30:20 +0000915 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
916 ospf6_interface_show (vty, ifp);
paul718e3742002-12-13 20:15:29 +0000917 }
hasso508e53e2004-05-18 18:57:06 +0000918
paul718e3742002-12-13 20:15:29 +0000919 return CMD_SUCCESS;
920}
921
922ALIAS (show_ipv6_ospf6_interface,
923 show_ipv6_ospf6_interface_cmd,
924 "show ipv6 ospf6 interface",
925 SHOW_STR
926 IP6_STR
927 OSPF6_STR
928 INTERFACE_STR
Paul Jakma6ac29a52008-08-15 13:45:30 +0100929 )
paul718e3742002-12-13 20:15:29 +0000930
hasso508e53e2004-05-18 18:57:06 +0000931DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
932 show_ipv6_ospf6_interface_ifname_prefix_cmd,
933 "show ipv6 ospf6 interface IFNAME prefix",
934 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000935 IP6_STR
936 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +0000937 INTERFACE_STR
938 IFNAME_STR
939 "Display connected prefixes to advertise\n"
paul718e3742002-12-13 20:15:29 +0000940 )
941{
paul718e3742002-12-13 20:15:29 +0000942 struct interface *ifp;
hasso508e53e2004-05-18 18:57:06 +0000943 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000944
hasso508e53e2004-05-18 18:57:06 +0000945 ifp = if_lookup_by_name (argv[0]);
946 if (ifp == NULL)
947 {
hasso049207c2004-08-04 20:02:13 +0000948 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000949 return CMD_WARNING;
950 }
paul718e3742002-12-13 20:15:29 +0000951
hasso508e53e2004-05-18 18:57:06 +0000952 oi = ifp->info;
953 if (oi == NULL)
954 {
hasso049207c2004-08-04 20:02:13 +0000955 vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000956 return CMD_WARNING;
957 }
paul718e3742002-12-13 20:15:29 +0000958
hasso508e53e2004-05-18 18:57:06 +0000959 argc--;
960 argv++;
961 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
paul718e3742002-12-13 20:15:29 +0000962
963 return CMD_SUCCESS;
964}
965
hasso508e53e2004-05-18 18:57:06 +0000966ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
967 show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
968 "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
969 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000970 IP6_STR
971 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +0000972 INTERFACE_STR
973 IFNAME_STR
974 "Display connected prefixes to advertise\n"
975 OSPF6_ROUTE_ADDRESS_STR
976 OSPF6_ROUTE_PREFIX_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +0400977 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100978 )
hasso508e53e2004-05-18 18:57:06 +0000979
980ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
981 show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
982 "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
983 SHOW_STR
984 IP6_STR
985 OSPF6_STR
986 INTERFACE_STR
987 IFNAME_STR
988 "Display connected prefixes to advertise\n"
989 OSPF6_ROUTE_PREFIX_STR
990 OSPF6_ROUTE_MATCH_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +0400991 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100992 )
hasso508e53e2004-05-18 18:57:06 +0000993
994DEFUN (show_ipv6_ospf6_interface_prefix,
995 show_ipv6_ospf6_interface_prefix_cmd,
996 "show ipv6 ospf6 interface prefix",
997 SHOW_STR
998 IP6_STR
999 OSPF6_STR
1000 INTERFACE_STR
1001 "Display connected prefixes to advertise\n"
paul718e3742002-12-13 20:15:29 +00001002 )
1003{
hasso52dc7ee2004-09-23 19:18:23 +00001004 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +00001005 struct ospf6_interface *oi;
1006 struct interface *ifp;
1007
paul1eb8ef22005-04-07 07:30:20 +00001008 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
hasso508e53e2004-05-18 18:57:06 +00001009 {
hasso508e53e2004-05-18 18:57:06 +00001010 oi = (struct ospf6_interface *) ifp->info;
1011 if (oi == NULL)
1012 continue;
1013
1014 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1015 }
1016
1017 return CMD_SUCCESS;
1018}
1019
1020ALIAS (show_ipv6_ospf6_interface_prefix,
1021 show_ipv6_ospf6_interface_prefix_detail_cmd,
1022 "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
1023 SHOW_STR
1024 IP6_STR
1025 OSPF6_STR
1026 INTERFACE_STR
1027 "Display connected prefixes to advertise\n"
1028 OSPF6_ROUTE_ADDRESS_STR
1029 OSPF6_ROUTE_PREFIX_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +04001030 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +01001031 )
hasso508e53e2004-05-18 18:57:06 +00001032
1033ALIAS (show_ipv6_ospf6_interface_prefix,
1034 show_ipv6_ospf6_interface_prefix_match_cmd,
1035 "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
1036 SHOW_STR
1037 IP6_STR
1038 OSPF6_STR
1039 INTERFACE_STR
1040 "Display connected prefixes to advertise\n"
1041 OSPF6_ROUTE_PREFIX_STR
1042 OSPF6_ROUTE_MATCH_STR
Denis Ovsienkoea402192011-08-19 16:27:16 +04001043 "Display details of the prefixes\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +01001044 )
hasso508e53e2004-05-18 18:57:06 +00001045
1046
1047/* interface variable set command */
hassob596c712004-07-09 18:33:43 +00001048DEFUN (ipv6_ospf6_ifmtu,
1049 ipv6_ospf6_ifmtu_cmd,
1050 "ipv6 ospf6 ifmtu <1-65535>",
1051 IP6_STR
1052 OSPF6_STR
1053 "Interface MTU\n"
1054 "OSPFv3 Interface MTU\n"
1055 )
1056{
1057 struct ospf6_interface *oi;
1058 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001059 unsigned int ifmtu, iobuflen;
paul1eb8ef22005-04-07 07:30:20 +00001060 struct listnode *node, *nnode;
hassob596c712004-07-09 18:33:43 +00001061 struct ospf6_neighbor *on;
1062
1063 ifp = (struct interface *) vty->index;
1064 assert (ifp);
1065
1066 oi = (struct ospf6_interface *) ifp->info;
1067 if (oi == NULL)
1068 oi = ospf6_interface_create (ifp);
1069 assert (oi);
1070
1071 ifmtu = strtol (argv[0], NULL, 10);
1072
1073 if (oi->ifmtu == ifmtu)
1074 return CMD_SUCCESS;
1075
hasso1203e1c2004-07-23 21:34:27 +00001076 if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
hassob596c712004-07-09 18:33:43 +00001077 {
1078 vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
hasso049207c2004-08-04 20:02:13 +00001079 ifp->name, ifp->mtu6, VNL);
hassob596c712004-07-09 18:33:43 +00001080 return CMD_WARNING;
1081 }
1082
1083 if (oi->ifmtu < ifmtu)
1084 {
1085 iobuflen = ospf6_iobuf_size (ifmtu);
1086 if (iobuflen < ifmtu)
1087 {
1088 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
hasso049207c2004-08-04 20:02:13 +00001089 ifp->name, iobuflen, VNL);
hassob596c712004-07-09 18:33:43 +00001090 oi->ifmtu = iobuflen;
1091 }
1092 else
1093 oi->ifmtu = ifmtu;
1094 }
1095 else
1096 oi->ifmtu = ifmtu;
1097
1098 /* re-establish adjacencies */
paul1eb8ef22005-04-07 07:30:20 +00001099 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hassob596c712004-07-09 18:33:43 +00001100 {
hassob596c712004-07-09 18:33:43 +00001101 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001102 thread_add_event (master, inactivity_timer, on, 0);
hassob596c712004-07-09 18:33:43 +00001103 }
1104
1105 return CMD_SUCCESS;
1106}
1107
hasso049207c2004-08-04 20:02:13 +00001108DEFUN (no_ipv6_ospf6_ifmtu,
1109 no_ipv6_ospf6_ifmtu_cmd,
1110 "no ipv6 ospf6 ifmtu",
1111 NO_STR
1112 IP6_STR
1113 OSPF6_STR
1114 "Interface MTU\n"
1115 )
1116{
1117 struct ospf6_interface *oi;
1118 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001119 unsigned int iobuflen;
paul1eb8ef22005-04-07 07:30:20 +00001120 struct listnode *node, *nnode;
hasso049207c2004-08-04 20:02:13 +00001121 struct ospf6_neighbor *on;
1122
1123 ifp = (struct interface *) vty->index;
1124 assert (ifp);
1125
1126 oi = (struct ospf6_interface *) ifp->info;
1127 if (oi == NULL)
1128 oi = ospf6_interface_create (ifp);
1129 assert (oi);
1130
1131 if (oi->ifmtu < ifp->mtu)
1132 {
1133 iobuflen = ospf6_iobuf_size (ifp->mtu);
1134 if (iobuflen < ifp->mtu)
1135 {
1136 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1137 ifp->name, iobuflen, VNL);
1138 oi->ifmtu = iobuflen;
1139 }
1140 else
1141 oi->ifmtu = ifp->mtu;
1142 }
1143 else
1144 oi->ifmtu = ifp->mtu;
1145
1146 /* re-establish adjacencies */
paul1eb8ef22005-04-07 07:30:20 +00001147 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
hasso049207c2004-08-04 20:02:13 +00001148 {
hasso049207c2004-08-04 20:02:13 +00001149 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001150 thread_add_event (master, inactivity_timer, on, 0);
hasso049207c2004-08-04 20:02:13 +00001151 }
1152
1153 return CMD_SUCCESS;
1154}
1155
hasso508e53e2004-05-18 18:57:06 +00001156DEFUN (ipv6_ospf6_cost,
1157 ipv6_ospf6_cost_cmd,
1158 "ipv6 ospf6 cost <1-65535>",
1159 IP6_STR
1160 OSPF6_STR
1161 "Interface cost\n"
1162 "Outgoing metric of this interface\n"
1163 )
1164{
1165 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001166 struct interface *ifp;
paul0c083ee2004-10-10 12:54:58 +00001167 unsigned long int lcost;
paul718e3742002-12-13 20:15:29 +00001168
1169 ifp = (struct interface *) vty->index;
1170 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001171
hasso508e53e2004-05-18 18:57:06 +00001172 oi = (struct ospf6_interface *) ifp->info;
1173 if (oi == NULL)
1174 oi = ospf6_interface_create (ifp);
1175 assert (oi);
1176
paul0c083ee2004-10-10 12:54:58 +00001177 lcost = strtol (argv[0], NULL, 10);
1178
1179 if (lcost > UINT32_MAX)
1180 {
1181 vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
1182 return CMD_WARNING;
1183 }
1184
1185 if (oi->cost == lcost)
hasso508e53e2004-05-18 18:57:06 +00001186 return CMD_SUCCESS;
paul0c083ee2004-10-10 12:54:58 +00001187
1188 oi->cost = lcost;
1189
hasso508e53e2004-05-18 18:57:06 +00001190 /* update cost held in route_connected list in ospf6_interface */
1191 ospf6_interface_connected_route_update (oi->interface);
1192
1193 /* execute LSA hooks */
1194 if (oi->area)
1195 {
1196 OSPF6_LINK_LSA_SCHEDULE (oi);
1197 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
1198 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1199 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1200 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1201 }
1202
1203 return CMD_SUCCESS;
1204}
1205
1206DEFUN (ipv6_ospf6_hellointerval,
1207 ipv6_ospf6_hellointerval_cmd,
1208 "ipv6 ospf6 hello-interval <1-65535>",
1209 IP6_STR
1210 OSPF6_STR
1211 "Interval time of Hello packets\n"
1212 SECONDS_STR
1213 )
1214{
1215 struct ospf6_interface *oi;
1216 struct interface *ifp;
1217
1218 ifp = (struct interface *) vty->index;
1219 assert (ifp);
1220
1221 oi = (struct ospf6_interface *) ifp->info;
1222 if (oi == NULL)
1223 oi = ospf6_interface_create (ifp);
1224 assert (oi);
1225
1226 oi->hello_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001227 return CMD_SUCCESS;
1228}
1229
1230/* interface variable set command */
1231DEFUN (ipv6_ospf6_deadinterval,
1232 ipv6_ospf6_deadinterval_cmd,
hasso508e53e2004-05-18 18:57:06 +00001233 "ipv6 ospf6 dead-interval <1-65535>",
paul718e3742002-12-13 20:15:29 +00001234 IP6_STR
1235 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001236 "Interval time after which a neighbor is declared down\n"
paul718e3742002-12-13 20:15:29 +00001237 SECONDS_STR
1238 )
1239{
hasso508e53e2004-05-18 18:57:06 +00001240 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001241 struct interface *ifp;
1242
1243 ifp = (struct interface *) vty->index;
1244 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001245
hasso508e53e2004-05-18 18:57:06 +00001246 oi = (struct ospf6_interface *) ifp->info;
1247 if (oi == NULL)
1248 oi = ospf6_interface_create (ifp);
1249 assert (oi);
1250
1251 oi->dead_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001252 return CMD_SUCCESS;
1253}
1254
1255/* interface variable set command */
1256DEFUN (ipv6_ospf6_transmitdelay,
1257 ipv6_ospf6_transmitdelay_cmd,
hasso508e53e2004-05-18 18:57:06 +00001258 "ipv6 ospf6 transmit-delay <1-3600>",
paul718e3742002-12-13 20:15:29 +00001259 IP6_STR
1260 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001261 "Transmit delay of this interface\n"
paul718e3742002-12-13 20:15:29 +00001262 SECONDS_STR
1263 )
1264{
hasso508e53e2004-05-18 18:57:06 +00001265 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001266 struct interface *ifp;
1267
1268 ifp = (struct interface *) vty->index;
1269 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001270
hasso508e53e2004-05-18 18:57:06 +00001271 oi = (struct ospf6_interface *) ifp->info;
1272 if (oi == NULL)
1273 oi = ospf6_interface_create (ifp);
1274 assert (oi);
1275
1276 oi->transdelay = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001277 return CMD_SUCCESS;
1278}
1279
1280/* interface variable set command */
1281DEFUN (ipv6_ospf6_retransmitinterval,
1282 ipv6_ospf6_retransmitinterval_cmd,
hasso508e53e2004-05-18 18:57:06 +00001283 "ipv6 ospf6 retransmit-interval <1-65535>",
paul718e3742002-12-13 20:15:29 +00001284 IP6_STR
1285 OSPF6_STR
1286 "Time between retransmitting lost link state advertisements\n"
1287 SECONDS_STR
1288 )
1289{
hasso508e53e2004-05-18 18:57:06 +00001290 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001291 struct interface *ifp;
1292
1293 ifp = (struct interface *) vty->index;
1294 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001295
hasso508e53e2004-05-18 18:57:06 +00001296 oi = (struct ospf6_interface *) ifp->info;
1297 if (oi == NULL)
1298 oi = ospf6_interface_create (ifp);
1299 assert (oi);
1300
1301 oi->rxmt_interval = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001302 return CMD_SUCCESS;
1303}
1304
1305/* interface variable set command */
1306DEFUN (ipv6_ospf6_priority,
1307 ipv6_ospf6_priority_cmd,
hasso508e53e2004-05-18 18:57:06 +00001308 "ipv6 ospf6 priority <0-255>",
paul718e3742002-12-13 20:15:29 +00001309 IP6_STR
1310 OSPF6_STR
1311 "Router priority\n"
hasso508e53e2004-05-18 18:57:06 +00001312 "Priority value\n"
paul718e3742002-12-13 20:15:29 +00001313 )
1314{
hasso508e53e2004-05-18 18:57:06 +00001315 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001316 struct interface *ifp;
1317
1318 ifp = (struct interface *) vty->index;
1319 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001320
hasso508e53e2004-05-18 18:57:06 +00001321 oi = (struct ospf6_interface *) ifp->info;
1322 if (oi == NULL)
1323 oi = ospf6_interface_create (ifp);
1324 assert (oi);
paul718e3742002-12-13 20:15:29 +00001325
hasso508e53e2004-05-18 18:57:06 +00001326 oi->priority = strtol (argv[0], NULL, 10);
1327
1328 if (oi->area)
1329 ospf6_interface_state_change (dr_election (oi), oi);
paul718e3742002-12-13 20:15:29 +00001330
1331 return CMD_SUCCESS;
1332}
1333
1334DEFUN (ipv6_ospf6_instance,
1335 ipv6_ospf6_instance_cmd,
hasso508e53e2004-05-18 18:57:06 +00001336 "ipv6 ospf6 instance-id <0-255>",
paul718e3742002-12-13 20:15:29 +00001337 IP6_STR
1338 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001339 "Instance ID for this interface\n"
1340 "Instance ID value\n"
paul718e3742002-12-13 20:15:29 +00001341 )
1342{
hasso508e53e2004-05-18 18:57:06 +00001343 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001344 struct interface *ifp;
1345
1346 ifp = (struct interface *)vty->index;
1347 assert (ifp);
1348
hasso508e53e2004-05-18 18:57:06 +00001349 oi = (struct ospf6_interface *)ifp->info;
1350 if (oi == NULL)
1351 oi = ospf6_interface_create (ifp);
1352 assert (oi);
paul718e3742002-12-13 20:15:29 +00001353
hasso508e53e2004-05-18 18:57:06 +00001354 oi->instance_id = strtol (argv[0], NULL, 10);
paul718e3742002-12-13 20:15:29 +00001355 return CMD_SUCCESS;
1356}
1357
1358DEFUN (ipv6_ospf6_passive,
1359 ipv6_ospf6_passive_cmd,
1360 "ipv6 ospf6 passive",
1361 IP6_STR
1362 OSPF6_STR
hasso508e53e2004-05-18 18:57:06 +00001363 "passive interface, No adjacency will be formed on this interface\n"
paul718e3742002-12-13 20:15:29 +00001364 )
1365{
hasso508e53e2004-05-18 18:57:06 +00001366 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001367 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +00001368 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +00001369 struct ospf6_neighbor *on;
paul718e3742002-12-13 20:15:29 +00001370
1371 ifp = (struct interface *) vty->index;
1372 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001373
hasso508e53e2004-05-18 18:57:06 +00001374 oi = (struct ospf6_interface *) ifp->info;
1375 if (oi == NULL)
1376 oi = ospf6_interface_create (ifp);
1377 assert (oi);
paul718e3742002-12-13 20:15:29 +00001378
hasso508e53e2004-05-18 18:57:06 +00001379 SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1380 THREAD_OFF (oi->thread_send_hello);
1381
paul1eb8ef22005-04-07 07:30:20 +00001382 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
paul718e3742002-12-13 20:15:29 +00001383 {
hasso508e53e2004-05-18 18:57:06 +00001384 THREAD_OFF (on->inactivity_timer);
hasso3e834b12005-06-24 07:50:12 +00001385 thread_add_event (master, inactivity_timer, on, 0);
paul718e3742002-12-13 20:15:29 +00001386 }
1387
1388 return CMD_SUCCESS;
1389}
1390
1391DEFUN (no_ipv6_ospf6_passive,
1392 no_ipv6_ospf6_passive_cmd,
1393 "no ipv6 ospf6 passive",
1394 NO_STR
1395 IP6_STR
1396 OSPF6_STR
1397 "passive interface: No Adjacency will be formed on this I/F\n"
1398 )
1399{
hasso508e53e2004-05-18 18:57:06 +00001400 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001401 struct interface *ifp;
1402
1403 ifp = (struct interface *) vty->index;
1404 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001405
hasso508e53e2004-05-18 18:57:06 +00001406 oi = (struct ospf6_interface *) ifp->info;
1407 if (oi == NULL)
1408 oi = ospf6_interface_create (ifp);
1409 assert (oi);
paul718e3742002-12-13 20:15:29 +00001410
hasso508e53e2004-05-18 18:57:06 +00001411 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1412 THREAD_OFF (oi->thread_send_hello);
1413 oi->thread_send_hello =
1414 thread_add_event (master, ospf6_hello_send, oi, 0);
paul718e3742002-12-13 20:15:29 +00001415
1416 return CMD_SUCCESS;
1417}
1418
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001419DEFUN (ipv6_ospf6_mtu_ignore,
1420 ipv6_ospf6_mtu_ignore_cmd,
1421 "ipv6 ospf6 mtu-ignore",
1422 IP6_STR
1423 OSPF6_STR
1424 "Ignore MTU mismatch on this interface\n"
1425 )
1426{
1427 struct ospf6_interface *oi;
1428 struct interface *ifp;
1429
1430 ifp = (struct interface *) vty->index;
1431 assert (ifp);
1432
1433 oi = (struct ospf6_interface *) ifp->info;
1434 if (oi == NULL)
1435 oi = ospf6_interface_create (ifp);
1436 assert (oi);
1437
1438 oi->mtu_ignore = 1;
1439
1440 return CMD_SUCCESS;
1441}
1442
1443DEFUN (no_ipv6_ospf6_mtu_ignore,
1444 no_ipv6_ospf6_mtu_ignore_cmd,
1445 "no ipv6 ospf6 mtu-ignore",
1446 NO_STR
1447 IP6_STR
1448 OSPF6_STR
1449 "Ignore MTU mismatch on this interface\n"
1450 )
1451{
1452 struct ospf6_interface *oi;
1453 struct interface *ifp;
1454
1455 ifp = (struct interface *) vty->index;
1456 assert (ifp);
1457
1458 oi = (struct ospf6_interface *) ifp->info;
1459 if (oi == NULL)
1460 oi = ospf6_interface_create (ifp);
1461 assert (oi);
1462
1463 oi->mtu_ignore = 0;
1464
1465 return CMD_SUCCESS;
1466}
1467
paul718e3742002-12-13 20:15:29 +00001468DEFUN (ipv6_ospf6_advertise_prefix_list,
1469 ipv6_ospf6_advertise_prefix_list_cmd,
1470 "ipv6 ospf6 advertise prefix-list WORD",
1471 IP6_STR
1472 OSPF6_STR
1473 "Advertising options\n"
1474 "Filter prefix using prefix-list\n"
1475 "Prefix list name\n"
1476 )
1477{
hasso508e53e2004-05-18 18:57:06 +00001478 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001479 struct interface *ifp;
1480
1481 ifp = (struct interface *) vty->index;
1482 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001483
hasso508e53e2004-05-18 18:57:06 +00001484 oi = (struct ospf6_interface *) ifp->info;
1485 if (oi == NULL)
1486 oi = ospf6_interface_create (ifp);
1487 assert (oi);
paul718e3742002-12-13 20:15:29 +00001488
hasso508e53e2004-05-18 18:57:06 +00001489 if (oi->plist_name)
1490 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1491 oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
paul718e3742002-12-13 20:15:29 +00001492
hasso508e53e2004-05-18 18:57:06 +00001493 ospf6_interface_connected_route_update (oi->interface);
David Ward2470e992010-01-05 02:45:39 +00001494
1495 if (oi->area)
hasso508e53e2004-05-18 18:57:06 +00001496 {
David Ward2470e992010-01-05 02:45:39 +00001497 OSPF6_LINK_LSA_SCHEDULE (oi);
1498 if (oi->state == OSPF6_INTERFACE_DR)
1499 {
1500 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1501 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1502 }
1503 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
hasso508e53e2004-05-18 18:57:06 +00001504 }
paul718e3742002-12-13 20:15:29 +00001505
1506 return CMD_SUCCESS;
1507}
1508
1509DEFUN (no_ipv6_ospf6_advertise_prefix_list,
1510 no_ipv6_ospf6_advertise_prefix_list_cmd,
1511 "no ipv6 ospf6 advertise prefix-list",
1512 NO_STR
1513 IP6_STR
1514 OSPF6_STR
1515 "Advertising options\n"
1516 "Filter prefix using prefix-list\n"
1517 )
1518{
hasso508e53e2004-05-18 18:57:06 +00001519 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001520 struct interface *ifp;
1521
1522 ifp = (struct interface *) vty->index;
1523 assert (ifp);
paul718e3742002-12-13 20:15:29 +00001524
hasso508e53e2004-05-18 18:57:06 +00001525 oi = (struct ospf6_interface *) ifp->info;
1526 if (oi == NULL)
1527 oi = ospf6_interface_create (ifp);
1528 assert (oi);
1529
1530 if (oi->plist_name)
paul718e3742002-12-13 20:15:29 +00001531 {
hasso508e53e2004-05-18 18:57:06 +00001532 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1533 oi->plist_name = NULL;
paul718e3742002-12-13 20:15:29 +00001534 }
1535
hasso508e53e2004-05-18 18:57:06 +00001536 ospf6_interface_connected_route_update (oi->interface);
David Ward2470e992010-01-05 02:45:39 +00001537
1538 if (oi->area)
hasso508e53e2004-05-18 18:57:06 +00001539 {
David Ward2470e992010-01-05 02:45:39 +00001540 OSPF6_LINK_LSA_SCHEDULE (oi);
1541 if (oi->state == OSPF6_INTERFACE_DR)
1542 {
1543 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1544 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1545 }
1546 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
hasso508e53e2004-05-18 18:57:06 +00001547 }
paul718e3742002-12-13 20:15:29 +00001548
1549 return CMD_SUCCESS;
1550}
1551
Dinesh Duttc5926a92013-08-24 07:55:00 +00001552DEFUN (ipv6_ospf6_network,
1553 ipv6_ospf6_network_cmd,
1554 "ipv6 ospf6 network (broadcast|point-to-point)",
1555 IP6_STR
1556 OSPF6_STR
1557 "Network Type\n"
1558 "Specify OSPFv6 broadcast network\n"
1559 "Specify OSPF6 point-to-point network\n"
1560 )
1561{
1562 struct ospf6_interface *oi;
1563 struct interface *ifp;
1564
1565 ifp = (struct interface *) vty->index;
1566 assert (ifp);
1567
1568 oi = (struct ospf6_interface *) ifp->info;
1569 if (oi == NULL) {
1570 oi = ospf6_interface_create (ifp);
1571 }
1572 assert (oi);
1573
1574 if (strncmp (argv[0], "b", 1) == 0)
1575 {
1576 if (oi->type == OSPF_IFTYPE_BROADCAST)
1577 return CMD_SUCCESS;
1578
1579 oi->type = OSPF_IFTYPE_BROADCAST;
1580 }
1581 else if (strncmp (argv[0], "point-to-p", 10) == 0)
1582 {
1583 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
1584 return CMD_SUCCESS;
1585 }
1586 oi->type = OSPF_IFTYPE_POINTOPOINT;
1587 }
1588
1589 /* Reset the interface */
1590 thread_add_event (master, interface_down, oi, 0);
1591 thread_add_event (master, interface_up, oi, 0);
1592
1593 return CMD_SUCCESS;
1594}
1595
1596DEFUN (no_ipv6_ospf6_network,
1597 no_ipv6_ospf6_network_cmd,
1598 "no ipv6 ospf6 network",
1599 NO_STR
1600 IP6_STR
1601 OSPF6_STR
1602 "Network Type\n"
1603 "Default to whatever interface type system specifies"
1604 )
1605{
1606 struct ospf6_interface *oi;
1607 struct interface *ifp;
1608 int type;
1609
1610 ifp = (struct interface *) vty->index;
1611 assert (ifp);
1612
1613 oi = (struct ospf6_interface *) ifp->info;
1614 if (oi == NULL) {
1615 return CMD_SUCCESS;
1616 }
1617
1618 type = ospf6_default_iftype (ifp);
1619 if (oi->type == type)
1620 {
1621 return CMD_SUCCESS;
1622 }
1623 oi->type = type;
1624
1625 /* Reset the interface */
1626 thread_add_event (master, interface_down, oi, 0);
1627 thread_add_event (master, interface_up, oi, 0);
1628
1629 return CMD_SUCCESS;
1630}
1631
Paul Jakma6ac29a52008-08-15 13:45:30 +01001632static int
hasso508e53e2004-05-18 18:57:06 +00001633config_write_ospf6_interface (struct vty *vty)
paul718e3742002-12-13 20:15:29 +00001634{
hasso52dc7ee2004-09-23 19:18:23 +00001635 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +00001636 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +00001637 struct interface *ifp;
1638
paul1eb8ef22005-04-07 07:30:20 +00001639 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
paul718e3742002-12-13 20:15:29 +00001640 {
hasso508e53e2004-05-18 18:57:06 +00001641 oi = (struct ospf6_interface *) ifp->info;
1642 if (oi == NULL)
paul718e3742002-12-13 20:15:29 +00001643 continue;
1644
1645 vty_out (vty, "interface %s%s",
hasso049207c2004-08-04 20:02:13 +00001646 oi->interface->name, VNL);
hasso508e53e2004-05-18 18:57:06 +00001647
1648 if (ifp->desc)
hasso049207c2004-08-04 20:02:13 +00001649 vty_out (vty, " description %s%s", ifp->desc, VNL);
hasso1203e1c2004-07-23 21:34:27 +00001650 if (ifp->mtu6 != oi->ifmtu)
hasso049207c2004-08-04 20:02:13 +00001651 vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
Vyacheslav Trushkinb51a3a32012-02-10 10:42:45 +04001652
1653 if (oi->cost != OSPF6_INTERFACE_COST)
1654 vty_out (vty, " ipv6 ospf6 cost %d%s",
1655 oi->cost, VNL);
1656
1657 if (oi->hello_interval != OSPF6_INTERFACE_HELLO_INTERVAL)
1658 vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
1659 oi->hello_interval, VNL);
1660
1661 if (oi->dead_interval != OSPF6_INTERFACE_DEAD_INTERVAL)
1662 vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
1663 oi->dead_interval, VNL);
1664
1665 if (oi->rxmt_interval != OSPF6_INTERFACE_RXMT_INTERVAL)
1666 vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
1667 oi->rxmt_interval, VNL);
1668
1669 if (oi->priority != OSPF6_INTERFACE_PRIORITY)
1670 vty_out (vty, " ipv6 ospf6 priority %d%s",
1671 oi->priority, VNL);
1672
1673 if (oi->transdelay != OSPF6_INTERFACE_TRANSDELAY)
1674 vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
1675 oi->transdelay, VNL);
1676
1677 if (oi->instance_id != OSPF6_INTERFACE_INSTANCE_ID)
1678 vty_out (vty, " ipv6 ospf6 instance-id %d%s",
1679 oi->instance_id, VNL);
paul718e3742002-12-13 20:15:29 +00001680
hasso508e53e2004-05-18 18:57:06 +00001681 if (oi->plist_name)
paul718e3742002-12-13 20:15:29 +00001682 vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
hasso049207c2004-08-04 20:02:13 +00001683 oi->plist_name, VNL);
paul718e3742002-12-13 20:15:29 +00001684
hasso508e53e2004-05-18 18:57:06 +00001685 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
hasso049207c2004-08-04 20:02:13 +00001686 vty_out (vty, " ipv6 ospf6 passive%s", VNL);
paul718e3742002-12-13 20:15:29 +00001687
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001688 if (oi->mtu_ignore)
1689 vty_out (vty, " ipv6 ospf6 mtu-ignore%s", VNL);
1690
Dinesh Duttc5926a92013-08-24 07:55:00 +00001691 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
1692 vty_out (vty, " ipv6 ospf6 network point-to-point%s", VNL);
1693 else if (oi->type == OSPF_IFTYPE_BROADCAST)
1694 vty_out (vty, " ipv6 ospf6 network broadcast%s", VNL);
1695
hasso049207c2004-08-04 20:02:13 +00001696 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +00001697 }
1698 return 0;
1699}
1700
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08001701static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +00001702{
1703 INTERFACE_NODE,
1704 "%s(config-if)# ",
hasso69b4a812004-08-26 18:10:36 +00001705 1 /* VTYSH */
paul718e3742002-12-13 20:15:29 +00001706};
1707
1708void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001709ospf6_interface_init (void)
paul718e3742002-12-13 20:15:29 +00001710{
1711 /* Install interface node. */
hasso508e53e2004-05-18 18:57:06 +00001712 install_node (&interface_node, config_write_ospf6_interface);
paul718e3742002-12-13 20:15:29 +00001713
1714 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
hasso508e53e2004-05-18 18:57:06 +00001715 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1716 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1717 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001718 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
hasso508e53e2004-05-18 18:57:06 +00001719 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1720 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1721 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001722 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
hasso508e53e2004-05-18 18:57:06 +00001723 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1724 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1725 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001726 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
hasso508e53e2004-05-18 18:57:06 +00001727 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1728 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1729 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
paul718e3742002-12-13 20:15:29 +00001730
hasso508e53e2004-05-18 18:57:06 +00001731 install_element (CONFIG_NODE, &interface_cmd);
paul718e3742002-12-13 20:15:29 +00001732 install_default (INTERFACE_NODE);
1733 install_element (INTERFACE_NODE, &interface_desc_cmd);
1734 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1735 install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
hassob596c712004-07-09 18:33:43 +00001736 install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
hasso049207c2004-08-04 20:02:13 +00001737 install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
paul718e3742002-12-13 20:15:29 +00001738 install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
1739 install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
1740 install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
1741 install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
1742 install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
1743 install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
hasso508e53e2004-05-18 18:57:06 +00001744
paul718e3742002-12-13 20:15:29 +00001745 install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
1746 install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
hasso508e53e2004-05-18 18:57:06 +00001747
Dmitrij Tejblumd42306d2011-04-22 19:27:54 +04001748 install_element (INTERFACE_NODE, &ipv6_ospf6_mtu_ignore_cmd);
1749 install_element (INTERFACE_NODE, &no_ipv6_ospf6_mtu_ignore_cmd);
1750
hasso508e53e2004-05-18 18:57:06 +00001751 install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
1752 install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
Dinesh Duttc5926a92013-08-24 07:55:00 +00001753
1754 install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
1755 install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
hasso508e53e2004-05-18 18:57:06 +00001756}
1757
1758DEFUN (debug_ospf6_interface,
1759 debug_ospf6_interface_cmd,
1760 "debug ospf6 interface",
1761 DEBUG_STR
1762 OSPF6_STR
1763 "Debug OSPFv3 Interface\n"
1764 )
1765{
1766 OSPF6_DEBUG_INTERFACE_ON ();
1767 return CMD_SUCCESS;
1768}
1769
1770DEFUN (no_debug_ospf6_interface,
1771 no_debug_ospf6_interface_cmd,
1772 "no debug ospf6 interface",
1773 NO_STR
1774 DEBUG_STR
1775 OSPF6_STR
1776 "Debug OSPFv3 Interface\n"
1777 )
1778{
hasso3b687352004-08-19 06:56:53 +00001779 OSPF6_DEBUG_INTERFACE_OFF ();
hasso508e53e2004-05-18 18:57:06 +00001780 return CMD_SUCCESS;
1781}
1782
1783int
1784config_write_ospf6_debug_interface (struct vty *vty)
1785{
1786 if (IS_OSPF6_DEBUG_INTERFACE)
hasso049207c2004-08-04 20:02:13 +00001787 vty_out (vty, "debug ospf6 interface%s", VNL);
hasso508e53e2004-05-18 18:57:06 +00001788 return 0;
1789}
1790
1791void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001792install_element_ospf6_debug_interface (void)
hasso508e53e2004-05-18 18:57:06 +00001793{
1794 install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
1795 install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
1796 install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
1797 install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
paul718e3742002-12-13 20:15:29 +00001798}
1799
1800