Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/route6d use getifaddrs. avoid "extern int errno".



details:   https://anonhg.NetBSD.org/src/rev/c823bba244f5
branches:  trunk
changeset: 482915:c823bba244f5
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Feb 25 06:22:05 2000 +0000

description:
use getifaddrs.  avoid "extern int errno".
(sync with latest kame code)

diffstat:

 usr.sbin/route6d/Makefile  |    5 +-
 usr.sbin/route6d/route6d.8 |    5 +-
 usr.sbin/route6d/route6d.c |  104 ++++++++++++++++++++++++++++++++++++++------
 usr.sbin/route6d/route6d.h |    7 +--
 4 files changed, 97 insertions(+), 24 deletions(-)

diffs (263 lines):

diff -r 1830231aa927 -r c823bba244f5 usr.sbin/route6d/Makefile
--- a/usr.sbin/route6d/Makefile Fri Feb 25 05:28:42 2000 +0000
+++ b/usr.sbin/route6d/Makefile Fri Feb 25 06:22:05 2000 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: Makefile,v 1.1 1999/07/02 11:47:12 itojun Exp $
+# $NetBSD: Makefile,v 1.2 2000/02/25 06:22:05 itojun Exp $
 
 PROG=  route6d
 MAN=   route6d.8
 
-CPPFLAGS+=     -Dss_len=__ss_len -Dss_family=__ss_family -DADVAPI -DINET6
+CPPFLAGS+=-Dss_len=__ss_len -Dss_family=__ss_family -DADVAPI -DINET6 \
+       -DHAVE_GETIFADDRS
 
 .include <bsd.prog.mk>
diff -r 1830231aa927 -r c823bba244f5 usr.sbin/route6d/route6d.8
--- a/usr.sbin/route6d/route6d.8        Fri Feb 25 05:28:42 2000 +0000
+++ b/usr.sbin/route6d/route6d.8        Fri Feb 25 06:22:05 2000 +0000
@@ -1,3 +1,6 @@
+.\"    $NetBSD: route6d.8,v 1.5 2000/02/25 06:22:05 itojun Exp $
+.\"    $KAME: route6d.8,v 1.5 2000/02/25 06:15:05 itojun Exp $
+.\"
 .\" Copyright (c) 1996 WIDE Project. All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -12,8 +15,6 @@
 .\" LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 .\" A PARTICULAR PURPOSE.
 .\"
-.\"    $NetBSD: route6d.8,v 1.4 1999/12/16 05:55:54 itojun Exp $
-.\"
 .Dd January 31, 1997
 .Dt ROUTE6D 8
 .Os
diff -r 1830231aa927 -r c823bba244f5 usr.sbin/route6d/route6d.c
--- a/usr.sbin/route6d/route6d.c        Fri Feb 25 05:28:42 2000 +0000
+++ b/usr.sbin/route6d/route6d.c        Fri Feb 25 06:22:05 2000 +0000
@@ -1,6 +1,4 @@
-/*
- * KAME Header: /cvsroot/kame/kame/kame/kame/route6d/route6d.c,v 1.6 1999/09/10 08:20:59 itojun Exp
- */
+/*     $KAME: route6d.c,v 1.14 2000/02/25 06:15:57 itojun Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -33,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef        lint
-__RCSID("$NetBSD: route6d.c,v 1.9 1999/09/13 11:07:52 itojun Exp $");
+__RCSID("$NetBSD: route6d.c,v 1.10 2000/02/25 06:22:05 itojun Exp $");
 #endif
 
 #include <stdio.h>
@@ -50,6 +48,7 @@
 #endif
 #include <syslog.h>
 #include <stddef.h>
+#include <errno.h>
 #include <err.h>
 
 #include <sys/types.h>
@@ -58,7 +57,6 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/sysctl.h>
-#include <sys/errno.h>
 #ifdef ADVAPI
 #include <sys/uio.h>
 #endif
@@ -67,13 +65,18 @@
 #include <net/if_var.h>
 #endif /* __FreeBSD__ >= 3 */
 #define        KERNEL  1
