Deleted Added
full compact
rtadvd.c (112676) rtadvd.c (118660)
1/* $FreeBSD: head/usr.sbin/rtadvd/rtadvd.c 112676 2003-03-26 17:28:47Z ume $ */
1/* $FreeBSD: head/usr.sbin/rtadvd/rtadvd.c 118660 2003-08-08 16:38:23Z ume $ */
2/* $KAME: rtadvd.c,v 1.50 2001/02/04 06:15:15 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

--- 232 unchanged lines hidden (view full) ---

242 if (!fflag)
243 daemon(1, 0);
244
245 /* record the current PID */
246 pid = getpid();
247 if ((pidfp = fopen(pidfilename, "w")) == NULL) {
248 syslog(LOG_ERR,
249 "<%s> failed to open a log file(%s), run anyway.",
2/* $KAME: rtadvd.c,v 1.50 2001/02/04 06:15:15 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

--- 232 unchanged lines hidden (view full) ---

242 if (!fflag)
243 daemon(1, 0);
244
245 /* record the current PID */
246 pid = getpid();
247 if ((pidfp = fopen(pidfilename, "w")) == NULL) {
248 syslog(LOG_ERR,
249 "<%s> failed to open a log file(%s), run anyway.",
250 __FUNCTION__, pidfilename);
250 __func__, pidfilename);
251 } else {
252 fprintf(pidfp, "%d\n", pid);
253 fclose(pidfp);
254 }
255
256 FD_ZERO(&fdset);
257 FD_SET(sock, &fdset);
258 maxfd = sock;

--- 22 unchanged lines hidden (view full) ---

281 }
282
283 /* timer expiration check and reset the timer */
284 timeout = rtadvd_check_timer();
285
286 if (timeout != NULL) {
287 syslog(LOG_DEBUG,
288 "<%s> set timer to %ld:%ld. waiting for "
251 } else {
252 fprintf(pidfp, "%d\n", pid);
253 fclose(pidfp);
254 }
255
256 FD_ZERO(&fdset);
257 FD_SET(sock, &fdset);
258 maxfd = sock;

--- 22 unchanged lines hidden (view full) ---

281 }
282
283 /* timer expiration check and reset the timer */
284 timeout = rtadvd_check_timer();
285
286 if (timeout != NULL) {
287 syslog(LOG_DEBUG,
288 "<%s> set timer to %ld:%ld. waiting for "
289 "inputs or timeout", __FUNCTION__,
289 "inputs or timeout", __func__,
290 (long int)timeout->tv_sec,
291 (long int)timeout->tv_usec);
292 } else {
293 syslog(LOG_DEBUG,
294 "<%s> there's no timer. waiting for inputs",
290 (long int)timeout->tv_sec,
291 (long int)timeout->tv_usec);
292 } else {
293 syslog(LOG_DEBUG,
294 "<%s> there's no timer. waiting for inputs",
295 __FUNCTION__);
295 __func__);
296 }
297
298 if ((i = select(maxfd + 1, &select_fd,
299 NULL, NULL, timeout)) < 0) {
300 /* EINTR would occur upon SIGUSR1 for status dump */
301 if (errno != EINTR)
302 syslog(LOG_ERR, "<%s> select: %s",
296 }
297
298 if ((i = select(maxfd + 1, &select_fd,
299 NULL, NULL, timeout)) < 0) {
300 /* EINTR would occur upon SIGUSR1 for status dump */
301 if (errno != EINTR)
302 syslog(LOG_ERR, "<%s> select: %s",
303 __FUNCTION__, strerror(errno));
303 __func__, strerror(errno));
304 continue;
305 }
306 if (i == 0) /* timeout */
307 continue;
308 if (rtsock != -1 && FD_ISSET(rtsock, &select_fd))
309 rtmsg_input();
310 if (FD_ISSET(sock, &select_fd))
311 rtadvd_input();

--- 18 unchanged lines hidden (view full) ---

