2001-04-14 03:29:55 +04:00
|
|
|
/* $NetBSD: ns.c,v 1.21 2001/04/13 23:30:29 thorpej Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1994-05-13 10:10:16 +04:00
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)ns.c 8.5 (Berkeley) 2/9/95
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1996-02-14 01:13:43 +03:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1996-05-22 17:54:55 +04:00
|
|
|
#include <sys/proc.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
1996-02-14 01:13:43 +03:00
|
|
|
#include <netns/ns_var.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1995-06-13 12:36:58 +04:00
|
|
|
struct ns_ifaddrhead ns_ifaddr;
|
1993-04-09 16:00:07 +04:00
|
|
|
int ns_interfaces;
|
|
|
|
extern struct sockaddr_ns ns_netmask, ns_hostmask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic internet control operations (ioctl's).
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
1996-05-22 17:54:55 +04:00
|
|
|
ns_control(so, cmd, data, ifp, p)
|
1993-04-09 16:00:07 +04:00
|
|
|
struct socket *so;
|
1995-03-08 05:14:50 +03:00
|
|
|
u_long cmd;
|
1993-04-09 16:00:07 +04:00
|
|
|
caddr_t data;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet *ifp;
|
1996-05-22 17:54:55 +04:00
|
|
|
struct proc *p;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct ns_ifaddr *ia = 0;
|
1996-09-08 18:49:41 +04:00
|
|
|
struct ns_aliasreq *ifra = (struct ns_aliasreq *)data;
|
|
|
|
struct sockaddr_ns oldaddr;
|
1996-10-11 03:25:50 +04:00
|
|
|
int error = 0, dstIsNew, hostIsNew;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find address for this interface, if it exists.
|
|
|
|
*/
|
1996-09-08 18:49:41 +04:00
|
|
|
if (ifp)
|
|
|
|
for (ia = ns_ifaddr.tqh_first; ia != 0; ia = ia->ia_list.tqe_next)
|
|
|
|
if (ia->ia_ifp == ifp)
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCAIFADDR:
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
if (ifra->ifra_addr.sns_family == AF_NS)
|
1996-09-08 18:49:41 +04:00
|
|
|
for (; ia; ia = ia->ia_list.tqe_next) {
|
|
|
|
if (ia->ia_ifp == ifp &&
|
|
|
|
ns_neteq(ia->ia_addr.sns_addr, ifra->ifra_addr.sns_addr))
|
|
|
|
break;
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
if (cmd == SIOCDIFADDR && ia == 0)
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
1996-09-08 18:49:41 +04:00
|
|
|
if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag)))
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
if (ifp == 0)
|
|
|
|
panic("ns_control");
|
1995-06-13 12:36:58 +04:00
|
|
|
if (ia == 0) {
|
1996-09-08 18:49:41 +04:00
|
|
|
MALLOC(ia, struct ns_ifaddr *, sizeof(*ia),
|
|
|
|
M_IFADDR, M_WAITOK);
|
1995-06-13 12:36:58 +04:00
|
|
|
if (ia == 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
return (ENOBUFS);
|
1995-06-13 12:36:58 +04:00
|
|
|
bzero((caddr_t)ia, sizeof(*ia));
|
|
|
|
TAILQ_INSERT_TAIL(&ns_ifaddr, ia, ia_list);
|
2000-02-02 01:52:04 +03:00
|
|
|
IFAREF((struct ifaddr *)ia);
|
1995-06-13 12:36:58 +04:00
|
|
|
TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia,
|
|
|
|
ifa_list);
|
2000-02-02 01:52:04 +03:00
|
|
|
IFAREF((struct ifaddr *)ia);
|
1995-06-13 12:36:58 +04:00
|
|
|
ia->ia_ifa.ifa_addr = snstosa(&ia->ia_addr);
|
|
|
|
ia->ia_ifa.ifa_netmask = snstosa(&ns_netmask);
|
|
|
|
ia->ia_ifa.ifa_dstaddr = snstosa(&ia->ia_dstaddr);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
|
|
|
ia->ia_broadaddr.sns_len = sizeof(ia->ia_addr);
|
1996-09-08 18:49:41 +04:00
|
|
|
ia->ia_broadaddr.sns_family = AF_NS;
|
1993-04-09 16:00:07 +04:00
|
|
|
ia->ia_broadaddr.sns_addr.x_host = ns_broadhost;
|
|
|
|
}
|
1996-09-08 18:49:41 +04:00
|
|
|
ia->ia_ifp = ifp;
|
|
|
|
if ((ifp->if_flags & IFF_LOOPBACK) == 0)
|
|
|
|
ns_interfaces++;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-09-08 18:49:41 +04:00
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-09-08 18:49:41 +04:00
|
|
|
case SIOCGIFADDR:
|
|
|
|
case SIOCGIFDSTADDR:
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
if (ia == 0)
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
break;
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (cmd) {
|
1996-09-08 18:49:41 +04:00
|
|
|
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
*satosns(&ifr->ifr_addr) = ia->ia_addr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
if ((ifp->if_flags & IFF_BROADCAST) == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
*satosns(&ifr->ifr_dstaddr) = ia->ia_broadaddr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFDSTADDR:
|
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
*satosns(&ifr->ifr_dstaddr) = ia->ia_dstaddr;
|
|
|
|
break;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
|
|
|
|
return (EINVAL);
|
1996-09-08 18:49:41 +04:00
|
|
|
oldaddr = ia->ia_dstaddr;
|
|
|
|
ia->ia_dstaddr = *satosns(&ifr->ifr_dstaddr);
|
|
|
|
if (ifp->if_ioctl && (error = (*ifp->if_ioctl)
|
|
|
|
(ifp, SIOCSIFDSTADDR, (caddr_t)ia))) {
|
|
|
|
ia->ia_dstaddr = oldaddr;
|
|
|
|
return (error);
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ia->ia_flags & IFA_ROUTE) {
|
1996-09-08 18:49:41 +04:00
|
|
|
ia->ia_ifa.ifa_dstaddr = snstosa(&oldaddr);
|
1993-04-09 16:00:07 +04:00
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
|
1996-09-08 18:49:41 +04:00
|
|
|
ia->ia_ifa.ifa_dstaddr = snstosa(&ia->ia_dstaddr);
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-09-08 18:49:41 +04:00
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
1995-06-13 12:36:58 +04:00
|
|
|
return (ns_ifinit(ifp, ia, satosns(&ifr->ifr_addr), 1));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
case SIOCAIFADDR:
|
1996-09-08 18:49:41 +04:00
|
|
|
dstIsNew = 0;
|
|
|
|
hostIsNew = 1;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ia->ia_addr.sns_family == AF_NS) {
|
|
|
|
if (ifra->ifra_addr.sns_len == 0) {
|
|
|
|
ifra->ifra_addr = ia->ia_addr;
|
|
|
|
hostIsNew = 0;
|
1996-09-08 18:49:41 +04:00
|
|
|
} else if (ns_neteq(ifra->ifra_addr.sns_addr, ia->ia_addr.sns_addr))
|
1993-04-09 16:00:07 +04:00
|
|
|
hostIsNew = 0;
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) &&
|
|
|
|
(ifra->ifra_dstaddr.sns_family == AF_NS)) {
|
1996-09-08 18:49:41 +04:00
|
|
|
ns_ifscrub(ifp, ia);
|
1993-04-09 16:00:07 +04:00
|
|
|
ia->ia_dstaddr = ifra->ifra_dstaddr;
|
|
|
|
dstIsNew = 1;
|
|
|
|
}
|
|
|
|
if (ifra->ifra_addr.sns_family == AF_NS &&
|
1996-09-08 18:49:41 +04:00
|
|
|
(hostIsNew || dstIsNew))
|
1993-04-09 16:00:07 +04:00
|
|
|
error = ns_ifinit(ifp, ia, &ifra->ifra_addr, 0);
|
|
|
|
return (error);
|
|
|
|
|
1996-09-08 18:49:41 +04:00
|
|
|
case SIOCDIFADDR:
|
2000-02-02 01:52:04 +03:00
|
|
|
ns_purgeaddr(&ia->ia_ifa, ifp);
|
1996-09-08 18:49:41 +04:00
|
|
|
break;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
default:
|
1996-09-08 18:49:41 +04:00
|
|
|
if (ifp == 0 || ifp->if_ioctl == 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
return ((*ifp->if_ioctl)(ifp, cmd, data));
|
|
|
|
}
|
1996-09-08 18:49:41 +04:00
|
|
|
return (0);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
2000-02-02 01:52:04 +03:00
|
|
|
void
|
|
|
|
ns_purgeaddr(ifa, ifp)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct ns_ifaddr *ia = (void *) ifa;
|
|
|
|
|
|
|
|
ns_ifscrub(ifp, ia);
|
|
|
|
TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
|
|
|
|
IFAFREE(&ia->ia_ifa);
|
|
|
|
TAILQ_REMOVE(&ns_ifaddr, ia, ia_list);
|
|
|
|
IFAFREE((&ia->ia_ifa));
|
|
|
|
if (0 == --ns_interfaces) {
|
|
|
|
/*
|
|
|
|
* We reset to virginity and start all over again
|
|
|
|
*/
|
|
|
|
ns_thishost = ns_zerohost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-03 02:28:08 +03:00
|
|
|
void
|
|
|
|
ns_purgeif(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct ifaddr *ifa, *nifa;
|
|
|
|
|
|
|
|
for (ifa = TAILQ_FIRST(&ifp->if_addrlist); ifa != NULL; ifa = nifa) {
|
|
|
|
nifa = TAILQ_NEXT(ifa, ifa_list);
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_NS)
|
|
|
|
continue;
|
|
|
|
ns_purgeaddr(ifa, ifp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1998-09-13 19:21:32 +04:00
|
|
|
* Delete any previous route for an old address.
|
|
|
|
*/
|
1996-02-14 01:13:43 +03:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
ns_ifscrub(ifp, ia)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ns_ifaddr *ia;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-09-08 18:49:41 +04:00
|
|
|
|
|
|
|
if ((ia->ia_flags & IFA_ROUTE) == 0)
|
|
|
|
return;
|
|
|
|
if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
|
|
|
|
else
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
|
|
|
|
ia->ia_flags &= ~IFA_ROUTE;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Initialize an interface's internet address
|
|
|
|
* and routing table entry.
|
|
|
|
*/
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
1993-04-09 16:00:07 +04:00
|
|
|
ns_ifinit(ifp, ia, sns, scrub)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ns_ifaddr *ia;
|
|
|
|
struct sockaddr_ns *sns;
|
1996-02-14 01:13:43 +03:00
|
|
|
int scrub;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
struct sockaddr_ns oldaddr;
|
2000-03-30 16:51:13 +04:00
|
|
|
union ns_host *h = &ia->ia_addr.sns_addr.x_host;
|
2001-04-14 03:29:55 +04:00
|
|
|
int s = splnet(), error;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up new addresses.
|
|
|
|
*/
|
|
|
|
oldaddr = ia->ia_addr;
|
|
|
|
ia->ia_addr = *sns;
|
|
|
|
/*
|
|
|
|
* The convention we shall adopt for naming is that
|
|
|
|
* a supplied address of zero means that "we don't care".
|
|
|
|
* if there is a single interface, use the address of that
|
|
|
|
* interface as our 6 byte host address.
|
|
|
|
* if there are multiple interfaces, use any address already
|
|
|
|
* used.
|
|
|
|
*
|
|
|
|
* Give the interface a chance to initialize
|
|
|
|
* if this is its first address,
|
|
|
|
* and to validate the address if necessary.
|
|
|
|
*/
|
|
|
|
if (ns_hosteqnh(ns_thishost, ns_zerohost)) {
|
|
|
|
if (ifp->if_ioctl &&
|
1994-05-13 10:10:16 +04:00
|
|
|
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR,
|
1995-02-01 12:10:38 +03:00
|
|
|
(caddr_t)ia)))
|
|
|
|
goto bad;
|
1993-04-09 16:00:07 +04:00
|
|
|
ns_thishost = *h;
|
|
|
|
} else if (ns_hosteqnh(sns->sns_addr.x_host, ns_zerohost)
|
|
|
|
|| ns_hosteqnh(sns->sns_addr.x_host, ns_thishost)) {
|
|
|
|
*h = ns_thishost;
|
|
|
|
if (ifp->if_ioctl &&
|
1994-05-13 10:10:16 +04:00
|
|
|
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR,
|
1995-02-01 12:10:38 +03:00
|
|
|
(caddr_t)ia)))
|
|
|
|
goto bad;
|
|
|
|
if (!ns_hosteqnh(ns_thishost, *h)) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
} else {
|
1995-02-01 12:10:38 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1994-05-13 10:10:16 +04:00
|
|
|
ia->ia_ifa.ifa_metric = ifp->if_metric;
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* Add route for the network.
|
|
|
|
*/
|
|
|
|
if (scrub) {
|
1995-06-13 12:36:58 +04:00
|
|
|
ia->ia_ifa.ifa_addr = snstosa(&oldaddr);
|
1993-04-09 16:00:07 +04:00
|
|
|
ns_ifscrub(ifp, ia);
|
1995-06-13 12:36:58 +04:00
|
|
|
ia->ia_ifa.ifa_addr = snstosa(&ia->ia_addr);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT)
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
|
|
|
|
else {
|
1994-05-13 10:10:16 +04:00
|
|
|
ia->ia_broadaddr.sns_addr.x_net = ia->ia_addr.sns_addr.x_net;
|
1993-04-09 16:00:07 +04:00
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
|
|
|
|
}
|
|
|
|
ia->ia_flags |= IFA_ROUTE;
|
1995-02-01 12:10:38 +03:00
|
|
|
splx(s);
|
1993-04-09 16:00:07 +04:00
|
|
|
return (0);
|
1995-02-01 12:10:38 +03:00
|
|
|
bad:
|
|
|
|
ia->ia_addr = oldaddr;
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return address info for specified internet network.
|
|
|
|
*/
|
|
|
|
struct ns_ifaddr *
|
|
|
|
ns_iaonnetof(dst)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ns_addr *dst;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ns_ifaddr *ia;
|
|
|
|
struct ns_addr *compare;
|
|
|
|
struct ifnet *ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct ns_ifaddr *ia_maybe = 0;
|
|
|
|
union ns_net net = dst->x_net;
|
|
|
|
|
1995-06-13 12:36:58 +04:00
|
|
|
for (ia = ns_ifaddr.tqh_first; ia != 0; ia = ia->ia_list.tqe_next) {
|
1996-02-14 01:13:43 +03:00
|
|
|
if ((ifp = ia->ia_ifp) != NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT) {
|
|
|
|
compare = &satons_addr(ia->ia_dstaddr);
|
|
|
|
if (ns_hosteq(*dst, *compare))
|
|
|
|
return (ia);
|
1994-05-13 10:10:16 +04:00
|
|
|
if (ns_neteqnn(net, ia->ia_addr.sns_addr.x_net))
|
1993-04-09 16:00:07 +04:00
|
|
|
ia_maybe = ia;
|
|
|
|
} else {
|
1994-05-13 10:10:16 +04:00
|
|
|
if (ns_neteqnn(net, ia->ia_addr.sns_addr.x_net))
|
1993-04-09 16:00:07 +04:00
|
|
|
return (ia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ia_maybe);
|
|
|
|
}
|