summaryrefslogtreecommitdiff
path: root/sys/netiso/clnp_er.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-03-04 10:37:32 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-03-04 10:37:32 +0000
commit19b3595c2000294ed57cd7cb23e1d91ee553215d (patch)
tree404b337fc172b005d07d5f30eeeb873a270a9eac /sys/netiso/clnp_er.c
parentd4b3fca05966647ecd8191d973cdce74570844ca (diff)
Initial commit of NetBSD 960217 netiso.
all the rest is the fixes to the import by Niklas.
Diffstat (limited to 'sys/netiso/clnp_er.c')
-rw-r--r--sys/netiso/clnp_er.c310
1 files changed, 164 insertions, 146 deletions
diff --git a/sys/netiso/clnp_er.c b/sys/netiso/clnp_er.c
index 98d81ada21f..f2eb126286c 100644
--- a/sys/netiso/clnp_er.c
+++ b/sys/netiso/clnp_er.c
@@ -1,4 +1,5 @@
-/* $NetBSD: clnp_er.c,v 1.6 1995/06/13 07:13:17 mycroft Exp $ */
+/* $OpenBSD: clnp_er.c,v 1.2 1996/03/04 10:34:48 mickey Exp $ */
+/* $NetBSD: clnp_er.c,v 1.7 1996/02/13 22:08:17 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -40,13 +41,13 @@
All Rights Reserved
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
+both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
+software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
@@ -69,6 +70,7 @@ SOFTWARE.
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/errno.h>
+#include <sys/systm.h>
#include <net/if.h>
#include <net/route.h>
@@ -80,15 +82,17 @@ SOFTWARE.
#include <netiso/clnp.h>
#include <netiso/clnp_stat.h>
#include <netiso/argo_debug.h>
+#include <netiso/tp_param.h>
+#include <netiso/tp_var.h>
static struct clnp_fixed er_template = {
- ISO8473_CLNP, /* network identifier */
- 0, /* length */
+ ISO8473_CLNP, /* network identifier */
+ 0, /* length */
ISO8473_V1, /* version */
CLNP_TTL, /* ttl */
CLNP_ER, /* type */
- 0, /* segment length */
- 0 /* checksum */
+ 0, /* segment length */
+ 0 /* checksum */
};
/*
@@ -96,76 +100,78 @@ static struct clnp_fixed er_template = {
*
* PURPOSE: Process an ER pdu.
*
- * RETURNS:
+ * RETURNS:
*
- * SIDE EFFECTS:
+ * SIDE EFFECTS:
*
- * NOTES:
+ * NOTES:
*/
+void
clnp_er_input(m, src, reason)
-struct mbuf *m; /* ptr to packet itself */
-struct iso_addr *src; /* ptr to src of er */
-u_char reason; /* reason code of er */
+ struct mbuf *m; /* ptr to packet itself */
+ struct iso_addr *src; /* ptr to src of er */
+ u_int reason; /* reason code of er */
{
- int cmd = -1;
- extern u_char clnp_protox[];
+ int cmd = -1;
- IFDEBUG(D_CTLINPUT)
- printf("clnp_er_input: m x%x, src %s, reason x%x\n", m,
- clnp_iso_addrp(src), reason);
- ENDDEBUG
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_CTLINPUT]) {
+ printf("clnp_er_input: m x%x, src %s, reason x%x\n",
+ (unsigned int) m, clnp_iso_addrp(src), reason);
+ }
+#endif
INCSTAT(cns_er_inhist[clnp_er_index(reason)]);
switch (reason) {
- case GEN_NOREAS:
- case GEN_PROTOERR:
- break;
- case GEN_BADCSUM:
- cmd = PRC_PARAMPROB;
- break;
- case GEN_CONGEST:
- cmd = PRC_QUENCH;
- break;
- case GEN_HDRSYNTAX:
- cmd = PRC_PARAMPROB;
- break;
- case GEN_SEGNEEDED:
- cmd = PRC_MSGSIZE;
- break;
- case GEN_INCOMPLETE:
- cmd = PRC_PARAMPROB;
- break;
- case GEN_DUPOPT:
- cmd = PRC_PARAMPROB;
- break;
- case ADDR_DESTUNREACH:
- cmd = PRC_UNREACH_HOST;
- break;
- case ADDR_DESTUNKNOWN:
- cmd = PRC_UNREACH_PROTOCOL;
- break;
- case SRCRT_UNSPECERR:
- case SRCRT_SYNTAX:
- case SRCRT_UNKNOWNADDR:
- case SRCRT_BADPATH:
- cmd = PRC_UNREACH_SRCFAIL;
- break;
- case TTL_EXPTRANSIT:
- cmd = PRC_TIMXCEED_INTRANS;
- break;
- case TTL_EXPREASS:
- cmd = PRC_TIMXCEED_REASS;
- break;
- case DISC_UNSUPPOPT:
- case DISC_UNSUPPVERS:
- case DISC_UNSUPPSECURE:
- case DISC_UNSUPPSRCRT:
- case DISC_UNSUPPRECRT:
- cmd = PRC_PARAMPROB;
- break;
- case REASS_INTERFERE:
- cmd = PRC_TIMXCEED_REASS;
- break;
+ case GEN_NOREAS:
+ case GEN_PROTOERR:
+ break;
+ case GEN_BADCSUM:
+ cmd = PRC_PARAMPROB;
+ break;
+ case GEN_CONGEST:
+ cmd = PRC_QUENCH;
+ break;
+ case GEN_HDRSYNTAX:
+ cmd = PRC_PARAMPROB;
+ break;
+ case GEN_SEGNEEDED:
+ cmd = PRC_MSGSIZE;
+ break;
+ case GEN_INCOMPLETE:
+ cmd = PRC_PARAMPROB;
+ break;
+ case GEN_DUPOPT:
+ cmd = PRC_PARAMPROB;
+ break;
+ case ADDR_DESTUNREACH:
+ cmd = PRC_UNREACH_HOST;
+ break;
+ case ADDR_DESTUNKNOWN:
+ cmd = PRC_UNREACH_PROTOCOL;
+ break;
+ case SRCRT_UNSPECERR:
+ case SRCRT_SYNTAX:
+ case SRCRT_UNKNOWNADDR:
+ case SRCRT_BADPATH:
+ cmd = PRC_UNREACH_SRCFAIL;
+ break;
+ case TTL_EXPTRANSIT:
+ cmd = PRC_TIMXCEED_INTRANS;
+ break;
+ case TTL_EXPREASS:
+ cmd = PRC_TIMXCEED_REASS;
+ break;
+ case DISC_UNSUPPOPT:
+ case DISC_UNSUPPVERS:
+ case DISC_UNSUPPSECURE:
+ case DISC_UNSUPPSRCRT:
+ case DISC_UNSUPPRECRT:
+ cmd = PRC_PARAMPROB;
+ break;
+ case REASS_INTERFERE:
+ cmd = PRC_TIMXCEED_REASS;
+ break;
}
/*
@@ -181,31 +187,36 @@ u_char reason; /* reason code of er */
/*
* FUNCTION: clnp_discard
*
- * PURPOSE: Discard a clnp datagram
+ * PURPOSE: Discard a clnp datagram
*
- * RETURNS: nothing
+ * RETURNS: nothing
*
* SIDE EFFECTS: Will emit an ER pdu if possible
*
- * NOTES: This code assumes that we have previously tried to pull
- * up the header of the datagram into one mbuf.
+ * NOTES: This code assumes that we have previously tried to pull
+ * up the header of the datagram into one mbuf.
*/
+void
clnp_discard(m, reason)
-struct mbuf *m; /* header of packet to discard */
-char reason; /* reason for discard */
+ struct mbuf *m; /* header of packet to discard */
+ u_int reason; /* reason for discard */
{
- IFDEBUG(D_DISCARD)
- printf("clnp_discard: m x%x, reason x%x\n", m, reason);
- ENDDEBUG
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_DISCARD]) {
+ printf("clnp_discard: m x%x, reason x%x\n",
+ (unsigned int) m, reason);
+ }
+#endif
if (m != NULL) {
if (m->m_len >= sizeof(struct clnp_fixed)) {
- register struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
+ register struct clnp_fixed *clnp =
+ mtod(m, struct clnp_fixed *);
if (((clnp->cnf_type & CNF_TYPE) != CLNP_ER) &&
- (clnp->cnf_type & CNF_ERR_OK)) {
- clnp_emit_er(m, reason);
- return;
+ (clnp->cnf_type & CNF_ERR_OK)) {
+ clnp_emit_er(m, reason);
+ return;
}
}
m_freem(m);
@@ -215,113 +226,119 @@ char reason; /* reason for discard */
/*
* FUNCTION: clnp_emit_er
*
- * PURPOSE: Send an ER pdu.
- * The src of the of the ER pdu is the host that is sending
- * the ER (ie. us), *not* the original destination of the
- * packet.
+ * PURPOSE: Send an ER pdu.
+ * The src of the of the ER pdu is the host that is sending
+ * the ER (ie. us), *not* the original destination of the
+ * packet.
*
- * RETURNS: nothing
+ * RETURNS: nothing
*
- * SIDE EFFECTS:
+ * SIDE EFFECTS:
*
- * NOTES: Takes responsibility for freeing mbuf passed
- * This function may be called with a packet that
- * was created by us; in this case, do not send
- * an ER.
+ * NOTES: Takes responsibility for freeing mbuf passed
+ * This function may be called with a packet that
+ * was created by us; in this case, do not send
+ * an ER.
*/
+void
clnp_emit_er(m, reason)
-struct mbuf *m; /* header of packet to discard */
-char reason; /* reason for discard */
+ struct mbuf *m; /* header of packet to discard */
+ u_int reason; /* reason for discard */
{
- register struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
- register struct clnp_fixed *er;
- struct route_iso route;
- struct ifnet *ifp;
- struct sockaddr *first_hop;
- struct iso_addr src, dst, *our_addr;
- caddr_t hoff, hend;
- int total_len; /* total len of dg */
- struct mbuf *m0; /* contains er pdu hdr */
- struct iso_ifaddr *ia = 0;
-
- IFDEBUG(D_DISCARD)
- printf("clnp_emit_er: m x%x, hdr len %d\n", m, clnp->cnf_hdr_len);
- ENDDEBUG
-
- bzero((caddr_t)&route, sizeof(route));
+ register struct clnp_fixed *clnp = mtod(m, struct clnp_fixed *);
+ register struct clnp_fixed *er;
+ struct route_iso route;
+ struct ifnet *ifp;
+ struct sockaddr *first_hop;
+ struct iso_addr src, dst, *our_addr;
+ caddr_t hoff, hend;
+ int total_len; /* total len of dg */
+ struct mbuf *m0; /* contains er pdu hdr */
+ struct iso_ifaddr *ia = 0;
+
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_DISCARD]) {
+ printf("clnp_emit_er: m x%x, hdr len %d\n",
+ (unsigned int) m, clnp->cnf_hdr_len);
+ }
+#endif
+
+ bzero((caddr_t) & route, sizeof(route));
/*
- * If header length is incorrect, or entire header is not contained
- * in this mbuf, we punt
+ * If header length is incorrect, or entire header is not contained
+ * in this mbuf, we punt
*/
if ((clnp->cnf_hdr_len < CLNP_HDR_MIN) ||
- (clnp->cnf_hdr_len > CLNP_HDR_MAX) ||
- (clnp->cnf_hdr_len > m->m_len))
+ (clnp->cnf_hdr_len > CLNP_HDR_MAX) ||
+ (clnp->cnf_hdr_len > m->m_len))
goto bad;
-
+
/* extract src, dest address */
- hend = (caddr_t)clnp + clnp->cnf_hdr_len;
- hoff = (caddr_t)clnp + sizeof(struct clnp_fixed);
+ hend = (caddr_t) clnp + clnp->cnf_hdr_len;
+ hoff = (caddr_t) clnp + sizeof(struct clnp_fixed);
CLNP_EXTRACT_ADDR(dst, hoff, hend);
- if (hoff == (caddr_t)0) {
+ if (hoff == (caddr_t) 0) {
goto bad;
}
CLNP_EXTRACT_ADDR(src, hoff, hend);
- if (hoff == (caddr_t)0) {
+ if (hoff == (caddr_t) 0) {
goto bad;
}
-
/*
- * Do not send ER if we generated the packet.
+ * Do not send ER if we generated the packet.
*/
if (clnp_ours(&src))
goto bad;
- /*
- * Trim mbuf to hold only the header.
- * This mbuf will be the 'data' of the er pdu
+ /*
+ * Trim mbuf to hold only the header. This mbuf will be the 'data' of
+ * the er pdu
*/
if (m->m_next != NULL) {
m_freem(m->m_next);
m->m_next = NULL;
}
-
if (m->m_len > clnp->cnf_hdr_len)
- m_adj(m, (int)-(m->m_len - (int)clnp->cnf_hdr_len));
+ m_adj(m, (int) -(m->m_len - (int) clnp->cnf_hdr_len));
/* route er pdu: note we send pkt to src of original packet */
- if (clnp_route(&src, &route, /* flags */0, &first_hop, &ia) != 0)
+ if (clnp_route(&src, &route, /* flags */ 0, &first_hop, &ia) != 0)
goto bad;
/* compute our address based upon firsthop/ifp */
if (ia)
- our_addr = &ia->ia_addr.siso_addr;
+ our_addr = &ia->ia_addr.siso_addr;
else
- goto bad;
+ goto bad;
ifp = ia->ia_ifp;
- IFDEBUG(D_DISCARD)
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_DISCARD]) {
printf("clnp_emit_er: to %s", clnp_iso_addrp(&src));
printf(" from %s\n", clnp_iso_addrp(our_addr));
- ENDDEBUG
+ }
+#endif
- IFDEBUG(D_DISCARD)
- printf("clnp_emit_er: packet routed to %s\n",
- clnp_iso_addrp(&satosiso(first_hop)->siso_addr));
- ENDDEBUG
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_DISCARD]) {
+ printf("clnp_emit_er: packet routed to %s\n",
+ clnp_iso_addrp(&satosiso(first_hop)->siso_addr));
+ }
+#endif
/* allocate mbuf for er pdu header: punt on no space */
MGET(m0, M_DONTWAIT, MT_HEADER);
if (m0 == 0)
goto bad;
-
+
m0->m_next = m;
er = mtod(m0, struct clnp_fixed *);
*er = er_template;
/* setup src/dst on er pdu */
/* NOTE REVERSAL OF SRC/DST */
- hoff = (caddr_t)er + sizeof(struct clnp_fixed);
+ hoff = (caddr_t) er + sizeof(struct clnp_fixed);
CLNP_INSERT_ADDR(hoff, src);
CLNP_INSERT_ADDR(hoff, *our_addr);
@@ -332,25 +349,25 @@ char reason; /* reason for discard */
/* add er option */
*hoff++ = CLNPOVAL_ERREAS; /* code */
- *hoff++ = 2; /* length */
- *hoff++ = reason; /* discard reason */
- *hoff++ = 0; /* error localization = not specified */
+ *hoff++ = 2; /* length */
+ *hoff++ = reason; /* discard reason */
+ *hoff++ = 0; /* error localization = not specified */
/* set length */
- er->cnf_hdr_len = m0->m_len = (u_char)(hoff - (caddr_t)er);
+ er->cnf_hdr_len = m0->m_len = (u_char) (hoff - (caddr_t) er);
total_len = m0->m_len + m->m_len;
HTOC(er->cnf_seglen_msb, er->cnf_seglen_lsb, total_len);
/* compute checksum (on header only) */
- iso_gen_csum(m0, CLNP_CKSUM_OFF, (int)er->cnf_hdr_len);
+ iso_gen_csum(m0, CLNP_CKSUM_OFF, (int) er->cnf_hdr_len);
/* trim packet if too large for interface */
if (total_len > ifp->if_mtu)
m_adj(m0, -(total_len - ifp->if_mtu));
-
+
/* send packet */
INCSTAT(cns_er_outhist[clnp_er_index(reason)]);
- (void) (*ifp->if_output)(ifp, m0, first_hop, route.ro_rt);
+ (void) (*ifp->if_output) (ifp, m0, first_hop, route.ro_rt);
goto done;
bad:
@@ -362,8 +379,9 @@ done:
RTFREE(route.ro_rt);
}
+int
clnp_er_index(p)
-u_char p;
+ u_int p;
{
register u_char *cp = clnp_er_codes + CLNP_ERRORS;
while (cp > clnp_er_codes) {