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