summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mrouted/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/mrouted/config.c')
-rw-r--r--usr.sbin/mrouted/config.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/usr.sbin/mrouted/config.c b/usr.sbin/mrouted/config.c
index 1147412..0b5ff7b 100644
--- a/usr.sbin/mrouted/config.c
+++ b/usr.sbin/mrouted/config.c
@@ -7,12 +7,18 @@
* Leland Stanford Junior University.
*
*
- * $Id: config.c,v 3.8 1995/11/29 22:36:57 fenner Rel $
+ * config.c,v 3.8.4.10 1998/01/06 01:57:41 fenner Exp
*/
#include "defs.h"
+#ifndef lint
+static char rcsid[] = "@(#) $Id: \
+config.c,v 3.8.4.10 1998/01/06 01:57:41 fenner Exp $";
+#endif
+
+struct ifconf ifc;
/*
* Query the kernel to find network interfaces that are multicast-capable
@@ -21,28 +27,48 @@
void
config_vifs_from_kernel()
{
- struct ifreq ifbuf[32];
struct ifreq *ifrp, *ifend;
- struct ifconf ifc;
register struct uvif *v;
register vifi_t vifi;
int n;
u_int32 addr, mask, subnet;
short flags;
+ int num_ifreq = 32;
+
+ ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
+ ifc.ifc_buf = malloc(ifc.ifc_len);
+ while (ifc.ifc_buf) {
+ if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
+ log(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;
- ifc.ifc_buf = (char *)ifbuf;
- ifc.ifc_len = sizeof(ifbuf);
- if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
- log(LOG_ERR, errno, "ioctl SIOCGIFCONF");
+ num_ifreq *= 2;
+ ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
+ ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len);
+ }
+ if (ifc.ifc_buf == NULL)
+ log(LOG_ERR, 0, "config_vifs_from_kernel: ran out of memory");
- ifrp = (struct ifreq *)ifbuf;
- ifend = (struct ifreq *)((char *)ifbuf + ifc.ifc_len);
+ 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;
-#if BSD >= 199006
+#ifdef HAVE_SA_LEN
n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
if (n < sizeof(*ifrp))
n = sizeof(*ifrp);
@@ -97,6 +123,12 @@ config_vifs_from_kernel()
* one already installed in the uvifs array.
*/
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
+ if (strcmp(v->uv_name, ifr.ifr_name) == 0) {
+ log(LOG_DEBUG, 0, "skipping %s (%s on subnet %s) (alias for vif#%u?)",
+ v->uv_name, inet_fmt(addr, s1),
+ inet_fmts(subnet, mask, s2), vifi);
+ break;
+ }
if ((addr & v->uv_subnetmask) == v->uv_subnet ||
(v->uv_subnet & mask) == subnet) {
log(LOG_WARNING, 0, "ignoring %s, same subnet as %s",
@@ -114,20 +146,15 @@ config_vifs_from_kernel()
continue;
}
v = &uvifs[numvifs];
- v->uv_flags = 0;
- v->uv_metric = DEFAULT_METRIC;
- v->uv_rate_limit = DEFAULT_PHY_RATE_LIMIT;
- v->uv_threshold = DEFAULT_THRESHOLD;
+ zero_vif(v, 0);
v->uv_lcl_addr = addr;
- v->uv_rmt_addr = 0;
v->uv_subnet = subnet;
v->uv_subnetmask = mask;
v->uv_subnetbcast = subnet | ~mask;
strncpy(v->uv_name, ifr.ifr_name, IFNAMSIZ);
- v->uv_groups = NULL;
- v->uv_neighbors = NULL;
- v->uv_acl = NULL;
- v->uv_addrs = NULL;
+
+ if (flags & IFF_POINTOPOINT)
+ v->uv_flags |= VIFF_REXMIT_PRUNES;
log(LOG_INFO,0,"installing %s (%s on subnet %s) as vif #%u - rate=%d",
v->uv_name, inet_fmt(addr, s1), inet_fmts(subnet, mask, s2),
OpenPOWER on IntegriCloud