Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/route6d bring in latest kame code.



details:   https://anonhg.NetBSD.org/src/rev/c2e68b3c561b
branches:  trunk
changeset: 503499:c2e68b3c561b
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Feb 07 13:46:04 2001 +0000

description:
bring in latest kame code.
- correct RTA_NETMASK processing
- correct -A filter behavior (do not advert aggregated route to other if)
- better signal handling
- mandate getifaddrs
- do not advert connected routes on !IFF_UP routes.  experimental
sync with kame

diffstat:

 usr.sbin/route6d/Makefile  |    4 +-
 usr.sbin/route6d/route6d.c |  678 +++++++++++++++++++++++++-------------------
 usr.sbin/route6d/route6d.h |    6 +-
 3 files changed, 390 insertions(+), 298 deletions(-)

diffs (truncated from 1367 to 300 lines):

diff -r f8888cbc8384 -r c2e68b3c561b usr.sbin/route6d/Makefile
--- a/usr.sbin/route6d/Makefile Wed Feb 07 13:36:04 2001 +0000
+++ b/usr.sbin/route6d/Makefile Wed Feb 07 13:46:04 2001 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.3 2000/07/15 04:55:40 itojun Exp $
+# $NetBSD: Makefile,v 1.4 2001/02/07 13:46:04 itojun Exp $
 
 PROG=  route6d
 MAN=   route6d.8
 
-CPPFLAGS+=-Dss_len=__ss_len -Dss_family=__ss_family -DINET6 -DHAVE_GETIFADDRS
+CPPFLAGS+=-Dss_len=__ss_len -Dss_family=__ss_family -DINET6
 
 .include <bsd.prog.mk>
diff -r f8888cbc8384 -r c2e68b3c561b usr.sbin/route6d/route6d.c
--- a/usr.sbin/route6d/route6d.c        Wed Feb 07 13:36:04 2001 +0000
+++ b/usr.sbin/route6d/route6d.c        Wed Feb 07 13:46:04 2001 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: route6d.c,v 1.23 2001/02/07 13:24:42 pk Exp $  */
-/*     $KAME: route6d.c,v 1.41 2001/01/12 17:48:02 itojun Exp $        */
+/*     $NetBSD: route6d.c,v 1.24 2001/02/07 13:46:04 itojun Exp $      */
+/*     $KAME: route6d.c,v 1.58 2001/02/07 13:42:02 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.23 2001/02/07 13:24:42 pk Exp $");
+__RCSID("$NetBSD: route6d.c,v 1.24 2001/02/07 13:46:04 itojun Exp $");
 #endif
 
 #include <stdio.h>
@@ -73,9 +73,7 @@
 #include <netinet/ip6.h>
 #include <netinet/udp.h>
 #include <netdb.h>
-#ifdef HAVE_GETIFADDRS
 #include <ifaddrs.h>
-#endif
 
 #include <arpa/inet.h>
 
@@ -112,7 +110,8 @@
        int     ifc_index;                      /* if index */
        int     ifc_mtu;                        /* if mtu */
        int     ifc_metric;                     /* if metric */
-       short   ifc_flags;                      /* flags */
+       u_int   ifc_flags;                      /* flags */
+       short   ifc_cflags;                     /* IFC_XXX */
        struct  in6_addr ifc_mylladdr;          /* my link-local address */
        struct  sockaddr_in6 ifc_ripsin;        /* rip multicast address */
        struct  iff *ifc_filter;                /* filter structure */
@@ -148,13 +147,13 @@
 struct rip6 *ripbuf;   /* packet buffer for sending */
 
 /*
- * Maintain the routes in a linked list. When the number of the routes
+ * Maintain the routes in a linked list.  When the number of the routes
  * grows, somebody would like to introduce a hash based or a radix tree
- * based strucutre. I believe the number of routes handled by RIP is
+ * based structure.  I believe the number of routes handled by RIP is
  * limited and I don't have to manage a complex data structure, however.
  *
  * One of the major drawbacks of the linear linked list is the difficulty
- * of representing the relationship between a couple of routes. This may
+ * of representing the relationship between a couple of routes.  This may
  * be a significant problem when we have to support route aggregation with
  * supressing the specifices covered by the aggregate.
  */
