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