Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/route6d sync with the latest KAME tree.



details:   https://anonhg.NetBSD.org/src/rev/411b85b3a111
branches:  trunk
changeset: 514547:411b85b3a111
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Sep 05 01:17:31 2001 +0000

description:
sync with the latest KAME tree.
- don't use FD_SETSIZE on select
- "sin" conflicts with math library, so use sin6
- other minor updates

diffstat:

 usr.sbin/route6d/route6d.c |  290 ++++++++++++++++++++++++++------------------
 1 files changed, 173 insertions(+), 117 deletions(-)

diffs (truncated from 723 to 300 lines):

diff -r b8f7d1173166 -r 411b85b3a111 usr.sbin/route6d/route6d.c
--- a/usr.sbin/route6d/route6d.c        Tue Sep 04 21:47:31 2001 +0000
+++ b/usr.sbin/route6d/route6d.c        Wed Sep 05 01:17:31 2001 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: route6d.c,v 1.28 2001/06/13 04:31:52 itojun Exp $      */
-/*     $KAME: route6d.c,v 1.60 2001/03/08 02:15:42 onoe Exp $  */
+/*     $NetBSD: route6d.c,v 1.29 2001/09/05 01:17:31 itojun Exp $      */
+/*     $KAME: route6d.c,v 1.73 2001/09/05 01:12:34 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.28 2001/06/13 04:31:52 itojun Exp $");
+__RCSID("$NetBSD: route6d.c,v 1.29 2001/09/05 01:17:31 itojun Exp $");
 #endif
 
 #include <stdio.h>
@@ -143,6 +143,7 @@
 fd_set sockvec;        /* vector to select() for receiving */
 int    rtsock;         /* the routing socket */
 int    ripsock;        /* socket to send/receive RIP datagram */
+int    maxfd;          /* maximum fd for select() */
 
 struct rip6 *ripbuf;   /* packet buffer for sending */
 
@@ -433,6 +434,8 @@
        alarm(ripinterval(INIT_INTERVAL6));
 
        for (ifcp = ifc; ifcp; ifcp = ifcp->ifc_next) {
+               if (iff_find(ifcp, 'N'))
+                       continue;
                if (ifcp->ifc_index > 0 && (ifcp->ifc_flags & IFF_UP))
                        sendrequest(ifcp);
        }
@@ -461,7 +464,7 @@
 
                FD_COPY(&sockvec, &recvec);
                signo = 0;
-               switch (select(FD_SETSIZE, &recvec, 0, 0, 0)) {
+               switch (select(maxfd + 1, &recvec, 0, 0, 0)) {
                case -1:
                        if (errno != EINTR) {
                                fatal("select");
@@ -661,6 +664,7 @@
        memset(&sockvec, 0, sizeof(sockvec));
 #endif
        FD_SET(ripsock, &sockvec);
+       maxfd = ripsock;
 
        if (nflag == 0) {
                if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
@@ -668,6 +672,8 @@
                        /*NOTREACHED*/
                }
                FD_SET(rtsock, &sockvec);
+               if (rtsock > maxfd)
+                       maxfd = rtsock;
        } else
                rtsock = -1;    /*just for safety */
 }
@@ -682,9 +688,9 @@
 static struct netinfo6 *np;
 
 void
-ripflush(ifcp, sin)
+ripflush(ifcp, sin6)
        struct ifc *ifcp;
-       struct sockaddr_in6 *sin;
+       struct sockaddr_in6 *sin6;
 {
        int i;
        int error;
@@ -692,10 +698,10 @@
        if (ifcp)
                tracet(1, "Send(%s): info(%d) to %s.%d\n",
                        ifcp->ifc_name, nrt,
-                       inet6_n2p(&sin->sin6_addr), ntohs(sin->sin6_port));
+                       inet6_n2p(&sin6->sin6_addr), ntohs(sin6->sin6_port));
        else
                tracet(1, "Send: info(%d) to %s.%d\n",
-                       nrt, inet6_n2p(&sin->sin6_addr), ntohs(sin->sin6_port));
+                       nrt, inet6_n2p(&sin6->sin6_addr), ntohs(sin6->sin6_port));
        if (dflag >= 2) {
                np = ripbuf->rip6_nets;
                for (i = 0; i < nrt; i++, np++) {
@@ -718,7 +724,7 @@
                        trace(2, "\n");
                }
        }