@@ -203,6 +202,9 @@
 static u_long  seq = 0;
 
 volatile int signo;
+volatile sig_atomic_t seenalrm;
+volatile sig_atomic_t seenquit;
+volatile sig_atomic_t seenusr1;
 
 #define        RRTF_AGGREGATE          0x08000000
 #define        RRTF_NOADVERTISE        0x10000000
@@ -212,9 +214,10 @@
 
 int main __P((int, char **));
 void sighandler __P((int));
-void ripalarm __P((int));
+void ripalarm __P((void));
 void riprecv __P((void));
 void ripsend __P((struct ifc *, struct sockaddr_in6 *, int));
+int out_filter __P((struct riprt *, struct ifc *));
 void init __P((void));
 void sockopt __P((struct ifc *));
 void ifconfig __P((void));
@@ -226,10 +229,10 @@
        const struct sockaddr_in6 *));
 void filterconfig __P((void));
 int getifmtu __P((int));
-const char *rttypes __P((struct rt_msghdr *rtm));
-const char *rtflags __P((struct rt_msghdr *rtm));
-const char *ifflags __P((int flags));
-void ifrt __P((struct ifc *, int));
+const char *rttypes __P((struct rt_msghdr *));
+const char *rtflags __P((struct rt_msghdr *));
+const char *ifflags __P((int));
+int ifrt __P((struct ifc *, int));
 void ifrt_p2p __P((struct ifc *, int));
 void applymask __P((struct in6_addr *, struct in6_addr *));
 void applyplen __P((struct in6_addr *, int));
@@ -238,10 +241,12 @@
 void ifdump0 __P((FILE *, const struct ifc *));
 void rtdump __P((int));
 void rt_entry __P((struct rt_msghdr *, int));
-void rtdexit __P((int));
-void riprequest __P((struct ifc *, struct netinfo6 *, int, struct sockaddr_in6 *));
+void rtdexit __P((void));
+void riprequest __P((struct ifc *, struct netinfo6 *, int,
+       struct sockaddr_in6 *));
 void ripflush __P((struct ifc *, struct sockaddr_in6 *));
 void sendrequest __P((struct ifc *));
+int sin6mask2len __P((const struct sockaddr_in6 *));
 int mask2len __P((const struct in6_addr *, int));
 int sendpacket __P((struct sockaddr_in6 *, int));
 int addroute __P((struct riprt *, const struct in6_addr *, struct ifc *));
@@ -254,7 +259,7 @@
 const char *inet6_n2p __P((const struct in6_addr *));
 struct ifac *ifa_match __P((const struct ifc *, const struct in6_addr *, int));
 struct in6_addr *plen2mask __P((int));
-struct riprt *rtsearch __P((struct netinfo6 *));
+struct riprt *rtsearch __P((struct netinfo6 *, struct riprt **));
 int ripinterval __P((int));
 time_t ripsuptrig __P((void));
 void fatal __P((const char *, ...))
@@ -347,6 +352,15 @@
        }
        openlog(progname, LOG_NDELAY|LOG_PID, LOG_DAEMON);
        logopened++;
