2008-01-28 21:28:31 +03:00
|
|
|
/* $NetBSD: ddp_usrreq.c,v 1.30 2008/01/28 18:28:31 dyoung Exp $ */
|
1997-04-03 01:31:01 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1990,1991 Regents of The University of Michigan.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and
|
|
|
|
* its documentation for any purpose and without fee is hereby granted,
|
|
|
|
* provided that the above copyright notice appears in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation, and that the name of The University
|
|
|
|
* of Michigan not be used in advertising or publicity pertaining to
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
* permission. This software is supplied as is without expressed or
|
|
|
|
* implied warranties of any kind.
|
|
|
|
*
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
*
|
|
|
|
* Research Systems Unix Group
|
|
|
|
* The University of Michigan
|
|
|
|
* c/o Wesley Craig
|
|
|
|
* 535 W. William Street
|
|
|
|
* Ann Arbor, Michigan
|
|
|
|
* +1-313-764-2278
|
|
|
|
* netatalk@umich.edu
|
|
|
|
*/
|
|
|
|
|
2001-11-13 03:00:58 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-01-28 21:28:31 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ddp_usrreq.c,v 1.30 2008/01/28 18:28:31 dyoung Exp $");
|
2003-06-23 15:00:59 +04:00
|
|
|
|
|
|
|
#include "opt_mbuftrace.h"
|
2001-11-13 03:00:58 +03:00
|
|
|
|
1997-04-03 01:31:01 +04:00
|
|
|
#include <sys/param.h>
|
2001-11-15 12:47:59 +03:00
|
|
|
#include <sys/errno.h>
|
1997-04-03 01:31:01 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/ioctl.h>
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
#include <sys/queue.h>
|
1997-04-03 01:31:01 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
2006-05-15 01:19:33 +04:00
|
|
|
#include <sys/kauth.h>
|
1997-04-03 01:31:01 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/at_var.h>
|
|
|
|
#include <netatalk/ddp_var.h>
|
|
|
|
#include <netatalk/aarp.h>
|
|
|
|
#include <netatalk/at_extern.h>
|
|
|
|
|
|
|
|
static void at_pcbdisconnect __P((struct ddpcb *));
|
|
|
|
static void at_sockaddr __P((struct ddpcb *, struct mbuf *));
|
2006-07-24 02:06:03 +04:00
|
|
|
static int at_pcbsetaddr __P((struct ddpcb *, struct mbuf *, struct lwp *));
|
|
|
|
static int at_pcbconnect __P((struct ddpcb *, struct mbuf *, struct lwp *));
|
1997-04-03 01:31:01 +04:00
|
|
|
static void at_pcbdetach __P((struct socket *, struct ddpcb *));
|
|
|
|
static int at_pcballoc __P((struct socket *));
|
|
|
|
|
2002-05-13 01:43:23 +04:00
|
|
|
struct ifqueue atintrq1, atintrq2;
|
1997-04-03 01:31:01 +04:00
|
|
|
struct ddpcb *ddp_ports[ATPORT_LAST];
|
|
|
|
struct ddpcb *ddpcb = NULL;
|
2002-05-13 01:43:23 +04:00
|
|
|
struct ddpstat ddpstat;
|
1997-04-03 01:31:01 +04:00
|
|
|
struct at_ifaddrhead at_ifaddr; /* Here as inited in this file */
|
|
|
|
u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
|
1997-04-29 17:44:47 +04:00
|
|
|
u_long ddp_recvspace = 25 * (587 + sizeof(struct sockaddr_at));
|
1997-04-03 01:31:01 +04:00
|
|
|
|
2003-02-26 10:53:04 +03:00
|
|
|
#ifdef MBUFTRACE
|
2006-10-11 01:49:14 +04:00
|
|
|
struct mowner atalk_rx_mowner = MOWNER_INIT("atalk", "rx");
|
|
|
|
struct mowner atalk_tx_mowner = MOWNER_INIT("atalk", "tx");
|
2003-02-26 10:53:04 +03:00
|
|
|
#endif
|
|
|
|
|
1997-04-03 01:31:01 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
ddp_usrreq(so, req, m, addr, rights, l)
|
1997-04-03 01:31:01 +04:00
|
|
|
struct socket *so;
|
|
|
|
int req;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct mbuf *addr;
|
|
|
|
struct mbuf *rights;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
2003-06-30 02:28:00 +04:00
|
|
|
{
|
1997-04-03 01:31:01 +04:00
|
|
|
struct ddpcb *ddp;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
|
|
|
|
if (req == PRU_CONTROL) {
|
2007-03-04 08:59:00 +03:00
|
|
|
return (at_control((long) m, (void *) addr,
|
2006-07-24 02:06:03 +04:00
|
|
|
(struct ifnet *) rights, l));
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
2000-02-03 02:28:08 +03:00
|
|
|
if (req == PRU_PURGEIF) {
|
|
|
|
at_purgeif((struct ifnet *) rights);
|
2000-02-02 01:52:04 +03:00
|
|
|
return (0);
|
|
|
|
}
|
1997-04-03 01:31:01 +04:00
|
|
|
if (rights && rights->m_len) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
if (ddp == NULL && req != PRU_ATTACH) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
switch (req) {
|
|
|
|
case PRU_ATTACH:
|
|
|
|
if (ddp != NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((error = at_pcballoc(so)) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = soreserve(so, ddp_sendspace, ddp_recvspace);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_DETACH:
|
|
|
|
at_pcbdetach(so, ddp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_BIND:
|
2006-07-24 02:06:03 +04:00
|
|
|
error = at_pcbsetaddr(ddp, addr, l);
|
1997-04-03 01:31:01 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_SOCKADDR:
|
|
|
|
at_sockaddr(ddp, addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_CONNECT:
|
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
|
|
|
error = EISCONN;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-24 02:06:03 +04:00
|
|
|
error = at_pcbconnect(ddp, addr, l);
|
1997-04-03 01:31:01 +04:00
|
|
|
if (error == 0)
|
|
|
|
soisconnected(so);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_DISCONNECT:
|
|
|
|
if (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
at_pcbdisconnect(ddp);
|
|
|
|
soisdisconnected(so);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_SHUTDOWN:
|
|
|
|
socantsendmore(so);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_SEND:{
|
|
|
|
int s = 0;
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
|
|
|
error = EISCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = splnet();
|
2006-07-24 02:06:03 +04:00
|
|
|
error = at_pcbconnect(ddp, addr, l);
|
1997-04-03 01:31:01 +04:00
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ddp_output(m, ddp);
|
|
|
|
m = NULL;
|
|
|
|
if (addr) {
|
|
|
|
at_pcbdisconnect(ddp);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_ABORT:
|
|
|
|
soisdisconnected(so);
|
|
|
|
at_pcbdetach(so, ddp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_LISTEN:
|
|
|
|
case PRU_CONNECT2:
|
|
|
|
case PRU_ACCEPT:
|
|
|
|
case PRU_SENDOOB:
|
|
|
|
case PRU_FASTTIMO:
|
|
|
|
case PRU_SLOWTIMO:
|
|
|
|
case PRU_PROTORCV:
|
|
|
|
case PRU_PROTOSEND:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_RCVD:
|
|
|
|
case PRU_RCVOOB:
|
|
|
|
/*
|
|
|
|
* Don't mfree. Good architecture...
|
|
|
|
*/
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
case PRU_SENSE:
|
|
|
|
/*
|
|
|
|
* 1. Don't return block size.
|
|
|
|
* 2. Don't mfree.
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
release:
|
|
|
|
if (m != NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
at_sockaddr(ddp, addr)
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
struct mbuf *addr;
|
|
|
|
{
|
|
|
|
struct sockaddr_at *sat;
|
|
|
|
|
|
|
|
addr->m_len = sizeof(struct sockaddr_at);
|
|
|
|
sat = mtod(addr, struct sockaddr_at *);
|
|
|
|
*sat = ddp->ddp_lsat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-07-24 02:06:03 +04:00
|
|
|
at_pcbsetaddr(ddp, addr, l)
|
1997-04-03 01:31:01 +04:00
|
|
|
struct ddpcb *ddp;
|
|
|
|
struct mbuf *addr;
|
2006-07-24 02:06:03 +04:00
|
|
|
struct lwp *l;
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
|
|
|
struct sockaddr_at lsat, *sat;
|
|
|
|
struct at_ifaddr *aa;
|
|
|
|
struct ddpcb *ddpp;
|
|
|
|
|
|
|
|
if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT) { /* shouldn't be bound */
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (addr != 0) { /* validate passed address */
|
|
|
|
sat = mtod(addr, struct sockaddr_at *);
|
|
|
|
if (addr->m_len != sizeof(*sat))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (sat->sat_family != AF_APPLETALK)
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
|
|
|
|
if (sat->sat_addr.s_node != ATADDR_ANYNODE ||
|
|
|
|
sat->sat_addr.s_net != ATADDR_ANYNET) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
|
1997-04-03 01:31:01 +04: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))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!aa)
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
|
|
|
if (sat->sat_port != ATADDR_ANYPORT) {
|
|
|
|
if (sat->sat_port < ATPORT_FIRST ||
|
|
|
|
sat->sat_port >= ATPORT_LAST)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2006-07-24 02:06:03 +04:00
|
|
|
if (sat->sat_port < ATPORT_RESERVED && l &&
|
|
|
|
kauth_authorize_generic(l->l_cred,
|
2007-01-04 22:07:03 +03:00
|
|
|
KAUTH_GENERIC_ISSUSER, NULL))
|
1997-04-03 01:31:01 +04:00
|
|
|
return (EACCES);
|
|
|
|
}
|
|
|
|
} else {
|
2007-03-04 08:59:00 +03:00
|
|
|
bzero((void *) & lsat, sizeof(struct sockaddr_at));
|
1997-04-03 01:31:01 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sat->sat_addr.s_node == ATADDR_ANYNODE &&
|
|
|
|
sat->sat_addr.s_net == ATADDR_ANYNET) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
if (TAILQ_EMPTY(&at_ifaddr))
|
|
|
|
return EADDRNOTAVAIL;
|
|
|
|
sat->sat_addr = AA_SAT(TAILQ_FIRST(&at_ifaddr))->sat_addr;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
ddp->ddp_lsat = *sat;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose port.
|
|
|
|
*/
|
|
|
|
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] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sat->sat_port == ATPORT_LAST) {
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
|
|
|
ddp->ddp_lsat.sat_port = sat->sat_port;
|
|
|
|
ddp_ports[sat->sat_port - 1] = ddp;
|
|
|
|
} else {
|
|
|
|
for (ddpp = ddp_ports[sat->sat_port - 1]; ddpp;
|
|
|
|
ddpp = ddpp->ddp_pnext) {
|
2005-02-27 01:45:09 +03:00
|
|
|
if (ddpp->ddp_lsat.sat_addr.s_net ==
|
1997-04-03 01:31:01 +04:00
|
|
|
sat->sat_addr.s_net &&
|
|
|
|
ddpp->ddp_lsat.sat_addr.s_node ==
|
|
|
|
sat->sat_addr.s_node)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ddpp != NULL)
|
|
|
|
return (EADDRINUSE);
|
|
|
|
|
|
|
|
ddp->ddp_pnext = ddp_ports[sat->sat_port - 1];
|
|
|
|
ddp_ports[sat->sat_port - 1] = ddp;
|
|
|
|
if (ddp->ddp_pnext)
|
|
|
|
ddp->ddp_pnext->ddp_pprev = ddp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-07-24 02:06:03 +04:00
|
|
|
at_pcbconnect(ddp, addr, l)
|
1997-04-03 01:31:01 +04:00
|
|
|
struct ddpcb *ddp;
|
|
|
|
struct mbuf *addr;
|
2006-07-24 02:06:03 +04:00
|
|
|
struct lwp *l;
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
2007-12-20 22:53:29 +03:00
|
|
|
struct rtentry *rt;
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
const struct sockaddr_at *cdst;
|
1997-04-03 01:31:01 +04:00
|
|
|
struct sockaddr_at *sat = mtod(addr, struct sockaddr_at *);
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
struct route *ro;
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
struct at_ifaddr *aa;
|
1997-04-03 01:31:01 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_short hintnet = 0, net;
|
|
|
|
|
|
|
|
if (addr->m_len != sizeof(*sat))
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
return EINVAL;
|
1997-04-03 01:31:01 +04:00
|
|
|
if (sat->sat_family != AF_APPLETALK) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
return EAFNOSUPPORT;
|
1997-04-03 01:31:01 +04: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.
|
|
|
|
*/
|
|
|
|
if (sat->sat_addr.s_net == ATADDR_ANYNET
|
|
|
|
&& sat->sat_addr.s_node != ATADDR_ANYNODE) {
|
|
|
|
if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
return EADDRNOTAVAIL;
|
1997-04-03 01:31:01 +04: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.
|
|
|
|
*/
|
2008-01-12 05:58:58 +03:00
|
|
|
if ((rt = rtcache_validate(ro)) != NULL ||
|
|
|
|
(rt = rtcache_update(ro, 1)) != NULL) {
|
1997-04-03 01:31:01 +04:00
|
|
|
if (hintnet) {
|
|
|
|
net = hintnet;
|
|
|
|
} else {
|
|
|
|
net = sat->sat_addr.s_net;
|
|
|
|
}
|
2007-12-20 22:53:29 +03:00
|
|
|
if ((ifp = rt->rt_ifp) != NULL) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
|
1997-04-03 01:31:01 +04:00
|
|
|
if (aa->aa_ifp == ifp &&
|
|
|
|
ntohs(net) >= ntohs(aa->aa_firstnet) &&
|
|
|
|
ntohs(net) <= ntohs(aa->aa_lastnet)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
} else
|
|
|
|
aa = NULL;
|
|
|
|
cdst = satocsat(rtcache_getdst(ro));
|
|
|
|
if (aa == NULL || (cdst->sat_addr.s_net !=
|
1997-04-03 01:31:01 +04:00
|
|
|
(hintnet ? hintnet : sat->sat_addr.s_net) ||
|
2008-01-14 07:12:40 +03:00
|
|
|
cdst->sat_addr.s_node != sat->sat_addr.s_node)) {
|
2006-12-16 00:18:52 +03:00
|
|
|
rtcache_free(ro);
|
2008-01-14 07:12:40 +03:00
|
|
|
rt = NULL;
|
|
|
|
}
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we've got no route for this interface, try to find one.
|
|
|
|
*/
|
2008-01-14 07:12:40 +03:00
|
|
|
if (rt == NULL) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
union {
|
|
|
|
struct sockaddr dst;
|
|
|
|
struct sockaddr_at dsta;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
sockaddr_at_init(&u.dsta, &sat->sat_addr, 0);
|
|
|
|
if (hintnet)
|
|
|
|
u.dsta.sat_addr.s_net = hintnet;
|
2008-01-28 21:28:31 +03:00
|
|
|
rt = rtcache_lookup(ro, &u.dst);
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make sure any route that we have has a valid interface.
|
|
|
|
*/
|
2008-01-10 11:04:18 +03:00
|
|
|
if (rt != NULL && (ifp = rt->rt_ifp) != NULL) {
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
|
|
|
|
if (aa->aa_ifp == ifp)
|
1997-04-03 01:31:01 +04:00
|
|
|
break;
|
|
|
|
}
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
} else
|
|
|
|
aa = NULL;
|
|
|
|
if (aa == NULL)
|
|
|
|
return ENETUNREACH;
|
1997-04-03 01:31:01 +04:00
|
|
|
ddp->ddp_fsat = *sat;
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT)
|
|
|
|
return at_pcbsetaddr(ddp, NULL, l);
|
|
|
|
return 0;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
at_pcbdisconnect(ddp)
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
at_pcballoc(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-04-18 22:55:57 +04:00
|
|
|
MALLOC(ddp, struct ddpcb *, sizeof(*ddp), M_PCB, M_WAITOK|M_ZERO);
|
1997-04-03 01:31:01 +04:00
|
|
|
if (!ddp)
|
|
|
|
panic("at_pcballoc");
|
|
|
|
ddp->ddp_lsat.sat_port = ATADDR_ANYPORT;
|
|
|
|
|
|
|
|
ddp->ddp_next = ddpcb;
|
|
|
|
ddp->ddp_prev = NULL;
|
|
|
|
ddp->ddp_pprev = NULL;
|
|
|
|
ddp->ddp_pnext = NULL;
|
|
|
|
if (ddpcb) {
|
|
|
|
ddpcb->ddp_prev = ddp;
|
|
|
|
}
|
|
|
|
ddpcb = ddp;
|
|
|
|
|
|
|
|
ddp->ddp_socket = so;
|
2007-03-04 08:59:00 +03:00
|
|
|
so->so_pcb = (void *) ddp;
|
2003-02-26 10:53:04 +03:00
|
|
|
#ifdef MBUFTRACE
|
|
|
|
so->so_rcv.sb_mowner = &atalk_rx_mowner;
|
|
|
|
so->so_snd.sb_mowner = &atalk_tx_mowner;
|
|
|
|
#endif
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
return 0;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
at_pcbdetach(so, ddp)
|
|
|
|
struct socket *so;
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
{
|
|
|
|
soisdisconnected(so);
|
|
|
|
so->so_pcb = 0;
|
|
|
|
sofree(so);
|
|
|
|
|
|
|
|
/* remove ddp from ddp_ports list */
|
|
|
|
if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT &&
|
|
|
|
ddp_ports[ddp->ddp_lsat.sat_port - 1] != NULL) {
|
|
|
|
if (ddp->ddp_pprev != NULL) {
|
|
|
|
ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext;
|
|
|
|
} else {
|
|
|
|
ddp_ports[ddp->ddp_lsat.sat_port - 1] = ddp->ddp_pnext;
|
|
|
|
}
|
|
|
|
if (ddp->ddp_pnext != NULL) {
|
|
|
|
ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev;
|
|
|
|
}
|
|
|
|
}
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
rtcache_free(&ddp->ddp_route);
|
1997-04-03 01:31:01 +04:00
|
|
|
if (ddp->ddp_prev) {
|
|
|
|
ddp->ddp_prev->ddp_next = ddp->ddp_next;
|
|
|
|
} else {
|
|
|
|
ddpcb = ddp->ddp_next;
|
|
|
|
}
|
|
|
|
if (ddp->ddp_next) {
|
|
|
|
ddp->ddp_next->ddp_prev = ddp->ddp_prev;
|
|
|
|
}
|
|
|
|
free(ddp, M_PCB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 *
|
2006-10-12 05:30:41 +04:00
|
|
|
ddp_search(
|
2006-11-16 04:32:37 +03:00
|
|
|
struct sockaddr_at *from,
|
2006-10-12 05:30:41 +04:00
|
|
|
struct sockaddr_at *to,
|
|
|
|
struct at_ifaddr *aa)
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for bad ports.
|
|
|
|
*/
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
if (to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST)
|
|
|
|
return NULL;
|
|
|
|
|
1997-04-03 01:31:01 +04:00
|
|
|
/*
|
|
|
|
* Make sure the local address matches the sent address. What about
|
|
|
|
* the interface?
|
|
|
|
*/
|
|
|
|
for (ddp = ddp_ports[to->sat_port - 1]; ddp; ddp = ddp->ddp_pnext) {
|
|
|
|
/* XXX should we handle 0.YY? */
|
|
|
|
|
|
|
|
/* XXXX.YY to socket on destination interface */
|
|
|
|
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) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* 0.255 to socket on receiving interface */
|
|
|
|
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) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXXX.0 to socket on destination interface */
|
|
|
|
if (to->sat_addr.s_net == aa->aa_firstnet &&
|
|
|
|
to->sat_addr.s_node == 0 &&
|
|
|
|
ntohs(ddp->ddp_lsat.sat_addr.s_net) >=
|
|
|
|
ntohs(aa->aa_firstnet) &&
|
|
|
|
ntohs(ddp->ddp_lsat.sat_addr.s_net) <=
|
|
|
|
ntohs(aa->aa_lastnet)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ddp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize all the ddp & appletalk stuff
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ddp_init()
|
|
|
|
{
|
|
|
|
TAILQ_INIT(&at_ifaddr);
|
|
|
|
atintrq1.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
atintrq2.ifq_maxlen = IFQ_MAXLEN;
|
2003-02-26 10:53:04 +03:00
|
|
|
|
|
|
|
MOWNER_ATTACH(&atalk_tx_mowner);
|
|
|
|
MOWNER_ATTACH(&atalk_rx_mowner);
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void
|
|
|
|
ddp_clean()
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
|
|
|
for (ddp = ddpcb; ddp; ddp = ddp->ddp_next)
|
|
|
|
at_pcbdetach(ddp->ddp_socket, ddp);
|
|
|
|
}
|
|
|
|
#endif
|