Deleted Added
full compact
if_fddisubr.c (33676) if_fddisubr.c (34961)
1/*
2 * Copyright (c) 1995, 1996
3 * Matt Thomas <matt@3am-software.com>. All rights reserved.
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
1/*
2 * Copyright (c) 1995, 1996
3 * Matt Thomas <matt@3am-software.com>. All rights reserved.
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
36 * $Id: if_fddisubr.c,v 1.25 1998/01/09 00:51:55 eivind Exp $
36 * $Id: if_fddisubr.c,v 1.26 1998/02/20 13:11:49 bde Exp $
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_ipx.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/mbuf.h>
47#include <sys/socket.h>
48
49#include <net/if.h>
50#include <net/netisr.h>
51#include <net/route.h>
52#include <net/if_llc.h>
53#include <net/if_dl.h>
54#include <net/if_types.h>
55
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/in_var.h>
59#include <netinet/if_ether.h>
60#endif
61#if defined(__FreeBSD__)
62#include <netinet/if_fddi.h>
63#else
64#include <net/if_fddi.h>
65#endif
66
67#ifdef IPX
68#include <netipx/ipx.h>
69#include <netipx/ipx_if.h>
70#endif
71
72#ifdef NS
73#include <netns/ns.h>
74#include <netns/ns_if.h>
75#endif
76
77#ifdef DECNET
78#include <netdnet/dn.h>
79#endif
80
81#ifdef ISO
82#include <netiso/argo_debug.h>
83#include <netiso/iso.h>
84#include <netiso/iso_var.h>
85#include <netiso/iso_snpac.h>
86#endif
87
88#ifdef LLC
89#include <netccitt/dll.h>
90#include <netccitt/llc_var.h>
91#endif
92
93#ifdef NETATALK
94#include <netatalk/at.h>
95#include <netatalk/at_var.h>
96#include <netatalk/at_extern.h>
97
98#define llc_snap_org_code llc_un.type_snap.org_code
99#define llc_snap_ether_type llc_un.type_snap.ether_type
100
101extern u_char at_org_code[ 3 ];
102extern u_char aarp_org_code[ 3 ];
103#endif /* NETATALK */
104
105#if defined(LLC) && defined(CCITT)
106extern struct ifqueue pkintrq;
107#endif
108
109#include "bpfilter.h"
110
111#define senderr(e) { error = (e); goto bad;}
112
113/*
114 * This really should be defined in if_llc.h but in case it isn't.
115 */
116#ifndef llc_snap
117#define llc_snap llc_un.type_snap
118#endif
119
120#if defined(__bsdi__) || defined(__NetBSD__)
121#define RTALLOC1(a, b) rtalloc1(a, b)
122#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e)
123#elif defined(__FreeBSD__)
124#define RTALLOC1(a, b) rtalloc1(a, b, 0UL)
125#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f)
126#endif
127/*
128 * FDDI output routine.
129 * Encapsulate a packet of type family for the local net.
130 * Use trailer local net encapsulation if enough data in first
131 * packet leaves a multiple of 512 bytes of data in remainder.
132 * Assumes that ifp is actually pointer to arpcom structure.
133 */
134int
135fddi_output(ifp, m0, dst, rt0)
136 register struct ifnet *ifp;
137 struct mbuf *m0;
138 struct sockaddr *dst;
139 struct rtentry *rt0;
140{
141 u_int16_t type;
142 int s, error = 0;
143 u_char edst[6];
144 register struct mbuf *m = m0;
145 register struct rtentry *rt;
146 register struct fddi_header *fh;
147 struct mbuf *mcopy = (struct mbuf *)0;
148 struct arpcom *ac = (struct arpcom *)ifp;
149
150 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
151 senderr(ENETDOWN);
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_ipx.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/mbuf.h>
47#include <sys/socket.h>
48
49#include <net/if.h>
50#include <net/netisr.h>
51#include <net/route.h>
52#include <net/if_llc.h>
53#include <net/if_dl.h>
54#include <net/if_types.h>
55
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/in_var.h>
59#include <netinet/if_ether.h>
60#endif
61#if defined(__FreeBSD__)
62#include <netinet/if_fddi.h>
63#else
64#include <net/if_fddi.h>
65#endif
66
67#ifdef IPX
68#include <netipx/ipx.h>
69#include <netipx/ipx_if.h>
70#endif
71
72#ifdef NS
73#include <netns/ns.h>
74#include <netns/ns_if.h>
75#endif
76
77#ifdef DECNET
78#include <netdnet/dn.h>
79#endif
80
81#ifdef ISO
82#include <netiso/argo_debug.h>
83#include <netiso/iso.h>
84#include <netiso/iso_var.h>
85#include <netiso/iso_snpac.h>
86#endif
87
88#ifdef LLC
89#include <netccitt/dll.h>
90#include <netccitt/llc_var.h>
91#endif
92
93#ifdef NETATALK
94#include <netatalk/at.h>
95#include <netatalk/at_var.h>
96#include <netatalk/at_extern.h>
97
98#define llc_snap_org_code llc_un.type_snap.org_code
99#define llc_snap_ether_type llc_un.type_snap.ether_type
100
101extern u_char at_org_code[ 3 ];
102extern u_char aarp_org_code[ 3 ];
103#endif /* NETATALK */
104
105#if defined(LLC) && defined(CCITT)
106extern struct ifqueue pkintrq;
107#endif
108
109#include "bpfilter.h"
110
111#define senderr(e) { error = (e); goto bad;}
112
113/*
114 * This really should be defined in if_llc.h but in case it isn't.
115 */
116#ifndef llc_snap
117#define llc_snap llc_un.type_snap
118#endif
119
120#if defined(__bsdi__) || defined(__NetBSD__)
121#define RTALLOC1(a, b) rtalloc1(a, b)
122#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e)
123#elif defined(__FreeBSD__)
124#define RTALLOC1(a, b) rtalloc1(a, b, 0UL)
125#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f)
126#endif
127/*
128 * FDDI output routine.
129 * Encapsulate a packet of type family for the local net.
130 * Use trailer local net encapsulation if enough data in first
131 * packet leaves a multiple of 512 bytes of data in remainder.
132 * Assumes that ifp is actually pointer to arpcom structure.
133 */
134int
135fddi_output(ifp, m0, dst, rt0)
136 register struct ifnet *ifp;
137 struct mbuf *m0;
138 struct sockaddr *dst;
139 struct rtentry *rt0;
140{
141 u_int16_t type;
142 int s, error = 0;
143 u_char edst[6];
144 register struct mbuf *m = m0;
145 register struct rtentry *rt;
146 register struct fddi_header *fh;
147 struct mbuf *mcopy = (struct mbuf *)0;
148 struct arpcom *ac = (struct arpcom *)ifp;
149
150 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
151 senderr(ENETDOWN);
152 gettime(&ifp->if_lastchange);
152 getmicrotime(&ifp->if_lastchange);
153#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
154 if (rt = rt0) {
155 if ((rt->rt_flags & RTF_UP) == 0) {
156 if (rt0 = rt = RTALLOC1(dst, 1))
157 rt->rt_refcnt--;
158 else
159 senderr(EHOSTUNREACH);
160 }
161 if (rt->rt_flags & RTF_GATEWAY) {
162 if (rt->rt_gwroute == 0)
163 goto lookup;
164 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
165 rtfree(rt); rt = rt0;
166 lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 1);
167 if ((rt = rt->rt_gwroute) == 0)
168 senderr(EHOSTUNREACH);
169 }
170 }
171 if (rt->rt_flags & RTF_REJECT)
172 if (rt->rt_rmx.rmx_expire == 0 ||
153#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
154 if (rt = rt0) {
155 if ((rt->rt_flags & RTF_UP) == 0) {
156 if (rt0 = rt = RTALLOC1(dst, 1))
157 rt->rt_refcnt--;
158 else
159 senderr(EHOSTUNREACH);
160 }
161 if (rt->rt_flags & RTF_GATEWAY) {
162 if (rt->rt_gwroute == 0)
163 goto lookup;
164 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
165 rtfree(rt); rt = rt0;
166 lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 1);
167 if ((rt = rt->rt_gwroute) == 0)
168 senderr(EHOSTUNREACH);
169 }
170 }
171 if (rt->rt_flags & RTF_REJECT)
172 if (rt->rt_rmx.rmx_expire == 0 ||
173 time.tv_sec < rt->rt_rmx.rmx_expire)
173 time_second < rt->rt_rmx.rmx_expire)
174 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
175 }
176#endif
177 switch (dst->sa_family) {
178
179#ifdef INET
180 case AF_INET: {
181#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
182 if (!ARPRESOLVE(ac, rt, m, dst, edst, rt0))
183 return (0); /* if not yet resolved */
184#else
185 int usetrailers;
186 if (!arpresolve(ac, m, &((struct sockaddr_in *)dst)->sin_addr, edst, &usetrailers))
187 return (0); /* if not yet resolved */
188#endif
189 /* If broadcasting on a simplex interface, loopback a copy */
190 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
191 mcopy = m_copy(m, 0, (int)M_COPYALL);
192 type = htons(ETHERTYPE_IP);
193 break;
194 }
195#endif
196#ifdef IPX
197 case AF_IPX:
198 {
199 struct ifaddr *ia;
200
201 type = htons(ETHERTYPE_IPX);
202 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
203 (caddr_t)edst, sizeof (edst));
204
205 for(ia = ifp->if_addrhead.tqh_first; ia != 0;
206 ia = ia->ifa_link.tqe_next) {
207 if(ia->ifa_addr->sa_family == AF_IPX &&
208 !bcmp((caddr_t)edst,
209 (caddr_t)&((struct ipx_ifaddr *)ia)->ia_addr.sipx_addr.x_host,
210 sizeof(edst)) )
211 return (looutput(ifp, m, dst, rt));
212 }
213
214 /* If broadcasting on a simplex interface, loopback a copy */
215 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
216 mcopy = m_copy(m, 0, (int)M_COPYALL);
217 break;
218 }
219#endif
220#ifdef NETATALK
221 case AF_APPLETALK: {
222 struct at_ifaddr *aa;
223 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) {
224#ifdef NETATALKDEBUG
225 extern char *prsockaddr(struct sockaddr *);
226 printf("aarpresolv: failed for %s\n", prsockaddr(dst));
227#endif
228 return (0);
229 }
230 /*
231 * ifaddr is the first thing in at_ifaddr
232 */
233 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
234 goto bad;
235
236 /*
237 * In the phase 2 case, we need to prepend an mbuf for the llc header.
238 * Since we must preserve the value of m, which is passed to us by
239 * value, we m_copy() the first mbuf, and use it for our llc header.
240 */
241 if (aa->aa_flags & AFA_PHASE2) {
242 struct llc llc;
243
244 M_PREPEND(m, sizeof(struct llc), M_WAIT);
245 if (m == 0)
246 senderr(ENOBUFS);
247 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
248 llc.llc_control = LLC_UI;
249 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
250 llc.llc_snap_ether_type = htons(ETHERTYPE_AT);
251 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
252 type = 0;
253 } else {
254 type = htons(ETHERTYPE_AT);
255 }
256 break;
257 }
258#endif /* NETATALK */
259#ifdef NS
260 case AF_NS:
261 type = htons(ETHERTYPE_NS);
262 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
263 (caddr_t)edst, sizeof (edst));
264 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
265 return (looutput(ifp, m, dst, rt));
266 /* If broadcasting on a simplex interface, loopback a copy */
267 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
268 mcopy = m_copy(m, 0, (int)M_COPYALL);
269 break;
270#endif
271#ifdef ISO
272 case AF_ISO: {
273 int snpalen;
274 struct llc *l;
275 register struct sockaddr_dl *sdl;
276
277 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
278 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
279 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
280 } else if (error =
281 iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
282 (char *)edst, &snpalen))
283 goto bad; /* Not Resolved */
284 /* If broadcasting on a simplex interface, loopback a copy */
285 if (*edst & 1)
286 m->m_flags |= (M_BCAST|M_MCAST);
287 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
288 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
289 M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
290 if (mcopy) {
291 fh = mtod(mcopy, struct fddi_header *);
292 bcopy((caddr_t)edst,
293 (caddr_t)fh->fddi_dhost, sizeof (edst));
294 bcopy((caddr_t)ac->ac_enaddr,
295 (caddr_t)fh->fddi_shost, sizeof (edst));
296 }
297 }
298 M_PREPEND(m, 3, M_DONTWAIT);
299 if (m == NULL)
300 return (0);
301 type = 0;
302 l = mtod(m, struct llc *);
303 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
304 l->llc_control = LLC_UI;
305 IFDEBUG(D_ETHER)
306 int i;
307 printf("unoutput: sending pkt to: ");
308 for (i=0; i<6; i++)
309 printf("%x ", edst[i] & 0xff);
310 printf("\n");
311 ENDDEBUG
312 } break;
313#endif /* ISO */
314#ifdef LLC
315/* case AF_NSAP: */
316 case AF_CCITT: {
317 register struct sockaddr_dl *sdl =
318 (struct sockaddr_dl *) rt -> rt_gateway;
319
320 if (sdl && sdl->sdl_family != AF_LINK && sdl->sdl_alen <= 0)
321 goto bad; /* Not a link interface ? Funny ... */
322 bcopy(LLADDR(sdl), (char *)edst, sizeof(edst));
323 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
324 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
325 M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
326 if (mcopy) {
327 fh = mtod(mcopy, struct fddi_header *);
328 bcopy((caddr_t)edst,
329 (caddr_t)fh->fddi_dhost, sizeof (edst));
330 bcopy((caddr_t)ac->ac_enaddr,
331 (caddr_t)fh->fddi_shost, sizeof (edst));
332 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
333 }
334 }
335 type = 0;
336#ifdef LLC_DEBUG
337 {
338 int i;
339 register struct llc *l = mtod(m, struct llc *);
340
341 printf("fddi_output: sending LLC2 pkt to: ");
342 for (i=0; i<6; i++)
343 printf("%x ", edst[i] & 0xff);
344 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
345 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
346 l->llc_control & 0xff);
347
348 }
349#endif /* LLC_DEBUG */
350 } break;
351#endif /* LLC */
352
353 case AF_UNSPEC:
354 {
355 struct ether_header *eh;
356 eh = (struct ether_header *)dst->sa_data;
357 (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
358 if (*edst & 1)
359 m->m_flags |= (M_BCAST|M_MCAST);
360 type = eh->ether_type;
361 break;
362 }
363
364#if NBPFILTER > 0
365 case AF_IMPLINK:
366 {
367 fh = mtod(m, struct fddi_header *);
368 error = EPROTONOSUPPORT;
369 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
370 case FDDIFC_LLC_ASYNC: {
371 /* legal priorities are 0 through 7 */
372 if ((fh->fddi_fc & FDDIFC_Z) > 7)
373 goto bad;
374 break;
375 }
376 case FDDIFC_LLC_SYNC: {
377 /* FDDIFC_Z bits reserved, must be zero */
378 if (fh->fddi_fc & FDDIFC_Z)
379 goto bad;
380 break;
381 }
382 case FDDIFC_SMT: {
383 /* FDDIFC_Z bits must be non zero */
384 if ((fh->fddi_fc & FDDIFC_Z) == 0)
385 goto bad;
386 break;
387 }
388 default: {
389 /* anything else is too dangerous */
390 goto bad;
391 }
392 }
393 error = 0;
394 if (fh->fddi_dhost[0] & 1)
395 m->m_flags |= (M_BCAST|M_MCAST);
396 goto queue_it;
397 }
398#endif
399 default:
400 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
401 dst->sa_family);
402 senderr(EAFNOSUPPORT);
403 }
404
405
406 if (mcopy)
407 (void) looutput(ifp, mcopy, dst, rt);
408 if (type != 0) {
409 register struct llc *l;
410 M_PREPEND(m, sizeof (struct llc), M_DONTWAIT);
411 if (m == 0)
412 senderr(ENOBUFS);
413 l = mtod(m, struct llc *);
414 l->llc_control = LLC_UI;
415 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
416 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0;
417 (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type,
418 sizeof(u_int16_t));
419 }
420 /*
421 * Add local net header. If no space in first mbuf,
422 * allocate another.
423 */
424 M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT);
425 if (m == 0)
426 senderr(ENOBUFS);
427 fh = mtod(m, struct fddi_header *);
428 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
429 (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst));
430 queue_it:
431 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr,
432 sizeof(fh->fddi_shost));
433 s = splimp();
434 /*
435 * Queue message on interface, and start output if interface
436 * not yet active.
437 */
438 if (IF_QFULL(&ifp->if_snd)) {
439 IF_DROP(&ifp->if_snd);
440 splx(s);
441 senderr(ENOBUFS);
442 }
443 ifp->if_obytes += m->m_pkthdr.len;
444 IF_ENQUEUE(&ifp->if_snd, m);
445 if ((ifp->if_flags & IFF_OACTIVE) == 0)
446 (*ifp->if_start)(ifp);
447 splx(s);
448 if (m->m_flags & M_MCAST)
449 ifp->if_omcasts++;
450 return (error);
451
452bad:
453 if (m)
454 m_freem(m);
455 return (error);
456}
457
458/*
459 * Process a received FDDI packet;
460 * the packet is in the mbuf chain m without
461 * the fddi header, which is provided separately.
462 */
463void
464fddi_input(ifp, fh, m)
465 struct ifnet *ifp;
466 register struct fddi_header *fh;
467 struct mbuf *m;
468{
469 register struct ifqueue *inq;
470 register struct llc *l;
471 int s;
472
473 if ((ifp->if_flags & IFF_UP) == 0) {
474 m_freem(m);
475 return;
476 }
174 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
175 }
176#endif
177 switch (dst->sa_family) {
178
179#ifdef INET
180 case AF_INET: {
181#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
182 if (!ARPRESOLVE(ac, rt, m, dst, edst, rt0))
183 return (0); /* if not yet resolved */
184#else
185 int usetrailers;
186 if (!arpresolve(ac, m, &((struct sockaddr_in *)dst)->sin_addr, edst, &usetrailers))
187 return (0); /* if not yet resolved */
188#endif
189 /* If broadcasting on a simplex interface, loopback a copy */
190 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
191 mcopy = m_copy(m, 0, (int)M_COPYALL);
192 type = htons(ETHERTYPE_IP);
193 break;
194 }
195#endif
196#ifdef IPX
197 case AF_IPX:
198 {
199 struct ifaddr *ia;
200
201 type = htons(ETHERTYPE_IPX);
202 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
203 (caddr_t)edst, sizeof (edst));
204
205 for(ia = ifp->if_addrhead.tqh_first; ia != 0;
206 ia = ia->ifa_link.tqe_next) {
207 if(ia->ifa_addr->sa_family == AF_IPX &&
208 !bcmp((caddr_t)edst,
209 (caddr_t)&((struct ipx_ifaddr *)ia)->ia_addr.sipx_addr.x_host,
210 sizeof(edst)) )
211 return (looutput(ifp, m, dst, rt));
212 }
213
214 /* If broadcasting on a simplex interface, loopback a copy */
215 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
216 mcopy = m_copy(m, 0, (int)M_COPYALL);
217 break;
218 }
219#endif
220#ifdef NETATALK
221 case AF_APPLETALK: {
222 struct at_ifaddr *aa;
223 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) {
224#ifdef NETATALKDEBUG
225 extern char *prsockaddr(struct sockaddr *);
226 printf("aarpresolv: failed for %s\n", prsockaddr(dst));
227#endif
228 return (0);
229 }
230 /*
231 * ifaddr is the first thing in at_ifaddr
232 */
233 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
234 goto bad;
235
236 /*
237 * In the phase 2 case, we need to prepend an mbuf for the llc header.
238 * Since we must preserve the value of m, which is passed to us by
239 * value, we m_copy() the first mbuf, and use it for our llc header.
240 */
241 if (aa->aa_flags & AFA_PHASE2) {
242 struct llc llc;
243
244 M_PREPEND(m, sizeof(struct llc), M_WAIT);
245 if (m == 0)
246 senderr(ENOBUFS);
247 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
248 llc.llc_control = LLC_UI;
249 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
250 llc.llc_snap_ether_type = htons(ETHERTYPE_AT);
251 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
252 type = 0;
253 } else {
254 type = htons(ETHERTYPE_AT);
255 }
256 break;
257 }
258#endif /* NETATALK */
259#ifdef NS
260 case AF_NS:
261 type = htons(ETHERTYPE_NS);
262 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
263 (caddr_t)edst, sizeof (edst));
264 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
265 return (looutput(ifp, m, dst, rt));
266 /* If broadcasting on a simplex interface, loopback a copy */
267 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
268 mcopy = m_copy(m, 0, (int)M_COPYALL);
269 break;
270#endif
271#ifdef ISO
272 case AF_ISO: {
273 int snpalen;
274 struct llc *l;
275 register struct sockaddr_dl *sdl;
276
277 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
278 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
279 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
280 } else if (error =
281 iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
282 (char *)edst, &snpalen))
283 goto bad; /* Not Resolved */
284 /* If broadcasting on a simplex interface, loopback a copy */
285 if (*edst & 1)
286 m->m_flags |= (M_BCAST|M_MCAST);
287 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
288 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
289 M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
290 if (mcopy) {
291 fh = mtod(mcopy, struct fddi_header *);
292 bcopy((caddr_t)edst,
293 (caddr_t)fh->fddi_dhost, sizeof (edst));
294 bcopy((caddr_t)ac->ac_enaddr,
295 (caddr_t)fh->fddi_shost, sizeof (edst));
296 }
297 }
298 M_PREPEND(m, 3, M_DONTWAIT);
299 if (m == NULL)
300 return (0);
301 type = 0;
302 l = mtod(m, struct llc *);
303 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
304 l->llc_control = LLC_UI;
305 IFDEBUG(D_ETHER)
306 int i;
307 printf("unoutput: sending pkt to: ");
308 for (i=0; i<6; i++)
309 printf("%x ", edst[i] & 0xff);
310 printf("\n");
311 ENDDEBUG
312 } break;
313#endif /* ISO */
314#ifdef LLC
315/* case AF_NSAP: */
316 case AF_CCITT: {
317 register struct sockaddr_dl *sdl =
318 (struct sockaddr_dl *) rt -> rt_gateway;
319
320 if (sdl && sdl->sdl_family != AF_LINK && sdl->sdl_alen <= 0)
321 goto bad; /* Not a link interface ? Funny ... */
322 bcopy(LLADDR(sdl), (char *)edst, sizeof(edst));
323 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
324 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
325 M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
326 if (mcopy) {
327 fh = mtod(mcopy, struct fddi_header *);
328 bcopy((caddr_t)edst,
329 (caddr_t)fh->fddi_dhost, sizeof (edst));
330 bcopy((caddr_t)ac->ac_enaddr,
331 (caddr_t)fh->fddi_shost, sizeof (edst));
332 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
333 }
334 }
335 type = 0;
336#ifdef LLC_DEBUG
337 {
338 int i;
339 register struct llc *l = mtod(m, struct llc *);
340
341 printf("fddi_output: sending LLC2 pkt to: ");
342 for (i=0; i<6; i++)
343 printf("%x ", edst[i] & 0xff);
344 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
345 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
346 l->llc_control & 0xff);
347
348 }
349#endif /* LLC_DEBUG */
350 } break;
351#endif /* LLC */
352
353 case AF_UNSPEC:
354 {
355 struct ether_header *eh;
356 eh = (struct ether_header *)dst->sa_data;
357 (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
358 if (*edst & 1)
359 m->m_flags |= (M_BCAST|M_MCAST);
360 type = eh->ether_type;
361 break;
362 }
363
364#if NBPFILTER > 0
365 case AF_IMPLINK:
366 {
367 fh = mtod(m, struct fddi_header *);
368 error = EPROTONOSUPPORT;
369 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
370 case FDDIFC_LLC_ASYNC: {
371 /* legal priorities are 0 through 7 */
372 if ((fh->fddi_fc & FDDIFC_Z) > 7)
373 goto bad;
374 break;
375 }
376 case FDDIFC_LLC_SYNC: {
377 /* FDDIFC_Z bits reserved, must be zero */
378 if (fh->fddi_fc & FDDIFC_Z)
379 goto bad;
380 break;
381 }
382 case FDDIFC_SMT: {
383 /* FDDIFC_Z bits must be non zero */
384 if ((fh->fddi_fc & FDDIFC_Z) == 0)
385 goto bad;
386 break;
387 }
388 default: {
389 /* anything else is too dangerous */
390 goto bad;
391 }
392 }
393 error = 0;
394 if (fh->fddi_dhost[0] & 1)
395 m->m_flags |= (M_BCAST|M_MCAST);
396 goto queue_it;
397 }
398#endif
399 default:
400 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
401 dst->sa_family);
402 senderr(EAFNOSUPPORT);
403 }
404
405
406 if (mcopy)
407 (void) looutput(ifp, mcopy, dst, rt);
408 if (type != 0) {
409 register struct llc *l;
410 M_PREPEND(m, sizeof (struct llc), M_DONTWAIT);
411 if (m == 0)
412 senderr(ENOBUFS);
413 l = mtod(m, struct llc *);
414 l->llc_control = LLC_UI;
415 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
416 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0;
417 (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type,
418 sizeof(u_int16_t));
419 }
420 /*
421 * Add local net header. If no space in first mbuf,
422 * allocate another.
423 */
424 M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT);
425 if (m == 0)
426 senderr(ENOBUFS);
427 fh = mtod(m, struct fddi_header *);
428 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
429 (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst));
430 queue_it:
431 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr,
432 sizeof(fh->fddi_shost));
433 s = splimp();
434 /*
435 * Queue message on interface, and start output if interface
436 * not yet active.
437 */
438 if (IF_QFULL(&ifp->if_snd)) {
439 IF_DROP(&ifp->if_snd);
440 splx(s);
441 senderr(ENOBUFS);
442 }
443 ifp->if_obytes += m->m_pkthdr.len;
444 IF_ENQUEUE(&ifp->if_snd, m);
445 if ((ifp->if_flags & IFF_OACTIVE) == 0)
446 (*ifp->if_start)(ifp);
447 splx(s);
448 if (m->m_flags & M_MCAST)
449 ifp->if_omcasts++;
450 return (error);
451
452bad:
453 if (m)
454 m_freem(m);
455 return (error);
456}
457
458/*
459 * Process a received FDDI packet;
460 * the packet is in the mbuf chain m without
461 * the fddi header, which is provided separately.
462 */
463void
464fddi_input(ifp, fh, m)
465 struct ifnet *ifp;
466 register struct fddi_header *fh;
467 struct mbuf *m;
468{
469 register struct ifqueue *inq;
470 register struct llc *l;
471 int s;
472
473 if ((ifp->if_flags & IFF_UP) == 0) {
474 m_freem(m);
475 return;
476 }
477 gettime(&ifp->if_lastchange);
477 getmicrotime(&ifp->if_lastchange);
478 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh);
479 if (fh->fddi_dhost[0] & 1) {
480 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost,
481 sizeof(fddibroadcastaddr)) == 0)
482 m->m_flags |= M_BCAST;
483 else
484 m->m_flags |= M_MCAST;
485 ifp->if_imcasts++;
486 } else if ((ifp->if_flags & IFF_PROMISC)
487 && bcmp(((struct arpcom *)ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost,
488 sizeof(fh->fddi_dhost)) != 0) {
489 m_freem(m);
490 return;
491 }
492
493#ifdef M_LINK0
494 /*
495 * If this has a LLC priority of 0, then mark it so upper
496 * layers have a hint that it really came via a FDDI/Ethernet
497 * bridge.
498 */
499 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
500 m->m_flags |= M_LINK0;
501#endif
502
503 l = mtod(m, struct llc *);
504 switch (l->llc_dsap) {
505#if defined(INET) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK)
506 case LLC_SNAP_LSAP:
507 {
508 u_int16_t type;
509 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP)
510 goto dropanyway;
511#ifdef NETATALK
512 if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code,
513 sizeof(at_org_code)) == 0 &&
514 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) {
515 inq = &atintrq2;
516 m_adj( m, sizeof( struct llc ));
517 schednetisr(NETISR_ATALK);
518 break;
519 }
520
521 if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code,
522 sizeof(aarp_org_code)) == 0 &&
523 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) {
524 m_adj( m, sizeof( struct llc ));
525 aarpinput((struct arpcom *)ifp, m); /* XXX */
526 return;
527 }
528#endif /* NETATALK */
529 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0)
530 goto dropanyway;
531 type = ntohs(l->llc_snap.ether_type);
532 m_adj(m, 8);
533 switch (type) {
534#ifdef INET
535 case ETHERTYPE_IP:
536 schednetisr(NETISR_IP);
537 inq = &ipintrq;
538 break;
539
540 case ETHERTYPE_ARP:
541#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
542 schednetisr(NETISR_ARP);
543 inq = &arpintrq;
544 break;
545#else
546 arpinput((struct arpcom *)ifp, m);
547 return;
548#endif
549#endif
550#ifdef IPX
551 case ETHERTYPE_IPX:
552 schednetisr(NETISR_IPX);
553 inq = &ipxintrq;
554 break;
555#endif
556#ifdef NS
557 case ETHERTYPE_NS:
558 schednetisr(NETISR_NS);
559 inq = &nsintrq;
560 break;
561#endif
562#ifdef DECNET
563 case ETHERTYPE_DECNET:
564 schednetisr(NETISR_DECNET);
565 inq = &decnetintrq;
566 break;
567#endif
568#ifdef NETATALK
569 case ETHERTYPE_AT:
570 schednetisr(NETISR_ATALK);
571 inq = &atintrq1;
572 break;
573 case ETHERTYPE_AARP:
574 /* probably this should be done with a NETISR as well */
575 aarpinput((struct arpcom *)ifp, m); /* XXX */
576 return;
577#endif /* NETATALK */
578 default:
579 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
580 ifp->if_noproto++;
581 goto dropanyway;
582 }
583 break;
584 }
585#endif /* INET || NS */
586#ifdef ISO
587 case LLC_ISO_LSAP:
588 switch (l->llc_control) {
589 case LLC_UI:
590 /* LLC_UI_P forbidden in class 1 service */
591 if ((l->llc_dsap == LLC_ISO_LSAP) &&
592 (l->llc_ssap == LLC_ISO_LSAP)) {
593 /* LSAP for ISO */
594 m->m_data += 3; /* XXX */
595 m->m_len -= 3; /* XXX */
596 m->m_pkthdr.len -= 3; /* XXX */
597 M_PREPEND(m, sizeof *fh, M_DONTWAIT);
598 if (m == 0)
599 return;
600 *mtod(m, struct fddi_header *) = *fh;
601 IFDEBUG(D_ETHER)
602 printf("clnp packet");
603 ENDDEBUG
604 schednetisr(NETISR_ISO);
605 inq = &clnlintrq;
606 break;
607 }
608 goto dropanyway;
609
610 case LLC_XID:
611 case LLC_XID_P:
612 if(m->m_len < 6)
613 goto dropanyway;
614 l->llc_window = 0;
615 l->llc_fid = 9;
616 l->llc_class = 1;
617 l->llc_dsap = l->llc_ssap = 0;
618 /* Fall through to */
619 case LLC_TEST:
620 case LLC_TEST_P:
621 {
622 struct sockaddr sa;
623 register struct ether_header *eh;
624 struct arpcom *ac = (struct arpcom *) ifp;
625 int i;
626 u_char c = l->llc_dsap;
627
628 l->llc_dsap = l->llc_ssap;
629 l->llc_ssap = c;
630 if (m->m_flags & (M_BCAST | M_MCAST))
631 bcopy((caddr_t)ac->ac_enaddr,
632 (caddr_t)eh->ether_dhost, 6);
633 sa.sa_family = AF_UNSPEC;
634 sa.sa_len = sizeof(sa);
635 eh = (struct ether_header *)sa.sa_data;
636 for (i = 0; i < 6; i++) {
637 eh->ether_shost[i] = fh->fddi_dhost[i];
638 eh->ether_dhost[i] = fh->fddi_shost[i];
639 }
640 eh->ether_type = 0;
641 ifp->if_output(ifp, m, &sa, NULL);
642 return;
643 }
644 default:
645 m_freem(m);
646 return;
647 }
648 break;
649#endif /* ISO */
650#ifdef LLC
651 case LLC_X25_LSAP:
652 {
653 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
654 if (m == 0)
655 return;
656 if ( !sdl_sethdrif(ifp, fh->fddi_shost, LLC_X25_LSAP,
657 fh->fddi_dhost, LLC_X25_LSAP, 6,
658 mtod(m, struct sdl_hdr *)))
659 panic("ETHER cons addr failure");
660 mtod(m, struct sdl_hdr *)->sdlhdr_len = m->m_pkthdr.len - sizeof(struct sdl_hdr);
661#ifdef LLC_DEBUG
662 printf("llc packet\n");
663#endif /* LLC_DEBUG */
664 schednetisr(NETISR_CCITT);
665 inq = &llcintrq;
666 break;
667 }
668#endif /* LLC */
669
670 default:
671 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
672 ifp->if_noproto++;
673 dropanyway:
674 m_freem(m);
675 return;
676 }
677
678 s = splimp();
679 if (IF_QFULL(inq)) {
680 IF_DROP(inq);
681 m_freem(m);
682 } else
683 IF_ENQUEUE(inq, m);
684 splx(s);
685}
686/*
687 * Perform common duties while attaching to interface list
688 */
689#ifdef __NetBSD__
690#define ifa_next ifa_list.tqe_next
691#endif
692
693void
694fddi_ifattach(ifp)
695 register struct ifnet *ifp;
696{
697 register struct ifaddr *ifa;
698 register struct sockaddr_dl *sdl;
699
700 ifp->if_type = IFT_FDDI;
701 ifp->if_addrlen = 6;
702 ifp->if_hdrlen = 21;
703 ifp->if_mtu = FDDIMTU;
704 ifp->if_baudrate = 100000000;
705#ifdef IFF_NOTRAILERS
706 ifp->if_flags |= IFF_NOTRAILERS;
707#endif
708#if defined(__FreeBSD__)
709 ifa = ifnet_addrs[ifp->if_index - 1];
710 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
711 sdl->sdl_type = IFT_FDDI;
712 sdl->sdl_alen = ifp->if_addrlen;
713 bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
714#elif defined(__NetBSD__)
715 LIST_INIT(&((struct arpcom *)ifp)->ac_multiaddrs);
716 for (ifa = ifp->if_addrlist.tqh_first; ifa != NULL; ifa = ifa->ifa_list.tqe_next)
717#else
718 for (ifa = ifp->if_addrlist; ifa != NULL; ifa = ifa->ifa_next)
719#endif
720#if !defined(__FreeBSD__)
721 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
722 sdl->sdl_family == AF_LINK) {
723 sdl->sdl_type = IFT_FDDI;
724 sdl->sdl_alen = ifp->if_addrlen;
725 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
726 LLADDR(sdl), ifp->if_addrlen);
727 break;
728 }
729#endif
730}
478 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh);
479 if (fh->fddi_dhost[0] & 1) {
480 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost,
481 sizeof(fddibroadcastaddr)) == 0)
482 m->m_flags |= M_BCAST;
483 else
484 m->m_flags |= M_MCAST;
485 ifp->if_imcasts++;
486 } else if ((ifp->if_flags & IFF_PROMISC)
487 && bcmp(((struct arpcom *)ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost,
488 sizeof(fh->fddi_dhost)) != 0) {
489 m_freem(m);
490 return;
491 }
492
493#ifdef M_LINK0
494 /*
495 * If this has a LLC priority of 0, then mark it so upper
496 * layers have a hint that it really came via a FDDI/Ethernet
497 * bridge.
498 */
499 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
500 m->m_flags |= M_LINK0;
501#endif
502
503 l = mtod(m, struct llc *);
504 switch (l->llc_dsap) {
505#if defined(INET) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK)
506 case LLC_SNAP_LSAP:
507 {
508 u_int16_t type;
509 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP)
510 goto dropanyway;
511#ifdef NETATALK
512 if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code,
513 sizeof(at_org_code)) == 0 &&
514 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) {
515 inq = &atintrq2;
516 m_adj( m, sizeof( struct llc ));
517 schednetisr(NETISR_ATALK);
518 break;
519 }
520
521 if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code,
522 sizeof(aarp_org_code)) == 0 &&
523 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) {
524 m_adj( m, sizeof( struct llc ));
525 aarpinput((struct arpcom *)ifp, m); /* XXX */
526 return;
527 }
528#endif /* NETATALK */
529 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0)
530 goto dropanyway;
531 type = ntohs(l->llc_snap.ether_type);
532 m_adj(m, 8);
533 switch (type) {
534#ifdef INET
535 case ETHERTYPE_IP:
536 schednetisr(NETISR_IP);
537 inq = &ipintrq;
538 break;
539
540 case ETHERTYPE_ARP:
541#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
542 schednetisr(NETISR_ARP);
543 inq = &arpintrq;
544 break;
545#else
546 arpinput((struct arpcom *)ifp, m);
547 return;
548#endif
549#endif
550#ifdef IPX
551 case ETHERTYPE_IPX:
552 schednetisr(NETISR_IPX);
553 inq = &ipxintrq;
554 break;
555#endif
556#ifdef NS
557 case ETHERTYPE_NS:
558 schednetisr(NETISR_NS);
559 inq = &nsintrq;
560 break;
561#endif
562#ifdef DECNET
563 case ETHERTYPE_DECNET:
564 schednetisr(NETISR_DECNET);
565 inq = &decnetintrq;
566 break;
567#endif
568#ifdef NETATALK
569 case ETHERTYPE_AT:
570 schednetisr(NETISR_ATALK);
571 inq = &atintrq1;
572 break;
573 case ETHERTYPE_AARP:
574 /* probably this should be done with a NETISR as well */
575 aarpinput((struct arpcom *)ifp, m); /* XXX */
576 return;
577#endif /* NETATALK */
578 default:
579 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
580 ifp->if_noproto++;
581 goto dropanyway;
582 }
583 break;
584 }
585#endif /* INET || NS */
586#ifdef ISO
587 case LLC_ISO_LSAP:
588 switch (l->llc_control) {
589 case LLC_UI:
590 /* LLC_UI_P forbidden in class 1 service */
591 if ((l->llc_dsap == LLC_ISO_LSAP) &&
592 (l->llc_ssap == LLC_ISO_LSAP)) {
593 /* LSAP for ISO */
594 m->m_data += 3; /* XXX */
595 m->m_len -= 3; /* XXX */
596 m->m_pkthdr.len -= 3; /* XXX */
597 M_PREPEND(m, sizeof *fh, M_DONTWAIT);
598 if (m == 0)
599 return;
600 *mtod(m, struct fddi_header *) = *fh;
601 IFDEBUG(D_ETHER)
602 printf("clnp packet");
603 ENDDEBUG
604 schednetisr(NETISR_ISO);
605 inq = &clnlintrq;
606 break;
607 }
608 goto dropanyway;
609
610 case LLC_XID:
611 case LLC_XID_P:
612 if(m->m_len < 6)
613 goto dropanyway;
614 l->llc_window = 0;
615 l->llc_fid = 9;
616 l->llc_class = 1;
617 l->llc_dsap = l->llc_ssap = 0;
618 /* Fall through to */
619 case LLC_TEST:
620 case LLC_TEST_P:
621 {
622 struct sockaddr sa;
623 register struct ether_header *eh;
624 struct arpcom *ac = (struct arpcom *) ifp;
625 int i;
626 u_char c = l->llc_dsap;
627
628 l->llc_dsap = l->llc_ssap;
629 l->llc_ssap = c;
630 if (m->m_flags & (M_BCAST | M_MCAST))
631 bcopy((caddr_t)ac->ac_enaddr,
632 (caddr_t)eh->ether_dhost, 6);
633 sa.sa_family = AF_UNSPEC;
634 sa.sa_len = sizeof(sa);
635 eh = (struct ether_header *)sa.sa_data;
636 for (i = 0; i < 6; i++) {
637 eh->ether_shost[i] = fh->fddi_dhost[i];
638 eh->ether_dhost[i] = fh->fddi_shost[i];
639 }
640 eh->ether_type = 0;
641 ifp->if_output(ifp, m, &sa, NULL);
642 return;
643 }
644 default:
645 m_freem(m);
646 return;
647 }
648 break;
649#endif /* ISO */
650#ifdef LLC
651 case LLC_X25_LSAP:
652 {
653 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
654 if (m == 0)
655 return;
656 if ( !sdl_sethdrif(ifp, fh->fddi_shost, LLC_X25_LSAP,
657 fh->fddi_dhost, LLC_X25_LSAP, 6,
658 mtod(m, struct sdl_hdr *)))
659 panic("ETHER cons addr failure");
660 mtod(m, struct sdl_hdr *)->sdlhdr_len = m->m_pkthdr.len - sizeof(struct sdl_hdr);
661#ifdef LLC_DEBUG
662 printf("llc packet\n");
663#endif /* LLC_DEBUG */
664 schednetisr(NETISR_CCITT);
665 inq = &llcintrq;
666 break;
667 }
668#endif /* LLC */
669
670 default:
671 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
672 ifp->if_noproto++;
673 dropanyway:
674 m_freem(m);
675 return;
676 }
677
678 s = splimp();
679 if (IF_QFULL(inq)) {
680 IF_DROP(inq);
681 m_freem(m);
682 } else
683 IF_ENQUEUE(inq, m);
684 splx(s);
685}
686/*
687 * Perform common duties while attaching to interface list
688 */
689#ifdef __NetBSD__
690#define ifa_next ifa_list.tqe_next
691#endif
692
693void
694fddi_ifattach(ifp)
695 register struct ifnet *ifp;
696{
697 register struct ifaddr *ifa;
698 register struct sockaddr_dl *sdl;
699
700 ifp->if_type = IFT_FDDI;
701 ifp->if_addrlen = 6;
702 ifp->if_hdrlen = 21;
703 ifp->if_mtu = FDDIMTU;
704 ifp->if_baudrate = 100000000;
705#ifdef IFF_NOTRAILERS
706 ifp->if_flags |= IFF_NOTRAILERS;
707#endif
708#if defined(__FreeBSD__)
709 ifa = ifnet_addrs[ifp->if_index - 1];
710 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
711 sdl->sdl_type = IFT_FDDI;
712 sdl->sdl_alen = ifp->if_addrlen;
713 bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
714#elif defined(__NetBSD__)
715 LIST_INIT(&((struct arpcom *)ifp)->ac_multiaddrs);
716 for (ifa = ifp->if_addrlist.tqh_first; ifa != NULL; ifa = ifa->ifa_list.tqe_next)
717#else
718 for (ifa = ifp->if_addrlist; ifa != NULL; ifa = ifa->ifa_next)
719#endif
720#if !defined(__FreeBSD__)
721 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
722 sdl->sdl_family == AF_LINK) {
723 sdl->sdl_type = IFT_FDDI;
724 sdl->sdl_alen = ifp->if_addrlen;
725 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
726 LLADDR(sdl), ifp->if_addrlen);
727 break;
728 }
729#endif
730}