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