Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

assume presense of getifaddrs

  • Loading branch information...
commit 978d2a6cf49e92ba5d01993c5c335eebd2c8b0f3 1 parent 77bb73b
itojun authored
View
6 kame/kame/pim6dd/Makefile
@@ -1,4 +1,4 @@
-# $KAME: Makefile,v 1.5 2003/07/30 06:49:21 itojun Exp $
+# $KAME: Makefile,v 1.6 2003/09/23 11:10:08 itojun Exp $
#
# Copyright (c) 1998 WIDE Project. All rights reserved.
#
@@ -91,9 +91,9 @@ CC= gcc
CFLAGS+=-Wall
.endif
.if (${OPSYS} != "NetBSD")
-CFLAGS+=-DINET6 -DPIM -DIOCTL_OK_ON_RAW_SOCKET -DHAVE_GETIFADDRS
+CFLAGS+=-DINET6 -DPIM -DIOCTL_OK_ON_RAW_SOCKET
.else
-CPPFLAGS+=-DINET6 -DPIM -DIOCTL_OK_ON_RAW_SOCKET -DHAVE_GETIFADDRS
+CPPFLAGS+=-DINET6 -DPIM -DIOCTL_OK_ON_RAW_SOCKET
.endif
.if exists(/usr/local/v6/lib/libinet6.a)
LDADD+= -L${.OBJDIR}/../libinet6 -L${.OBJDIR}/../libinet6/obj \
View
185 kame/kame/pim6dd/config.c
@@ -1,4 +1,4 @@
-/* $KAME: config.c,v 1.10 2003/09/02 09:57:04 itojun Exp $ */
+/* $KAME: config.c,v 1.11 2003/09/23 11:10:09 itojun Exp $ */
/*
* Copyright (c) 1998-2001
@@ -40,10 +40,7 @@
*/
#include "defs.h"
-#ifdef HAVE_GETIFADDRS
#include <ifaddrs.h>
-#endif
-
/*
* Forward declarations.
@@ -73,18 +70,10 @@ config_vifs_from_kernel()
struct sockaddr_in6 addr, rmt_addr, *rmt;
struct in6_addr mask, prefix;
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_msg(LOG_ERR, errno, "getiaddrs");
@@ -223,178 +212,6 @@ config_vifs_from_kernel()
}
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) {
- caddr_t newbuf;
-
- if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFCONF");
-
- /*
- * If the buffer was large enough to hold all the addresses
- * then break out, otherwise increase the buffer size and
- * try again.
- *
- * The only way to know that we definitely had enough space
- * is to know that there was enough space for at least one
- * more struct ifreq. ???
- */
- if ((num_ifreq * sizeof(struct ifreq)) >=
- ifc.ifc_len + sizeof(struct ifreq))
- break;
-
- num_ifreq *= 2;
- ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
- newbuf = realloc(ifc.ifc_buf, ifc.ifc_len);
- if (newbuf == NULL)
- free(ifc.ifc_buf);
- ifc.ifc_buf = newbuf;
- }
- if (ifc.ifc_buf == NULL)
- log_msg(LOG_ERR, 0, "config_vifs_from_kernel: ran out of memory");
-
- ifrp = (struct ifreq *)ifc.ifc_buf;
- ifend = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len);
- /*
- * Loop through all of the interfaces.
- */
- for (; ifrp < ifend; ifrp = (struct ifreq *)((char *)ifrp + n)) {
- struct ifreq ifr;
- struct in6_ifreq ifr6;
-#ifdef HAVE_SA_LEN
- n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
- if (n < sizeof(*ifrp))
- n = sizeof(*ifrp);
-#else
- n = sizeof(*ifrp);
-#endif /* HAVE_SA_LEN */
-
- /*
- * Ignore any interface for an address family other than IPv6.
- */
- if (ifrp->ifr_addr.sa_family != AF_INET6) {
- total_interfaces++; /* Eventually may have IPv6 address later */
- continue;
- }
-
- memcpy(&addr, &ifrp->ifr_addr, sizeof(struct sockaddr_in6));
-
- /*
- * Need a template to preserve address info that is
- * used below to locate the next entry. (Otherwise,
- * SIOCGIFFLAGS stomps over it because the requests
- * are returned in a union.)
- */
- memcpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
- memcpy(ifr6.ifr_name, ifrp->ifr_name, sizeof(ifr6.ifr_name));
-
- /*
- * Ignore loopback interfaces and interfaces that do not
- * support multicast.
- */
- if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
- flags = ifr.ifr_flags;
- if ((flags & (IFF_LOOPBACK | IFF_MULTICAST)) != IFF_MULTICAST)
- continue;
-
- /*
- * Get netmask of the address.
- */
- ifr6.ifr_addr = *(struct sockaddr_in6 *)&ifrp->ifr_addr;
- if (ioctl(udp_socket, SIOCGIFNETMASK_IN6, (char *)&ifr6) < 0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFNETMASK_IN6 for %s",
- ifr6.ifr_name);
- memcpy(&mask, &ifr6.ifr_addr.sin6_addr, sizeof(mask));
-
- if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr)) {
- addr.sin6_scope_id = if_nametoindex(ifrp->ifr_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, ifr.ifr_name) == 0) {
- add_phaddr(v, &addr, &mask, rmt);
- break;
- }
- }
- if (vifi != numvifs)
- continue;
-
- /*
- * If there is room in the uvifs array, install this interface.
- */
- if (numvifs == MAXMIFS) {
- log_msg(LOG_WARNING, 0, "too many ifs, ignoring %s", ifr.ifr_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_flags = 0;
- v->uv_metric = DEFAULT_METRIC;
- v->uv_admetric = 0;
- v->uv_rate_limit = DEFAULT_PHY_RATE_LIMIT;
- v->uv_dst_addr = allpim6routers_group;
- v->uv_prefix.sin6_addr = prefix;
- v->uv_subnetmask = mask;
- strncpy(v->uv_name, ifr.ifr_name, IFNAMSIZ);
- v->uv_ifindex = if_nametoindex(v->uv_name);
- v->uv_groups = (struct listaddr *)NULL;
- v->uv_dvmrp_neighbors = (struct listaddr *)NULL;
- NBRM_CLRALL(v->uv_nbrmap);
- v->uv_querier = (struct listaddr *)NULL;
- v->uv_prune_lifetime = 0;
- v->uv_acl = (struct vif_acl *)NULL;
- v->uv_leaf_timer = 0;
- v->uv_addrs = (struct phaddr *)NULL;
- v->uv_filter = (struct vif_filter *)NULL;
- v->uv_pim_hello_timer = 0;
- v->uv_gq_timer = 0;
- v->uv_pim_neighbors = (struct pim_nbr_entry *)NULL;
- v->uv_local_pref = default_source_preference;
- v->uv_local_metric = default_source_metric;
- add_phaddr(v, &addr, &mask, rmt);
-
- if (flags & IFF_POINTOPOINT)
- v->uv_flags |= (VIFF_REXMIT_PRUNES | VIFF_POINT_TO_POINT);
- log_msg(LOG_INFO, 0,
- "installing %s as if #%u - rate=%d",
- v->uv_name, numvifs, v->uv_rate_limit);
- ++numvifs;
-
- /*
- * If the interface is not yet up, set the vifs_down flag to
- * remind us to check again later.
- */
- if (!(flags & IFF_UP)) {
- v->uv_flags |= VIFF_DOWN;
- vifs_down = TRUE;
- }
- }
-#endif /* HAVE_GETIFADDRS */
}
static void
View
204 kame/kame/pim6sd/config.c
@@ -1,4 +1,4 @@
-/* $KAME: config.c,v 1.35 2003/09/02 09:48:44 suz Exp $ */
+/* $KAME: config.c,v 1.36 2003/09/23 11:08:36 itojun Exp $ */
/*
* Copyright (c) 1998-2001
@@ -72,9 +72,7 @@
#include <arpa/inet.h>
#include <syslog.h>
#include <stdlib.h>
-#ifdef HAVE_GETIFADDRS
#include <ifaddrs.h>
-#endif
#include <string.h>
#include <errno.h>
#include <ctype.h>
@@ -102,18 +100,10 @@ config_vifs_from_kernel()
struct sockaddr_in6 addr, rmt_addr, *rmt;
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_msg(LOG_ERR, errno, "getifaddrs");
@@ -267,198 +257,6 @@ config_vifs_from_kernel()
}
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) {
- caddr_t newbuf;
-
- if (ioctl(udp_socket,SIOCGIFCONF,(char *)&ifc) <0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFCONF");
- /*
- * If the buffer was large enough to hold all the addresses
- * then break out, otherwise increase the buffer size and
- * try again.
- *
- * The only way to know that we definitely had enough space
- * is to know that there was enough space for at least one
- * more struct ifreq. ???
- */
- if( (num_ifreq * sizeof (struct ifreq)) >=
- ifc.ifc_len + sizeof(struct ifreq))
- break;
-
- num_ifreq *= 2;
- ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
- newbuf = realloc(ifc.ifc_buf, ifc.ifc_len);
- if (newbuf == NULL)
- free(ifc.ifc_buf);
- ifc.ifc_buf = newbuf;
- }
- if (ifc.ifc_buf == NULL)
- log_msg(LOG_ERR, 0, "config_vifs_from_kernel: ran out of memory");
-
-
- ifrp = (struct ifreq *) ifc.ifc_buf;
- ifend = (struct ifreq * ) (ifc.ifc_buf + ifc.ifc_len);
-
- /*
- * Loop through all of the interfaces.
- */
- for(;ifrp < ifend;ifrp = (struct ifreq *)((char *)ifrp+n))
- {
- struct ifreq ifr;
- struct in6_ifreq ifr6;
-
-#ifdef HAVE_SA_LEN
- n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
- if(n < sizeof(*ifrp))
- n=sizeof(*ifrp);
-#else
- n=sizeof(*ifrp);
-#endif
-
- /*
- * Ignore any interface for an address family other than IPv6.
- */
- if ( ifrp->ifr_addr.sa_family != AF_INET6)
- {
- /* Eventually may have IP address later */
- total_interfaces++;
- continue;
- }
-
- memcpy(&addr,&ifrp->ifr_addr,sizeof(struct sockaddr_in6));
-
- /*
- * Need a template to preserve address info that is
- * used below to locate the next entry. (Otherwise,
- * SIOCGIFFLAGS stomps over it because the requests
- * are returned in a union.)
- */
- strncpy(ifr.ifr_name,ifrp->ifr_name,sizeof(ifr.ifr_name));
- strncpy(ifr6.ifr_name,ifrp->ifr_name,sizeof(ifr6.ifr_name));
-
- if(ioctl(udp_socket,SIOCGIFFLAGS,(char *)&ifr) <0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
- flags = ifr.ifr_flags;
-
-#if 0
- /*
- * Ignore loopback interfaces and interfaces that do not
- * support multicast.
- */
- if((flags & (IFF_LOOPBACK | IFF_MULTICAST ))!= IFF_MULTICAST)
- continue;
-#endif
-
- /*
- * Get netmask of the address.
- */
- ifr6.ifr_addr = *(struct sockaddr_in6 *)&ifrp->ifr_addr;
- if(ioctl(udp_socket, SIOCGIFNETMASK_IN6, (char *)&ifr6) <0)
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFNETMASK_IN6 for %s",
- sa6_fmt(&ifr6.ifr_addr));
- memcpy(&mask,&ifr6.ifr_addr.sin6_addr,sizeof(mask));
-
- /*
- * Get IPv6 specific flags, and ignore an anycast address.
- * XXX: how about a deprecated, tentative, duplicated or
- * detached address?
- */
- ifr6.ifr_addr = *(struct sockaddr_in6 *)&ifrp->ifr_addr;
- if (ioctl(udp_socket, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
- log_msg(LOG_ERR, errno, "ioctl SIOCGIFAFLAG_IN6 for %s",
- sa6_fmt(&ifr6.ifr_addr));
- }
- else {
- if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_ANYCAST) {
- log_msg(LOG_DEBUG, 0, "config_vifs_from_kernel: "
- "%s on %s is an anycast address, ignored",
- sa6_fmt(&ifr6.ifr_addr),
- ifr.ifr_name);
- continue;
- }
- }
-
- if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr))
- {
- addr.sin6_scope_id = if_nametoindex(ifrp->ifr_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.
- */
- v = find_vif(ifr.ifr_name, DONT_CREATE, default_vif_status);
- if (v != NULL) {
- add_phaddr(v, &addr, &mask, rmt);
- continue;
- }
-
- total_interfaces++;
-
- /*
- * If there is room in the uvifs array, install this interface.
- */
- v = find_vif(ifr.ifr_name, CREATE, default_vif_status);
- if (v == NULL) {
- log_msg(LOG_WARNING, 0,
- "ignored implicitly disabled interface %s",
- ifr.ifr_name);
- continue;
- }
-
- v->uv_dst_addr = allpim6routers_group;
- v->uv_subnetmask = mask;
- strncpy(v->uv_name, ifr.ifr_name,IFNAMSIZ);
- v->uv_ifindex = if_nametoindex(v->uv_name);
- add_phaddr(v, &addr, &mask, rmt);
-
- /* 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_msg(LOG_DEBUG,0,
- "Installing %s (%s on subnet %s) ,"
- "as vif #%u - rate = %d",
- v->uv_name, sa6_fmt(&addr),
- net6name(&v->uv_prefix.sin6_addr,&mask),
- numvifs,v->uv_rate_limit);
-
- if( !(flags & IFF_UP))
- {
- v->uv_flags |= VIFF_DOWN;
- vifs_down = TRUE;
- }
-
- }
-#endif /* HAVE_GETIFADDRS */
}
void

0 comments on commit 978d2a6

Please sign in to comment.
Something went wrong with that request. Please try again.