2009-03-15 00:04:01 +03:00
|
|
|
/* $NetBSD: clnp_er.c,v 1.25 2009/03/14 21:04:25 dsl 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_er.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-15 00:04:01 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: clnp_er.c,v 1.25 2009/03/14 21:04:25 dsl Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
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>
|
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>
|
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>
|
1993-04-09 16:00:07 +04:00
|
|
|
#define CLNP_ER_CODES
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/clnp.h>
|
|
|
|
#include <netiso/clnp_stat.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/tp_param.h>
|
|
|
|
#include <netiso/tp_var.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
2004-04-19 09:16:45 +04:00
|
|
|
static const struct clnp_fixed er_template = {
|
1996-02-14 01:07:57 +03:00
|
|
|
ISO8473_CLNP, /* network identifier */
|
|
|
|
0, /* length */
|
1993-04-09 16:00:07 +04:00
|
|
|
ISO8473_V1, /* version */
|
|
|
|
CLNP_TTL, /* ttl */
|
|
|
|
CLNP_ER, /* type */
|
2006-08-30 03:40:14 +04:00
|
|
|
0, /* segment length msb */
|
|
|
|
0, /* segment length lsb */
|
|
|
|
0, /* checksum msb */
|
|
|
|
0, /* checksum lmsb */
|
1993-04-09 16:00:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_er_input
|
|
|
|
*
|
|
|
|
* PURPOSE: Process an ER pdu.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS:
|
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_er_input(
|
|
|
|
struct mbuf *m, /* ptr to packet itself */
|
|
|
|
struct iso_addr *src, /* ptr to src of er */
|
|
|
|
u_int reason) /* reason code of er */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int cmd = -1;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CTLINPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_er_input: m %p, src %s, reason x%x\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
m, clnp_iso_addrp(src), reason);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
INCSTAT(cns_er_inhist[clnp_er_index(reason)]);
|
|
|
|
switch (reason) {
|
1996-02-14 01:07:57 +03:00
|
|
|
case GEN_NOREAS:
|
|
|
|
case GEN_PROTOERR:
|
|
|
|
break;
|
|
|
|
case GEN_BADCSUM:
|
|
|
|
cmd = PRC_PARAMPROB;
|
|
|
|
break;
|
|
|
|
case GEN_CONGEST:
|
|
|
|
cmd = PRC_QUENCH;
|
|
|
|
break;
|
|
|
|
case GEN_HDRSYNTAX:
|
|
|
|
cmd = PRC_PARAMPROB;
|
|
|
|
break;
|
|
|
|
case GEN_SEGNEEDED:
|
|
|
|
cmd = PRC_MSGSIZE;
|
|
|
|
break;
|
|
|
|
case GEN_INCOMPLETE:
|
|
|
|
cmd = PRC_PARAMPROB;
|
|
|
|
break;
|
|
|
|
case GEN_DUPOPT:
|
|
|
|
cmd = PRC_PARAMPROB;
|
|
|
|
break;
|
|
|
|
case ADDR_DESTUNREACH:
|
|
|
|
cmd = PRC_UNREACH_HOST;
|
|
|
|
break;
|
|
|
|
case ADDR_DESTUNKNOWN:
|
|
|
|
cmd = PRC_UNREACH_PROTOCOL;
|
|
|
|
break;
|
|
|
|
case SRCRT_UNSPECERR:
|
|
|
|
case SRCRT_SYNTAX:
|
|
|
|
case SRCRT_UNKNOWNADDR:
|
|
|
|
case SRCRT_BADPATH:
|
|
|
|
cmd = PRC_UNREACH_SRCFAIL;
|
|
|
|
break;
|
|
|
|
case TTL_EXPTRANSIT:
|
|
|
|
cmd = PRC_TIMXCEED_INTRANS;
|
|
|
|
break;
|
|
|
|
case TTL_EXPREASS:
|
|
|
|
cmd = PRC_TIMXCEED_REASS;
|
|
|
|
break;
|
|
|
|
case DISC_UNSUPPOPT:
|
|
|
|
case DISC_UNSUPPVERS:
|
|
|
|
case DISC_UNSUPPSECURE:
|
|
|
|
case DISC_UNSUPPSRCRT:
|
|
|
|
case DISC_UNSUPPRECRT:
|
|
|
|
cmd = PRC_PARAMPROB;
|
|
|
|
break;
|
|
|
|
case REASS_INTERFERE:
|
|
|
|
cmd = PRC_TIMXCEED_REASS;
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tpclnp_ctlinput1 is called directly so that we don't
|
|
|
|
* have to build an iso_sockaddr out of src.
|
|
|
|
*/
|
|
|
|
if (cmd >= 0)
|
|
|
|
tpclnp_ctlinput1(cmd, src);
|
|
|
|
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_discard
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Discard a clnp datagram
|
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
|
|
|
*
|
|
|
|
* SIDE EFFECTS: Will emit an ER pdu if possible
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: This code assumes that we have previously tried to pull
|
|
|
|
* up the header of the datagram into one mbuf.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
clnp_discard(struct mbuf *m, u_int reason)
|
|
|
|
/* m: header of packet to discard */
|
|
|
|
/* reason: reason for discard */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DISCARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_discard: m %p, reason x%x\n", m, reason);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (m != NULL) {
|
|
|
|
if (m->m_len >= sizeof(struct clnp_fixed)) {
|
2000-03-30 16:51:13 +04:00
|
|
|
struct clnp_fixed *clnp =
|
1996-02-14 01:07:57 +03:00
|
|
|
mtod(m, struct clnp_fixed *);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (((clnp->cnf_type & CNF_TYPE) != CLNP_ER) &&
|
1996-02-14 01:07:57 +03:00
|
|
|
(clnp->cnf_type & CNF_ERR_OK)) {
|
|
|
|
clnp_emit_er(m, reason);
|
|
|
|
return;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_emit_er
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Send an ER pdu.
|
|
|
|
* The src of the of the ER pdu is the host that is sending
|
|
|
|
* the ER (ie. us), *not* the original destination of the
|
|
|
|
* packet.
|
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: Takes responsibility for freeing mbuf passed
|
|
|
|
* This function may be called with a packet that
|
|
|
|
* was created by us; in this case, do not send
|
|
|
|
* an ER.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
clnp_emit_er(struct mbuf *m, u_int reason)
|
|
|
|
/* m: header of packet to discard */
|
|
|
|
/* reason: reason for discard */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
struct clnp_fixed *er;
|
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;
|
1996-02-14 01:07:57 +03:00
|
|
|
struct ifnet *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
|
|
|
const struct sockaddr *first_hop;
|
1996-02-14 01:07:57 +03:00
|
|
|
struct iso_addr src, dst, *our_addr;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *hoff, *hend;
|
|
|
|
int total_len; /* total len of dg */
|
1996-02-14 01:07:57 +03:00
|
|
|
struct iso_ifaddr *ia = 0;
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DISCARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_emit_er: m %p, hdr len %d\n",
|
1996-04-13 05:34:06 +04:00
|
|
|
m, clnp->cnf_hdr_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#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
|
|
|
memset(&route, 0, sizeof(route));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If header length is incorrect, or entire header is not contained
|
|
|
|
* in this mbuf, we punt
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((clnp->cnf_hdr_len < CLNP_HDR_MIN) ||
|
1996-02-14 01:07:57 +03:00
|
|
|
(clnp->cnf_hdr_len > CLNP_HDR_MAX) ||
|
|
|
|
(clnp->cnf_hdr_len > m->m_len))
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/* extract src, dest address */
|
2007-03-04 08:59:00 +03:00
|
|
|
hend = (char *)clnp + clnp->cnf_hdr_len;
|
|
|
|
hoff = (char *)clnp + sizeof(struct clnp_fixed);
|
1993-04-09 16:00:07 +04:00
|
|
|
CLNP_EXTRACT_ADDR(dst, hoff, hend);
|
2007-03-04 08:59:00 +03:00
|
|
|
if (hoff == (void *) 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
CLNP_EXTRACT_ADDR(src, hoff, hend);
|
2007-03-04 08:59:00 +03:00
|
|
|
if (hoff == (void *) 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Do not send ER if we generated the packet.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (clnp_ours(&src))
|
|
|
|
goto bad;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Trim mbuf to hold only the header. This mbuf will be the 'data' of
|
|
|
|
* the er pdu
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (m->m_next != NULL) {
|
|
|
|
m_freem(m->m_next);
|
|
|
|
m->m_next = NULL;
|
|
|
|
}
|
|
|
|
if (m->m_len > clnp->cnf_hdr_len)
|
1996-02-14 01:07:57 +03:00
|
|
|
m_adj(m, (int) -(m->m_len - (int) clnp->cnf_hdr_len));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* route er pdu: note we send pkt to src of original packet */
|
1996-02-14 01:07:57 +03:00
|
|
|
if (clnp_route(&src, &route, /* flags */ 0, &first_hop, &ia) != 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/* compute our address based upon firsthop/ifp */
|
|
|
|
if (ia)
|
1996-02-14 01:07:57 +03:00
|
|
|
our_addr = &ia->ia_addr.siso_addr;
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
1996-02-14 01:07:57 +03:00
|
|
|
goto bad;
|
1993-04-09 16:00:07 +04:00
|
|
|
ifp = ia->ia_ifp;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DISCARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_emit_er: to %s", clnp_iso_addrp(&src));
|
|
|
|
printf(" from %s\n", clnp_iso_addrp(our_addr));
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DISCARD]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_emit_er: 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(first_hop)->siso_addr));
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* allocate mbuf for er pdu header: punt on no space */
|
2003-05-25 12:47:54 +04:00
|
|
|
/*
|
2005-02-27 01:31:44 +03:00
|
|
|
* fixed part, two addresses and their length bytes, and a
|
2003-05-25 12:47:54 +04:00
|
|
|
* 4-byte option
|
|
|
|
*/
|
|
|
|
|
|
|
|
M_PREPEND(m, sizeof(struct clnp_fixed) + 4 + 1 + 1 +
|
|
|
|
src.isoa_len + our_addr->isoa_len, M_DONTWAIT);
|
|
|
|
if (m == 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
2003-05-25 12:47:54 +04:00
|
|
|
er = mtod(m, struct clnp_fixed *);
|
1993-04-09 16:00:07 +04:00
|
|
|
*er = er_template;
|
|
|
|
|
|
|
|
/* setup src/dst on er pdu */
|
|
|
|
/* NOTE REVERSAL OF SRC/DST */
|
2007-03-04 08:59:00 +03:00
|
|
|
hoff = (char *)er + sizeof(struct clnp_fixed);
|
1993-04-09 16:00:07 +04:00
|
|
|
CLNP_INSERT_ADDR(hoff, src);
|
|
|
|
CLNP_INSERT_ADDR(hoff, *our_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: if complete src rt was specified, then reverse path, and
|
|
|
|
* copy into er as option.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* add er option */
|
|
|
|
*hoff++ = CLNPOVAL_ERREAS; /* code */
|
1996-02-14 01:07:57 +03:00
|
|
|
*hoff++ = 2; /* length */
|
|
|
|
*hoff++ = reason; /* discard reason */
|
|
|
|
*hoff++ = 0; /* error localization = not specified */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* set length */
|
2007-03-04 08:59:00 +03:00
|
|
|
er->cnf_hdr_len = (u_char) (hoff - (char *)er);
|
2003-05-25 12:47:54 +04:00
|
|
|
total_len = m->m_pkthdr.len;
|
1993-04-09 16:00:07 +04:00
|
|
|
HTOC(er->cnf_seglen_msb, er->cnf_seglen_lsb, total_len);
|
|
|
|
|
|
|
|
/* compute checksum (on header only) */
|
2003-05-25 12:47:54 +04:00
|
|
|
iso_gen_csum(m, CLNP_CKSUM_OFF, (int) er->cnf_hdr_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* trim packet if too large for interface */
|
|
|
|
if (total_len > ifp->if_mtu)
|
2003-05-25 12:47:54 +04:00
|
|
|
m_adj(m, -(total_len - ifp->if_mtu));
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/* send packet */
|
|
|
|
INCSTAT(cns_er_outhist[clnp_er_index(reason)]);
|
2008-01-14 07:17:35 +03:00
|
|
|
(void) (*ifp->if_output) (ifp, m, first_hop, rtcache_validate(&route));
|
1993-04-09 16:00:07 +04:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* free route if it is a temp */
|
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
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_er_index(u_int p)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
u_char *cp = clnp_er_codes + CLNP_ERRORS;
|
1993-04-09 16:00:07 +04:00
|
|
|
while (cp > clnp_er_codes) {
|
|
|
|
cp--;
|
|
|
|
if (*cp == p)
|
|
|
|
return (cp - clnp_er_codes);
|
|
|
|
}
|
|
|
|
return (CLNP_ERRORS + 1);
|
|
|
|
}
|