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