Home | History | Annotate | Line # | Download | only in net
if_arcsubr.c revision 1.5.2.1
      1  1.5.2.1      is /*	$NetBSD: if_arcsubr.c,v 1.5.2.1 1996/04/15 12:46:10 is Exp $	*/
      2      1.1   glass 
      3      1.1   glass /*
      4      1.1   glass  * Copyright (c) 1994, 1995 Ignatios Souvatzis
      5      1.1   glass  * Copyright (c) 1982, 1989, 1993
      6      1.1   glass  *	The Regents of the University of California.  All rights reserved.
      7      1.1   glass  *
      8      1.1   glass  * Redistribution and use in source and binary forms, with or without
      9      1.1   glass  * modification, are permitted provided that the following conditions
     10      1.1   glass  * are met:
     11      1.1   glass  * 1. Redistributions of source code must retain the above copyright
     12      1.1   glass  *    notice, this list of conditions and the following disclaimer.
     13      1.1   glass  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1   glass  *    notice, this list of conditions and the following disclaimer in the
     15      1.1   glass  *    documentation and/or other materials provided with the distribution.
     16      1.1   glass  * 3. All advertising materials mentioning features or use of this software
     17      1.1   glass  *    must display the following acknowledgement:
     18      1.1   glass  *	This product includes software developed by the University of
     19      1.1   glass  *	California, Berkeley and its contributors.
     20      1.1   glass  * 4. Neither the name of the University nor the names of its contributors
     21      1.1   glass  *    may be used to endorse or promote products derived from this software
     22      1.1   glass  *    without specific prior written permission.
     23      1.1   glass  *
     24      1.1   glass  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25      1.1   glass  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26      1.1   glass  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27      1.1   glass  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28      1.1   glass  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29      1.1   glass  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30      1.1   glass  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31      1.1   glass  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32      1.1   glass  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33      1.1   glass  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34      1.1   glass  * SUCH DAMAGE.
     35      1.1   glass  *
     36      1.1   glass  * from: NetBSD: if_ethersubr.c,v 1.9 1994/06/29 06:36:11 cgd Exp
     37      1.1   glass  *       @(#)if_ethersubr.c	8.1 (Berkeley) 6/10/93
     38      1.1   glass  *
     39      1.1   glass  */
     40      1.1   glass 
     41      1.1   glass #include <sys/param.h>
     42      1.1   glass #include <sys/systm.h>
     43      1.1   glass #include <sys/kernel.h>
     44      1.1   glass #include <sys/malloc.h>
     45      1.1   glass #include <sys/mbuf.h>
     46      1.1   glass #include <sys/socket.h>
     47      1.3  chopps #include <sys/syslog.h>
     48      1.1   glass #include <sys/errno.h>
     49      1.1   glass 
     50      1.1   glass #include <machine/cpu.h>
     51      1.1   glass 
     52      1.1   glass #include <net/if.h>
     53      1.1   glass #include <net/netisr.h>
     54      1.1   glass #include <net/route.h>
     55      1.1   glass #include <net/if_dl.h>
     56      1.1   glass #include <net/if_types.h>
     57      1.1   glass 
     58      1.1   glass #ifdef INET
     59      1.1   glass #include <netinet/in.h>
     60      1.1   glass #include <netinet/in_var.h>
     61      1.1   glass #endif
     62      1.1   glass #include <netinet/if_arc.h>
     63      1.1   glass 
     64      1.4     cgd #ifndef	ARC_PHDSMTU
     65      1.4     cgd #define	ARC_PHDSMTU	1500
     66      1.4     cgd #endif
     67      1.4     cgd 
     68      1.4     cgd /* why isnt this in /sys/sys/mbuf.h?? */
     69      1.4     cgd extern struct mbuf *m_split __P((struct mbuf *, int, int));
     70      1.4     cgd static struct mbuf *arc_defrag __P((struct ifnet *, struct mbuf *));
     71      1.4     cgd 
     72      1.4     cgd /*
     73      1.4     cgd  * RC1201 requires us to have this configurable. We have it only per
     74      1.4     cgd  * machine at the moment... there is no generic "set mtu" ioctl, AFAICS.
     75      1.4     cgd  * Anyway, it is possible to binpatch this or set it per kernel config
     76      1.4     cgd  * option.
     77      1.4     cgd  */
     78      1.4     cgd #if ARC_PHDSMTU > 60480
     79      1.4     cgd ERROR: The arc_phdsmtu is ARC_PHDSMTU, but must not exceed 60480.
     80      1.4     cgd #endif
     81      1.4     cgd u_int16_t arc_phdsmtu = ARC_PHDSMTU;
     82      1.4     cgd u_int8_t  arcbroadcastaddr = 0;
     83      1.1   glass 
     84      1.1   glass #define senderr(e) { error = (e); goto bad;}
     85      1.1   glass #define SIN(s) ((struct sockaddr_in *)s)
     86      1.1   glass 
     87      1.1   glass /*
     88      1.1   glass  * ARCnet output routine.
     89      1.1   glass  * Encapsulate a packet of type family for the local net.
     90      1.1   glass  * Assumes that ifp is actually pointer to arccom structure.
     91      1.1   glass  */
     92      1.1   glass int
     93      1.1   glass arc_output(ifp, m0, dst, rt0)
     94      1.1   glass 	register struct ifnet *ifp;
     95      1.1   glass 	struct mbuf *m0;
     96      1.1   glass 	struct sockaddr *dst;
     97      1.1   glass 	struct rtentry *rt0;
     98      1.1   glass {
     99      1.4     cgd 	struct mbuf		*m, *m1, *mcopy;
    100      1.4     cgd 	struct rtentry		*rt;
    101      1.4     cgd 	struct arccom		*ac;
    102      1.1   glass 	register struct arc_header *ah;
    103      1.4     cgd 	int			off, len;
    104      1.4     cgd 	int			s, error, newencoding;
    105      1.4     cgd 	u_int8_t		atype, adst;
    106      1.4     cgd 	int			tfrags, sflag, fsflag, rsflag;
    107      1.1   glass 
    108      1.1   glass 	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
    109  1.5.2.1      is 		return(ENETDOWN); /* m, m1 aren't inialized yet */
    110      1.4     cgd 
    111      1.4     cgd 	error = newencoding = 0;
    112      1.4     cgd 	ac = (struct arccom *)ifp;
    113      1.4     cgd 	m = m0;
    114      1.4     cgd 	len = m->m_pkthdr.len;
    115      1.4     cgd 	mcopy = m1 = NULL;
    116      1.4     cgd 
    117      1.1   glass 	ifp->if_lastchange = time;
    118      1.1   glass 	if (rt = rt0) {
    119      1.1   glass 		if ((rt->rt_flags & RTF_UP) == 0) {
    120      1.1   glass 			if (rt0 = rt = rtalloc1(dst, 1))
    121      1.1   glass 				rt->rt_refcnt--;
    122      1.1   glass 			else
    123      1.1   glass 				senderr(EHOSTUNREACH);
    124      1.1   glass 		}
    125      1.1   glass 		if (rt->rt_flags & RTF_GATEWAY) {
    126      1.1   glass 			if (rt->rt_gwroute == 0)
    127      1.1   glass 				goto lookup;
    128      1.1   glass 			if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
    129      1.1   glass 				rtfree(rt); rt = rt0;
    130      1.1   glass 			lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
    131      1.1   glass 				if ((rt = rt->rt_gwroute) == 0)
    132      1.1   glass 					senderr(EHOSTUNREACH);
    133      1.1   glass 			}
    134      1.1   glass 		}
    135      1.1   glass 		if (rt->rt_flags & RTF_REJECT)
    136      1.1   glass 			if (rt->rt_rmx.rmx_expire == 0 ||
    137      1.1   glass 			    time.tv_sec < rt->rt_rmx.rmx_expire)
    138      1.1   glass 				senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
    139      1.1   glass 	}
    140      1.4     cgd 
    141      1.1   glass 	switch (dst->sa_family) {
    142      1.1   glass #ifdef INET
    143      1.1   glass 	case AF_INET:
    144      1.1   glass 
    145      1.1   glass 		/*
    146      1.1   glass 		 * For now, use the simple IP addr -> ARCnet addr mapping
    147      1.1   glass 		 */
    148      1.1   glass 		if (m->m_flags & M_BCAST)
    149      1.1   glass 			adst = arcbroadcastaddr; /* ARCnet broadcast address */
    150      1.1   glass 		else
    151      1.1   glass 			adst = ntohl(SIN(dst)->sin_addr.s_addr) & 0xFF;
    152      1.1   glass 
    153      1.1   glass 		/* If broadcasting on a simplex interface, loopback a copy */
    154      1.1   glass 		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
    155      1.1   glass 			mcopy = m_copy(m, 0, (int)M_COPYALL);
    156      1.1   glass 		off = m->m_pkthdr.len - m->m_len;
    157      1.4     cgd 		if (ifp->if_flags & IFF_LINK0) {
    158      1.4     cgd 			atype = ARCTYPE_IP;
    159      1.4     cgd 			newencoding = 1;
    160      1.4     cgd 		} else {
    161      1.4     cgd 			atype = ARCTYPE_IP_OLD;
    162      1.4     cgd 			newencoding = 0;
    163      1.4     cgd 		}
    164      1.1   glass 		break;
    165      1.1   glass #endif
    166      1.4     cgd 
    167      1.1   glass 	case AF_UNSPEC:
    168      1.1   glass 		ah = (struct arc_header *)dst->sa_data;
    169      1.1   glass  		adst = ah->arc_dhost;
    170      1.1   glass 		atype = ah->arc_type;
    171      1.1   glass 		break;
    172      1.1   glass 
    173      1.1   glass 	default:
    174      1.1   glass 		printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
    175      1.1   glass 			dst->sa_family);
    176      1.1   glass 		senderr(EAFNOSUPPORT);
    177      1.1   glass 	}
    178      1.1   glass 
    179      1.1   glass 	if (mcopy)
    180      1.1   glass 		(void) looutput(ifp, mcopy, dst, rt);
    181      1.4     cgd 
    182      1.1   glass 	/*
    183      1.1   glass 	 * Add local net header.  If no space in first mbuf,
    184      1.1   glass 	 * allocate another.
    185      1.1   glass 	 *
    186      1.1   glass 	 * For ARCnet, this is just symbolic. The header changes
    187      1.1   glass 	 * form and position on its way into the hardware and out of
    188      1.1   glass 	 * the wire.  At this point, it contains source, destination and
    189      1.1   glass 	 * packet type.
    190      1.1   glass 	 */
    191      1.4     cgd 	if (newencoding) {
    192      1.4     cgd 		++ac->ac_seqid; /* make the seqid unique */
    193      1.4     cgd 
    194      1.4     cgd 		tfrags = (len + 503) / 504;
    195      1.4     cgd 		fsflag = 2*tfrags-3;
    196      1.4     cgd 		sflag = 0;
    197      1.4     cgd 		rsflag = fsflag;
    198      1.4     cgd 
    199      1.4     cgd 		while (sflag < fsflag) {
    200      1.4     cgd 			/* we CAN'T have short packets here */
    201      1.4     cgd 			m1 = m_split(m, 504, M_DONTWAIT);
    202      1.4     cgd 			if (m1 == 0)
    203      1.4     cgd 				senderr(ENOBUFS);
    204      1.4     cgd 
    205      1.4     cgd 			M_PREPEND(m, ARC_HDRNEWLEN, M_DONTWAIT);
    206      1.4     cgd 			if (m == 0)
    207      1.4     cgd 				senderr(ENOBUFS);
    208      1.4     cgd 			m = m_pullup(m,ARC_HDRNEWLEN);
    209      1.4     cgd 			if (m == 0)
    210      1.4     cgd 				senderr(ENOBUFS);
    211      1.4     cgd 
    212      1.4     cgd 			ah = mtod(m, struct arc_header *);
    213      1.4     cgd 			ah->arc_type = atype;
    214      1.4     cgd 			ah->arc_dhost = adst;
    215      1.4     cgd 			ah->arc_shost = ac->ac_anaddr;
    216      1.4     cgd 			ah->arc_flag = rsflag;
    217      1.4     cgd 			ah->arc_seqid = ac->ac_seqid;
    218      1.4     cgd 
    219      1.4     cgd 			s = splimp();
    220      1.4     cgd 			/*
    221      1.4     cgd 			 * Queue message on interface, and start output if
    222      1.4     cgd 			 * interface not yet active.
    223      1.4     cgd 			 */
    224      1.4     cgd 			if (IF_QFULL(&ifp->if_snd)) {
    225      1.4     cgd 				IF_DROP(&ifp->if_snd);
    226      1.4     cgd 				splx(s);
    227      1.4     cgd 				senderr(ENOBUFS);
    228      1.4     cgd 			}
    229      1.4     cgd 			IF_ENQUEUE(&ifp->if_snd, m);
    230      1.4     cgd 			if ((ifp->if_flags & IFF_OACTIVE) == 0)
    231      1.4     cgd 				(*ifp->if_start)(ifp);
    232      1.4     cgd 			splx(s);
    233      1.4     cgd 
    234      1.4     cgd 			/* we don't count the hardwares lenght bytes here */
    235      1.4     cgd 			ifp->if_obytes += 504 + ARC_HDRNEWLEN;
    236      1.4     cgd 
    237      1.4     cgd 			m = m1;
    238      1.4     cgd 			len -= 504;
    239      1.4     cgd 			sflag += 2;
    240      1.4     cgd 			rsflag = sflag;
    241      1.4     cgd 		}
    242      1.4     cgd 		m1 = NULL;
    243      1.4     cgd 
    244      1.4     cgd 		M_PREPEND(m, ARC_HDRNEWLEN, M_DONTWAIT);
    245      1.4     cgd 		if (m == 0)
    246      1.4     cgd 			senderr(ENOBUFS);
    247      1.4     cgd 		m = m_pullup(m, ARC_HDRNEWLEN);
    248      1.4     cgd 		if (m == 0)
    249      1.4     cgd 			senderr(ENOBUFS);
    250      1.4     cgd 
    251      1.4     cgd 		ah = mtod(m, struct arc_header *);
    252      1.4     cgd 		ah->arc_type = atype;
    253      1.4     cgd 		ah->arc_flag = sflag;
    254      1.4     cgd 		ah->arc_seqid= ac->ac_seqid;
    255      1.4     cgd 
    256      1.4     cgd 		/* here we can have small, especially forbidden packets */
    257      1.4     cgd 
    258      1.4     cgd 		if ((len >= ARC_MIN_FORBID_LEN - ARC_HDRNEWLEN + 2) &&
    259      1.4     cgd 		    (len <= ARC_MAX_FORBID_LEN - ARC_HDRNEWLEN + 2)) {
    260      1.4     cgd 
    261      1.4     cgd 			M_PREPEND(m, 4, M_DONTWAIT);
    262      1.4     cgd 			if (m == 0)
    263      1.4     cgd 				senderr(ENOBUFS);
    264      1.4     cgd 
    265      1.4     cgd 			m = m_pullup(m, ARC_HDRNEWLEN);
    266      1.4     cgd 			if (m == 0)
    267      1.4     cgd 				senderr(ENOBUFS);
    268      1.4     cgd 
    269      1.4     cgd 			ah = mtod(m, struct arc_header *);
    270      1.4     cgd 			ah->arc_type = atype;
    271      1.4     cgd 			ah->arc_flag = 0xFF;
    272      1.4     cgd 			ah->arc_seqid= 0xFFFF;
    273      1.4     cgd 			len += 4;
    274      1.4     cgd 		}
    275      1.4     cgd 
    276      1.4     cgd 		ah->arc_dhost= adst;
    277      1.4     cgd 		ah->arc_shost= ac->ac_anaddr;
    278      1.4     cgd 
    279      1.4     cgd 		s = splimp();
    280      1.4     cgd 		/*
    281      1.4     cgd 		 * Queue message on interface, and start output if interface
    282      1.4     cgd 		 * not yet active.
    283      1.4     cgd 		 */
    284      1.4     cgd 		if (IF_QFULL(&ifp->if_snd)) {
    285      1.4     cgd 			IF_DROP(&ifp->if_snd);
    286      1.4     cgd 			splx(s);
    287      1.4     cgd 			senderr(ENOBUFS);
    288      1.4     cgd 		}
    289      1.4     cgd 		IF_ENQUEUE(&ifp->if_snd, m);
    290      1.4     cgd 		if ((ifp->if_flags & IFF_OACTIVE) == 0)
    291      1.4     cgd 			(*ifp->if_start)(ifp);
    292      1.4     cgd 		splx(s);
    293      1.4     cgd 
    294      1.4     cgd 		ifp->if_obytes += len + ARC_HDRNEWLEN;
    295      1.4     cgd 
    296      1.4     cgd 	} else {
    297      1.4     cgd 		M_PREPEND(m, ARC_HDRLEN, M_DONTWAIT);
    298      1.4     cgd 		if (m == 0)
    299      1.4     cgd 			senderr(ENOBUFS);
    300      1.4     cgd 		ah = mtod(m, struct arc_header *);
    301      1.4     cgd 		ah->arc_type = atype;
    302      1.4     cgd 		ah->arc_dhost= adst;
    303      1.4     cgd 		ah->arc_shost= ac->ac_anaddr;
    304      1.4     cgd 		s = splimp();
    305      1.4     cgd 		/*
    306      1.4     cgd 		 * Queue message on interface, and start output if interface
    307      1.4     cgd 		 * not yet active.
    308      1.4     cgd 		 */
    309      1.4     cgd 		if (IF_QFULL(&ifp->if_snd)) {
    310      1.4     cgd 			IF_DROP(&ifp->if_snd);
    311      1.4     cgd 			splx(s);
    312      1.4     cgd 			senderr(ENOBUFS);
    313      1.4     cgd 		}
    314      1.4     cgd 		IF_ENQUEUE(&ifp->if_snd, m);
    315      1.4     cgd 		if ((ifp->if_flags & IFF_OACTIVE) == 0)
    316      1.4     cgd 			(*ifp->if_start)(ifp);
    317      1.1   glass 		splx(s);
    318      1.4     cgd 
    319      1.4     cgd 		ifp->if_obytes += len + ARC_HDRLEN;
    320      1.1   glass 	}
    321      1.1   glass 	return (error);
    322      1.1   glass 
    323      1.1   glass bad:
    324      1.4     cgd 	if (m1)
    325      1.4     cgd 		m_freem(m1);
    326      1.1   glass 	if (m)
    327      1.1   glass 		m_freem(m);
    328      1.1   glass 	return (error);
    329      1.1   glass }
    330      1.1   glass 
    331      1.1   glass /*
    332      1.4     cgd  * Defragmenter. Returns mbuf if last packet found, else
    333      1.4     cgd  * NULL. frees imcoming mbuf as necessary.
    334      1.4     cgd  */
    335      1.4     cgd 
    336      1.4     cgd __inline struct mbuf *
    337      1.4     cgd arc_defrag(ifp, m)
    338      1.4     cgd 	struct ifnet *ifp;
    339      1.4     cgd 	struct mbuf *m;
    340      1.4     cgd {
    341      1.4     cgd 	struct arc_header *ah, *ah1;
    342      1.4     cgd 	struct arccom *ac;
    343      1.4     cgd 	struct ac_frag *af;
    344      1.4     cgd 	struct mbuf *m1;
    345      1.4     cgd 	char *s;
    346      1.4     cgd 	int newflen;
    347      1.4     cgd 	u_char src,dst,typ;
    348      1.4     cgd 
    349      1.4     cgd 	ac = (struct arccom *)ifp;
    350      1.4     cgd 
    351      1.4     cgd 	m = m_pullup(m, ARC_HDRNEWLEN);
    352      1.4     cgd 	if (m == NULL) {
    353      1.4     cgd 		++ifp->if_ierrors;
    354      1.4     cgd 		return NULL;
    355      1.4     cgd 	}
    356      1.4     cgd 
    357      1.4     cgd 	ah = mtod(m, struct arc_header *);
    358      1.4     cgd 	typ = ah->arc_type;
    359      1.4     cgd 
    360      1.4     cgd 	if (!arc_isphds(typ))
    361      1.4     cgd 		return m;
    362      1.4     cgd 
    363      1.4     cgd 	src = ah->arc_shost;
    364      1.4     cgd 	dst = ah->arc_dhost;
    365      1.4     cgd 
    366      1.4     cgd 	if (ah->arc_flag == 0xff) {
    367      1.4     cgd 		m_adj(m, 4);
    368      1.4     cgd 
    369      1.4     cgd 		m = m_pullup(m, ARC_HDRNEWLEN);
    370      1.4     cgd 		if (m == NULL) {
    371      1.4     cgd 			++ifp->if_ierrors;
    372      1.4     cgd 			return NULL;
    373      1.4     cgd 		}
    374      1.4     cgd 
    375      1.4     cgd 		ah = mtod(m, struct arc_header *);
    376      1.4     cgd 		ah->arc_shost = src;
    377      1.4     cgd 		ah->arc_dhost = dst;
    378      1.4     cgd 		ah->arc_type = typ;
    379      1.4     cgd 	}
    380      1.4     cgd 
    381      1.4     cgd 	af = &ac->ac_fragtab[src];
    382      1.4     cgd 	m1 = af->af_packet;
    383      1.4     cgd 	s = "debug code error";
    384      1.4     cgd 
    385      1.4     cgd 	if (ah->arc_flag & 1) {
    386      1.4     cgd 		/*
    387      1.4     cgd 		 * first fragment. We always initialize, which is
    388      1.4     cgd 		 * about the right thing to do, as we only want to
    389      1.4     cgd 		 * accept one fragmented packet per src at a time.
    390      1.4     cgd 		 */
    391      1.4     cgd 		if (m1 != NULL)
    392      1.4     cgd 			m_freem(m1);
    393      1.4     cgd 
    394      1.4     cgd 		af->af_packet = m;
    395      1.4     cgd 		m1 = m;
    396      1.4     cgd 		af->af_maxflag = ah->arc_flag;
    397      1.4     cgd 		af->af_lastseen = 0;
    398      1.4     cgd 		af->af_seqid = ah->arc_seqid;
    399      1.4     cgd 
    400      1.4     cgd 		return NULL;
    401      1.4     cgd 		/* notreached */
    402      1.4     cgd 	} else {
    403      1.4     cgd 		/* check for unfragmented packet */
    404      1.4     cgd 		if (ah->arc_flag == 0)
    405      1.4     cgd 			return m;
    406      1.4     cgd 
    407      1.4     cgd 		/* do we have a first packet from that src? */
    408      1.4     cgd 		if (m1 == NULL) {
    409      1.4     cgd 			s = "no first frag";
    410      1.4     cgd 			goto outofseq;
    411      1.4     cgd 		}
    412      1.4     cgd 
    413      1.4     cgd 		ah1 = mtod(m1, struct arc_header *);
    414      1.4     cgd 
    415      1.4     cgd 		if (ah->arc_seqid != ah1->arc_seqid) {
    416      1.4     cgd 			s = "seqid differs";
    417      1.4     cgd 			goto outofseq;
    418      1.4     cgd 		}
    419      1.4     cgd 
    420      1.4     cgd 		if (ah->arc_type != ah1->arc_type) {
    421      1.4     cgd 			s = "type differs";
    422      1.4     cgd 			goto outofseq;
    423      1.4     cgd 		}
    424      1.4     cgd 
    425      1.4     cgd 		if (ah->arc_dhost != ah1->arc_dhost) {
    426      1.4     cgd 			s = "dest host differs";
    427      1.4     cgd 			goto outofseq;
    428      1.4     cgd 		}
    429      1.4     cgd 
    430      1.4     cgd 		/* typ, seqid and dst are ok here. */
    431      1.4     cgd 
    432      1.4     cgd 		if (ah->arc_flag == af->af_lastseen) {
    433      1.4     cgd 			m_freem(m);
    434      1.4     cgd 			return NULL;
    435      1.4     cgd 		}
    436      1.4     cgd 
    437      1.4     cgd 		if (ah->arc_flag == af->af_lastseen + 2) {
    438      1.4     cgd 			/* ok, this is next fragment */
    439      1.4     cgd 			af->af_lastseen = ah->arc_flag;
    440      1.4     cgd 			m_adj(m,ARC_HDRNEWLEN);
    441      1.4     cgd 
    442      1.4     cgd 			/*
    443      1.4     cgd 			 * m_cat might free the first mbuf (with pkthdr)
    444      1.4     cgd 			 * in 2nd chain; therefore:
    445      1.4     cgd 			 */
    446      1.4     cgd 
    447      1.4     cgd 			newflen = m->m_pkthdr.len;
    448      1.4     cgd 
    449      1.4     cgd 			m_cat(m1,m);
    450      1.4     cgd 
    451      1.4     cgd 			m1->m_pkthdr.len += newflen;
    452      1.4     cgd 
    453      1.4     cgd 			/* is it the last one? */
    454      1.4     cgd 			if (af->af_lastseen > af->af_maxflag) {
    455      1.4     cgd 				af->af_packet = NULL;
    456      1.4     cgd 				return(m1);
    457      1.4     cgd 			} else
    458      1.4     cgd 				return NULL;
    459      1.4     cgd 		}
    460      1.4     cgd 		s = "other reason";
    461      1.4     cgd 		/* if all else fails, it is out of sequence, too */
    462      1.4     cgd 	}
    463      1.4     cgd outofseq:
    464      1.4     cgd 	if (m1) {
    465      1.4     cgd 		m_freem(m1);
    466      1.4     cgd 		af->af_packet = NULL;
    467      1.4     cgd 	}
    468      1.4     cgd 
    469      1.4     cgd 	if (m)
    470      1.4     cgd 		m_freem(m);
    471      1.4     cgd 
    472      1.4     cgd 	log(LOG_INFO,"%s%d: got out of seq. packet: %s\n",
    473      1.4     cgd 	    ifp->if_name, ifp->if_unit, s);
    474      1.4     cgd 
    475      1.4     cgd 	return NULL;
    476      1.4     cgd }
    477      1.4     cgd 
    478      1.4     cgd /*
    479      1.4     cgd  * return 1 if Packet Header Definition Standard, else 0.
    480      1.4     cgd  * For now: old IP, old ARP aren't obviously. Lacking correct information,
    481      1.4     cgd  * we guess that besides new IP and new ARP also IPX and APPLETALK are PHDS.
    482      1.4     cgd  * (Apple and Novell corporations were involved, among others, in PHDS work).
    483      1.4     cgd  * Easiest is to assume that everybody else uses that, too.
    484      1.4     cgd  */
    485      1.4     cgd int
    486      1.4     cgd arc_isphds(type)
    487      1.4     cgd 	int type;
    488      1.4     cgd {
    489      1.4     cgd 	return ((type != ARCTYPE_IP_OLD &&
    490      1.4     cgd 		 type != ARCTYPE_ARP_OLD));
    491      1.4     cgd }
    492      1.4     cgd 
    493      1.4     cgd /*
    494      1.1   glass  * Process a received Arcnet packet;
    495      1.3  chopps  * the packet is in the mbuf chain m with
    496      1.3  chopps  * the ARCnet header.
    497      1.1   glass  */
    498      1.1   glass void
    499      1.3  chopps arc_input(ifp, m)
    500      1.1   glass 	struct ifnet *ifp;
    501      1.1   glass 	struct mbuf *m;
    502      1.1   glass {
    503      1.3  chopps 	register struct arc_header *ah;
    504      1.1   glass 	register struct ifqueue *inq;
    505      1.4     cgd 	u_int8_t atype;
    506      1.1   glass 	int s;
    507      1.1   glass 
    508      1.1   glass 	if ((ifp->if_flags & IFF_UP) == 0) {
    509      1.1   glass 		m_freem(m);
    510      1.1   glass 		return;
    511      1.1   glass 	}
    512      1.4     cgd 
    513      1.4     cgd 	/* possibly defragment: */
    514      1.4     cgd 	m = arc_defrag(ifp, m);
    515      1.4     cgd 	if (m == NULL)
    516      1.4     cgd 		return;
    517      1.4     cgd 
    518      1.4     cgd 	ah = mtod(m, struct arc_header *);
    519      1.3  chopps 
    520      1.1   glass 	ifp->if_lastchange = time;
    521      1.3  chopps 	ifp->if_ibytes += m->m_pkthdr.len;
    522      1.1   glass 
    523      1.1   glass 	if (arcbroadcastaddr == ah->arc_dhost) {
    524      1.1   glass 		m->m_flags |= M_BCAST;
    525      1.1   glass 		ifp->if_imcasts++;
    526      1.1   glass 	}
    527      1.1   glass 
    528      1.1   glass 	atype = ah->arc_type;
    529      1.1   glass 	switch (atype) {
    530      1.1   glass #ifdef INET
    531      1.4     cgd 	case ARCTYPE_IP:
    532      1.4     cgd 		m_adj(m,ARC_HDRNEWLEN);
    533      1.4     cgd 		schednetisr(NETISR_IP);
    534      1.4     cgd 		inq = &ipintrq;
    535      1.4     cgd 		break;
    536      1.4     cgd 
    537      1.1   glass 	case ARCTYPE_IP_OLD:
    538      1.3  chopps 		m_adj(m,ARC_HDRLEN);
    539      1.1   glass 		schednetisr(NETISR_IP);
    540      1.1   glass 		inq = &ipintrq;
    541      1.1   glass 		break;
    542      1.1   glass #endif
    543      1.1   glass 	default:
    544      1.1   glass 		m_freem(m);
    545      1.1   glass 		return;
    546      1.1   glass 	}
    547      1.1   glass 
    548      1.1   glass 	s = splimp();
    549      1.1   glass 	if (IF_QFULL(inq)) {
    550      1.1   glass 		IF_DROP(inq);
    551      1.1   glass 		m_freem(m);
    552      1.1   glass 	} else
    553      1.1   glass 		IF_ENQUEUE(inq, m);
    554      1.1   glass 	splx(s);
    555      1.1   glass }
    556      1.1   glass 
    557      1.1   glass /*
    558      1.1   glass  * Convert Arcnet address to printable (loggable) representation.
    559      1.1   glass  */
    560      1.1   glass static char digits[] = "0123456789abcdef";
    561      1.1   glass char *
    562      1.1   glass arc_sprintf(ap)
    563      1.4     cgd 	register u_int8_t *ap;
    564      1.1   glass {
    565      1.1   glass 	static char arcbuf[3];
    566      1.1   glass 	register char *cp = arcbuf;
    567      1.1   glass 
    568      1.1   glass 	*cp++ = digits[*ap >> 4];
    569      1.1   glass 	*cp++ = digits[*ap++ & 0xf];
    570      1.1   glass 	*cp   = 0;
    571      1.1   glass 	return (arcbuf);
    572      1.1   glass }
    573      1.1   glass 
    574      1.1   glass /*
    575      1.1   glass  * Perform common duties while attaching to interface list
    576      1.1   glass  */
    577      1.1   glass void
    578      1.1   glass arc_ifattach(ifp)
    579      1.1   glass 	register struct ifnet *ifp;
    580      1.1   glass {
    581      1.1   glass 	register struct ifaddr *ifa;
    582      1.1   glass 	register struct sockaddr_dl *sdl;
    583      1.4     cgd 	register struct arccom *ac;
    584      1.1   glass 
    585      1.1   glass 	ifp->if_type = IFT_ARCNET;
    586      1.1   glass 	ifp->if_addrlen = 1;
    587      1.1   glass 	ifp->if_hdrlen = ARC_HDRLEN;
    588      1.4     cgd 	if (ifp->if_flags & IFF_LINK0 && arc_phdsmtu > 60480)
    589      1.4     cgd 		log(LOG_ERR,
    590      1.4     cgd 		    "%s%d: arc_phdsmtu is %d, but must not exceed 60480",
    591      1.4     cgd 		    ifp->if_name, ifp->if_unit, arc_phdsmtu);
    592      1.4     cgd 
    593      1.4     cgd 	ifp->if_mtu = (ifp->if_flags & IFF_LINK0 ? arc_phdsmtu : ARCMTU);
    594      1.4     cgd 	ac = (struct arccom *)ifp;
    595      1.4     cgd 	ac->ac_seqid = (time.tv_sec) & 0xFFFF; /* try to make seqid unique */
    596      1.4     cgd 	if (ac->ac_anaddr == 0) {
    597      1.4     cgd 		/* XXX this message isn't entirely clear, to me -- cgd */
    598      1.4     cgd 		log(LOG_ERR,"%s%d: link address 0 reserved for broadcasts.  Please change it and ifconfig %s%d down up\n",
    599      1.3  chopps 		   ifp->if_name,ifp->if_unit,ifp->if_name,ifp->if_unit);
    600      1.3  chopps 	}
    601      1.5     cgd 	for (ifa = ifp->if_addrlist.tqh_first; ifa != 0;
    602      1.5     cgd 	    ifa = ifa->ifa_list.tqe_next)
    603      1.1   glass 		if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
    604      1.1   glass 		    sdl->sdl_family == AF_LINK) {
    605      1.1   glass 			sdl->sdl_type = IFT_ARCNET;
    606      1.1   glass 			sdl->sdl_alen = ifp->if_addrlen;
    607      1.1   glass 			bcopy((caddr_t)&((struct arccom *)ifp)->ac_anaddr,
    608      1.1   glass 			      LLADDR(sdl), ifp->if_addrlen);
    609      1.1   glass 			break;
    610      1.1   glass 		}
    611      1.1   glass }
    612