330die()
331{
332 struct rainfo *ra;
333 int i;
334 const int retrans = MAX_FINAL_RTR_ADVERTISEMENTS;
335
336 if (dflag > 1) {
337 syslog(LOG_DEBUG, "<%s> cease to be an advertising router\n",
304 continue;
305 }
306 if (i == 0) /* timeout */
307 continue;
308 if (rtsock != -1 && FD_ISSET(rtsock, &select_fd))
309 rtmsg_input();
310 if (FD_ISSET(sock, &select_fd))
311 rtadvd_input();

--- 18 unchanged lines hidden (view full) ---

330die()
331{
332 struct rainfo *ra;
333 int i;
334 const int retrans = MAX_FINAL_RTR_ADVERTISEMENTS;
335
336 if (dflag > 1) {
337 syslog(LOG_DEBUG, "<%s> cease to be an advertising router\n",
338 __FUNCTION__);
338 __func__);
339 }
340
341 for (ra = ralist; ra; ra = ra->next) {
342 ra->lifetime = 0;
343 make_packet(ra);
344 }
345 for (i = 0; i < retrans; i++) {
346 for (ra = ralist; ra; ra = ra->next)

--- 14 unchanged lines hidden (view full) ---

361 struct prefix *prefix;
362 struct rainfo *rai;
363 struct in6_addr *addr;
364 char addrbuf[INET6_ADDRSTRLEN];
365
366 n = read(rtsock, msg, sizeof(msg));
367 if (dflag > 1) {
368 syslog(LOG_DEBUG, "<%s> received a routing message "
339 }
340
341 for (ra = ralist; ra; ra = ra->next) {
342 ra->lifetime = 0;
343 make_packet(ra);
344 }
345 for (i = 0; i < retrans; i++) {
346 for (ra = ralist; ra; ra = ra->next)

--- 14 unchanged lines hidden (view full) ---

361 struct prefix *prefix;
362 struct rainfo *rai;
363 struct in6_addr *addr;
364 char addrbuf[INET6_ADDRSTRLEN];
365
366 n = read(rtsock, msg, sizeof(msg));
367 if (dflag > 1) {
368 syslog(LOG_DEBUG, "<%s> received a routing message "
369 "(type = %d, len = %d)", __FUNCTION__, rtmsg_type(msg), n);
369 "(type = %d, len = %d)", __func__, rtmsg_type(msg), n);
370 }
371 if (n > rtmsg_len(msg)) {
372 /*
373 * This usually won't happen for messages received on
374 * a routing socket.
375 */
376 if (dflag > 1)
377 syslog(LOG_DEBUG,
378 "<%s> received data length is larger than "
379 "1st routing message len. multiple messages? "
380 "read %d bytes, but 1st msg len = %d",
370 }
371 if (n > rtmsg_len(msg)) {
372 /*
373 * This usually won't happen for messages received on
374 * a routing socket.
375 */
376 if (dflag > 1)
377 syslog(LOG_DEBUG,
378 "<%s> received data length is larger than "
379 "1st routing message len. multiple messages? "
380 "read %d bytes, but 1st msg len = %d",
381 __FUNCTION__, n, rtmsg_len(msg));
381 __func__, n, rtmsg_len(msg));
382#if 0
383 /* adjust length */
384 n = rtmsg_len(msg);
385#endif
386 }
387
388 lim = msg + n;
389 for (next = msg; next < lim; next += len) {

--- 20 unchanged lines hidden (view full) ---

410 case RTM_IFINFO:
411 ifindex = get_ifm_ifindex(next);
412 break;
413 default:
414 /* should not reach here */
415 if (dflag > 1) {
416 syslog(LOG_DEBUG,
417 "<%s:%d> unknown rtmsg %d on %s",
382#if 0
383 /* adjust length */
384 n = rtmsg_len(msg);
385#endif
386 }
387
388 lim = msg + n;
389 for (next = msg; next < lim; next += len) {

--- 20 unchanged lines hidden (view full) ---

410 case RTM_IFINFO:
411 ifindex = get_ifm_ifindex(next);
412 break;
413 default:
414 /* should not reach here */
415 if (dflag > 1) {
416 syslog(LOG_DEBUG,
417 "<%s:%d> unknown rtmsg %d on %s",
418 __FUNCTION__, __LINE__, type,
418 __func__, __LINE__, type,
419 if_indextoname(ifindex, ifname));
420 }
421 continue;
422 }
423
424 if ((rai = if_indextorainfo(ifindex)) == NULL) {
425 if (dflag > 1) {
426 syslog(LOG_DEBUG,
427 "<%s> route changed on "
428 "non advertising interface(%s)",
419 if_indextoname(ifindex, ifname));
420 }
421 continue;
422 }
423
424 if ((rai = if_indextorainfo(ifindex)) == NULL) {
425 if (dflag > 1) {
426 syslog(LOG_DEBUG,
427 "<%s> route changed on "
428 "non advertising interface(%s)",
429 __FUNCTION__,
429 __func__,
430 if_indextoname(ifindex, ifname));
431 }
432 continue;
433 }
434 oldifflags = iflist[ifindex]->ifm_flags;
435
436 switch (type) {
437 case RTM_ADD:

--- 6 unchanged lines hidden (view full) ---

444
445 addr = get_addr(msg);
446 plen = get_prefixlen(msg);
447 /* sanity check for plen */
448 /* as RFC2373, prefixlen is at least 4 */
449 if (plen < 4 || plen > 127) {
450 syslog(LOG_INFO, "<%s> new interface route's"
451 "plen %d is invalid for a prefix",
430 if_indextoname(ifindex, ifname));
431 }
432 continue;
433 }
434 oldifflags = iflist[ifindex]->ifm_flags;
435
436 switch (type) {
437 case RTM_ADD:

--- 6 unchanged lines hidden (view full) ---

444
445 addr = get_addr(msg);
446 plen = get_prefixlen(msg);
447 /* sanity check for plen */
448 /* as RFC2373, prefixlen is at least 4 */
449 if (plen < 4 || plen > 127) {
450 syslog(LOG_INFO, "<%s> new interface route's"
451 "plen %d is invalid for a prefix",
452 __FUNCTION__, plen);
452 __func__, plen);
453 break;
454 }
455 prefix = find_prefix(rai, addr, plen);
456 if (prefix) {
457 if (prefix->timer) {
458 /*
459 * If the prefix has been invalidated,
460 * make it available again.
461 */
462 update_prefix(prefix);
463 } else if (dflag > 1) {
464 syslog(LOG_DEBUG,
465 "<%s> new prefix(%s/%d) "
466 "added on %s, "
467 "but it was already in list",
453 break;
454 }
455 prefix = find_prefix(rai, addr, plen);
456 if (prefix) {
457 if (prefix->timer) {
458 /*
459 * If the prefix has been invalidated,
460 * make it available again.
461 */
462 update_prefix(prefix);
463 } else if (dflag > 1) {
464 syslog(LOG_DEBUG,
465 "<%s> new prefix(%s/%d) "
466 "added on %s, "
467 "but it was already in list",
468 __FUNCTION__,
468 __func__,
469 inet_ntop(AF_INET6, addr,
470 (char *)addrbuf, INET6_ADDRSTRLEN),
471 plen, rai->ifname);
472 }
473 break;
474 }
475 make_prefix(rai, ifindex, addr, plen);
476 break;

--- 8 unchanged lines hidden (view full) ---

485 addr = get_addr(msg);
486 plen = get_prefixlen(msg);
487 /* sanity check for plen */
488 /* as RFC2373, prefixlen is at least 4 */
489 if (plen < 4 || plen > 127) {
490 syslog(LOG_INFO,
491 "<%s> deleted interface route's "
492 "plen %d is invalid for a prefix",
469 inet_ntop(AF_INET6, addr,
470 (char *)addrbuf, INET6_ADDRSTRLEN),
471 plen, rai->ifname);
472 }
473 break;
474 }
475 make_prefix(rai, ifindex, addr, plen);
476 break;

--- 8 unchanged lines hidden (view full) ---

485 addr = get_addr(msg);
486 plen = get_prefixlen(msg);
487 /* sanity check for plen */
488 /* as RFC2373, prefixlen is at least 4 */
489 if (plen < 4 || plen > 127) {
490 syslog(LOG_INFO,
491 "<%s> deleted interface route's "
492 "plen %d is invalid for a prefix",
493 __FUNCTION__, plen);
493 __func__, plen);
494 break;
495 }
496 prefix = find_prefix(rai, addr, plen);
497 if (prefix == NULL) {
498 if (dflag > 1) {
499 syslog(LOG_DEBUG,
500 "<%s> prefix(%s/%d) was "
501 "deleted on %s, "
502 "but it was not in list",
494 break;
495 }
496 prefix = find_prefix(rai, addr, plen);
497 if (prefix == NULL) {
498 if (dflag > 1) {
499 syslog(LOG_DEBUG,
500 "<%s> prefix(%s/%d) was "
501 "deleted on %s, "
502 "but it was not in list",
503 __FUNCTION__,
503 __func__,
504 inet_ntop(AF_INET6, addr,
505 (char *)addrbuf, INET6_ADDRSTRLEN),
506 plen, rai->ifname);
507 }
508 break;
509 }
510 invalidate_prefix(prefix);
511 break;

--- 6 unchanged lines hidden (view full) ---

518 case RTM_IFINFO:
519 iflist[ifindex]->ifm_flags = get_ifm_flags(next);
520 break;
521 default:
522 /* should not reach here */
523 if (dflag > 1) {
524 syslog(LOG_DEBUG,
525 "<%s:%d> unknown rtmsg %d on %s",
504 inet_ntop(AF_INET6, addr,
505 (char *)addrbuf, INET6_ADDRSTRLEN),
506 plen, rai->ifname);
507 }
508 break;
509 }
510 invalidate_prefix(prefix);
511 break;

--- 6 unchanged lines hidden (view full) ---

518 case RTM_IFINFO:
519 iflist[ifindex]->ifm_flags = get_ifm_flags(next);
520 break;
521 default:
522 /* should not reach here */
523 if (dflag > 1) {
524 syslog(LOG_DEBUG,
525 "<%s:%d> unknown rtmsg %d on %s",
526 __FUNCTION__, __LINE__, type,
526 __func__, __LINE__, type,
527 if_indextoname(ifindex, ifname));
528 }
529 return;
530 }
531
532 /* check if an interface flag is changed */
533 if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */
534 (iflist[ifindex]->ifm_flags & IFF_UP) == 0) {
535 syslog(LOG_INFO,
536 "<%s> interface %s becomes down. stop timer.",
527 if_indextoname(ifindex, ifname));
528 }
529 return;
530 }
531
532 /* check if an interface flag is changed */
533 if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */
534 (iflist[ifindex]->ifm_flags & IFF_UP) == 0) {
535 syslog(LOG_INFO,
536 "<%s> interface %s becomes down. stop timer.",
537 __FUNCTION__, rai->ifname);
537 __func__, rai->ifname);
538 rtadvd_remove_timer(&rai->timer);
539 } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
540 (iflist[ifindex]->ifm_flags & IFF_UP) != 0) {
541 syslog(LOG_INFO,
542 "<%s> interface %s becomes up. restart timer.",
538 rtadvd_remove_timer(&rai->timer);
539 } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
540 (iflist[ifindex]->ifm_flags & IFF_UP) != 0) {
541 syslog(LOG_INFO,
542 "<%s> interface %s becomes up. restart timer.",
543 __FUNCTION__, rai->ifname);
543 __func__, rai->ifname);
544
545 rai->initcounter = 0; /* reset the counter */
546 rai->waiting = 0; /* XXX */
547 rai->timer = rtadvd_add_timer(ra_timeout,
548 ra_timer_update, rai, rai);
549 ra_timer_update((void *)rai, &rai->timer->tm);
550 rtadvd_set_timer(&rai->timer->tm, rai->timer);
551 }

--- 40 unchanged lines hidden (view full) ---