+#define        _KERNEL 1
 #include <net/route.h>
 #undef KERNEL
+#undef _KERNEL
 #include <netinet/in.h>
 #include <netinet/in_var.h>
 #include <netinet/ip6.h>
 #include <netinet/udp.h>
 #include <netdb.h>
+#ifdef HAVE_GETIFADDRS
+#include <ifaddrs.h>
+#endif
 
 #include <arpa/inet.h>
 
@@ -206,8 +209,6 @@
 #define        RTF_CHANGED             0x80000000
 #define        RTF_ROUTE_H             0xffff
 
-extern int errno;
-
 int main __P((int, char **));
 void ripalarm __P((int));
 void riprecv __P((void));
@@ -215,7 +216,7 @@
 void init __P((void));
 void sockopt __P((struct ifc *));
 void ifconfig __P((void));
-void ifconfig1 __P((struct ifreq *, struct ifc *, int));
+void ifconfig1 __P((const char *, const struct sockaddr *, struct ifc *, int));
 void rtrecv __P((void));
 int rt_del __P((const struct sockaddr_in6 *, const struct sockaddr_in6 *,
        const struct sockaddr_in6 *));
@@ -545,8 +546,15 @@
                fatal("rip IPV6_MULTICAST_LOOP");
 #ifdef ADVAPI
        i = 1;
-       if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_PKTINFO, &i, sizeof(i)) < 0)
+#ifdef IPV6_RECVPKTINFO
+       if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &i,
+                      sizeof(i)) < 0)
+               fatal("rip IPV6_RECVPKTINFO");
+#else  /* old adv. API */
+       if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_PKTINFO, &i,
+                      sizeof(i)) < 0)
                fatal("rip IPV6_PKTINFO");
+#endif 
 #endif /*ADVAPI*/
 
        memset(&hints, 0, sizeof(hints));
@@ -1204,6 +1212,65 @@
 void
 ifconfig()
 {
+#ifdef HAVE_GETIFADDRS
+       struct ifaddrs *ifap, *ifa;
+       struct ifc *ifcp;
+       struct ipv6_mreq mreq;
+       int s;
+
+       if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+               fatal("socket");
+
+       if (getifaddrs(&ifap) != 0)
+               fatal("getifaddrs");
+
+       for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+               if (ifa->ifa_addr->sa_family != AF_INET6)
+                       continue;
+               ifcp = ifc_find(ifa->ifa_name);
+               /* we are interested in multicast-capable interfaces */
+               if ((ifa->ifa_flags & IFF_MULTICAST) == 0)
+                       continue;
+               if (!ifcp) {
+                       /* new interface */
+                       ifcp = (struct ifc *)malloc(sizeof(*ifcp));
+                       memset(ifcp, 0, sizeof(*ifcp));
+                       ifcp->ifc_index = -1;
+                       ifcp->ifc_next = ifc;
+                       ifc = ifcp;
+                       nifc++;
+                       ifcp->ifc_name = allocopy(ifa->ifa_name);
+                       ifcp->ifc_addr = 0;
+                       ifcp->ifc_filter = 0;
+                       ifcp->ifc_flags = ifa->ifa_flags;
+                       trace(1, "newif %s <%s>\n", ifcp->ifc_name,
+                               ifflags(ifcp->ifc_flags));
+                       if (!strcmp(ifcp->ifc_name, LOOPBACK_IF))
+                               loopifcp = ifcp;
+               } else {
+                       /* update flag, this may be up again */
+                       if (ifcp->ifc_flags != ifa->ifa_flags) {
+                               trace(1, "%s: <%s> -> ", ifcp->ifc_name,
+                                       ifflags(ifcp->ifc_flags));
+                               trace(1, "<%s>\n", ifflags(ifa->ifa_flags));
+                       }
+                       ifcp->ifc_flags = ifa->ifa_flags;
+               }
+               ifconfig1(ifa->ifa_name, ifa->ifa_addr, ifcp, s);
+               if ((ifcp->ifc_flags & (IFF_LOOPBACK | IFF_UP)) == IFF_UP
+                && 0 < ifcp->ifc_index && !ifcp->ifc_joined) {
+                       mreq.ipv6mr_multiaddr = ifcp->ifc_ripsin.sin6_addr;
+                       mreq.ipv6mr_interface = ifcp->ifc_index;
+                       if (setsockopt(ripsock, IPPROTO_IPV6,
+                               IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0)
+                               fatal("IPV6_JOIN_GROUP");
+                       trace(1, "join %s %s\n", ifcp->ifc_name, RIP6_DEST);
+                       ifcp->ifc_joined++;
+               }
+       }
+       close(s);
+       freeifaddrs(ifap);
+#else
        int     s, i;
        char    *buf;
        struct  ifconf ifconf;
@@ -1231,6 +1298,8 @@
                fatal("ioctl: SIOCGIFCONF");
        i = ifconf.ifc_len;
        while (1) {
+               char *newbuf;
+
                ifconf.ifc_buf = buf;
                ifconf.ifc_len = bufsiz;
                if (ioctl(s, SIOCGIFCONF, (char *)&ifconf) < 0)
@@ -1239,8 +1308,11 @@
                        break;
                i = ifconf.ifc_len;
                bufsiz *= 2;
-               if ((buf = (char *)realloc(buf, bufsiz)) == NULL)
+               if ((newbuf = (char *)realloc(buf, bufsiz)) == NULL) {
+                       free(buf);
                        fatal("realloc");
+               }
+               buf = newbuf;
        }
        for (i = 0; i < ifconf.ifc_len; ) {
                ifrp = (struct ifreq *)(buf + i);
@@ -1278,7 +1350,7 @@
                        }
                        ifcp->ifc_flags = ifr.ifr_flags;
                }
