]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_interface.c
bgpd: Fix function return
[mirror_frr.git] / ospf6d / ospf6_interface.c
CommitLineData
718e3744 1/*
508e53e2 2 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
508e53e2 22#include <zebra.h>
718e3744 23
508e53e2 24#include "memory.h"
718e3744 25#include "if.h"
26#include "log.h"
27#include "command.h"
508e53e2 28#include "thread.h"
29#include "prefix.h"
30#include "plist.h"
88177fe3 31#include "zclient.h"
718e3744 32
508e53e2 33#include "ospf6_lsa.h"
718e3744 34#include "ospf6_lsdb.h"
508e53e2 35#include "ospf6_network.h"
36#include "ospf6_message.h"
37#include "ospf6_route.h"
718e3744 38#include "ospf6_top.h"
39#include "ospf6_area.h"
40#include "ospf6_interface.h"
508e53e2 41#include "ospf6_neighbor.h"
42#include "ospf6_intra.h"
43#include "ospf6_spf.h"
049207c3 44#include "ospf6d.h"
7f342629 45#include "ospf6_bfd.h"
718e3744 46
508e53e2 47unsigned char conf_debug_ospf6_interface = 0;
48
0c083ee9 49const char *ospf6_interface_state_str[] =
718e3744 50{
508e53e2 51 "None",
52 "Down",
53 "Loopback",
54 "Waiting",
55 "PointToPoint",
56 "DROther",
57 "BDR",
58 "DR",
59 NULL
718e3744 60};
61
508e53e2 62struct ospf6_interface *
63ospf6_interface_lookup_by_ifindex (int ifindex)
718e3744 64{
508e53e2 65 struct ospf6_interface *oi;
66 struct interface *ifp;
718e3744 67
508e53e2 68 ifp = if_lookup_by_index (ifindex);
69 if (ifp == NULL)
70 return (struct ospf6_interface *) NULL;
71
72 oi = (struct ospf6_interface *) ifp->info;
73 return oi;
718e3744 74}
75
508e53e2 76/* schedule routing table recalculation */
6ac29a51 77static void
a0edf674 78ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa, unsigned int reason)
718e3744 79{
3810e06e
DD
80 struct ospf6_interface *oi;
81
82 if (lsa == NULL)
83 return;
84
85 oi = lsa->lsdb->data;
508e53e2 86 switch (ntohs (lsa->header->type))
87 {
88 case OSPF6_LSTYPE_LINK:
3810e06e
DD
89 if (oi->state == OSPF6_INTERFACE_DR)
90 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
988bf1fe 91 if (oi->area)
92 ospf6_spf_schedule (oi->area->ospf6, reason);
508e53e2 93 break;
94
95 default:
508e53e2 96 break;
97 }
718e3744 98}
99
a0edf674
DD
100static void
101ospf6_interface_lsdb_hook_add (struct ospf6_lsa *lsa)
102{
103 ospf6_interface_lsdb_hook(lsa, ospf6_lsadd_to_spf_reason(lsa));
104}
105
106static void
107ospf6_interface_lsdb_hook_remove (struct ospf6_lsa *lsa)
108{
109 ospf6_interface_lsdb_hook(lsa, ospf6_lsremove_to_spf_reason(lsa));
110}
111
c5926a92
DD
112static u_char
113ospf6_default_iftype(struct interface *ifp)
114{
115 if (if_is_pointopoint (ifp))
116 return OSPF_IFTYPE_POINTOPOINT;
117 else if (if_is_loopback (ifp))
118 return OSPF_IFTYPE_LOOPBACK;
119 else
120 return OSPF_IFTYPE_BROADCAST;
121}
122
c19543b2
VB
123static u_int32_t
124ospf6_interface_get_cost (struct ospf6_interface *oi)
125{
126 /* If all else fails, use default OSPF cost */
127 u_int32_t cost;
128 u_int32_t bw, refbw;
129
130 bw = oi->interface->bandwidth ? oi->interface->bandwidth : OSPF6_INTERFACE_BANDWIDTH;
fd500689 131 refbw = ospf6 ? ospf6->ref_bandwidth : OSPF6_REFERENCE_BANDWIDTH;
c19543b2
VB
132
133 /* A specifed ip ospf cost overrides a calculated one. */
134 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST))
135 cost = oi->cost;
136 else
137 {
138 cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
139 if (cost < 1) cost = 1;
140 else if (cost > UINT32_MAX) cost = UINT32_MAX;
141 }
142
143 return cost;
144}
145
146static void
147ospf6_interface_recalculate_cost (struct ospf6_interface *oi)
148{
149 u_int32_t newcost;
150
151 newcost = ospf6_interface_get_cost (oi);
152 if (newcost == oi->cost) return;
153 oi->cost = newcost;
154
155 /* update cost held in route_connected list in ospf6_interface */
156 ospf6_interface_connected_route_update (oi->interface);
157
158 /* execute LSA hooks */
159 if (oi->area)
160 {
161 OSPF6_LINK_LSA_SCHEDULE (oi);
162 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
163 OSPF6_NETWORK_LSA_SCHEDULE (oi);
164 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
165 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
166 }
167}
168
718e3744 169/* Create new ospf6 interface structure */
170struct ospf6_interface *
171ospf6_interface_create (struct interface *ifp)
172{
508e53e2 173 struct ospf6_interface *oi;
0c083ee9 174 unsigned int iobuflen;
718e3744 175
508e53e2 176 oi = (struct ospf6_interface *)
393deb9b 177 XCALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
718e3744 178
393deb9b 179 if (!oi)
718e3744 180 {
181 zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
182 return (struct ospf6_interface *) NULL;
183 }
184
508e53e2 185 oi->area = (struct ospf6_area *) NULL;
186 oi->neighbor_list = list_new ();
187 oi->neighbor_list->cmp = ospf6_neighbor_cmp;
188 oi->linklocal_addr = (struct in6_addr *) NULL;
b51a3a31
VT
189 oi->instance_id = OSPF6_INTERFACE_INSTANCE_ID;
190 oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
191 oi->priority = OSPF6_INTERFACE_PRIORITY;
192
8551e6da
DD
193 oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
194 oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
195 oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
c5926a92 196 oi->type = ospf6_default_iftype (ifp);
508e53e2 197 oi->state = OSPF6_INTERFACE_DOWN;
198 oi->flag = 0;
d42306d9 199 oi->mtu_ignore = 0;
508e53e2 200
b596c71e 201 /* Try to adjust I/O buffer size with IfMtu */
1203e1c0 202 oi->ifmtu = ifp->mtu6;
203 iobuflen = ospf6_iobuf_size (ifp->mtu6);
b596c71e 204 if (oi->ifmtu > iobuflen)
3b4cd3a9 205 {
1e05838a 206 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 207 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
208 ifp->name, iobuflen);
3b4cd3a9 209 oi->ifmtu = iobuflen;
210 }
3b4cd3a9 211
6452df09 212 oi->lsupdate_list = ospf6_lsdb_create (oi);
213 oi->lsack_list = ospf6_lsdb_create (oi);
214 oi->lsdb = ospf6_lsdb_create (oi);
a0edf674
DD
215 oi->lsdb->hook_add = ospf6_interface_lsdb_hook_add;
216 oi->lsdb->hook_remove = ospf6_interface_lsdb_hook_remove;
6452df09 217 oi->lsdb_self = ospf6_lsdb_create (oi);
508e53e2 218
cf1ce250
PJ
219 oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
220 oi->route_connected->scope = oi;
718e3744 221
222 /* link both */
508e53e2 223 oi->interface = ifp;
224 ifp->info = oi;
718e3744 225
c19543b2
VB
226 /* Compute cost. */
227 oi->cost = ospf6_interface_get_cost(oi);
228
508e53e2 229 return oi;
718e3744 230}
231
232void
508e53e2 233ospf6_interface_delete (struct ospf6_interface *oi)
718e3744 234{
1eb8ef25 235 struct listnode *node, *nnode;
508e53e2 236 struct ospf6_neighbor *on;
718e3744 237
1eb8ef25 238 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
508e53e2 239 ospf6_neighbor_delete (on);
1eb8ef25 240
508e53e2 241 list_delete (oi->neighbor_list);
718e3744 242
508e53e2 243 THREAD_OFF (oi->thread_send_hello);
244 THREAD_OFF (oi->thread_send_lsupdate);
245 THREAD_OFF (oi->thread_send_lsack);
246
247 ospf6_lsdb_remove_all (oi->lsdb);
248 ospf6_lsdb_remove_all (oi->lsupdate_list);
249 ospf6_lsdb_remove_all (oi->lsack_list);
250
251 ospf6_lsdb_delete (oi->lsdb);
6452df09 252 ospf6_lsdb_delete (oi->lsdb_self);
253
508e53e2 254 ospf6_lsdb_delete (oi->lsupdate_list);
255 ospf6_lsdb_delete (oi->lsack_list);
718e3744 256
508e53e2 257 ospf6_route_table_delete (oi->route_connected);
718e3744 258
259 /* cut link */
508e53e2 260 oi->interface->info = NULL;
718e3744 261
262 /* plist_name */
508e53e2 263 if (oi->plist_name)
264 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
265
68fe91d6 266 ospf6_bfd_info_free(&(oi->bfd_info));
7f342629 267
508e53e2 268 XFREE (MTYPE_OSPF6_IF, oi);
269}
270
271void
272ospf6_interface_enable (struct ospf6_interface *oi)
273{
274 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
d9628728 275 ospf6_interface_state_update (oi->interface);
508e53e2 276}
277
278void
279ospf6_interface_disable (struct ospf6_interface *oi)
280{
508e53e2 281 SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
282
d9628728 283 thread_execute (master, interface_down, oi, 0);
508e53e2 284
285 ospf6_lsdb_remove_all (oi->lsdb);
d9628728 286 ospf6_lsdb_remove_all (oi->lsdb_self);
508e53e2 287 ospf6_lsdb_remove_all (oi->lsupdate_list);
288 ospf6_lsdb_remove_all (oi->lsack_list);
289
290 THREAD_OFF (oi->thread_send_hello);
291 THREAD_OFF (oi->thread_send_lsupdate);
292 THREAD_OFF (oi->thread_send_lsack);
d9628728
CF
293
294 THREAD_OFF (oi->thread_network_lsa);
295 THREAD_OFF (oi->thread_link_lsa);
296 THREAD_OFF (oi->thread_intra_prefix_lsa);
718e3744 297}
298
299static struct in6_addr *
508e53e2 300ospf6_interface_get_linklocal_address (struct interface *ifp)
718e3744 301{
52dc7ee6 302 struct listnode *n;
718e3744 303 struct connected *c;
304 struct in6_addr *l = (struct in6_addr *) NULL;
305
306 /* for each connected address */
1eb8ef25 307 for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
718e3744 308 {
718e3744 309 /* if family not AF_INET6, ignore */
310 if (c->address->family != AF_INET6)
311 continue;
312
313 /* linklocal scope check */
314 if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
315 l = &c->address->u.prefix6;
316 }
317 return l;
318}
319
320void
321ospf6_interface_if_add (struct interface *ifp)
322{
508e53e2 323 struct ospf6_interface *oi;
0c083ee9 324 unsigned int iobuflen;
718e3744 325
508e53e2 326 oi = (struct ospf6_interface *) ifp->info;
327 if (oi == NULL)
718e3744 328 return;
329
b596c71e 330 /* Try to adjust I/O buffer size with IfMtu */
331 if (oi->ifmtu == 0)
1203e1c0 332 oi->ifmtu = ifp->mtu6;
333 iobuflen = ospf6_iobuf_size (ifp->mtu6);
b596c71e 334 if (oi->ifmtu > iobuflen)
3b4cd3a9 335 {
1e05838a 336 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 337 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
338 ifp->name, iobuflen);
3b4cd3a9 339 oi->ifmtu = iobuflen;
340 }
718e3744 341
342 /* interface start */
b13c1d92 343 ospf6_interface_state_update(oi->interface);
718e3744 344}
345
346void
347ospf6_interface_if_del (struct interface *ifp)
348{
508e53e2 349 struct ospf6_interface *oi;
718e3744 350
508e53e2 351 oi = (struct ospf6_interface *) ifp->info;
352 if (oi == NULL)
718e3744 353 return;
354
355 /* interface stop */
508e53e2 356 if (oi->area)
357 thread_execute (master, interface_down, oi, 0);
718e3744 358
508e53e2 359 listnode_delete (oi->area->if_list, oi);
360 oi->area = (struct ospf6_area *) NULL;
718e3744 361
362 /* cut link */
508e53e2 363 oi->interface = NULL;
718e3744 364 ifp->info = NULL;
365
508e53e2 366 ospf6_interface_delete (oi);
718e3744 367}
368
369void
370ospf6_interface_state_update (struct interface *ifp)
371{
508e53e2 372 struct ospf6_interface *oi;
718e3744 373
508e53e2 374 oi = (struct ospf6_interface *) ifp->info;
375 if (oi == NULL)
718e3744 376 return;
508e53e2 377 if (oi->area == NULL)
718e3744 378 return;
d9628728
CF
379 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
380 return;
718e3744 381
b13c1d92
CF
382 if (if_is_operative (ifp)
383 && (ospf6_interface_get_linklocal_address(oi->interface)
384 || if_is_loopback(oi->interface)))
508e53e2 385 thread_add_event (master, interface_up, oi, 0);
718e3744 386 else
508e53e2 387 thread_add_event (master, interface_down, oi, 0);
718e3744 388
389 return;
390}
391
392void
508e53e2 393ospf6_interface_connected_route_update (struct interface *ifp)
718e3744 394{
508e53e2 395 struct ospf6_interface *oi;
396 struct ospf6_route *route;
397 struct connected *c;
1eb8ef25 398 struct listnode *node, *nnode;
c3c0ac83 399 struct in6_addr nh_addr;
718e3744 400
508e53e2 401 oi = (struct ospf6_interface *) ifp->info;
402 if (oi == NULL)
718e3744 403 return;
404
405 /* reset linklocal pointer */
508e53e2 406 oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
718e3744 407
508e53e2 408 /* if area is null, do not make connected-route list */
409 if (oi->area == NULL)
718e3744 410 return;
411
d9628728
CF
412 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
413 return;
414
508e53e2 415 /* update "route to advertise" interface route table */
416 ospf6_route_remove_all (oi->route_connected);
508e53e2 417
1eb8ef25 418 for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
419 {
508e53e2 420 if (c->address->family != AF_INET6)
421 continue;
422
1e05838a 423 CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
424 CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
425 CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
426 CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
427 CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
718e3744 428
508e53e2 429 /* apply filter */
430 if (oi->plist_name)
431 {
432 struct prefix_list *plist;
433 enum prefix_list_type ret;
4690c7d7 434 char buf[PREFIX2STR_BUFFER];
508e53e2 435
436 prefix2str (c->address, buf, sizeof (buf));
437 plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
438 ret = prefix_list_apply (plist, (void *) c->address);
439 if (ret == PREFIX_DENY)
440 {
1e05838a 441 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 442 zlog_debug ("%s on %s filtered by prefix-list %s ",
443 buf, oi->interface->name, oi->plist_name);
508e53e2 444 continue;
445 }
446 }
447
448 route = ospf6_route_create ();
449 memcpy (&route->prefix, c->address, sizeof (struct prefix));
450 apply_mask (&route->prefix);
451 route->type = OSPF6_DEST_TYPE_NETWORK;
452 route->path.area_id = oi->area->area_id;
453 route->path.type = OSPF6_PATH_TYPE_INTRA;
454 route->path.cost = oi->cost;
c3c0ac83
DS
455 inet_pton (AF_INET6, "::1", &nh_addr);
456 ospf6_route_add_nexthop (route, oi->interface->ifindex, &nh_addr);
508e53e2 457 ospf6_route_add (route, oi->route_connected);
458 }
459
460 /* create new Link-LSA */
461 OSPF6_LINK_LSA_SCHEDULE (oi);
462 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
463 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
718e3744 464}
465
508e53e2 466static void
467ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
718e3744 468{
508e53e2 469 u_char prev_state;
718e3744 470
508e53e2 471 prev_state = oi->state;
472 oi->state = next_state;
718e3744 473
508e53e2 474 if (prev_state == next_state)
475 return;
476
477 /* log */
478 if (IS_OSPF6_DEBUG_INTERFACE)
479 {
c6487d61 480 zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
481 ospf6_interface_state_str[prev_state],
482 ospf6_interface_state_str[next_state]);
508e53e2 483 }
3bc4f84e 484 oi->state_change++;
718e3744 485
508e53e2 486 if ((prev_state == OSPF6_INTERFACE_DR ||
487 prev_state == OSPF6_INTERFACE_BDR) &&
488 (next_state != OSPF6_INTERFACE_DR &&
489 next_state != OSPF6_INTERFACE_BDR))
9a9446ea 490 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP);
c5926a92 491
508e53e2 492 if ((prev_state != OSPF6_INTERFACE_DR &&
493 prev_state != OSPF6_INTERFACE_BDR) &&
494 (next_state == OSPF6_INTERFACE_DR ||
495 next_state == OSPF6_INTERFACE_BDR))
9a9446ea 496 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP);
508e53e2 497
498 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
6452df09 499 if (next_state == OSPF6_INTERFACE_DOWN)
500 {
501 OSPF6_NETWORK_LSA_EXECUTE (oi);
502 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
503 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
504 }
505 else if (prev_state == OSPF6_INTERFACE_DR ||
506 next_state == OSPF6_INTERFACE_DR)
508e53e2 507 {
508 OSPF6_NETWORK_LSA_SCHEDULE (oi);
509 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
510 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
511 }
bf836661
VB
512
513#ifdef HAVE_SNMP
514 /* Terminal state or regression */
515 if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
516 (next_state == OSPF6_INTERFACE_DROTHER) ||
517 (next_state == OSPF6_INTERFACE_BDR) ||
518 (next_state == OSPF6_INTERFACE_DR) ||
519 (next_state < prev_state))
520 ospf6TrapIfStateChange (oi);
521#endif
522
718e3744 523}
524
6b0655a2 525
508e53e2 526/* DR Election, RFC2328 section 9.4 */
718e3744 527
508e53e2 528#define IS_ELIGIBLE(n) \
529 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
718e3744 530
508e53e2 531static struct ospf6_neighbor *
532better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
533{
534 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
535 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
536 return NULL;
537 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
538 return b;
539 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
540 return a;
541
542 if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
543 return a;
544 if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
545 return b;
546
547 if (a->priority > b->priority)
548 return a;
549 if (a->priority < b->priority)
550 return b;
551
552 if (ntohl (a->router_id) > ntohl (b->router_id))
553 return a;
554 if (ntohl (a->router_id) < ntohl (b->router_id))
555 return b;
556
557 zlog_warn ("Router-ID duplicate ?");
558 return a;
559}
718e3744 560
508e53e2 561static struct ospf6_neighbor *
562better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
563{
564 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
565 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
566 return NULL;
567 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
568 return b;
569 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
570 return a;
571
572 if (a->drouter == a->router_id && b->drouter != b->router_id)
573 return a;
574 if (a->drouter != a->router_id && b->drouter == b->router_id)
575 return b;
576
577 if (a->priority > b->priority)
578 return a;
579 if (a->priority < b->priority)
580 return b;
581
582 if (ntohl (a->router_id) > ntohl (b->router_id))
583 return a;
584 if (ntohl (a->router_id) < ntohl (b->router_id))
585 return b;
586
587 zlog_warn ("Router-ID duplicate ?");
588 return a;
718e3744 589}
590
508e53e2 591static u_char
592dr_election (struct ospf6_interface *oi)
718e3744 593{
1eb8ef25 594 struct listnode *node, *nnode;
508e53e2 595 struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
596 struct ospf6_neighbor *best_drouter, *best_bdrouter;
597 u_char next_state = 0;
598
599 drouter = bdrouter = NULL;
600 best_drouter = best_bdrouter = NULL;
601
602 /* pseudo neighbor myself, including noting current DR/BDR (1) */
603 memset (&myself, 0, sizeof (myself));
604 inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
605 sizeof (myself.name));
606 myself.state = OSPF6_NEIGHBOR_TWOWAY;
607 myself.drouter = oi->drouter;
608 myself.bdrouter = oi->bdrouter;
609 myself.priority = oi->priority;
610 myself.router_id = oi->area->ospf6->router_id;
611
612 /* Electing BDR (2) */
1eb8ef25 613 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
614 bdrouter = better_bdrouter (bdrouter, on);
615
508e53e2 616 best_bdrouter = bdrouter;
617 bdrouter = better_bdrouter (best_bdrouter, &myself);
618
619 /* Electing DR (3) */
1eb8ef25 620 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
621 drouter = better_drouter (drouter, on);
622
508e53e2 623 best_drouter = drouter;
624 drouter = better_drouter (best_drouter, &myself);
625 if (drouter == NULL)
626 drouter = bdrouter;
627
628 /* the router itself is newly/no longer DR/BDR (4) */
629 if ((drouter == &myself && myself.drouter != myself.router_id) ||
630 (drouter != &myself && myself.drouter == myself.router_id) ||
631 (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
632 (bdrouter != &myself && myself.bdrouter == myself.router_id))
633 {
634 myself.drouter = (drouter ? drouter->router_id : htonl (0));
635 myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
636
637 /* compatible to Electing BDR (2) */
638 bdrouter = better_bdrouter (best_bdrouter, &myself);
639
640 /* compatible to Electing DR (3) */
641 drouter = better_drouter (best_drouter, &myself);
642 if (drouter == NULL)
643 drouter = bdrouter;
644 }
645
646 /* Set interface state accordingly (5) */
647 if (drouter && drouter == &myself)
648 next_state = OSPF6_INTERFACE_DR;
649 else if (bdrouter && bdrouter == &myself)
650 next_state = OSPF6_INTERFACE_BDR;
651 else
652 next_state = OSPF6_INTERFACE_DROTHER;
718e3744 653
508e53e2 654 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
655 /* XXX */
656
657 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
658 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
659 accordingly after AdjOK */
660 if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
661 oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
718e3744 662 {
508e53e2 663 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 664 zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
665 (drouter ? drouter->name : "0.0.0.0"),
666 (bdrouter ? bdrouter->name : "0.0.0.0"));
508e53e2 667
1eb8ef25 668 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
508e53e2 669 {
508e53e2 670 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
671 continue;
672 /* Schedule AdjOK. */
673 thread_add_event (master, adj_ok, on, 0);
674 }
718e3744 675 }
508e53e2 676
677 oi->drouter = (drouter ? drouter->router_id : htonl (0));
678 oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
679 return next_state;
718e3744 680}
681
6b0655a2 682
508e53e2 683/* Interface State Machine */
718e3744 684int
508e53e2 685interface_up (struct thread *thread)
718e3744 686{
508e53e2 687 struct ospf6_interface *oi;
688
689 oi = (struct ospf6_interface *) THREAD_ARG (thread);
690 assert (oi && oi->interface);
691
692 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 693 zlog_debug ("Interface Event %s: [InterfaceUp]",
694 oi->interface->name);
508e53e2 695
696 /* check physical interface is up */
e7ad6b20 697 if (! if_is_operative (oi->interface))
508e53e2 698 {
699 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 700 zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
701 oi->interface->name);
508e53e2 702 return 0;
703 }
704
b13c1d92
CF
705 /* check interface has a link-local address */
706 if (! (ospf6_interface_get_linklocal_address(oi->interface)
707 || if_is_loopback(oi->interface)))
708 {
709 if (IS_OSPF6_DEBUG_INTERFACE)
710 zlog_debug ("Interface %s has no link local address, can't execute [InterfaceUp]",
711 oi->interface->name);
712 return 0;
713 }
714
c19543b2
VB
715 /* Recompute cost */
716 ospf6_interface_recalculate_cost (oi);
717
508e53e2 718 /* if already enabled, do nothing */
719 if (oi->state > OSPF6_INTERFACE_DOWN)
720 {
721 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 722 zlog_debug ("Interface %s already enabled",
723 oi->interface->name);
508e53e2 724 return 0;
725 }
726
ba960d5a
DD
727 /* If no area assigned, return */
728 if (oi->area == NULL)
729 {
730 zlog_debug ("%s: Not scheduleing Hello for %s as there is no area assigned yet", __func__,
731 oi->interface->name);
732 return 0;
733 }
734
508e53e2 735 /* Join AllSPFRouters */
8e370bfa
DS
736 if (ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP) < 0)
737 {
738 if (oi->sso_try_cnt++ < OSPF6_INTERFACE_SSO_RETRY_MAX)
739 {
740 zlog_info("Scheduling %s for sso retry, trial count: %d",
741 oi->interface->name, oi->sso_try_cnt);
742 thread_add_timer (master, interface_up, oi,
743 OSPF6_INTERFACE_SSO_RETRY_INT);
744 }
745 return 0;
746 }
747 oi->sso_try_cnt = 0; /* Reset on success */
508e53e2 748
749 /* Update interface route */
750 ospf6_interface_connected_route_update (oi->interface);
718e3744 751
508e53e2 752 /* Schedule Hello */
419b65ee
DS
753 if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE) &&
754 !if_is_loopback (oi->interface))
424cc3bd 755 oi->thread_send_hello = thread_add_event (master, ospf6_hello_send, oi, 0);
508e53e2 756
757 /* decide next interface state */
c5926a92
DD
758 if ((if_is_pointopoint (oi->interface)) ||
759 (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
508e53e2 760 ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
c5926a92 761 }
508e53e2 762 else if (oi->priority == 0)
763 ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
764 else
718e3744 765 {
508e53e2 766 ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
767 thread_add_timer (master, wait_timer, oi, oi->dead_interval);
718e3744 768 }
508e53e2 769
770 return 0;
718e3744 771}
772
773int
508e53e2 774wait_timer (struct thread *thread)
718e3744 775{
508e53e2 776 struct ospf6_interface *oi;
718e3744 777
508e53e2 778 oi = (struct ospf6_interface *) THREAD_ARG (thread);
779 assert (oi && oi->interface);
718e3744 780
508e53e2 781 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 782 zlog_debug ("Interface Event %s: [WaitTimer]",
783 oi->interface->name);
718e3744 784
508e53e2 785 if (oi->state == OSPF6_INTERFACE_WAITING)
786 ospf6_interface_state_change (dr_election (oi), oi);
718e3744 787
508e53e2 788 return 0;
718e3744 789}
790
508e53e2 791int
792backup_seen (struct thread *thread)
793{
794 struct ospf6_interface *oi;
795
796 oi = (struct ospf6_interface *) THREAD_ARG (thread);
797 assert (oi && oi->interface);
798
799 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 800 zlog_debug ("Interface Event %s: [BackupSeen]",
801 oi->interface->name);
508e53e2 802
803 if (oi->state == OSPF6_INTERFACE_WAITING)
804 ospf6_interface_state_change (dr_election (oi), oi);
805
806 return 0;
807}
808
809int
810neighbor_change (struct thread *thread)
718e3744 811{
508e53e2 812 struct ospf6_interface *oi;
813
814 oi = (struct ospf6_interface *) THREAD_ARG (thread);
815 assert (oi && oi->interface);
816
817 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 818 zlog_debug ("Interface Event %s: [NeighborChange]",
819 oi->interface->name);
508e53e2 820
821 if (oi->state == OSPF6_INTERFACE_DROTHER ||
822 oi->state == OSPF6_INTERFACE_BDR ||
823 oi->state == OSPF6_INTERFACE_DR)
824 ospf6_interface_state_change (dr_election (oi), oi);
825
826 return 0;
718e3744 827}
828
508e53e2 829int
830interface_down (struct thread *thread)
718e3744 831{
508e53e2 832 struct ospf6_interface *oi;
1eb8ef25 833 struct listnode *node, *nnode;
508e53e2 834 struct ospf6_neighbor *on;
835
836 oi = (struct ospf6_interface *) THREAD_ARG (thread);
837 assert (oi && oi->interface);
838
839 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 840 zlog_debug ("Interface Event %s: [InterfaceDown]",
841 oi->interface->name);
508e53e2 842
424cc3bd
DL
843 /* Stop Hellos */
844 THREAD_OFF (oi->thread_send_hello);
845
508e53e2 846 /* Leave AllSPFRouters */
847 if (oi->state > OSPF6_INTERFACE_DOWN)
9a9446ea 848 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_LEAVE_GROUP);
508e53e2 849
850 ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
851
1eb8ef25 852 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
853 ospf6_neighbor_delete (on);
854
508e53e2 855 list_delete_all_node (oi->neighbor_list);
856
37531a7e
CF
857 /* When interface state is reset, also reset information about
858 * DR election, as it is no longer valid. */
859 oi->drouter = oi->prev_drouter = htonl(0);
860 oi->bdrouter = oi->prev_bdrouter = htonl(0);
508e53e2 861 return 0;
718e3744 862}
863
6b0655a2 864
718e3744 865/* show specified interface structure */
6ac29a51 866static int
508e53e2 867ospf6_interface_show (struct vty *vty, struct interface *ifp)
718e3744 868{
508e53e2 869 struct ospf6_interface *oi;
718e3744 870 struct connected *c;
871 struct prefix *p;
52dc7ee6 872 struct listnode *i;
4690c7d7 873 char strbuf[PREFIX2STR_BUFFER], drouter[32], bdrouter[32];
0c083ee9 874 const char *updown[3] = {"down", "up", NULL};
875 const char *type;
508e53e2 876 struct timeval res, now;
877 char duration[32];
878 struct ospf6_lsa *lsa;
718e3744 879
880 /* check physical interface type */
508e53e2 881 if (if_is_loopback (ifp))
718e3744 882 type = "LOOPBACK";
508e53e2 883 else if (if_is_broadcast (ifp))
718e3744 884 type = "BROADCAST";
508e53e2 885 else if (if_is_pointopoint (ifp))
718e3744 886 type = "POINTOPOINT";
887 else
888 type = "UNKNOWN";
889
890 vty_out (vty, "%s is %s, type %s%s",
e7ad6b20 891 ifp->name, updown[if_is_operative (ifp)], type,
049207c3 892 VNL);
893 vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
718e3744 894
508e53e2 895 if (ifp->info == NULL)
718e3744 896 {
049207c3 897 vty_out (vty, " OSPF not enabled on this interface%s", VNL);
718e3744 898 return 0;
899 }
900 else
508e53e2 901 oi = (struct ospf6_interface *) ifp->info;
718e3744 902
049207c3 903 vty_out (vty, " Internet Address:%s", VNL);
1eb8ef25 904
905 for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
718e3744 906 {
718e3744 907 p = c->address;
908 prefix2str (p, strbuf, sizeof (strbuf));
909 switch (p->family)
910 {
911 case AF_INET:
508e53e2 912 vty_out (vty, " inet : %s%s", strbuf,
049207c3 913 VNL);
718e3744 914 break;
915 case AF_INET6:
508e53e2 916 vty_out (vty, " inet6: %s%s", strbuf,
049207c3 917 VNL);
718e3744 918 break;
919 default:
508e53e2 920 vty_out (vty, " ??? : %s%s", strbuf,
049207c3 921 VNL);
718e3744 922 break;
923 }
924 }
925
508e53e2 926 if (oi->area)
718e3744 927 {
508e53e2 928 vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
049207c3 929 oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
d42306d9
DT
930 vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ?
931 "disabled" : "enabled", VNL);
508e53e2 932 inet_ntop (AF_INET, &oi->area->area_id,
718e3744 933 strbuf, sizeof (strbuf));
508e53e2 934 vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
049207c3 935 VNL);
718e3744 936 }
937 else
049207c3 938 vty_out (vty, " Not Attached to Area%s", VNL);
718e3744 939
940 vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
508e53e2 941 ospf6_interface_state_str[oi->state],
942 oi->transdelay, oi->priority,
049207c3 943 VNL);
944 vty_out (vty, " Timer intervals configured:%s", VNL);
718e3744 945 vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
508e53e2 946 oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
049207c3 947 VNL);
718e3744 948
508e53e2 949 inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
950 inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
049207c3 951 vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
718e3744 952
953 vty_out (vty, " Number of I/F scoped LSAs is %u%s",
049207c3 954 oi->lsdb->count, VNL);
718e3744 955
86f72dcb 956 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
718e3744 957
508e53e2 958 timerclear (&res);
959 if (oi->thread_send_lsupdate)
960 timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
961 timerstring (&res, duration, sizeof (duration));
962 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
963 oi->lsupdate_list->count, duration,
964 (oi->thread_send_lsupdate ? "on" : "off"),
049207c3 965 VNL);
508e53e2 966 for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
967 lsa = ospf6_lsdb_next (lsa))
049207c3 968 vty_out (vty, " %s%s", lsa->name, VNL);
508e53e2 969
970 timerclear (&res);
971 if (oi->thread_send_lsack)
972 timersub (&oi->thread_send_lsack->u.sands, &now, &res);
973 timerstring (&res, duration, sizeof (duration));
974 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
975 oi->lsack_list->count, duration,
976 (oi->thread_send_lsack ? "on" : "off"),
049207c3 977 VNL);
508e53e2 978 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
979 lsa = ospf6_lsdb_next (lsa))
049207c3 980 vty_out (vty, " %s%s", lsa->name, VNL);
68fe91d6 981 ospf6_bfd_show_info(vty, oi->bfd_info, 1);
508e53e2 982 return 0;
718e3744 983}
984
985/* show interface */
986DEFUN (show_ipv6_ospf6_interface,
987 show_ipv6_ospf6_interface_ifname_cmd,
988 "show ipv6 ospf6 interface IFNAME",
989 SHOW_STR
990 IP6_STR
991 OSPF6_STR
992 INTERFACE_STR
993 IFNAME_STR
994 )
995{
996 struct interface *ifp;
52dc7ee6 997 struct listnode *i;
718e3744 998
999 if (argc)
1000 {
1001 ifp = if_lookup_by_name (argv[0]);
508e53e2 1002 if (ifp == NULL)
718e3744 1003 {
1004 vty_out (vty, "No such Interface: %s%s", argv[0],
049207c3 1005 VNL);
718e3744 1006 return CMD_WARNING;
1007 }
1008 ospf6_interface_show (vty, ifp);
1009 }
1010 else
1011 {
b2d7c082 1012 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
1eb8ef25 1013 ospf6_interface_show (vty, ifp);
718e3744 1014 }
508e53e2 1015
718e3744 1016 return CMD_SUCCESS;
1017}
1018
1019ALIAS (show_ipv6_ospf6_interface,
1020 show_ipv6_ospf6_interface_cmd,
1021 "show ipv6 ospf6 interface",
1022 SHOW_STR
1023 IP6_STR
1024 OSPF6_STR
1025 INTERFACE_STR
6ac29a51 1026 )
508e53e2 1027
1028DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
1029 show_ipv6_ospf6_interface_ifname_prefix_cmd,
1030 "show ipv6 ospf6 interface IFNAME prefix",
1031 SHOW_STR
1032 IP6_STR
1033 OSPF6_STR
1034 INTERFACE_STR
1035 IFNAME_STR
1036 "Display connected prefixes to advertise\n"
718e3744 1037 )
508e53e2 1038{
1039 struct interface *ifp;
1040 struct ospf6_interface *oi;
1041
1042 ifp = if_lookup_by_name (argv[0]);
1043 if (ifp == NULL)
1044 {
049207c3 1045 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
508e53e2 1046 return CMD_WARNING;
1047 }
1048
1049 oi = ifp->info;
1050 if (oi == NULL)
1051 {
049207c3 1052 vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
508e53e2 1053 return CMD_WARNING;
1054 }
1055
1056 argc--;
1057 argv++;
1058 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1059
1060 return CMD_SUCCESS;
1061}
1062
1063ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
1064 show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
1065 "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
1066 SHOW_STR
1067 IP6_STR
1068 OSPF6_STR
1069 INTERFACE_STR
1070 IFNAME_STR
1071 "Display connected prefixes to advertise\n"
1072 OSPF6_ROUTE_ADDRESS_STR
1073 OSPF6_ROUTE_PREFIX_STR
ea402198 1074 "Display details of the prefixes\n"
6ac29a51 1075 )
508e53e2 1076
1077ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
1078 show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
1079 "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
1080 SHOW_STR
1081 IP6_STR
1082 OSPF6_STR
1083 INTERFACE_STR
1084 IFNAME_STR
1085 "Display connected prefixes to advertise\n"
1086 OSPF6_ROUTE_PREFIX_STR
1087 OSPF6_ROUTE_MATCH_STR
ea402198 1088 "Display details of the prefixes\n"
6ac29a51 1089 )
508e53e2 1090
1091DEFUN (show_ipv6_ospf6_interface_prefix,
1092 show_ipv6_ospf6_interface_prefix_cmd,
1093 "show ipv6 ospf6 interface prefix",
1094 SHOW_STR
1095 IP6_STR
1096 OSPF6_STR
1097 INTERFACE_STR
1098 "Display connected prefixes to advertise\n"
1099 )
1100{
52dc7ee6 1101 struct listnode *i;
508e53e2 1102 struct ospf6_interface *oi;
1103 struct interface *ifp;
1104
b2d7c082 1105 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
508e53e2 1106 {
508e53e2 1107 oi = (struct ospf6_interface *) ifp->info;
1108 if (oi == NULL)
1109 continue;
1110
1111 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1112 }
1113
1114 return CMD_SUCCESS;
1115}
1116
1117ALIAS (show_ipv6_ospf6_interface_prefix,
1118 show_ipv6_ospf6_interface_prefix_detail_cmd,
1119 "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
1120 SHOW_STR
1121 IP6_STR
1122 OSPF6_STR
1123 INTERFACE_STR
1124 "Display connected prefixes to advertise\n"
1125 OSPF6_ROUTE_ADDRESS_STR
1126 OSPF6_ROUTE_PREFIX_STR
ea402198 1127 "Display details of the prefixes\n"
6ac29a51 1128 )
508e53e2 1129
1130ALIAS (show_ipv6_ospf6_interface_prefix,
1131 show_ipv6_ospf6_interface_prefix_match_cmd,
1132 "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
1133 SHOW_STR
1134 IP6_STR
1135 OSPF6_STR
1136 INTERFACE_STR
1137 "Display connected prefixes to advertise\n"
1138 OSPF6_ROUTE_PREFIX_STR
1139 OSPF6_ROUTE_MATCH_STR
ea402198 1140 "Display details of the prefixes\n"
6ac29a51 1141 )
508e53e2 1142
718e3744 1143
1144/* interface variable set command */
b596c71e 1145DEFUN (ipv6_ospf6_ifmtu,
1146 ipv6_ospf6_ifmtu_cmd,
1147 "ipv6 ospf6 ifmtu <1-65535>",
1148 IP6_STR
1149 OSPF6_STR
1150 "Interface MTU\n"
1151 "OSPFv3 Interface MTU\n"
1152 )
1153{
1154 struct ospf6_interface *oi;
1155 struct interface *ifp;
0c083ee9 1156 unsigned int ifmtu, iobuflen;
1eb8ef25 1157 struct listnode *node, *nnode;
b596c71e 1158 struct ospf6_neighbor *on;
1159
1160 ifp = (struct interface *) vty->index;
1161 assert (ifp);
1162
1163 oi = (struct ospf6_interface *) ifp->info;
1164 if (oi == NULL)
1165 oi = ospf6_interface_create (ifp);
1166 assert (oi);
1167
1168 ifmtu = strtol (argv[0], NULL, 10);
1169
1170 if (oi->ifmtu == ifmtu)
1171 return CMD_SUCCESS;
1172
1203e1c0 1173 if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
b596c71e 1174 {
1175 vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
049207c3 1176 ifp->name, ifp->mtu6, VNL);
b596c71e 1177 return CMD_WARNING;
1178 }
1179
1180 if (oi->ifmtu < ifmtu)
1181 {
1182 iobuflen = ospf6_iobuf_size (ifmtu);
1183 if (iobuflen < ifmtu)
1184 {
1185 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
049207c3 1186 ifp->name, iobuflen, VNL);
b596c71e 1187 oi->ifmtu = iobuflen;
1188 }
1189 else
1190 oi->ifmtu = ifmtu;
1191 }
1192 else
1193 oi->ifmtu = ifmtu;
1194
1195 /* re-establish adjacencies */
1eb8ef25 1196 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
b596c71e 1197 {
b596c71e 1198 THREAD_OFF (on->inactivity_timer);
3e834b12 1199 thread_add_event (master, inactivity_timer, on, 0);
b596c71e 1200 }
1201
1202 return CMD_SUCCESS;
1203}
1204
049207c3 1205DEFUN (no_ipv6_ospf6_ifmtu,
1206 no_ipv6_ospf6_ifmtu_cmd,
1207 "no ipv6 ospf6 ifmtu",
1208 NO_STR
1209 IP6_STR
1210 OSPF6_STR
1211 "Interface MTU\n"
1212 )
1213{
1214 struct ospf6_interface *oi;
1215 struct interface *ifp;
0c083ee9 1216 unsigned int iobuflen;
1eb8ef25 1217 struct listnode *node, *nnode;
049207c3 1218 struct ospf6_neighbor *on;
1219
1220 ifp = (struct interface *) vty->index;
1221 assert (ifp);
1222
1223 oi = (struct ospf6_interface *) ifp->info;
1224 if (oi == NULL)
1225 oi = ospf6_interface_create (ifp);
1226 assert (oi);
1227
1228 if (oi->ifmtu < ifp->mtu)
1229 {
1230 iobuflen = ospf6_iobuf_size (ifp->mtu);
1231 if (iobuflen < ifp->mtu)
1232 {
1233 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1234 ifp->name, iobuflen, VNL);
1235 oi->ifmtu = iobuflen;
1236 }
1237 else
1238 oi->ifmtu = ifp->mtu;
1239 }
1240 else
1241 oi->ifmtu = ifp->mtu;
1242
1243 /* re-establish adjacencies */
1eb8ef25 1244 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
049207c3 1245 {
049207c3 1246 THREAD_OFF (on->inactivity_timer);
3e834b12 1247 thread_add_event (master, inactivity_timer, on, 0);
049207c3 1248 }
1249
1250 return CMD_SUCCESS;
1251}
1252
718e3744 1253DEFUN (ipv6_ospf6_cost,
1254 ipv6_ospf6_cost_cmd,
508e53e2 1255 "ipv6 ospf6 cost <1-65535>",
718e3744 1256 IP6_STR
1257 OSPF6_STR
1258 "Interface cost\n"
508e53e2 1259 "Outgoing metric of this interface\n"
718e3744 1260 )
1261{
508e53e2 1262 struct ospf6_interface *oi;
718e3744 1263 struct interface *ifp;
0c083ee9 1264 unsigned long int lcost;
718e3744 1265
508e53e2 1266 ifp = (struct interface *) vty->index;
718e3744 1267 assert (ifp);
1268
508e53e2 1269 oi = (struct ospf6_interface *) ifp->info;
1270 if (oi == NULL)
1271 oi = ospf6_interface_create (ifp);
1272 assert (oi);
718e3744 1273
0c083ee9 1274 lcost = strtol (argv[0], NULL, 10);
718e3744 1275
0c083ee9 1276 if (lcost > UINT32_MAX)
1277 {
1278 vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
1279 return CMD_WARNING;
1280 }
1281
1282 if (oi->cost == lcost)
1283 return CMD_SUCCESS;
1284
1285 oi->cost = lcost;
c19543b2 1286 SET_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST);
718e3744 1287
c19543b2
VB
1288 ospf6_interface_recalculate_cost(oi);
1289
1290 return CMD_SUCCESS;
1291}
1292
1293DEFUN (no_ipv6_ospf6_cost,
1294 no_ipv6_ospf6_cost_cmd,
1295 "no ipv6 ospf6 cost",
1296 NO_STR
1297 IP6_STR
1298 OSPF6_STR
1299 "Calculate interface cost from bandwidth\n"
1300 )
1301{
1302 struct ospf6_interface *oi;
1303 struct interface *ifp;
c19543b2
VB
1304
1305 ifp = (struct interface *) vty->index;
1306 assert (ifp);
1307
1308 oi = (struct ospf6_interface *) ifp->info;
1309 if (oi == NULL)
1310 oi = ospf6_interface_create (ifp);
1311 assert (oi);
1312
1313 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST);
1314
1315 ospf6_interface_recalculate_cost(oi);
718e3744 1316
1317 return CMD_SUCCESS;
1318}
1319
fd500689
VB
1320DEFUN (auto_cost_reference_bandwidth,
1321 auto_cost_reference_bandwidth_cmd,
1322 "auto-cost reference-bandwidth <1-4294967>",
1323 "Calculate OSPF interface cost according to bandwidth\n"
1324 "Use reference bandwidth method to assign OSPF cost\n"
1325 "The reference bandwidth in terms of Mbits per second\n")
1326{
1327 struct ospf6 *o = vty->index;
1328 struct ospf6_area *oa;
1329 struct ospf6_interface *oi;
1330 struct listnode *i, *j;
1331 u_int32_t refbw;
1332
1333 refbw = strtol (argv[0], NULL, 10);
1334 if (refbw < 1 || refbw > 4294967)
1335 {
1336 vty_out (vty, "reference-bandwidth value is invalid%s", VTY_NEWLINE);
1337 return CMD_WARNING;
1338 }
1339
1340 /* If reference bandwidth is changed. */
1341 if ((refbw * 1000) == o->ref_bandwidth)
1342 return CMD_SUCCESS;
1343
1344 o->ref_bandwidth = refbw * 1000;
1345 for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
1346 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
1347 ospf6_interface_recalculate_cost (oi);
1348
1349 return CMD_SUCCESS;
1350}
1351
1352DEFUN (no_auto_cost_reference_bandwidth,
1353 no_auto_cost_reference_bandwidth_cmd,
1354 "no auto-cost reference-bandwidth",
1355 NO_STR
1356 "Calculate OSPF interface cost according to bandwidth\n"
1357 "Use reference bandwidth method to assign OSPF cost\n")
1358{
1359 struct ospf6 *o = vty->index;
1360 struct ospf6_area *oa;
1361 struct ospf6_interface *oi;
1362 struct listnode *i, *j;
1363
1364 if (o->ref_bandwidth == OSPF6_REFERENCE_BANDWIDTH)
1365 return CMD_SUCCESS;
1366
1367 o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;
1368 for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
1369 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
1370 ospf6_interface_recalculate_cost (oi);
1371
1372 return CMD_SUCCESS;
1373}
1374
813d4307
DW
1375ALIAS (no_auto_cost_reference_bandwidth,
1376 no_auto_cost_reference_bandwidth_val_cmd,
1377 "no auto-cost reference-bandwidth <1-4294967>",
1378 NO_STR
1379 "Calculate OSPF interface cost according to bandwidth\n"
1380 "Use reference bandwidth method to assign OSPF cost\n"
1381 "The reference bandwidth in terms of Mbits per second\n")
1382
718e3744 1383DEFUN (ipv6_ospf6_hellointerval,
1384 ipv6_ospf6_hellointerval_cmd,
508e53e2 1385 "ipv6 ospf6 hello-interval <1-65535>",
718e3744 1386 IP6_STR
1387 OSPF6_STR
508e53e2 1388 "Interval time of Hello packets\n"
718e3744 1389 SECONDS_STR
1390 )
1391{
508e53e2 1392 struct ospf6_interface *oi;
718e3744 1393 struct interface *ifp;
1394
1395 ifp = (struct interface *) vty->index;
1396 assert (ifp);
718e3744 1397
508e53e2 1398 oi = (struct ospf6_interface *) ifp->info;
1399 if (oi == NULL)
1400 oi = ospf6_interface_create (ifp);
1401 assert (oi);
1402
1403 oi->hello_interval = strtol (argv[0], NULL, 10);
718e3744 1404 return CMD_SUCCESS;
1405}
1406
1407/* interface variable set command */
1408DEFUN (ipv6_ospf6_deadinterval,
1409 ipv6_ospf6_deadinterval_cmd,
508e53e2 1410 "ipv6 ospf6 dead-interval <1-65535>",
718e3744 1411 IP6_STR
1412 OSPF6_STR
508e53e2 1413 "Interval time after which a neighbor is declared down\n"
718e3744 1414 SECONDS_STR
1415 )
1416{
508e53e2 1417 struct ospf6_interface *oi;
718e3744 1418 struct interface *ifp;
1419
1420 ifp = (struct interface *) vty->index;
1421 assert (ifp);
718e3744 1422
508e53e2 1423 oi = (struct ospf6_interface *) ifp->info;
1424 if (oi == NULL)
1425 oi = ospf6_interface_create (ifp);
1426 assert (oi);
1427
1428 oi->dead_interval = strtol (argv[0], NULL, 10);
718e3744 1429 return CMD_SUCCESS;
1430}
1431
1432/* interface variable set command */
1433DEFUN (ipv6_ospf6_transmitdelay,
1434 ipv6_ospf6_transmitdelay_cmd,
508e53e2 1435 "ipv6 ospf6 transmit-delay <1-3600>",
718e3744 1436 IP6_STR
1437 OSPF6_STR
508e53e2 1438 "Transmit delay of this interface\n"
718e3744 1439 SECONDS_STR
1440 )
1441{
508e53e2 1442 struct ospf6_interface *oi;
718e3744 1443 struct interface *ifp;
1444
1445 ifp = (struct interface *) vty->index;
1446 assert (ifp);
718e3744 1447
508e53e2 1448 oi = (struct ospf6_interface *) ifp->info;
1449 if (oi == NULL)
1450 oi = ospf6_interface_create (ifp);
1451 assert (oi);
1452
1453 oi->transdelay = strtol (argv[0], NULL, 10);
718e3744 1454 return CMD_SUCCESS;
1455}
1456
1457/* interface variable set command */
1458DEFUN (ipv6_ospf6_retransmitinterval,
1459 ipv6_ospf6_retransmitinterval_cmd,
508e53e2 1460 "ipv6 ospf6 retransmit-interval <1-65535>",
718e3744 1461 IP6_STR
1462 OSPF6_STR
1463 "Time between retransmitting lost link state advertisements\n"
1464 SECONDS_STR
1465 )
1466{
508e53e2 1467 struct ospf6_interface *oi;
718e3744 1468 struct interface *ifp;
1469
1470 ifp = (struct interface *) vty->index;
1471 assert (ifp);
718e3744 1472
508e53e2 1473 oi = (struct ospf6_interface *) ifp->info;
1474 if (oi == NULL)
1475 oi = ospf6_interface_create (ifp);
1476 assert (oi);
1477
1478 oi->rxmt_interval = strtol (argv[0], NULL, 10);
718e3744 1479 return CMD_SUCCESS;
1480}
1481
1482/* interface variable set command */
1483DEFUN (ipv6_ospf6_priority,
1484 ipv6_ospf6_priority_cmd,
508e53e2 1485 "ipv6 ospf6 priority <0-255>",
718e3744 1486 IP6_STR
1487 OSPF6_STR
1488 "Router priority\n"
508e53e2 1489 "Priority value\n"
718e3744 1490 )
1491{
508e53e2 1492 struct ospf6_interface *oi;
718e3744 1493 struct interface *ifp;
1494
1495 ifp = (struct interface *) vty->index;
1496 assert (ifp);
718e3744 1497
508e53e2 1498 oi = (struct ospf6_interface *) ifp->info;
1499 if (oi == NULL)
1500 oi = ospf6_interface_create (ifp);
1501 assert (oi);
1502
1503 oi->priority = strtol (argv[0], NULL, 10);
718e3744 1504
7d4aa1d5
CF
1505 if (oi->area &&
1506 (oi->state == OSPF6_INTERFACE_DROTHER ||
1507 oi->state == OSPF6_INTERFACE_BDR ||
1508 oi->state == OSPF6_INTERFACE_DR))
508e53e2 1509 ospf6_interface_state_change (dr_election (oi), oi);
718e3744 1510
1511 return CMD_SUCCESS;
1512}
1513
1514DEFUN (ipv6_ospf6_instance,
1515 ipv6_ospf6_instance_cmd,
508e53e2 1516 "ipv6 ospf6 instance-id <0-255>",
718e3744 1517 IP6_STR
1518 OSPF6_STR
508e53e2 1519 "Instance ID for this interface\n"
1520 "Instance ID value\n"
718e3744 1521 )
1522{
508e53e2 1523 struct ospf6_interface *oi;
718e3744 1524 struct interface *ifp;
1525
1526 ifp = (struct interface *)vty->index;
1527 assert (ifp);
1528
508e53e2 1529 oi = (struct ospf6_interface *)ifp->info;
1530 if (oi == NULL)
1531 oi = ospf6_interface_create (ifp);
1532 assert (oi);
718e3744 1533
508e53e2 1534 oi->instance_id = strtol (argv[0], NULL, 10);
718e3744 1535 return CMD_SUCCESS;
1536}
1537
1538DEFUN (ipv6_ospf6_passive,
1539 ipv6_ospf6_passive_cmd,
1540 "ipv6 ospf6 passive",
1541 IP6_STR
1542 OSPF6_STR
508e53e2 1543 "passive interface, No adjacency will be formed on this interface\n"
718e3744 1544 )
1545{
508e53e2 1546 struct ospf6_interface *oi;
718e3744 1547 struct interface *ifp;
1eb8ef25 1548 struct listnode *node, *nnode;
508e53e2 1549 struct ospf6_neighbor *on;
718e3744 1550
1551 ifp = (struct interface *) vty->index;
1552 assert (ifp);
718e3744 1553
508e53e2 1554 oi = (struct ospf6_interface *) ifp->info;
1555 if (oi == NULL)
1556 oi = ospf6_interface_create (ifp);
1557 assert (oi);
718e3744 1558
508e53e2 1559 SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1560 THREAD_OFF (oi->thread_send_hello);
1561
1eb8ef25 1562 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
718e3744 1563 {
508e53e2 1564 THREAD_OFF (on->inactivity_timer);
3e834b12 1565 thread_add_event (master, inactivity_timer, on, 0);
718e3744 1566 }
1567
1568 return CMD_SUCCESS;
1569}
1570
1571DEFUN (no_ipv6_ospf6_passive,
1572 no_ipv6_ospf6_passive_cmd,
1573 "no ipv6 ospf6 passive",
1574 NO_STR
1575 IP6_STR
1576 OSPF6_STR
1577 "passive interface: No Adjacency will be formed on this I/F\n"
1578 )
1579{
508e53e2 1580 struct ospf6_interface *oi;
718e3744 1581 struct interface *ifp;
1582
1583 ifp = (struct interface *) vty->index;
1584 assert (ifp);
718e3744 1585
508e53e2 1586 oi = (struct ospf6_interface *) ifp->info;
1587 if (oi == NULL)
1588 oi = ospf6_interface_create (ifp);
1589 assert (oi);
718e3744 1590
508e53e2 1591 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1592 THREAD_OFF (oi->thread_send_hello);
1593 oi->thread_send_hello =
1594 thread_add_event (master, ospf6_hello_send, oi, 0);
718e3744 1595
1596 return CMD_SUCCESS;
1597}
1598
d42306d9
DT
1599DEFUN (ipv6_ospf6_mtu_ignore,
1600 ipv6_ospf6_mtu_ignore_cmd,
1601 "ipv6 ospf6 mtu-ignore",
1602 IP6_STR
1603 OSPF6_STR
1604 "Ignore MTU mismatch on this interface\n"
1605 )
1606{
1607 struct ospf6_interface *oi;
1608 struct interface *ifp;
1609
1610 ifp = (struct interface *) vty->index;
1611 assert (ifp);
1612
1613 oi = (struct ospf6_interface *) ifp->info;
1614 if (oi == NULL)
1615 oi = ospf6_interface_create (ifp);
1616 assert (oi);
1617
1618 oi->mtu_ignore = 1;
1619
1620 return CMD_SUCCESS;
1621}
1622
1623DEFUN (no_ipv6_ospf6_mtu_ignore,
1624 no_ipv6_ospf6_mtu_ignore_cmd,
1625 "no ipv6 ospf6 mtu-ignore",
1626 NO_STR
1627 IP6_STR
1628 OSPF6_STR
1629 "Ignore MTU mismatch on this interface\n"
1630 )
1631{
1632 struct ospf6_interface *oi;
1633 struct interface *ifp;
1634
1635 ifp = (struct interface *) vty->index;
1636 assert (ifp);
1637
1638 oi = (struct ospf6_interface *) ifp->info;
1639 if (oi == NULL)
1640 oi = ospf6_interface_create (ifp);
1641 assert (oi);
1642
1643 oi->mtu_ignore = 0;
1644
1645 return CMD_SUCCESS;
1646}
1647
718e3744 1648DEFUN (ipv6_ospf6_advertise_prefix_list,
1649 ipv6_ospf6_advertise_prefix_list_cmd,
1650 "ipv6 ospf6 advertise prefix-list WORD",
1651 IP6_STR
1652 OSPF6_STR
1653 "Advertising options\n"
1654 "Filter prefix using prefix-list\n"
1655 "Prefix list name\n"
1656 )
1657{
508e53e2 1658 struct ospf6_interface *oi;
718e3744 1659 struct interface *ifp;
1660
1661 ifp = (struct interface *) vty->index;
1662 assert (ifp);
718e3744 1663
508e53e2 1664 oi = (struct ospf6_interface *) ifp->info;
1665 if (oi == NULL)
1666 oi = ospf6_interface_create (ifp);
1667 assert (oi);
718e3744 1668
508e53e2 1669 if (oi->plist_name)
1670 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1671 oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
718e3744 1672
508e53e2 1673 ospf6_interface_connected_route_update (oi->interface);
2470e99e
DW
1674
1675 if (oi->area)
508e53e2 1676 {
2470e99e
DW
1677 OSPF6_LINK_LSA_SCHEDULE (oi);
1678 if (oi->state == OSPF6_INTERFACE_DR)
1679 {
1680 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1681 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1682 }
1683 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
508e53e2 1684 }
718e3744 1685
1686 return CMD_SUCCESS;
1687}
1688
1689DEFUN (no_ipv6_ospf6_advertise_prefix_list,
1690 no_ipv6_ospf6_advertise_prefix_list_cmd,
1691 "no ipv6 ospf6 advertise prefix-list",
1692 NO_STR
1693 IP6_STR
1694 OSPF6_STR
1695 "Advertising options\n"
1696 "Filter prefix using prefix-list\n"
1697 )
1698{
508e53e2 1699 struct ospf6_interface *oi;
718e3744 1700 struct interface *ifp;
1701
1702 ifp = (struct interface *) vty->index;
1703 assert (ifp);
718e3744 1704
508e53e2 1705 oi = (struct ospf6_interface *) ifp->info;
1706 if (oi == NULL)
1707 oi = ospf6_interface_create (ifp);
1708 assert (oi);
1709
1710 if (oi->plist_name)
718e3744 1711 {
508e53e2 1712 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1713 oi->plist_name = NULL;
718e3744 1714 }
1715
508e53e2 1716 ospf6_interface_connected_route_update (oi->interface);
2470e99e
DW
1717
1718 if (oi->area)
508e53e2 1719 {
2470e99e
DW
1720 OSPF6_LINK_LSA_SCHEDULE (oi);
1721 if (oi->state == OSPF6_INTERFACE_DR)
1722 {
1723 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1724 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1725 }
1726 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
508e53e2 1727 }
718e3744 1728
1729 return CMD_SUCCESS;
1730}
1731
c5926a92
DD
1732DEFUN (ipv6_ospf6_network,
1733 ipv6_ospf6_network_cmd,
1734 "ipv6 ospf6 network (broadcast|point-to-point)",
1735 IP6_STR
1736 OSPF6_STR
1737 "Network Type\n"
1738 "Specify OSPFv6 broadcast network\n"
1739 "Specify OSPF6 point-to-point network\n"
1740 )
1741{
1742 struct ospf6_interface *oi;
1743 struct interface *ifp;
1744
1745 ifp = (struct interface *) vty->index;
1746 assert (ifp);
1747
1748 oi = (struct ospf6_interface *) ifp->info;
1749 if (oi == NULL) {
1750 oi = ospf6_interface_create (ifp);
1751 }
1752 assert (oi);
1753
1754 if (strncmp (argv[0], "b", 1) == 0)
1755 {
1756 if (oi->type == OSPF_IFTYPE_BROADCAST)
1757 return CMD_SUCCESS;
1758
1759 oi->type = OSPF_IFTYPE_BROADCAST;
1760 }
1761 else if (strncmp (argv[0], "point-to-p", 10) == 0)
1762 {
1763 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
1764 return CMD_SUCCESS;
1765 }
1766 oi->type = OSPF_IFTYPE_POINTOPOINT;
1767 }
1768
1769 /* Reset the interface */
1770 thread_add_event (master, interface_down, oi, 0);
1771 thread_add_event (master, interface_up, oi, 0);
1772
1773 return CMD_SUCCESS;
1774}
1775
1776DEFUN (no_ipv6_ospf6_network,
1777 no_ipv6_ospf6_network_cmd,
1778 "no ipv6 ospf6 network",
1779 NO_STR
1780 IP6_STR
1781 OSPF6_STR
1782 "Network Type\n"
1783 "Default to whatever interface type system specifies"
1784 )
1785{
1786 struct ospf6_interface *oi;
1787 struct interface *ifp;
1788 int type;
1789
1790 ifp = (struct interface *) vty->index;
1791 assert (ifp);
1792
1793 oi = (struct ospf6_interface *) ifp->info;
1794 if (oi == NULL) {
1795 return CMD_SUCCESS;
1796 }
1797
1798 type = ospf6_default_iftype (ifp);
1799 if (oi->type == type)
1800 {
1801 return CMD_SUCCESS;
1802 }
1803 oi->type = type;
1804
1805 /* Reset the interface */
1806 thread_add_event (master, interface_down, oi, 0);
1807 thread_add_event (master, interface_up, oi, 0);
1808
1809 return CMD_SUCCESS;
1810}
1811
6ac29a51 1812static int
508e53e2 1813config_write_ospf6_interface (struct vty *vty)
718e3744 1814{
52dc7ee6 1815 struct listnode *i;
508e53e2 1816 struct ospf6_interface *oi;
718e3744 1817 struct interface *ifp;
1818
b2d7c082 1819 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
718e3744 1820 {
508e53e2 1821 oi = (struct ospf6_interface *) ifp->info;
1822 if (oi == NULL)
718e3744 1823 continue;
1824
1825 vty_out (vty, "interface %s%s",
049207c3 1826 oi->interface->name, VNL);
508e53e2 1827
1828 if (ifp->desc)
049207c3 1829 vty_out (vty, " description %s%s", ifp->desc, VNL);
1203e1c0 1830 if (ifp->mtu6 != oi->ifmtu)
049207c3 1831 vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
b51a3a31 1832
c19543b2 1833 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST))
b51a3a31
VT
1834 vty_out (vty, " ipv6 ospf6 cost %d%s",
1835 oi->cost, VNL);
1836
1837 if (oi->hello_interval != OSPF6_INTERFACE_HELLO_INTERVAL)
1838 vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
1839 oi->hello_interval, VNL);
1840
1841 if (oi->dead_interval != OSPF6_INTERFACE_DEAD_INTERVAL)
1842 vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
1843 oi->dead_interval, VNL);
1844
1845 if (oi->rxmt_interval != OSPF6_INTERFACE_RXMT_INTERVAL)
1846 vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
1847 oi->rxmt_interval, VNL);
1848
1849 if (oi->priority != OSPF6_INTERFACE_PRIORITY)
1850 vty_out (vty, " ipv6 ospf6 priority %d%s",
1851 oi->priority, VNL);
1852
1853 if (oi->transdelay != OSPF6_INTERFACE_TRANSDELAY)
1854 vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
1855 oi->transdelay, VNL);
1856
1857 if (oi->instance_id != OSPF6_INTERFACE_INSTANCE_ID)
1858 vty_out (vty, " ipv6 ospf6 instance-id %d%s",
1859 oi->instance_id, VNL);
718e3744 1860
508e53e2 1861 if (oi->plist_name)
718e3744 1862 vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
049207c3 1863 oi->plist_name, VNL);
718e3744 1864
508e53e2 1865 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
049207c3 1866 vty_out (vty, " ipv6 ospf6 passive%s", VNL);
718e3744 1867
d42306d9
DT
1868 if (oi->mtu_ignore)
1869 vty_out (vty, " ipv6 ospf6 mtu-ignore%s", VNL);
1870
1d374104 1871 if (oi->type != ospf6_default_iftype(ifp))
1872 {
1873 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
1874 vty_out (vty, " ipv6 ospf6 network point-to-point%s", VNL);
1875 else if (oi->type == OSPF_IFTYPE_BROADCAST)
1876 vty_out (vty, " ipv6 ospf6 network broadcast%s", VNL);
1877 }
c5926a92 1878
7f342629
DS
1879 ospf6_bfd_write_config(vty, oi);
1880
049207c3 1881 vty_out (vty, "!%s", VNL);
718e3744 1882 }
1883 return 0;
1884}
1885
7fc626de 1886static struct cmd_node interface_node =
718e3744 1887{
1888 INTERFACE_NODE,
1889 "%s(config-if)# ",
69b4a810 1890 1 /* VTYSH */
718e3744 1891};
1892
1893void
6ac29a51 1894ospf6_interface_init (void)
718e3744 1895{
1896 /* Install interface node. */
508e53e2 1897 install_node (&interface_node, config_write_ospf6_interface);
718e3744 1898
1899 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
508e53e2 1900 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1901 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1902 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
718e3744 1903 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
508e53e2 1904 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1905 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1906 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
718e3744 1907 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
508e53e2 1908 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1909 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1910 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
718e3744 1911 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
508e53e2 1912 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1913 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1914 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
718e3744 1915
508e53e2 1916 install_element (CONFIG_NODE, &interface_cmd);
718e3744 1917 install_default (INTERFACE_NODE);
1918 install_element (INTERFACE_NODE, &interface_desc_cmd);
1919 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1920 install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
c19543b2 1921 install_element (INTERFACE_NODE, &no_ipv6_ospf6_cost_cmd);
b596c71e 1922 install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
049207c3 1923 install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
718e3744 1924 install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
1925 install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
1926 install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
1927 install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
1928 install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
1929 install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
508e53e2 1930
718e3744 1931 install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
1932 install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
508e53e2 1933
d42306d9
DT
1934 install_element (INTERFACE_NODE, &ipv6_ospf6_mtu_ignore_cmd);
1935 install_element (INTERFACE_NODE, &no_ipv6_ospf6_mtu_ignore_cmd);
1936
508e53e2 1937 install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
1938 install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
c5926a92
DD
1939
1940 install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
1941 install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
fd500689
VB
1942
1943 /* reference bandwidth commands */
1944 install_element (OSPF6_NODE, &auto_cost_reference_bandwidth_cmd);
1945 install_element (OSPF6_NODE, &no_auto_cost_reference_bandwidth_cmd);
813d4307 1946 install_element (OSPF6_NODE, &no_auto_cost_reference_bandwidth_val_cmd);
508e53e2 1947}
1948
a1b11f9b
DS
1949/* Clear the specified interface structure */
1950static void
1951ospf6_interface_clear (struct vty *vty, struct interface *ifp)
1952{
1953 struct ospf6_interface *oi;
1954
1955 if (!if_is_operative (ifp))
1956 return;
1957
1958 if (ifp->info == NULL)
1959 return;
1960
1961 oi = (struct ospf6_interface *) ifp->info;
1962
1963 if (IS_OSPF6_DEBUG_INTERFACE)
1964 zlog_debug ("Interface %s: clear by reset", ifp->name);
1965
1966 /* Reset the interface */
1967 thread_add_event (master, interface_down, oi, 0);
1968 thread_add_event (master, interface_up, oi, 0);
1969}
1970
1971/* Clear interface */
1972DEFUN (clear_ipv6_ospf6_interface,
1973 clear_ipv6_ospf6_interface_cmd,
1974 "clear ipv6 ospf6 interface [IFNAME]",
1975 CLEAR_STR
1976 IP6_STR
1977 OSPF6_STR
1978 INTERFACE_STR
1979 IFNAME_STR
1980 )
1981{
1982 struct interface *ifp;
1983 struct listnode *node;
1984
1985 if (argc == 0) /* Clear all the ospfv3 interfaces. */
1986 {
b2d7c082 1987 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
a1b11f9b
DS
1988 ospf6_interface_clear (vty, ifp);
1989 }
1990 else /* Interface name is specified. */
1991 {
1992 if ((ifp = if_lookup_by_name (argv[0])) == NULL)
1993 {
1994 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
1995 return CMD_WARNING;
1996 }
1997 ospf6_interface_clear (vty, ifp);
1998 }
1999
2000 return CMD_SUCCESS;
2001}
2002
2003void
2004install_element_ospf6_clear_interface (void)
2005{
2006 install_element (ENABLE_NODE, &clear_ipv6_ospf6_interface_cmd);
2007}
2008
508e53e2 2009DEFUN (debug_ospf6_interface,
2010 debug_ospf6_interface_cmd,
2011 "debug ospf6 interface",
2012 DEBUG_STR
2013 OSPF6_STR
2014 "Debug OSPFv3 Interface\n"
2015 )
2016{
2017 OSPF6_DEBUG_INTERFACE_ON ();
2018 return CMD_SUCCESS;
2019}
2020
2021DEFUN (no_debug_ospf6_interface,
2022 no_debug_ospf6_interface_cmd,
2023 "no debug ospf6 interface",
2024 NO_STR
2025 DEBUG_STR
2026 OSPF6_STR
2027 "Debug OSPFv3 Interface\n"
2028 )
2029{
3b68735f 2030 OSPF6_DEBUG_INTERFACE_OFF ();
508e53e2 2031 return CMD_SUCCESS;
2032}
2033
2034int
2035config_write_ospf6_debug_interface (struct vty *vty)
2036{
2037 if (IS_OSPF6_DEBUG_INTERFACE)
049207c3 2038 vty_out (vty, "debug ospf6 interface%s", VNL);
508e53e2 2039 return 0;
2040}
2041
2042void
6ac29a51 2043install_element_ospf6_debug_interface (void)
508e53e2 2044{
2045 install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
2046 install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
2047 install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
2048 install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
718e3744 2049}
2050
2051