592 if (cm->cmsg_level == IPPROTO_IPV6 &&
593 cm->cmsg_type == IPV6_HOPLIMIT &&
594 cm->cmsg_len == CMSG_LEN(sizeof(int)))
595 hlimp = (int *)CMSG_DATA(cm);
596 }
597 if (ifindex == 0) {
598 syslog(LOG_ERR,
599 "<%s> failed to get receiving interface",
544
545 rai->initcounter = 0; /* reset the counter */
546 rai->waiting = 0; /* XXX */
547 rai->timer = rtadvd_add_timer(ra_timeout,
548 ra_timer_update, rai, rai);
549 ra_timer_update((void *)rai, &rai->timer->tm);
550 rtadvd_set_timer(&rai->timer->tm, rai->timer);
551 }

--- 40 unchanged lines hidden (view full) ---

592 if (cm->cmsg_level == IPPROTO_IPV6 &&
593 cm->cmsg_type == IPV6_HOPLIMIT &&
594 cm->cmsg_len == CMSG_LEN(sizeof(int)))
595 hlimp = (int *)CMSG_DATA(cm);
596 }
597 if (ifindex == 0) {
598 syslog(LOG_ERR,
599 "<%s> failed to get receiving interface",
600 __FUNCTION__);
600 __func__);
601 return;
602 }
603 if (hlimp == NULL) {
604 syslog(LOG_ERR,
605 "<%s> failed to get receiving hop limit",
601 return;
602 }
603 if (hlimp == NULL) {
604 syslog(LOG_ERR,
605 "<%s> failed to get receiving hop limit",
606 __FUNCTION__);
606 __func__);
607 return;
608 }
609
610 /*
611 * If we happen to receive data on an interface which is now down,
612 * just discard the data.
613 */
614 if ((iflist[pi->ipi6_ifindex]->ifm_flags & IFF_UP) == 0) {
615 syslog(LOG_INFO,
616 "<%s> received data on a disabled interface (%s)",
607 return;
608 }
609
610 /*
611 * If we happen to receive data on an interface which is now down,
612 * just discard the data.
613 */
614 if ((iflist[pi->ipi6_ifindex]->ifm_flags & IFF_UP) == 0) {
615 syslog(LOG_INFO,
616 "<%s> received data on a disabled interface (%s)",
617 __FUNCTION__,
617 __func__,
618 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
619 return;
620 }
621
622#ifdef OLDRAWSOCKET
623 if (i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
624 syslog(LOG_ERR,
625 "<%s> packet size(%d) is too short",
618 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
619 return;
620 }
621
622#ifdef OLDRAWSOCKET
623 if (i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
624 syslog(LOG_ERR,
625 "<%s> packet size(%d) is too short",
626 __FUNCTION__, i);
626 __func__, i);
627 return;
628 }
629
630 ip = (struct ip6_hdr *)rcvmhdr.msg_iov[0].iov_base;
631 icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
632#else
633 if (i < sizeof(struct icmp6_hdr)) {
634 syslog(LOG_ERR,
635 "<%s> packet size(%d) is too short",
627 return;
628 }
629
630 ip = (struct ip6_hdr *)rcvmhdr.msg_iov[0].iov_base;
631 icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
632#else
633 if (i < sizeof(struct icmp6_hdr)) {
634 syslog(LOG_ERR,
635 "<%s> packet size(%d) is too short",
636 __FUNCTION__, i);
636 __func__, i);
637 return;
638 }
639
640 icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base;
641#endif
642
643 switch (icp->icmp6_type) {
644 case ND_ROUTER_SOLICIT:
645 /*
646 * Message verification - RFC-2461 6.1.1
647 * XXX: these checks must be done in the kernel as well,
648 * but we can't completely rely on them.
649 */
650 if (*hlimp != 255) {
651 syslog(LOG_NOTICE,
652 "<%s> RS with invalid hop limit(%d) "
653 "received from %s on %s",
637 return;
638 }
639
640 icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base;
641#endif
642
643 switch (icp->icmp6_type) {
644 case ND_ROUTER_SOLICIT:
645 /*
646 * Message verification - RFC-2461 6.1.1
647 * XXX: these checks must be done in the kernel as well,
648 * but we can't completely rely on them.
649 */
650 if (*hlimp != 255) {
651 syslog(LOG_NOTICE,
652 "<%s> RS with invalid hop limit(%d) "
653 "received from %s on %s",
654 __FUNCTION__, *hlimp,
654 __func__, *hlimp,
655 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
656 INET6_ADDRSTRLEN),
657 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
658 return;
659 }
660 if (icp->icmp6_code) {
661 syslog(LOG_NOTICE,
662 "<%s> RS with invalid ICMP6 code(%d) "
663 "received from %s on %s",
655 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
656 INET6_ADDRSTRLEN),
657 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
658 return;
659 }
660 if (icp->icmp6_code) {
661 syslog(LOG_NOTICE,
662 "<%s> RS with invalid ICMP6 code(%d) "
663 "received from %s on %s",
664 __FUNCTION__, icp->icmp6_code,
664 __func__, icp->icmp6_code,
665 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
666 INET6_ADDRSTRLEN),
667 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
668 return;
669 }
670 if (i < sizeof(struct nd_router_solicit)) {
671 syslog(LOG_NOTICE,
672 "<%s> RS from %s on %s does not have enough "
673 "length (len = %d)",
665 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
666 INET6_ADDRSTRLEN),
667 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
668 return;
669 }
670 if (i < sizeof(struct nd_router_solicit)) {
671 syslog(LOG_NOTICE,
672 "<%s> RS from %s on %s does not have enough "
673 "length (len = %d)",
674 __FUNCTION__,
674 __func__,
675 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
676 INET6_ADDRSTRLEN),
677 if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
678 return;
679 }
680 rs_input(i, (struct nd_router_solicit *)icp, pi, &from);
681 break;
682 case ND_ROUTER_ADVERT:
683 /*
684 * Message verification - RFC-2461 6.1.2
685 * XXX: there's a same dilemma as above...
686 */
687 if (*hlimp != 255) {
688 syslog(LOG_NOTICE,
689 "<%s> RA with invalid hop limit(%d) "
690 "received from %s on %s",
675 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
676 INET6_ADDRSTRLEN),
677 if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
678 return;
679 }
680 rs_input(i, (struct nd_router_solicit *)icp, pi, &from);
681 break;
682 case ND_ROUTER_ADVERT:
683 /*
684 * Message verification - RFC-2461 6.1.2
685 * XXX: there's a same dilemma as above...
686 */
687 if (*hlimp != 255) {
688 syslog(LOG_NOTICE,
689 "<%s> RA with invalid hop limit(%d) "
690 "received from %s on %s",
691 __FUNCTION__, *hlimp,
691 __func__, *hlimp,
692 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
693 INET6_ADDRSTRLEN),
694 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
695 return;
696 }
697 if (icp->icmp6_code) {
698 syslog(LOG_NOTICE,
699 "<%s> RA with invalid ICMP6 code(%d) "
700 "received from %s on %s",
692 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
693 INET6_ADDRSTRLEN),
694 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
695 return;
696 }
697 if (icp->icmp6_code) {
698 syslog(LOG_NOTICE,
699 "<%s> RA with invalid ICMP6 code(%d) "
700 "received from %s on %s",
701 __FUNCTION__, icp->icmp6_code,
701 __func__, icp->icmp6_code,
702 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
703 INET6_ADDRSTRLEN),
704 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
705 return;
706 }
707 if (i < sizeof(struct nd_router_advert)) {
708 syslog(LOG_NOTICE,
709 "<%s> RA from %s on %s does not have enough "
710 "length (len = %d)",
702 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
703 INET6_ADDRSTRLEN),
704 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
705 return;
706 }
707 if (i < sizeof(struct nd_router_advert)) {
708 syslog(LOG_NOTICE,
709 "<%s> RA from %s on %s does not have enough "
710 "length (len = %d)",
711 __FUNCTION__,
711 __func__,
712 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
713 INET6_ADDRSTRLEN),
714 if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
715 return;
716 }
717 ra_input(i, (struct nd_router_advert *)icp, pi, &from);
718 break;
719 case ICMP6_ROUTER_RENUMBERING:
720 if (accept_rr == 0) {
721 syslog(LOG_ERR, "<%s> received a router renumbering "
722 "message, but not allowed to be accepted",
712 inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
713 INET6_ADDRSTRLEN),
714 if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
715 return;
716 }
717 ra_input(i, (struct nd_router_advert *)icp, pi, &from);
718 break;
719 case ICMP6_ROUTER_RENUMBERING:
720 if (accept_rr == 0) {
721 syslog(LOG_ERR, "<%s> received a router renumbering "
722 "message, but not allowed to be accepted",
723 __FUNCTION__);
723 __func__);
724 break;
725 }
726 rr_input(i, (struct icmp6_router_renum *)icp, pi, &from,
727 &dst);
728 break;
729 default:
730 /*
731 * Note that this case is POSSIBLE, especially just
732 * after invocation of the daemon. This is because we
733 * could receive message after opening the socket and
734 * before setting ICMP6 type filter(see sock_open()).
735 */
736 syslog(LOG_ERR, "<%s> invalid icmp type(%d)",
724 break;
725 }
726 rr_input(i, (struct icmp6_router_renum *)icp, pi, &from,
727 &dst);
728 break;
729 default:
730 /*
731 * Note that this case is POSSIBLE, especially just
732 * after invocation of the daemon. This is because we
733 * could receive message after opening the socket and
734 * before setting ICMP6 type filter(see sock_open()).
735 */
736 syslog(LOG_ERR, "<%s> invalid icmp type(%d)",
737 __FUNCTION__, icp->icmp6_type);
737 __func__, icp->icmp6_type);
738 return;
739 }
740
741 return;
742}
743
744static void
745rs_input(int len, struct nd_router_solicit *rs,
746 struct in6_pktinfo *pi, struct sockaddr_in6 *from)
747{
748 u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
749 union nd_opts ndopts;
750 struct rainfo *ra;
751
752 syslog(LOG_DEBUG,
753 "<%s> RS received from %s on %s",
738 return;
739 }
740
741 return;
742}
743
744static void
745rs_input(int len, struct nd_router_solicit *rs,
746 struct in6_pktinfo *pi, struct sockaddr_in6 *from)
747{
748 u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
749 union nd_opts ndopts;
750 struct rainfo *ra;
751
752 syslog(LOG_DEBUG,
753 "<%s> RS received from %s on %s",
754 __FUNCTION__,
754 __func__,
755 inet_ntop(AF_INET6, &from->sin6_addr,
756 ntopbuf, INET6_ADDRSTRLEN),
757 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
758
759 /* ND option check */
760 memset(&ndopts, 0, sizeof(ndopts));
761 if (nd6_options((struct nd_opt_hdr *)(rs + 1),
762 len - sizeof(struct nd_router_solicit),
763 &ndopts, NDOPT_FLAG_SRCLINKADDR)) {
764 syslog(LOG_DEBUG,
765 "<%s> ND option check failed for an RS from %s on %s",
755 inet_ntop(AF_INET6, &from->sin6_addr,
756 ntopbuf, INET6_ADDRSTRLEN),
757 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
758
759 /* ND option check */
760 memset(&ndopts, 0, sizeof(ndopts));
761 if (nd6_options((struct nd_opt_hdr *)(rs + 1),
762 len - sizeof(struct nd_router_solicit),
763 &ndopts, NDOPT_FLAG_SRCLINKADDR)) {
764 syslog(LOG_DEBUG,
765 "<%s> ND option check failed for an RS from %s on %s",
766 __FUNCTION__,
766 __func__,
767 inet_ntop(AF_INET6, &from->sin6_addr,
768 ntopbuf, INET6_ADDRSTRLEN),
769 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
770 return;
771 }
772
773 /*
774 * If the IP source address is the unspecified address, there
775 * must be no source link-layer address option in the message.
776 * (RFC-2461 6.1.1)
777 */
778 if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) &&
779 ndopts.nd_opts_src_lladdr) {
780 syslog(LOG_ERR,
781 "<%s> RS from unspecified src on %s has a link-layer"
782 " address option",
767 inet_ntop(AF_INET6, &from->sin6_addr,
768 ntopbuf, INET6_ADDRSTRLEN),
769 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
770 return;
771 }
772
773 /*
774 * If the IP source address is the unspecified address, there
775 * must be no source link-layer address option in the message.
776 * (RFC-2461 6.1.1)
777 */
778 if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) &&
779 ndopts.nd_opts_src_lladdr) {
780 syslog(LOG_ERR,
781 "<%s> RS from unspecified src on %s has a link-layer"
782 " address option",
783 __FUNCTION__,
783 __func__,
784 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
785 goto done;
786 }
787
788 ra = ralist;
789 while (ra != NULL) {
790 if (pi->ipi6_ifindex == ra->ifindex)
791 break;
792 ra = ra->next;
793 }
794 if (ra == NULL) {
795 syslog(LOG_INFO,
796 "<%s> RS received on non advertising interface(%s)",
784 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
785 goto done;
786 }
787
788 ra = ralist;
789 while (ra != NULL) {
790 if (pi->ipi6_ifindex == ra->ifindex)
791 break;
792 ra = ra->next;
793 }
794 if (ra == NULL) {
795 syslog(LOG_INFO,
796 "<%s> RS received on non advertising interface(%s)",
797 __FUNCTION__,
797 __func__,
798 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
799 goto done;
800 }
801
802 ra->rsinput++; /* increment statistics */
803
804 /*
805 * Decide whether to send RA according to the rate-limit

--- 33 unchanged lines hidden (view full) ---

839 delay = random() % MAX_RA_DELAY_TIME;
840 interval.tv_sec = 0;
841 interval.tv_usec = delay;
842 rest = rtadvd_timer_rest(ra->timer);
843 if (TIMEVAL_LT(*rest, interval)) {
844 syslog(LOG_DEBUG,
845 "<%s> random delay is larger than "
846 "the rest of normal timer",
798 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
799 goto done;
800 }
801
802 ra->rsinput++; /* increment statistics */
803
804 /*
805 * Decide whether to send RA according to the rate-limit

--- 33 unchanged lines hidden (view full) ---

839 delay = random() % MAX_RA_DELAY_TIME;
840 interval.tv_sec = 0;
841 interval.tv_usec = delay;
842 rest = rtadvd_timer_rest(ra->timer);
843 if (TIMEVAL_LT(*rest, interval)) {
844 syslog(LOG_DEBUG,
845 "<%s> random delay is larger than "
846 "the rest of normal timer",
847 __FUNCTION__);
847 __func__);
848 interval = *rest;
849 }
850
851 /*
852 * If we sent a multicast Router Advertisement within
853 * the last MIN_DELAY_BETWEEN_RAS seconds, schedule
854 * the advertisement to be sent at a time corresponding to
855 * MIN_DELAY_BETWEEN_RAS plus the random value after the

--- 24 unchanged lines hidden (view full) ---

880 u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
881 union nd_opts ndopts;
882 char *on_off[] = {"OFF", "ON"};
883 u_int32_t reachabletime, retranstimer, mtu;
884 int inconsistent = 0;
885
886 syslog(LOG_DEBUG,
887 "<%s> RA received from %s on %s",
848 interval = *rest;
849 }
850
851 /*
852 * If we sent a multicast Router Advertisement within
853 * the last MIN_DELAY_BETWEEN_RAS seconds, schedule
854 * the advertisement to be sent at a time corresponding to
855 * MIN_DELAY_BETWEEN_RAS plus the random value after the

--- 24 unchanged lines hidden (view full) ---

880 u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
881 union nd_opts ndopts;
882 char *on_off[] = {"OFF", "ON"};
883 u_int32_t reachabletime, retranstimer, mtu;
884 int inconsistent = 0;
885
886 syslog(LOG_DEBUG,
887 "<%s> RA received from %s on %s",
888 __FUNCTION__,
888 __func__,
889 inet_ntop(AF_INET6, &from->sin6_addr,
890 ntopbuf, INET6_ADDRSTRLEN),
891 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
892
893 /* ND option check */
894 memset(&ndopts, 0, sizeof(ndopts));
895 if (nd6_options((struct nd_opt_hdr *)(ra + 1),
896 len - sizeof(struct nd_router_advert),
897 &ndopts, NDOPT_FLAG_SRCLINKADDR |
898 NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU)) {
899 syslog(LOG_ERR,
900 "<%s> ND option check failed for an RA from %s on %s",
889 inet_ntop(AF_INET6, &from->sin6_addr,
890 ntopbuf, INET6_ADDRSTRLEN),
891 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
892
893 /* ND option check */
894 memset(&ndopts, 0, sizeof(ndopts));
895 if (nd6_options((struct nd_opt_hdr *)(ra + 1),
896 len - sizeof(struct nd_router_advert),
897 &ndopts, NDOPT_FLAG_SRCLINKADDR |
898 NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU)) {
899 syslog(LOG_ERR,
900 "<%s> ND option check failed for an RA from %s on %s",
901 __FUNCTION__,
901 __func__,
902 inet_ntop(AF_INET6, &from->sin6_addr,
903 ntopbuf, INET6_ADDRSTRLEN),
904 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
905 return;
906 }
907
908 /*
909 * RA consistency check according to RFC-2461 6.2.7
910 */
911 if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == 0) {
912 syslog(LOG_INFO,
913 "<%s> received RA from %s on non-advertising"
914 " interface(%s)",
902 inet_ntop(AF_INET6, &from->sin6_addr,
903 ntopbuf, INET6_ADDRSTRLEN),
904 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
905 return;
906 }
907
908 /*
909 * RA consistency check according to RFC-2461 6.2.7
910 */
911 if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == 0) {
912 syslog(LOG_INFO,
913 "<%s> received RA from %s on non-advertising"
914 " interface(%s)",
915 __FUNCTION__,
915 __func__,
916 inet_ntop(AF_INET6, &from->sin6_addr,
917 ntopbuf, INET6_ADDRSTRLEN),
918 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
919 goto done;
920 }
921 rai->rainput++; /* increment statistics */
922
923 /* Cur Hop Limit value */
924 if (ra->nd_ra_curhoplimit && rai->hoplimit &&
925 ra->nd_ra_curhoplimit != rai->hoplimit) {
926 syslog(LOG_INFO,
927 "<%s> CurHopLimit inconsistent on %s:"
928 " %d from %s, %d from us",
916 inet_ntop(AF_INET6, &from->sin6_addr,
917 ntopbuf, INET6_ADDRSTRLEN),
918 if_indextoname(pi->ipi6_ifindex, ifnamebuf));
919 goto done;
920 }
921 rai->rainput++; /* increment statistics */
922
923 /* Cur Hop Limit value */
924 if (ra->nd_ra_curhoplimit && rai->hoplimit &&
925 ra->nd_ra_curhoplimit != rai->hoplimit) {
926 syslog(LOG_INFO,
927 "<%s> CurHopLimit inconsistent on %s:"
928 " %d from %s, %d from us",
929 __FUNCTION__,
929 __func__,
930 rai->ifname,
931 ra->nd_ra_curhoplimit,
932 inet_ntop(AF_INET6, &from->sin6_addr,
933 ntopbuf, INET6_ADDRSTRLEN),
934 rai->hoplimit);
935 inconsistent++;
936 }
937 /* M flag */
938 if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
939 rai->managedflg) {
940 syslog(LOG_INFO,
941 "<%s> M flag inconsistent on %s:"
942 " %s from %s, %s from us",
930 rai->ifname,
931 ra->nd_ra_curhoplimit,
932 inet_ntop(AF_INET6, &from->sin6_addr,
933 ntopbuf, INET6_ADDRSTRLEN),
934 rai->hoplimit);
935 inconsistent++;
936 }
937 /* M flag */
938 if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
939 rai->managedflg) {
940 syslog(LOG_INFO,
941 "<%s> M flag inconsistent on %s:"
942 " %s from %s, %s from us",
943 __FUNCTION__,
943 __func__,
944 rai->ifname,
945 on_off[!rai->managedflg],
946 inet_ntop(AF_INET6, &from->sin6_addr,
947 ntopbuf, INET6_ADDRSTRLEN),
948 on_off[rai->managedflg]);
949 inconsistent++;
950 }
951 /* O flag */
952 if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
953 rai->otherflg) {
954 syslog(LOG_INFO,
955 "<%s> O flag inconsistent on %s:"
956 " %s from %s, %s from us",
944 rai->ifname,
945 on_off[!rai->managedflg],
946 inet_ntop(AF_INET6, &from->sin6_addr,
947 ntopbuf, INET6_ADDRSTRLEN),
948 on_off[rai->managedflg]);
949 inconsistent++;
950 }
951 /* O flag */
952 if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
953 rai->otherflg) {
954 syslog(LOG_INFO,
955 "<%s> O flag inconsistent on %s:"
956 " %s from %s, %s from us",
957 __FUNCTION__,
957 __func__,
958 rai->ifname,
959 on_off[!rai->otherflg],
960 inet_ntop(AF_INET6, &from->sin6_addr,
961 ntopbuf, INET6_ADDRSTRLEN),
962 on_off[rai->otherflg]);
963 inconsistent++;
964 }
965 /* Reachable Time */
966 reachabletime = ntohl(ra->nd_ra_reachable);
967 if (reachabletime && rai->reachabletime &&
968 reachabletime != rai->reachabletime) {
969 syslog(LOG_INFO,
970 "<%s> ReachableTime inconsistent on %s:"
971 " %d from %s, %d from us",
958 rai->ifname,
959 on_off[!rai->otherflg],
960 inet_ntop(AF_INET6, &from->sin6_addr,
961 ntopbuf, INET6_ADDRSTRLEN),
962 on_off[rai->otherflg]);
963 inconsistent++;
964 }
965 /* Reachable Time */
966 reachabletime = ntohl(ra->nd_ra_reachable);
967 if (reachabletime && rai->reachabletime &&
968 reachabletime != rai->reachabletime) {
969 syslog(LOG_INFO,
970 "<%s> ReachableTime inconsistent on %s:"
971 " %d from %s, %d from us",
972 __FUNCTION__,
972 __func__,
973 rai->ifname,
974 reachabletime,
975 inet_ntop(AF_INET6, &from->sin6_addr,
976 ntopbuf, INET6_ADDRSTRLEN),
977 rai->reachabletime);
978 inconsistent++;
979 }
980 /* Retrans Timer */
981 retranstimer = ntohl(ra->nd_ra_retransmit);
982 if (retranstimer && rai->retranstimer &&
983 retranstimer != rai->retranstimer) {
984 syslog(LOG_INFO,
985 "<%s> RetranceTimer inconsistent on %s:"
986 " %d from %s, %d from us",
973 rai->ifname,
974 reachabletime,
975 inet_ntop(AF_INET6, &from->sin6_addr,
976 ntopbuf, INET6_ADDRSTRLEN),
977 rai->reachabletime);
978 inconsistent++;
979 }
980 /* Retrans Timer */
981 retranstimer = ntohl(ra->nd_ra_retransmit);
982 if (retranstimer && rai->retranstimer &&
983 retranstimer != rai->retranstimer) {
984 syslog(LOG_INFO,
985 "<%s> RetranceTimer inconsistent on %s:"
986 " %d from %s, %d from us",
987 __FUNCTION__,
987 __func__,
988 rai->ifname,
989 retranstimer,
990 inet_ntop(AF_INET6, &from->sin6_addr,
991 ntopbuf, INET6_ADDRSTRLEN),
992 rai->retranstimer);
993 inconsistent++;
994 }
995 /* Values in the MTU options */
996 if (ndopts.nd_opts_mtu) {
997 mtu = ntohl(ndopts.nd_opts_mtu->nd_opt_mtu_mtu);
998 if (mtu && rai->linkmtu && mtu != rai->linkmtu) {
999 syslog(LOG_INFO,
1000 "<%s> MTU option value inconsistent on %s:"
1001 " %d from %s, %d from us",
988 rai->ifname,
989 retranstimer,
990 inet_ntop(AF_INET6, &from->sin6_addr,
991 ntopbuf, INET6_ADDRSTRLEN),
992 rai->retranstimer);
993 inconsistent++;
994 }
995 /* Values in the MTU options */
996 if (ndopts.nd_opts_mtu) {
997 mtu = ntohl(ndopts.nd_opts_mtu->nd_opt_mtu_mtu);
998 if (mtu && rai->linkmtu && mtu != rai->linkmtu) {
999 syslog(LOG_INFO,
1000 "<%s> MTU option value inconsistent on %s:"
1001 " %d from %s, %d from us",
1002 __FUNCTION__,
1002 __func__,
1003 rai->ifname, mtu,
1004 inet_ntop(AF_INET6, &from->sin6_addr,
1005 ntopbuf, INET6_ADDRSTRLEN),
1006 rai->linkmtu);
1007 inconsistent++;
1008 }
1009 }
1010 /* Preferred and Valid Lifetimes for prefixes */

--- 38 unchanged lines hidden (view full) ---

1049
1050 /*
1051 * log if the adveritsed prefix has link-local scope(sanity check?)
1052 */
1053 if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix)) {
1054 syslog(LOG_INFO,
1055 "<%s> link-local prefix %s/%d is advertised "
1056 "from %s on %s",
1003 rai->ifname, mtu,
1004 inet_ntop(AF_INET6, &from->sin6_addr,
1005 ntopbuf, INET6_ADDRSTRLEN),
1006 rai->linkmtu);
1007 inconsistent++;
1008 }
1009 }
1010 /* Preferred and Valid Lifetimes for prefixes */

--- 38 unchanged lines hidden (view full) ---

1049
1050 /*
1051 * log if the adveritsed prefix has link-local scope(sanity check?)
1052 */
1053 if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix)) {
1054 syslog(LOG_INFO,
1055 "<%s> link-local prefix %s/%d is advertised "
1056 "from %s on %s",
1057 __FUNCTION__,
1057 __func__,
1058 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1059 prefixbuf, INET6_ADDRSTRLEN),
1060 pinfo->nd_opt_pi_prefix_len,
1061 inet_ntop(AF_INET6, &from->sin6_addr,
1062 ntopbuf, INET6_ADDRSTRLEN),
1063 rai->ifname);
1064 }
1065
1066 if ((pp = find_prefix(rai, &pinfo->nd_opt_pi_prefix,
1067 pinfo->nd_opt_pi_prefix_len)) == NULL) {
1068 syslog(LOG_INFO,
1069 "<%s> prefix %s/%d from %s on %s is not in our list",
1058 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1059 prefixbuf, INET6_ADDRSTRLEN),
1060 pinfo->nd_opt_pi_prefix_len,
1061 inet_ntop(AF_INET6, &from->sin6_addr,
1062 ntopbuf, INET6_ADDRSTRLEN),
1063 rai->ifname);
1064 }
1065
1066 if ((pp = find_prefix(rai, &pinfo->nd_opt_pi_prefix,
1067 pinfo->nd_opt_pi_prefix_len)) == NULL) {
1068 syslog(LOG_INFO,
1069 "<%s> prefix %s/%d from %s on %s is not in our list",
1070 __FUNCTION__,
1070 __func__,
1071 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1072 prefixbuf, INET6_ADDRSTRLEN),
1073 pinfo->nd_opt_pi_prefix_len,
1074 inet_ntop(AF_INET6, &from->sin6_addr,
1075 ntopbuf, INET6_ADDRSTRLEN),
1076 rai->ifname);
1077 return(0);
1078 }

