2001-10-19 00:17:24 +04:00
|
|
|
/* $NetBSD: iso_chksum.c,v 1.15 2001/10/18 20:17:30 thorpej Exp $ */
|
1994-06-29 10:39:25 +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:39:25 +04:00
|
|
|
* @(#)iso_chksum.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
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
1993-04-09 16:00:07 +04:00
|
|
|
* ISO CHECKSUM
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* The checksum generation and check routines are here. The checksum is 2 bytes
|
|
|
|
* such that the sum of all the bytes b(i) == 0 and the sum of i * b(i) == 0.
|
1993-04-09 16:00:07 +04:00
|
|
|
* The whole thing is complicated by the fact that the data are in mbuf
|
1996-02-14 01:07:57 +03:00
|
|
|
* chains. Furthermore, there is the possibility of wraparound in the running
|
|
|
|
* sums after adding up 4102 octets. In order to avoid doing a mod operation
|
|
|
|
* after EACH add, we have restricted this implementation to negotiating a
|
|
|
|
* maximum of 4096-octets per TPDU (for the transport layer). The routine
|
|
|
|
* iso_check_csum doesn't need to know where the checksum octets are. The
|
|
|
|
* routine iso_gen_csum takes a pointer to an mbuf chain (logically a chunk
|
|
|
|
* of data), an offset into the chunk at which the 2 octets are to be
|
|
|
|
* stuffed, and the length of the chunk. The 2 octets have to be logically
|
|
|
|
* adjacent, but may be physically located in separate mbufs.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ISO
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/mbuf.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/iso_var.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#endif /* ISO */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: iso_check_csum
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: To check the checksum of the packet in the mbuf chain (m).
|
|
|
|
* The total length of the packet is (len).
|
|
|
|
* Called from tp_input() and clnp_intr()
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: TRUE (something non-zero) if there is a checksum error,
|
|
|
|
* FALSE if there was NO checksum error.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: none
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: It might be possible to gain something by optimizing
|
1993-04-09 16:00:07 +04:00
|
|
|
* this routine (unrolling loops, etc). But it is such
|
1996-02-14 01:07:57 +03:00
|
|
|
* a horrible thing to fiddle with anyway, it probably
|
|
|
|
* isn't worth it.
|
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
|
|
|
iso_check_csum(m, len)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
int len;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
u_char *p = mtod(m, u_char *);
|
|
|
|
u_long c0 = 0, c1 = 0;
|
|
|
|
int i = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
int cum = 0;/* cumulative length */
|
|
|
|
int l;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
l = len;
|
1994-05-13 10:08:03 +04:00
|
|
|
len = min(m->m_len, len);
|
1993-04-09 16:00:07 +04:00
|
|
|
i = 0;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("iso_check_csum: m %p, l x%x, m->m_len x%x\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
m, l, m->m_len);
|
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
|
|
|
while (i < l) {
|
1993-04-09 16:00:07 +04:00
|
|
|
cum += len;
|
1996-02-14 01:07:57 +03:00
|
|
|
while (i < cum) {
|
1993-04-09 16:00:07 +04:00
|
|
|
c0 = c0 + *(p++);
|
|
|
|
c1 += c0;
|
|
|
|
i++;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if (i < l) {
|
1993-04-09 16:00:07 +04:00
|
|
|
m = m->m_next;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("iso_check_csum: new mbuf\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
if (l - i < m->m_len)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-04-13 05:34:06 +04:00
|
|
|
"bad mbuf chain in check csum l 0x%x i 0x%x m_data %p",
|
|
|
|
l, i, m->m_data);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ASSERT(m != NULL);
|
|
|
|
len = min(m->m_len, l - i);
|
1993-04-09 16:00:07 +04:00
|
|
|
p = mtod(m, u_char *);
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if (((int) c0 % 255) || ((int) c1 % 255)) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("BAD iso_check_csum l 0x%x cum 0x%x len 0x%x, i 0x%x",
|
1996-10-11 03:12:43 +04:00
|
|
|
l, cum, len, i);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ((int) c0 % 255) << 8 | ((int) c1 % 255);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: iso_gen_csum
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: To generate the checksum of the packet in the mbuf chain (m).
|
|
|
|
* The first of the 2 (logically) adjacent checksum bytes
|
|
|
|
* (x and y) go at offset (n).
|
|
|
|
* (n) is an offset relative to the beginning of the data,
|
|
|
|
* not the beginning of the mbuf.
|
|
|
|
* (l) is the length of the total mbuf chain's data.
|
|
|
|
* Called from tp_emit(), tp_error_emit()
|
|
|
|
* clnp_emit_er(), clnp_forward(), clnp_output().
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: Rien
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: Puts the 2 checksum bytes into the packet.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: Ditto the note for iso_check_csum().
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_gen_csum(m, n, l)
|
|
|
|
struct mbuf *m;
|
|
|
|
int n; /* offset of 2 checksum bytes */
|
|
|
|
int l;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
u_char *p = mtod(m, u_char *);
|
|
|
|
int c0 = 0, c1 = 0;
|
|
|
|
int i = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
int loc = n++, len = 0; /* n is position, loc is
|
|
|
|
* offset */
|
|
|
|
u_char *xloc = NULL;
|
|
|
|
u_char *yloc = NULL;
|
|
|
|
int cum = 0;/* cum == cumulative length */
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("enter gen csum m %p n 0x%x l 0x%x\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
m, n - 1, l);
|
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
|
|
|
while (i < l) {
|
1999-12-04 15:11:13 +03:00
|
|
|
len = min(m->m_len, NBPG);
|
1993-04-09 16:00:07 +04:00
|
|
|
/* RAH: don't cksum more than l bytes */
|
1994-05-13 10:08:03 +04:00
|
|
|
len = min(len, l - i);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
cum += len;
|
1993-04-09 16:00:07 +04:00
|
|
|
p = mtod(m, u_char *);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (loc >= 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (loc < len) {
|
|
|
|
xloc = loc + mtod(m, u_char *);
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("1: zeroing xloc %p loc 0x%x\n",
|
1996-04-13 05:34:06 +04:00
|
|
|
xloc, loc);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*xloc = (u_char) 0;
|
|
|
|
if (loc + 1 < len) {
|
|
|
|
/*
|
|
|
|
* both xloc and yloc are in same
|
|
|
|
* mbuf
|
|
|
|
*/
|
|
|
|
yloc = 1 + xloc;
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-04-13 05:34:06 +04:00
|
|
|
"2: zeroing yloc %p loc 0x%x\n",
|
|
|
|
yloc, loc);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*yloc = (u_char) 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
|
|
|
/* crosses boundary of mbufs */
|
|
|
|
yloc = mtod(m->m_next, u_char *);
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-04-13 05:34:06 +04:00
|
|
|
"3: zeroing yloc %p \n", yloc);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*yloc = (u_char) 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
loc -= len;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
while (i < cum) {
|
1993-04-09 16:00:07 +04:00
|
|
|
c0 = (c0 + *p);
|
1996-02-14 01:07:57 +03:00
|
|
|
c1 += c0;
|
|
|
|
i++;
|
1993-04-09 16:00:07 +04:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("gen csum final xloc %p yloc %p\n", xloc, yloc);
|
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
|
|
|
c1 = (((c0 * (l - n)) - c1) % 255);
|
|
|
|
*xloc = (u_char) ((c1 < 0) ? c1 + 255 : c1);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
c1 = (-(int) (c1 + c0)) % 255;
|
|
|
|
*yloc = (u_char) (c1 < 0 ? c1 + 255 : c1);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CHKSUM]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("gen csum end \n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: m_datalen
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: returns length of the mbuf chain.
|
|
|
|
* used all over the iso code.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: integer
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: none
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1996-02-14 01:07:57 +03:00
|
|
|
m_datalen(m)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
1996-02-14 01:07:57 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int datalen;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
for (datalen = 0; m; m = m->m_next)
|
|
|
|
datalen += m->m_len;
|
1993-04-09 16:00:07 +04:00
|
|
|
return datalen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
m_compress(in, out)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *in, **out;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int datalen = 0;
|
2001-04-14 03:29:55 +04:00
|
|
|
int s = splnet();
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (in->m_next == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
*out = in;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress returning 0x%x: A\n", in->m_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
splx(s);
|
|
|
|
return in->m_len;
|
|
|
|
}
|
|
|
|
MGET((*out), M_DONTWAIT, MT_DATA);
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((*out) == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
*out = in;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress returning -1: B\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
splx(s);
|
1996-02-14 01:07:57 +03:00
|
|
|
return -1;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
(*out)->m_len = 0;
|
2001-10-19 00:17:24 +04:00
|
|
|
(*out)->m_nextpkt = NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
while (in) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress in %p *out %p\n", in, *out);
|
|
|
|
printf("m_compress in: len 0x%x, off %p\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
in->m_len, in->m_data);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress *out: len 0x%x, off %p\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
(*out)->m_len, (*out)->m_data);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
if (in->m_flags & M_EXT) {
|
|
|
|
ASSERT(in->m_len == 0);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if (in->m_len == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
in = in->m_next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (((*out)->m_flags & M_EXT) == 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
int len;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
len = M_TRAILINGSPACE(*out);
|
1994-05-13 10:08:03 +04:00
|
|
|
len = min(len, in->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
datalen += len;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress copying len %d\n", len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
bcopy(mtod(in, caddr_t), mtod((*out), caddr_t) + (*out)->m_len,
|
1996-02-14 01:07:57 +03:00
|
|
|
(unsigned) len);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
(*out)->m_len += len;
|
|
|
|
in->m_len -= len;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* (*out) is full */
|
1996-02-14 01:07:57 +03:00
|
|
|
if (((*out)->m_next = m_get(M_DONTWAIT, MT_DATA)) == NULL) {
|
1993-04-09 16:00:07 +04:00
|
|
|
m_freem(*out);
|
|
|
|
*out = in;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress returning -1: B\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
splx(s);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
(*out)->m_len = 0;
|
2001-10-19 00:17:24 +04:00
|
|
|
(*out)->m_nextpkt = NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
*out = (*out)->m_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_freem(in);
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_REQUEST]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m_compress returning 0x%x: A\n", datalen);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
splx(s);
|
|
|
|
return datalen;
|
|
|
|
}
|