Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/pim6sd bring in from latest kame tree. use getifad...



details:   https://anonhg.NetBSD.org/src/rev/c56ff66ce4c6
branches:  trunk
changeset: 482916:c56ff66ce4c6
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Feb 25 06:27:32 2000 +0000

description:
bring in from latest kame tree.  use getifaddrs, not SIOCGIFCONF.

diffstat:

 usr.sbin/pim6sd/Makefile |     4 +-
 usr.sbin/pim6sd/config.c |  1436 +++++----------------------------------------
 2 files changed, 163 insertions(+), 1277 deletions(-)

diffs (truncated from 1500 to 300 lines):

diff -r c823bba244f5 -r c56ff66ce4c6 usr.sbin/pim6sd/Makefile
--- a/usr.sbin/pim6sd/Makefile  Fri Feb 25 06:22:05 2000 +0000
+++ b/usr.sbin/pim6sd/Makefile  Fri Feb 25 06:27:32 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2000/01/28 19:32:45 itojun Exp $
+# $NetBSD: Makefile,v 1.2 2000/02/25 06:27:32 itojun Exp $
 
 PROG=  pim6sd
 SRCS=  mld6.c mld6_proto.c \
@@ -8,7 +8,7 @@
 CFLAGS+= -g
 CPPFLAGS+=-I.
 CPPFLAGS+=-DINET6 -DPIM -DIOCTL_OK_ON_RAW_SOCKET
-CPPFLAGS+=-DHAVE_STDARG_H -DYY_NO_UNPUT
+CPPFLAGS+=-DHAVE_STDARG_H -DYY_NO_UNPUT -DHAVE_GETIFADDRS
 LDADD+=-ly -ll
 YFLAGS+=-d
 CLEANFILES+=   y.tab.h
diff -r c823bba244f5 -r c56ff66ce4c6 usr.sbin/pim6sd/config.c
--- a/usr.sbin/pim6sd/config.c  Fri Feb 25 06:22:05 2000 +0000
+++ b/usr.sbin/pim6sd/config.c  Fri Feb 25 06:27:32 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.c,v 1.1 2000/01/28 19:32:46 itojun Exp $        */
+/*     $NetBSD: config.c,v 1.2 2000/02/25 06:27:32 itojun Exp $        */
 
 /*
  *  Copyright (c) 1998 by the University of Southern California.
@@ -73,6 +73,9 @@
 #include <net/if_var.h>
 #endif
 #include <netinet6/in6_var.h>
+#ifdef HAVE_GETIFADDRS
+#include <ifaddrs.h>
+#endif 
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
@@ -81,40 +84,176 @@
 #include <stdio.h>
 #include "debug.h"
 
-void add_phaddr(struct uvif *v , struct sockaddr_in6 *addr,struct in6_addr *mask);
-char *next_word(char **s);
-int wordToOption(char *word);
-int parse_phyint(char *s);
-int parse_candidateRP(char *s);
-int parse_group_prefix(char *s);
-int parseBSR(char *s);
-int parse_reg_threshold(char *s);
-int parse_data_threshold(char *s);
-int parse_default_source_metric(char *s);
-int parse_default_source_preference(char *s);
-int parse_hello_period(char *s);
-int parse_granularity(char *s);
-int parse_jp_period(char *s);
-int parse_data_timeout(char *s);
-int parse_register_suppression_timeout(char *s);
-int parse_probe_time(char *s);
-int parse_assert_timeout(char *s);
+void add_phaddr(struct uvif *v, struct sockaddr_in6 *addr,
+               struct in6_addr *mask);
 
 void
 config_vifs_from_kernel()
 {
-       struct ifreq *ifrp,*ifend;
        register struct uvif *v;
        register vifi_t vifi;
-       int n,i;
+       int i;
        struct sockaddr_in6 addr;
        struct in6_addr mask;
        short flags;
+#ifdef HAVE_GETIFADDRS
+       struct ifaddrs *ifap, *ifa;
+#else
+       int n;
        int num_ifreq = 64;
        struct ifconf ifc;
+       struct ifreq *ifrp,*ifend;
+#endif
 
        total_interfaces= 0;    /* The total number of physical interfaces */
 