--- 11 unchanged lines hidden (view full) ---

1090 preferred_time += now.tv_sec;
1091
1092 if (rai->clockskew &&
1093 abs(preferred_time - pp->pltimeexpire) > rai->clockskew) {
1094 syslog(LOG_INFO,
1095 "<%s> prefeerred lifetime for %s/%d"
1096 " (decr. in real time) inconsistent on %s:"
1097 " %d from %s, %ld from us",
1071 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1072 prefixbuf, INET6_ADDRSTRLEN),
1073 pinfo->nd_opt_pi_prefix_len,
1074 inet_ntop(AF_INET6, &from->sin6_addr,
1075 ntopbuf, INET6_ADDRSTRLEN),
1076 rai->ifname);
1077 return(0);
1078 }

--- 11 unchanged lines hidden (view full) ---

1090 preferred_time += now.tv_sec;
1091
1092 if (rai->clockskew &&
1093 abs(preferred_time - pp->pltimeexpire) > rai->clockskew) {
1094 syslog(LOG_INFO,
1095 "<%s> prefeerred lifetime for %s/%d"
1096 " (decr. in real time) inconsistent on %s:"
1097 " %d from %s, %ld from us",
1098 __FUNCTION__,
1098 __func__,
1099 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1100 prefixbuf, INET6_ADDRSTRLEN),
1101 pinfo->nd_opt_pi_prefix_len,
1102 rai->ifname, preferred_time,
1103 inet_ntop(AF_INET6, &from->sin6_addr,
1104 ntopbuf, INET6_ADDRSTRLEN),
1105 pp->pltimeexpire);
1106 inconsistent++;
1107 }
1108 } else if (preferred_time != pp->preflifetime) {
1109 syslog(LOG_INFO,
1110 "<%s> prefeerred lifetime for %s/%d"
1111 " inconsistent on %s:"
1112 " %d from %s, %d from us",
1099 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1100 prefixbuf, INET6_ADDRSTRLEN),
1101 pinfo->nd_opt_pi_prefix_len,
1102 rai->ifname, preferred_time,
1103 inet_ntop(AF_INET6, &from->sin6_addr,
1104 ntopbuf, INET6_ADDRSTRLEN),
1105 pp->pltimeexpire);
1106 inconsistent++;
1107 }
1108 } else if (preferred_time != pp->preflifetime) {
1109 syslog(LOG_INFO,
1110 "<%s> prefeerred lifetime for %s/%d"
1111 " inconsistent on %s:"
1112 " %d from %s, %d from us",
1113 __FUNCTION__,
1113 __func__,
1114 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1115 prefixbuf, INET6_ADDRSTRLEN),
1116 pinfo->nd_opt_pi_prefix_len,
1117 rai->ifname, preferred_time,
1118 inet_ntop(AF_INET6, &from->sin6_addr,
1119 ntopbuf, INET6_ADDRSTRLEN),
1120 pp->preflifetime);
1121 }

