Permalink
Browse files

assume presense of getifaddrs

  • Loading branch information...
1 parent 77bb73b commit 978d2a6cf49e92ba5d01993c5c335eebd2c8b0f3 itojun committed Sep 23, 2003
Showing with 5 additions and 390 deletions.
  1. +3 −3 kame/kame/pim6dd/Makefile
  2. +1 −184 kame/kame/pim6dd/config.c
  3. +1 −203 kame/kame/pim6sd/config.c
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit 978d2a6

Please sign in to comment.