-       error = sendpacket(sin, RIPSIZE(nrt));
+       error = sendpacket(sin6, RIPSIZE(nrt));
        if (error == EAFNOSUPPORT) {
                /* Protocol not supported */
                tracet(1, "Could not send info to %s (%s): "
@@ -733,9 +739,9 @@
  * Generate RIP6_RESPONSE packets and send them.
  */
 void
-ripsend(ifcp, sin, flag)
+ripsend(ifcp, sin6, flag)
        struct  ifc *ifcp;
-       struct  sockaddr_in6 *sin;
+       struct  sockaddr_in6 *sin6;
        int flag;
 {
        struct  riprt *rrt;
@@ -759,12 +765,12 @@
                        *np = rrt->rrt_info;
                        np++; nrt++;
                        if (nrt == maxrte) {
-                               ripflush(NULL, sin);
+                               ripflush(NULL, sin6);
                                nh = NULL;
                        }
                }
                if (nrt)        /* Send last packet */
-                       ripflush(NULL, sin);
+                       ripflush(NULL, sin6);
                return;
        }
 
@@ -783,11 +789,12 @@
                rrt_info.rip6_dest = in6addr_any;
                rrt_info.rip6_plen = 0;
                rrt_info.rip6_metric = 1;
+               rrt_info.rip6_metric += ifcp->ifc_metric;
                rrt_info.rip6_tag = htons(routetag & 0xffff);
                np = ripbuf->rip6_nets;
                *np = rrt_info;
                nrt = 1;
-               ripflush(ifcp, sin);
+               ripflush(ifcp, sin6);
                return;
        }
 
@@ -820,7 +827,7 @@
                    (rrt->rrt_rflags & RRTF_NH_NOT_LLADDR) == 0) {
                        if (nh == NULL || !IN6_ARE_ADDR_EQUAL(nh, &rrt->rrt_gw)) {
                                if (nrt == maxrte - 2)
-                                       ripflush(ifcp, sin);
+                                       ripflush(ifcp, sin6);
                                np->rip6_dest = rrt->rrt_gw;
                                if (IN6_IS_ADDR_LINKLOCAL(&np->rip6_dest))
                                        SET_IN6_LINKLOCAL_IFINDEX(np->rip6_dest, 0);
@@ -835,7 +842,7 @@
                                  rrt->rrt_rflags & RRTF_NH_NOT_LLADDR)) {
                        /* Reset nexthop */
                        if (nrt == maxrte - 2)
-                               ripflush(ifcp, sin);
+                               ripflush(ifcp, sin6);
                        memset(np, 0, sizeof(struct netinfo6));
                        np->rip6_metric = NEXTHOP_METRIC;
                        nh = NULL;
@@ -846,12 +853,12 @@
                *np = rrt->rrt_info;
                np++; nrt++;
                if (nrt == maxrte) {
-                       ripflush(ifcp, sin);
+                       ripflush(ifcp, sin6);
                        nh = NULL;
                }
        }
        if (nrt)        /* Send last packet */
-               ripflush(ifcp, sin);
+               ripflush(ifcp, sin6);
 }
 
 /*
@@ -958,8 +965,8 @@
  * Send a rip packet actually.
  */
 int
-sendpacket(sin, len)
-       struct  sockaddr_in6 *sin;
+sendpacket(sin6, len)
+       struct  sockaddr_in6 *sin6;
        int     len;
 {
        /*
@@ -976,18 +983,18 @@
        struct sockaddr_in6 sincopy;
 
        /* do not overwrite the given sin */
-       sincopy = *sin;
-       sin = &sincopy;
+       sincopy = *sin6;
+       sin6 = &sincopy;
 
-       if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)
-        || IN6_IS_ADDR_MULTICAST(&sin->sin6_addr)) {
-               idx = IN6_LINKLOCAL_IFINDEX(sin->sin6_addr);
-               SET_IN6_LINKLOCAL_IFINDEX(sin->sin6_addr, 0);
+       if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)
+        || IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
+               idx = IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr);
+               SET_IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr, 0);
        } else
                idx = 0;
 
