Deleted Added
full compact
rtsold.c (93363) rtsold.c (118660)
1/* $KAME: rtsold.c,v 1.31 2001/05/22 06:03:06 jinmei Exp $ */
2
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
1/* $KAME: rtsold.c,v 1.31 2001/05/22 06:03:06 jinmei Exp $ */
2
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $FreeBSD: head/usr.sbin/rtsold/rtsold.c 93363 2002-03-29 04:43:07Z ume $
31 * $FreeBSD: head/usr.sbin/rtsold/rtsold.c 118660 2003-08-08 16:38:23Z ume $
32 */
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37
38#include <net/if.h>
39#include <net/if_dl.h>

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

254 daemon(0, 0); /* act as a daemon */
255
256 /* dump the current pid */
257 if (!once) {
258 pid_t pid = getpid();
259 FILE *fp;
260
261 if ((fp = fopen(pidfilename, "w")) == NULL)
32 */
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37
38#include <net/if.h>
39#include <net/if_dl.h>

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

254 daemon(0, 0); /* act as a daemon */
255
256 /* dump the current pid */
257 if (!once) {
258 pid_t pid = getpid();
259 FILE *fp;
260
261 if ((fp = fopen(pidfilename, "w")) == NULL)
262 warnmsg(LOG_ERR, __FUNCTION__,
262 warnmsg(LOG_ERR, __func__,
263 "failed to open a log file(%s): %s",
264 pidfilename, strerror(errno));
265 else {
266 fprintf(fp, "%d\n", pid);
267 fclose(fp);
268 }
269 }
270

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

295 break;
296 }
297 if (ifi == NULL)
298 break;
299 }
300 e = select(maxfd + 1, &select_fd, NULL, NULL, timeout);
301 if (e < 1) {
302 if (e < 0 && errno != EINTR) {
263 "failed to open a log file(%s): %s",
264 pidfilename, strerror(errno));
265 else {
266 fprintf(fp, "%d\n", pid);
267 fclose(fp);
268 }
269 }
270

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

295 break;
296 }
297 if (ifi == NULL)
298 break;
299 }
300 e = select(maxfd + 1, &select_fd, NULL, NULL, timeout);
301 if (e < 1) {
302 if (e < 0 && errno != EINTR) {
303 warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
303 warnmsg(LOG_ERR, __func__, "select: %s",
304 strerror(errno));
305 }
306 continue;
307 }
308
309 /* packet reception */
310 if (FD_ISSET(rtsock, &select_fd))
311 rtsock_input(rtsock);

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

320static int
321ifconfig(char *ifname)
322{
323 struct ifinfo *ifinfo;
324 struct sockaddr_dl *sdl;
325 int flags;
326
327 if ((sdl = if_nametosdl(ifname)) == NULL) {
304 strerror(errno));
305 }
306 continue;
307 }
308
309 /* packet reception */
310 if (FD_ISSET(rtsock, &select_fd))
311 rtsock_input(rtsock);

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

