2009-03-18 19:00:08 +03:00
|
|
|
/* $NetBSD: clnp_subr.c,v 1.33 2009/03/18 16:00:23 cegger Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*-
|
1994-05-13 10:08:03 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-09 16:00:07 +04:00
|
|
|
* 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.
|
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* @(#)clnp_subr.c 8.1 (Berkeley) 6/10/93
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
Copyright IBM Corporation 1987
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1993-04-09 16:00:07 +04:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1996-02-14 01:07:57 +03:00
|
|
|
both that copyright notice and this permission notice appear in
|
1993-04-09 16:00:07 +04:00
|
|
|
supporting documentation, and that the name of IBM not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
1996-02-14 01:07:57 +03:00
|
|
|
software without specific, written prior permission.
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
|
|
|
|
*/
|
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-18 19:00:08 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: clnp_subr.c,v 1.33 2009/03/18 16:00:23 cegger Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ISO
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <sys/systm.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_dl.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/iso_var.h>
|
|
|
|
#include <netiso/iso_pcb.h>
|
|
|
|
#include <netiso/iso_snpac.h>
|
|
|
|
#include <netiso/clnp.h>
|
|
|
|
#include <netiso/clnp_stat.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/esis.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_data_ck
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Check that the amount of data in the mbuf chain is
|
|
|
|
* at least as much as the clnp header would have us
|
|
|
|
* expect. Trim mbufs if longer than expected, drop
|
|
|
|
* packet if shorter than expected.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: success - ptr to mbuf chain
|
|
|
|
* failure - 0
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_data_ck(
|
|
|
|
struct mbuf *m, /* ptr to mbuf chain containing hdr & data */
|
|
|
|
int length) /* length (in bytes) of packet */
|
1996-02-14 01:07:57 +03:00
|
|
|
{
|
2004-04-19 09:16:45 +04:00
|
|
|
int len; /* length of data */
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *mhead; /* ptr to head of chain */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
len = -length;
|
|
|
|
mhead = m;
|
|
|
|
for (;;) {
|
|
|
|
len += m->m_len;
|
|
|
|
if (m->m_next == 0)
|
|
|
|
break;
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
if (len != 0) {
|
|
|
|
if (len < 0) {
|
|
|
|
INCSTAT(cns_toosmall);
|
|
|
|
clnp_discard(mhead, GEN_INCOMPLETE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (len <= m->m_len)
|
|
|
|
m->m_len -= len;
|
|
|
|
else
|
|
|
|
m_adj(mhead, -len);
|
|
|
|
}
|
|
|
|
return mhead;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_extract_addr
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Extract the source and destination address from the
|
|
|
|
* supplied buffer. Place them in the supplied address buffers.
|
|
|
|
* If insufficient data is supplied, then fail.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: success - Address of first byte in the packet past
|
|
|
|
* the address part.
|
|
|
|
* failure - 0
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
2007-03-04 08:59:00 +03:00
|
|
|
void *
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_extract_addr(
|
2007-03-04 08:59:00 +03:00
|
|
|
void * bufp, /* ptr to buffer containing addresses */
|
2004-04-19 09:16:45 +04:00
|
|
|
int buflen, /* length of buffer */
|
|
|
|
struct iso_addr *srcp, /* ptr to source address buffer */
|
|
|
|
struct iso_addr *destp) /* ptr to destination address
|
1996-02-14 01:07:57 +03:00
|
|
|
* buffer */
|
|
|
|
{
|
2007-03-29 12:19:20 +04:00
|
|
|
size_t len; /* argument to memcpy */
|
1996-02-14 01:07:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check that we have enough data. Plus1 is for length octet
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
2007-03-29 12:19:20 +04:00
|
|
|
len = (u_char)*bufp++;
|
|
|
|
if (len > buflen)
|
|
|
|
return NULL;
|
|
|
|
destp->isoa_len = len;
|
|
|
|
(void)memcpy(destp, bufp, len);
|
1993-04-09 16:00:07 +04:00
|
|
|
buflen -= len;
|
|
|
|
bufp += len;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* check that we have enough data. Plus1 is for length octet
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
2007-03-29 12:19:20 +04:00
|
|
|
len = (u_char)*bufp++;
|
|
|
|
if (len > buflen)
|
|
|
|
return NULL;
|
|
|
|
srcp->isoa_len = len;
|
|
|
|
(void)memcpy(srcp, bufp, len);
|
1993-04-09 16:00:07 +04:00
|
|
|
bufp += len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insure that the addresses make sense
|
|
|
|
*/
|
|
|
|
if (iso_ck_addr(srcp) && iso_ck_addr(destp))
|
|
|
|
return bufp;
|
|
|
|
else
|
2007-03-29 12:19:20 +04:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* notdef */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_ours
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Decide whether the supplied packet is destined for
|
|
|
|
* us, or that it should be forwarded on.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: packet is for us - 1
|
|
|
|
* packet is not for us - 0
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_ours(
|
|
|
|
struct iso_addr *dst) /* ptr to destination address */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct iso_ifaddr *ia; /* scan through interface addresses */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1995-06-13 11:13:14 +04:00
|
|
|
for (ia = iso_ifaddr.tqh_first; ia != 0; ia = ia->ia_list.tqe_next) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_ROUTE]) {
|
2005-02-27 01:31:44 +03:00
|
|
|
printf("clnp_ours: ia_sis %p, dst %p\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
&ia->ia_addr, dst);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* XXX Warning:
|
|
|
|
* We are overloading siso_tlen in the if's address, as an nsel length.
|
|
|
|
*/
|
|
|
|
if (dst->isoa_len == ia->ia_addr.siso_nlen &&
|
2009-03-18 18:14:29 +03:00
|
|
|
memcmp((void *) ia->ia_addr.siso_addr.isoa_genaddr,
|
2007-03-04 08:59:00 +03:00
|
|
|
(void *) dst->isoa_genaddr,
|
1996-02-14 01:07:57 +03:00
|
|
|
ia->ia_addr.siso_nlen - ia->ia_addr.siso_tlen) == 0)
|
|
|
|
return 1;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dec bit set if ifp qlen is greater than congest_threshold */
|
1996-02-14 01:07:57 +03:00
|
|
|
int congest_threshold = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_forward
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Forward the datagram passed
|
|
|
|
* clnpintr guarantees that the header will be
|
|
|
|
* contigious (a cluster mbuf will be used if necessary).
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If oidx is NULL, no options are present.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: nothing
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_forward(
|
|
|
|
struct mbuf *m, /* pkt to forward */
|
|
|
|
int len, /* length of pkt */
|
|
|
|
struct iso_addr *dst, /* destination address */
|
|
|
|
struct clnp_optidx *oidx, /* option index */
|
|
|
|
int seg_off, /* offset of segmentation part */
|
|
|
|
struct snpa_hdr *inbound_shp) /* subnetwork header of inbound
|
1996-02-14 01:07:57 +03:00
|
|
|
* packet */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2004-04-19 09:16:45 +04:00
|
|
|
struct clnp_fixed *clnp; /* ptr to fixed part of header */
|
|
|
|
int error; /* return value of route function */
|
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 *next_hop; /* next hop for dgram */
|
2004-04-19 09:16:45 +04:00
|
|
|
struct ifnet *ifp; /* ptr to outgoing interface */
|
1996-02-14 01:07:57 +03:00
|
|
|
struct iso_ifaddr *ia = 0; /* ptr to iso name for ifp */
|
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 route route; /* filled in by clnp_route */
|
2008-01-14 07:17:35 +03:00
|
|
|
struct rtentry *rt;
|
1996-02-14 01:07:57 +03:00
|
|
|
extern int iso_systype;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
2009-03-18 19:00:08 +03:00
|
|
|
memset((void *) & route, 0, sizeof(route)); /* MUST be done before
|
1996-02-14 01:07:57 +03:00
|
|
|
* "bad:" */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't forward multicast or broadcast packets
|
|
|
|
*/
|
|
|
|
if ((inbound_shp) && (IS_MULTICAST(inbound_shp->snh_dhost))) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: dropping multicast packet\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
clnp->cnf_type &= ~CNF_ERR_OK; /* so we don't generate an ER */
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_discard(m, 0);
|
|
|
|
INCSTAT(cns_cantforward);
|
|
|
|
goto done;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: %d bytes, to %s, options %p\n", len,
|
1996-04-13 05:34:06 +04:00
|
|
|
clnp_iso_addrp(dst), oidx);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrement ttl, and if zero drop datagram
|
|
|
|
* Can't compare ttl as less than zero 'cause its a unsigned
|
|
|
|
*/
|
|
|
|
if ((clnp->cnf_ttl == 0) || (--clnp->cnf_ttl == 0)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: discarding datagram because ttl is zero\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_ttlexpired);
|
|
|
|
clnp_discard(m, TTL_EXPTRANSIT);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Route packet; special case for source rt
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if CLNPSRCRT_VALID
|
|
|
|
(oidx) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* Update src route first
|
|
|
|
*/
|
|
|
|
clnp_update_srcrt(m, oidx);
|
|
|
|
error = clnp_srcroute(m, oidx, &route, &next_hop, &ia, dst);
|
|
|
|
} else {
|
|
|
|
error = clnp_route(dst, &route, 0, &next_hop, &ia);
|
|
|
|
}
|
|
|
|
if (error || ia == 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: can't route packet (errno %d)\n", error);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_discard(m, ADDR_DESTUNREACH);
|
|
|
|
INCSTAT(cns_cantforward);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
ifp = ia->ia_ifp;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: packet routed to %s\n",
|
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
|
|
|
clnp_iso_addrp(&satocsiso(next_hop)->siso_addr));
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
INCSTAT(cns_forward);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are an intermediate system and
|
|
|
|
* we are routing outbound on the same ifp that the packet
|
1996-02-14 01:07:57 +03:00
|
|
|
* arrived upon, and we know the next hop snpa,
|
1993-04-09 16:00:07 +04:00
|
|
|
* then generate a redirect request
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((iso_systype & SNPA_IS) && (inbound_shp) &&
|
|
|
|
(ifp == inbound_shp->snh_ifp))
|
2008-01-14 07:17:35 +03:00
|
|
|
esis_rdoutput(inbound_shp, m, oidx, dst, rtcache_validate(&route));
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* If options are present, update them
|
|
|
|
*/
|
|
|
|
if (oidx) {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct iso_addr *mysrc = &ia->ia_addr.siso_addr;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (mysrc == NULL) {
|
|
|
|
clnp_discard(m, ADDR_DESTUNREACH);
|
|
|
|
INCSTAT(cns_cantforward);
|
|
|
|
clnp_stat.cns_forward--;
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
(void) clnp_dooptions(m, oidx, ifp, mysrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DECBIT
|
|
|
|
if (ifp->if_snd.ifq_len > congest_threshold) {
|
|
|
|
/*
|
|
|
|
* Congestion! Set the Dec Bit and thank Dave Oran
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: congestion experienced\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
if ((oidx) && (oidx->cni_qos_formatp)) {
|
2007-03-04 08:59:00 +03:00
|
|
|
char * qosp = CLNP_OFFTOOPT(m, oidx->cni_qos_formatp);
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char qos = *qosp;
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FORWARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_forward: setting congestion bit (qos x%x)\n", qos);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
if ((qos & CLNPOVAL_GLOBAL) == CLNPOVAL_GLOBAL) {
|
|
|
|
qos |= CLNPOVAL_CONGESTED;
|
|
|
|
INCSTAT(cns_congest_set);
|
|
|
|
*qosp = qos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* DECBIT */
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* Dispatch the datagram if it is small enough, otherwise fragment
|
|
|
|
*/
|
2008-01-14 07:17:35 +03:00
|
|
|
if ((rt = rtcache_validate(&route)) == NULL)
|
|
|
|
;
|
|
|
|
else if (len <= SN_MTU(ifp, rt)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_gen_csum(m, CLNP_CKSUM_OFF, (int) clnp->cnf_hdr_len);
|
2008-01-14 07:17:35 +03:00
|
|
|
(void) (*ifp->if_output) (ifp, m, next_hop, rt);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
2008-01-14 07:17:35 +03:00
|
|
|
(void) clnp_fragment(ifp, m, next_hop, len, seg_off, /* flags */ 0, rt);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
done:
|
|
|
|
/*
|
|
|
|
* Free route
|
|
|
|
*/
|
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(&route);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_insert_addr
|
|
|
|
*
|
|
|
|
* PURPOSE: Insert the address part into a clnp datagram.
|
|
|
|
*
|
|
|
|
* RETURNS: Address of first byte after address part in datagram.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* NOTES: Assume that there is enough space for the address part.
|
|
|
|
*/
|
2007-03-04 08:59:00 +03:00
|
|
|
void *
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_insert_addr(
|
2007-03-04 08:59:00 +03:00
|
|
|
void * bufp, /* address of where addr part goes */
|
2004-04-19 09:16:45 +04:00
|
|
|
struct iso_addr *srcp, /* ptr to src addr */
|
|
|
|
struct iso_addr *dstp) /* ptr to dst addr */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
*bufp++ = dstp->isoa_len;
|
2007-03-29 12:19:20 +04:00
|
|
|
(void)memcpy(bufp, dstp, dstp->isoa_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
bufp += dstp->isoa_len;
|
|
|
|
|
|
|
|
*bufp++ = srcp->isoa_len;
|
2007-03-29 12:19:20 +04:00
|
|
|
(void)memcpy(bufp, srcp, srcp->isoa_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
bufp += srcp->isoa_len;
|
|
|
|
|
|
|
|
return bufp;
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* notdef */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_route
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Route a clnp datagram to the first hop toward its
|
|
|
|
* destination. In many cases, the first hop will be
|
|
|
|
* the destination. The address of a route
|
|
|
|
* is specified. If a routing entry is present in
|
|
|
|
* that route, and it is still up to the same destination,
|
|
|
|
* then no further action is necessary. Otherwise, a
|
|
|
|
* new routing entry will be allocated.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: route found - 0
|
|
|
|
* unix error code
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: It is up to the caller to free the routing entry
|
|
|
|
* allocated in route.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_route(
|
|
|
|
struct iso_addr *dst, /* ptr to datagram destination */
|
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 route *ro, /* existing route structure */
|
2004-04-19 09:16:45 +04:00
|
|
|
int flags, /* flags for routing */
|
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 **first_hop, /* result: fill in with ptr to
|
|
|
|
* firsthop */
|
2004-04-19 09:16:45 +04:00
|
|
|
struct iso_ifaddr **ifa) /* result: fill in with ptr to ifa */
|
1993-04-09 16:00:07 +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
|
|
|
int rc;
|
|
|
|
union {
|
|
|
|
struct sockaddr dst;
|
|
|
|
struct sockaddr_iso dsti;
|
|
|
|
} u;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
if (flags & SO_DONTROUTE) {
|
|
|
|
struct iso_ifaddr *ia;
|
|
|
|
|
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 ((rc = sockaddr_iso_init(&u.dsti, dst)) != 0)
|
|
|
|
return rc;
|
|
|
|
rtcache_setdst(ro, &u.dst);
|
|
|
|
|
|
|
|
if (rtcache_getdst(ro) == NULL)
|
|
|
|
return EADDRNOTAVAIL;
|
|
|
|
ia = iso_localifa(satocsiso(rtcache_getdst(ro)));
|
2007-02-17 08:01:47 +03:00
|
|
|
if (ia == NULL)
|
1993-04-09 16:00:07 +04:00
|
|
|
return EADDRNOTAVAIL;
|
2007-02-17 08:01:47 +03:00
|
|
|
if (ifa != NULL)
|
1993-04-09 16:00:07 +04:00
|
|
|
*ifa = ia;
|
2007-02-17 08:01:47 +03:00
|
|
|
if (first_hop != 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
|
|
|
*first_hop = rtcache_getdst(ro);
|
1993-04-09 16:00:07 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* set up new route structure */
|
|
|
|
if ((rc = sockaddr_iso_init(&u.dsti, dst)) != 0)
|
|
|
|
return rc;
|
2007-12-20 22:53:29 +03:00
|
|
|
if ((rt = rtcache_lookup(ro, &u.dst)) == 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
|
|
|
rtcache_free(ro);
|
|
|
|
return ENETUNREACH;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
2007-12-20 22:53:29 +03:00
|
|
|
rt->rt_use++;
|
2007-02-17 08:01:47 +03:00
|
|
|
if (ifa != NULL)
|
2007-12-20 22:53:29 +03:00
|
|
|
if ((*ifa = (struct iso_ifaddr *)rt->rt_ifa) == NULL)
|
1993-04-09 16:00:07 +04:00
|
|
|
panic("clnp_route");
|
2007-02-17 08:01:47 +03:00
|
|
|
if (first_hop != NULL) {
|
2007-12-20 22:53:29 +03:00
|
|
|
if (rt->rt_flags & RTF_GATEWAY)
|
|
|
|
*first_hop = rt->rt_gateway;
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
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
|
|
|
*first_hop = rtcache_getdst(ro);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
2007-02-17 08:01:47 +03:00
|
|
|
return 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_srcroute
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Source route the datagram. If complete source
|
|
|
|
* routing is specified but not possible, then
|
|
|
|
* return an error. If src routing is terminated, then
|
|
|
|
* try routing on destination.
|
|
|
|
* Usage of first_hop,
|
|
|
|
* ifp, and error return is identical to clnp_route.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: 0 or unix error code
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: Remember that option index pointers are really
|
|
|
|
* offsets from the beginning of the mbuf.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_srcroute(
|
|
|
|
struct mbuf *options, /* ptr to options */
|
|
|
|
struct clnp_optidx *oidx, /* index to options */
|
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 route *ro, /* route structure */
|
|
|
|
const struct sockaddr **first_hop, /* RETURN: fill in with ptr to
|
|
|
|
* firsthop */
|
2004-04-19 09:16:45 +04:00
|
|
|
struct iso_ifaddr **ifa, /* RETURN: fill in with ptr to ifa */
|
|
|
|
struct iso_addr *final_dst) /* final destination */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct iso_addr dst; /* first hop specified by src rt */
|
|
|
|
int error = 0; /* return code */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Check if we have run out of routes
|
1993-04-09 16:00:07 +04:00
|
|
|
* If so, then try to route on destination.
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if CLNPSRCRT_TERM
|
|
|
|
(oidx, options) {
|
1993-04-09 16:00:07 +04:00
|
|
|
dst.isoa_len = final_dst->isoa_len;
|
2007-03-29 12:19:20 +04:00
|
|
|
if (sizeof(dst.isoa_genaddr) < (size_t)dst.isoa_len)
|
|
|
|
return EINVAL;
|
|
|
|
(void)memcpy(dst.isoa_genaddr, final_dst->isoa_genaddr,
|
|
|
|
(size_t)dst.isoa_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* setup dst based on src rt specified
|
|
|
|
*/
|
|
|
|
dst.isoa_len = CLNPSRCRT_CLEN(oidx, options);
|
2007-03-29 12:19:20 +04:00
|
|
|
if (sizeof(dst.isoa_genaddr) < (unsigned)dst.isoa_len)
|
|
|
|
return EINVAL;
|
|
|
|
(void)memcpy(dst.isoa_genaddr, CLNPSRCRT_CADDR(oidx, options),
|
|
|
|
(size_t)dst.isoa_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* try to route it
|
|
|
|
*/
|
|
|
|
error = clnp_route(&dst, ro, 0, first_hop, ifa);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* If complete src rt, first hop must be equal to dst
|
|
|
|
*/
|
|
|
|
if ((CLNPSRCRT_TYPE(oidx, options) == CLNPOVAL_COMPRT) &&
|
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
|
|
|
(!iso_addrmatch1(&satocsiso(*first_hop)->siso_addr, &dst))) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_srcroute: complete src route failed\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return EHOSTUNREACH; /* RAH? would like ESRCRTFAILED */
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_echoreply
|
|
|
|
*
|
|
|
|
* PURPOSE: generate an echo reply packet and transmit
|
|
|
|
*
|
|
|
|
* RETURNS: result of clnp_output
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1994-05-13 10:08:03 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_echoreply(
|
2006-10-12 05:30:41 +04:00
|
|
|
struct mbuf *ec_m, /* echo request */
|
|
|
|
int ec_len, /* length of ec */
|
|
|
|
struct sockaddr_iso *ec_src, /* src of ec */
|
|
|
|
struct sockaddr_iso *ec_dst, /* destination of ec (i.e., us) */
|
2006-11-16 04:32:37 +03:00
|
|
|
struct clnp_optidx *ec_oidxp) /* options index to ec packet */
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb isopcb;
|
|
|
|
int flags = CLNP_NOCACHE | CLNP_ECHOR;
|
|
|
|
int ret;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
/* fill in fake isopcb to pass to output function */
|
2009-03-18 19:00:08 +03:00
|
|
|
memset(&isopcb, 0, sizeof(isopcb));
|
1994-05-13 10:08:03 +04:00
|
|
|
isopcb.isop_laddr = ec_dst;
|
|
|
|
isopcb.isop_faddr = ec_src;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* forget copying the options for now. If implemented, need only copy
|
|
|
|
* record route option, but it must be reset to zero length
|
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
ret = clnp_output(ec_m, &isopcb, ec_len, flags);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OUTPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_echoreply: output returns %d\n", ret);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_badmtu
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: print notice of route with mtu not initialized.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: mtu of ifp.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: prints notice, slows down system.
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_badmtu(
|
|
|
|
struct ifnet *ifp, /* outgoing interface */
|
|
|
|
struct rtentry *rt, /* dst route */
|
|
|
|
int line, /* where the dirty deed occurred */
|
2005-05-30 01:27:45 +04:00
|
|
|
const char *file) /* where the dirty deed occurred */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("sending on route %p with no mtu, line %d of file %s\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
rt, line, file);
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ARGO_DEBUG
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("route dst is ");
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
dump_isoaddr(satocsiso(rt_getkey(rt)));
|
1993-04-09 16:00:07 +04:00
|
|
|
#endif
|
|
|
|
return ifp->if_mtu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_ypocb - backwards bcopy
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: bcopy starting at end of src rather than beginning.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: none
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: No attempt has been made to make this efficient
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_ypocb(
|
2007-03-04 08:59:00 +03:00
|
|
|
void * from, /* src buffer */
|
|
|
|
void * to, /* dst buffer */
|
2004-04-19 09:16:45 +04:00
|
|
|
u_int len) /* number of bytes */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
while (len--)
|
2007-03-04 08:59:00 +03:00
|
|
|
*((char *)to + len) = *((char *)from + len);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* ISO */
|