+#ifdef HAVE_GETIFADDRS
+       if (getifaddrs(&ifap))
+               log(LOG_ERR, errno, "getifaddrs");
+
+       /*
+        * Loop through all of the interfaces.
+        */
+       for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+               struct in6_ifreq ifr6;
+
+               /*
+                * Ignore any interface for an address family other than IPv6.
+                */
+               if (ifa->ifa_addr->sa_family != AF_INET6) {
+                       /* Eventually may have IPv6 address later */
+                       total_interfaces++;
+                       continue;
+               }
+
+               memcpy(&addr, ifa->ifa_addr, sizeof(struct sockaddr_in6));
+
+               flags = ifa->ifa_flags;
+
+
+               /*
+                * Get netmask of the address.
+                */
+               memcpy(&mask,
+                      &((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr,
+                      sizeof(mask));
+
+               /*
+                * Get IPv6 specific flags, and ignore an anycast address.
+                * XXX: how about a deprecated, tentative, duplicated or
+                * detached address?
+                */
+               memcpy(ifr6.ifr_name, ifa->ifa_name, sizeof(ifr6.ifr_name));
+               ifr6.ifr_addr = *(struct sockaddr_in6 *)ifa->ifa_addr;
+               if (ioctl(udp_socket, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
+                       log(LOG_ERR, errno, "ioctl SIOCGIFAFLAG_IN6 for %s",
+                           inet6_fmt(&ifr6.ifr_addr.sin6_addr));
+               }
+               else {
+                       if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_ANYCAST) {
+                               log(LOG_DEBUG, 0, "config_vifs_from_kernel: "
+                                   "%s on %s is an anycast address, ignored",
+                                   inet6_fmt(&ifr6.ifr_addr.sin6_addr),
+                                   ifa->ifa_name);
+                               continue;
+                       }
+               }
+
+               if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr))
+               {
+                       addr.sin6_scope_id = if_nametoindex(ifa->ifa_name);
+#ifdef __KAME__
+                       /*
+                        * Hack for KAME kernel.
+                        * Set sin6_scope_id field of a link local address and clear
+                        * the index embedded in the address.
+                        */
+                       /* clear interface index */
+                       addr.sin6_addr.s6_addr[2] = 0;
+                       addr.sin6_addr.s6_addr[3] = 0;
+#endif
+               }
+
+               /*
+                * If the address is connected to the same subnet as one
+                * already installed in the uvifs array, just add the address
+                * to the list of addresses of the uvif.
+                */
+               for(vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v)
+               {
+                       if( strcmp(v->uv_name , ifa->ifa_name) == 0 )
+                       {
+                               add_phaddr(v, &addr, &mask);
+                               break;
+                       }
+               }       
+
+               if (vifi != numvifs)
+                       continue;
+
+               /*
+                * If there is room in the uvifs array, install this interface.
+                */
+               if (numvifs == MAXMIFS)
+               {
+                       log(LOG_WARNING, 0,
+                           "too many vifs, ignoring %s", ifa->ifa_name);
+                       continue;
+               }
+
+               /*
+                * Everyone below is a potential vif interface.
+                * We don't care if it has wrong configuration or not
+                * configured at all.
+                */
+               total_interfaces++;
+
+               v  = &uvifs[numvifs];
+               v->uv_dst_addr = allpim6routers_group;
+               v->uv_subnetmask = mask;
+               strncpy(v->uv_name, ifa->ifa_name, IFNAMSIZ);
+               v->uv_ifindex = if_nametoindex(v->uv_name);
+               add_phaddr(v, &addr,&mask);
+       
+               /* prefix local calc. (and what about add_phaddr?...) */
+               for (i = 0; i < sizeof(struct in6_addr); i++)
+                       v->uv_prefix.sin6_addr.s6_addr[i] =
+                               addr.sin6_addr.s6_addr[i] & mask.s6_addr[i];
+       
+               if(flags & IFF_POINTOPOINT)
+                       v->uv_flags |=(VIFF_REXMIT_PRUNES | VIFF_POINT_TO_POINT);
+
+               /*
+                * Disable multicast routing on loopback interfaces and
+                * interfaces that do not support multicast. But they are
+                * still necessary, since global addresses maybe assigned only
+                * on such interfaces.
+                */
+               if ((flags & IFF_LOOPBACK) != 0 ||
+                   (flags & IFF_MULTICAST) == 0)
+                       v->uv_flags |= VIFF_DISABLED;
+
+               IF_DEBUG(DEBUG_IF)
+                       log(LOG_DEBUG,0,
+                           "Installing %s (%s on subnet %s) ,"
+                           "as vif #%u - rate = %d",
+                           v->uv_name,inet6_fmt(&addr.sin6_addr),
+                           net6name(&v->uv_prefix.sin6_addr,&mask),
+                           numvifs,v->uv_rate_limit);
+
+               ++numvifs;
+
+               
+               if( !(flags & IFF_UP)) 
+               {
+                       v->uv_flags |= VIFF_DOWN;
+                       vifs_down = TRUE;
+               }
+
+       }
+
+       freeifaddrs(ifap);
+#else  /* !HAVE_GETIFADDRS */
        ifc.ifc_len = num_ifreq * sizeof (struct ifreq);
        ifc.ifc_buf = calloc(ifc.ifc_len,sizeof(char));
        while (ifc.ifc_buf) {
@@ -319,6 +458,7 @@
                }
 
        }
