1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* The mrouted program is covered by the license in the accompanying file
|
|
|
|
* named "LICENSE". Use of the mrouted program represents acceptance of
|
|
|
|
* the terms and conditions listed in that file.
|
|
|
|
*
|
|
|
|
* The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
|
|
|
|
* Leland Stanford Junior University.
|
1999-01-20 07:55:57 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* config.c,v 3.8.4.10 1998/01/06 01:57:41 fenner Exp
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:17:45 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-01-20 07:55:57 +00:00
|
|
|
"$Id: config.c,v 1.12 1998/06/09 05:01:29 imp Exp $";
|
1998-01-16 07:17:45 +00:00
|
|
|
#endif /* not lint */
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
1999-01-20 07:55:57 +00:00
|
|
|
|
|
|
|
struct ifconf ifc;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* Query the kernel to find network interfaces that are multicast-capable
|
|
|
|
* and install them in the uvifs array.
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
void
|
|
|
|
config_vifs_from_kernel()
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct ifreq *ifrp, *ifend;
|
1994-09-08 00:26:13 +00:00
|
|
|
register struct uvif *v;
|
|
|
|
register vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
int n;
|
|
|
|
u_int32 addr, mask, subnet;
|
1994-09-08 00:26:13 +00:00
|
|
|
short flags;
|
1999-01-20 07:55:57 +00:00
|
|
|
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;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1999-01-20 07:55:57 +00:00
|
|
|
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");
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1999-01-20 07:55:57 +00:00
|
|
|
ifrp = (struct ifreq *)ifc.ifc_buf;
|
|
|
|
ifend = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len);
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* Loop through all of the interfaces.
|
|
|
|
*/
|
|
|
|
for (; ifrp < ifend; ifrp = (struct ifreq *)((char *)ifrp + n)) {
|
|
|
|
struct ifreq ifr;
|
1999-01-20 07:55:57 +00:00
|
|
|
#ifdef HAVE_SA_LEN
|
1994-09-08 00:26:13 +00:00
|
|
|
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 IP.
|
|
|
|
*/
|
|
|
|
if (ifrp->ifr_addr.sa_family != AF_INET)
|
|
|
|
continue;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
addr = ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* 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.)
|
|
|
|
*/
|
|
|
|
bcopy(ifrp->ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore loopback interfaces and interfaces that do not support
|
|
|
|
* multicast.
|
|
|
|
*/
|
|
|
|
if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0)
|
|
|
|
log(LOG_ERR, errno, "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
|
|
|
|
flags = ifr.ifr_flags;
|
|
|
|
if ((flags & (IFF_LOOPBACK|IFF_MULTICAST)) != IFF_MULTICAST) continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore any interface whose address and mask do not define a
|
|
|
|
* valid subnet number, or whose address is of the form {subnet,0}
|
|
|
|
* or {subnet,-1}.
|
|
|
|
*/
|
|
|
|
if (ioctl(udp_socket, SIOCGIFNETMASK, (char *)&ifr) < 0)
|
|
|
|
log(LOG_ERR, errno, "ioctl SIOCGIFNETMASK for %s", ifr.ifr_name);
|
|
|
|
mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
|
|
|
|
subnet = addr & mask;
|
|
|
|
if (!inet_valid_subnet(subnet, mask) ||
|
|
|
|
addr == subnet ||
|
|
|
|
addr == (subnet | ~mask)) {
|
|
|
|
log(LOG_WARNING, 0,
|
1995-06-13 18:05:16 +00:00
|
|
|
"ignoring %s, has invalid address (%s) and/or mask (%s)",
|
|
|
|
ifr.ifr_name, inet_fmt(addr, s1), inet_fmt(mask, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore any interface that is connected to the same subnet as
|
|
|
|
* one already installed in the uvifs array.
|
|
|
|
*/
|
|
|
|
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
|
1999-01-20 07:55:57 +00:00
|
|
|
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;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
if ((addr & v->uv_subnetmask) == v->uv_subnet ||
|
|
|
|
(v->uv_subnet & mask) == subnet) {
|
|
|
|
log(LOG_WARNING, 0, "ignoring %s, same subnet as %s",
|
|
|
|
ifr.ifr_name, v->uv_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vifi != numvifs) continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is room in the uvifs array, install this interface.
|
|
|
|
*/
|
|
|
|
if (numvifs == MAXVIFS) {
|
|
|
|
log(LOG_WARNING, 0, "too many vifs, ignoring %s", ifr.ifr_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
v = &uvifs[numvifs];
|
1999-01-20 07:55:57 +00:00
|
|
|
zero_vif(v, 0);
|
1994-09-08 00:26:13 +00:00
|
|
|
v->uv_lcl_addr = addr;
|
|
|
|
v->uv_subnet = subnet;
|
|
|
|
v->uv_subnetmask = mask;
|
|
|
|
v->uv_subnetbcast = subnet | ~mask;
|
|
|
|
strncpy(v->uv_name, ifr.ifr_name, IFNAMSIZ);
|
1998-06-09 05:01:38 +00:00
|
|
|
v->uv_name[IFNAMSIZ-1] = '\0';
|
1999-01-20 07:55:57 +00:00
|
|
|
|
|
|
|
if (flags & IFF_POINTOPOINT)
|
|
|
|
v->uv_flags |= VIFF_REXMIT_PRUNES;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
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),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|