summaryrefslogtreecommitdiffstats
path: root/sys/netipx/ipx_pcb.c
diff options
context:
space:
mode:
authorjhay <jhay@FreeBSD.org>1997-05-10 09:58:58 +0000
committerjhay <jhay@FreeBSD.org>1997-05-10 09:58:58 +0000
commit0993d64164c5645de9b918e293cd3ae73cc6eeab (patch)
tree1020b5e960a3798c25dbbee04af310936411983a /sys/netipx/ipx_pcb.c
parentd166039f66bb01a24268ecef1ad2038d00c72a4d (diff)
downloadFreeBSD-src-0993d64164c5645de9b918e293cd3ae73cc6eeab.zip
FreeBSD-src-0993d64164c5645de9b918e293cd3ae73cc6eeab.tar.gz
Mega IPX commit.
Use the MAC address of an interface for the host part of an IPX address and not the MAC address of the first interface for every IPX address. This is more inline with the way others like Novell do it. Mostly Submitted by: "Serge A. Babkin" <babkin@hq.icb.chel.su> Take out the error messages (the ip icmp equivalent) with #ifdef IPXERRORMSGS. This is bogus and as far as I could figure out IPX don't have anything like it. This is a leftover from its XNS heritage. If nobody complains, I will take it out completely in a few weeks. Add some more ipxstat statistics counters. Make ipxprintfs a sysctl variable and off by default. Add IPX Netbios "routing" support. This is off by default and can be switched on with a sysctl knob. General code cleanup to at least use the same style throughout the IPX code, but also be more style(9) conformant. Also make a lot of functions static. If I don't get any complaints I'll bring all of this over to the 2.2 tree in a few weeks.
Diffstat (limited to 'sys/netipx/ipx_pcb.c')
-rw-r--r--sys/netipx/ipx_pcb.c102
1 files changed, 67 insertions, 35 deletions
diff --git a/sys/netipx/ipx_pcb.c b/sys/netipx/ipx_pcb.c
index 07f0f98..cb4d450 100644
--- a/sys/netipx/ipx_pcb.c
+++ b/sys/netipx/ipx_pcb.c
@@ -33,7 +33,7 @@
*
* @(#)ipx_pcb.c
*
- * $Id: ipx_pcb.c,v 1.7 1997/02/22 09:41:56 peter Exp $
+ * $Id: ipx_pcb.c,v 1.8 1997/05/01 06:21:29 jhay Exp $
*/
#include <sys/param.h>
@@ -52,6 +52,7 @@
#include <netipx/ipx.h>
#include <netipx/ipx_if.h>
#include <netipx/ipx_pcb.h>
+#include <netipx/ipx_var.h>
struct ipx_addr zeroipx_addr;
@@ -85,10 +86,10 @@ ipx_pcbbind(ipxp, nam, p)
if (ipxp->ipxp_lport || !ipx_nullhost(ipxp->ipxp_laddr))
return (EINVAL);
- if (nam == 0)
+ if (nam == NULL)
goto noname;
sipx = mtod(nam, struct sockaddr_ipx *);
- if (nam->m_len != sizeof (*sipx))
+ if (nam->m_len != sizeof(*sipx))
return (EINVAL);
if (!ipx_nullhost(sipx->sipx_addr)) {
int tport = sipx->sipx_port;
@@ -103,8 +104,8 @@ ipx_pcbbind(ipxp, nam, p)
u_short aport = ntohs(lport);
int error;
- if (aport < IPXPORT_MAX &&
- p && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
+ if (aport < IPXPORT_RESERVED &&
+ p != NULL && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
if (ipx_pcblookup(&zeroipx_addr, lport, 0))
return (EADDRINUSE);
@@ -113,8 +114,10 @@ ipx_pcbbind(ipxp, nam, p)
noname:
if (lport == 0)
do {
- if (ipxpcb.ipxp_lport++ < IPXPORT_MAX)
- ipxpcb.ipxp_lport = IPXPORT_MAX;
+ ipxpcb.ipxp_lport++;
+ if ((ipxpcb.ipxp_lport < IPXPORT_RESERVED) ||
+ (ipxpcb.ipxp_lport >= IPXPORT_WELLKNOWN))
+ ipxpcb.ipxp_lport = IPXPORT_RESERVED;
lport = htons(ipxpcb.ipxp_lport);
} while (ipx_pcblookup(&zeroipx_addr, lport, 0));
ipxp->ipxp_lport = lport;
@@ -139,11 +142,13 @@ ipx_pcbconnect(ipxp, nam, p)
register struct route *ro;
struct ifnet *ifp;
- if (nam->m_len != sizeof (*sipx))
+ ia = NULL;
+
+ if (nam->m_len != sizeof(*sipx))
return (EINVAL);
if (sipx->sipx_family != AF_IPX)
return (EAFNOSUPPORT);
- if (sipx->sipx_port==0 || ipx_nullhost(sipx->sipx_addr))
+ if (sipx->sipx_port == 0 || ipx_nullhost(sipx->sipx_addr))
return (EADDRNOTAVAIL);
/*
* If we haven't bound which network number to use as ours,
@@ -164,21 +169,20 @@ ipx_pcbconnect(ipxp, nam, p)
if (!ipx_neteq(ipxp->ipxp_lastdst, sipx->sipx_addr))
goto flush;
if (!ipx_hosteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) {
- if (ro->ro_rt && ! (ro->ro_rt->rt_flags & RTF_HOST)) {
+ if (ro->ro_rt != NULL && !(ro->ro_rt->rt_flags & RTF_HOST)) {
/* can patch route to avoid rtalloc */
*dst = sipx->sipx_addr;
} else {
flush:
- if (ro->ro_rt)
+ if (ro->ro_rt != NULL)
RTFREE(ro->ro_rt);
- ro->ro_rt = (struct rtentry *)0;
+ ro->ro_rt = NULL;
ipxp->ipxp_laddr.x_net = ipx_zeronet;
}
}/* else cached route is ok; do nothing */
ipxp->ipxp_lastdst = sipx->sipx_addr;
if ((ipxp->ipxp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
- (ro->ro_rt == (struct rtentry *)0 ||
- ro->ro_rt->rt_ifp == (struct ifnet *)0)) {
+ (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL)) {
/* No route yet, so try to acquire one */
ro->ro_dst.sa_family = AF_IPX;
ro->ro_dst.sa_len = sizeof(ro->ro_dst);
@@ -192,37 +196,65 @@ ipx_pcbconnect(ipxp, nam, p)
* our src addr is taken from the i/f, else punt.
*/
- ia = (struct ipx_ifaddr *)0;
/*
* If we found a route, use the address
* corresponding to the outgoing interface
*/
- if (ro->ro_rt && (ifp = ro->ro_rt->rt_ifp))
- for (ia = ipx_ifaddr; ia; ia = ia->ia_next)
+ if (ro->ro_rt != NULL && (ifp = ro->ro_rt->rt_ifp) != NULL)
+ for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
if (ia->ia_ifp == ifp)
break;
- if (ia == 0) {
+ if (ia == NULL) {
u_short fport = sipx->sipx_addr.x_port;
sipx->sipx_addr.x_port = 0;
ia = (struct ipx_ifaddr *)
ifa_ifwithdstaddr((struct sockaddr *)sipx);
sipx->sipx_addr.x_port = fport;
- if (ia == 0)
+ if (ia == NULL)
ia = ipx_iaonnetof(&sipx->sipx_addr);
- if (ia == 0)
+ if (ia == NULL)
ia = ipx_ifaddr;
- if (ia == 0)
+ if (ia == NULL)
return (EADDRNOTAVAIL);
}
ipxp->ipxp_laddr.x_net = satoipx_addr(ia->ia_addr).x_net;
}
- if (ipx_pcblookup(&sipx->sipx_addr, ipxp->ipxp_lport, 0))
- return (EADDRINUSE);
if (ipx_nullhost(ipxp->ipxp_laddr)) {
- if (ipxp->ipxp_lport == 0)
- (void) ipx_pcbbind(ipxp, (struct mbuf *)0, p);
- ipxp->ipxp_laddr.x_host = ipx_thishost;
+ /*
+ * If route is known or can be allocated now,
+ * our src addr is taken from the i/f, else punt.
+ */
+
+ /*
+ * If we found a route, use the address
+ * corresponding to the outgoing interface
+ */
+ if (ro->ro_rt != NULL && (ifp = ro->ro_rt->rt_ifp) != NULL)
+ for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
+ if (ia->ia_ifp == ifp)
+ break;
+ if (ia == NULL) {
+ u_short fport = sipx->sipx_addr.x_port;
+ sipx->sipx_addr.x_port = 0;
+ ia = (struct ipx_ifaddr *)
+ ifa_ifwithdstaddr((struct sockaddr *)sipx);
+ sipx->sipx_addr.x_port = fport;
+ if (ia == NULL)
+ ia = ipx_iaonnetof(&sipx->sipx_addr);
+ if (ia == NULL)
+ ia = ipx_ifaddr;
+ if (ia == NULL)
+ return (EADDRNOTAVAIL);
+ }
+ ipxp->ipxp_laddr.x_host = satoipx_addr(ia->ia_addr).x_host;
}
+ if (ipx_pcblookup(&sipx->sipx_addr, ipxp->ipxp_lport, 0))
+ return (EADDRINUSE);
+ if (ipxp->ipxp_lport == 0)
+ ipx_pcbbind(ipxp, (struct mbuf *)NULL, p);
+
+ /* XXX just leave it zero if we can't find a route */
+
ipxp->ipxp_faddr = sipx->sipx_addr;
/* Includes ipxp->ipxp_fport = sipx->sipx_port; */
return (0);
@@ -246,10 +278,10 @@ ipx_pcbdetach(ipxp)
so->so_pcb = 0;
sofree(so);
- if (ipxp->ipxp_route.ro_rt)
+ if (ipxp->ipxp_route.ro_rt != NULL)
rtfree(ipxp->ipxp_route.ro_rt);
remque(ipxp);
- (void) m_free(dtom(ipxp));
+ m_free(dtom(ipxp));
}
void
@@ -259,9 +291,9 @@ ipx_setsockaddr(ipxp, nam)
{
register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *);
- nam->m_len = sizeof (*sipx);
+ nam->m_len = sizeof(*sipx);
sipx = mtod(nam, struct sockaddr_ipx *);
- bzero((caddr_t)sipx, sizeof (*sipx));
+ bzero((caddr_t)sipx, sizeof(*sipx));
sipx->sipx_len = sizeof(*sipx);
sipx->sipx_family = AF_IPX;
sipx->sipx_addr = ipxp->ipxp_laddr;
@@ -274,9 +306,9 @@ ipx_setpeeraddr(ipxp, nam)
{
register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *);
- nam->m_len = sizeof (*sipx);
+ nam->m_len = sizeof(*sipx);
sipx = mtod(nam, struct sockaddr_ipx *);
- bzero((caddr_t)sipx, sizeof (*sipx));
+ bzero((caddr_t)sipx, sizeof(*sipx));
sipx->sipx_len = sizeof(*sipx);
sipx->sipx_family = AF_IPX;
sipx->sipx_addr = ipxp->ipxp_faddr;
@@ -325,9 +357,9 @@ ipx_pcbnotify(dst, errno, notify, param)
ipx_rtchange(ipxp)
struct ipxpcb *ipxp;
{
- if (ipxp->ipxp_route.ro_rt) {
+ if (ipxp->ipxp_route.ro_rt != NULL) {
rtfree(ipxp->ipxp_route.ro_rt);
- ipxp->ipxp_route.ro_rt = 0;
+ ipxp->ipxp_route.ro_rt = NULL;
/*
* A new route can be allocated the next time
* output is attempted.
@@ -369,7 +401,7 @@ ipx_pcblookup(faddr, lport, wildp)
}
}
}
- if (wildcard && wildp==0)
+ if (wildcard && wildp == 0)
continue;
if (wildcard < matchwild) {
match = ipxp;
OpenPOWER on IntegriCloud