+#endif /* HAVE_GETIFADDRS */
 }
 
 void
@@ -354,1257 +494,3 @@
        pa->pa_next = v->uv_addrs;
        v->uv_addrs = pa;
 }
-
-void
-config_vifs_from_file()
-{
-       FILE *f;
-       char linebuf[100];
-       char *w,*s;
-       struct ifconf ifc;
-       int option;
-       char ifbuf[BUFSIZ];
-       u_int8 *data_ptr;
-
-       if((f=fopen(configfilename,"r"))==NULL)
-       {
-               if( errno != ENOENT)
-                       log(LOG_ERR,errno,"Can't open %s",configfilename);
-               log(LOG_WARNING,errno,"Can't open  %s",configfilename);
-               return;
-       }
-       /*
-        * Note that sizeof(pim6_enocd_uni_addr_t) might be larger than
-        * the length of the Encoded-Unicast-address field(18 byte) due to
-        * some padding put in the compiler. However, it doesn't matter
-        * since we use the space just as a buffer(i.e not as the message).
-        */
-       cand_rp_adv_message.buffer = (u_int8 *)malloc( 4 + sizeof(pim6_encod_uni_addr_t) +
-                                                               255*sizeof(pim6_encod_grp_addr_t));
-       if(cand_rp_adv_message.buffer == NULL)
-               log(LOG_ERR,errno,"Candrpadv Buffer allocation");
-
-       cand_rp_adv_message.prefix_cnt_ptr = cand_rp_adv_message.buffer;
-
-    /* By default, if no group_prefix configured, then prefix_cnt == 0
-     * implies group_prefix = ff::/8 and masklen = 8.
-     */
-
-       *cand_rp_adv_message.prefix_cnt_ptr = 0;
-       cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer;
-
-       /* TODO: XXX: HARDCODING!!! */
-       cand_rp_adv_message.insert_data_ptr += (4 + 18);
-
-       ifc.ifc_buf = ifbuf;
-       ifc.ifc_len = sizeof(ifbuf);
-       if(ioctl(udp_socket,SIOCGIFCONF,(char *)&ifc) < 0)
-               log(LOG_ERR, errno, "ioctl SIOCGIFCONF");
-
-       while( fgets(linebuf, sizeof(linebuf),f) != NULL )
-       {
-               s = linebuf;
-               w = next_word(&s);
-               option = wordToOption(w);
-               switch(option)
-               {



Home | Main Index | Thread Index | Old Index