320static int
321ifconfig(char *ifname)
322{
323 struct ifinfo *ifinfo;
324 struct sockaddr_dl *sdl;
325 int flags;
326
327 if ((sdl = if_nametosdl(ifname)) == NULL) {
328 warnmsg(LOG_ERR, __FUNCTION__,
328 warnmsg(LOG_ERR, __func__,
329 "failed to get link layer information for %s", ifname);
330 return(-1);
331 }
332 if (find_ifinfo(sdl->sdl_index)) {
329 "failed to get link layer information for %s", ifname);
330 return(-1);
331 }
332 if (find_ifinfo(sdl->sdl_index)) {
333 warnmsg(LOG_ERR, __FUNCTION__,
333 warnmsg(LOG_ERR, __func__,
334 "interface %s was already configured", ifname);
335 free(sdl);
336 return(-1);
337 }
338
339 if ((ifinfo = malloc(sizeof(*ifinfo))) == NULL) {
334 "interface %s was already configured", ifname);
335 free(sdl);
336 return(-1);
337 }
338
339 if ((ifinfo = malloc(sizeof(*ifinfo))) == NULL) {
340 warnmsg(LOG_ERR, __FUNCTION__, "memory allocation failed");
340 warnmsg(LOG_ERR, __func__, "memory allocation failed");
341 free(sdl);
342 return(-1);
343 }
344 memset(ifinfo, 0, sizeof(*ifinfo));
345 ifinfo->sdl = sdl;
346
347 strncpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
348

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

430static int
431make_packet(struct ifinfo *ifinfo)
432{
433 char *buf;
434 struct nd_router_solicit *rs;
435 size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0;
436
437 if ((lladdroptlen = lladdropt_length(ifinfo->sdl)) == 0) {
341 free(sdl);
342 return(-1);
343 }
344 memset(ifinfo, 0, sizeof(*ifinfo));
345 ifinfo->sdl = sdl;
346
347 strncpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
348

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

430static int
431make_packet(struct ifinfo *ifinfo)
432{
433 char *buf;
434 struct nd_router_solicit *rs;
435 size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0;
436
437 if ((lladdroptlen = lladdropt_length(ifinfo->sdl)) == 0) {
438 warnmsg(LOG_INFO, __FUNCTION__,
438 warnmsg(LOG_INFO, __func__,
439 "link-layer address option has null length"
440 " on %s. Treat as not included.", ifinfo->ifname);
441 }
442 packlen += lladdroptlen;
443 ifinfo->rs_datalen = packlen;
444
445 /* allocate buffer */
446 if ((buf = malloc(packlen)) == NULL) {
439 "link-layer address option has null length"
440 " on %s. Treat as not included.", ifinfo->ifname);
441 }
442 packlen += lladdroptlen;
443 ifinfo->rs_datalen = packlen;
444
445 /* allocate buffer */
446 if ((buf = malloc(packlen)) == NULL) {
447 warnmsg(LOG_ERR, __FUNCTION__,
447 warnmsg(LOG_ERR, __func__,
448 "memory allocation failed for %s", ifinfo->ifname);
449 return(-1);
450 }
451 ifinfo->rs_data = buf;
452
453 /* fill in the message */
454 rs = (struct nd_router_solicit *)buf;
455 rs->nd_rs_type = ND_ROUTER_SOLICIT;

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

475
476 gettimeofday(&now, NULL);
477
478 rtsol_timer = tm_max;
479
480 for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) {
481 if (TIMEVAL_LEQ(ifinfo->expire, now)) {
482 if (dflag > 1)
448 "memory allocation failed for %s", ifinfo->ifname);
449 return(-1);
450 }
451 ifinfo->rs_data = buf;
452
453 /* fill in the message */
454 rs = (struct nd_router_solicit *)buf;
455 rs->nd_rs_type = ND_ROUTER_SOLICIT;

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

475
476 gettimeofday(&now, NULL);
477
478 rtsol_timer = tm_max;
479
480 for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) {
481 if (TIMEVAL_LEQ(ifinfo->expire, now)) {
482 if (dflag > 1)
483 warnmsg(LOG_DEBUG, __FUNCTION__,
483 warnmsg(LOG_DEBUG, __func__,
484 "timer expiration on %s, "
485 "state = %d", ifinfo->ifname,
486 ifinfo->state);
487
488 switch (ifinfo->state) {
489 case IFS_DOWN:
490 case IFS_TENTATIVE:
491 /* interface_up returns 0 on success */

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

501 {
502 int oldstatus = ifinfo->active;
503 int probe = 0;
504
505 ifinfo->active =
506 interface_status(ifinfo);
507
508 if (oldstatus != ifinfo->active) {
484 "timer expiration on %s, "
485 "state = %d", ifinfo->ifname,
486 ifinfo->state);
487
488 switch (ifinfo->state) {
489 case IFS_DOWN:
490 case IFS_TENTATIVE:
491 /* interface_up returns 0 on success */

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

501 {
502 int oldstatus = ifinfo->active;
503 int probe = 0;
504
505 ifinfo->active =
506 interface_status(ifinfo);
507
508 if (oldstatus != ifinfo->active) {
509 warnmsg(LOG_DEBUG, __FUNCTION__,
509 warnmsg(LOG_DEBUG, __func__,
510 "%s status is changed"
511 " from %d to %d",
512 ifinfo->ifname,
513 oldstatus, ifinfo->active);
514 probe = 1;
515 ifinfo->state = IFS_DELAY;
516 }
517 else if (ifinfo->probeinterval &&

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

531 case IFS_DELAY:
532 ifinfo->state = IFS_PROBE;
533 sendpacket(ifinfo);
534 break;
535 case IFS_PROBE:
536 if (ifinfo->probes < MAX_RTR_SOLICITATIONS)
537 sendpacket(ifinfo);
538 else {
510 "%s status is changed"
511 " from %d to %d",
512 ifinfo->ifname,
513 oldstatus, ifinfo->active);
514 probe = 1;
515 ifinfo->state = IFS_DELAY;
516 }
517 else if (ifinfo->probeinterval &&

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

531 case IFS_DELAY:
532 ifinfo->state = IFS_PROBE;
533 sendpacket(ifinfo);
534 break;
535 case IFS_PROBE:
536 if (ifinfo->probes < MAX_RTR_SOLICITATIONS)
537 sendpacket(ifinfo);
538 else {
539 warnmsg(LOG_INFO, __FUNCTION__,
539 warnmsg(LOG_INFO, __func__,
540 "No answer "
541 "after sending %d RSs",
542 ifinfo->probes);
543 ifinfo->probes = 0;
544 ifinfo->state = IFS_IDLE;
545 }
546 break;
547 }
548 rtsol_timer_update(ifinfo);
549 }
550
551 if (TIMEVAL_LT(ifinfo->expire, rtsol_timer))
552 rtsol_timer = ifinfo->expire;
553 }
554
555 if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
540 "No answer "
541 "after sending %d RSs",
542 ifinfo->probes);
543 ifinfo->probes = 0;
544 ifinfo->state = IFS_IDLE;
545 }
546 break;
547 }
548 rtsol_timer_update(ifinfo);
549 }
550
551 if (TIMEVAL_LT(ifinfo->expire, rtsol_timer))
552 rtsol_timer = ifinfo->expire;
553 }
554
555 if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
556 warnmsg(LOG_DEBUG, __FUNCTION__, "there is no timer");
556 warnmsg(LOG_DEBUG, __func__, "there is no timer");
557 return(NULL);
558 }
559 else if (TIMEVAL_LT(rtsol_timer, now))
560 /* this may occur when the interval is too small */
561 returnval.tv_sec = returnval.tv_usec = 0;
562 else
563 TIMEVAL_SUB(&rtsol_timer, &now, &returnval);
564
565 if (dflag > 1)
557 return(NULL);
558 }
559 else if (TIMEVAL_LT(rtsol_timer, now))
560 /* this may occur when the interval is too small */
561 returnval.tv_sec = returnval.tv_usec = 0;
562 else
563 TIMEVAL_SUB(&rtsol_timer, &now, &returnval);
564
565 if (dflag > 1)
566 warnmsg(LOG_DEBUG, __FUNCTION__, "New timer is %ld:%08ld",
566 warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld",
567 (long)returnval.tv_sec, (long)returnval.tv_usec);
568
569 return(&returnval);
570}
571
572void
573rtsol_timer_update(struct ifinfo *ifinfo)
574{

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

616 * will be no more solicatation. Thus, we change
617 * the timer value to MAX_RTR_SOLICITATION_DELAY based
618 * on RFC 2461, Section 6.3.7.
619 */
620 ifinfo->timer.tv_sec = MAX_RTR_SOLICITATION_DELAY;
621 }
622 break;
623 default:
567 (long)returnval.tv_sec, (long)returnval.tv_usec);
568
569 return(&returnval);
570}
571
572void
573rtsol_timer_update(struct ifinfo *ifinfo)
574{

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

616 * will be no more solicatation. Thus, we change
617 * the timer value to MAX_RTR_SOLICITATION_DELAY based
618 * on RFC 2461, Section 6.3.7.
619 */
620 ifinfo->timer.tv_sec = MAX_RTR_SOLICITATION_DELAY;
621 }
622 break;
623 default:
624 warnmsg(LOG_ERR, __FUNCTION__,
624 warnmsg(LOG_ERR, __func__,
625 "illegal interface state(%d) on %s",
626 ifinfo->state, ifinfo->ifname);
627 return;
628 }
629
630 /* reset the timer */
631 if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
632 ifinfo->expire = tm_max;
625 "illegal interface state(%d) on %s",
626 ifinfo->state, ifinfo->ifname);
627 return;
628 }
629
630 /* reset the timer */
631 if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
632 ifinfo->expire = tm_max;
633 warnmsg(LOG_DEBUG, __FUNCTION__,
633 warnmsg(LOG_DEBUG, __func__,
634 "stop timer for %s", ifinfo->ifname);
635 }
636 else {
637 gettimeofday(&now, NULL);
638 TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
639
640 if (dflag > 1)
634 "stop timer for %s", ifinfo->ifname);
635 }
636 else {
637 gettimeofday(&now, NULL);
638 TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
639
640 if (dflag > 1)
641 warnmsg(LOG_DEBUG, __FUNCTION__,
641 warnmsg(LOG_DEBUG, __func__,
642 "set timer for %s to %d:%d", ifinfo->ifname,
643 (int)ifinfo->timer.tv_sec,
644 (int)ifinfo->timer.tv_usec);
645 }
646
647#undef MILLION
648}
649

--- 143 unchanged lines hidden ---
642 "set timer for %s to %d:%d", ifinfo->ifname,
643 (int)ifinfo->timer.tv_sec,
644 (int)ifinfo->timer.tv_usec);
645 }
646
647#undef MILLION
648}
649

--- 143 unchanged lines hidden ---