--- 4 unchanged lines hidden (view full) ---

1126 valid_time += now.tv_sec;
1127
1128 if (rai->clockskew &&
1129 abs(valid_time - pp->vltimeexpire) > rai->clockskew) {
1130 syslog(LOG_INFO,
1131 "<%s> valid lifetime for %s/%d"
1132 " (decr. in real time) inconsistent on %s:"
1133 " %d from %s, %ld from us",
1114 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1115 prefixbuf, INET6_ADDRSTRLEN),
1116 pinfo->nd_opt_pi_prefix_len,
1117 rai->ifname, preferred_time,
1118 inet_ntop(AF_INET6, &from->sin6_addr,
1119 ntopbuf, INET6_ADDRSTRLEN),
1120 pp->preflifetime);
1121 }

--- 4 unchanged lines hidden (view full) ---

1126 valid_time += now.tv_sec;
1127
1128 if (rai->clockskew &&
1129 abs(valid_time - pp->vltimeexpire) > rai->clockskew) {
1130 syslog(LOG_INFO,
1131 "<%s> valid lifetime for %s/%d"
1132 " (decr. in real time) inconsistent on %s:"
1133 " %d from %s, %ld from us",
1134 __FUNCTION__,
1134 __func__,
1135 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1136 prefixbuf, INET6_ADDRSTRLEN),
1137 pinfo->nd_opt_pi_prefix_len,
1138 rai->ifname, preferred_time,
1139 inet_ntop(AF_INET6, &from->sin6_addr,
1140 ntopbuf, INET6_ADDRSTRLEN),
1141 pp->vltimeexpire);
1142 inconsistent++;
1143 }
1144 } else if (valid_time != pp->validlifetime) {
1145 syslog(LOG_INFO,
1146 "<%s> valid lifetime for %s/%d"
1147 " inconsistent on %s:"
1148 " %d from %s, %d from us",
1135 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1136 prefixbuf, INET6_ADDRSTRLEN),
1137 pinfo->nd_opt_pi_prefix_len,
1138 rai->ifname, preferred_time,
1139 inet_ntop(AF_INET6, &from->sin6_addr,
1140 ntopbuf, INET6_ADDRSTRLEN),
1141 pp->vltimeexpire);
1142 inconsistent++;
1143 }
1144 } else if (valid_time != pp->validlifetime) {
1145 syslog(LOG_INFO,
1146 "<%s> valid lifetime for %s/%d"
1147 " inconsistent on %s:"
1148 " %d from %s, %d from us",
1149 __FUNCTION__,
1149 __func__,
1150 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1151 prefixbuf, INET6_ADDRSTRLEN),
1152 pinfo->nd_opt_pi_prefix_len,
1153 rai->ifname, valid_time,
1154 inet_ntop(AF_INET6, &from->sin6_addr,
1155 ntopbuf, INET6_ADDRSTRLEN),
1156 pp->validlifetime);
1157 inconsistent++;

