]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_interface.c
* lib/prefix.[hc]: inet6_ntoa utility function copied from
[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"
718e3744 31
508e53e2 32#include "ospf6_lsa.h"
718e3744 33#include "ospf6_lsdb.h"
508e53e2 34#include "ospf6_network.h"
35#include "ospf6_message.h"
36#include "ospf6_route.h"
718e3744 37#include "ospf6_top.h"
38#include "ospf6_area.h"
39#include "ospf6_interface.h"
508e53e2 40#include "ospf6_neighbor.h"
41#include "ospf6_intra.h"
42#include "ospf6_spf.h"
049207c3 43#include "ospf6d.h"
718e3744 44
508e53e2 45unsigned char conf_debug_ospf6_interface = 0;
46
0c083ee9 47const char *ospf6_interface_state_str[] =
718e3744 48{
508e53e2 49 "None",
50 "Down",
51 "Loopback",
52 "Waiting",
53 "PointToPoint",
54 "DROther",
55 "BDR",
56 "DR",
57 NULL
718e3744 58};
59
508e53e2 60struct ospf6_interface *
61ospf6_interface_lookup_by_ifindex (int ifindex)
718e3744 62{
508e53e2 63 struct ospf6_interface *oi;
64 struct interface *ifp;
718e3744 65
508e53e2 66 ifp = if_lookup_by_index (ifindex);
67 if (ifp == NULL)
68 return (struct ospf6_interface *) NULL;
69
70 oi = (struct ospf6_interface *) ifp->info;
71 return oi;
718e3744 72}
73
508e53e2 74/* schedule routing table recalculation */
718e3744 75void
508e53e2 76ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
718e3744 77{
508e53e2 78 switch (ntohs (lsa->header->type))
79 {
80 case OSPF6_LSTYPE_LINK:
6452df09 81 if (OSPF6_INTERFACE (lsa->lsdb->data)->state == OSPF6_INTERFACE_DR)
82 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (OSPF6_INTERFACE (lsa->lsdb->data));
83 ospf6_spf_schedule (OSPF6_INTERFACE (lsa->lsdb->data)->area);
508e53e2 84 break;
85
86 default:
508e53e2 87 break;
88 }
718e3744 89}
90
91/* Create new ospf6 interface structure */
92struct ospf6_interface *
93ospf6_interface_create (struct interface *ifp)
94{
508e53e2 95 struct ospf6_interface *oi;
0c083ee9 96 unsigned int iobuflen;
718e3744 97
508e53e2 98 oi = (struct ospf6_interface *)
718e3744 99 XMALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
100
508e53e2 101 if (oi)
102 memset (oi, 0, sizeof (struct ospf6_interface));
718e3744 103 else
104 {
105 zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
106 return (struct ospf6_interface *) NULL;
107 }
108
508e53e2 109 oi->area = (struct ospf6_area *) NULL;
110 oi->neighbor_list = list_new ();
111 oi->neighbor_list->cmp = ospf6_neighbor_cmp;
112 oi->linklocal_addr = (struct in6_addr *) NULL;
113 oi->instance_id = 0;
114 oi->transdelay = 1;
115 oi->priority = 1;
116
117 oi->hello_interval = 10;
118 oi->dead_interval = 40;
119 oi->rxmt_interval = 5;
120 oi->cost = 1;
508e53e2 121 oi->state = OSPF6_INTERFACE_DOWN;
122 oi->flag = 0;
123
b596c71e 124 /* Try to adjust I/O buffer size with IfMtu */
1203e1c0 125 oi->ifmtu = ifp->mtu6;
126 iobuflen = ospf6_iobuf_size (ifp->mtu6);
b596c71e 127 if (oi->ifmtu > iobuflen)
3b4cd3a9 128 {
1e05838a 129 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 130 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
131 ifp->name, iobuflen);
3b4cd3a9 132 oi->ifmtu = iobuflen;
133 }
3b4cd3a9 134
6452df09 135 oi->lsupdate_list = ospf6_lsdb_create (oi);
136 oi->lsack_list = ospf6_lsdb_create (oi);
137 oi->lsdb = ospf6_lsdb_create (oi);
508e53e2 138 oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
139 oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
6452df09 140 oi->lsdb_self = ospf6_lsdb_create (oi);
508e53e2 141
142 oi->route_connected = ospf6_route_table_create ();
718e3744 143
144 /* link both */
508e53e2 145 oi->interface = ifp;
146 ifp->info = oi;
718e3744 147
508e53e2 148 return oi;
718e3744 149}
150
151void
508e53e2 152ospf6_interface_delete (struct ospf6_interface *oi)
718e3744 153{
52dc7ee6 154 struct listnode *n;
508e53e2 155 struct ospf6_neighbor *on;
718e3744 156
508e53e2 157 for (n = listhead (oi->neighbor_list); n; nextnode (n))
718e3744 158 {
508e53e2 159 on = (struct ospf6_neighbor *) getdata (n);
160 ospf6_neighbor_delete (on);
718e3744 161 }
508e53e2 162 list_delete (oi->neighbor_list);
718e3744 163
508e53e2 164 THREAD_OFF (oi->thread_send_hello);
165 THREAD_OFF (oi->thread_send_lsupdate);
166 THREAD_OFF (oi->thread_send_lsack);
167
168 ospf6_lsdb_remove_all (oi->lsdb);
169 ospf6_lsdb_remove_all (oi->lsupdate_list);
170 ospf6_lsdb_remove_all (oi->lsack_list);
171
172 ospf6_lsdb_delete (oi->lsdb);
6452df09 173 ospf6_lsdb_delete (oi->lsdb_self);
174
508e53e2 175 ospf6_lsdb_delete (oi->lsupdate_list);
176 ospf6_lsdb_delete (oi->lsack_list);
718e3744 177
508e53e2 178 ospf6_route_table_delete (oi->route_connected);
718e3744 179
180 /* cut link */
508e53e2 181 oi->interface->info = NULL;
718e3744 182
183 /* plist_name */
508e53e2 184 if (oi->plist_name)
185 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
186
187 XFREE (MTYPE_OSPF6_IF, oi);
188}
189
190void
191ospf6_interface_enable (struct ospf6_interface *oi)
192{
193 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
718e3744 194
508e53e2 195 oi->thread_send_hello =
196 thread_add_event (master, ospf6_hello_send, oi, 0);
197}
198
199void
200ospf6_interface_disable (struct ospf6_interface *oi)
201{
52dc7ee6 202 struct listnode *i;
508e53e2 203 struct ospf6_neighbor *on;
204
205 SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
206
207 for (i = listhead (oi->neighbor_list); i; nextnode (i))
208 {
209 on = (struct ospf6_neighbor *) getdata (i);
210 ospf6_neighbor_delete (on);
211 }
212 list_delete_all_node (oi->neighbor_list);
213
214 ospf6_lsdb_remove_all (oi->lsdb);
215 ospf6_lsdb_remove_all (oi->lsupdate_list);
216 ospf6_lsdb_remove_all (oi->lsack_list);
217
218 THREAD_OFF (oi->thread_send_hello);
219 THREAD_OFF (oi->thread_send_lsupdate);
220 THREAD_OFF (oi->thread_send_lsack);
718e3744 221}
222
223static struct in6_addr *
508e53e2 224ospf6_interface_get_linklocal_address (struct interface *ifp)
718e3744 225{
52dc7ee6 226 struct listnode *n;
718e3744 227 struct connected *c;
228 struct in6_addr *l = (struct in6_addr *) NULL;
229
230 /* for each connected address */
231 for (n = listhead (ifp->connected); n; nextnode (n))
232 {
233 c = (struct connected *) getdata (n);
234
235 /* if family not AF_INET6, ignore */
236 if (c->address->family != AF_INET6)
237 continue;
238
239 /* linklocal scope check */
240 if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
241 l = &c->address->u.prefix6;
242 }
243 return l;
244}
245
246void
247ospf6_interface_if_add (struct interface *ifp)
248{
508e53e2 249 struct ospf6_interface *oi;
0c083ee9 250 unsigned int iobuflen;
718e3744 251
508e53e2 252 oi = (struct ospf6_interface *) ifp->info;
253 if (oi == NULL)
718e3744 254 return;
255
b596c71e 256 /* Try to adjust I/O buffer size with IfMtu */
257 if (oi->ifmtu == 0)
1203e1c0 258 oi->ifmtu = ifp->mtu6;
259 iobuflen = ospf6_iobuf_size (ifp->mtu6);
b596c71e 260 if (oi->ifmtu > iobuflen)
3b4cd3a9 261 {
1e05838a 262 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 263 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
264 ifp->name, iobuflen);
3b4cd3a9 265 oi->ifmtu = iobuflen;
266 }
718e3744 267
268 /* interface start */
508e53e2 269 if (oi->area)
270 thread_add_event (master, interface_up, oi, 0);
718e3744 271}
272
273void
274ospf6_interface_if_del (struct interface *ifp)
275{
508e53e2 276 struct ospf6_interface *oi;
718e3744 277
508e53e2 278 oi = (struct ospf6_interface *) ifp->info;
279 if (oi == NULL)
718e3744 280 return;
281
282 /* interface stop */
508e53e2 283 if (oi->area)
284 thread_execute (master, interface_down, oi, 0);
718e3744 285
508e53e2 286 listnode_delete (oi->area->if_list, oi);
287 oi->area = (struct ospf6_area *) NULL;
718e3744 288
289 /* cut link */
508e53e2 290 oi->interface = NULL;
718e3744 291 ifp->info = NULL;
292
508e53e2 293 ospf6_interface_delete (oi);
718e3744 294}
295
296void
297ospf6_interface_state_update (struct interface *ifp)
298{
508e53e2 299 struct ospf6_interface *oi;
718e3744 300
508e53e2 301 oi = (struct ospf6_interface *) ifp->info;
302 if (oi == NULL)
718e3744 303 return;
508e53e2 304 if (oi->area == NULL)
718e3744 305 return;
306
307 if (if_is_up (ifp))
508e53e2 308 thread_add_event (master, interface_up, oi, 0);
718e3744 309 else
508e53e2 310 thread_add_event (master, interface_down, oi, 0);
718e3744 311
312 return;
313}
314
315void
508e53e2 316ospf6_interface_connected_route_update (struct interface *ifp)
718e3744 317{
508e53e2 318 struct ospf6_interface *oi;
319 struct ospf6_route *route;
320 struct connected *c;
52dc7ee6 321 struct listnode *i;
718e3744 322
508e53e2 323 oi = (struct ospf6_interface *) ifp->info;
324 if (oi == NULL)
718e3744 325 return;
326
327 /* reset linklocal pointer */
508e53e2 328 oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
718e3744 329
508e53e2 330 /* if area is null, do not make connected-route list */
331 if (oi->area == NULL)
718e3744 332 return;
333
508e53e2 334 /* update "route to advertise" interface route table */
335 ospf6_route_remove_all (oi->route_connected);
336 for (i = listhead (oi->interface->connected); i; nextnode (i))
337 {
338 c = (struct connected *) getdata (i);
339
340 if (c->address->family != AF_INET6)
341 continue;
342
1e05838a 343 CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
344 CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
345 CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
346 CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
347 CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
718e3744 348
508e53e2 349 /* apply filter */
350 if (oi->plist_name)
351 {
352 struct prefix_list *plist;
353 enum prefix_list_type ret;
354 char buf[128];
355
356 prefix2str (c->address, buf, sizeof (buf));
357 plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
358 ret = prefix_list_apply (plist, (void *) c->address);
359 if (ret == PREFIX_DENY)
360 {
1e05838a 361 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 362 zlog_debug ("%s on %s filtered by prefix-list %s ",
363 buf, oi->interface->name, oi->plist_name);
508e53e2 364 continue;
365 }
366 }
367
368 route = ospf6_route_create ();
369 memcpy (&route->prefix, c->address, sizeof (struct prefix));
370 apply_mask (&route->prefix);
371 route->type = OSPF6_DEST_TYPE_NETWORK;
372 route->path.area_id = oi->area->area_id;
373 route->path.type = OSPF6_PATH_TYPE_INTRA;
374 route->path.cost = oi->cost;
375 route->nexthop[0].ifindex = oi->interface->ifindex;
376 inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
377 ospf6_route_add (route, oi->route_connected);
378 }
379
380 /* create new Link-LSA */
381 OSPF6_LINK_LSA_SCHEDULE (oi);
382 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
383 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
718e3744 384}
385
508e53e2 386static void
387ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
718e3744 388{
508e53e2 389 u_char prev_state;
718e3744 390
508e53e2 391 prev_state = oi->state;
392 oi->state = next_state;
718e3744 393
508e53e2 394 if (prev_state == next_state)
395 return;
396
397 /* log */
398 if (IS_OSPF6_DEBUG_INTERFACE)
399 {
c6487d61 400 zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
401 ospf6_interface_state_str[prev_state],
402 ospf6_interface_state_str[next_state]);
508e53e2 403 }
718e3744 404
508e53e2 405 if ((prev_state == OSPF6_INTERFACE_DR ||
406 prev_state == OSPF6_INTERFACE_BDR) &&
407 (next_state != OSPF6_INTERFACE_DR &&
408 next_state != OSPF6_INTERFACE_BDR))
409 ospf6_leave_alldrouters (oi->interface->ifindex);
410 if ((prev_state != OSPF6_INTERFACE_DR &&
411 prev_state != OSPF6_INTERFACE_BDR) &&
412 (next_state == OSPF6_INTERFACE_DR ||
413 next_state == OSPF6_INTERFACE_BDR))
414 ospf6_join_alldrouters (oi->interface->ifindex);
415
416 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
6452df09 417 if (next_state == OSPF6_INTERFACE_DOWN)
418 {
419 OSPF6_NETWORK_LSA_EXECUTE (oi);
420 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
421 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
422 }
423 else if (prev_state == OSPF6_INTERFACE_DR ||
424 next_state == OSPF6_INTERFACE_DR)
508e53e2 425 {
426 OSPF6_NETWORK_LSA_SCHEDULE (oi);
427 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
428 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
429 }
718e3744 430}
431
508e53e2 432\f
433/* DR Election, RFC2328 section 9.4 */
718e3744 434
508e53e2 435#define IS_ELIGIBLE(n) \
436 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
718e3744 437
508e53e2 438static struct ospf6_neighbor *
439better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
440{
441 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
442 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
443 return NULL;
444 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
445 return b;
446 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
447 return a;
448
449 if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
450 return a;
451 if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
452 return b;
453
454 if (a->priority > b->priority)
455 return a;
456 if (a->priority < b->priority)
457 return b;
458
459 if (ntohl (a->router_id) > ntohl (b->router_id))
460 return a;
461 if (ntohl (a->router_id) < ntohl (b->router_id))
462 return b;
463
464 zlog_warn ("Router-ID duplicate ?");
465 return a;
466}
718e3744 467
508e53e2 468static struct ospf6_neighbor *
469better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
470{
471 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
472 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
473 return NULL;
474 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
475 return b;
476 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
477 return a;
478
479 if (a->drouter == a->router_id && b->drouter != b->router_id)
480 return a;
481 if (a->drouter != a->router_id && b->drouter == b->router_id)
482 return b;
483
484 if (a->priority > b->priority)
485 return a;
486 if (a->priority < b->priority)
487 return b;
488
489 if (ntohl (a->router_id) > ntohl (b->router_id))
490 return a;
491 if (ntohl (a->router_id) < ntohl (b->router_id))
492 return b;
493
494 zlog_warn ("Router-ID duplicate ?");
495 return a;
718e3744 496}
497
508e53e2 498static u_char
499dr_election (struct ospf6_interface *oi)
718e3744 500{
52dc7ee6 501 struct listnode *i;
508e53e2 502 struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
503 struct ospf6_neighbor *best_drouter, *best_bdrouter;
504 u_char next_state = 0;
505
506 drouter = bdrouter = NULL;
507 best_drouter = best_bdrouter = NULL;
508
509 /* pseudo neighbor myself, including noting current DR/BDR (1) */
510 memset (&myself, 0, sizeof (myself));
511 inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
512 sizeof (myself.name));
513 myself.state = OSPF6_NEIGHBOR_TWOWAY;
514 myself.drouter = oi->drouter;
515 myself.bdrouter = oi->bdrouter;
516 myself.priority = oi->priority;
517 myself.router_id = oi->area->ospf6->router_id;
518
519 /* Electing BDR (2) */
520 for (i = listhead (oi->neighbor_list); i; nextnode (i))
521 {
522 on = (struct ospf6_neighbor *) getdata (i);
523 bdrouter = better_bdrouter (bdrouter, on);
524 }
525 best_bdrouter = bdrouter;
526 bdrouter = better_bdrouter (best_bdrouter, &myself);
527
528 /* Electing DR (3) */
529 for (i = listhead (oi->neighbor_list); i; nextnode (i))
530 {
531 on = (struct ospf6_neighbor *) getdata (i);
532 drouter = better_drouter (drouter, on);
533 }
534 best_drouter = drouter;
535 drouter = better_drouter (best_drouter, &myself);
536 if (drouter == NULL)
537 drouter = bdrouter;
538
539 /* the router itself is newly/no longer DR/BDR (4) */
540 if ((drouter == &myself && myself.drouter != myself.router_id) ||
541 (drouter != &myself && myself.drouter == myself.router_id) ||
542 (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
543 (bdrouter != &myself && myself.bdrouter == myself.router_id))
544 {
545 myself.drouter = (drouter ? drouter->router_id : htonl (0));
546 myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
547
548 /* compatible to Electing BDR (2) */
549 bdrouter = better_bdrouter (best_bdrouter, &myself);
550
551 /* compatible to Electing DR (3) */
552 drouter = better_drouter (best_drouter, &myself);
553 if (drouter == NULL)
554 drouter = bdrouter;
555 }
556
557 /* Set interface state accordingly (5) */
558 if (drouter && drouter == &myself)
559 next_state = OSPF6_INTERFACE_DR;
560 else if (bdrouter && bdrouter == &myself)
561 next_state = OSPF6_INTERFACE_BDR;
562 else
563 next_state = OSPF6_INTERFACE_DROTHER;
718e3744 564
508e53e2 565 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
566 /* XXX */
567
568 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
569 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
570 accordingly after AdjOK */
571 if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
572 oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
718e3744 573 {
508e53e2 574 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 575 zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
576 (drouter ? drouter->name : "0.0.0.0"),
577 (bdrouter ? bdrouter->name : "0.0.0.0"));
508e53e2 578
579 for (i = listhead (oi->neighbor_list); i; nextnode (i))
580 {
581 on = (struct ospf6_neighbor *) getdata (i);
582 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
583 continue;
584 /* Schedule AdjOK. */
585 thread_add_event (master, adj_ok, on, 0);
586 }
718e3744 587 }
508e53e2 588
589 oi->drouter = (drouter ? drouter->router_id : htonl (0));
590 oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
591 return next_state;
718e3744 592}
593
508e53e2 594\f
595/* Interface State Machine */
718e3744 596int
508e53e2 597interface_up (struct thread *thread)
718e3744 598{
508e53e2 599 struct ospf6_interface *oi;
600
601 oi = (struct ospf6_interface *) THREAD_ARG (thread);
602 assert (oi && oi->interface);
603
604 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 605 zlog_debug ("Interface Event %s: [InterfaceUp]",
606 oi->interface->name);
508e53e2 607
608 /* check physical interface is up */
609 if (! if_is_up (oi->interface))
610 {
611 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 612 zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
613 oi->interface->name);
508e53e2 614 return 0;
615 }
616
617 /* if already enabled, do nothing */
618 if (oi->state > OSPF6_INTERFACE_DOWN)
619 {
620 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 621 zlog_debug ("Interface %s already enabled",
622 oi->interface->name);
508e53e2 623 return 0;
624 }
625
626 /* Join AllSPFRouters */
627 ospf6_join_allspfrouters (oi->interface->ifindex);
628
629 /* Update interface route */
630 ospf6_interface_connected_route_update (oi->interface);
718e3744 631
508e53e2 632 /* Schedule Hello */
633 if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
634 thread_add_event (master, ospf6_hello_send, oi, 0);
635
636 /* decide next interface state */
637 if (if_is_pointopoint (oi->interface))
638 ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
639 else if (oi->priority == 0)
640 ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
641 else
718e3744 642 {
508e53e2 643 ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
644 thread_add_timer (master, wait_timer, oi, oi->dead_interval);
718e3744 645 }
508e53e2 646
647 return 0;
718e3744 648}
649
650int
508e53e2 651wait_timer (struct thread *thread)
718e3744 652{
508e53e2 653 struct ospf6_interface *oi;
718e3744 654
508e53e2 655 oi = (struct ospf6_interface *) THREAD_ARG (thread);
656 assert (oi && oi->interface);
718e3744 657
508e53e2 658 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 659 zlog_debug ("Interface Event %s: [WaitTimer]",
660 oi->interface->name);
718e3744 661
508e53e2 662 if (oi->state == OSPF6_INTERFACE_WAITING)
663 ospf6_interface_state_change (dr_election (oi), oi);
718e3744 664
508e53e2 665 return 0;
718e3744 666}
667
508e53e2 668int
669backup_seen (struct thread *thread)
670{
671 struct ospf6_interface *oi;
672
673 oi = (struct ospf6_interface *) THREAD_ARG (thread);
674 assert (oi && oi->interface);
675
676 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 677 zlog_debug ("Interface Event %s: [BackupSeen]",
678 oi->interface->name);
508e53e2 679
680 if (oi->state == OSPF6_INTERFACE_WAITING)
681 ospf6_interface_state_change (dr_election (oi), oi);
682
683 return 0;
684}
685
686int
687neighbor_change (struct thread *thread)
718e3744 688{
508e53e2 689 struct ospf6_interface *oi;
690
691 oi = (struct ospf6_interface *) THREAD_ARG (thread);
692 assert (oi && oi->interface);
693
694 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 695 zlog_debug ("Interface Event %s: [NeighborChange]",
696 oi->interface->name);
508e53e2 697
698 if (oi->state == OSPF6_INTERFACE_DROTHER ||
699 oi->state == OSPF6_INTERFACE_BDR ||
700 oi->state == OSPF6_INTERFACE_DR)
701 ospf6_interface_state_change (dr_election (oi), oi);
702
703 return 0;
718e3744 704}
705
508e53e2 706int
707loopind (struct thread *thread)
708{
709 struct ospf6_interface *oi;
710
711 oi = (struct ospf6_interface *) THREAD_ARG (thread);
712 assert (oi && oi->interface);
713
714 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 715 zlog_debug ("Interface Event %s: [LoopInd]",
716 oi->interface->name);
508e53e2 717
718 /* XXX not yet */
719
720 return 0;
721}
722
723int
724interface_down (struct thread *thread)
718e3744 725{
508e53e2 726 struct ospf6_interface *oi;
52dc7ee6 727 struct listnode *n;
508e53e2 728 struct ospf6_neighbor *on;
729
730 oi = (struct ospf6_interface *) THREAD_ARG (thread);
731 assert (oi && oi->interface);
732
733 if (IS_OSPF6_DEBUG_INTERFACE)
c6487d61 734 zlog_debug ("Interface Event %s: [InterfaceDown]",
735 oi->interface->name);
508e53e2 736
737 /* Leave AllSPFRouters */
738 if (oi->state > OSPF6_INTERFACE_DOWN)
739 ospf6_leave_allspfrouters (oi->interface->ifindex);
740
741 ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
742
743 for (n = listhead (oi->neighbor_list); n; nextnode (n))
744 {
745 on = (struct ospf6_neighbor *) getdata (n);
746 ospf6_neighbor_delete (on);
747 }
748 list_delete_all_node (oi->neighbor_list);
749
750 return 0;
718e3744 751}
752
508e53e2 753\f
718e3744 754/* show specified interface structure */
755int
508e53e2 756ospf6_interface_show (struct vty *vty, struct interface *ifp)
718e3744 757{
508e53e2 758 struct ospf6_interface *oi;
718e3744 759 struct connected *c;
760 struct prefix *p;
52dc7ee6 761 struct listnode *i;
508e53e2 762 char strbuf[64], drouter[32], bdrouter[32];
0c083ee9 763 const char *updown[3] = {"down", "up", NULL};
764 const char *type;
508e53e2 765 struct timeval res, now;
766 char duration[32];
767 struct ospf6_lsa *lsa;
718e3744 768
769 /* check physical interface type */
508e53e2 770 if (if_is_loopback (ifp))
718e3744 771 type = "LOOPBACK";
508e53e2 772 else if (if_is_broadcast (ifp))
718e3744 773 type = "BROADCAST";
508e53e2 774 else if (if_is_pointopoint (ifp))
718e3744 775 type = "POINTOPOINT";
776 else
777 type = "UNKNOWN";
778
779 vty_out (vty, "%s is %s, type %s%s",
508e53e2 780 ifp->name, updown[if_is_up (ifp)], type,
049207c3 781 VNL);
782 vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
718e3744 783
508e53e2 784 if (ifp->info == NULL)
718e3744 785 {
049207c3 786 vty_out (vty, " OSPF not enabled on this interface%s", VNL);
718e3744 787 return 0;
788 }
789 else
508e53e2 790 oi = (struct ospf6_interface *) ifp->info;
718e3744 791
049207c3 792 vty_out (vty, " Internet Address:%s", VNL);
508e53e2 793 for (i = listhead (ifp->connected); i; nextnode (i))
718e3744 794 {
795 c = (struct connected *)getdata (i);
796 p = c->address;
797 prefix2str (p, strbuf, sizeof (strbuf));
798 switch (p->family)
799 {
800 case AF_INET:
508e53e2 801 vty_out (vty, " inet : %s%s", strbuf,
049207c3 802 VNL);
718e3744 803 break;
804 case AF_INET6:
508e53e2 805 vty_out (vty, " inet6: %s%s", strbuf,
049207c3 806 VNL);
718e3744 807 break;
808 default:
508e53e2 809 vty_out (vty, " ??? : %s%s", strbuf,
049207c3 810 VNL);
718e3744 811 break;
812 }
813 }
814
508e53e2 815 if (oi->area)
718e3744 816 {
508e53e2 817 vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
049207c3 818 oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
508e53e2 819 inet_ntop (AF_INET, &oi->area->area_id,
718e3744 820 strbuf, sizeof (strbuf));
508e53e2 821 vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
049207c3 822 VNL);
718e3744 823 }
824 else
049207c3 825 vty_out (vty, " Not Attached to Area%s", VNL);
718e3744 826
827 vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
508e53e2 828 ospf6_interface_state_str[oi->state],
829 oi->transdelay, oi->priority,
049207c3 830 VNL);
831 vty_out (vty, " Timer intervals configured:%s", VNL);
718e3744 832 vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
508e53e2 833 oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
049207c3 834 VNL);
718e3744 835
508e53e2 836 inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
837 inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
049207c3 838 vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
718e3744 839
840 vty_out (vty, " Number of I/F scoped LSAs is %u%s",
049207c3 841 oi->lsdb->count, VNL);
718e3744 842
843 gettimeofday (&now, (struct timezone *) NULL);
718e3744 844
508e53e2 845 timerclear (&res);
846 if (oi->thread_send_lsupdate)
847 timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
848 timerstring (&res, duration, sizeof (duration));
849 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
850 oi->lsupdate_list->count, duration,
851 (oi->thread_send_lsupdate ? "on" : "off"),
049207c3 852 VNL);
508e53e2 853 for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
854 lsa = ospf6_lsdb_next (lsa))
049207c3 855 vty_out (vty, " %s%s", lsa->name, VNL);
508e53e2 856
857 timerclear (&res);
858 if (oi->thread_send_lsack)
859 timersub (&oi->thread_send_lsack->u.sands, &now, &res);
860 timerstring (&res, duration, sizeof (duration));
861 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
862 oi->lsack_list->count, duration,
863 (oi->thread_send_lsack ? "on" : "off"),
049207c3 864 VNL);
508e53e2 865 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
866 lsa = ospf6_lsdb_next (lsa))
049207c3 867 vty_out (vty, " %s%s", lsa->name, VNL);
718e3744 868
508e53e2 869 return 0;
718e3744 870}
871
872/* show interface */
873DEFUN (show_ipv6_ospf6_interface,
874 show_ipv6_ospf6_interface_ifname_cmd,
875 "show ipv6 ospf6 interface IFNAME",
876 SHOW_STR
877 IP6_STR
878 OSPF6_STR
879 INTERFACE_STR
880 IFNAME_STR
881 )
882{
883 struct interface *ifp;
52dc7ee6 884 struct listnode *i;
718e3744 885
886 if (argc)
887 {
888 ifp = if_lookup_by_name (argv[0]);
508e53e2 889 if (ifp == NULL)
718e3744 890 {
891 vty_out (vty, "No such Interface: %s%s", argv[0],
049207c3 892 VNL);
718e3744 893 return CMD_WARNING;
894 }
895 ospf6_interface_show (vty, ifp);
896 }
897 else
898 {
899 for (i = listhead (iflist); i; nextnode (i))
900 {
508e53e2 901 ifp = (struct interface *) getdata (i);
718e3744 902 ospf6_interface_show (vty, ifp);
903 }
904 }
508e53e2 905
718e3744 906 return CMD_SUCCESS;
907}
908
909ALIAS (show_ipv6_ospf6_interface,
910 show_ipv6_ospf6_interface_cmd,
911 "show ipv6 ospf6 interface",
912 SHOW_STR
913 IP6_STR
914 OSPF6_STR
915 INTERFACE_STR
508e53e2 916 );
917
918DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
919 show_ipv6_ospf6_interface_ifname_prefix_cmd,
920 "show ipv6 ospf6 interface IFNAME prefix",
921 SHOW_STR
922 IP6_STR
923 OSPF6_STR
924 INTERFACE_STR
925 IFNAME_STR
926 "Display connected prefixes to advertise\n"
718e3744 927 )
508e53e2 928{
929 struct interface *ifp;
930 struct ospf6_interface *oi;
931
932 ifp = if_lookup_by_name (argv[0]);
933 if (ifp == NULL)
934 {
049207c3 935 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
508e53e2 936 return CMD_WARNING;
937 }
938
939 oi = ifp->info;
940 if (oi == NULL)
941 {
049207c3 942 vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
508e53e2 943 return CMD_WARNING;
944 }
945
946 argc--;
947 argv++;
948 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
949
950 return CMD_SUCCESS;
951}
952
953ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
954 show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
955 "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
956 SHOW_STR
957 IP6_STR
958 OSPF6_STR
959 INTERFACE_STR
960 IFNAME_STR
961 "Display connected prefixes to advertise\n"
962 OSPF6_ROUTE_ADDRESS_STR
963 OSPF6_ROUTE_PREFIX_STR
964 "Dispaly details of the prefixes\n"
965 );
966
967ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
968 show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
969 "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
970 SHOW_STR
971 IP6_STR
972 OSPF6_STR
973 INTERFACE_STR
974 IFNAME_STR
975 "Display connected prefixes to advertise\n"
976 OSPF6_ROUTE_PREFIX_STR
977 OSPF6_ROUTE_MATCH_STR
978 "Dispaly details of the prefixes\n"
979 );
980
981DEFUN (show_ipv6_ospf6_interface_prefix,
982 show_ipv6_ospf6_interface_prefix_cmd,
983 "show ipv6 ospf6 interface prefix",
984 SHOW_STR
985 IP6_STR
986 OSPF6_STR
987 INTERFACE_STR
988 "Display connected prefixes to advertise\n"
989 )
990{
52dc7ee6 991 struct listnode *i;
508e53e2 992 struct ospf6_interface *oi;
993 struct interface *ifp;
994
995 for (i = listhead (iflist); i; nextnode (i))
996 {
997 ifp = (struct interface *) getdata (i);
998 oi = (struct ospf6_interface *) ifp->info;
999 if (oi == NULL)
1000 continue;
1001
1002 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1003 }
1004
1005 return CMD_SUCCESS;
1006}
1007
1008ALIAS (show_ipv6_ospf6_interface_prefix,
1009 show_ipv6_ospf6_interface_prefix_detail_cmd,
1010 "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
1011 SHOW_STR
1012 IP6_STR
1013 OSPF6_STR
1014 INTERFACE_STR
1015 "Display connected prefixes to advertise\n"
1016 OSPF6_ROUTE_ADDRESS_STR
1017 OSPF6_ROUTE_PREFIX_STR
1018 "Dispaly details of the prefixes\n"
1019 );
1020
1021ALIAS (show_ipv6_ospf6_interface_prefix,
1022 show_ipv6_ospf6_interface_prefix_match_cmd,
1023 "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
1024 SHOW_STR
1025 IP6_STR
1026 OSPF6_STR
1027 INTERFACE_STR
1028 "Display connected prefixes to advertise\n"
1029 OSPF6_ROUTE_PREFIX_STR
1030 OSPF6_ROUTE_MATCH_STR
1031 "Dispaly details of the prefixes\n"
1032 );
1033
718e3744 1034
1035/* interface variable set command */
b596c71e 1036DEFUN (ipv6_ospf6_ifmtu,
1037 ipv6_ospf6_ifmtu_cmd,
1038 "ipv6 ospf6 ifmtu <1-65535>",
1039 IP6_STR
1040 OSPF6_STR
1041 "Interface MTU\n"
1042 "OSPFv3 Interface MTU\n"
1043 )
1044{
1045 struct ospf6_interface *oi;
1046 struct interface *ifp;
0c083ee9 1047 unsigned int ifmtu, iobuflen;
52dc7ee6 1048 struct listnode *node;
b596c71e 1049 struct ospf6_neighbor *on;
1050
1051 ifp = (struct interface *) vty->index;
1052 assert (ifp);
1053
1054 oi = (struct ospf6_interface *) ifp->info;
1055 if (oi == NULL)
1056 oi = ospf6_interface_create (ifp);
1057 assert (oi);
1058
1059 ifmtu = strtol (argv[0], NULL, 10);
1060
1061 if (oi->ifmtu == ifmtu)
1062 return CMD_SUCCESS;
1063
1203e1c0 1064 if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
b596c71e 1065 {
1066 vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
049207c3 1067 ifp->name, ifp->mtu6, VNL);
b596c71e 1068 return CMD_WARNING;
1069 }
1070
1071 if (oi->ifmtu < ifmtu)
1072 {
1073 iobuflen = ospf6_iobuf_size (ifmtu);
1074 if (iobuflen < ifmtu)
1075 {
1076 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
049207c3 1077 ifp->name, iobuflen, VNL);
b596c71e 1078 oi->ifmtu = iobuflen;
1079 }
1080 else
1081 oi->ifmtu = ifmtu;
1082 }
1083 else
1084 oi->ifmtu = ifmtu;
1085
1086 /* re-establish adjacencies */
1087 for (node = listhead (oi->neighbor_list); node; nextnode (node))
1088 {
1089 on = (struct ospf6_neighbor *) getdata (node);
1090 THREAD_OFF (on->inactivity_timer);
1091 thread_execute (master, inactivity_timer, on, 0);
1092 }
1093
1094 return CMD_SUCCESS;
1095}
1096
049207c3 1097DEFUN (no_ipv6_ospf6_ifmtu,
1098 no_ipv6_ospf6_ifmtu_cmd,
1099 "no ipv6 ospf6 ifmtu",
1100 NO_STR
1101 IP6_STR
1102 OSPF6_STR
1103 "Interface MTU\n"
1104 )
1105{
1106 struct ospf6_interface *oi;
1107 struct interface *ifp;
0c083ee9 1108 unsigned int iobuflen;
52dc7ee6 1109 struct listnode *node;
049207c3 1110 struct ospf6_neighbor *on;
1111
1112 ifp = (struct interface *) vty->index;
1113 assert (ifp);
1114
1115 oi = (struct ospf6_interface *) ifp->info;
1116 if (oi == NULL)
1117 oi = ospf6_interface_create (ifp);
1118 assert (oi);
1119
1120 if (oi->ifmtu < ifp->mtu)
1121 {
1122 iobuflen = ospf6_iobuf_size (ifp->mtu);
1123 if (iobuflen < ifp->mtu)
1124 {
1125 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1126 ifp->name, iobuflen, VNL);
1127 oi->ifmtu = iobuflen;
1128 }
1129 else
1130 oi->ifmtu = ifp->mtu;
1131 }
1132 else
1133 oi->ifmtu = ifp->mtu;
1134
1135 /* re-establish adjacencies */
1136 for (node = listhead (oi->neighbor_list); node; nextnode (node))
1137 {
1138 on = (struct ospf6_neighbor *) getdata (node);
1139 THREAD_OFF (on->inactivity_timer);
1140 thread_execute (master, inactivity_timer, on, 0);
1141 }
1142
1143 return CMD_SUCCESS;
1144}
1145
718e3744 1146DEFUN (ipv6_ospf6_cost,
1147 ipv6_ospf6_cost_cmd,
508e53e2 1148 "ipv6 ospf6 cost <1-65535>",
718e3744 1149 IP6_STR
1150 OSPF6_STR
1151 "Interface cost\n"
508e53e2 1152 "Outgoing metric of this interface\n"
718e3744 1153 )
1154{
508e53e2 1155 struct ospf6_interface *oi;
718e3744 1156 struct interface *ifp;
0c083ee9 1157 unsigned long int lcost;
718e3744 1158
508e53e2 1159 ifp = (struct interface *) vty->index;
718e3744 1160 assert (ifp);
1161
508e53e2 1162 oi = (struct ospf6_interface *) ifp->info;
1163 if (oi == NULL)
1164 oi = ospf6_interface_create (ifp);
1165 assert (oi);
718e3744 1166
0c083ee9 1167 lcost = strtol (argv[0], NULL, 10);
718e3744 1168
0c083ee9 1169 if (lcost > UINT32_MAX)
1170 {
1171 vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
1172 return CMD_WARNING;
1173 }
1174
1175 if (oi->cost == lcost)
1176 return CMD_SUCCESS;
1177
1178 oi->cost = lcost;
1179
508e53e2 1180 /* update cost held in route_connected list in ospf6_interface */
1181 ospf6_interface_connected_route_update (oi->interface);
718e3744 1182
508e53e2 1183 /* execute LSA hooks */
1184 if (oi->area)
1185 {
1186 OSPF6_LINK_LSA_SCHEDULE (oi);
1187 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
1188 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1189 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1190 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1191 }
718e3744 1192
1193 return CMD_SUCCESS;
1194}
1195
718e3744 1196DEFUN (ipv6_ospf6_hellointerval,
1197 ipv6_ospf6_hellointerval_cmd,
508e53e2 1198 "ipv6 ospf6 hello-interval <1-65535>",
718e3744 1199 IP6_STR
1200 OSPF6_STR
508e53e2 1201 "Interval time of Hello packets\n"
718e3744 1202 SECONDS_STR
1203 )
1204{
508e53e2 1205 struct ospf6_interface *oi;
718e3744 1206 struct interface *ifp;
1207
1208 ifp = (struct interface *) vty->index;
1209 assert (ifp);
718e3744 1210
508e53e2 1211 oi = (struct ospf6_interface *) ifp->info;
1212 if (oi == NULL)
1213 oi = ospf6_interface_create (ifp);
1214 assert (oi);
1215
1216 oi->hello_interval = strtol (argv[0], NULL, 10);
718e3744 1217 return CMD_SUCCESS;
1218}
1219
1220/* interface variable set command */
1221DEFUN (ipv6_ospf6_deadinterval,
1222 ipv6_ospf6_deadinterval_cmd,
508e53e2 1223 "ipv6 ospf6 dead-interval <1-65535>",
718e3744 1224 IP6_STR
1225 OSPF6_STR
508e53e2 1226 "Interval time after which a neighbor is declared down\n"
718e3744 1227 SECONDS_STR
1228 )
1229{
508e53e2 1230 struct ospf6_interface *oi;
718e3744 1231 struct interface *ifp;
1232
1233 ifp = (struct interface *) vty->index;
1234 assert (ifp);
718e3744 1235
508e53e2 1236 oi = (struct ospf6_interface *) ifp->info;
1237 if (oi == NULL)
1238 oi = ospf6_interface_create (ifp);
1239 assert (oi);
1240
1241 oi->dead_interval = strtol (argv[0], NULL, 10);
718e3744 1242 return CMD_SUCCESS;
1243}
1244
1245/* interface variable set command */
1246DEFUN (ipv6_ospf6_transmitdelay,
1247 ipv6_ospf6_transmitdelay_cmd,
508e53e2 1248 "ipv6 ospf6 transmit-delay <1-3600>",
718e3744 1249 IP6_STR
1250 OSPF6_STR
508e53e2 1251 "Transmit delay of this interface\n"
718e3744 1252 SECONDS_STR
1253 )
1254{
508e53e2 1255 struct ospf6_interface *oi;
718e3744 1256 struct interface *ifp;
1257
1258 ifp = (struct interface *) vty->index;
1259 assert (ifp);
718e3744 1260
508e53e2 1261 oi = (struct ospf6_interface *) ifp->info;
1262 if (oi == NULL)
1263 oi = ospf6_interface_create (ifp);
1264 assert (oi);
1265
1266 oi->transdelay = strtol (argv[0], NULL, 10);
718e3744 1267 return CMD_SUCCESS;
1268}
1269
1270/* interface variable set command */
1271DEFUN (ipv6_ospf6_retransmitinterval,
1272 ipv6_ospf6_retransmitinterval_cmd,
508e53e2 1273 "ipv6 ospf6 retransmit-interval <1-65535>",
718e3744 1274 IP6_STR
1275 OSPF6_STR
1276 "Time between retransmitting lost link state advertisements\n"
1277 SECONDS_STR
1278 )
1279{
508e53e2 1280 struct ospf6_interface *oi;
718e3744 1281 struct interface *ifp;
1282
1283 ifp = (struct interface *) vty->index;
1284 assert (ifp);
718e3744 1285
508e53e2 1286 oi = (struct ospf6_interface *) ifp->info;
1287 if (oi == NULL)
1288 oi = ospf6_interface_create (ifp);
1289 assert (oi);
1290
1291 oi->rxmt_interval = strtol (argv[0], NULL, 10);
718e3744 1292 return CMD_SUCCESS;
1293}
1294
1295/* interface variable set command */
1296DEFUN (ipv6_ospf6_priority,
1297 ipv6_ospf6_priority_cmd,
508e53e2 1298 "ipv6 ospf6 priority <0-255>",
718e3744 1299 IP6_STR
1300 OSPF6_STR
1301 "Router priority\n"
508e53e2 1302 "Priority value\n"
718e3744 1303 )
1304{
508e53e2 1305 struct ospf6_interface *oi;
718e3744 1306 struct interface *ifp;
1307
1308 ifp = (struct interface *) vty->index;
1309 assert (ifp);
718e3744 1310
508e53e2 1311 oi = (struct ospf6_interface *) ifp->info;
1312 if (oi == NULL)
1313 oi = ospf6_interface_create (ifp);
1314 assert (oi);
1315
1316 oi->priority = strtol (argv[0], NULL, 10);
718e3744 1317
508e53e2 1318 if (oi->area)
1319 ospf6_interface_state_change (dr_election (oi), oi);
718e3744 1320
1321 return CMD_SUCCESS;
1322}
1323
1324DEFUN (ipv6_ospf6_instance,
1325 ipv6_ospf6_instance_cmd,
508e53e2 1326 "ipv6 ospf6 instance-id <0-255>",
718e3744 1327 IP6_STR
1328 OSPF6_STR
508e53e2 1329 "Instance ID for this interface\n"
1330 "Instance ID value\n"
718e3744 1331 )
1332{
508e53e2 1333 struct ospf6_interface *oi;
718e3744 1334 struct interface *ifp;
1335
1336 ifp = (struct interface *)vty->index;
1337 assert (ifp);
1338
508e53e2 1339 oi = (struct ospf6_interface *)ifp->info;
1340 if (oi == NULL)
1341 oi = ospf6_interface_create (ifp);
1342 assert (oi);
718e3744 1343
508e53e2 1344 oi->instance_id = strtol (argv[0], NULL, 10);
718e3744 1345 return CMD_SUCCESS;
1346}
1347
1348DEFUN (ipv6_ospf6_passive,
1349 ipv6_ospf6_passive_cmd,
1350 "ipv6 ospf6 passive",
1351 IP6_STR
1352 OSPF6_STR
508e53e2 1353 "passive interface, No adjacency will be formed on this interface\n"
718e3744 1354 )
1355{
508e53e2 1356 struct ospf6_interface *oi;
718e3744 1357 struct interface *ifp;
52dc7ee6 1358 struct listnode *node;
508e53e2 1359 struct ospf6_neighbor *on;
718e3744 1360
1361 ifp = (struct interface *) vty->index;
1362 assert (ifp);
718e3744 1363
508e53e2 1364 oi = (struct ospf6_interface *) ifp->info;
1365 if (oi == NULL)
1366 oi = ospf6_interface_create (ifp);
1367 assert (oi);
718e3744 1368
508e53e2 1369 SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1370 THREAD_OFF (oi->thread_send_hello);
1371
1372 for (node = listhead (oi->neighbor_list); node; nextnode (node))
718e3744 1373 {
508e53e2 1374 on = (struct ospf6_neighbor *) getdata (node);
1375 THREAD_OFF (on->inactivity_timer);
1376 thread_execute (master, inactivity_timer, on, 0);
718e3744 1377 }
1378
1379 return CMD_SUCCESS;
1380}
1381
1382DEFUN (no_ipv6_ospf6_passive,
1383 no_ipv6_ospf6_passive_cmd,
1384 "no ipv6 ospf6 passive",
1385 NO_STR
1386 IP6_STR
1387 OSPF6_STR
1388 "passive interface: No Adjacency will be formed on this I/F\n"
1389 )
1390{
508e53e2 1391 struct ospf6_interface *oi;
718e3744 1392 struct interface *ifp;
1393
1394 ifp = (struct interface *) vty->index;
1395 assert (ifp);
718e3744 1396
508e53e2 1397 oi = (struct ospf6_interface *) ifp->info;
1398 if (oi == NULL)
1399 oi = ospf6_interface_create (ifp);
1400 assert (oi);
718e3744 1401
508e53e2 1402 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1403 THREAD_OFF (oi->thread_send_hello);
1404 oi->thread_send_hello =
1405 thread_add_event (master, ospf6_hello_send, oi, 0);
718e3744 1406
1407 return CMD_SUCCESS;
1408}
1409
1410DEFUN (ipv6_ospf6_advertise_prefix_list,
1411 ipv6_ospf6_advertise_prefix_list_cmd,
1412 "ipv6 ospf6 advertise prefix-list WORD",
1413 IP6_STR
1414 OSPF6_STR
1415 "Advertising options\n"
1416 "Filter prefix using prefix-list\n"
1417 "Prefix list name\n"
1418 )
1419{
508e53e2 1420 struct ospf6_interface *oi;
718e3744 1421 struct interface *ifp;
1422
1423 ifp = (struct interface *) vty->index;
1424 assert (ifp);
718e3744 1425
508e53e2 1426 oi = (struct ospf6_interface *) ifp->info;
1427 if (oi == NULL)
1428 oi = ospf6_interface_create (ifp);
1429 assert (oi);
718e3744 1430
508e53e2 1431 if (oi->plist_name)
1432 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1433 oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
718e3744 1434
508e53e2 1435 ospf6_interface_connected_route_update (oi->interface);
1436 OSPF6_LINK_LSA_SCHEDULE (oi);
1437 if (oi->state == OSPF6_INTERFACE_DR)
1438 {
1439 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1440 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1441 }
1442 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
718e3744 1443
1444 return CMD_SUCCESS;
1445}
1446
1447DEFUN (no_ipv6_ospf6_advertise_prefix_list,
1448 no_ipv6_ospf6_advertise_prefix_list_cmd,
1449 "no ipv6 ospf6 advertise prefix-list",
1450 NO_STR
1451 IP6_STR
1452 OSPF6_STR
1453 "Advertising options\n"
1454 "Filter prefix using prefix-list\n"
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 if (oi->plist_name)
718e3744 1469 {
508e53e2 1470 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1471 oi->plist_name = NULL;
718e3744 1472 }
1473
508e53e2 1474 ospf6_interface_connected_route_update (oi->interface);
1475 OSPF6_LINK_LSA_SCHEDULE (oi);
1476 if (oi->state == OSPF6_INTERFACE_DR)
1477 {
1478 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1479 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1480 }
1481 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
718e3744 1482
1483 return CMD_SUCCESS;
1484}
1485
1486int
508e53e2 1487config_write_ospf6_interface (struct vty *vty)
718e3744 1488{
52dc7ee6 1489 struct listnode *i;
508e53e2 1490 struct ospf6_interface *oi;
718e3744 1491 struct interface *ifp;
1492
1493 for (i = listhead (iflist); i; nextnode (i))
1494 {
1495 ifp = (struct interface *) getdata (i);
508e53e2 1496 oi = (struct ospf6_interface *) ifp->info;
1497 if (oi == NULL)
718e3744 1498 continue;
1499
1500 vty_out (vty, "interface %s%s",
049207c3 1501 oi->interface->name, VNL);
508e53e2 1502
1503 if (ifp->desc)
049207c3 1504 vty_out (vty, " description %s%s", ifp->desc, VNL);
508e53e2 1505
1203e1c0 1506 if (ifp->mtu6 != oi->ifmtu)
049207c3 1507 vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
718e3744 1508 vty_out (vty, " ipv6 ospf6 cost %d%s",
049207c3 1509 oi->cost, VNL);
718e3744 1510 vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
049207c3 1511 oi->hello_interval, VNL);
718e3744 1512 vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
049207c3 1513 oi->dead_interval, VNL);
718e3744 1514 vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
049207c3 1515 oi->rxmt_interval, VNL);
718e3744 1516 vty_out (vty, " ipv6 ospf6 priority %d%s",
049207c3 1517 oi->priority, VNL);
718e3744 1518 vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
049207c3 1519 oi->transdelay, VNL);
718e3744 1520 vty_out (vty, " ipv6 ospf6 instance-id %d%s",
049207c3 1521 oi->instance_id, VNL);
718e3744 1522
508e53e2 1523 if (oi->plist_name)
718e3744 1524 vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
049207c3 1525 oi->plist_name, VNL);
718e3744 1526
508e53e2 1527 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
049207c3 1528 vty_out (vty, " ipv6 ospf6 passive%s", VNL);
718e3744 1529
049207c3 1530 vty_out (vty, "!%s", VNL);
718e3744 1531 }
1532 return 0;
1533}
1534
1535struct cmd_node interface_node =
1536{
1537 INTERFACE_NODE,
1538 "%s(config-if)# ",
69b4a810 1539 1 /* VTYSH */
718e3744 1540};
1541
1542void
1543ospf6_interface_init ()
1544{
1545 /* Install interface node. */
508e53e2 1546 install_node (&interface_node, config_write_ospf6_interface);
718e3744 1547
1548 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
508e53e2 1549 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1550 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1551 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
718e3744 1552 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
508e53e2 1553 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1554 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1555 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
718e3744 1556 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
508e53e2 1557 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1558 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1559 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
718e3744 1560 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
508e53e2 1561 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1562 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1563 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
718e3744 1564
508e53e2 1565 install_element (CONFIG_NODE, &interface_cmd);
718e3744 1566 install_default (INTERFACE_NODE);
1567 install_element (INTERFACE_NODE, &interface_desc_cmd);
1568 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1569 install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
b596c71e 1570 install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
049207c3 1571 install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
718e3744 1572 install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
1573 install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
1574 install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
1575 install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
1576 install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
1577 install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
508e53e2 1578
718e3744 1579 install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
1580 install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
508e53e2 1581
1582 install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
1583 install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
1584}
1585
1586DEFUN (debug_ospf6_interface,
1587 debug_ospf6_interface_cmd,
1588 "debug ospf6 interface",
1589 DEBUG_STR
1590 OSPF6_STR
1591 "Debug OSPFv3 Interface\n"
1592 )
1593{
1594 OSPF6_DEBUG_INTERFACE_ON ();
1595 return CMD_SUCCESS;
1596}
1597
1598DEFUN (no_debug_ospf6_interface,
1599 no_debug_ospf6_interface_cmd,
1600 "no debug ospf6 interface",
1601 NO_STR
1602 DEBUG_STR
1603 OSPF6_STR
1604 "Debug OSPFv3 Interface\n"
1605 )
1606{
3b68735f 1607 OSPF6_DEBUG_INTERFACE_OFF ();
508e53e2 1608 return CMD_SUCCESS;
1609}
1610
1611int
1612config_write_ospf6_debug_interface (struct vty *vty)
1613{
1614 if (IS_OSPF6_DEBUG_INTERFACE)
049207c3 1615 vty_out (vty, "debug ospf6 interface%s", VNL);
508e53e2 1616 return 0;
1617}
1618
1619void
1620install_element_ospf6_debug_interface ()
1621{
1622 install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
1623 install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
1624 install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
1625 install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
718e3744 1626}
1627
1628