-       m.msg_name = (caddr_t)sin;
-       m.msg_namelen = sizeof(*sin);
+       m.msg_name = (caddr_t)sin6;
+       m.msg_namelen = sizeof(*sin6);
        iov[0].iov_base = (caddr_t)ripbuf;
        iov[0].iov_len = len;
        m.msg_iov = iov;
@@ -1334,11 +1341,11 @@
  * Process a RIP6_REQUEST packet.
  */
 void
-riprequest(ifcp, np, nn, sin)
+riprequest(ifcp, np, nn, sin6)
        struct ifc *ifcp;
        struct netinfo6 *np;
        int nn;
-       struct sockaddr_in6 *sin;
+       struct sockaddr_in6 *sin6;
 {
        int i;
        struct riprt *rrt;
@@ -1354,12 +1361,12 @@
                        else
                                np->rip6_metric = HOPCNT_INFINITY6;
                }
-               (void)sendpacket(sin, RIPSIZE(nn));
+               (void)sendpacket(sin6, RIPSIZE(nn));
                return;
        }
        /* Whole routing table dump */
        trace(1, "\tRIP Request -- whole routing table\n");
-       ripsend(ifcp, sin, RRTF_SENDANYWAY);
+       ripsend(ifcp, sin6, RRTF_SENDANYWAY);
 }
 
 /*
@@ -1445,20 +1452,22 @@
        int     s;
 {
        struct  in6_ifreq ifr;
-       const struct sockaddr_in6 *sin;
+       const struct sockaddr_in6 *sin6;
        struct  ifac *ifa;
        int     plen;
        char    buf[BUFSIZ];
 
-       sin = (const struct sockaddr_in6 *)sa;
-       ifr.ifr_addr = *sin;
+       sin6 = (const struct sockaddr_in6 *)sa;
+       if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) && !lflag)
+               return;
+       ifr.ifr_addr = *sin6;
        strcpy(ifr.ifr_name, name);
        if (ioctl(s, SIOCGIFNETMASK_IN6, (char *)&ifr) < 0) {
                fatal("ioctl: SIOCGIFNETMASK_IN6");
                /*NOTREACHED*/
        }
        plen = sin6mask2len(&ifr.ifr_addr);
-       if ((ifa = ifa_match(ifcp, &sin->sin6_addr, plen)) != NULL) {
+       if ((ifa = ifa_match(ifcp, &sin6->sin6_addr, plen)) != NULL) {
                /* same interface found */
                /* need check if something changed */
                /* XXX not yet implemented */
@@ -1475,10 +1484,10 @@
        ifa->ifa_conf = ifcp;
        ifa->ifa_next = ifcp->ifc_addr;
        ifcp->ifc_addr = ifa;
-       ifa->ifa_addr = sin->sin6_addr;
+       ifa->ifa_addr = sin6->sin6_addr;
        ifa->ifa_plen = plen;
        if (ifcp->ifc_flags & IFF_POINTOPOINT) {
-               ifr.ifr_addr = *sin;
+               ifr.ifr_addr = *sin6;
                if (ioctl(s, SIOCGIFDSTADDR_IN6, (char *)&ifr) < 0) {
                        fatal("ioctl: SIOCGIFDSTADDR_IN6");
                        /*NOTREACHED*/
@@ -1508,7 +1517,8 @@
                ifcp->ifc_metric = ifr.ifr_metric;
                trace(1, "\tindex: %d, mtu: %d, metric: %d\n",
                        ifcp->ifc_index, ifcp->ifc_mtu, ifcp->ifc_metric);
-       }
+       } else
+               ifcp->ifc_cflags |= IFC_CHANGED;
 }
 
 /*
@@ -1527,6 +1537,7 @@
        struct ifc *ifcp, *ic;
        int iface = 0, rtable = 0;
        struct sockaddr_in6 *rta[RTAX_MAX];
+       struct sockaddr_in6 mask;
        int i, addrs;
        struct riprt *rrt;
 
@@ -1539,6 +1550,14 @@
                        len, (u_long)sizeof(*rtm));
                return;
        }



Home | Main Index | Thread Index | Old Index