2001-02-20 13:38:37 +03:00
|
|
|
/* $NetBSD: clnp_input.c,v 1.21 2001/02/20 10:38:37 itojun 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_input.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
|
|
|
|
*/
|
|
|
|
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
|
|
|
|
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/if_types.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1999-04-14 20:26:42 +04:00
|
|
|
#include <net/if_fddi.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/iso_var.h>
|
|
|
|
#include <netiso/iso_snpac.h>
|
|
|
|
#include <netiso/clnp.h>
|
|
|
|
#include <netiso/clnl.h>
|
|
|
|
#include <netiso/esis.h>
|
1994-01-04 11:13:28 +03:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/eonvar.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
|
|
|
#ifdef ISO
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char clnp_protox[ISOPROTO_MAX];
|
1993-04-09 16:00:07 +04:00
|
|
|
struct clnl_protosw clnl_protox[256];
|
1996-02-14 01:07:57 +03:00
|
|
|
int clnpqmaxlen = IFQ_MAXLEN; /* RAH? why is this a
|
|
|
|
* variable */
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ISO_X25ESIS
|
1996-02-14 01:07:57 +03:00
|
|
|
#if 0
|
|
|
|
void x25esis_input();
|
|
|
|
#endif
|
|
|
|
#endif /* ISO_X25ESIS */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_init
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: clnp initialization. Fill in clnp switch tables.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: none
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* SIDE EFFECTS: fills in clnp_protox table with correct offsets into
|
1996-02-14 01:07:57 +03:00
|
|
|
* the isosw table.
|
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
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_init()
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct protosw *pr;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* CLNP protox initialization
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((pr = pffindproto(PF_ISO, ISOPROTO_RAW, SOCK_RAW)) == 0)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnl_init: no raw CLNP\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
|
|
|
clnp_protox[ISOPROTO_RAW] = pr - isosw;
|
|
|
|
|
|
|
|
if ((pr = pffindproto(PF_ISO, ISOPROTO_TP, SOCK_SEQPACKET)) == 0)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnl_init: no tp/clnp\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
|
|
|
clnp_protox[ISOPROTO_TP] = pr - isosw;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CLNL protox initialization
|
|
|
|
*/
|
|
|
|
clnl_protox[ISO8473_CLNP].clnl_input = clnp_input;
|
|
|
|
|
|
|
|
clnlintrq.ifq_maxlen = clnpqmaxlen;
|
1995-07-28 00:36:14 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&iso_ifaddr);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnlintr
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Process a packet on the clnl input queue
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: nothing.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
clnlintr()
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;/* ptr to first mbuf of pkt */
|
|
|
|
struct clnl_fixed *clnl; /* ptr to fixed part of clnl
|
1996-02-14 01:07:57 +03:00
|
|
|
* hdr */
|
|
|
|
int s; /* save and restore priority */
|
|
|
|
struct clnl_protosw *clnlsw; /* ptr to protocol switch */
|
|
|
|
struct snpa_hdr sh; /* subnetwork hdr */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get next datagram off clnl input queue
|
|
|
|
*/
|
|
|
|
next:
|
|
|
|
s = splimp();
|
1996-02-14 01:07:57 +03:00
|
|
|
/* IF_DEQUEUESNPAHDR(&clnlintrq, m, sh); */
|
1993-04-09 16:00:07 +04:00
|
|
|
IF_DEQUEUE(&clnlintrq, m);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
|
|
|
|
if (m == 0) /* nothing to do */
|
|
|
|
return;
|
|
|
|
if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.rcvif == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
goto next;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) & sh, sizeof(sh));
|
|
|
|
sh.snh_flags = m->m_flags & (M_MCAST | M_BCAST);
|
|
|
|
switch ((sh.snh_ifp = m->m_pkthdr.rcvif)->if_type) {
|
1993-04-09 16:00:07 +04:00
|
|
|
case IFT_EON:
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy(mtod(m, caddr_t), (caddr_t) sh.snh_dhost, sizeof(u_long));
|
1993-04-09 16:00:07 +04:00
|
|
|
bcopy(sizeof(u_long) + mtod(m, caddr_t),
|
1996-02-14 01:07:57 +03:00
|
|
|
(caddr_t) sh.snh_shost, sizeof(u_long));
|
1993-04-09 16:00:07 +04:00
|
|
|
sh.snh_dhost[4] = mtod(m, u_char *)[sizeof(struct ip) +
|
1998-01-28 05:35:10 +03:00
|
|
|
offsetof(struct eon_hdr, eonh_class)];
|
1993-04-09 16:00:07 +04:00
|
|
|
m->m_data += EONIPLEN;
|
|
|
|
m->m_len -= EONIPLEN;
|
|
|
|
m->m_pkthdr.len -= EONIPLEN;
|
|
|
|
break;
|
1999-04-14 20:26:42 +04:00
|
|
|
case IFT_ETHER:
|
|
|
|
bcopy((caddr_t) (mtod(m, struct ether_header *)->ether_dhost),
|
|
|
|
(caddr_t) sh.snh_dhost, 2 * sizeof(sh.snh_dhost));
|
|
|
|
m->m_data += sizeof(struct ether_header);
|
|
|
|
m->m_len -= sizeof(struct ether_header);
|
|
|
|
m->m_pkthdr.len -= sizeof(struct ether_header);
|
|
|
|
break;
|
|
|
|
case IFT_FDDI:
|
|
|
|
bcopy((caddr_t) (mtod(m, struct fddi_header *)->fddi_dhost),
|
|
|
|
(caddr_t) sh.snh_dhost, 2 * sizeof(sh.snh_dhost));
|
|
|
|
m->m_data += sizeof(struct fddi_header);
|
|
|
|
m->m_len -= sizeof(struct fddi_header);
|
|
|
|
m->m_pkthdr.len -= sizeof(struct fddi_header);
|
|
|
|
break;
|
2000-01-08 23:39:45 +03:00
|
|
|
case IFT_PTPSERIAL:
|
2001-02-20 13:38:37 +03:00
|
|
|
case IFT_GIF:
|
2000-01-08 23:39:45 +03:00
|
|
|
/* nothing extra to get from the mbuf */
|
|
|
|
bzero((caddr_t)sh.snh_dhost, sizeof(sh.snh_dhost));
|
|
|
|
bzero((caddr_t)sh.snh_shost, sizeof(sh.snh_shost));
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
default:
|
1999-04-14 20:26:42 +04:00
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
|
|
|
int i;
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnlintr: src:");
|
1996-02-14 01:07:57 +03:00
|
|
|
for (i = 0; i < 6; i++)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("%x%c", sh.snh_shost[i] & 0xff,
|
1996-10-11 03:12:43 +04:00
|
|
|
(i < 5) ? ':' : ' ');
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(" dst:");
|
1996-02-14 01:07:57 +03:00
|
|
|
for (i = 0; i < 6; i++)
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("%x%c", sh.snh_dhost[i] & 0xff,
|
1996-10-11 03:12:43 +04:00
|
|
|
(i < 5) ? ':' : ' ');
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\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
|
|
|
* Get the fixed part of the clnl header into the first mbuf.
|
|
|
|
* Drop the packet if this fails.
|
|
|
|
* Do not call m_pullup if we have a cluster mbuf or the
|
|
|
|
* data is not there.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if ((IS_CLUSTER(m) || (m->m_len < sizeof(struct clnl_fixed))) &&
|
1996-02-14 01:07:57 +03:00
|
|
|
((m = m_pullup(m, sizeof(struct clnl_fixed))) == 0)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_toosmall); /* TODO: use clnl stats */
|
1996-02-14 01:07:57 +03:00
|
|
|
goto next; /* m_pullup discards mbuf */
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
clnl = mtod(m, struct clnl_fixed *);
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* Drop packet if the length of the header is not reasonable.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((clnl->cnf_hdr_len < CLNP_HDR_MIN) ||
|
|
|
|
(clnl->cnf_hdr_len > CLNP_HDR_MAX)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_badhlen); /* TODO: use clnl stats */
|
|
|
|
m_freem(m);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the header is not contained in this mbuf, make it so.
|
|
|
|
* Drop packet if this fails.
|
|
|
|
* Note: m_pullup will allocate a cluster mbuf if necessary
|
|
|
|
*/
|
|
|
|
if (clnl->cnf_hdr_len > m->m_len) {
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((m = m_pullup(m, (int) clnl->cnf_hdr_len)) == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_badhlen); /* TODO: use clnl stats */
|
|
|
|
goto next; /* m_pullup discards mbuf */
|
|
|
|
}
|
|
|
|
clnl = mtod(m, struct clnl_fixed *);
|
|
|
|
}
|
|
|
|
clnlsw = &clnl_protox[clnl->cnf_proto_id];
|
|
|
|
|
|
|
|
|
|
|
|
if (clnlsw->clnl_input)
|
|
|
|
(*clnlsw->clnl_input) (m, &sh);
|
|
|
|
else
|
|
|
|
m_freem(m);
|
|
|
|
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_input
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: process an incoming clnp 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
|
|
|
*
|
|
|
|
* SIDE EFFECTS: increments fields of clnp_stat structure.
|
1996-02-14 01:07:57 +03:00
|
|
|
*
|
1993-04-09 16:00:07 +04:00
|
|
|
* NOTES:
|
1996-02-14 01:07:57 +03:00
|
|
|
* TODO: I would like to make seg_part a pointer into the mbuf, but
|
1993-04-09 16:00:07 +04:00
|
|
|
* will it be correctly aligned?
|
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
clnp_input(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
clnp_input(m, va_alist)
|
|
|
|
struct mbuf *m; /* ptr to first mbuf of pkt */
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct snpa_hdr *shp; /* subnetwork header */
|
2000-01-08 23:39:45 +03:00
|
|
|
struct ifaddr *ifa;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct clnp_fixed *clnp; /* ptr to fixed part of
|
1996-02-14 01:07:57 +03:00
|
|
|
* header */
|
|
|
|
struct sockaddr_iso source; /* source address of pkt */
|
|
|
|
struct sockaddr_iso target; /* destination address of pkt */
|
1993-04-09 16:00:07 +04:00
|
|
|
#define src source.siso_addr
|
|
|
|
#define dst target.siso_addr
|
1996-02-14 01:07:57 +03:00
|
|
|
caddr_t hoff; /* current offset in packet */
|
|
|
|
caddr_t hend; /* address of end of header info */
|
|
|
|
struct clnp_segment seg_part; /* segment part of hdr */
|
|
|
|
int seg_off = 0; /* offset of segment part of hdr */
|
|
|
|
int seg_len;/* length of packet data&hdr in bytes */
|
|
|
|
struct clnp_optidx oidx, *oidxp = NULL; /* option index */
|
|
|
|
extern int iso_systype; /* used by ESIS config resp */
|
|
|
|
extern struct sockaddr_iso blank_siso; /* used for initializing */
|
|
|
|
int need_afrin = 0;
|
|
|
|
/* true if congestion experienced */
|
|
|
|
/* which means you need afrin nose */
|
|
|
|
/* spray. How clever! */
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m);
|
|
|
|
shp = va_arg(ap, struct snpa_hdr *);
|
|
|
|
va_end(ap);
|
|
|
|
|
2000-01-08 23:39:45 +03:00
|
|
|
/*
|
|
|
|
* make sure this interface has a ISO address
|
|
|
|
*/
|
|
|
|
for (ifa = shp->snh_ifp->if_addrlist.tqh_first; ifa != 0;
|
|
|
|
ifa = ifa->ifa_list.tqe_next)
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_ISO)
|
|
|
|
break;
|
|
|
|
if (ifa == 0) {
|
|
|
|
clnp_discard(m, ADDR_DESTUNREACH);
|
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-10-11 03:12:43 +04:00
|
|
|
"clnp_input: proccessing dg; First mbuf m_len %d, m_type x%x, %s\n",
|
|
|
|
m->m_len, m->m_type, IS_CLUSTER(m) ? "cluster" : "normal");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
need_afrin = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no iso addresses have been set, there is nothing
|
|
|
|
* to do with the packet.
|
|
|
|
*/
|
1995-06-13 11:13:14 +04:00
|
|
|
if (iso_ifaddr.tqh_first == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_discard(m, ADDR_DESTUNREACH);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
INCSTAT(cns_total);
|
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DUMPIN]) {
|
|
|
|
struct mbuf *mhead;
|
|
|
|
int total_len = 0;
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: clnp header:\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_buf(mtod(m, caddr_t), clnp->cnf_hdr_len);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: mbuf chain:\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
for (mhead = m; mhead != NULL; mhead = mhead->m_next) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("m %p, len %d\n", mhead, mhead->m_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
total_len += mhead->m_len;
|
|
|
|
}
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: total length of mbuf chain %d:\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
total_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute checksum (if necessary) and drop packet if
|
|
|
|
* checksum does not match
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if (CKSUM_REQUIRED(clnp) &&
|
|
|
|
iso_check_csum(m, (int) clnp->cnf_hdr_len)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_badcsum);
|
|
|
|
clnp_discard(m, GEN_BADCSUM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (clnp->cnf_vers != ISO8473_V1) {
|
|
|
|
INCSTAT(cns_badvers);
|
|
|
|
clnp_discard(m, DISC_UNSUPPVERS);
|
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
/* check mbuf data length: clnp_data_ck will free mbuf upon error */
|
1993-04-09 16:00:07 +04:00
|
|
|
CTOH(clnp->cnf_seglen_msb, clnp->cnf_seglen_lsb, seg_len);
|
|
|
|
if ((m = clnp_data_ck(m, seg_len)) == 0)
|
|
|
|
return;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
1996-02-14 01:07:57 +03:00
|
|
|
hend = (caddr_t) clnp + clnp->cnf_hdr_len;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* extract the source and destination address drop packet on failure
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
source = target = blank_siso;
|
|
|
|
|
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_EXTRACT_ADDR(dst, hoff, hend);
|
1996-02-14 01:07:57 +03:00
|
|
|
if (hoff == (caddr_t) 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_badaddr);
|
|
|
|
clnp_discard(m, GEN_INCOMPLETE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CLNP_EXTRACT_ADDR(src, hoff, hend);
|
1996-02-14 01:07:57 +03:00
|
|
|
if (hoff == (caddr_t) 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
INCSTAT(cns_badaddr);
|
|
|
|
clnp_discard(m, GEN_INCOMPLETE);
|
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: from %s", clnp_iso_addrp(&src));
|
|
|
|
printf(" to %s\n", clnp_iso_addrp(&dst));
|
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
|
|
|
* extract the segmentation information, if it is present.
|
|
|
|
* drop packet on failure
|
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_SEG_OK)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (hoff + sizeof(struct clnp_segment) > hend) {
|
|
|
|
INCSTAT(cns_noseg);
|
|
|
|
clnp_discard(m, GEN_INCOMPLETE);
|
|
|
|
return;
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
(void) bcopy(hoff, (caddr_t) & seg_part,
|
|
|
|
sizeof(struct clnp_segment));
|
1993-04-09 16:00:07 +04:00
|
|
|
/* make sure segmentation fields are in host order */
|
|
|
|
seg_part.cng_id = ntohs(seg_part.cng_id);
|
|
|
|
seg_part.cng_off = ntohs(seg_part.cng_off);
|
|
|
|
seg_part.cng_tot_len = ntohs(seg_part.cng_tot_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
seg_off = 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
|
|
|
* process options if present. If clnp_opt_sanity returns
|
|
|
|
* false (indicating an error was found in the options) or
|
|
|
|
* an unsupported option was found
|
|
|
|
* then drop packet and emit an ER.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (hoff < hend) {
|
1996-02-14 01:07:57 +03:00
|
|
|
int errcode;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
oidxp = &oidx;
|
1996-02-14 01:07:57 +03:00
|
|
|
errcode = clnp_opt_sanity(m, hoff, hend - hoff, oidxp);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* we do not support security */
|
|
|
|
if ((errcode == 0) && (oidxp->cni_securep))
|
|
|
|
errcode = DISC_UNSUPPSECURE;
|
|
|
|
|
|
|
|
/* the er option is valid with ER pdus only */
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((errcode == 0) && (oidxp->cni_er_reason != ER_INVALREAS) &&
|
|
|
|
((clnp->cnf_type & CNF_TYPE) != CLNP_ER))
|
1993-04-09 16:00:07 +04:00
|
|
|
errcode = DISC_UNSUPPOPT;
|
|
|
|
|
|
|
|
#ifdef DECBIT
|
|
|
|
/* check if the congestion experienced bit is set */
|
|
|
|
if (oidxp->cni_qos_formatp) {
|
1996-02-14 01:07:57 +03:00
|
|
|
caddr_t qosp = CLNP_OFFTOOPT(m, oidxp->cni_qos_formatp);
|
|
|
|
u_char qos = *qosp;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
need_afrin = ((qos & (CLNPOVAL_GLOBAL | CLNPOVAL_CONGESTED)) ==
|
|
|
|
(CLNPOVAL_GLOBAL | CLNPOVAL_CONGESTED));
|
1993-04-09 16:00:07 +04:00
|
|
|
if (need_afrin)
|
|
|
|
INCSTAT(cns_congest_rcvd);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* DECBIT */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (errcode != 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
clnp_discard(m, (char) errcode);
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-10-11 03:12:43 +04:00
|
|
|
"clnp_input: dropped (err x%x) due to bad options\n",
|
|
|
|
errcode);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* check if this packet is for us. if not, then forward
|
|
|
|
*/
|
|
|
|
if (clnp_ours(&dst) == 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: forwarding packet not for us\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
clnp_forward(m, seg_len, &dst, oidxp, seg_off, shp);
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* ESIS Configuration Response Function
|
|
|
|
*
|
|
|
|
* If the packet received was sent to the multicast address
|
|
|
|
* all end systems, then send an esh to the source
|
|
|
|
*/
|
|
|
|
if ((shp->snh_flags & M_MCAST) && (iso_systype == SNPA_ES)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
extern short esis_holding_time;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
esis_shoutput(shp->snh_ifp, ESIS_ESH, esis_holding_time,
|
1996-02-14 01:07:57 +03:00
|
|
|
shp->snh_shost, 6, &dst);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* If this is a fragment, then try to reassemble it. If clnp_reass
|
|
|
|
* returns non NULL, the packet has been reassembled, and should
|
|
|
|
* be give to TP. Otherwise the fragment has been delt with
|
|
|
|
* by the reassembly code (either stored or deleted). In either case
|
|
|
|
* we should have nothing more to do with it.
|
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_SEG_OK) &&
|
|
|
|
(seg_len != seg_part.cng_tot_len)) {
|
|
|
|
struct mbuf *m0;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if ((m0 = clnp_reass(m, &src, &dst, &seg_part)) != NULL) {
|
|
|
|
m = m0;
|
|
|
|
clnp = mtod(m, struct clnp_fixed *);
|
|
|
|
INCSTAT(cns_reassembled);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* give the packet to the higher layer
|
|
|
|
*
|
|
|
|
* Note: the total length of packet
|
|
|
|
* is the total length field of the segmentation part,
|
|
|
|
* or, if absent, the segment length field of the
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
INCSTAT(cns_delivered);
|
|
|
|
switch (clnp->cnf_type & CNF_TYPE) {
|
|
|
|
case CLNP_ER:
|
|
|
|
/*
|
|
|
|
* This ER must have the er option.
|
|
|
|
* If the option is not present, discard datagram.
|
|
|
|
*/
|
|
|
|
if (oidxp == NULL || oidxp->cni_er_reason == ER_INVALREAS) {
|
|
|
|
clnp_discard(m, GEN_HDRSYNTAX);
|
|
|
|
} else {
|
|
|
|
clnp_er_input(m, &src, oidxp->cni_er_reason);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLNP_DT:
|
|
|
|
(*isosw[clnp_protox[ISOPROTO_TP]].pr_input)(m, &source, &target,
|
1996-02-14 01:07:57 +03:00
|
|
|
clnp->cnf_hdr_len, need_afrin);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNP_RAW:
|
1993-04-09 16:00:07 +04:00
|
|
|
case CLNP_ECR:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: raw input of %d bytes\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
clnp->cnf_type & CNF_SEG_OK ?
|
|
|
|
seg_part.cng_tot_len : seg_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
(*isosw[clnp_protox[ISOPROTO_RAW]].pr_input)(m, &source,
|
|
|
|
&target,
|
|
|
|
clnp->cnf_hdr_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLNP_EC:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_INPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: echoing packet\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
(void) clnp_echoreply(m, (clnp->cnf_type & CNF_SEG_OK ?
|
|
|
|
(int) seg_part.cng_tot_len : seg_len),
|
|
|
|
&source, &target, oidxp);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_input: unknown clnp pkt type %d\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
clnp->cnf_type & CNF_TYPE);
|
1993-04-09 16:00:07 +04:00
|
|
|
clnp_stat.cns_delivered--;
|
|
|
|
clnp_stat.cns_noproto++;
|
|
|
|
clnp_discard(m, GEN_HDRSYNTAX);
|
1996-02-14 01:07:57 +03:00
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* ISO */
|