--- 46 unchanged lines hidden (view full) ---

1204static int
1205nd6_options(struct nd_opt_hdr *hdr, int limit,
1206 union nd_opts *ndopts, u_int32_t optflags)
1207{
1208 int optlen = 0;
1209
1210 for (; limit > 0; limit -= optlen) {
1211 if (limit < sizeof(struct nd_opt_hdr)) {
1150 inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
1151 prefixbuf, INET6_ADDRSTRLEN),
1152 pinfo->nd_opt_pi_prefix_len,
1153 rai->ifname, valid_time,
1154 inet_ntop(AF_INET6, &from->sin6_addr,
1155 ntopbuf, INET6_ADDRSTRLEN),
1156 pp->validlifetime);
1157 inconsistent++;

--- 46 unchanged lines hidden (view full) ---

1204static int
1205nd6_options(struct nd_opt_hdr *hdr, int limit,
1206 union nd_opts *ndopts, u_int32_t optflags)
1207{
1208 int optlen = 0;
1209
1210 for (; limit > 0; limit -= optlen) {
1211 if (limit < sizeof(struct nd_opt_hdr)) {
1212 syslog(LOG_INFO, "<%s> short option header", __FUNCTION__);
1212 syslog(LOG_INFO, "<%s> short option header", __func__);
1213 goto bad;
1214 }
1215
1216 hdr = (struct nd_opt_hdr *)((caddr_t)hdr + optlen);
1217 if (hdr->nd_opt_len == 0) {
1218 syslog(LOG_INFO,
1219 "<%s> bad ND option length(0) (type = %d)",
1213 goto bad;
1214 }
1215
1216 hdr = (struct nd_opt_hdr *)((caddr_t)hdr + optlen);
1217 if (hdr->nd_opt_len == 0) {
1218 syslog(LOG_INFO,
1219 "<%s> bad ND option length(0) (type = %d)",
1220 __FUNCTION__, hdr->nd_opt_type);
1220 __func__, hdr->nd_opt_type);
1221 goto bad;
1222 }
1223 optlen = hdr->nd_opt_len << 3;
1224 if (optlen > limit) {
1221 goto bad;
1222 }
1223 optlen = hdr->nd_opt_len << 3;
1224 if (optlen > limit) {
1225 syslog(LOG_INFO, "<%s> short option", __FUNCTION__);
1225 syslog(LOG_INFO, "<%s> short option", __func__);
1226 goto bad;
1227 }
1228
1229 if (hdr->nd_opt_type > ND_OPT_MTU) {
1230 syslog(LOG_INFO,
1231 "<%s> unknown ND option(type %d)",
1226 goto bad;
1227 }
1228
1229 if (hdr->nd_opt_type > ND_OPT_MTU) {
1230 syslog(LOG_INFO,
1231 "<%s> unknown ND option(type %d)",
1232 __FUNCTION__, hdr->nd_opt_type);
1232 __func__, hdr->nd_opt_type);
1233 continue;
1234 }
1235
1236 if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) {
1237 syslog(LOG_INFO,
1238 "<%s> unexpected ND option(type %d)",
1233 continue;
1234 }
1235
1236 if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) {
1237 syslog(LOG_INFO,
1238 "<%s> unexpected ND option(type %d)",
1239 __FUNCTION__, hdr->nd_opt_type);
1239 __func__, hdr->nd_opt_type);
1240 continue;
1241 }
1242
1243 /*
1244 * Option length check. Do it here for all fixed-length
1245 * options.
1246 */
1247 if ((hdr->nd_opt_type == ND_OPT_MTU &&
1248 (optlen != sizeof(struct nd_opt_mtu))) ||
1249 ((hdr->nd_opt_type == ND_OPT_PREFIX_INFORMATION &&
1250 optlen != sizeof(struct nd_opt_prefix_info)))) {
1251 syslog(LOG_INFO, "<%s> invalid option length",
1240 continue;
1241 }
1242
1243 /*
1244 * Option length check. Do it here for all fixed-length
1245 * options.
1246 */
1247 if ((hdr->nd_opt_type == ND_OPT_MTU &&
1248 (optlen != sizeof(struct nd_opt_mtu))) ||
1249 ((hdr->nd_opt_type == ND_OPT_PREFIX_INFORMATION &&
1250 optlen != sizeof(struct nd_opt_prefix_info)))) {
1251 syslog(LOG_INFO, "<%s> invalid option length",
1252 __FUNCTION__);
1252 __func__);
1253 continue;
1254 }
1255
1256 switch (hdr->nd_opt_type) {
1257 case ND_OPT_SOURCE_LINKADDR:
1258 case ND_OPT_TARGET_LINKADDR:
1259 case ND_OPT_REDIRECTED_HEADER:
1260 break; /* we don't care about these options */
1261 case ND_OPT_MTU:
1262 if (ndopts->nd_opt_array[hdr->nd_opt_type]) {
1263 syslog(LOG_INFO,
1264 "<%s> duplicated ND option (type = %d)",
1253 continue;
1254 }
1255
1256 switch (hdr->nd_opt_type) {
1257 case ND_OPT_SOURCE_LINKADDR:
1258 case ND_OPT_TARGET_LINKADDR:
1259 case ND_OPT_REDIRECTED_HEADER:
1260 break; /* we don't care about these options */
1261 case ND_OPT_MTU:
1262 if (ndopts->nd_opt_array[hdr->nd_opt_type]) {
1263 syslog(LOG_INFO,
1264 "<%s> duplicated ND option (type = %d)",
1265 __FUNCTION__, hdr->nd_opt_type);
1265 __func__, hdr->nd_opt_type);
1266 }
1267 ndopts->nd_opt_array[hdr->nd_opt_type] = hdr;
1268 break;
1269 case ND_OPT_PREFIX_INFORMATION:
1270 {
1271 struct nd_optlist *pfxlist;
1272
1273 if (ndopts->nd_opts_pi == 0) {
1274 ndopts->nd_opts_pi =
1275 (struct nd_opt_prefix_info *)hdr;
1276 continue;
1277 }
1278 if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) {
1279 syslog(LOG_ERR, "<%s> can't allocate memory",
1266 }
1267 ndopts->nd_opt_array[hdr->nd_opt_type] = hdr;
1268 break;
1269 case ND_OPT_PREFIX_INFORMATION:
1270 {
1271 struct nd_optlist *pfxlist;
1272
1273 if (ndopts->nd_opts_pi == 0) {
1274 ndopts->nd_opts_pi =
1275 (struct nd_opt_prefix_info *)hdr;
1276 continue;
1277 }
1278 if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) {
1279 syslog(LOG_ERR, "<%s> can't allocate memory",
1280 __FUNCTION__);
1280 __func__);
1281 goto bad;
1282 }
1283 pfxlist->next = ndopts->nd_opts_list;
1284 pfxlist->opt = hdr;
1285 ndopts->nd_opts_list = pfxlist;
1286
1287 break;
1288 }

--- 31 unchanged lines hidden (view full) ---

1320 int on;
1321 /* XXX: should be max MTU attached to the node */
1322 static u_char answer[1500];
1323
1324 rcvcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
1325 CMSG_SPACE(sizeof(int));
1326 rcvcmsgbuf = (u_char *)malloc(rcvcmsgbuflen);
1327 if (rcvcmsgbuf == NULL) {
1281 goto bad;
1282 }
1283 pfxlist->next = ndopts->nd_opts_list;
1284 pfxlist->opt = hdr;
1285 ndopts->nd_opts_list = pfxlist;
1286
1287 break;
1288 }

--- 31 unchanged lines hidden (view full) ---

1320 int on;
1321 /* XXX: should be max MTU attached to the node */
1322 static u_char answer[1500];
1323
1324 rcvcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
1325 CMSG_SPACE(sizeof(int));
1326 rcvcmsgbuf = (u_char *)malloc(rcvcmsgbuflen);
1327 if (rcvcmsgbuf == NULL) {
1328 syslog(LOG_ERR, "<%s> not enough core", __FUNCTION__);
1328 syslog(LOG_ERR, "<%s> not enough core", __func__);
1329 exit(1);
1330 }
1331
1332 sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
1333 CMSG_SPACE(sizeof(int));
1334 sndcmsgbuf = (u_char *)malloc(sndcmsgbuflen);
1335 if (sndcmsgbuf == NULL) {
1329 exit(1);
1330 }
1331
1332 sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
1333 CMSG_SPACE(sizeof(int));
1334 sndcmsgbuf = (u_char *)malloc(sndcmsgbuflen);
1335 if (sndcmsgbuf == NULL) {
1336 syslog(LOG_ERR, "<%s> not enough core", __FUNCTION__);
1336 syslog(LOG_ERR, "<%s> not enough core", __func__);
1337 exit(1);
1338 }
1339
1340 if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
1337 exit(1);
1338 }
1339
1340 if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
1341 syslog(LOG_ERR, "<%s> socket: %s", __FUNCTION__,
1341 syslog(LOG_ERR, "<%s> socket: %s", __func__,
1342 strerror(errno));
1343 exit(1);
1344 }
1345
1346 /* specify to tell receiving interface */
1347 on = 1;
1348#ifdef IPV6_RECVPKTINFO
1349 if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
1350 sizeof(on)) < 0) {
1351 syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s",
1342 strerror(errno));
1343 exit(1);
1344 }
1345
1346 /* specify to tell receiving interface */
1347 on = 1;
1348#ifdef IPV6_RECVPKTINFO
1349 if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
1350 sizeof(on)) < 0) {
1351 syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s",
1352 __FUNCTION__, strerror(errno));
1352 __func__, strerror(errno));
1353 exit(1);
1354 }
1355#else /* old adv. API */
1356 if (setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
1357 sizeof(on)) < 0) {
1358 syslog(LOG_ERR, "<%s> IPV6_PKTINFO: %s",
1353 exit(1);
1354 }
1355#else /* old adv. API */
1356 if (setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
1357 sizeof(on)) < 0) {
1358 syslog(LOG_ERR, "<%s> IPV6_PKTINFO: %s",
1359 __FUNCTION__, strerror(errno));
1359 __func__, strerror(errno));
1360 exit(1);
1361 }
1362#endif
1363
1364 on = 1;
1365 /* specify to tell value of hoplimit field of received IP6 hdr */
1366#ifdef IPV6_RECVHOPLIMIT
1367 if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
1368 sizeof(on)) < 0) {
1369 syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %s",
1360 exit(1);
1361 }
1362#endif
1363
1364 on = 1;
1365 /* specify to tell value of hoplimit field of received IP6 hdr */
1366#ifdef IPV6_RECVHOPLIMIT
1367 if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
1368 sizeof(on)) < 0) {
1369 syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %s",
1370 __FUNCTION__, strerror(errno));
1370 __func__, strerror(errno));
1371 exit(1);
1372 }
1373#else /* old adv. API */
1374 if (setsockopt(sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
1375 sizeof(on)) < 0) {
1376 syslog(LOG_ERR, "<%s> IPV6_HOPLIMIT: %s",
1371 exit(1);
1372 }
1373#else /* old adv. API */
1374 if (setsockopt(sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
1375 sizeof(on)) < 0) {
1376 syslog(LOG_ERR, "<%s> IPV6_HOPLIMIT: %s",
1377 __FUNCTION__, strerror(errno));
1377 __func__, strerror(errno));
1378 exit(1);
1379 }
1380#endif
1381
1382 ICMP6_FILTER_SETBLOCKALL(&filt);
1383 ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt);
1384 ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
1385 if (accept_rr)
1386 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
1387 if (setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
1388 sizeof(filt)) < 0) {
1389 syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s",
1378 exit(1);
1379 }
1380#endif
1381
1382 ICMP6_FILTER_SETBLOCKALL(&filt);
1383 ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt);
1384 ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
1385 if (accept_rr)
1386 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
1387 if (setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
1388 sizeof(filt)) < 0) {
1389 syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s",
1390 __FUNCTION__, strerror(errno));
1390 __func__, strerror(errno));
1391 exit(1);
1392 }
1393
1394 /*
1395 * join all routers multicast address on each advertising interface.
1396 */
1397 if (inet_pton(AF_INET6, ALLROUTERS_LINK,
1398 &mreq.ipv6mr_multiaddr.s6_addr)
1399 != 1) {
1400 syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
1391 exit(1);
1392 }
1393
1394 /*
1395 * join all routers multicast address on each advertising interface.
1396 */
1397 if (inet_pton(AF_INET6, ALLROUTERS_LINK,
1398 &mreq.ipv6mr_multiaddr.s6_addr)
1399 != 1) {
1400 syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
1401 __FUNCTION__);
1401 __func__);
1402 exit(1);
1403 }
1404 while (ra) {
1405 mreq.ipv6mr_interface = ra->ifindex;
1406 if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
1407 sizeof(mreq)) < 0) {
1408 syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP(link) on %s: %s",
1402 exit(1);
1403 }
1404 while (ra) {
1405 mreq.ipv6mr_interface = ra->ifindex;
1406 if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
1407 sizeof(mreq)) < 0) {
1408 syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP(link) on %s: %s",
1409 __FUNCTION__, ra->ifname, strerror(errno));
1409 __func__, ra->ifname, strerror(errno));
1410 exit(1);
1411 }
1412 ra = ra->next;
1413 }
1414
1415 /*
1416 * When attending router renumbering, join all-routers site-local
1417 * multicast group.
1418 */
1419 if (accept_rr) {
1420 if (inet_pton(AF_INET6, ALLROUTERS_SITE,
1421 &in6a_site_allrouters) != 1) {
1422 syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
1410 exit(1);
1411 }
1412 ra = ra->next;
1413 }
1414
1415 /*
1416 * When attending router renumbering, join all-routers site-local
1417 * multicast group.
1418 */
1419 if (accept_rr) {
1420 if (inet_pton(AF_INET6, ALLROUTERS_SITE,
1421 &in6a_site_allrouters) != 1) {
1422 syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
1423 __FUNCTION__);
1423 __func__);
1424 exit(1);
1425 }
1426 mreq.ipv6mr_multiaddr = in6a_site_allrouters;
1427 if (mcastif) {
1428 if ((mreq.ipv6mr_interface = if_nametoindex(mcastif))
1429 == 0) {
1430 syslog(LOG_ERR,
1431 "<%s> invalid interface: %s",
1424 exit(1);
1425 }
1426 mreq.ipv6mr_multiaddr = in6a_site_allrouters;
1427 if (mcastif) {
1428 if ((mreq.ipv6mr_interface = if_nametoindex(mcastif))
1429 == 0) {
1430 syslog(LOG_ERR,
1431 "<%s> invalid interface: %s",
1432 __FUNCTION__, mcastif);
1432 __func__, mcastif);
1433 exit(1);
1434 }
1435 } else
1436 mreq.ipv6mr_interface = ralist->ifindex;
1437 if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
1438 &mreq, sizeof(mreq)) < 0) {
1439 syslog(LOG_ERR,
1440 "<%s> IPV6_JOIN_GROUP(site) on %s: %s",
1433 exit(1);
1434 }
1435 } else
1436 mreq.ipv6mr_interface = ralist->ifindex;
1437 if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
1438 &mreq, sizeof(mreq)) < 0) {
1439 syslog(LOG_ERR,
1440 "<%s> IPV6_JOIN_GROUP(site) on %s: %s",
1441 __FUNCTION__,
1441 __func__,
1442 mcastif ? mcastif : ralist->ifname,
1443 strerror(errno));
1444 exit(1);
1445 }
1446 }
1447
1448 /* initialize msghdr for receiving packets */
1449 rcviov[0].iov_base = (caddr_t)answer;

