2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1995-10-26 20:31:59 +00:00
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
2009-06-21 21:42:29 +00:00
|
|
|
* The Regents of the University of California.
|
|
|
|
* Copyright (c) 2009 Robert N. M. Watson
|
|
|
|
* All rights reserved.
|
1995-10-26 20:31:59 +00: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.
|
2007-01-08 22:14:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995, Mike Mitchell
|
|
|
|
*
|
|
|
|
* 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.
|
1995-10-26 20:31:59 +00:00
|
|
|
* 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.
|
2005-01-02 15:13:59 +00:00
|
|
|
*
|
1995-11-04 09:03:47 +00:00
|
|
|
* @(#)ipx.c
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 05:37:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/param.h>
|
2004-08-28 15:24:53 +00:00
|
|
|
#include <sys/kernel.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/systm.h>
|
2009-06-21 21:04:12 +00:00
|
|
|
#include <sys/lock.h>
|
1997-06-26 19:36:03 +00:00
|
|
|
#include <sys/malloc.h>
|
2007-06-13 22:42:43 +00:00
|
|
|
#include <sys/priv.h>
|
2009-06-21 21:04:12 +00:00
|
|
|
#include <sys/rwlock.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
1997-05-10 09:58:58 +00:00
|
|
|
#include <netipx/ipx_var.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2004-08-28 15:24:53 +00:00
|
|
|
/*
|
2009-06-21 21:04:12 +00:00
|
|
|
* The IPX-layer address list is protected by ipx_ifaddr_rw.
|
2004-08-28 15:24:53 +00:00
|
|
|
*/
|
2009-06-21 21:04:12 +00:00
|
|
|
struct rwlock ipx_ifaddr_rw;
|
2009-06-24 20:57:50 +00:00
|
|
|
struct ipx_ifaddrhead ipx_ifaddrhead;
|
1997-05-10 09:58:58 +00:00
|
|
|
|
2009-06-21 16:56:49 +00:00
|
|
|
static void ipx_ifscrub(struct ifnet *ifp, struct ipx_ifaddr *ia);
|
|
|
|
static int ipx_ifinit(struct ifnet *ifp, struct ipx_ifaddr *ia,
|
|
|
|
struct sockaddr_ipx *sipx, int scrub);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic internet control operations (ioctl's).
|
|
|
|
*/
|
|
|
|
int
|
2007-05-11 10:38:34 +00:00
|
|
|
ipx_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
|
|
|
|
struct thread *td)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2007-05-11 10:38:34 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct ipx_aliasreq *ifra = (struct ipx_aliasreq *)data;
|
2009-06-24 20:57:50 +00:00
|
|
|
struct ipx_ifaddr *ia;
|
1995-10-26 20:31:59 +00:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
int dstIsNew, hostIsNew;
|
2009-06-24 16:52:23 +00:00
|
|
|
int error, priv;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find address for this interface, if it exists.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ifp == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
return (EADDRNOTAVAIL);
|
2009-06-21 21:42:29 +00:00
|
|
|
|
2009-06-24 16:52:23 +00:00
|
|
|
IPX_IFADDR_RLOCK();
|
2009-06-24 20:57:50 +00:00
|
|
|
TAILQ_FOREACH(ia, &ipx_ifaddrhead, ia_link) {
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ia->ia_ifp == ifp)
|
|
|
|
break;
|
2009-06-24 20:57:50 +00:00
|
|
|
}
|
2009-06-24 16:52:23 +00:00
|
|
|
if (ia != NULL)
|
|
|
|
ifa_ref(&ia->ia_ifa);
|
|
|
|
IPX_IFADDR_RUNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2009-06-24 16:52:23 +00:00
|
|
|
error = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGIFADDR:
|
2009-06-21 21:42:29 +00:00
|
|
|
if (ia == NULL) {
|
|
|
|
error = EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
*(struct sockaddr_ipx *)&ifr->ifr_addr = ia->ia_addr;
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
case SIOCGIFBRDADDR:
|
2009-06-21 21:42:29 +00:00
|
|
|
if (ia == NULL) {
|
|
|
|
error = EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_BROADCAST) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
*(struct sockaddr_ipx *)&ifr->ifr_dstaddr = ia->ia_broadaddr;
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
case SIOCGIFDSTADDR:
|
2009-06-21 21:42:29 +00:00
|
|
|
if (ia == NULL) {
|
|
|
|
error = EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
*(struct sockaddr_ipx *)&ifr->ifr_dstaddr = ia->ia_dstaddr;
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCAIFADDR:
|
|
|
|
case SIOCDIFADDR:
|
2008-09-17 15:49:44 +00:00
|
|
|
priv = (cmd == SIOCAIFADDR) ? PRIV_NET_ADDIFADDR :
|
|
|
|
PRIV_NET_DELIFADDR;
|
|
|
|
if (td && (error = priv_check(td, priv)) != 0)
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
2009-06-24 16:52:23 +00:00
|
|
|
|
|
|
|
IPX_IFADDR_RLOCK();
|
|
|
|
if (ifra->ifra_addr.sipx_family == AF_IPX) {
|
2009-06-24 20:57:50 +00:00
|
|
|
struct ipx_ifaddr *oia;
|
|
|
|
|
|
|
|
for (oia = ia; ia; ia = TAILQ_NEXT(ia, ia_link)) {
|
2009-06-24 16:52:23 +00:00
|
|
|
if (ia->ia_ifp == ifp &&
|
|
|
|
ipx_neteq(ia->ia_addr.sipx_addr,
|
|
|
|
ifra->ifra_addr.sipx_addr))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (oia != NULL && oia != ia)
|
|
|
|
ifa_free(&oia->ia_ifa);
|
|
|
|
if (ia != NULL && oia != ia)
|
|
|
|
ifa_ref(&ia->ia_ifa);
|
|
|
|
}
|
|
|
|
IPX_IFADDR_RUNLOCK();
|
2009-06-21 21:42:29 +00:00
|
|
|
if (cmd == SIOCDIFADDR && ia == NULL) {
|
|
|
|
error = EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
2008-09-17 15:49:44 +00:00
|
|
|
if (td && (error = priv_check(td, PRIV_NET_SETLLADDR)) != 0)
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ia == NULL) {
|
2009-06-24 16:52:23 +00:00
|
|
|
ia = malloc(sizeof(*ia), M_IFADDR, M_NOWAIT | M_ZERO);
|
|
|
|
if (ia == NULL) {
|
2009-06-21 21:42:29 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
|
|
|
}
|
1996-12-13 21:29:07 +00:00
|
|
|
ifa = (struct ifaddr *)ia;
|
2009-06-21 19:30:33 +00:00
|
|
|
ifa_init(ifa);
|
1995-10-26 20:31:59 +00:00
|
|
|
ia->ia_ifp = ifp;
|
1996-12-13 21:29:07 +00:00
|
|
|
ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr;
|
|
|
|
ifa->ifa_netmask = (struct sockaddr *)&ipx_netmask;
|
|
|
|
ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
|
|
|
ia->ia_broadaddr.sipx_family = AF_IPX;
|
2009-06-21 16:56:49 +00:00
|
|
|
ia->ia_broadaddr.sipx_len =
|
|
|
|
sizeof(ia->ia_addr);
|
|
|
|
ia->ia_broadaddr.sipx_addr.x_host =
|
|
|
|
ipx_broadhost;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2009-06-24 20:57:50 +00:00
|
|
|
ifa_ref(&ia->ia_ifa); /* ipx_ifaddrhead */
|
2009-06-24 16:52:23 +00:00
|
|
|
IPX_IFADDR_WLOCK();
|
2009-06-24 20:57:50 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ipx_ifaddrhead, ia, ia_link);
|
2009-06-24 16:52:23 +00:00
|
|
|
IPX_IFADDR_WUNLOCK();
|
|
|
|
|
|
|
|
ifa_ref(&ia->ia_ifa); /* if_addrhead */
|
2012-01-05 19:00:36 +00:00
|
|
|
IF_ADDR_WLOCK(ifp);
|
2009-06-21 20:08:07 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
|
2012-01-05 19:00:36 +00:00
|
|
|
IF_ADDR_WUNLOCK(ifp);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2008-09-17 15:49:44 +00:00
|
|
|
break;
|
2009-06-21 16:56:49 +00:00
|
|
|
|
2008-09-17 15:49:44 +00:00
|
|
|
default:
|
|
|
|
if (td && (error = priv_check(td, PRIV_NET_HWIOCTL)) != 0)
|
2009-06-21 21:42:29 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFDSTADDR:
|
2009-06-21 21:42:29 +00:00
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ia->ia_flags & IFA_ROUTE) {
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
|
|
|
|
ia->ia_flags &= ~IFA_ROUTE;
|
|
|
|
}
|
|
|
|
if (ifp->if_ioctl) {
|
2009-06-21 16:56:49 +00:00
|
|
|
error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR,
|
|
|
|
(void *)ia);
|
2009-06-24 16:52:23 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
*(struct sockaddr *)&ia->ia_dstaddr = ifr->ifr_dstaddr;
|
2009-06-24 16:52:23 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
2009-06-21 21:42:29 +00:00
|
|
|
error = ipx_ifinit(ifp, ia,
|
|
|
|
(struct sockaddr_ipx *)&ifr->ifr_addr, 1);
|
2009-06-24 16:52:23 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
ipx_ifscrub(ifp, ia);
|
1996-12-13 21:29:07 +00:00
|
|
|
ifa = (struct ifaddr *)ia;
|
2009-06-24 16:52:23 +00:00
|
|
|
|
2012-01-05 19:00:36 +00:00
|
|
|
IF_ADDR_WLOCK(ifp);
|
1996-12-13 21:29:07 +00:00
|
|
|
TAILQ_REMOVE(&ifp->if_addrhead, ifa, ifa_link);
|
2012-01-05 19:00:36 +00:00
|
|
|
IF_ADDR_WUNLOCK(ifp);
|
2009-06-24 16:52:23 +00:00
|
|
|
ifa_free(ifa); /* if_addrhead */
|
|
|
|
|
|
|
|
IPX_IFADDR_WLOCK();
|
2009-06-24 20:57:50 +00:00
|
|
|
TAILQ_REMOVE(&ipx_ifaddrhead, ia, ia_link);
|
2009-06-21 21:42:29 +00:00
|
|
|
IPX_IFADDR_WUNLOCK();
|
2009-06-24 20:57:50 +00:00
|
|
|
ifa_free(&ia->ia_ifa); /* ipx_ifaddrhead */
|
2009-06-24 16:52:23 +00:00
|
|
|
goto out;
|
2005-01-02 15:13:59 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
case SIOCAIFADDR:
|
1997-05-10 09:58:58 +00:00
|
|
|
dstIsNew = 0;
|
|
|
|
hostIsNew = 1;
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ia->ia_addr.sipx_family == AF_IPX) {
|
|
|
|
if (ifra->ifra_addr.sipx_len == 0) {
|
|
|
|
ifra->ifra_addr = ia->ia_addr;
|
|
|
|
hostIsNew = 0;
|
|
|
|
} else if (ipx_neteq(ifra->ifra_addr.sipx_addr,
|
|
|
|
ia->ia_addr.sipx_addr))
|
|
|
|
hostIsNew = 0;
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_POINTOPOINT) &&
|
|
|
|
(ifra->ifra_dstaddr.sipx_family == AF_IPX)) {
|
|
|
|
if (hostIsNew == 0)
|
|
|
|
ipx_ifscrub(ifp, ia);
|
|
|
|
ia->ia_dstaddr = ifra->ifra_dstaddr;
|
|
|
|
dstIsNew = 1;
|
|
|
|
}
|
|
|
|
if (ifra->ifra_addr.sipx_family == AF_IPX &&
|
|
|
|
(hostIsNew || dstIsNew))
|
|
|
|
error = ipx_ifinit(ifp, ia, &ifra->ifra_addr, 0);
|
2009-06-24 16:52:23 +00:00
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
default:
|
2009-06-24 16:52:23 +00:00
|
|
|
if (ifp->if_ioctl == NULL) {
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
error = ((*ifp->if_ioctl)(ifp, cmd, data));
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2009-06-21 21:42:29 +00:00
|
|
|
|
|
|
|
out:
|
2009-06-24 16:52:23 +00:00
|
|
|
if (ia != NULL)
|
|
|
|
ifa_free(&ia->ia_ifa);
|
2009-06-21 21:42:29 +00:00
|
|
|
return (error);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-06-21 16:56:49 +00:00
|
|
|
* Delete any previous route for an old address.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
static void
|
2007-05-11 10:38:34 +00:00
|
|
|
ipx_ifscrub(struct ifnet *ifp, struct ipx_ifaddr *ia)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2007-05-11 10:38:34 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ia->ia_flags & IFA_ROUTE) {
|
|
|
|
if (ifp->if_flags & 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;
|
|
|
|
}
|
|
|
|
}
|
2009-06-21 16:56:49 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2009-06-21 16:56:49 +00:00
|
|
|
* Initialize an interface's internet address and routing table entry.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
static int
|
2007-05-11 10:38:34 +00:00
|
|
|
ipx_ifinit(struct ifnet *ifp, struct ipx_ifaddr *ia,
|
|
|
|
struct sockaddr_ipx *sipx, int scrub)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_ipx oldaddr;
|
|
|
|
int s = splimp(), error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up new addresses.
|
|
|
|
*/
|
|
|
|
oldaddr = ia->ia_addr;
|
|
|
|
ia->ia_addr = *sipx;
|
1997-05-10 09:58:58 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2009-06-21 16:56:49 +00:00
|
|
|
* The convention we shall adopt for naming is that a supplied
|
|
|
|
* address of zero means that "we don't care". Use the MAC address
|
|
|
|
* of the interface. If it is an interface without a MAC address,
|
|
|
|
* like a serial line, the address must be supplied.
|
1995-10-26 20:31:59 +00:00
|
|
|
*
|
2009-06-21 16:56:49 +00:00
|
|
|
* Give the interface a chance to initialize if this is its first
|
|
|
|
* address, and to validate the address if necessary.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ifp->if_ioctl != NULL &&
|
|
|
|
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (void *)ia))) {
|
1995-10-26 20:31:59 +00:00
|
|
|
ia->ia_addr = oldaddr;
|
|
|
|
splx(s);
|
1997-05-10 09:58:58 +00:00
|
|
|
return (error);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
splx(s);
|
1995-10-26 20:31:59 +00:00
|
|
|
ia->ia_ifa.ifa_metric = ifp->if_metric;
|
2009-06-21 16:56:49 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Add route for the network.
|
|
|
|
*/
|
|
|
|
if (scrub) {
|
|
|
|
ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr;
|
|
|
|
ipx_ifscrub(ifp, ia);
|
|
|
|
ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
|
|
|
|
}
|
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT)
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
|
|
|
|
else {
|
|
|
|
ia->ia_broadaddr.sipx_addr.x_net = ia->ia_addr.sipx_addr.x_net;
|
|
|
|
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
|
|
|
|
}
|
|
|
|
ia->ia_flags |= IFA_ROUTE;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return address info for specified internet network.
|
|
|
|
*/
|
|
|
|
struct ipx_ifaddr *
|
2007-05-11 10:38:34 +00:00
|
|
|
ipx_iaonnetof(struct ipx_addr *dst)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2007-05-11 10:38:34 +00:00
|
|
|
struct ipx_ifaddr *ia;
|
|
|
|
struct ipx_addr *compare;
|
|
|
|
struct ifnet *ifp;
|
1997-05-10 09:58:58 +00:00
|
|
|
struct ipx_ifaddr *ia_maybe = NULL;
|
1995-10-26 20:31:59 +00:00
|
|
|
union ipx_net net = dst->x_net;
|
|
|
|
|
2009-06-21 21:04:12 +00:00
|
|
|
IPX_IFADDR_LOCK_ASSERT();
|
|
|
|
|
2009-06-24 20:57:50 +00:00
|
|
|
TAILQ_FOREACH(ia, &ipx_ifaddrhead, ia_link) {
|
1997-05-10 09:58:58 +00:00
|
|
|
if ((ifp = ia->ia_ifp) != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT) {
|
|
|
|
compare = &satoipx_addr(ia->ia_dstaddr);
|
|
|
|
if (ipx_hosteq(*dst, *compare))
|
|
|
|
return (ia);
|
2009-06-21 16:56:49 +00:00
|
|
|
if (ipx_neteqnn(net,
|
|
|
|
ia->ia_addr.sipx_addr.x_net))
|
1995-10-26 20:31:59 +00:00
|
|
|
ia_maybe = ia;
|
|
|
|
} else {
|
2009-06-21 16:56:49 +00:00
|
|
|
if (ipx_neteqnn(net,
|
|
|
|
ia->ia_addr.sipx_addr.x_net))
|
1995-10-26 20:31:59 +00:00
|
|
|
return (ia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ia_maybe);
|
|
|
|
}
|
1997-06-26 19:36:03 +00:00
|
|
|
|
|
|
|
void
|
2007-05-11 10:38:34 +00:00
|
|
|
ipx_printhost(struct ipx_addr *addr)
|
1997-06-26 19:36:03 +00:00
|
|
|
{
|
|
|
|
u_short port;
|
|
|
|
struct ipx_addr work = *addr;
|
2007-05-11 10:38:34 +00:00
|
|
|
char *p; u_char *q;
|
|
|
|
char *net = "", *host = "";
|
1997-06-26 19:36:03 +00:00
|
|
|
char cport[10], chost[15], cnet[15];
|
|
|
|
|
|
|
|
port = ntohs(work.x_port);
|
|
|
|
|
|
|
|
if (ipx_nullnet(work) && ipx_nullhost(work)) {
|
|
|
|
if (port)
|
|
|
|
printf("*.%x", port);
|
|
|
|
else
|
|
|
|
printf("*.*");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipx_wildnet(work))
|
|
|
|
net = "any";
|
|
|
|
else if (ipx_nullnet(work))
|
|
|
|
net = "*";
|
|
|
|
else {
|
|
|
|
q = work.x_net.c_net;
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(cnet, sizeof(cnet), "%x%x%x%x",
|
1997-06-26 19:36:03 +00:00
|
|
|
q[0], q[1], q[2], q[3]);
|
|
|
|
for (p = cnet; *p == '0' && p < cnet + 8; p++)
|
|
|
|
continue;
|
|
|
|
net = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipx_wildhost(work))
|
|
|
|
host = "any";
|
|
|
|
else if (ipx_nullhost(work))
|
|
|
|
host = "*";
|
|
|
|
else {
|
|
|
|
q = work.x_host.c_host;
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(chost, sizeof(chost), "%x%x%x%x%x%x",
|
1997-06-26 19:36:03 +00:00
|
|
|
q[0], q[1], q[2], q[3], q[4], q[5]);
|
|
|
|
for (p = chost; *p == '0' && p < chost + 12; p++)
|
|
|
|
continue;
|
|
|
|
host = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port) {
|
|
|
|
if (strcmp(host, "*") == 0) {
|
|
|
|
host = "";
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(cport, sizeof(cport), "%x", port);
|
1997-06-26 19:36:03 +00:00
|
|
|
} else
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(cport, sizeof(cport), ".%x", port);
|
1997-06-26 19:36:03 +00:00
|
|
|
} else
|
|
|
|
*cport = 0;
|
|
|
|
|
|
|
|
printf("%s.%s%s", net, host, cport);
|
|
|
|
}
|