1996-04-13 05:34:06 +04:00
|
|
|
/* $NetBSD: clnp_frag.c,v 1.8 1996/04/13 01:34:23 cgd 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_frag.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
|
|
|
|
*/
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.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/clnp.h>
|
|
|
|
#include <netiso/clnp_stat.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* all fragments are hung off this list */
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_fragl *clnp_frags = NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_fragment
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Fragment a datagram, and send the itty bitty pieces
|
|
|
|
* out over an interface.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: success - 0
|
|
|
|
* failure - 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: If there is an error sending the packet, clnp_discard
|
|
|
|
* is called to discard the packet and send an ER. If
|
|
|
|
* clnp_fragment was called from clnp_output, then
|
|
|
|
* we generated the packet, and should not send an
|
|
|
|
* ER -- clnp_emit_er will check for this. Otherwise,
|
|
|
|
* the packet was fragmented during forwarding. In this
|
|
|
|
* case, we ought to send an ER back.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_fragment(ifp, m, first_hop, total_len, segoff, flags, rt)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct ifnet *ifp; /* ptr to outgoing interface */
|
|
|
|
struct mbuf *m; /* ptr to packet */
|
|
|
|
struct sockaddr *first_hop; /* ptr to first hop */
|
|
|
|
int total_len; /* length of datagram */
|
|
|
|
int segoff; /* offset of segpart in hdr */
|
|
|
|
int flags; /* flags passed to clnp_output */
|
|
|
|
struct rtentry *rt; /* route if direct ether */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
int hdr_len = (int) clnp->cnf_hdr_len;
|
|
|
|
int frag_size = (SN_MTU(ifp, rt) - hdr_len) & ~7;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
total_len -= hdr_len;
|
|
|
|
if ((clnp->cnf_type & CNF_SEG_OK) &&
|
1996-02-14 01:07:57 +03:00
|
|
|
(total_len >= 8) &&
|
|
|
|
(frag_size > 8 || (frag_size == 8 && !(total_len & 7)))) {
|
|
|
|
struct mbuf *hdr = NULL; /* save copy of clnp hdr */
|
|
|
|
struct mbuf *frag_hdr = NULL;
|
|
|
|
struct mbuf *frag_data = NULL;
|
|
|
|
struct clnp_segment seg_part; /* segmentation header */
|
|
|
|
int frag_base;
|
|
|
|
int error = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
INCSTAT(cns_fragmented);
|
1996-02-14 01:07:57 +03:00
|
|
|
(void) bcopy(segoff + mtod(m, caddr_t), (caddr_t) & seg_part,
|
|
|
|
sizeof(seg_part));
|
1993-04-09 16:00:07 +04:00
|
|
|
frag_base = ntohs(seg_part.cng_off);
|
|
|
|
/*
|
|
|
|
* Duplicate header, and remove from packet
|
|
|
|
*/
|
|
|
|
if ((hdr = m_copy(m, 0, hdr_len)) == NULL) {
|
|
|
|
clnp_discard(m, GEN_CONGEST);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (ENOBUFS);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
m_adj(m, hdr_len);
|
|
|
|
|
|
|
|
while (total_len > 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
int remaining, last_frag;
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FRAG]) {
|
|
|
|
struct mbuf *mdump = frag_hdr;
|
|
|
|
int tot_mlen = 0;
|
|
|
|
printf("clnp_fragment: total_len %d:\n",
|
|
|
|
total_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("\tmbuf %p, m_len %d\n",
|
|
|
|
mdump, mdump->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
tot_mlen += mdump->m_len;
|
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
printf("clnp_fragment: sum of mbuf chain %d:\n",
|
|
|
|
tot_mlen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
frag_size = min(total_len, frag_size);
|
|
|
|
if ((remaining = total_len - frag_size) == 0)
|
|
|
|
last_frag = 1;
|
|
|
|
else {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If this fragment will cause the last one to
|
|
|
|
* be less than 8 bytes, shorten this fragment
|
|
|
|
* a bit. The obscure test on frag_size above
|
|
|
|
* ensures that frag_size will be positive.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
last_frag = 0;
|
|
|
|
if (remaining < 8)
|
1996-02-14 01:07:57 +03:00
|
|
|
frag_size -= 8;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_FRAG]) {
|
|
|
|
printf(
|
|
|
|
"clnp_fragment: seg off %d, size %d, rem %d\n",
|
|
|
|
ntohs(seg_part.cng_off), frag_size,
|
|
|
|
total_len - frag_size);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (last_frag)
|
1996-02-14 01:07:57 +03:00
|
|
|
printf(
|
|
|
|
"clnp_fragment: last fragment\n");
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (last_frag) {
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* this is the last fragment; we don't need
|
|
|
|
* to get any other mbufs.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
frag_hdr = hdr;
|
|
|
|
frag_data = m;
|
|
|
|
} else {
|
|
|
|
/* duplicate header and data mbufs */
|
1996-02-14 01:07:57 +03:00
|
|
|
frag_hdr = m_copy(hdr, 0, (int) M_COPYALL);
|
|
|
|
if (frag_hdr == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_discard(hdr, GEN_CONGEST);
|
|
|
|
m_freem(m);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (ENOBUFS);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
frag_data = m_copy(m, 0, frag_size);
|
|
|
|
if (frag_data == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_discard(hdr, GEN_CONGEST);
|
|
|
|
m_freem(m);
|
|
|
|
m_freem(frag_hdr);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (ENOBUFS);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
INCSTAT(cns_fragments);
|
|
|
|
}
|
|
|
|
clnp = mtod(frag_hdr, struct clnp_fixed *);
|
|
|
|
|
|
|
|
if (!last_frag)
|
|
|
|
clnp->cnf_type |= CNF_MORE_SEGS;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/* link together */
|
|
|
|
m_cat(frag_hdr, frag_data);
|
|
|
|
|
|
|
|
/* insert segmentation part; updated below */
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) & seg_part,
|
|
|
|
mtod(frag_hdr, caddr_t) + segoff,
|
|
|
|
sizeof(struct clnp_segment));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int derived_len = hdr_len + frag_size;
|
|
|
|
HTOC(clnp->cnf_seglen_msb,
|
|
|
|
clnp->cnf_seglen_lsb, derived_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
if ((frag_hdr->m_flags & M_PKTHDR) == 0)
|
|
|
|
panic("clnp_frag:lost header");
|
|
|
|
frag_hdr->m_pkthdr.len = derived_len;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/* compute clnp checksum (on header only) */
|
|
|
|
if (flags & CLNP_NO_CKSUM) {
|
1996-02-14 01:07:57 +03:00
|
|
|
HTOC(clnp->cnf_cksum_msb,
|
|
|
|
clnp->cnf_cksum_lsb, 0);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
|
|
|
iso_gen_csum(frag_hdr, CLNP_CKSUM_OFF, hdr_len);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DUMPOUT]) {
|
|
|
|
struct mbuf *mdump = frag_hdr;
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_fragment: sending dg:\n");
|
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("\tmbuf %p, m_len %d\n",
|
|
|
|
mdump, mdump->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
#ifdef TROLL
|
|
|
|
error = troll_output(ifp, frag_hdr, first_hop, rt);
|
|
|
|
#else
|
1996-02-14 01:07:57 +03:00
|
|
|
error = (*ifp->if_output) (ifp, frag_hdr, first_hop, rt);
|
|
|
|
#endif /* TROLL */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Tough situation: if the error occured on the last
|
|
|
|
* fragment, we can not send an ER, as the if_output
|
|
|
|
* routine consumed the packet. If the error occured
|
|
|
|
* on any intermediate packets, we can send an ER
|
|
|
|
* because we still have the original header in (m).
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (error) {
|
|
|
|
if (frag_hdr != hdr) {
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* The error was not on the last
|
|
|
|
* fragment. We must free hdr and m
|
|
|
|
* before returning
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
clnp_discard(hdr, GEN_NOREAS);
|
|
|
|
m_freem(m);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return (error);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* bump segment offset, trim data mbuf, and decrement
|
|
|
|
* count left
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef TROLL
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Decrement frag_size by some fraction. This will
|
|
|
|
* cause the next fragment to start 'early', thus
|
|
|
|
* duplicating the end of the current fragment.
|
|
|
|
* troll.tr_dup_size controls the fraction. If
|
|
|
|
* positive, it specifies the fraction. If
|
|
|
|
* negative, a random fraction is used.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((trollctl.tr_ops & TR_DUPEND) && (!last_frag)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
int num_bytes = frag_size;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (trollctl.tr_dup_size > 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
num_bytes *= trollctl.tr_dup_size;
|
|
|
|
else
|
|
|
|
num_bytes *= troll_random();
|
|
|
|
frag_size -= num_bytes;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* TROLL */
|
1993-04-09 16:00:07 +04:00
|
|
|
total_len -= frag_size;
|
|
|
|
if (!last_frag) {
|
|
|
|
frag_base += frag_size;
|
|
|
|
seg_part.cng_off = htons(frag_base);
|
|
|
|
m_adj(m, frag_size);
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return (0);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
|
|
|
INCSTAT(cns_cantfrag);
|
|
|
|
clnp_discard(m, GEN_SEGNEEDED);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (EMSGSIZE);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_reass
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Attempt to reassemble a clnp packet given the current
|
|
|
|
* fragment. If reassembly succeeds (all the fragments
|
|
|
|
* are present), then return a pointer to an mbuf chain
|
|
|
|
* containing the reassembled packet. This packet will
|
|
|
|
* appear in the mbufs as if it had just arrived in
|
|
|
|
* one piece.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If reassembly fails, then save this fragment and
|
|
|
|
* return 0.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: Ptr to assembled packet, or 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: clnp_slowtimo can not affect this code because
|
|
|
|
* clnpintr, and thus this code, is called at a higher
|
|
|
|
* priority than clnp_slowtimo.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_reass(m, src, dst, seg)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *m; /* new fragment */
|
|
|
|
struct iso_addr *src; /* src of new fragment */
|
|
|
|
struct iso_addr *dst; /* dst of new fragment */
|
|
|
|
struct clnp_segment *seg; /* segment part of fragment header */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct clnp_fragl *cfh;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* look for other fragments of this datagram */
|
|
|
|
for (cfh = clnp_frags; cfh != NULL; cfh = cfh->cfl_next) {
|
|
|
|
if (seg->cng_id == cfh->cfl_id &&
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_addrmatch1(src, &cfh->cfl_src) &&
|
|
|
|
iso_addrmatch1(dst, &cfh->cfl_dst)) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_reass: found packet\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
|
|
|
* There are other fragments here already. Lets see if
|
|
|
|
* this fragment is of any help
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
clnp_insert_frag(cfh, m, seg);
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((m = clnp_comp_pdu(cfh)) != NULL) {
|
|
|
|
struct clnp_fixed *clnp =
|
|
|
|
mtod(m, struct clnp_fixed *);
|
|
|
|
HTOC(clnp->cnf_seglen_msb,
|
|
|
|
clnp->cnf_seglen_lsb,
|
|
|
|
seg->cng_tot_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_reass: new packet!\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
|
|
|
* This is the first fragment. If src is not consuming too many
|
|
|
|
* resources, then create a new fragment list and add
|
|
|
|
* this fragment to the list.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
/* TODO: don't let one src hog all the reassembly buffers */
|
1996-02-14 01:07:57 +03:00
|
|
|
if (!clnp_newpkt(m, src, dst, seg) /* || this src is a hog */ ) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_fragdropped);
|
|
|
|
clnp_discard(m, GEN_CONGEST);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return (NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_newpkt
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Create the necessary structures to handle a new
|
|
|
|
* fragmented clnp packet.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: non-zero if it succeeds, zero if fails.
|
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: Failure is only due to insufficient resources.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_newpkt(m, src, dst, seg)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *m; /* new fragment */
|
|
|
|
struct iso_addr *src; /* src of new fragment */
|
|
|
|
struct iso_addr *dst; /* dst of new fragment */
|
|
|
|
struct clnp_segment *seg; /* segment part of fragment header */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct clnp_fragl *cfh;
|
|
|
|
register struct clnp_fixed *clnp;
|
|
|
|
struct mbuf *m0;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Allocate new clnp fragl structure to act as header of all
|
|
|
|
* fragments for this datagram.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
MGET(m0, M_DONTWAIT, MT_FTABLE);
|
|
|
|
if (m0 == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cfh = mtod(m0, struct clnp_fragl *);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Duplicate the header of this fragment, and save in cfh. Free m0
|
|
|
|
* and return if m_copy does not succeed.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
cfh->cfl_orighdr = m_copy(m, 0, (int) clnp->cnf_hdr_len);
|
|
|
|
if (cfh->cfl_orighdr == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
m_freem(m0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/* Fill in rest of fragl structure */
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) src, (caddr_t) & cfh->cfl_src, sizeof(struct iso_addr));
|
|
|
|
bcopy((caddr_t) dst, (caddr_t) & cfh->cfl_dst, sizeof(struct iso_addr));
|
1993-04-09 16:00:07 +04:00
|
|
|
cfh->cfl_id = seg->cng_id;
|
|
|
|
cfh->cfl_ttl = clnp->cnf_ttl;
|
|
|
|
cfh->cfl_last = (seg->cng_tot_len - clnp->cnf_hdr_len) - 1;
|
|
|
|
cfh->cfl_frags = NULL;
|
|
|
|
cfh->cfl_next = NULL;
|
|
|
|
|
|
|
|
/* Insert into list of packets */
|
|
|
|
cfh->cfl_next = clnp_frags;
|
|
|
|
clnp_frags = cfh;
|
|
|
|
|
|
|
|
/* Insert this fragment into list headed by cfh */
|
|
|
|
clnp_insert_frag(cfh, m, seg);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (1);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_insert_frag
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Insert fragment into list headed by 'cf'.
|
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: This is the 'guts' of the reassembly algorithm.
|
|
|
|
* Each fragment in this list contains a clnp_frag
|
|
|
|
* structure followed by the data of the fragment.
|
|
|
|
* The clnp_frag structure actually lies on top of
|
|
|
|
* part of the old clnp header.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_insert_frag(cfh, m, seg)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_fragl *cfh; /* header of list of packet fragments */
|
|
|
|
struct mbuf *m; /* new fragment */
|
|
|
|
struct clnp_segment *seg; /* segment part of fragment header */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct clnp_fixed *clnp; /* clnp hdr of fragment */
|
|
|
|
register struct clnp_frag *cf; /* generic fragment ptr */
|
|
|
|
register struct clnp_frag *cf_sub = NULL; /* frag subseq to new
|
|
|
|
* one */
|
|
|
|
register struct clnp_frag *cf_prev = NULL; /* frag prev to new one */
|
|
|
|
u_short first; /* offset of first byte of initial pdu */
|
|
|
|
u_short last; /* offset of last byte of initial pdu */
|
|
|
|
u_short fraglen;/* length of fragment */
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
first = seg->cng_off;
|
|
|
|
CTOH(clnp->cnf_seglen_msb, clnp->cnf_seglen_lsb, fraglen);
|
|
|
|
fraglen -= clnp->cnf_hdr_len;
|
|
|
|
last = (first + fraglen) - 1;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf("clnp_insert_frag: New fragment: [%d-%d], len %d\n",
|
|
|
|
first, last, fraglen);
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_insert_frag: current fragments:\n");
|
|
|
|
for (cf = cfh->cfl_frags; cf != NULL; cf = cf->cfr_next) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("\tcf %p: [%d-%d]\n",
|
|
|
|
cf, cf->cfr_first, cf->cfr_last);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (cfh->cfl_frags != NULL) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Find fragment which begins after the new one
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
for (cf = cfh->cfl_frags; cf != NULL;
|
|
|
|
cf_prev = cf, cf = cf->cfr_next) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (cf->cfr_first > first) {
|
|
|
|
cf_sub = cf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_insert_frag: Previous frag is ");
|
|
|
|
if (cf_prev == NULL)
|
|
|
|
printf("NULL\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
else
|
|
|
|
printf("[%d-%d]\n", cf_prev->cfr_first,
|
|
|
|
cf_prev->cfr_last);
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_insert_frag: Subsequent frag is ");
|
|
|
|
if (cf_sub == NULL)
|
|
|
|
printf("NULL\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
else
|
|
|
|
printf("[%d-%d]\n", cf_sub->cfr_first,
|
|
|
|
cf_sub->cfr_last);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If there is a fragment before the new one, check if it
|
|
|
|
* overlaps the new one. If so, then trim the end of the
|
|
|
|
* previous one.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (cf_prev != NULL) {
|
|
|
|
if (cf_prev->cfr_last > first) {
|
1996-02-14 01:07:57 +03:00
|
|
|
u_short overlap = cf_prev->cfr_last - first;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf(
|
|
|
|
"clnp_insert_frag: previous overlaps by %d\n",
|
|
|
|
overlap);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (overlap > fraglen) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The new fragment is entirely
|
|
|
|
* contained in the preceeding one.
|
|
|
|
* We can punt on the new frag
|
|
|
|
* completely.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Trim data off of end of previous
|
|
|
|
* fragment
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* inc overlap to prevent duplication
|
|
|
|
* of last byte
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
overlap++;
|
1996-02-14 01:07:57 +03:00
|
|
|
m_adj(cf_prev->cfr_data, -(int) overlap);
|
1993-04-09 16:00:07 +04:00
|
|
|
cf_prev->cfr_last -= overlap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* For all fragments past the new one, check if any data on
|
|
|
|
* the new one overlaps data on existing fragments. If so,
|
|
|
|
* then trim the extra data off the end of the new one.
|
|
|
|
*/
|
|
|
|
for (cf = cf_sub; cf != NULL; cf = cf->cfr_next) {
|
|
|
|
if (cf->cfr_first < last) {
|
1996-02-14 01:07:57 +03:00
|
|
|
u_short overlap = last - cf->cfr_first;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf(
|
|
|
|
"clnp_insert_frag: subsequent overlaps by %d\n",
|
|
|
|
overlap);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (overlap > fraglen) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The new fragment is entirely
|
|
|
|
* contained in the succeeding one.
|
|
|
|
* This should not happen, because
|
|
|
|
* early on in this code we scanned
|
|
|
|
* for the fragment which started
|
|
|
|
* after the new one!
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
m_freem(m);
|
1996-02-14 01:07:57 +03:00
|
|
|
printf(
|
|
|
|
"clnp_insert_frag: internal error!\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Trim data off of end of new fragment
|
|
|
|
* inc overlap to prevent duplication
|
|
|
|
* of last byte
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
overlap++;
|
1996-02-14 01:07:57 +03:00
|
|
|
m_adj(m, -(int) overlap);
|
1993-04-09 16:00:07 +04:00
|
|
|
last -= overlap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Insert the new fragment beween cf_prev and cf_sub
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Note: the clnp hdr is still in the mbuf.
|
|
|
|
* If the data of the mbuf is not word aligned, shave off enough
|
|
|
|
* so that it is. Then, cast the clnp_frag structure on top
|
|
|
|
* of the clnp header.
|
|
|
|
* The clnp_hdr will not be used again (as we already have
|
|
|
|
* saved a copy of it).
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Save in cfr_bytes the number of bytes to shave off to get to
|
|
|
|
* the data of the packet. This is used when we coalesce fragments;
|
|
|
|
* the clnp_frag structure must be removed before joining mbufs.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int pad;
|
|
|
|
u_int bytes;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* determine if header is not word aligned */
|
1996-02-14 01:07:57 +03:00
|
|
|
pad = (long) clnp % 4;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (pad < 0)
|
|
|
|
pad = -pad;
|
|
|
|
|
|
|
|
/* bytes is number of bytes left in front of data */
|
|
|
|
bytes = clnp->cnf_hdr_len - pad;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf(
|
1996-04-13 05:34:06 +04:00
|
|
|
"clnp_insert_frag: clnp %p requires %d alignment\n",
|
|
|
|
clnp, pad);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* make it word aligned if necessary */
|
|
|
|
if (pad)
|
|
|
|
m_adj(m, pad);
|
|
|
|
|
|
|
|
cf = mtod(m, struct clnp_frag *);
|
|
|
|
cf->cfr_bytes = bytes;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("clnp_insert_frag: cf now %p, cfr_bytes %d\n",
|
|
|
|
cf, cf->cfr_bytes);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
cf->cfr_first = first;
|
|
|
|
cf->cfr_last = last;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The data is the mbuf itself, although we must remember that the
|
|
|
|
* first few bytes are actually a clnp_frag structure
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
cf->cfr_data = m;
|
|
|
|
|
|
|
|
/* link into place */
|
|
|
|
cf->cfr_next = cf_sub;
|
|
|
|
if (cf_prev == NULL)
|
|
|
|
cfh->cfl_frags = cf;
|
|
|
|
else
|
|
|
|
cf_prev->cfr_next = cf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_comp_pdu
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Scan the list of fragments headed by cfh. Merge
|
|
|
|
* any contigious fragments into one. If, after
|
|
|
|
* traversing all the fragments, it is determined that
|
|
|
|
* the packet is complete, then return a pointer to
|
|
|
|
* the packet (with header prepended). Otherwise,
|
|
|
|
* return NULL.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: NULL, or a pointer to the assembled pdu in an mbuf
|
|
|
|
* chain.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: Will colapse contigious fragments into one.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: This code assumes that there are no overlaps of
|
|
|
|
* fragment pdus.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_comp_pdu(cfh)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_fragl *cfh; /* fragment header */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct clnp_frag *cf = cfh->cfl_frags;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
while (cf->cfr_next != NULL) {
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct clnp_frag *cf_next = cf->cfr_next;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf("clnp_comp_pdu: comparing: [%d-%d] to [%d-%d]\n",
|
|
|
|
cf->cfr_first, cf->cfr_last, cf_next->cfr_first,
|
|
|
|
cf_next->cfr_last);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (cf->cfr_last == (cf_next->cfr_first - 1)) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Merge fragment cf and cf_next
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* - update cf header
|
|
|
|
* - trim clnp_frag structure off of cf_next
|
|
|
|
* - append cf_next to cf
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
struct clnp_frag cf_next_hdr;
|
|
|
|
struct clnp_frag *next_frag;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
cf_next_hdr = *cf_next;
|
|
|
|
next_frag = cf_next->cfr_next;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
struct mbuf *mdump;
|
|
|
|
int l;
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_comp_pdu: merging fragments\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
printf(
|
|
|
|
"clnp_comp_pdu: 1st: [%d-%d] (bytes %d)\n",
|
|
|
|
cf->cfr_first, cf->cfr_last,
|
|
|
|
cf->cfr_bytes);
|
1993-04-09 16:00:07 +04:00
|
|
|
mdump = cf->cfr_data;
|
|
|
|
l = 0;
|
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("\tmbuf %p, m_len %d\n",
|
|
|
|
mdump, mdump->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
l += mdump->m_len;
|
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
|
|
|
printf("\ttotal len: %d\n", l);
|
1996-02-14 01:07:57 +03:00
|
|
|
printf(
|
|
|
|
"clnp_comp_pdu: 2nd: [%d-%d] (bytes %d)\n",
|
|
|
|
cf_next->cfr_first, cf_next->cfr_last,
|
|
|
|
cf_next->cfr_bytes);
|
1993-04-09 16:00:07 +04:00
|
|
|
mdump = cf_next->cfr_data;
|
|
|
|
l = 0;
|
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("\tmbuf %p, m_len %d\n",
|
|
|
|
mdump, mdump->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
l += mdump->m_len;
|
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
|
|
|
printf("\ttotal len: %d\n", l);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
cf->cfr_last = cf_next->cfr_last;
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* After this m_adj, the cf_next ptr is useless
|
|
|
|
* because we have adjusted the clnp_frag structure
|
|
|
|
* away...
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
printf("clnp_comp_pdu: shaving off %d bytes\n",
|
|
|
|
cf_next_hdr.cfr_bytes);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_adj(cf_next_hdr.cfr_data,
|
|
|
|
(int) cf_next_hdr.cfr_bytes);
|
1993-04-09 16:00:07 +04:00
|
|
|
m_cat(cf->cfr_data, cf_next_hdr.cfr_data);
|
|
|
|
cf->cfr_next = next_frag;
|
|
|
|
} else {
|
|
|
|
cf = cf->cfr_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cf = cfh->cfl_frags;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
|
|
|
struct mbuf *mdump = cf->cfr_data;
|
|
|
|
printf("clnp_comp_pdu: first frag now: [%d-%d]\n",
|
|
|
|
cf->cfr_first, cf->cfr_last);
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_comp_pdu: data for frag:\n");
|
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("mbuf %p, m_len %d\n", mdump, mdump->m_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
/* dump_buf(mtod(mdump, caddr_t), mdump->m_len); */
|
1993-04-09 16:00:07 +04:00
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* Check if datagram is complete */
|
|
|
|
if ((cf->cfr_first == 0) && (cf->cfr_last == cfh->cfl_last)) {
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* We have a complete pdu!
|
|
|
|
* - Remove the frag header from (only) remaining fragment
|
|
|
|
* (which is not really a fragment anymore, as the datagram
|
|
|
|
* is complete).
|
|
|
|
* - Prepend a clnp header
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *data = cf->cfr_data;
|
|
|
|
struct mbuf *hdr = cfh->cfl_orighdr;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct clnp_fragl *scan;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REASS]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_comp_pdu: complete pdu!\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_adj(data, (int) cf->cfr_bytes);
|
1993-04-09 16:00:07 +04:00
|
|
|
m_cat(hdr, data);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DUMPIN]) {
|
|
|
|
struct mbuf *mdump = hdr;
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("clnp_comp_pdu: pdu is:\n");
|
|
|
|
while (mdump != NULL) {
|
1996-04-13 05:34:06 +04:00
|
|
|
printf("mbuf %p, m_len %d\n",
|
|
|
|
mdump, mdump->m_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
#if 0
|
|
|
|
dump_buf(mtod(mdump, caddr_t), mdump->m_len);
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
mdump = mdump->m_next;
|
|
|
|
}
|
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
|
|
|
* Remove cfh from the list of fragmented pdus
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (clnp_frags == cfh) {
|
|
|
|
clnp_frags = cfh->cfl_next;
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
for (scan = clnp_frags; scan != NULL;
|
|
|
|
scan = scan->cfl_next) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (scan->cfl_next == cfh) {
|
|
|
|
scan->cfl_next = cfh->cfl_next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free cfh */
|
|
|
|
m_freem(dtom(cfh));
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
return (hdr);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return (NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
#ifdef TROLL
|
1996-02-14 01:07:57 +03:00
|
|
|
static int troll_cnt;
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/time.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* FUNCTION: troll_random
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: generate a pseudo-random number between 0 and 1
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: the random number
|
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: This is based on the clock.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
float
|
|
|
|
troll_random()
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
extern struct timeval time;
|
1996-02-14 01:07:57 +03:00
|
|
|
long t = time.tv_usec % 100;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
return ((float) t / (float) 100);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: troll_output
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Do something sneaky with the datagram passed. Possible
|
|
|
|
* operations are:
|
|
|
|
* Duplicate the packet
|
|
|
|
* Drop the packet
|
|
|
|
* Trim some number of bytes from the packet
|
|
|
|
* Munge some byte in the packet
|
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: The operation of this procedure is regulated by the
|
|
|
|
* troll control structure (Troll).
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1993-04-09 16:00:07 +04:00
|
|
|
troll_output(ifp, m, dst, rt)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct sockaddr *dst;
|
|
|
|
struct rtentry *rt;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int err = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
troll_cnt++;
|
|
|
|
|
|
|
|
if (trollctl.tr_ops & TR_DUPPKT) {
|
|
|
|
/*
|
|
|
|
* Duplicate every Nth packet
|
|
|
|
* TODO: random?
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
float f_freq = troll_cnt * trollctl.tr_dup_freq;
|
|
|
|
int i_freq = troll_cnt * trollctl.tr_dup_freq;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (i_freq == f_freq) {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *dup = m_copy(m, 0, (int) M_COPYALL);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (dup != NULL)
|
1996-02-14 01:07:57 +03:00
|
|
|
err = (*ifp->if_output) (ifp, dup, dst, rt);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
if (!err)
|
1996-02-14 01:07:57 +03:00
|
|
|
err = (*ifp->if_output) (ifp, m, dst, rt);
|
|
|
|
return (err);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else if (trollctl.tr_ops & TR_DROPPKT) {
|
|
|
|
} else if (trollctl.tr_ops & TR_CHANGE) {
|
|
|
|
struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
clnp->cnf_cksum_msb = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
err = (*ifp->if_output) (ifp, m, dst, rt);
|
|
|
|
return (err);
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
err = (*ifp->if_output) (ifp, m, dst, rt);
|
|
|
|
return (err);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* TROLL */
|