--- 16 unchanged lines hidden (view full) ---

1466}
1467
1468/* open a routing socket to watch the routing table */
1469static void
1470rtsock_open()
1471{
1472 if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
1473 syslog(LOG_ERR,
1442 mcastif ? mcastif : ralist->ifname,
1443 strerror(errno));
1444 exit(1);
1445 }
1446 }
1447
1448 /* initialize msghdr for receiving packets */
1449 rcviov[0].iov_base = (caddr_t)answer;

--- 16 unchanged lines hidden (view full) ---

1466}
1467
1468/* open a routing socket to watch the routing table */
1469static void
1470rtsock_open()
1471{
1472 if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
1473 syslog(LOG_ERR,
1474 "<%s> socket: %s", __FUNCTION__, strerror(errno));
1474 "<%s> socket: %s", __func__, strerror(errno));
1475 exit(1);
1476 }
1477}
1478
1479struct rainfo *
1480if_indextorainfo(int index)
1481{
1482 struct rainfo *rai = ralist;

--- 12 unchanged lines hidden (view full) ---

1495{
1496 int i;
1497 struct cmsghdr *cm;
1498 struct in6_pktinfo *pi;
1499 struct soliciter *sol, *nextsol;
1500
1501 if ((iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) {
1502 syslog(LOG_DEBUG, "<%s> %s is not up, skip sending RA",
1475 exit(1);
1476 }
1477}
1478
1479struct rainfo *
1480if_indextorainfo(int index)
1481{
1482 struct rainfo *rai = ralist;

--- 12 unchanged lines hidden (view full) ---

1495{
1496 int i;
1497 struct cmsghdr *cm;
1498 struct in6_pktinfo *pi;
1499 struct soliciter *sol, *nextsol;
1500
1501 if ((iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) {
1502 syslog(LOG_DEBUG, "<%s> %s is not up, skip sending RA",
1503 __FUNCTION__, rainfo->ifname);
1503 __func__, rainfo->ifname);
1504 return;
1505 }
1506
1507 make_packet(rainfo); /* XXX: inefficient */
1508
1509 sndmhdr.msg_name = (caddr_t)&sin6_allnodes;
1510 sndmhdr.msg_iov[0].iov_base = (caddr_t)rainfo->ra_data;
1511 sndmhdr.msg_iov[0].iov_len = rainfo->ra_datalen;

--- 15 unchanged lines hidden (view full) ---

1527 cm->cmsg_level = IPPROTO_IPV6;
1528 cm->cmsg_type = IPV6_HOPLIMIT;
1529 cm->cmsg_len = CMSG_LEN(sizeof(int));
1530 memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
1531 }
1532
1533 syslog(LOG_DEBUG,
1534 "<%s> send RA on %s, # of waitings = %d",
1504 return;
1505 }
1506
1507 make_packet(rainfo); /* XXX: inefficient */
1508
1509 sndmhdr.msg_name = (caddr_t)&sin6_allnodes;
1510 sndmhdr.msg_iov[0].iov_base = (caddr_t)rainfo->ra_data;
1511 sndmhdr.msg_iov[0].iov_len = rainfo->ra_datalen;

--- 15 unchanged lines hidden (view full) ---

1527 cm->cmsg_level = IPPROTO_IPV6;
1528 cm->cmsg_type = IPV6_HOPLIMIT;
1529 cm->cmsg_len = CMSG_LEN(sizeof(int));
1530 memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
1531 }
1532
1533 syslog(LOG_DEBUG,
1534 "<%s> send RA on %s, # of waitings = %d",
1535 __FUNCTION__, rainfo->ifname, rainfo->waiting);
1535 __func__, rainfo->ifname, rainfo->waiting);
1536
1537 i = sendmsg(sock, &sndmhdr, 0);
1538
1539 if (i < 0 || i != rainfo->ra_datalen) {
1540 if (i < 0) {
1541 syslog(LOG_ERR, "<%s> sendmsg on %s: %s",
1536
1537 i = sendmsg(sock, &sndmhdr, 0);
1538
1539 if (i < 0 || i != rainfo->ra_datalen) {
1540 if (i < 0) {
1541 syslog(LOG_ERR, "<%s> sendmsg on %s: %s",
1542 __FUNCTION__, rainfo->ifname,
1542 __func__, rainfo->ifname,
1543 strerror(errno));
1544 }
1545 }
1546
1547 /*
1548 * unicast advertisements
1549 * XXX commented out. reason: though spec does not forbit it, unicast
1550 * advert does not really help
1551 */
1552 for (sol = rainfo->soliciter; sol; sol = nextsol) {
1553 nextsol = sol->next;
1554
1555#if 0
1556 sndmhdr.msg_name = (caddr_t)&sol->addr;
1557 i = sendmsg(sock, &sndmhdr, 0);
1558 if (i < 0 || i != rainfo->ra_datalen) {
1559 if (i < 0) {
1560 syslog(LOG_ERR,
1561 "<%s> unicast sendmsg on %s: %s",
1543 strerror(errno));
1544 }
1545 }
1546
1547 /*
1548 * unicast advertisements
1549 * XXX commented out. reason: though spec does not forbit it, unicast
1550 * advert does not really help
1551 */
1552 for (sol = rainfo->soliciter; sol; sol = nextsol) {
1553 nextsol = sol->next;
1554
1555#if 0
1556 sndmhdr.msg_name = (caddr_t)&sol->addr;
1557 i = sendmsg(sock, &sndmhdr, 0);
1558 if (i < 0 || i != rainfo->ra_datalen) {
1559 if (i < 0) {
1560 syslog(LOG_ERR,
1561 "<%s> unicast sendmsg on %s: %s",
1562 __FUNCTION__, rainfo->ifname,
1562 __func__, rainfo->ifname,
1563 strerror(errno));
1564 }
1565 }
1566#endif
1567
1568 sol->next = NULL;
1569 free(sol);
1570 }

--- 18 unchanged lines hidden (view full) ---

1589 struct rainfo *rai = (struct rainfo *)data;
1590
1591#ifdef notyet
1592 /* if necessary, reconstruct the packet. */
1593#endif
1594
1595 syslog(LOG_DEBUG,
1596 "<%s> RA timer on %s is expired",
1563 strerror(errno));
1564 }
1565 }
1566#endif
1567
1568 sol->next = NULL;
1569 free(sol);
1570 }

--- 18 unchanged lines hidden (view full) ---

1589 struct rainfo *rai = (struct rainfo *)data;
1590
1591#ifdef notyet
1592 /* if necessary, reconstruct the packet. */
1593#endif
1594
1595 syslog(LOG_DEBUG,
1596 "<%s> RA timer on %s is expired",
1597 __FUNCTION__, rai->ifname);
1597 __func__, rai->ifname);
1598
1599 ra_output(rai);
1600
1601 return(rai->timer);
1602}
1603
1604/* update RA timer */
1605void

--- 22 unchanged lines hidden (view full) ---

1628 interval > MAX_INITIAL_RTR_ADVERT_INTERVAL)
1629 interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
1630
1631 tm->tv_sec = interval;
1632 tm->tv_usec = 0;
1633
1634 syslog(LOG_DEBUG,
1635 "<%s> RA timer on %s is set to %ld:%ld",
1598
1599 ra_output(rai);
1600
1601 return(rai->timer);
1602}
1603
1604/* update RA timer */
1605void

--- 22 unchanged lines hidden (view full) ---

1628 interval > MAX_INITIAL_RTR_ADVERT_INTERVAL)
1629 interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
1630
1631 tm->tv_sec = interval;
1632 tm->tv_usec = 0;
1633
1634 syslog(LOG_DEBUG,
1635 "<%s> RA timer on %s is set to %ld:%ld",
1636 __FUNCTION__, rai->ifname,
1636 __func__, rai->ifname,
1637 (long int)tm->tv_sec, (long int)tm->tv_usec);
1638
1639 return;
1640}
1637 (long int)tm->tv_sec, (long int)tm->tv_usec);
1638
1639 return;
1640}