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