+
+       if ((ripbuf = (struct rip6 *)malloc(RIP6_MAXMTU)) == NULL)
+               fatal("malloc");
+       memset(ripbuf, 0, RIP6_MAXMTU);
+       ripbuf->rip6_cmd = RIP6_RESPONSE;
+       ripbuf->rip6_vers = RIP6_VERSION;
+       ripbuf->rip6_res1[0] = 0;
+       ripbuf->rip6_res1[1] = 0;
+
        init();
        ifconfig();
        for (ifcp = ifc; ifcp; ifcp = ifcp->ifc_next) {
@@ -429,6 +443,22 @@
        while (1) {
                fd_set  recvec;
 
+               if (seenalrm) {
+                       ripalarm();
+                       seenalrm = 0;
+                       continue;
+               }
+               if (seenquit) {
+                       rtdexit();
+                       seenquit = 0;
+                       continue;
+               }
+               if (seenusr1) {
+                       ifrtdump(SIGUSR1);
+                       seenusr1 = 0;
+                       continue;
+               }
+
                FD_COPY(&sockvec, &recvec);
                signo = 0;
                switch (select(FD_SETSIZE, &recvec, 0, 0, 0)) {
@@ -437,20 +467,6 @@
                                fatal("select");
                                /*NOTREACHED*/
                        }
-                       switch (signo) {
-                       case SIGALRM:
-                               ripalarm(signo);
-                               break;
-                       case SIGQUIT:
-                       case SIGTERM:
-                               rtdexit(signo);
-                               break;
-                       case SIGUSR1:
-                       case SIGHUP:
-                       case SIGINT:
-                               ifrtdump(signo);
-                               break;
-                       }
                        continue;
                case 0:
                        continue;
@@ -473,7 +489,22 @@
 sighandler(sig)
        int sig;
 {
+
        signo = sig;
+       switch (signo) {
+       case SIGALRM:
+               seenalrm++;
+               break;
+       case SIGQUIT:
+       case SIGTERM:
+               seenquit++;
+               break;
+       case SIGUSR1:
+       case SIGHUP:
+       case SIGINT:
+               seenusr1++;
+               break;
+       }
 }
 
 /*
@@ -481,8 +512,7 @@
  */
 /* ARGSUSED */
 void
-rtdexit(sig)
-       int sig;
+rtdexit()
 {
        struct  riprt *rrt;
 
@@ -503,14 +533,13 @@
  * Called periodically:
  *     1. age out the learned route. remove it if necessary.
  *     2. submit RIP6_RESPONSE packets.
- * Invoked in every SUPPLY_INTERVAL6 (30) seconds. I believe we don't have
+ * Invoked in every SUPPLY_INTERVAL6 (30) seconds.  I believe we don't have
  * to invoke this function in every 1 or 5 or 10 seconds only to age the
  * routes more precisely.
  */
 /* ARGSUSED */
 void
-ripalarm(sig)
-       int sig;
+ripalarm()
 {
        struct  ifc *ifcp;
        struct  riprt *rrt, *rrt_prev, *rrt_next;
@@ -711,9 +740,7 @@
 {
        struct  riprt *rrt;
        struct  in6_addr *nh;   /* next hop */
-       struct  in6_addr ia;
-       struct  iff *iffp;
-       int     maxrte, ok;
+       int     maxrte;
 
        if (ifcp == NULL) {
                /*
@@ -744,8 +771,12 @@
        if ((flag & RRTF_SENDANYWAY) == 0 &&
            (qflag || (ifcp->ifc_flags & IFF_LOOPBACK)))
                return;
+
+       /* -N: no use */
        if (iff_find(ifcp, 'N') != NULL)
                return;
+
+       /* -T: generate default route only */
        if (iff_find(ifcp, 'T') != NULL) {
                struct netinfo6 rrt_info;
                memset(&rrt_info, 0, sizeof(struct netinfo6));
@@ -759,52 +790,30 @@
                ripflush(ifcp, sin);
                return;
        }
+
        maxrte = (ifcp->ifc_mtu - sizeof(struct ip6_hdr) - 
                        sizeof(struct udphdr) - 
                        sizeof(struct rip6) + sizeof(struct netinfo6)) /
                        sizeof(struct netinfo6);
+
        nrt = 0; np = ripbuf->rip6_nets; nh = NULL;
        for (rrt = riprt; rrt; rrt = rrt->rrt_next) {
                if (rrt->rrt_rflags & RRTF_NOADVERTISE)
                        continue;
-               /* Need to check filer here */
-               ok = 1;
-               for (iffp = ifcp->ifc_filter; iffp; iffp = iffp->iff_next) {
-                       if (iffp->iff_type != 'A')
-                               continue;
-                       if (rrt->rrt_info.rip6_plen <= iffp->iff_plen)
-                               continue;
-                       ia = rrt->rrt_info.rip6_dest; 
-                       applyplen(&ia, iffp->iff_plen);
-                       if (IN6_ARE_ADDR_EQUAL(&ia, &iffp->iff_addr)) {
-                               ok = 0;
-                               break;
-                       }
-               }
-               if (!ok)
+
+               /* Need to check filter here */
+               if (out_filter(rrt, ifcp) == 0)
                        continue;
-               for (iffp = ifcp->ifc_filter; iffp; iffp = iffp->iff_next) {



Home | Main Index | Thread Index | Old Index