-               ifconfig1(ifrp, ifcp, s);
+               ifconfig1(ifrp->ifr_name, &ifrp->ifr_addr, ifcp, s);
                if ((ifcp->ifc_flags & (IFF_LOOPBACK | IFF_UP)) == IFF_UP
                 && 0 < ifcp->ifc_index && !ifcp->ifc_joined) {
                        mreq.ipv6mr_multiaddr = ifcp->ifc_ripsin.sin6_addr;
@@ -1298,11 +1370,13 @@
        }
        close(s);
        free(buf);
+#endif
 }
 
 void
-ifconfig1(ifrp, ifcp, s)
-       struct  ifreq *ifrp;
+ifconfig1(name, sa, ifcp, s)
+       const char *name;
+       const struct sockaddr *sa;
        struct  ifc *ifcp;
        int     s;
 {
@@ -1312,9 +1386,9 @@
        int     plen;
        char    buf[BUFSIZ];
 
-       sin = (struct sockaddr_in6 *)&ifrp->ifr_addr;
+       sin = (struct sockaddr_in6 *)sa;
        ifr.ifr_addr = *sin;
-       strcpy(ifr.ifr_name, ifrp->ifr_name);
+       strcpy(ifr.ifr_name, name);
        if (ioctl(s, SIOCGIFNETMASK_IN6, (char *)&ifr) < 0)
                fatal("ioctl: SIOCGIFNETMASK_IN6");
        plen = mask2len(&ifr.ifr_addr.sin6_addr, 16);
diff -r 1830231aa927 -r c823bba244f5 usr.sbin/route6d/route6d.h
--- a/usr.sbin/route6d/route6d.h        Fri Feb 25 05:28:42 2000 +0000
+++ b/usr.sbin/route6d/route6d.h        Fri Feb 25 06:22:05 2000 +0000
@@ -1,8 +1,5 @@
-/*     $NetBSD: route6d.h,v 1.4 1999/12/16 05:55:54 itojun Exp $       */
-
-/*
- * KAME Header: /cvsroot/kame/kame/kame/kame/route6d/route6d.h,v 1.2 1999/12/16 05:38:44 jinmei Exp
- */
+/*     $NetBSD: route6d.h,v 1.5 2000/02/25 06:22:05 itojun Exp $       */
+/*     $KAME: route6d.h,v 1.3 2000/02/25 06:15:06 itojun Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.



Home | Main Index | Thread Index | Old Index