2001-11-13 03:56:55 +03:00
|
|
|
/* $NetBSD: clnp_output.c,v 1.13 2001/11/13 01:10:47 lukem 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* 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_output.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>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: clnp_output.c,v 1.13 2001/11/13 01:10:47 lukem Exp $");
|
|
|
|
|
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>
|
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/clnp.h>
|
|
|
|
#include <netiso/clnp_stat.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
static struct clnp_fixed dt_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 */
|
1996-02-14 01:07:57 +03:00
|
|
|
CLNP_DT | CNF_SEG_OK | CNF_ERR_OK, /* type */
|
|
|
|
0, /* segment length */
|
|
|
|
0 /* checksum */
|
1993-04-09 16:00:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct clnp_fixed raw_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 */
|
1996-02-14 01:07:57 +03:00
|
|
|
CLNP_RAW | CNF_SEG_OK | CNF_ERR_OK, /* type */
|
|
|
|
0, /* segment length */
|
|
|
|
0 /* checksum */
|
1993-04-09 16:00:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct clnp_fixed echo_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 */
|
1996-02-14 01:07:57 +03:00
|
|
|
CLNP_EC | CNF_SEG_OK | CNF_ERR_OK, /* type */
|
|
|
|
0, /* segment length */
|
|
|
|
0 /* checksum */
|
1993-04-09 16:00:07 +04:00
|
|
|
};
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
static struct clnp_fixed echor_template = {
|
1996-02-14 01:07:57 +03:00
|
|
|
ISO8473_CLNP, /* network identifier */
|
|
|
|
0, /* length */
|
1994-05-13 10:08:03 +04:00
|
|
|
ISO8473_V1, /* version */
|
|
|
|
CLNP_TTL, /* ttl */
|
1996-02-14 01:07:57 +03:00
|
|
|
CLNP_ECR | CNF_SEG_OK | CNF_ERR_OK, /* type */
|
|
|
|
0, /* segment length */
|
|
|
|
0 /* checksum */
|
1994-05-13 10:08:03 +04:00
|
|
|
};
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef DECBIT
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char qos_option[] = {CLNPOVAL_QOS, 1,
|
|
|
|
CLNPOVAL_GLOBAL | CLNPOVAL_SEQUENCING | CLNPOVAL_LOWDELAY};
|
|
|
|
#endif /* DECBIT */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int clnp_id = 0; /* id for segmented dgrams */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_output
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: output the data in the mbuf as a clnp datagram
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The data specified by m0 is sent as a clnp datagram.
|
|
|
|
* The mbuf chain m0 will be freed when this routine has
|
|
|
|
* returned.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If options is non-null, it points to an mbuf which
|
|
|
|
* contains options to be sent with the datagram. The
|
|
|
|
* options must be formatted in the mbuf according to
|
|
|
|
* clnp rules. Options will not be freed.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Datalen specifies the length of the data in m0.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Src and dst are the addresses for the packet.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If route is non-null, it is used as the route for
|
|
|
|
* the packet.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* By default, a DT is sent. However,
|
|
|
|
* if flags & CNLP_SEND_ER then an ER will be sent.
|
|
|
|
* If flags & CLNP_SEND_RAW, then the packet will
|
|
|
|
* be send as raw clnp.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: 0 success
|
|
|
|
* appropriate error code
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: none
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: Flags are interpretated as follows:
|
|
|
|
* CLNP_NO_SEG - do not allow this pkt to be segmented.
|
|
|
|
* CLNP_NO_ER - have pkt request ER suppression.
|
|
|
|
* CLNP_SEND_RAW - send pkt as RAW DT rather than TP DT
|
|
|
|
* CLNP_NO_CKSUM - don't compute clnp checksum
|
|
|
|
* CLNP_ECHO - send as ECHO packet
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* When checking for a cached packet, clnp checks
|
|
|
|
* that the route taken is still up. It does not
|
|
|
|
* check that the route is still to the same destination.
|
|
|
|
* This means that any entity that alters an existing
|
|
|
|
* route for an isopcb (such as when a redirect arrives)
|
|
|
|
* must invalidate the clnp cache. It might be perferable
|
|
|
|
* to have clnp check that the route has the same dest, but
|
|
|
|
* by avoiding this check, we save a call to
|
|
|
|
* iso_addrmatch1.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
#if __STDC__
|
|
|
|
clnp_output(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
clnp_output(m0, va_alist)
|
|
|
|
struct mbuf *m0; /* data for the packet */
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb *isop; /* iso pcb */
|
|
|
|
int datalen;/* number of bytes of data in m0 */
|
|
|
|
int flags; /* flags */
|
|
|
|
int error = 0; /* return value of function */
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m = m0; /* mbuf for clnp header chain */
|
|
|
|
struct clnp_fixed *clnp; /* ptr to fixed part of hdr */
|
|
|
|
caddr_t hoff; /* offset into header */
|
1996-02-14 01:07:57 +03:00
|
|
|
int total_len; /* total length of packet */
|
|
|
|
struct iso_addr *src; /* ptr to source address */
|
|
|
|
struct iso_addr *dst; /* ptr to destination address */
|
|
|
|
struct clnp_cache clc; /* storage for cache information */
|
|
|
|
struct clnp_cache *clcp = NULL; /* ptr to clc */
|
|
|
|
int hdrlen = 0;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m0);
|
|
|
|
isop = va_arg(ap, struct isopcb *);
|
|
|
|
datalen = va_arg(ap, int);
|
|
|
|
flags = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
dst = &isop->isop_faddr->siso_addr;
|
|
|
|
if (isop->isop_laddr == 0) {
|
|
|
|
struct iso_ifaddr *ia = 0;
|
|
|
|
clnp_route(dst, &isop->isop_route, flags, 0, &ia);
|
|
|
|
if (ia == 0 || ia->ia_ifa.ifa_addr->sa_family != AF_ISO)
|
|
|
|
return (ENETUNREACH);
|
|
|
|
src = &ia->ia_addr.siso_addr;
|
|
|
|
} else
|
|
|
|
src = &isop->isop_laddr->siso_addr;
|
|
|
|
|
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_output: to %s", clnp_iso_addrp(dst));
|
|
|
|
printf(" from %s of %d bytes\n", clnp_iso_addrp(src), datalen);
|
|
|
|
printf("\toptions %p, flags x%x, isop_clnpcache %p\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
isop->isop_options, flags, isop->isop_clnpcache);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (isop->isop_clnpcache != NULL) {
|
|
|
|
clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if cache is valid ...
|
|
|
|
*/
|
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_output: ck cache: clcp %p\n", clcp);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (clcp != NULL) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\tclc_dst %s\n", clnp_iso_addrp(&clcp->clc_dst));
|
|
|
|
printf("\tisop_opts %p, clc_opts %p\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
isop->isop_options, clcp->clc_options);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (isop->isop_route.ro_rt)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\tro_rt %p, rt_flags x%x\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
isop->isop_route.ro_rt,
|
|
|
|
isop->isop_route.ro_rt->rt_flags);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\tflags x%x, clc_flags x%x\n", flags,
|
1996-10-11 03:12:43 +04:00
|
|
|
clcp->clc_flags);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\tclc_hdr %p\n", clcp->clc_hdr);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((clcp != NULL) && /* cache exists */
|
|
|
|
(isop->isop_options == clcp->clc_options) && /* same options */
|
|
|
|
(iso_addrmatch1(dst, &clcp->clc_dst)) && /* dst still same */
|
|
|
|
(isop->isop_route.ro_rt != NULL) && /* route exists */
|
|
|
|
(isop->isop_route.ro_rt == clcp->clc_rt) && /* and is cached */
|
|
|
|
(isop->isop_route.ro_rt->rt_flags & RTF_UP) && /* route still up */
|
|
|
|
(flags == clcp->clc_flags) && /* same flags */
|
|
|
|
(clcp->clc_hdr != NULL)) { /* hdr mbuf exists */
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The cache is valid
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
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_output: using cache\n");
|
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
|
|
|
m = m_copy(clcp->clc_hdr, 0, (int) M_COPYALL);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (m == NULL) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* No buffers left to copy cached packet header. Use
|
|
|
|
* the cached packet header this time, and
|
|
|
|
* mark the hdr as vacant
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
m = clcp->clc_hdr;
|
|
|
|
clcp->clc_hdr = NULL;
|
|
|
|
}
|
|
|
|
m->m_next = m0; /* ASSUMES pkt hdr is 1 mbuf long */
|
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_optidx *oidx = NULL; /* index to clnp options */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The cache is not valid. Allocate an mbuf (if necessary)
|
|
|
|
* to hold cached info. If one is not available, then
|
|
|
|
* don't bother with the cache
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
INCSTAT(cns_cachemiss);
|
|
|
|
if (flags & CLNP_NOCACHE) {
|
|
|
|
clcp = &clc;
|
|
|
|
} else {
|
|
|
|
if (isop->isop_clnpcache == NULL) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* There is no clnpcache. Allocate an mbuf
|
|
|
|
* to hold one
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((isop->isop_clnpcache = m_get(M_DONTWAIT, MT_HEADER))
|
1996-02-14 01:07:57 +03:00
|
|
|
== NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* No mbufs available. Pretend that we
|
|
|
|
* don't want caching this time.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
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_output: no mbufs to allocate to cache\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
flags |= CLNP_NOCACHE;
|
1993-04-09 16:00:07 +04:00
|
|
|
clcp = &clc;
|
|
|
|
} else {
|
|
|
|
clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* A clnpcache mbuf exists. If the clc_hdr
|
|
|
|
* is not null, we must free it, as a new one
|
|
|
|
* is about to be created.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
|
|
|
|
if (clcp->clc_hdr != NULL) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The clc_hdr is not null but a
|
|
|
|
* clnpcache mbuf exists. This means
|
|
|
|
* that there was a cache, but the
|
|
|
|
* existing copy of the hdr is no
|
|
|
|
* longer valid. Free it now
|
|
|
|
* before we lose the pointer to it.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
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(
|
1996-04-13 05:34:06 +04:00
|
|
|
"clnp_output: freeing old clc_hdr %p\n",
|
|
|
|
clcp->clc_hdr);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
m_free(clcp->clc_hdr);
|
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_output: freed old clc_hdr (done)\n");
|
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_OUTPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_output: NEW clcp %p\n", clcp);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
bzero((caddr_t) clcp, sizeof(struct clnp_cache));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (isop->isop_optindex)
|
|
|
|
oidx = mtod(isop->isop_optindex, struct clnp_optidx *);
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Don't allow packets with security, quality of service,
|
|
|
|
* priority, or error report options to be sent.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((isop->isop_options) && (oidx)) {
|
|
|
|
if ((oidx->cni_securep) ||
|
1996-02-14 01:07:57 +03:00
|
|
|
(oidx->cni_priorp) ||
|
|
|
|
(oidx->cni_qos_formatp) ||
|
|
|
|
(oidx->cni_er_reason != ER_INVALREAS)) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OUTPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_output: pkt dropped - option unsupported\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
m_freem(m0);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (EINVAL);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Don't allow any invalid flags to be set
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((flags & (CLNP_VFLAGS)) != 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_output: packet dropped - flags unsupported\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_odropped);
|
|
|
|
m_freem(m0);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (EINVAL);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Don't allow funny lengths on dst; src may be zero in which
|
|
|
|
* case we insert the source address based upon the interface
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((src->isoa_len > sizeof(struct iso_addr)) ||
|
|
|
|
(dst->isoa_len == 0) ||
|
|
|
|
(dst->isoa_len > sizeof(struct iso_addr))) {
|
1993-04-09 16:00:07 +04:00
|
|
|
m_freem(m0);
|
|
|
|
INCSTAT(cns_odropped);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (ENAMETOOLONG);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Grab mbuf to contain header
|
|
|
|
*/
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_HEADER);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(m0);
|
|
|
|
INCSTAT(cns_odropped);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (ENOBUFS);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
INCSTAT(cns_sent);
|
|
|
|
m->m_next = m0;
|
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
clcp->clc_segoff = 0;
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Fill in all of fixed hdr except lengths and checksum
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (flags & CLNP_SEND_RAW) {
|
|
|
|
*clnp = raw_template;
|
|
|
|
} else if (flags & CLNP_ECHO) {
|
|
|
|
*clnp = echo_template;
|
1994-05-13 10:08:03 +04:00
|
|
|
} else if (flags & CLNP_ECHOR) {
|
|
|
|
*clnp = echor_template;
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
|
|
|
*clnp = dt_template;
|
|
|
|
}
|
|
|
|
if (flags & CLNP_NO_SEG)
|
|
|
|
clnp->cnf_type &= ~CNF_SEG_OK;
|
|
|
|
if (flags & CLNP_NO_ER)
|
|
|
|
clnp->cnf_type &= ~CNF_ERR_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Route packet; special case for source rt
|
|
|
|
*/
|
|
|
|
if ((isop->isop_options) && CLNPSRCRT_VALID(oidx)) {
|
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_output: calling clnp_srcroute\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
error = clnp_srcroute(isop->isop_options, oidx, &isop->isop_route,
|
1996-02-14 01:07:57 +03:00
|
|
|
&clcp->clc_firsthop, &clcp->clc_ifa, dst);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OUTPUT]) {
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
error = clnp_route(dst, &isop->isop_route, flags,
|
|
|
|
&clcp->clc_firsthop, &clcp->clc_ifa);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
if (error || (clcp->clc_ifa == 0)) {
|
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_output: route failed, errno %d\n", error);
|
|
|
|
printf("@clcp:\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
dump_buf(clcp, sizeof(struct clnp_cache));
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
clcp->clc_rt = isop->isop_route.ro_rt; /* XXX */
|
1996-02-14 01:07:57 +03:00
|
|
|
clcp->clc_ifp = clcp->clc_ifa->ia_ifp; /* XXX */
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OUTPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_output: packet routed to %s\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
clnp_iso_addrp(
|
1996-02-14 01:07:57 +03:00
|
|
|
&satosiso(clcp->clc_firsthop)->siso_addr));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If src address is not yet specified, use address of
|
|
|
|
* interface. NOTE: this will now update the laddr field in
|
|
|
|
* the isopcb. Is this desirable? RAH?
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (src->isoa_len == 0) {
|
|
|
|
src = &(clcp->clc_ifa->ia_addr.siso_addr);
|
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_output: new src %s\n", clnp_iso_addrp(src));
|
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
|
|
|
* Insert the source and destination address,
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
hoff = (caddr_t) clnp + sizeof(struct clnp_fixed);
|
1993-04-09 16:00:07 +04:00
|
|
|
CLNP_INSERT_ADDR(hoff, *dst);
|
|
|
|
CLNP_INSERT_ADDR(hoff, *src);
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Leave room for the segment part, if segmenting is selected
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (clnp->cnf_type & CNF_SEG_OK) {
|
1996-02-14 01:07:57 +03:00
|
|
|
clcp->clc_segoff = hoff - (caddr_t) clnp;
|
1993-04-09 16:00:07 +04:00
|
|
|
hoff += sizeof(struct clnp_segment);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
clnp->cnf_hdr_len = m->m_len = (u_char) (hoff - (caddr_t) clnp);
|
1993-04-09 16:00:07 +04:00
|
|
|
hdrlen = clnp->cnf_hdr_len;
|
|
|
|
|
|
|
|
#ifdef DECBIT
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Add the globally unique QOS (with room for congestion
|
|
|
|
* experienced bit). I can safely assume that this option
|
|
|
|
* is not in the options mbuf below because I checked that
|
|
|
|
* the option was not specified previously
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((m->m_len + sizeof(qos_option)) < MLEN) {
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) qos_option, hoff, sizeof(qos_option));
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp->cnf_hdr_len += sizeof(qos_option);
|
|
|
|
hdrlen += sizeof(qos_option);
|
|
|
|
m->m_len += sizeof(qos_option);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* DECBIT */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If an options mbuf is present, concatenate a copy to the hdr mbuf.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (isop->isop_options) {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *opt_copy =
|
|
|
|
m_copy(isop->isop_options, 0, (int) M_COPYALL);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (opt_copy == NULL) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* Link in place */
|
|
|
|
opt_copy->m_next = m->m_next;
|
|
|
|
m->m_next = opt_copy;
|
|
|
|
|
|
|
|
/* update size of header */
|
|
|
|
clnp->cnf_hdr_len += opt_copy->m_len;
|
|
|
|
hdrlen += opt_copy->m_len;
|
|
|
|
}
|
|
|
|
if (hdrlen > CLNP_HDR_MAX) {
|
|
|
|
error = EMSGSIZE;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Now set up the cache entry in the pcb
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((flags & CLNP_NOCACHE) == 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
clcp->clc_hdr = m_copy(m, 0, (int) clnp->cnf_hdr_len);
|
|
|
|
if (clcp->clc_hdr) {
|
|
|
|
clcp->clc_dst = *dst;
|
1993-04-09 16:00:07 +04:00
|
|
|
clcp->clc_flags = flags;
|
|
|
|
clcp->clc_options = isop->isop_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If small enough for interface, send directly
|
|
|
|
* Fill in segmentation part of hdr if using the full protocol
|
|
|
|
*/
|
|
|
|
total_len = clnp->cnf_hdr_len + datalen;
|
|
|
|
if (clnp->cnf_type & CNF_SEG_OK) {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_segment seg_part; /* segment part of hdr */
|
1993-04-09 16:00:07 +04:00
|
|
|
seg_part.cng_id = htons(clnp_id++);
|
|
|
|
seg_part.cng_off = htons(0);
|
|
|
|
seg_part.cng_tot_len = htons(total_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
(void) bcopy((caddr_t) & seg_part, (caddr_t) clnp + clcp->clc_segoff,
|
|
|
|
sizeof(seg_part));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
if (total_len <= SN_MTU(clcp->clc_ifp, clcp->clc_rt)) {
|
|
|
|
HTOC(clnp->cnf_seglen_msb, clnp->cnf_seglen_lsb, total_len);
|
|
|
|
m->m_pkthdr.len = total_len;
|
|
|
|
/*
|
|
|
|
* Compute clnp checksum (on header only)
|
|
|
|
*/
|
|
|
|
if (flags & CLNP_NO_CKSUM) {
|
|
|
|
HTOC(clnp->cnf_cksum_msb, clnp->cnf_cksum_lsb, 0);
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_gen_csum(m, CLNP_CKSUM_OFF, (int) clnp->cnf_hdr_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DUMPOUT]) {
|
|
|
|
struct mbuf *mdump = m;
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_output: sending dg:\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
while (mdump != NULL) {
|
|
|
|
dump_buf(mtod(mdump, caddr_t), mdump->m_len);
|
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
error = SN_OUTPUT(clcp, m);
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Too large for interface; fragment if possible.
|
|
|
|
*/
|
|
|
|
error = clnp_fragment(clcp->clc_ifp, m, clcp->clc_firsthop,
|
1996-02-14 01:07:57 +03:00
|
|
|
total_len, clcp->clc_segoff, flags, clcp->clc_rt);
|
1993-04-09 16:00:07 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
done:
|
|
|
|
if (error) {
|
|
|
|
clnp_stat.cns_sent--;
|
|
|
|
clnp_stat.cns_odropped++;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
|
|
|
clnp_ctloutput()
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
}
|