diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1996-03-04 10:37:32 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1996-03-04 10:37:32 +0000 |
commit | 19b3595c2000294ed57cd7cb23e1d91ee553215d (patch) | |
tree | 404b337fc172b005d07d5f30eeeb873a270a9eac /sys/netiso/clnp_input.c | |
parent | d4b3fca05966647ecd8191d973cdce74570844ca (diff) |
Initial commit of NetBSD 960217 netiso.
all the rest is the fixes to the import by Niklas.
Diffstat (limited to 'sys/netiso/clnp_input.c')
-rw-r--r-- | sys/netiso/clnp_input.c | 364 |
1 files changed, 196 insertions, 168 deletions
diff --git a/sys/netiso/clnp_input.c b/sys/netiso/clnp_input.c index ecdbf3ff56f..ebe4c49afc5 100644 --- a/sys/netiso/clnp_input.c +++ b/sys/netiso/clnp_input.c @@ -1,4 +1,5 @@ -/* $NetBSD: clnp_input.c,v 1.10 1995/07/27 20:36:14 mycroft Exp $ */ +/* $OpenBSD: clnp_input.c,v 1.2 1996/03/04 10:34:53 mickey Exp $ */ +/* $NetBSD: clnp_input.c,v 1.11 1996/02/13 22:08:26 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 @@ -70,6 +71,7 @@ SOFTWARE. #include <sys/socketvar.h> #include <sys/errno.h> #include <sys/time.h> +#include <sys/systm.h> #include <net/if.h> #include <net/if_types.h> @@ -88,28 +90,30 @@ SOFTWARE. #include <netiso/clnp_stat.h> #include <netiso/argo_debug.h> +#include <machine/stdarg.h> + #ifdef ISO -u_char clnp_protox[ISOPROTO_MAX]; +u_char clnp_protox[ISOPROTO_MAX]; struct clnl_protosw clnl_protox[256]; -int clnpqmaxlen = IFQ_MAXLEN; /* RAH? why is this a variable */ -struct mbuf *clnp_data_ck(); - -void clnp_input(), esis_input(); +int clnpqmaxlen = IFQ_MAXLEN; /* RAH? why is this a + * variable */ #ifdef ISO_X25ESIS -void x25esis_input(); -#endif /* ISO_X25ESIS */ +#if 0 +void x25esis_input(); +#endif +#endif /* ISO_X25ESIS */ /* * FUNCTION: clnp_init * - * PURPOSE: clnp initialization. Fill in clnp switch tables. + * PURPOSE: clnp initialization. Fill in clnp switch tables. * - * RETURNS: none + * RETURNS: none * * SIDE EFFECTS: fills in clnp_protox table with correct offsets into - * the isosw table. + * the isosw table. * - * NOTES: + * NOTES: */ void clnp_init() @@ -117,7 +121,7 @@ clnp_init() register struct protosw *pr; /* - * CLNP protox initialization + * CLNP protox initialization */ if ((pr = pffindproto(PF_ISO, ISOPROTO_RAW, SOCK_RAW)) == 0) printf("clnl_init: no raw CLNP\n"); @@ -142,28 +146,30 @@ clnp_init() /* * FUNCTION: clnlintr * - * PURPOSE: Process a packet on the clnl input queue + * PURPOSE: Process a packet on the clnl input queue * - * RETURNS: nothing. + * RETURNS: nothing. * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ +void clnlintr() { - register struct mbuf *m; /* ptr to first mbuf of pkt */ - register struct clnl_fixed *clnl; /* ptr to fixed part of clnl hdr */ - int s; /* save and restore priority */ - struct clnl_protosw *clnlsw;/* ptr to protocol switch */ - struct snpa_hdr sh; /* subnetwork hdr */ + register struct mbuf *m;/* ptr to first mbuf of pkt */ + register struct clnl_fixed *clnl; /* ptr to fixed part of clnl + * hdr */ + int s; /* save and restore priority */ + struct clnl_protosw *clnlsw; /* ptr to protocol switch */ + struct snpa_hdr sh; /* subnetwork hdr */ /* * Get next datagram off clnl input queue */ next: s = splimp(); - /* IF_DEQUEUESNPAHDR(&clnlintrq, m, sh);*/ + /* IF_DEQUEUESNPAHDR(&clnlintrq, m, sh); */ IF_DEQUEUE(&clnlintrq, m); splx(s); @@ -176,7 +182,7 @@ next: } else { register struct ifaddr *ifa; for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) + ifa = ifa->ifa_list.tqe_next) if (ifa->ifa_addr->sa_family == AF_ISO) break; if (ifa == 0) { @@ -184,16 +190,15 @@ next: goto next; } } - 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) { - extern int ether_output(); + 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) { case IFT_EON: - bcopy(mtod(m, caddr_t), (caddr_t)sh.snh_dhost, sizeof(u_long)); + bcopy(mtod(m, caddr_t), (caddr_t) sh.snh_dhost, sizeof(u_long)); bcopy(sizeof(u_long) + mtod(m, caddr_t), - (caddr_t)sh.snh_shost, sizeof(u_long)); + (caddr_t) sh.snh_shost, sizeof(u_long)); sh.snh_dhost[4] = mtod(m, u_char *)[sizeof(struct ip) + - _offsetof(struct eon_hdr, eonh_class)]; + _offsetof(struct eon_hdr, eonh_class)]; m->m_data += EONIPLEN; m->m_len -= EONIPLEN; m->m_pkthdr.len -= EONIPLEN; @@ -201,61 +206,62 @@ next: default: if (sh.snh_ifp->if_output == ether_output) { - 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); + 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); } } - IFDEBUG(D_INPUT) - int i; +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { + int i; printf("clnlintr: src:"); - for (i=0; i<6; i++) - printf("%x%c", sh.snh_shost[i] & 0xff, (i<5) ? ':' : ' '); + for (i = 0; i < 6; i++) + printf("%x%c", sh.snh_shost[i] & 0xff, + (i < 5) ? ':' : ' '); printf(" dst:"); - for (i=0; i<6; i++) - printf("%x%c", sh.snh_dhost[i] & 0xff, (i<5) ? ':' : ' '); + for (i = 0; i < 6; i++) + printf("%x%c", sh.snh_dhost[i] & 0xff, + (i < 5) ? ':' : ' '); printf("\n"); - ENDDEBUG + } +#endif /* - * 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. + * 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. */ if ((IS_CLUSTER(m) || (m->m_len < sizeof(struct clnl_fixed))) && - ((m = m_pullup(m, sizeof(struct clnl_fixed))) == 0)) { + ((m = m_pullup(m, sizeof(struct clnl_fixed))) == 0)) { INCSTAT(cns_toosmall); /* TODO: use clnl stats */ - goto next; /* m_pullup discards mbuf */ + goto next; /* m_pullup discards mbuf */ } - clnl = mtod(m, struct clnl_fixed *); /* - * Drop packet if the length of the header is not reasonable. + * Drop packet if the length of the header is not reasonable. */ - if ((clnl->cnf_hdr_len < CLNP_HDR_MIN) || - (clnl->cnf_hdr_len > CLNP_HDR_MAX)) { + if ((clnl->cnf_hdr_len < CLNP_HDR_MIN) || + (clnl->cnf_hdr_len > CLNP_HDR_MAX)) { 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) { - if ((m = m_pullup(m, (int)clnl->cnf_hdr_len)) == 0) { + if ((m = m_pullup(m, (int) clnl->cnf_hdr_len)) == 0) { 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]; @@ -270,44 +276,58 @@ next: /* * FUNCTION: clnp_input * - * PURPOSE: process an incoming clnp packet + * PURPOSE: process an incoming clnp packet * - * RETURNS: nothing + * RETURNS: nothing * * SIDE EFFECTS: increments fields of clnp_stat structure. - * + * * NOTES: - * TODO: I would like to make seg_part a pointer into the mbuf, but + * TODO: I would like to make seg_part a pointer into the mbuf, but * will it be correctly aligned? */ void -clnp_input(m, shp) -struct mbuf *m; /* ptr to first mbuf of pkt */ -struct snpa_hdr *shp; /* subnetwork header */ +#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 { - register struct clnp_fixed *clnp; /* ptr to fixed part of header */ - struct sockaddr_iso source; /* source address of pkt */ - struct sockaddr_iso target; /* destination address of pkt */ + struct snpa_hdr *shp; /* subnetwork header */ + register struct clnp_fixed *clnp; /* ptr to fixed part of + * header */ + struct sockaddr_iso source; /* source address of pkt */ + struct sockaddr_iso target; /* destination address of pkt */ #define src source.siso_addr #define dst target.siso_addr - 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! */ - - IFDEBUG(D_INPUT) + 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); + + +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { printf( - "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"); - ENDDEBUG + "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"); + } +#endif need_afrin = 0; /* @@ -318,149 +338,153 @@ struct snpa_hdr *shp; /* subnetwork header */ clnp_discard(m, ADDR_DESTUNREACH); return; } - INCSTAT(cns_total); clnp = mtod(m, struct clnp_fixed *); - IFDEBUG(D_DUMPIN) - struct mbuf *mhead; - int total_len = 0; +#ifdef ARGO_DEBUG + if (argo_debug[D_DUMPIN]) { + struct mbuf *mhead; + int total_len = 0; printf("clnp_input: clnp header:\n"); dump_buf(mtod(m, caddr_t), clnp->cnf_hdr_len); printf("clnp_input: mbuf chain:\n"); - for (mhead = m; mhead != NULL; mhead=mhead->m_next) { - printf("m x%x, len %d\n", mhead, mhead->m_len); + for (mhead = m; mhead != NULL; mhead = mhead->m_next) { + printf("m x%x, len %d\n", (unsigned int) mhead, + mhead->m_len); total_len += mhead->m_len; } - printf("clnp_input: total length of mbuf chain %d:\n", total_len); - ENDDEBUG + printf("clnp_input: total length of mbuf chain %d:\n", + total_len); + } +#endif /* * Compute checksum (if necessary) and drop packet if * checksum does not match */ - if (CKSUM_REQUIRED(clnp) && iso_check_csum(m, (int)clnp->cnf_hdr_len)) { + if (CKSUM_REQUIRED(clnp) && + iso_check_csum(m, (int) clnp->cnf_hdr_len)) { INCSTAT(cns_badcsum); clnp_discard(m, GEN_BADCSUM); return; } - if (clnp->cnf_vers != ISO8473_V1) { INCSTAT(cns_badvers); clnp_discard(m, DISC_UNSUPPVERS); return; } - - - /* check mbuf data length: clnp_data_ck will free mbuf upon error */ + /* check mbuf data length: clnp_data_ck will free mbuf upon error */ CTOH(clnp->cnf_seglen_msb, clnp->cnf_seglen_lsb, seg_len); if ((m = clnp_data_ck(m, seg_len)) == 0) return; - + clnp = mtod(m, struct clnp_fixed *); - hend = (caddr_t)clnp + clnp->cnf_hdr_len; + hend = (caddr_t) clnp + clnp->cnf_hdr_len; - /* - * extract the source and destination address - * drop packet on failure + /* + * extract the source and destination address drop packet on failure */ source = target = blank_siso; - hoff = (caddr_t)clnp + sizeof(struct clnp_fixed); + hoff = (caddr_t) clnp + sizeof(struct clnp_fixed); CLNP_EXTRACT_ADDR(dst, hoff, hend); - if (hoff == (caddr_t)0) { + if (hoff == (caddr_t) 0) { INCSTAT(cns_badaddr); clnp_discard(m, GEN_INCOMPLETE); return; } CLNP_EXTRACT_ADDR(src, hoff, hend); - if (hoff == (caddr_t)0) { + if (hoff == (caddr_t) 0) { INCSTAT(cns_badaddr); clnp_discard(m, GEN_INCOMPLETE); return; } - - IFDEBUG(D_INPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { printf("clnp_input: from %s", clnp_iso_addrp(&src)); printf(" to %s\n", clnp_iso_addrp(&dst)); - ENDDEBUG + } +#endif /* - * extract the segmentation information, if it is present. - * drop packet on failure + * extract the segmentation information, if it is present. + * drop packet on failure */ if (((clnp->cnf_type & CNF_TYPE) != CLNP_ER) && - (clnp->cnf_type & CNF_SEG_OK)) { + (clnp->cnf_type & CNF_SEG_OK)) { if (hoff + sizeof(struct clnp_segment) > hend) { INCSTAT(cns_noseg); clnp_discard(m, GEN_INCOMPLETE); return; } else { - (void) bcopy(hoff, (caddr_t)&seg_part, sizeof(struct clnp_segment)); + (void) bcopy(hoff, (caddr_t) & seg_part, + sizeof(struct clnp_segment)); /* 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); - seg_off = hoff - (caddr_t)clnp; + seg_off = hoff - (caddr_t) clnp; hoff += sizeof(struct clnp_segment); } } - /* - * 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. + * 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. */ if (hoff < hend) { - int errcode; + int errcode; oidxp = &oidx; - errcode = clnp_opt_sanity(m, hoff, hend-hoff, oidxp); + errcode = clnp_opt_sanity(m, hoff, hend - hoff, oidxp); /* we do not support security */ if ((errcode == 0) && (oidxp->cni_securep)) errcode = DISC_UNSUPPSECURE; /* the er option is valid with ER pdus only */ - if ((errcode == 0) && (oidxp->cni_er_reason != ER_INVALREAS) && - ((clnp->cnf_type & CNF_TYPE) != CLNP_ER)) + if ((errcode == 0) && (oidxp->cni_er_reason != ER_INVALREAS) && + ((clnp->cnf_type & CNF_TYPE) != CLNP_ER)) errcode = DISC_UNSUPPOPT; #ifdef DECBIT /* check if the congestion experienced bit is set */ if (oidxp->cni_qos_formatp) { - caddr_t qosp = CLNP_OFFTOOPT(m, oidxp->cni_qos_formatp); - u_char qos = *qosp; + caddr_t qosp = CLNP_OFFTOOPT(m, oidxp->cni_qos_formatp); + u_char qos = *qosp; - need_afrin = ((qos & (CLNPOVAL_GLOBAL|CLNPOVAL_CONGESTED)) == - (CLNPOVAL_GLOBAL|CLNPOVAL_CONGESTED)); + need_afrin = ((qos & (CLNPOVAL_GLOBAL | CLNPOVAL_CONGESTED)) == + (CLNPOVAL_GLOBAL | CLNPOVAL_CONGESTED)); if (need_afrin) INCSTAT(cns_congest_rcvd); } -#endif /* DECBIT */ +#endif /* DECBIT */ if (errcode != 0) { - clnp_discard(m, (char)errcode); - IFDEBUG(D_INPUT) - printf("clnp_input: dropped (err x%x) due to bad options\n", - errcode); - ENDDEBUG + clnp_discard(m, (char) errcode); +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { + printf( + "clnp_input: dropped (err x%x) due to bad options\n", + errcode); + } +#endif return; } } - /* * check if this packet is for us. if not, then forward */ if (clnp_ours(&dst) == 0) { - IFDEBUG(D_INPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { printf("clnp_input: forwarding packet not for us\n"); - ENDDEBUG - clnp_forward(m, seg_len, &dst, oidxp, seg_off, shp); + } +#endif + clnp_forward(m, seg_len, &dst, oidxp, seg_off, shp); return; } - /* * ESIS Configuration Response Function * @@ -468,23 +492,22 @@ struct snpa_hdr *shp; /* subnetwork header */ * all end systems, then send an esh to the source */ if ((shp->snh_flags & M_MCAST) && (iso_systype == SNPA_ES)) { - extern short esis_holding_time; + extern short esis_holding_time; esis_shoutput(shp->snh_ifp, ESIS_ESH, esis_holding_time, - shp->snh_shost, 6, &dst); + shp->snh_shost, 6, &dst); } - /* - * 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. + * 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. */ if (((clnp->cnf_type & CNF_TYPE) != CLNP_ER) && - (clnp->cnf_type & CNF_SEG_OK) && - (seg_len != seg_part.cng_tot_len)) { - struct mbuf *m0; + (clnp->cnf_type & CNF_SEG_OK) && + (seg_len != seg_part.cng_tot_len)) { + struct mbuf *m0; if ((m0 = clnp_reass(m, &src, &dst, &seg_part)) != NULL) { m = m0; @@ -494,7 +517,6 @@ struct snpa_hdr *shp; /* subnetwork header */ return; } } - /* * give the packet to the higher layer * @@ -519,35 +541,41 @@ struct snpa_hdr *shp; /* subnetwork header */ case CLNP_DT: (*isosw[clnp_protox[ISOPROTO_TP]].pr_input)(m, &source, &target, - clnp->cnf_hdr_len, need_afrin); + clnp->cnf_hdr_len, need_afrin); break; - case CLNP_RAW: + case CLNP_RAW: case CLNP_ECR: - IFDEBUG(D_INPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { printf("clnp_input: raw input of %d bytes\n", - clnp->cnf_type & CNF_SEG_OK ? seg_part.cng_tot_len : seg_len); - ENDDEBUG - (*isosw[clnp_protox[ISOPROTO_RAW]].pr_input)(m, &source, &target, - clnp->cnf_hdr_len); + clnp->cnf_type & CNF_SEG_OK ? + seg_part.cng_tot_len : seg_len); + } +#endif + (*isosw[clnp_protox[ISOPROTO_RAW]].pr_input)(m, &source, + &target, + clnp->cnf_hdr_len); break; case CLNP_EC: - IFDEBUG(D_INPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_INPUT]) { printf("clnp_input: echoing packet\n"); - ENDDEBUG - (void)clnp_echoreply(m, - (clnp->cnf_type & CNF_SEG_OK ? (int)seg_part.cng_tot_len : seg_len), - &source, &target, oidxp); + } +#endif + (void) clnp_echoreply(m, (clnp->cnf_type & CNF_SEG_OK ? + (int) seg_part.cng_tot_len : seg_len), + &source, &target, oidxp); break; default: - printf("clnp_input: unknown clnp pkt type %d\n", - clnp->cnf_type & CNF_TYPE); + printf("clnp_input: unknown clnp pkt type %d\n", + clnp->cnf_type & CNF_TYPE); clnp_stat.cns_delivered--; clnp_stat.cns_noproto++; clnp_discard(m, GEN_HDRSYNTAX); - break; + break; } } -#endif /* ISO */ +#endif /* ISO */ |