1996-05-30 16:19:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1999-05-02 13:14:16 +00:00
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-27 10:17:27 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2004-02-25 23:20:22 +00:00
|
|
|
#ifdef __NetBSD__
|
1999-05-02 10:51:54 +00:00
|
|
|
__RCSID("$NetBSD$");
|
2004-02-25 23:20:22 +00:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
__RCSID("$FreeBSD$");
|
|
|
|
#else
|
|
|
|
__RCSID("$Revision: 2.27 $");
|
|
|
|
#ident "$Revision: 2.27 $"
|
1999-05-02 10:51:54 +00:00
|
|
|
#endif
|
2005-05-31 20:28:49 +00:00
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
struct ifhead ifnet = LIST_HEAD_INITIALIZER(ifnet); /* all interfaces */
|
2009-12-28 22:56:30 +00:00
|
|
|
struct ifhead remote_if = LIST_HEAD_INITIALIZER(remote_if); /* remote interfaces */
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
/* hash table for all interfaces, big enough to tolerate ridiculous
|
|
|
|
* numbers of IP aliases. Crazy numbers of aliases such as 7000
|
|
|
|
* still will not do well, but not just in looking up interfaces
|
|
|
|
* by name or address.
|
|
|
|
*/
|
|
|
|
#define AHASH_LEN 211 /* must be prime */
|
1997-01-06 17:24:50 +00:00
|
|
|
#define AHASH(a) &ahash_tbl[(a)%AHASH_LEN]
|
2009-04-05 15:55:09 +00:00
|
|
|
static struct interface *ahash_tbl[AHASH_LEN];
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
#define BHASH_LEN 211 /* must be prime */
|
1997-01-06 17:24:50 +00:00
|
|
|
#define BHASH(a) &bhash_tbl[(a)%BHASH_LEN]
|
2009-04-05 15:55:09 +00:00
|
|
|
static struct interface *bhash_tbl[BHASH_LEN];
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* hash for physical interface names.
|
|
|
|
* Assume there are never more 100 or 200 real interfaces, and that
|
1996-12-17 21:07:05 +00:00
|
|
|
* aliases are put on the end of the hash chains.
|
1996-11-19 20:23:47 +00:00
|
|
|
*/
|
|
|
|
#define NHASH_LEN 97
|
2009-04-05 15:55:09 +00:00
|
|
|
static struct interface *nhash_tbl[NHASH_LEN];
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
int tot_interfaces; /* # of remote and local interfaces */
|
|
|
|
int rip_interfaces; /* # of interfaces doing RIP */
|
2009-04-05 15:55:09 +00:00
|
|
|
static int foundloopback; /* valid flag for loopaddr */
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr loopaddr; /* our address on loopback */
|
2009-04-05 15:55:09 +00:00
|
|
|
static struct rt_spare loop_rts;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
struct timeval ifinit_timer;
|
1996-12-17 21:07:05 +00:00
|
|
|
static struct timeval last_ifinit;
|
1999-05-02 10:51:54 +00:00
|
|
|
#define IF_RESCAN_DELAY() (last_ifinit.tv_sec == now.tv_sec \
|
|
|
|
&& last_ifinit.tv_usec == now.tv_usec \
|
|
|
|
&& timercmp(&ifinit_timer, &now, >))
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
int have_ripv1_out; /* have a RIPv1 interface */
|
2009-04-05 15:55:09 +00:00
|
|
|
static int have_ripv1_in;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
2009-04-05 15:55:09 +00:00
|
|
|
static void if_bad(struct interface *);
|
|
|
|
static int addrouteforif(struct interface *);
|
|
|
|
|
1997-01-06 17:24:50 +00:00
|
|
|
static struct interface**
|
1999-05-02 10:51:54 +00:00
|
|
|
nhash(char *p)
|
1997-01-06 17:24:50 +00:00
|
|
|
{
|
1999-05-02 10:51:54 +00:00
|
|
|
u_int i;
|
1997-01-06 17:24:50 +00:00
|
|
|
|
|
|
|
for (i = 0; *p != '\0'; p++) {
|
|
|
|
i = ((i<<1) & 0x7fffffff) | ((i>>31) & 1);
|
|
|
|
i ^= *p;
|
|
|
|
}
|
|
|
|
return &nhash_tbl[i % NHASH_LEN];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-12-17 21:07:05 +00:00
|
|
|
/* Link a new interface into the lists and hash tables.
|
|
|
|
*/
|
1996-11-19 20:23:47 +00:00
|
|
|
void
|
|
|
|
if_link(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct interface **hifp;
|
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_INSERT_HEAD(&ifnet, ifp, int_list);
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
hifp = AHASH(ifp->int_addr);
|
|
|
|
ifp->int_ahash_prev = hifp;
|
2016-05-14 22:40:08 +00:00
|
|
|
if ((ifp->int_ahash = *hifp) != NULL)
|
1996-11-19 20:23:47 +00:00
|
|
|
(*hifp)->int_ahash_prev = &ifp->int_ahash;
|
|
|
|
*hifp = ifp;
|
|
|
|
|
|
|
|
if (ifp->int_if_flags & IFF_BROADCAST) {
|
|
|
|
hifp = BHASH(ifp->int_brdaddr);
|
|
|
|
ifp->int_bhash_prev = hifp;
|
2016-05-14 22:40:08 +00:00
|
|
|
if ((ifp->int_bhash = *hifp) != NULL)
|
1996-11-19 20:23:47 +00:00
|
|
|
(*hifp)->int_bhash_prev = &ifp->int_bhash;
|
|
|
|
*hifp = ifp;
|
|
|
|
}
|
|
|
|
|
2009-04-05 15:06:02 +00:00
|
|
|
if (ifp->int_state & IS_REMOTE)
|
|
|
|
LIST_INSERT_HEAD(&remote_if, ifp, remote_list);
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1997-01-06 17:24:50 +00:00
|
|
|
hifp = nhash(ifp->int_name);
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifp->int_state & IS_ALIAS) {
|
1996-12-17 21:07:05 +00:00
|
|
|
/* put aliases on the end of the hash chain */
|
2016-05-14 22:40:08 +00:00
|
|
|
while (*hifp != NULL)
|
1996-11-19 20:23:47 +00:00
|
|
|
hifp = &(*hifp)->int_nhash;
|
|
|
|
}
|
|
|
|
ifp->int_nhash_prev = hifp;
|
2016-05-14 22:40:08 +00:00
|
|
|
if ((ifp->int_nhash = *hifp) != NULL)
|
1996-11-19 20:23:47 +00:00
|
|
|
(*hifp)->int_nhash_prev = &ifp->int_nhash;
|
|
|
|
*hifp = ifp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
/* Find the interface with an address
|
|
|
|
*/
|
|
|
|
struct interface *
|
|
|
|
ifwithaddr(naddr addr,
|
|
|
|
int bcast, /* notice IFF_BROADCAST address */
|
|
|
|
int remote) /* include IS_REMOTE interfaces */
|
|
|
|
{
|
2016-05-14 22:40:08 +00:00
|
|
|
struct interface *ifp, *possible = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
remote = (remote == 0) ? IS_REMOTE : 0;
|
1996-07-22 20:56:54 +00:00
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
for (ifp = *AHASH(addr); ifp; ifp = ifp->int_ahash) {
|
|
|
|
if (ifp->int_addr != addr)
|
|
|
|
continue;
|
|
|
|
if ((ifp->int_state & remote) != 0)
|
|
|
|
continue;
|
|
|
|
if ((ifp->int_state & (IS_BROKE | IS_PASSIVE)) == 0)
|
|
|
|
return ifp;
|
|
|
|
possible = ifp;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
if (possible || !bcast)
|
|
|
|
return possible;
|
|
|
|
|
|
|
|
for (ifp = *BHASH(addr); ifp; ifp = ifp->int_bhash) {
|
|
|
|
if (ifp->int_brdaddr != addr)
|
|
|
|
continue;
|
|
|
|
if ((ifp->int_state & remote) != 0)
|
|
|
|
continue;
|
|
|
|
if ((ifp->int_state & (IS_BROKE | IS_PASSIVE)) == 0)
|
|
|
|
return ifp;
|
|
|
|
possible = ifp;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return possible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* find the interface with a name
|
|
|
|
*/
|
2009-04-05 15:55:09 +00:00
|
|
|
static struct interface *
|
1996-07-22 20:56:54 +00:00
|
|
|
ifwithname(char *name, /* "ec0" or whatever */
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr addr) /* 0 or network address */
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1996-12-17 21:07:05 +00:00
|
|
|
for (;;) {
|
2016-05-14 22:40:08 +00:00
|
|
|
for (ifp = *nhash(name); ifp != NULL; ifp = ifp->int_nhash) {
|
1996-12-17 21:07:05 +00:00
|
|
|
/* If the network address is not specified,
|
|
|
|
* ignore any alias interfaces. Otherwise, look
|
|
|
|
* for the interface with the target name and address.
|
|
|
|
*/
|
|
|
|
if (!strcmp(ifp->int_name, name)
|
|
|
|
&& ((addr == 0 && !(ifp->int_state & IS_ALIAS))
|
|
|
|
|| (ifp->int_addr == addr)))
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there is no known interface, maybe there is a
|
|
|
|
* new interface. So just once look for new interfaces.
|
1996-11-19 20:23:47 +00:00
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
if (IF_RESCAN_DELAY())
|
1996-12-17 21:07:05 +00:00
|
|
|
return 0;
|
|
|
|
ifinit();
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct interface *
|
2004-02-25 23:20:22 +00:00
|
|
|
ifwithindex(u_short ifindex,
|
1999-05-02 10:51:54 +00:00
|
|
|
int rescan_ok)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
for (;;) {
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list) {
|
2004-02-25 23:20:22 +00:00
|
|
|
if (ifp->int_index == ifindex)
|
1999-05-02 10:51:54 +00:00
|
|
|
return ifp;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
/* If there is no known interface, maybe there is a
|
|
|
|
* new interface. So just once look for new interfaces.
|
|
|
|
*/
|
|
|
|
if (!rescan_ok
|
|
|
|
|| IF_RESCAN_DELAY())
|
|
|
|
return 0;
|
|
|
|
ifinit();
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Find an interface from which the specified address
|
|
|
|
* should have come from. Used for figuring out which
|
1996-12-11 20:59:33 +00:00
|
|
|
* interface a packet came in on.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
struct interface *
|
|
|
|
iflookup(naddr addr)
|
|
|
|
{
|
|
|
|
struct interface *ifp, *maybe;
|
2004-02-25 23:20:22 +00:00
|
|
|
int once = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
2016-05-14 22:40:08 +00:00
|
|
|
maybe = NULL;
|
1996-12-11 20:59:33 +00:00
|
|
|
for (;;) {
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list) {
|
1996-12-11 20:59:33 +00:00
|
|
|
if (ifp->int_if_flags & IFF_POINTOPOINT) {
|
|
|
|
/* finished with a match */
|
|
|
|
if (ifp->int_dstaddr == addr)
|
|
|
|
return ifp;
|
1996-07-22 20:56:54 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
} else {
|
|
|
|
/* finished with an exact match */
|
|
|
|
if (ifp->int_addr == addr)
|
|
|
|
return ifp;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
/* Look for the longest approximate match.
|
|
|
|
*/
|
|
|
|
if (on_net(addr, ifp->int_net, ifp->int_mask)
|
2016-05-14 22:40:08 +00:00
|
|
|
&& (maybe == NULL
|
1996-12-11 20:59:33 +00:00
|
|
|
|| ifp->int_mask > maybe->int_mask))
|
|
|
|
maybe = ifp;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 22:40:08 +00:00
|
|
|
if (maybe != NULL || once || IF_RESCAN_DELAY())
|
1996-12-11 20:59:33 +00:00
|
|
|
return maybe;
|
2004-02-25 23:20:22 +00:00
|
|
|
once = 1;
|
1996-12-11 20:59:33 +00:00
|
|
|
|
|
|
|
/* If there is no known interface, maybe there is a
|
|
|
|
* new interface. So just once look for new interfaces.
|
|
|
|
*/
|
|
|
|
ifinit();
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the classical netmask for an IP address.
|
|
|
|
*/
|
1996-12-11 20:59:33 +00:00
|
|
|
naddr /* host byte order */
|
|
|
|
std_mask(naddr addr) /* network byte order */
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
2002-02-18 20:35:27 +00:00
|
|
|
addr = ntohl(addr); /* was a host, not a network */
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
if (addr == 0) /* default route has mask 0 */
|
|
|
|
return 0;
|
|
|
|
if (IN_CLASSA(addr))
|
|
|
|
return IN_CLASSA_NET;
|
|
|
|
if (IN_CLASSB(addr))
|
|
|
|
return IN_CLASSB_NET;
|
|
|
|
return IN_CLASSC_NET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-08-27 16:13:00 +00:00
|
|
|
/* Find the netmask that would be inferred by RIPv1 listeners
|
1996-07-22 20:56:54 +00:00
|
|
|
* on the given interface for a given network.
|
|
|
|
* If no interface is specified, look for the best fitting interface.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
naddr
|
|
|
|
ripv1_mask_net(naddr addr, /* in network byte order */
|
1996-07-22 20:56:54 +00:00
|
|
|
struct interface *ifp) /* as seen on this interface */
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1999-05-02 10:51:54 +00:00
|
|
|
struct r1net *r1p;
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr mask = 0;
|
|
|
|
|
|
|
|
if (addr == 0) /* default always has 0 mask */
|
|
|
|
return mask;
|
|
|
|
|
2016-05-14 22:40:08 +00:00
|
|
|
if (ifp != NULL && ifp->int_ripv1_mask != HOST_MASK) {
|
1996-07-22 20:56:54 +00:00
|
|
|
/* If the target network is that of the associated interface
|
|
|
|
* on which it arrived, then use the netmask of the interface.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (on_net(addr, ifp->int_net, ifp->int_std_mask))
|
|
|
|
mask = ifp->int_ripv1_mask;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Examine all interfaces, and if it the target seems
|
|
|
|
* to have the same network number of an interface, use the
|
|
|
|
* netmask of that interface. If there is more than one
|
|
|
|
* such interface, prefer the interface with the longest
|
|
|
|
* match.
|
|
|
|
*/
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (on_net(addr, ifp->int_std_net, ifp->int_std_mask)
|
1999-05-02 10:51:54 +00:00
|
|
|
&& ifp->int_ripv1_mask > mask
|
|
|
|
&& ifp->int_ripv1_mask != HOST_MASK)
|
1996-07-22 20:56:54 +00:00
|
|
|
mask = ifp->int_ripv1_mask;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1999-05-02 10:51:54 +00:00
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
/* check special definitions */
|
|
|
|
if (mask == 0) {
|
2016-05-14 22:40:08 +00:00
|
|
|
for (r1p = r1nets; r1p != NULL; r1p = r1p->r1net_next) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (on_net(addr, r1p->r1net_net, r1p->r1net_match)
|
|
|
|
&& r1p->r1net_mask > mask)
|
|
|
|
mask = r1p->r1net_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, make the classic A/B/C guess.
|
|
|
|
*/
|
|
|
|
if (mask == 0)
|
|
|
|
mask = std_mask(addr);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
naddr
|
|
|
|
ripv1_mask_host(naddr addr, /* in network byte order */
|
1996-07-22 20:56:54 +00:00
|
|
|
struct interface *ifp) /* as seen on this interface */
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
naddr mask = ripv1_mask_net(addr, ifp);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* If the computed netmask does not mask the address,
|
|
|
|
* then assume it is a host address
|
|
|
|
*/
|
|
|
|
if ((ntohl(addr) & ~mask) != 0)
|
|
|
|
mask = HOST_MASK;
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-01 18:49:04 +00:00
|
|
|
/* See if an IP address looks reasonable as a destination.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
int /* 0=bad */
|
|
|
|
check_dst(naddr addr)
|
|
|
|
{
|
2002-02-18 20:35:27 +00:00
|
|
|
addr = ntohl(addr);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
if (IN_CLASSA(addr)) {
|
|
|
|
if (addr == 0)
|
|
|
|
return 1; /* default */
|
|
|
|
|
|
|
|
addr >>= IN_CLASSA_NSHIFT;
|
|
|
|
return (addr != 0 && addr != IN_LOOPBACKNET);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (IN_CLASSB(addr) || IN_CLASSC(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* See a new interface duplicates an existing interface.
|
|
|
|
*/
|
|
|
|
struct interface *
|
1996-12-11 20:59:33 +00:00
|
|
|
check_dup(naddr addr, /* IP address, so network byte order */
|
|
|
|
naddr dstaddr, /* ditto */
|
|
|
|
naddr mask, /* mask, so host byte order */
|
1996-11-19 20:23:47 +00:00
|
|
|
int if_flags)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list) {
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifp->int_mask != mask)
|
|
|
|
continue;
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
if (!iff_up(ifp->int_if_flags))
|
1996-11-19 20:23:47 +00:00
|
|
|
continue;
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
/* The local address can only be shared with a point-to-point
|
|
|
|
* link.
|
1996-11-19 20:23:47 +00:00
|
|
|
*/
|
2004-02-25 23:20:22 +00:00
|
|
|
if ((!(ifp->int_state & IS_REMOTE) || !(if_flags & IS_REMOTE))
|
|
|
|
&& ifp->int_addr == addr
|
1996-11-19 20:23:47 +00:00
|
|
|
&& (((if_flags|ifp->int_if_flags) & IFF_POINTOPOINT) == 0))
|
|
|
|
return ifp;
|
|
|
|
|
|
|
|
if (on_net(ifp->int_dstaddr, ntohl(dstaddr),mask))
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* See that a remote gateway is reachable.
|
|
|
|
* Note that the answer can change as real interfaces come and go.
|
|
|
|
*/
|
|
|
|
int /* 0=bad */
|
|
|
|
check_remote(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct rt_entry *rt;
|
|
|
|
|
|
|
|
/* do not worry about other kinds */
|
|
|
|
if (!(ifp->int_state & IS_REMOTE))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
rt = rtfind(ifp->int_addr);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL
|
1996-11-19 20:23:47 +00:00
|
|
|
&& rt->rt_ifp != 0
|
|
|
|
&&on_net(ifp->int_addr,
|
|
|
|
rt->rt_ifp->int_net, rt->rt_ifp->int_mask))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* the gateway cannot be reached directly from one of our
|
|
|
|
* interfaces
|
|
|
|
*/
|
|
|
|
if (!(ifp->int_state & IS_BROKE)) {
|
|
|
|
msglog("unreachable gateway %s in "_PATH_GATEWAYS,
|
|
|
|
naddr_ntoa(ifp->int_addr));
|
|
|
|
if_bad(ifp);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
/* Delete an interface.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ifdel(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct interface *ifp1;
|
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_if("Del", ifp);
|
|
|
|
|
|
|
|
ifp->int_state |= IS_BROKE;
|
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_REMOVE(ifp, int_list);
|
1996-11-19 20:23:47 +00:00
|
|
|
*ifp->int_ahash_prev = ifp->int_ahash;
|
|
|
|
if (ifp->int_ahash != 0)
|
|
|
|
ifp->int_ahash->int_ahash_prev = ifp->int_ahash_prev;
|
1997-01-06 17:24:50 +00:00
|
|
|
*ifp->int_nhash_prev = ifp->int_nhash;
|
|
|
|
if (ifp->int_nhash != 0)
|
|
|
|
ifp->int_nhash->int_nhash_prev = ifp->int_nhash_prev;
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifp->int_if_flags & IFF_BROADCAST) {
|
|
|
|
*ifp->int_bhash_prev = ifp->int_bhash;
|
|
|
|
if (ifp->int_bhash != 0)
|
|
|
|
ifp->int_bhash->int_bhash_prev = ifp->int_bhash_prev;
|
|
|
|
}
|
2009-04-05 15:06:02 +00:00
|
|
|
if (ifp->int_state & IS_REMOTE)
|
|
|
|
LIST_REMOVE(ifp, remote_list);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
if (!(ifp->int_state & IS_ALIAS)) {
|
1996-11-19 20:23:47 +00:00
|
|
|
/* delete aliases when the main interface dies
|
1996-07-22 20:56:54 +00:00
|
|
|
*/
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp1, &ifnet, int_list) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp1 != ifp
|
|
|
|
&& !strcmp(ifp->int_name, ifp1->int_name))
|
|
|
|
ifdel(ifp1);
|
|
|
|
}
|
|
|
|
|
2008-07-30 11:56:15 +00:00
|
|
|
if ((ifp->int_if_flags & IFF_MULTICAST) && rip_sock >= 0) {
|
|
|
|
struct group_req gr;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
memset(&gr, 0, sizeof(gr));
|
|
|
|
gr.gr_interface = ifp->int_index;
|
|
|
|
sin = (struct sockaddr_in *)&gr.gr_group;
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
#ifdef _HAVE_SIN_LEN
|
|
|
|
sin->sin_len = sizeof(struct sockaddr_in);
|
2004-02-25 23:20:22 +00:00
|
|
|
#endif
|
2008-07-30 11:56:15 +00:00
|
|
|
sin->sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
|
|
|
|
if (setsockopt(rip_sock, IPPROTO_IP, MCAST_LEAVE_GROUP,
|
|
|
|
&gr, sizeof(gr)) < 0
|
1996-07-22 20:56:54 +00:00
|
|
|
&& errno != EADDRNOTAVAIL
|
|
|
|
&& !TRACEACTIONS)
|
2008-07-30 11:56:15 +00:00
|
|
|
LOGERR("setsockopt(MCAST_LEAVE_GROUP RIP)");
|
1996-11-19 20:23:47 +00:00
|
|
|
if (rip_sock_mcast == ifp)
|
2016-05-14 22:40:08 +00:00
|
|
|
rip_sock_mcast = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
if (ifp->int_rip_sock >= 0) {
|
|
|
|
(void)close(ifp->int_rip_sock);
|
|
|
|
ifp->int_rip_sock = -1;
|
|
|
|
fix_select();
|
|
|
|
}
|
|
|
|
|
|
|
|
tot_interfaces--;
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!IS_RIP_OFF(ifp->int_state))
|
1996-05-30 16:19:16 +00:00
|
|
|
rip_interfaces--;
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* Zap all routes associated with this interface.
|
1999-05-02 10:51:54 +00:00
|
|
|
* Assume routes just using gateways beyond this interface
|
|
|
|
* will timeout naturally, and have probably already died.
|
1996-07-22 20:56:54 +00:00
|
|
|
*/
|
|
|
|
(void)rn_walktree(rhead, walk_bad, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
set_rdisc_mg(ifp, 0);
|
|
|
|
if_bad_rdisc(ifp);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* Mark an interface ill.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
if_sick(struct interface *ifp)
|
|
|
|
{
|
|
|
|
if (0 == (ifp->int_state & (IS_SICK | IS_BROKE))) {
|
|
|
|
ifp->int_state |= IS_SICK;
|
1996-11-19 20:23:47 +00:00
|
|
|
ifp->int_act_time = NEVER;
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_if("Chg", ifp);
|
|
|
|
|
|
|
|
LIM_SEC(ifinit_timer, now.tv_sec+CHECK_BAD_INTERVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
/* Mark an interface dead.
|
|
|
|
*/
|
2009-04-05 15:55:09 +00:00
|
|
|
static void
|
1996-07-22 20:56:54 +00:00
|
|
|
if_bad(struct interface *ifp)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
struct interface *ifp1;
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
if (ifp->int_state & IS_BROKE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIM_SEC(ifinit_timer, now.tv_sec+CHECK_BAD_INTERVAL);
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state |= (IS_BROKE | IS_SICK);
|
1996-11-19 20:23:47 +00:00
|
|
|
ifp->int_act_time = NEVER;
|
|
|
|
ifp->int_query_time = NEVER;
|
1999-05-02 10:51:54 +00:00
|
|
|
ifp->int_data.ts = now.tv_sec;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
trace_if("Chg", ifp);
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!(ifp->int_state & IS_ALIAS)) {
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp1, &ifnet, int_list) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp1 != ifp
|
|
|
|
&& !strcmp(ifp->int_name, ifp1->int_name))
|
|
|
|
if_bad(ifp1);
|
|
|
|
}
|
|
|
|
(void)rn_walktree(rhead, walk_bad, 0);
|
|
|
|
if_bad_rdisc(ifp);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Mark an interface alive
|
|
|
|
*/
|
|
|
|
int /* 1=it was dead */
|
1996-07-22 20:56:54 +00:00
|
|
|
if_ok(struct interface *ifp,
|
1999-05-02 10:51:54 +00:00
|
|
|
const char *type)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
struct interface *ifp1;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(ifp->int_state & IS_BROKE)) {
|
|
|
|
if (ifp->int_state & IS_SICK) {
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("%sinterface %s to %s working better",
|
1996-07-22 20:56:54 +00:00
|
|
|
type,
|
1996-11-19 20:23:47 +00:00
|
|
|
ifp->int_name, naddr_ntoa(ifp->int_dstaddr));
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state &= ~IS_SICK;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
return 0;
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
msglog("%sinterface %s to %s restored",
|
1996-11-19 20:23:47 +00:00
|
|
|
type, ifp->int_name, naddr_ntoa(ifp->int_dstaddr));
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state &= ~(IS_BROKE | IS_SICK);
|
|
|
|
ifp->int_data.ts = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!(ifp->int_state & IS_ALIAS)) {
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp1, &ifnet, int_list) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp1 != ifp
|
|
|
|
&& !strcmp(ifp->int_name, ifp1->int_name))
|
|
|
|
if_ok(ifp1, type);
|
|
|
|
}
|
|
|
|
if_ok_rdisc(ifp);
|
|
|
|
}
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
if (ifp->int_state & IS_REMOTE) {
|
|
|
|
if (!addrouteforif(ifp))
|
|
|
|
return 0;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* disassemble routing message
|
|
|
|
*/
|
|
|
|
void
|
1996-07-22 20:56:54 +00:00
|
|
|
rt_xaddrs(struct rt_addrinfo *info,
|
|
|
|
struct sockaddr *sa,
|
1996-05-30 16:19:16 +00:00
|
|
|
struct sockaddr *lim,
|
|
|
|
int addrs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
#ifdef _HAVE_SA_LEN
|
|
|
|
static struct sockaddr sa_zero;
|
|
|
|
#endif
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
memset(info, 0, sizeof(*info));
|
1996-07-22 20:56:54 +00:00
|
|
|
info->rti_addrs = addrs;
|
1996-05-30 16:19:16 +00:00
|
|
|
for (i = 0; i < RTAX_MAX && sa < lim; i++) {
|
|
|
|
if ((addrs & (1 << i)) == 0)
|
|
|
|
continue;
|
1996-07-22 20:56:54 +00:00
|
|
|
info->rti_info[i] = (sa->sa_len != 0) ? sa : &sa_zero;
|
2004-04-13 11:24:43 +00:00
|
|
|
sa = (struct sockaddr *)((char*)(sa) + SA_SIZE(sa));
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Find the network interfaces which have configured themselves.
|
|
|
|
* This must be done regularly, if only for extra addresses
|
|
|
|
* that come and go on interfaces.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ifinit(void)
|
|
|
|
{
|
2009-04-05 17:12:13 +00:00
|
|
|
static struct ifa_msghdr *sysctl_buf;
|
1996-05-30 16:19:16 +00:00
|
|
|
static size_t sysctl_buf_size = 0;
|
|
|
|
uint complaints = 0;
|
|
|
|
static u_int prev_complaints = 0;
|
1996-08-27 16:13:00 +00:00
|
|
|
# define COMP_NOT_INET 0x001
|
1996-11-19 20:23:47 +00:00
|
|
|
# define COMP_NOADDR 0x002
|
|
|
|
# define COMP_BADADDR 0x004
|
|
|
|
# define COMP_NODST 0x008
|
|
|
|
# define COMP_NOBADR 0x010
|
|
|
|
# define COMP_NOMASK 0x020
|
|
|
|
# define COMP_DUP 0x040
|
|
|
|
# define COMP_BAD_METRIC 0x080
|
|
|
|
# define COMP_NETMASK 0x100
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
struct interface ifs, ifs0, *ifp, *ifp1;
|
|
|
|
struct rt_entry *rt;
|
|
|
|
size_t needed;
|
|
|
|
int mib[6];
|
|
|
|
struct if_msghdr *ifm;
|
2009-04-05 17:12:13 +00:00
|
|
|
void *ifam_lim;
|
|
|
|
struct ifa_msghdr *ifam, *ifam2;
|
1996-05-30 16:19:16 +00:00
|
|
|
int in, ierr, out, oerr;
|
|
|
|
struct intnet *intnetp;
|
1996-07-22 20:56:54 +00:00
|
|
|
struct rt_addrinfo info;
|
1996-05-30 16:19:16 +00:00
|
|
|
#ifdef SIOCGIFMETRIC
|
|
|
|
struct ifreq ifr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1996-12-17 21:07:05 +00:00
|
|
|
last_ifinit = now;
|
1996-05-30 16:19:16 +00:00
|
|
|
ifinit_timer.tv_sec = now.tv_sec + (supplier
|
|
|
|
? CHECK_ACT_INTERVAL
|
|
|
|
: CHECK_QUIET_INTERVAL);
|
|
|
|
|
1998-07-28 06:36:31 +00:00
|
|
|
/* mark all interfaces so we can get rid of those that disappear */
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list)
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state &= ~(IS_CHECKED | IS_DUP);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
/* Fetch the interface list, without too many system calls
|
|
|
|
* since we do it repeatedly.
|
|
|
|
*/
|
|
|
|
mib[0] = CTL_NET;
|
|
|
|
mib[1] = PF_ROUTE;
|
|
|
|
mib[2] = 0;
|
|
|
|
mib[3] = AF_INET;
|
|
|
|
mib[4] = NET_RT_IFLIST;
|
|
|
|
mib[5] = 0;
|
|
|
|
for (;;) {
|
|
|
|
if ((needed = sysctl_buf_size) != 0) {
|
|
|
|
if (sysctl(mib, 6, sysctl_buf,&needed, 0, 0) >= 0)
|
|
|
|
break;
|
1999-05-02 10:51:54 +00:00
|
|
|
/* retry if the table grew */
|
1996-05-30 16:19:16 +00:00
|
|
|
if (errno != ENOMEM && errno != EFAULT)
|
1999-05-02 10:51:54 +00:00
|
|
|
BADERR(1, "ifinit: sysctl(RT_IFLIST)");
|
1996-05-30 16:19:16 +00:00
|
|
|
free(sysctl_buf);
|
|
|
|
needed = 0;
|
|
|
|
}
|
|
|
|
if (sysctl(mib, 6, 0, &needed, 0, 0) < 0)
|
1999-05-02 10:51:54 +00:00
|
|
|
BADERR(1,"ifinit: sysctl(RT_IFLIST) estimate");
|
|
|
|
sysctl_buf = rtmalloc(sysctl_buf_size = needed,
|
|
|
|
"ifinit sysctl");
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 17:12:13 +00:00
|
|
|
/* XXX: thanks to malloc(3), alignment can be presumed OK */
|
|
|
|
ifam_lim = (char *)sysctl_buf + needed;
|
|
|
|
for (ifam = sysctl_buf; (void *)ifam < ifam_lim; ifam = ifam2) {
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
ifam2 = (struct ifa_msghdr*)((char*)ifam + ifam->ifam_msglen);
|
|
|
|
|
2004-02-25 23:20:22 +00:00
|
|
|
#ifdef RTM_OIFINFO
|
|
|
|
if (ifam->ifam_type == RTM_OIFINFO)
|
|
|
|
continue; /* just ignore compat message */
|
|
|
|
#endif
|
1996-05-30 16:19:16 +00:00
|
|
|
if (ifam->ifam_type == RTM_IFINFO) {
|
1996-11-19 20:23:47 +00:00
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
ifm = (struct if_msghdr *)ifam;
|
1996-07-22 20:56:54 +00:00
|
|
|
/* make prototype structure for the IP aliases
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
memset(&ifs0, 0, sizeof(ifs0));
|
1996-05-30 16:19:16 +00:00
|
|
|
ifs0.int_rip_sock = -1;
|
|
|
|
ifs0.int_index = ifm->ifm_index;
|
|
|
|
ifs0.int_if_flags = ifm->ifm_flags;
|
|
|
|
ifs0.int_state = IS_CHECKED;
|
1996-12-11 20:59:33 +00:00
|
|
|
ifs0.int_query_time = NEVER;
|
1996-05-30 16:19:16 +00:00
|
|
|
ifs0.int_act_time = now.tv_sec;
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs0.int_data.ts = now.tv_sec;
|
|
|
|
ifs0.int_data.ipackets = ifm->ifm_data.ifi_ipackets;
|
|
|
|
ifs0.int_data.ierrors = ifm->ifm_data.ifi_ierrors;
|
|
|
|
ifs0.int_data.opackets = ifm->ifm_data.ifi_opackets;
|
|
|
|
ifs0.int_data.oerrors = ifm->ifm_data.ifi_oerrors;
|
1996-05-30 16:19:16 +00:00
|
|
|
#ifdef sgi
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs0.int_data.odrops = ifm->ifm_data.ifi_odrops;
|
1996-05-30 16:19:16 +00:00
|
|
|
#endif
|
|
|
|
sdl = (struct sockaddr_dl *)(ifm + 1);
|
|
|
|
sdl->sdl_data[sdl->sdl_nlen] = 0;
|
1996-11-19 20:23:47 +00:00
|
|
|
strncpy(ifs0.int_name, sdl->sdl_data,
|
|
|
|
MIN(sizeof(ifs0.int_name), sdl->sdl_nlen));
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ifam->ifam_type != RTM_NEWADDR) {
|
1996-08-27 16:13:00 +00:00
|
|
|
logbad(1,"ifinit: out of sync");
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
rt_xaddrs(&info, (struct sockaddr *)(ifam+1),
|
1996-05-30 16:19:16 +00:00
|
|
|
(struct sockaddr *)ifam2,
|
|
|
|
ifam->ifam_addrs);
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* Prepare for the next address of this interface, which
|
|
|
|
* will be an alias.
|
|
|
|
* Do not output RIP or Router-Discovery packets via aliases.
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
memcpy(&ifs, &ifs0, sizeof(ifs));
|
|
|
|
ifs0.int_state |= (IS_ALIAS | IS_NO_RIP_OUT | IS_NO_RDISC);
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (INFO_IFA(&info) == 0) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(prev_complaints & COMP_NOADDR))
|
1996-09-16 16:51:32 +00:00
|
|
|
msglog("%s has no address",
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_name);
|
1996-05-30 16:19:16 +00:00
|
|
|
complaints |= COMP_NOADDR;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
if (INFO_IFA(&info)->sa_family != AF_INET) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(prev_complaints & COMP_NOT_INET))
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("%s: not AF_INET",
|
|
|
|
ifs.int_name);
|
1996-05-30 16:19:16 +00:00
|
|
|
complaints |= COMP_NOT_INET;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_addr = S_ADDR(INFO_IFA(&info));
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-09-16 16:51:32 +00:00
|
|
|
if (ntohl(ifs.int_addr)>>24 == 0
|
|
|
|
|| ntohl(ifs.int_addr)>>24 == 0xff) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-09-16 16:51:32 +00:00
|
|
|
if (!(prev_complaints & COMP_BADADDR))
|
|
|
|
msglog("%s has a bad address",
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_name);
|
1996-09-16 16:51:32 +00:00
|
|
|
complaints |= COMP_BADADDR;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifs.int_if_flags & IFF_LOOPBACK) {
|
2004-08-14 08:36:35 +00:00
|
|
|
ifs.int_state |= IS_NO_RIP | IS_NO_RDISC;
|
2005-12-20 18:18:37 +00:00
|
|
|
if (ifs.int_addr == htonl(INADDR_LOOPBACK))
|
2004-08-14 08:36:35 +00:00
|
|
|
ifs.int_state |= IS_PASSIVE;
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_dstaddr = ifs.int_addr;
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_mask = HOST_MASK;
|
|
|
|
ifs.int_ripv1_mask = HOST_MASK;
|
|
|
|
ifs.int_std_mask = std_mask(ifs.int_dstaddr);
|
|
|
|
ifs.int_net = ntohl(ifs.int_dstaddr);
|
|
|
|
if (!foundloopback) {
|
|
|
|
foundloopback = 1;
|
|
|
|
loopaddr = ifs.int_addr;
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_gate = loopaddr;
|
|
|
|
loop_rts.rts_router = loopaddr;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ifs.int_if_flags & IFF_POINTOPOINT) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (INFO_BRD(&info) == 0
|
|
|
|
|| INFO_BRD(&info)->sa_family != AF_INET) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(prev_complaints & COMP_NODST))
|
|
|
|
msglog("%s has a bad"
|
|
|
|
" destination address",
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_name);
|
1996-05-30 16:19:16 +00:00
|
|
|
complaints |= COMP_NODST;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_dstaddr = S_ADDR(INFO_BRD(&info));
|
1996-09-16 16:51:32 +00:00
|
|
|
if (ntohl(ifs.int_dstaddr)>>24 == 0
|
|
|
|
|| ntohl(ifs.int_dstaddr)>>24 == 0xff) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-09-16 16:51:32 +00:00
|
|
|
if (!(prev_complaints & COMP_NODST))
|
|
|
|
msglog("%s has a bad"
|
|
|
|
" destination address",
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_name);
|
1996-09-16 16:51:32 +00:00
|
|
|
complaints |= COMP_NODST;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
ifs.int_mask = HOST_MASK;
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_ripv1_mask = ntohl(S_ADDR(INFO_MASK(&info)));
|
1996-05-30 16:19:16 +00:00
|
|
|
ifs.int_std_mask = std_mask(ifs.int_dstaddr);
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_net = ntohl(ifs.int_dstaddr);
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (INFO_MASK(&info) == 0) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-11-19 20:23:47 +00:00
|
|
|
if (!(prev_complaints & COMP_NOMASK))
|
|
|
|
msglog("%s has no netmask",
|
|
|
|
ifs.int_name);
|
|
|
|
complaints |= COMP_NOMASK;
|
|
|
|
}
|
|
|
|
continue;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_dstaddr = ifs.int_addr;
|
|
|
|
ifs.int_mask = ntohl(S_ADDR(INFO_MASK(&info)));
|
|
|
|
ifs.int_ripv1_mask = ifs.int_mask;
|
|
|
|
ifs.int_std_mask = std_mask(ifs.int_addr);
|
|
|
|
ifs.int_net = ntohl(ifs.int_addr) & ifs.int_mask;
|
|
|
|
if (ifs.int_mask != ifs.int_std_mask)
|
|
|
|
ifs.int_state |= IS_SUBNET;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifs.int_if_flags & IFF_BROADCAST) {
|
|
|
|
if (INFO_BRD(&info) == 0) {
|
1999-05-02 10:51:54 +00:00
|
|
|
if (iff_up(ifs.int_if_flags)) {
|
1996-11-19 20:23:47 +00:00
|
|
|
if (!(prev_complaints
|
|
|
|
& COMP_NOBADR))
|
|
|
|
msglog("%s has"
|
|
|
|
"no broadcast address",
|
|
|
|
ifs.int_name);
|
|
|
|
complaints |= COMP_NOBADR;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ifs.int_brdaddr = S_ADDR(INFO_BRD(&info));
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
ifs.int_std_net = ifs.int_net & ifs.int_std_mask;
|
|
|
|
ifs.int_std_addr = htonl(ifs.int_std_net);
|
|
|
|
|
|
|
|
/* Use a minimum metric of one. Treat the interface metric
|
|
|
|
* (default 0) as an increment to the hop count of one.
|
|
|
|
*
|
|
|
|
* The metric obtained from the routing socket dump of
|
|
|
|
* interface addresses is wrong. It is not set by the
|
|
|
|
* SIOCSIFMETRIC ioctl.
|
|
|
|
*/
|
|
|
|
#ifdef SIOCGIFMETRIC
|
1996-11-19 20:23:47 +00:00
|
|
|
strncpy(ifr.ifr_name, ifs.int_name, sizeof(ifr.ifr_name));
|
1996-05-30 16:19:16 +00:00
|
|
|
if (ioctl(rt_sock, SIOCGIFMETRIC, &ifr) < 0) {
|
|
|
|
DBGERR(1, "ioctl(SIOCGIFMETRIC)");
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_metric = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
} else {
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_metric = ifr.ifr_metric;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
#else
|
1996-07-22 20:56:54 +00:00
|
|
|
ifs.int_metric = ifam->ifam_metric;
|
1996-05-30 16:19:16 +00:00
|
|
|
#endif
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifs.int_metric > HOPCNT_INFINITY) {
|
|
|
|
ifs.int_metric = 0;
|
|
|
|
if (!(prev_complaints & COMP_BAD_METRIC)
|
1999-05-02 10:51:54 +00:00
|
|
|
&& iff_up(ifs.int_if_flags)) {
|
1996-07-22 20:56:54 +00:00
|
|
|
complaints |= COMP_BAD_METRIC;
|
|
|
|
msglog("%s has a metric of %d",
|
1996-11-19 20:23:47 +00:00
|
|
|
ifs.int_name, ifs.int_metric);
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
/* See if this is a familiar interface.
|
|
|
|
* If so, stop worrying about it if it is the same.
|
|
|
|
* Start it over if it now is to somewhere else, as happens
|
|
|
|
* frequently with PPP and SLIP.
|
|
|
|
*/
|
1996-11-19 20:23:47 +00:00
|
|
|
ifp = ifwithname(ifs.int_name, ((ifs.int_state & IS_ALIAS)
|
|
|
|
? ifs.int_addr
|
|
|
|
: 0));
|
2016-05-14 22:40:08 +00:00
|
|
|
if (ifp != NULL) {
|
1996-05-30 16:19:16 +00:00
|
|
|
ifp->int_state |= IS_CHECKED;
|
|
|
|
|
|
|
|
if (0 != ((ifp->int_if_flags ^ ifs.int_if_flags)
|
|
|
|
& (IFF_BROADCAST
|
|
|
|
| IFF_LOOPBACK
|
|
|
|
| IFF_POINTOPOINT
|
|
|
|
| IFF_MULTICAST))
|
|
|
|
|| 0 != ((ifp->int_state ^ ifs.int_state)
|
|
|
|
& IS_ALIAS)
|
|
|
|
|| ifp->int_addr != ifs.int_addr
|
|
|
|
|| ifp->int_brdaddr != ifs.int_brdaddr
|
|
|
|
|| ifp->int_dstaddr != ifs.int_dstaddr
|
|
|
|
|| ifp->int_mask != ifs.int_mask
|
|
|
|
|| ifp->int_metric != ifs.int_metric) {
|
|
|
|
/* Forget old information about
|
|
|
|
* a changed interface.
|
|
|
|
*/
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("interface %s has changed",
|
1996-05-30 16:19:16 +00:00
|
|
|
ifp->int_name);
|
|
|
|
ifdel(ifp);
|
2016-05-14 22:40:08 +00:00
|
|
|
ifp = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 22:40:08 +00:00
|
|
|
if (ifp != NULL) {
|
1996-08-27 16:13:00 +00:00
|
|
|
/* The primary representative of an alias worries
|
|
|
|
* about how things are working.
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp->int_state & IS_ALIAS)
|
|
|
|
continue;
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
/* note interfaces that have been turned off
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
if (!iff_up(ifs.int_if_flags)) {
|
|
|
|
if (iff_up(ifp->int_if_flags)) {
|
1996-07-22 20:56:54 +00:00
|
|
|
msglog("interface %s to %s turned off",
|
|
|
|
ifp->int_name,
|
1996-11-19 20:23:47 +00:00
|
|
|
naddr_ntoa(ifp->int_dstaddr));
|
1996-07-22 20:56:54 +00:00
|
|
|
if_bad(ifp);
|
1999-05-02 10:51:54 +00:00
|
|
|
ifp->int_if_flags &= ~IFF_UP;
|
|
|
|
} else if (now.tv_sec>(ifp->int_data.ts
|
|
|
|
+ CHECK_BAD_INTERVAL)) {
|
|
|
|
trace_act("interface %s has been off"
|
2010-02-27 10:17:27 +00:00
|
|
|
" %jd seconds; forget it",
|
1999-05-02 10:51:54 +00:00
|
|
|
ifp->int_name,
|
2010-02-27 10:17:27 +00:00
|
|
|
(intmax_t)now.tv_sec -
|
2009-04-05 14:15:05 +00:00
|
|
|
ifp->int_data.ts);
|
1999-05-02 10:51:54 +00:00
|
|
|
ifdel(ifp);
|
2016-05-14 23:07:26 +00:00
|
|
|
ifp = NULL;
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* or that were off and are now ok */
|
1999-05-02 10:51:54 +00:00
|
|
|
if (!iff_up(ifp->int_if_flags)) {
|
|
|
|
ifp->int_if_flags |= IFF_UP;
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)if_ok(ifp, "");
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If it has been long enough,
|
|
|
|
* see if the interface is broken.
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (now.tv_sec < ifp->int_data.ts+CHECK_BAD_INTERVAL)
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
in = ifs.int_data.ipackets - ifp->int_data.ipackets;
|
|
|
|
ierr = ifs.int_data.ierrors - ifp->int_data.ierrors;
|
|
|
|
out = ifs.int_data.opackets - ifp->int_data.opackets;
|
|
|
|
oerr = ifs.int_data.oerrors - ifp->int_data.oerrors;
|
1996-05-30 16:19:16 +00:00
|
|
|
#ifdef sgi
|
1996-07-22 20:56:54 +00:00
|
|
|
/* Through at least IRIX 6.2, PPP and SLIP
|
1999-05-02 10:51:54 +00:00
|
|
|
* count packets dropped by the filters.
|
1996-07-22 20:56:54 +00:00
|
|
|
* But FDDI rings stuck non-operational count
|
|
|
|
* dropped packets as they wait for improvement.
|
|
|
|
*/
|
|
|
|
if (!(ifp->int_if_flags & IFF_POINTOPOINT))
|
|
|
|
oerr += (ifs.int_data.odrops
|
|
|
|
- ifp->int_data.odrops);
|
1996-05-30 16:19:16 +00:00
|
|
|
#endif
|
|
|
|
/* If the interface just awoke, restart the counters.
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp->int_data.ts == 0) {
|
|
|
|
ifp->int_data = ifs.int_data;
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_data = ifs.int_data;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1998-07-28 06:36:31 +00:00
|
|
|
/* Withhold judgment when the short error
|
1996-05-30 16:19:16 +00:00
|
|
|
* counters wrap or the interface is reset.
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ierr < 0 || in < 0 || oerr < 0 || out < 0) {
|
|
|
|
LIM_SEC(ifinit_timer,
|
|
|
|
now.tv_sec+CHECK_BAD_INTERVAL);
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
/* Withhold judgement when there is no traffic
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (in == 0 && out == 0 && ierr == 0 && oerr == 0)
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* It is bad if input or output is not working.
|
|
|
|
* Require presistent problems before marking it dead.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
if ((in <= ierr && ierr > 0)
|
|
|
|
|| (out <= oerr && oerr > 0)) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!(ifp->int_state & IS_SICK)) {
|
|
|
|
trace_act("interface %s to %s"
|
|
|
|
" sick: in=%d ierr=%d"
|
1996-11-19 20:23:47 +00:00
|
|
|
" out=%d oerr=%d",
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_name,
|
1996-11-19 20:23:47 +00:00
|
|
|
naddr_ntoa(ifp->int_dstaddr),
|
1996-07-22 20:56:54 +00:00
|
|
|
in, ierr, out, oerr);
|
|
|
|
if_sick(ifp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(ifp->int_state & IS_BROKE)) {
|
1996-11-19 20:23:47 +00:00
|
|
|
msglog("interface %s to %s broken:"
|
1996-07-22 20:56:54 +00:00
|
|
|
" in=%d ierr=%d out=%d oerr=%d",
|
|
|
|
ifp->int_name,
|
1996-11-19 20:23:47 +00:00
|
|
|
naddr_ntoa(ifp->int_dstaddr),
|
1996-07-22 20:56:54 +00:00
|
|
|
in, ierr, out, oerr);
|
|
|
|
if_bad(ifp);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise, it is active and healthy
|
|
|
|
*/
|
|
|
|
ifp->int_act_time = now.tv_sec;
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)if_ok(ifp, "");
|
1996-05-30 16:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* This is a new interface.
|
|
|
|
* If it is dead, forget it.
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
if (!iff_up(ifs.int_if_flags))
|
1996-07-22 20:56:54 +00:00
|
|
|
continue;
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* If it duplicates an existing interface,
|
|
|
|
* complain about it, mark the other one
|
|
|
|
* duplicated, and forget this one.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
1996-11-19 20:23:47 +00:00
|
|
|
ifp = check_dup(ifs.int_addr,ifs.int_dstaddr,ifs.int_mask,
|
|
|
|
ifs.int_if_flags);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (ifp != NULL) {
|
1999-05-02 10:51:54 +00:00
|
|
|
/* Ignore duplicates of itself, caused by having
|
|
|
|
* IP aliases on the same network.
|
|
|
|
*/
|
|
|
|
if (!strcmp(ifp->int_name, ifs.int_name))
|
|
|
|
continue;
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!(prev_complaints & COMP_DUP)) {
|
1996-05-30 16:19:16 +00:00
|
|
|
complaints |= COMP_DUP;
|
1996-12-11 20:59:33 +00:00
|
|
|
msglog("%s (%s%s%s) is duplicated by"
|
|
|
|
" %s (%s%s%s)",
|
|
|
|
ifs.int_name,
|
|
|
|
addrname(ifs.int_addr,ifs.int_mask,1),
|
|
|
|
((ifs.int_if_flags & IFF_POINTOPOINT)
|
|
|
|
? "-->" : ""),
|
|
|
|
((ifs.int_if_flags & IFF_POINTOPOINT)
|
|
|
|
? naddr_ntoa(ifs.int_dstaddr) : ""),
|
|
|
|
ifp->int_name,
|
|
|
|
addrname(ifp->int_addr,ifp->int_mask,1),
|
|
|
|
((ifp->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
? "-->" : ""),
|
|
|
|
((ifp->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
? naddr_ntoa(ifp->int_dstaddr) : ""));
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state |= IS_DUP;
|
|
|
|
continue;
|
1996-11-19 20:23:47 +00:00
|
|
|
}
|
|
|
|
|
2004-08-14 08:36:35 +00:00
|
|
|
if (0 == (ifs.int_if_flags & (IFF_POINTOPOINT | IFF_BROADCAST | IFF_LOOPBACK))) {
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("%s is neither broadcast, point-to-point,"
|
|
|
|
" nor loopback",
|
|
|
|
ifs.int_name);
|
|
|
|
if (!(ifs.int_state & IFF_MULTICAST))
|
|
|
|
ifs.int_state |= IS_NO_RDISC;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* It is new and ok. Add it to the list of interfaces
|
1996-07-22 20:56:54 +00:00
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
ifp = (struct interface *)rtmalloc(sizeof(*ifp), "ifinit ifp");
|
|
|
|
memcpy(ifp, &ifs, sizeof(*ifp));
|
1996-11-19 20:23:47 +00:00
|
|
|
get_parms(ifp);
|
|
|
|
if_link(ifp);
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_if("Add", ifp);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-08-27 16:13:00 +00:00
|
|
|
/* Notice likely bad netmask.
|
|
|
|
*/
|
|
|
|
if (!(prev_complaints & COMP_NETMASK)
|
1996-11-19 20:23:47 +00:00
|
|
|
&& !(ifp->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
&& ifp->int_addr != RIP_DEFAULT) {
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp1, &ifnet, int_list) {
|
1996-08-27 16:13:00 +00:00
|
|
|
if (ifp1->int_mask == ifp->int_mask)
|
|
|
|
continue;
|
|
|
|
if (ifp1->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
continue;
|
1996-11-19 20:23:47 +00:00
|
|
|
if (ifp1->int_dstaddr == RIP_DEFAULT)
|
|
|
|
continue;
|
2000-08-10 07:48:06 +00:00
|
|
|
/* ignore aliases on the right network */
|
|
|
|
if (!strcmp(ifp->int_name, ifp1->int_name))
|
|
|
|
continue;
|
1996-11-19 20:23:47 +00:00
|
|
|
if (on_net(ifp->int_dstaddr,
|
1996-08-27 16:13:00 +00:00
|
|
|
ifp1->int_net, ifp1->int_mask)
|
1996-11-19 20:23:47 +00:00
|
|
|
|| on_net(ifp1->int_dstaddr,
|
1996-08-27 16:13:00 +00:00
|
|
|
ifp->int_net, ifp->int_mask)) {
|
|
|
|
msglog("possible netmask problem"
|
1996-11-19 20:23:47 +00:00
|
|
|
" between %s:%s and %s:%s",
|
1996-08-27 16:13:00 +00:00
|
|
|
ifp->int_name,
|
|
|
|
addrname(htonl(ifp->int_net),
|
|
|
|
ifp->int_mask, 1),
|
|
|
|
ifp1->int_name,
|
|
|
|
addrname(htonl(ifp1->int_net),
|
|
|
|
ifp1->int_mask, 1));
|
|
|
|
complaints |= COMP_NETMASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(ifp->int_state & IS_ALIAS)) {
|
1996-11-19 20:23:47 +00:00
|
|
|
/* Count the # of directly connected networks.
|
|
|
|
*/
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(ifp->int_if_flags & IFF_LOOPBACK))
|
|
|
|
tot_interfaces++;
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!IS_RIP_OFF(ifp->int_state))
|
1996-05-30 16:19:16 +00:00
|
|
|
rip_interfaces++;
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* turn on router discovery and RIP If needed */
|
|
|
|
if_ok_rdisc(ifp);
|
|
|
|
rip_on(ifp);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* If we are multi-homed and have at least two interfaces
|
1996-05-30 16:19:16 +00:00
|
|
|
* listening to RIP, then output by default.
|
|
|
|
*/
|
|
|
|
if (!supplier_set && rip_interfaces > 1)
|
|
|
|
set_supplier();
|
|
|
|
|
|
|
|
/* If we are multi-homed, optionally advertise a route to
|
|
|
|
* our main address.
|
|
|
|
*/
|
2016-05-14 23:07:26 +00:00
|
|
|
if ((advertise_mhome && ifp)
|
1996-05-30 16:19:16 +00:00
|
|
|
|| (tot_interfaces > 1
|
|
|
|
&& mhome
|
2016-05-14 22:40:08 +00:00
|
|
|
&& (ifp = ifwithaddr(myaddr, 0, 0)) != NULL
|
1996-05-30 16:19:16 +00:00
|
|
|
&& foundloopback)) {
|
|
|
|
advertise_mhome = 1;
|
|
|
|
rt = rtget(myaddr, HOST_MASK);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (rt->rt_ifp != ifp
|
|
|
|
|| rt->rt_router != loopaddr) {
|
|
|
|
rtdelete(rt);
|
2016-05-14 22:40:08 +00:00
|
|
|
rt = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
} else {
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_ifp = ifp;
|
|
|
|
loop_rts.rts_metric = 0;
|
|
|
|
loop_rts.rts_time = rt->rt_time;
|
1996-05-30 16:19:16 +00:00
|
|
|
rtchange(rt, rt->rt_state | RS_MHOME,
|
1999-05-02 10:51:54 +00:00
|
|
|
&loop_rts, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt == NULL) {
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_ifp = ifp;
|
|
|
|
loop_rts.rts_metric = 0;
|
|
|
|
rtadd(myaddr, HOST_MASK, RS_MHOME, &loop_rts);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH_SAFE(ifp, &ifnet, int_list, ifp1) {
|
1996-05-30 16:19:16 +00:00
|
|
|
/* Forget any interfaces that have disappeared.
|
|
|
|
*/
|
|
|
|
if (!(ifp->int_state & (IS_CHECKED | IS_REMOTE))) {
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("interface %s has disappeared",
|
1996-05-30 16:19:16 +00:00
|
|
|
ifp->int_name);
|
|
|
|
ifdel(ifp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if ((ifp->int_state & IS_BROKE)
|
|
|
|
&& !(ifp->int_state & IS_PASSIVE))
|
1996-05-30 16:19:16 +00:00
|
|
|
LIM_SEC(ifinit_timer, now.tv_sec+CHECK_BAD_INTERVAL);
|
|
|
|
|
|
|
|
/* If we ever have a RIPv1 interface, assume we always will.
|
|
|
|
* It might come back if it ever goes away.
|
|
|
|
*/
|
1996-09-16 16:51:32 +00:00
|
|
|
if (!(ifp->int_state & IS_NO_RIPV1_OUT) && supplier)
|
|
|
|
have_ripv1_out = 1;
|
|
|
|
if (!(ifp->int_state & IS_NO_RIPV1_IN))
|
|
|
|
have_ripv1_in = 1;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 14:01:39 +00:00
|
|
|
LIST_FOREACH(ifp, &ifnet, int_list) {
|
1996-05-30 16:19:16 +00:00
|
|
|
/* Ensure there is always a network route for interfaces,
|
|
|
|
* after any dead interfaces have been deleted, which
|
|
|
|
* might affect routes for point-to-point links.
|
|
|
|
*/
|
1996-11-19 20:23:47 +00:00
|
|
|
if (!addrouteforif(ifp))
|
|
|
|
continue;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
/* Add routes to the local end of point-to-point interfaces
|
|
|
|
* using loopback.
|
|
|
|
*/
|
|
|
|
if ((ifp->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
&& !(ifp->int_state & IS_REMOTE)
|
|
|
|
&& foundloopback) {
|
|
|
|
/* Delete any routes to the network address through
|
|
|
|
* foreign routers. Remove even static routes.
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
del_static(ifp->int_addr, HOST_MASK, 0, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
rt = rtget(ifp->int_addr, HOST_MASK);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL && rt->rt_router != loopaddr) {
|
1996-05-30 16:19:16 +00:00
|
|
|
rtdelete(rt);
|
2016-05-14 22:40:08 +00:00
|
|
|
rt = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (!(rt->rt_state & RS_LOCAL)
|
|
|
|
|| rt->rt_metric > ifp->int_metric) {
|
|
|
|
ifp1 = ifp;
|
|
|
|
} else {
|
|
|
|
ifp1 = rt->rt_ifp;
|
|
|
|
}
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_ifp = ifp1;
|
|
|
|
loop_rts.rts_metric = 0;
|
|
|
|
loop_rts.rts_time = rt->rt_time;
|
|
|
|
rtchange(rt, ((rt->rt_state & ~RS_NET_SYN)
|
|
|
|
| (RS_IF|RS_LOCAL)),
|
|
|
|
&loop_rts, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
} else {
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_ifp = ifp;
|
|
|
|
loop_rts.rts_metric = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
rtadd(ifp->int_addr, HOST_MASK,
|
1999-05-02 10:51:54 +00:00
|
|
|
(RS_IF | RS_LOCAL), &loop_rts);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* add the authority routes */
|
2016-05-14 22:40:08 +00:00
|
|
|
for (intnetp = intnets; intnetp != NULL;
|
|
|
|
intnetp = intnetp->intnet_next) {
|
1996-07-22 20:56:54 +00:00
|
|
|
rt = rtget(intnetp->intnet_addr, intnetp->intnet_mask);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL
|
1996-07-22 20:56:54 +00:00
|
|
|
&& !(rt->rt_state & RS_NO_NET_SYN)
|
|
|
|
&& !(rt->rt_state & RS_NET_INT)) {
|
|
|
|
rtdelete(rt);
|
2016-05-14 22:40:08 +00:00
|
|
|
rt = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt == NULL) {
|
|
|
|
loop_rts.rts_ifp = NULL;
|
1999-05-02 10:51:54 +00:00
|
|
|
loop_rts.rts_metric = intnetp->intnet_metric-1;
|
1996-07-22 20:56:54 +00:00
|
|
|
rtadd(intnetp->intnet_addr, intnetp->intnet_mask,
|
1999-05-02 10:51:54 +00:00
|
|
|
RS_NET_SYN | RS_NET_INT, &loop_rts);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
prev_complaints = complaints;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1996-07-22 20:56:54 +00:00
|
|
|
check_net_syn(struct interface *ifp)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
struct rt_entry *rt;
|
1999-05-02 10:51:54 +00:00
|
|
|
static struct rt_spare new;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* Turn on the need to automatically synthesize a network route
|
|
|
|
* for this interface only if we are running RIPv1 on some other
|
|
|
|
* interface that is on a different class-A,B,or C network.
|
|
|
|
*/
|
|
|
|
if (have_ripv1_out || have_ripv1_in) {
|
|
|
|
ifp->int_state |= IS_NEED_NET_SYN;
|
|
|
|
rt = rtget(ifp->int_std_addr, ifp->int_std_mask);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL
|
1996-07-22 20:56:54 +00:00
|
|
|
&& 0 == (rt->rt_state & RS_NO_NET_SYN)
|
|
|
|
&& (!(rt->rt_state & RS_NET_SYN)
|
|
|
|
|| rt->rt_metric > ifp->int_metric)) {
|
|
|
|
rtdelete(rt);
|
2016-05-14 22:40:08 +00:00
|
|
|
rt = NULL;
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt == NULL) {
|
1999-05-02 10:51:54 +00:00
|
|
|
new.rts_ifp = ifp;
|
|
|
|
new.rts_gate = ifp->int_addr;
|
|
|
|
new.rts_router = ifp->int_addr;
|
|
|
|
new.rts_metric = ifp->int_metric;
|
1996-07-22 20:56:54 +00:00
|
|
|
rtadd(ifp->int_std_addr, ifp->int_std_mask,
|
1999-05-02 10:51:54 +00:00
|
|
|
RS_NET_SYN, &new);
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
} else {
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_state &= ~IS_NEED_NET_SYN;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
rt = rtget(ifp->int_std_addr,
|
|
|
|
ifp->int_std_mask);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL
|
1996-07-22 20:56:54 +00:00
|
|
|
&& (rt->rt_state & RS_NET_SYN)
|
1996-05-30 16:19:16 +00:00
|
|
|
&& rt->rt_ifp == ifp)
|
|
|
|
rtbad_sub(rt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Add route for interface if not currently installed.
|
|
|
|
* Create route to other end if a point-to-point link,
|
|
|
|
* otherwise a route to this (sub)network.
|
|
|
|
*/
|
2009-04-05 15:55:09 +00:00
|
|
|
static int /* 0=bad interface */
|
1996-05-30 16:19:16 +00:00
|
|
|
addrouteforif(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct rt_entry *rt;
|
1999-05-02 10:51:54 +00:00
|
|
|
static struct rt_spare new;
|
|
|
|
naddr dst;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* skip sick interfaces
|
|
|
|
*/
|
|
|
|
if (ifp->int_state & IS_BROKE)
|
1996-11-19 20:23:47 +00:00
|
|
|
return 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
/* If the interface on a subnet, then install a RIPv1 route to
|
|
|
|
* the network as well (unless it is sick).
|
|
|
|
*/
|
1996-07-22 20:56:54 +00:00
|
|
|
if (ifp->int_state & IS_SUBNET)
|
|
|
|
check_net_syn(ifp);
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
dst = (0 != (ifp->int_if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK))
|
|
|
|
? ifp->int_dstaddr
|
|
|
|
: htonl(ifp->int_net));
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
new.rts_ifp = ifp;
|
|
|
|
new.rts_router = ifp->int_addr;
|
|
|
|
new.rts_gate = ifp->int_addr;
|
|
|
|
new.rts_metric = ifp->int_metric;
|
|
|
|
new.rts_time = now.tv_sec;
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* If we are going to send packets to the gateway,
|
|
|
|
* it must be reachable using our physical interfaces
|
|
|
|
*/
|
|
|
|
if ((ifp->int_state & IS_REMOTE)
|
1996-12-11 20:59:33 +00:00
|
|
|
&& !(ifp->int_state & IS_EXTERNAL)
|
1996-11-19 20:23:47 +00:00
|
|
|
&& !check_remote(ifp))
|
|
|
|
return 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* We are finished if the correct main interface route exists.
|
1996-05-30 16:19:16 +00:00
|
|
|
* The right route must be for the right interface, not synthesized
|
|
|
|
* from a subnet, be a "gateway" or not as appropriate, and so forth.
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
del_static(dst, ifp->int_mask, 0, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
rt = rtget(dst, ifp->int_mask);
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt != NULL) {
|
1996-07-22 20:56:54 +00:00
|
|
|
if ((rt->rt_ifp != ifp
|
|
|
|
|| rt->rt_router != ifp->int_addr)
|
|
|
|
&& (!(ifp->int_state & IS_DUP)
|
|
|
|
|| rt->rt_ifp == 0
|
|
|
|
|| (rt->rt_ifp->int_state & IS_BROKE))) {
|
1996-05-30 16:19:16 +00:00
|
|
|
rtdelete(rt);
|
2016-05-14 22:40:08 +00:00
|
|
|
rt = NULL;
|
1996-05-30 16:19:16 +00:00
|
|
|
} else {
|
|
|
|
rtchange(rt, ((rt->rt_state | RS_IF)
|
1996-07-22 20:56:54 +00:00
|
|
|
& ~(RS_NET_SYN | RS_LOCAL)),
|
1999-05-02 10:51:54 +00:00
|
|
|
&new, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-14 22:40:08 +00:00
|
|
|
if (rt == NULL) {
|
1996-05-30 16:19:16 +00:00
|
|
|
if (ifp->int_transitions++ > 0)
|
1996-11-19 20:23:47 +00:00
|
|
|
trace_act("re-install interface %s",
|
1996-07-22 20:56:54 +00:00
|
|
|
ifp->int_name);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
rtadd(dst, ifp->int_mask, RS_IF, &new);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-11-19 20:23:47 +00:00
|
|
|
|
|
|
|
return 1;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|