avoid fd_set overrun. sync w/kame

This commit is contained in:
itojun 2002-06-07 16:45:30 +00:00
parent ac03214470
commit f78cc67c13
3 changed files with 31 additions and 22 deletions

View File

@ -1,5 +1,5 @@
.\" $NetBSD: route6d.8,v 1.9 2002/06/02 14:56:47 wiz Exp $
.\" $KAME: route6d.8,v 1.8 2000/05/31 17:00:09 itojun Exp $
.\" $NetBSD: route6d.8,v 1.10 2002/06/07 16:45:30 itojun Exp $
.\" $KAME: route6d.8,v 1.11 2002/06/02 15:00:30 itojun Exp $
.\"
.\" Copyright (c) 1996 WIDE Project. All rights reserved.
.\"
@ -22,7 +22,7 @@
.Nd RIP6 routing daemon
.Sh SYNOPSIS
.Nm route6d
.Op Fl adDhlqsS
.Op Fl adDhlnqsS
.Bk -words
.Op Fl R Ar routelog
.Ek
@ -146,6 +146,9 @@ For example, with
will accept the default route and routes in the 6bone test address range,
but no others.
.\"
.It Fl n
Do not update the kernel routing table.
.\"
.It Fl N Ar if1[,if2...]
Do not listen to, or advertise, route from/to interfaces specified by
.Ar if1,[if2...] .

View File

@ -1,5 +1,5 @@
/* $NetBSD: route6d.c,v 1.33 2002/05/29 23:11:13 itojun Exp $ */
/* $KAME: route6d.c,v 1.83 2002/05/29 23:07:33 itojun Exp $ */
/* $NetBSD: route6d.c,v 1.34 2002/06/07 16:45:30 itojun Exp $ */
/* $KAME: route6d.c,v 1.85 2002/06/07 16:39:41 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: route6d.c,v 1.33 2002/05/29 23:11:13 itojun Exp $");
__RCSID("$NetBSD: route6d.c,v 1.34 2002/06/07 16:45:30 itojun Exp $");
#endif
#include <stdio.h>
@ -140,7 +140,9 @@ int nifc; /* number of valid ifc's */
struct ifc **index2ifc;
int nindex2ifc;
struct ifc *loopifcp = NULL; /* pointing to loopback */
fd_set sockvec; /* vector to select() for receiving */
fd_set *sockvecp; /* vector to select() for receiving */
fd_set *recvecp;
int fdmasks;
int rtsock; /* the routing socket */
int ripsock; /* socket to send/receive RIP datagram */
int maxfd; /* maximum fd for select() */
@ -430,8 +432,6 @@ main(argc, argv)
sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
while (1) {
fd_set recvec;
if (seenalrm) {
ripalarm();
seenalrm = 0;
@ -448,8 +448,8 @@ main(argc, argv)
continue;
}
FD_COPY(&sockvec, &recvec);
switch (select(maxfd + 1, &recvec, 0, 0, 0)) {
memcpy(recvecp, sockvecp, fdmasks);
switch (select(maxfd + 1, recvecp, 0, 0, 0)) {
case -1:
if (errno != EINTR) {
fatal("select");
@ -459,12 +459,12 @@ main(argc, argv)
case 0:
continue;
default:
if (FD_ISSET(ripsock, &recvec)) {
if (FD_ISSET(ripsock, recvecp)) {
sigprocmask(SIG_BLOCK, &mask, &omask);
riprecv();
sigprocmask(SIG_SETMASK, &omask, NULL);
}
if (FD_ISSET(rtsock, &recvec)) {
if (FD_ISSET(rtsock, recvecp)) {
sigprocmask(SIG_BLOCK, &mask, &omask);
rtrecv();
sigprocmask(SIG_SETMASK, &omask, NULL);
@ -642,12 +642,6 @@ init()
}
memcpy(&ripsin, res->ai_addr, res->ai_addrlen);
#ifdef FD_ZERO
FD_ZERO(&sockvec);
#else
memset(&sockvec, 0, sizeof(sockvec));
#endif
FD_SET(ripsock, &sockvec);
maxfd = ripsock;
if (nflag == 0) {
@ -655,11 +649,24 @@ init()
fatal("route socket");
/*NOTREACHED*/
}
FD_SET(rtsock, &sockvec);
if (rtsock > maxfd)
maxfd = rtsock;
} else
rtsock = -1; /*just for safety */
fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask);
if ((sockvecp = malloc(fdmasks)) == NULL) {
fatal("malloc");
/*NOTREACHED*/
}
if ((recvecp = malloc(fdmasks)) == NULL) {
fatal("malloc");
/*NOTREACHED*/
}
memset(sockvecp, 0, fdmasks);
FD_SET(ripsock, sockvecp);
if (rtsock >= 0)
FD_SET(rtsock, sockvecp);
}
#define RIPSIZE(n) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: route6d.h,v 1.6 2001/02/07 13:46:04 itojun Exp $ */
/* $NetBSD: route6d.h,v 1.7 2002/06/07 16:45:30 itojun Exp $ */
/* $KAME: route6d.h,v 1.4 2001/01/15 03:50:54 inoue Exp $ */
/*
@ -35,7 +35,6 @@
*/
#define ROUTE6D_DUMP "/var/run/route6d_dump"
#define ROUTE6D_PID "/var/run/route6d.pid"
#define RIP6_VERSION 1