1996-05-24 01:35:45 +00:00
|
|
|
/*
|
2005-01-03 00:16:07 +00:00
|
|
|
* Copyright (c) 2004-2005 Robert N. M. Watson
|
1996-05-24 01:35:45 +00:00
|
|
|
* Copyright (c) 1990,1994 Regents of The University of Michigan.
|
|
|
|
* All Rights Reserved. See COPYRIGHT.
|
2000-10-29 16:06:56 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1996-05-24 01:35:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
2003-03-04 23:19:55 +00:00
|
|
|
#include <net/netisr.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/at_var.h>
|
|
|
|
#include <netatalk/ddp_var.h>
|
2004-03-19 07:21:22 +00:00
|
|
|
#include <netatalk/ddp_pcb.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
#include <netatalk/at_extern.h>
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
struct mtx ddp_list_mtx;
|
2004-03-17 12:54:21 +00:00
|
|
|
static struct ddpcb *ddp_ports[ ATPORT_LAST ];
|
2004-07-12 18:39:59 +00:00
|
|
|
struct ddpcb *ddpcb_list = NULL;
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
void
|
1997-08-16 19:16:27 +00:00
|
|
|
at_sockaddr(struct ddpcb *ddp, struct sockaddr **addr)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
2004-07-12 18:39:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent modification of ddp during copy of addr.
|
|
|
|
*/
|
|
|
|
DDP_LOCK_ASSERT(ddp);
|
2004-03-01 03:14:23 +00:00
|
|
|
*addr = sodupsockaddr((struct sockaddr *)&ddp->ddp_lsat, M_NOWAIT);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
at_pcbsetaddr(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_at lsat, *sat;
|
|
|
|
struct at_ifaddr *aa;
|
|
|
|
struct ddpcb *ddpp;
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
/*
|
|
|
|
* We read and write both the ddp passed in, and also ddp_ports.
|
|
|
|
*/
|
|
|
|
DDP_LIST_XLOCK_ASSERT();
|
|
|
|
DDP_LOCK_ASSERT(ddp);
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT) { /* shouldn't be bound */
|
|
|
|
return (EINVAL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-21 03:28:08 +00:00
|
|
|
if (addr != NULL) { /* validate passed address */
|
1997-08-16 19:16:27 +00:00
|
|
|
sat = (struct sockaddr_at *)addr;
|
|
|
|
if (sat->sat_family != AF_APPLETALK) {
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EAFNOSUPPORT);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_addr.s_node != ATADDR_ANYNODE ||
|
|
|
|
sat->sat_addr.s_net != ATADDR_ANYNET) {
|
2004-03-22 04:50:36 +00:00
|
|
|
for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) {
|
2004-03-22 03:24:10 +00:00
|
|
|
if ((sat->sat_addr.s_net == AA_SAT(aa)->sat_addr.s_net) &&
|
|
|
|
(sat->sat_addr.s_node == AA_SAT(aa)->sat_addr.s_node)) {
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (!aa) {
|
|
|
|
return (EADDRNOTAVAIL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_port != ATADDR_ANYPORT) {
|
|
|
|
if (sat->sat_port < ATPORT_FIRST ||
|
|
|
|
sat->sat_port >= ATPORT_LAST) {
|
|
|
|
return (EINVAL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_port < ATPORT_RESERVED &&
|
|
|
|
suser(td)) {
|
|
|
|
return (EACCES);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2004-03-22 03:24:10 +00:00
|
|
|
bzero((caddr_t)&lsat, sizeof(struct sockaddr_at));
|
1996-05-24 01:35:45 +00:00
|
|
|
lsat.sat_len = sizeof(struct sockaddr_at);
|
|
|
|
lsat.sat_addr.s_node = ATADDR_ANYNODE;
|
|
|
|
lsat.sat_addr.s_net = ATADDR_ANYNET;
|
|
|
|
lsat.sat_family = AF_APPLETALK;
|
|
|
|
sat = &lsat;
|
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_addr.s_node == ATADDR_ANYNODE &&
|
|
|
|
sat->sat_addr.s_net == ATADDR_ANYNET) {
|
2004-03-22 04:50:36 +00:00
|
|
|
if (at_ifaddr_list == NULL) {
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EADDRNOTAVAIL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 04:50:36 +00:00
|
|
|
sat->sat_addr = AA_SAT(at_ifaddr_list)->sat_addr;
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
ddp->ddp_lsat = *sat;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose port.
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_port == ATADDR_ANYPORT) {
|
|
|
|
for (sat->sat_port = ATPORT_RESERVED;
|
|
|
|
sat->sat_port < ATPORT_LAST; sat->sat_port++) {
|
|
|
|
if (ddp_ports[ sat->sat_port - 1 ] == NULL) {
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_port == ATPORT_LAST) {
|
|
|
|
return (EADDRNOTAVAIL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
ddp->ddp_lsat.sat_port = sat->sat_port;
|
|
|
|
ddp_ports[ sat->sat_port - 1 ] = ddp;
|
|
|
|
} else {
|
2004-03-22 03:24:10 +00:00
|
|
|
for (ddpp = ddp_ports[ sat->sat_port - 1 ]; ddpp;
|
|
|
|
ddpp = ddpp->ddp_pnext) {
|
|
|
|
if (ddpp->ddp_lsat.sat_addr.s_net == sat->sat_addr.s_net &&
|
|
|
|
ddpp->ddp_lsat.sat_addr.s_node == sat->sat_addr.s_node) {
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddpp != NULL) {
|
|
|
|
return (EADDRINUSE);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
ddp->ddp_pnext = ddp_ports[ sat->sat_port - 1 ];
|
|
|
|
ddp_ports[ sat->sat_port - 1 ] = ddp;
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_pnext) {
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_pnext->ddp_pprev = ddp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
return (0);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr_at *sat = (struct sockaddr_at *)addr;
|
1996-05-24 01:35:45 +00:00
|
|
|
struct route *ro;
|
2004-03-21 03:28:08 +00:00
|
|
|
struct at_ifaddr *aa = NULL;
|
1996-05-24 01:35:45 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_short hintnet = 0, net;
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK_ASSERT();
|
|
|
|
DDP_LOCK_ASSERT(ddp);
|
|
|
|
|
1997-08-16 19:16:27 +00:00
|
|
|
if (sat->sat_family != AF_APPLETALK) {
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EAFNOSUPPORT);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Under phase 2, network 0 means "the network". We take "the
|
|
|
|
* network" to mean the network the control block is bound to.
|
|
|
|
* If the control block is not bound, there is an error.
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
if (sat->sat_addr.s_net == ATADDR_ANYNET
|
|
|
|
&& sat->sat_addr.s_node != ATADDR_ANYNODE) {
|
|
|
|
if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT) {
|
|
|
|
return (EADDRNOTAVAIL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
hintnet = ddp->ddp_lsat.sat_addr.s_net;
|
|
|
|
}
|
|
|
|
|
|
|
|
ro = &ddp->ddp_route;
|
|
|
|
/*
|
|
|
|
* If we've got an old route for this pcb, check that it is valid.
|
|
|
|
* If we've changed our address, we may have an old "good looking"
|
|
|
|
* route here. Attempt to detect it.
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ro->ro_rt) {
|
|
|
|
if (hintnet) {
|
1996-05-24 01:35:45 +00:00
|
|
|
net = hintnet;
|
|
|
|
} else {
|
|
|
|
net = sat->sat_addr.s_net;
|
|
|
|
}
|
2004-03-21 03:28:08 +00:00
|
|
|
aa = NULL;
|
1999-01-27 22:42:27 +00:00
|
|
|
if ((ifp = ro->ro_rt->rt_ifp) != NULL) {
|
2004-03-22 04:50:36 +00:00
|
|
|
for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) {
|
2004-03-22 03:24:10 +00:00
|
|
|
if (aa->aa_ifp == ifp &&
|
|
|
|
ntohs(net) >= ntohs(aa->aa_firstnet) &&
|
|
|
|
ntohs(net) <= ntohs(aa->aa_lastnet)) {
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (aa == NULL || (satosat(&ro->ro_dst)->sat_addr.s_net !=
|
|
|
|
(hintnet ? hintnet : sat->sat_addr.s_net) ||
|
|
|
|
satosat(&ro->ro_dst)->sat_addr.s_node !=
|
|
|
|
sat->sat_addr.s_node)) {
|
|
|
|
RTFREE(ro->ro_rt);
|
2004-03-21 03:28:08 +00:00
|
|
|
ro->ro_rt = NULL;
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've got no route for this interface, try to find one.
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL) {
|
|
|
|
ro->ro_dst.sa_len = sizeof(struct sockaddr_at);
|
1996-05-24 01:35:45 +00:00
|
|
|
ro->ro_dst.sa_family = AF_APPLETALK;
|
2004-03-22 03:24:10 +00:00
|
|
|
if (hintnet) {
|
|
|
|
satosat(&ro->ro_dst)->sat_addr.s_net = hintnet;
|
1996-05-24 01:35:45 +00:00
|
|
|
} else {
|
2004-03-22 03:24:10 +00:00
|
|
|
satosat(&ro->ro_dst)->sat_addr.s_net = sat->sat_addr.s_net;
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
satosat(&ro->ro_dst)->sat_addr.s_node = sat->sat_addr.s_node;
|
|
|
|
rtalloc(ro);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure any route that we have has a valid interface.
|
|
|
|
*/
|
2004-03-21 03:28:08 +00:00
|
|
|
aa = NULL;
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ro->ro_rt && (ifp = ro->ro_rt->rt_ifp)) {
|
2004-03-22 04:50:36 +00:00
|
|
|
for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) {
|
2004-03-22 03:24:10 +00:00
|
|
|
if (aa->aa_ifp == ifp) {
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (aa == NULL) {
|
|
|
|
return (ENETUNREACH);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ddp->ddp_fsat = *sat;
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT) {
|
|
|
|
return (at_pcbsetaddr(ddp, NULL, td));
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
return (0);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
void
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdisconnect(struct ddpcb *ddp)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
2004-07-12 18:39:59 +00:00
|
|
|
|
|
|
|
DDP_LOCK_ASSERT(ddp);
|
|
|
|
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_fsat.sat_addr.s_net = ATADDR_ANYNET;
|
|
|
|
ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
|
|
|
|
ddp->ddp_fsat.sat_port = ATADDR_ANYPORT;
|
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
int
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcballoc(struct socket *so)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
1997-08-16 19:16:27 +00:00
|
|
|
struct ddpcb *ddp;
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK_ASSERT();
|
|
|
|
|
|
|
|
MALLOC(ddp, struct ddpcb *, sizeof *ddp, M_PCB, M_NOWAIT | M_ZERO);
|
2005-01-03 00:16:07 +00:00
|
|
|
if (ddp == NULL)
|
|
|
|
return (ENOBUFS);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LOCK_INIT(ddp);
|
1997-08-16 19:16:27 +00:00
|
|
|
ddp->ddp_lsat.sat_port = ATADDR_ANYPORT;
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
ddp->ddp_socket = so;
|
|
|
|
so->so_pcb = (caddr_t)ddp;
|
|
|
|
|
2004-03-22 04:54:36 +00:00
|
|
|
ddp->ddp_next = ddpcb_list;
|
1997-08-16 19:16:27 +00:00
|
|
|
ddp->ddp_prev = NULL;
|
|
|
|
ddp->ddp_pprev = NULL;
|
|
|
|
ddp->ddp_pnext = NULL;
|
2004-03-22 04:54:36 +00:00
|
|
|
if (ddpcb_list != NULL) {
|
|
|
|
ddpcb_list->ddp_prev = ddp;
|
1997-08-16 19:16:27 +00:00
|
|
|
}
|
2004-03-22 04:54:36 +00:00
|
|
|
ddpcb_list = ddp;
|
2004-07-12 18:39:59 +00:00
|
|
|
return(0);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
void
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(struct socket *so, struct ddpcb *ddp)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
2004-07-12 18:39:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We modify ddp, ddp_ports, and the global list.
|
|
|
|
*/
|
|
|
|
DDP_LIST_XLOCK_ASSERT();
|
|
|
|
DDP_LOCK_ASSERT(ddp);
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
soisdisconnected(so);
|
2004-10-18 22:19:43 +00:00
|
|
|
ACCEPT_LOCK();
|
2004-06-12 20:47:32 +00:00
|
|
|
SOCK_LOCK(so);
|
2004-03-21 03:28:08 +00:00
|
|
|
so->so_pcb = NULL;
|
2001-11-17 03:07:11 +00:00
|
|
|
sotryfree(so);
|
1996-05-24 01:35:45 +00:00
|
|
|
|
|
|
|
/* remove ddp from ddp_ports list */
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT &&
|
|
|
|
ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] != NULL) {
|
|
|
|
if (ddp->ddp_pprev != NULL) {
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext;
|
|
|
|
} else {
|
|
|
|
ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] = ddp->ddp_pnext;
|
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_pnext != NULL) {
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_route.ro_rt) {
|
|
|
|
RTFREE(ddp->ddp_route.ro_rt);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_prev) {
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_prev->ddp_next = ddp->ddp_next;
|
|
|
|
} else {
|
2004-03-22 04:54:36 +00:00
|
|
|
ddpcb_list = ddp->ddp_next;
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_next) {
|
1996-05-24 01:35:45 +00:00
|
|
|
ddp->ddp_next->ddp_prev = ddp->ddp_prev;
|
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
|
|
|
DDP_LOCK_DESTROY(ddp);
|
1997-08-16 19:16:27 +00:00
|
|
|
FREE(ddp, M_PCB);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the moment, this just find the pcb with the correct local address.
|
|
|
|
* In the future, this will actually do some real searching, so we can use
|
|
|
|
* the sender's address to do de-multiplexing on a single port to many
|
|
|
|
* sockets (pcbs).
|
|
|
|
*/
|
|
|
|
struct ddpcb *
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp_search(struct sockaddr_at *from, struct sockaddr_at *to,
|
1996-05-24 01:35:45 +00:00
|
|
|
struct at_ifaddr *aa)
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_SLOCK_ASSERT();
|
|
|
|
|
1996-05-24 01:35:45 +00:00
|
|
|
/*
|
|
|
|
* Check for bad ports.
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
if (to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST) {
|
|
|
|
return (NULL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the local address matches the sent address. What about
|
|
|
|
* the interface?
|
|
|
|
*/
|
2004-03-22 03:24:10 +00:00
|
|
|
for (ddp = ddp_ports[ to->sat_port - 1 ]; ddp; ddp = ddp->ddp_pnext) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
/* XXX should we handle 0.YY? */
|
|
|
|
|
|
|
|
/* XXXX.YY to socket on destination interface */
|
2004-03-22 03:24:10 +00:00
|
|
|
if (to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net &&
|
|
|
|
to->sat_addr.s_node == ddp->ddp_lsat.sat_addr.s_node) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0.255 to socket on receiving interface */
|
2004-03-22 03:24:10 +00:00
|
|
|
if (to->sat_addr.s_node == ATADDR_BCAST && (to->sat_addr.s_net == 0 ||
|
|
|
|
to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net) &&
|
|
|
|
ddp->ddp_lsat.sat_addr.s_net == AA_SAT(aa)->sat_addr.s_net) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXXX.0 to socket on destination interface */
|
2004-03-22 03:24:10 +00:00
|
|
|
if (to->sat_addr.s_net == aa->aa_firstnet &&
|
1996-05-24 01:35:45 +00:00
|
|
|
to->sat_addr.s_node == 0 &&
|
2004-03-22 03:24:10 +00:00
|
|
|
ntohs(ddp->ddp_lsat.sat_addr.s_net) >=
|
|
|
|
ntohs(aa->aa_firstnet) &&
|
|
|
|
ntohs(ddp->ddp_lsat.sat_addr.s_net) <=
|
|
|
|
ntohs(aa->aa_lastnet)) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
return (ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|