Deleted Added
full compact
if_fddisubr.c (172930) if_fddisubr.c (177599)
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 * $FreeBSD: head/sys/net/if_fddisubr.c 172930 2007-10-24 19:04:04Z rwatson $
36 * $FreeBSD: head/sys/net/if_fddisubr.c 177599 2008-03-25 09:39:02Z ru $
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_inet6.h"
42#include "opt_ipx.h"
43#include "opt_mac.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
48#include <sys/malloc.h>
49#include <sys/mbuf.h>
50#include <sys/module.h>
51#include <sys/socket.h>
52#include <sys/sockio.h>
53
54#include <net/if.h>
55#include <net/if_dl.h>
56#include <net/if_llc.h>
57#include <net/if_types.h>
58
59#include <net/netisr.h>
60#include <net/route.h>
61#include <net/bpf.h>
62#include <net/fddi.h>
63
64#if defined(INET) || defined(INET6)
65#include <netinet/in.h>
66#include <netinet/in_var.h>
67#include <netinet/if_ether.h>
68#endif
69#ifdef INET6
70#include <netinet6/nd6.h>
71#endif
72
73#ifdef IPX
74#include <netipx/ipx.h>
75#include <netipx/ipx_if.h>
76#endif
77
78#ifdef DECNET
79#include <netdnet/dn.h>
80#endif
81
82#ifdef NETATALK
83#include <netatalk/at.h>
84#include <netatalk/at_var.h>
85#include <netatalk/at_extern.h>
86
87extern u_char at_org_code[ 3 ];
88extern u_char aarp_org_code[ 3 ];
89#endif /* NETATALK */
90
91#include <security/mac/mac_framework.h>
92
93static const u_char fddibroadcastaddr[FDDI_ADDR_LEN] =
94 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95
96static int fddi_resolvemulti(struct ifnet *, struct sockaddr **,
97 struct sockaddr *);
98static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
99 struct rtentry *);
100static void fddi_input(struct ifnet *ifp, struct mbuf *m);
101
102#define senderr(e) do { error = (e); goto bad; } while (0)
103
104/*
105 * FDDI output routine.
106 * Encapsulate a packet of type family for the local net.
107 * Use trailer local net encapsulation if enough data in first
108 * packet leaves a multiple of 512 bytes of data in remainder.
109 * Assumes that ifp is actually pointer to arpcom structure.
110 */
111static int
112fddi_output(ifp, m, dst, rt0)
113 struct ifnet *ifp;
114 struct mbuf *m;
115 struct sockaddr *dst;
116 struct rtentry *rt0;
117{
118 u_int16_t type;
119 int loop_copy = 0, error = 0, hdrcmplt = 0;
120 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN];
121 struct fddi_header *fh;
122
123#ifdef MAC
124 error = mac_ifnet_check_transmit(ifp, m);
125 if (error)
126 senderr(error);
127#endif
128
129 if (ifp->if_flags & IFF_MONITOR)
130 senderr(ENETDOWN);
131 if (!((ifp->if_flags & IFF_UP) &&
132 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
133 senderr(ENETDOWN);
134 getmicrotime(&ifp->if_lastchange);
135
136 switch (dst->sa_family) {
137#ifdef INET
138 case AF_INET: {
139 error = arpresolve(ifp, rt0, m, dst, edst);
140 if (error)
141 return (error == EWOULDBLOCK ? 0 : error);
142 type = htons(ETHERTYPE_IP);
143 break;
144 }
145 case AF_ARP:
146 {
147 struct arphdr *ah;
148 ah = mtod(m, struct arphdr *);
149 ah->ar_hrd = htons(ARPHRD_ETHER);
150
151 loop_copy = -1; /* if this is for us, don't do it */
152
153 switch (ntohs(ah->ar_op)) {
154 case ARPOP_REVREQUEST:
155 case ARPOP_REVREPLY:
156 type = htons(ETHERTYPE_REVARP);
157 break;
158 case ARPOP_REQUEST:
159 case ARPOP_REPLY:
160 default:
161 type = htons(ETHERTYPE_ARP);
162 break;
163 }
164
165 if (m->m_flags & M_BCAST)
166 bcopy(ifp->if_broadcastaddr, edst, FDDI_ADDR_LEN);
167 else
168 bcopy(ar_tha(ah), edst, FDDI_ADDR_LEN);
169
170 }
171 break;
172#endif /* INET */
173#ifdef INET6
174 case AF_INET6:
175 error = nd6_storelladdr(ifp, rt0, m, dst, (u_char *)edst);
176 if (error)
177 return (error); /* Something bad happened */
178 type = htons(ETHERTYPE_IPV6);
179 break;
180#endif /* INET6 */
181#ifdef IPX
182 case AF_IPX:
183 type = htons(ETHERTYPE_IPX);
184 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
185 (caddr_t)edst, FDDI_ADDR_LEN);
186 break;
187#endif /* IPX */
188#ifdef NETATALK
189 case AF_APPLETALK: {
190 struct at_ifaddr *aa;
191 if (!aarpresolve(ifp, m, (struct sockaddr_at *)dst, edst))
192 return (0);
193 /*
194 * ifaddr is the first thing in at_ifaddr
195 */
196 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
197 goto bad;
198
199 /*
200 * In the phase 2 case, we need to prepend an mbuf for the llc header.
201 * Since we must preserve the value of m, which is passed to us by
202 * value, we m_copy() the first mbuf, and use it for our llc header.
203 */
204 if (aa->aa_flags & AFA_PHASE2) {
205 struct llc llc;
206
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_inet6.h"
42#include "opt_ipx.h"
43#include "opt_mac.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
48#include <sys/malloc.h>
49#include <sys/mbuf.h>
50#include <sys/module.h>
51#include <sys/socket.h>
52#include <sys/sockio.h>
53
54#include <net/if.h>
55#include <net/if_dl.h>
56#include <net/if_llc.h>
57#include <net/if_types.h>
58
59#include <net/netisr.h>
60#include <net/route.h>
61#include <net/bpf.h>
62#include <net/fddi.h>
63
64#if defined(INET) || defined(INET6)
65#include <netinet/in.h>
66#include <netinet/in_var.h>
67#include <netinet/if_ether.h>
68#endif
69#ifdef INET6
70#include <netinet6/nd6.h>
71#endif
72
73#ifdef IPX
74#include <netipx/ipx.h>
75#include <netipx/ipx_if.h>
76#endif
77
78#ifdef DECNET
79#include <netdnet/dn.h>
80#endif
81
82#ifdef NETATALK
83#include <netatalk/at.h>
84#include <netatalk/at_var.h>
85#include <netatalk/at_extern.h>
86
87extern u_char at_org_code[ 3 ];
88extern u_char aarp_org_code[ 3 ];
89#endif /* NETATALK */
90
91#include <security/mac/mac_framework.h>
92
93static const u_char fddibroadcastaddr[FDDI_ADDR_LEN] =
94 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95
96static int fddi_resolvemulti(struct ifnet *, struct sockaddr **,
97 struct sockaddr *);
98static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
99 struct rtentry *);
100static void fddi_input(struct ifnet *ifp, struct mbuf *m);
101
102#define senderr(e) do { error = (e); goto bad; } while (0)
103
104/*
105 * FDDI output routine.
106 * Encapsulate a packet of type family for the local net.
107 * Use trailer local net encapsulation if enough data in first
108 * packet leaves a multiple of 512 bytes of data in remainder.
109 * Assumes that ifp is actually pointer to arpcom structure.
110 */
111static int
112fddi_output(ifp, m, dst, rt0)
113 struct ifnet *ifp;
114 struct mbuf *m;
115 struct sockaddr *dst;
116 struct rtentry *rt0;
117{
118 u_int16_t type;
119 int loop_copy = 0, error = 0, hdrcmplt = 0;
120 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN];
121 struct fddi_header *fh;
122
123#ifdef MAC
124 error = mac_ifnet_check_transmit(ifp, m);
125 if (error)
126 senderr(error);
127#endif
128
129 if (ifp->if_flags & IFF_MONITOR)
130 senderr(ENETDOWN);
131 if (!((ifp->if_flags & IFF_UP) &&
132 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
133 senderr(ENETDOWN);
134 getmicrotime(&ifp->if_lastchange);
135
136 switch (dst->sa_family) {
137#ifdef INET
138 case AF_INET: {
139 error = arpresolve(ifp, rt0, m, dst, edst);
140 if (error)
141 return (error == EWOULDBLOCK ? 0 : error);
142 type = htons(ETHERTYPE_IP);
143 break;
144 }
145 case AF_ARP:
146 {
147 struct arphdr *ah;
148 ah = mtod(m, struct arphdr *);
149 ah->ar_hrd = htons(ARPHRD_ETHER);
150
151 loop_copy = -1; /* if this is for us, don't do it */
152
153 switch (ntohs(ah->ar_op)) {
154 case ARPOP_REVREQUEST:
155 case ARPOP_REVREPLY:
156 type = htons(ETHERTYPE_REVARP);
157 break;
158 case ARPOP_REQUEST:
159 case ARPOP_REPLY:
160 default:
161 type = htons(ETHERTYPE_ARP);
162 break;
163 }
164
165 if (m->m_flags & M_BCAST)
166 bcopy(ifp->if_broadcastaddr, edst, FDDI_ADDR_LEN);
167 else
168 bcopy(ar_tha(ah), edst, FDDI_ADDR_LEN);
169
170 }
171 break;
172#endif /* INET */
173#ifdef INET6
174 case AF_INET6:
175 error = nd6_storelladdr(ifp, rt0, m, dst, (u_char *)edst);
176 if (error)
177 return (error); /* Something bad happened */
178 type = htons(ETHERTYPE_IPV6);
179 break;
180#endif /* INET6 */
181#ifdef IPX
182 case AF_IPX:
183 type = htons(ETHERTYPE_IPX);
184 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
185 (caddr_t)edst, FDDI_ADDR_LEN);
186 break;
187#endif /* IPX */
188#ifdef NETATALK
189 case AF_APPLETALK: {
190 struct at_ifaddr *aa;
191 if (!aarpresolve(ifp, m, (struct sockaddr_at *)dst, edst))
192 return (0);
193 /*
194 * ifaddr is the first thing in at_ifaddr
195 */
196 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
197 goto bad;
198
199 /*
200 * In the phase 2 case, we need to prepend an mbuf for the llc header.
201 * Since we must preserve the value of m, which is passed to us by
202 * value, we m_copy() the first mbuf, and use it for our llc header.
203 */
204 if (aa->aa_flags & AFA_PHASE2) {
205 struct llc llc;
206
207 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT);
208 if (m == 0)
209 senderr(ENOBUFS);
207 M_PREPEND(m, LLC_SNAPFRAMELEN, M_WAIT);
210 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
211 llc.llc_control = LLC_UI;
212 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code));
213 llc.llc_snap.ether_type = htons(ETHERTYPE_AT);
214 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN);
215 type = 0;
216 } else {
217 type = htons(ETHERTYPE_AT);
218 }
219 break;
220 }
221#endif /* NETATALK */
222
223 case pseudo_AF_HDRCMPLT:
224 {
225 struct ether_header *eh;
226 hdrcmplt = 1;
227 eh = (struct ether_header *)dst->sa_data;
228 bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN);
229 /* FALLTHROUGH */
230 }
231
232 case AF_UNSPEC:
233 {
234 struct ether_header *eh;
235 loop_copy = -1;
236 eh = (struct ether_header *)dst->sa_data;
237 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN);
238 if (*edst & 1)
239 m->m_flags |= (M_BCAST|M_MCAST);
240 type = eh->ether_type;
241 break;
242 }
243
244 case AF_IMPLINK:
245 {
246 fh = mtod(m, struct fddi_header *);
247 error = EPROTONOSUPPORT;
248 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
249 case FDDIFC_LLC_ASYNC: {
250 /* legal priorities are 0 through 7 */
251 if ((fh->fddi_fc & FDDIFC_Z) > 7)
252 goto bad;
253 break;
254 }
255 case FDDIFC_LLC_SYNC: {
256 /* FDDIFC_Z bits reserved, must be zero */
257 if (fh->fddi_fc & FDDIFC_Z)
258 goto bad;
259 break;
260 }
261 case FDDIFC_SMT: {
262 /* FDDIFC_Z bits must be non zero */
263 if ((fh->fddi_fc & FDDIFC_Z) == 0)
264 goto bad;
265 break;
266 }
267 default: {
268 /* anything else is too dangerous */
269 goto bad;
270 }
271 }
272 error = 0;
273 if (fh->fddi_dhost[0] & 1)
274 m->m_flags |= (M_BCAST|M_MCAST);
275 goto queue_it;
276 }
277 default:
278 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
279 senderr(EAFNOSUPPORT);
280 }
281
282 /*
283 * Add LLC header.
284 */
285 if (type != 0) {
286 struct llc *l;
287 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
288 if (m == 0)
289 senderr(ENOBUFS);
290 l = mtod(m, struct llc *);
291 l->llc_control = LLC_UI;
292 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
293 l->llc_snap.org_code[0] =
294 l->llc_snap.org_code[1] =
295 l->llc_snap.org_code[2] = 0;
296 l->llc_snap.ether_type = htons(type);
297 }
298
299 /*
300 * Add local net header. If no space in first mbuf,
301 * allocate another.
302 */
303 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT);
304 if (m == 0)
305 senderr(ENOBUFS);
306 fh = mtod(m, struct fddi_header *);
307 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
308 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN);
309 queue_it:
310 if (hdrcmplt)
311 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN);
312 else
313 bcopy(IF_LLADDR(ifp), (caddr_t)fh->fddi_shost,
314 FDDI_ADDR_LEN);
315
316 /*
317 * If a simplex interface, and the packet is being sent to our
318 * Ethernet address or a broadcast address, loopback a copy.
319 * XXX To make a simplex device behave exactly like a duplex
320 * device, we should copy in the case of sending to our own
321 * ethernet address (thus letting the original actually appear
322 * on the wire). However, we don't do that here for security
323 * reasons and compatibility with the original behavior.
324 */
325 if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
326 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) {
327 struct mbuf *n;
328 n = m_copy(m, 0, (int)M_COPYALL);
329 (void) if_simloop(ifp, n, dst->sa_family,
330 FDDI_HDR_LEN);
331 } else if (bcmp(fh->fddi_dhost, fh->fddi_shost,
332 FDDI_ADDR_LEN) == 0) {
333 (void) if_simloop(ifp, m, dst->sa_family,
334 FDDI_HDR_LEN);
335 return (0); /* XXX */
336 }
337 }
338
339 IFQ_HANDOFF(ifp, m, error);
340 if (error)
341 ifp->if_oerrors++;
342
343 return (error);
344
345bad:
346 ifp->if_oerrors++;
347 if (m)
348 m_freem(m);
349 return (error);
350}
351
352/*
353 * Process a received FDDI packet.
354 */
355static void
356fddi_input(ifp, m)
357 struct ifnet *ifp;
358 struct mbuf *m;
359{
360 int isr;
361 struct llc *l;
362 struct fddi_header *fh;
363
364 /*
365 * Do consistency checks to verify assumptions
366 * made by code past this point.
367 */
368 if ((m->m_flags & M_PKTHDR) == 0) {
369 if_printf(ifp, "discard frame w/o packet header\n");
370 ifp->if_ierrors++;
371 m_freem(m);
372 return;
373 }
374 if (m->m_pkthdr.rcvif == NULL) {
375 if_printf(ifp, "discard frame w/o interface pointer\n");
376 ifp->if_ierrors++;
377 m_freem(m);
378 return;
379 }
380
381 m = m_pullup(m, FDDI_HDR_LEN);
382 if (m == NULL) {
383 ifp->if_ierrors++;
384 goto dropanyway;
385 }
386 fh = mtod(m, struct fddi_header *);
387 m->m_pkthdr.header = (void *)fh;
388
389 /*
390 * Discard packet if interface is not up.
391 */
392 if (!((ifp->if_flags & IFF_UP) &&
393 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
394 goto dropanyway;
395
396 /*
397 * Give bpf a chance at the packet.
398 */
399 BPF_MTAP(ifp, m);
400
401 /*
402 * Interface marked for monitoring; discard packet.
403 */
404 if (ifp->if_flags & IFF_MONITOR) {
405 m_freem(m);
406 return;
407 }
408
409#ifdef MAC
410 mac_ifnet_create_mbuf(ifp, m);
411#endif
412
413 /*
414 * Update interface statistics.
415 */
416 ifp->if_ibytes += m->m_pkthdr.len;
417 getmicrotime(&ifp->if_lastchange);
418
419 /*
420 * Discard non local unicast packets when interface
421 * is in promiscuous mode.
422 */
423 if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) &&
424 (bcmp(IF_LLADDR(ifp), (caddr_t)fh->fddi_dhost,
425 FDDI_ADDR_LEN) != 0))
426 goto dropanyway;
427
428 /*
429 * Set mbuf flags for bcast/mcast.
430 */
431 if (fh->fddi_dhost[0] & 1) {
432 if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost,
433 FDDI_ADDR_LEN) == 0)
434 m->m_flags |= M_BCAST;
435 else
436 m->m_flags |= M_MCAST;
437 ifp->if_imcasts++;
438 }
439
440#ifdef M_LINK0
441 /*
442 * If this has a LLC priority of 0, then mark it so upper
443 * layers have a hint that it really came via a FDDI/Ethernet
444 * bridge.
445 */
446 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
447 m->m_flags |= M_LINK0;
448#endif
449
450 /* Strip off FDDI header. */
451 m_adj(m, FDDI_HDR_LEN);
452
453 m = m_pullup(m, LLC_SNAPFRAMELEN);
454 if (m == 0) {
455 ifp->if_ierrors++;
456 goto dropanyway;
457 }
458 l = mtod(m, struct llc *);
459
460 switch (l->llc_dsap) {
461 case LLC_SNAP_LSAP:
462 {
463 u_int16_t type;
464 if ((l->llc_control != LLC_UI) ||
465 (l->llc_ssap != LLC_SNAP_LSAP)) {
466 ifp->if_noproto++;
467 goto dropanyway;
468 }
469#ifdef NETATALK
470 if (bcmp(&(l->llc_snap.org_code)[0], at_org_code,
471 sizeof(at_org_code)) == 0 &&
472 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) {
473 isr = NETISR_ATALK2;
474 m_adj(m, LLC_SNAPFRAMELEN);
475 break;
476 }
477
478 if (bcmp(&(l->llc_snap.org_code)[0], aarp_org_code,
479 sizeof(aarp_org_code)) == 0 &&
480 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) {
481 m_adj(m, LLC_SNAPFRAMELEN);
482 isr = NETISR_AARP;
483 break;
484 }
485#endif /* NETATALK */
486 if (l->llc_snap.org_code[0] != 0 ||
487 l->llc_snap.org_code[1] != 0 ||
488 l->llc_snap.org_code[2] != 0) {
489 ifp->if_noproto++;
490 goto dropanyway;
491 }
492
493 type = ntohs(l->llc_snap.ether_type);
494 m_adj(m, LLC_SNAPFRAMELEN);
495
496 switch (type) {
497#ifdef INET
498 case ETHERTYPE_IP:
499 if ((m = ip_fastforward(m)) == NULL)
500 return;
501 isr = NETISR_IP;
502 break;
503
504 case ETHERTYPE_ARP:
505 if (ifp->if_flags & IFF_NOARP)
506 goto dropanyway;
507 isr = NETISR_ARP;
508 break;
509#endif
510#ifdef INET6
511 case ETHERTYPE_IPV6:
512 isr = NETISR_IPV6;
513 break;
514#endif
515#ifdef IPX
516 case ETHERTYPE_IPX:
517 isr = NETISR_IPX;
518 break;
519#endif
520#ifdef DECNET
521 case ETHERTYPE_DECNET:
522 isr = NETISR_DECNET;
523 break;
524#endif
525#ifdef NETATALK
526 case ETHERTYPE_AT:
527 isr = NETISR_ATALK1;
528 break;
529 case ETHERTYPE_AARP:
530 isr = NETISR_AARP;
531 break;
532#endif /* NETATALK */
533 default:
534 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
535 ifp->if_noproto++;
536 goto dropanyway;
537 }
538 break;
539 }
540
541 default:
542 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
543 ifp->if_noproto++;
544 goto dropanyway;
545 }
546 netisr_dispatch(isr, m);
547 return;
548
549dropanyway:
550 ifp->if_iqdrops++;
551 if (m)
552 m_freem(m);
553 return;
554}
555
556/*
557 * Perform common duties while attaching to interface list
558 */
559void
560fddi_ifattach(ifp, lla, bpf)
561 struct ifnet *ifp;
562 const u_int8_t *lla;
563 int bpf;
564{
565 struct ifaddr *ifa;
566 struct sockaddr_dl *sdl;
567
568 ifp->if_type = IFT_FDDI;
569 ifp->if_addrlen = FDDI_ADDR_LEN;
570 ifp->if_hdrlen = 21;
571
572 if_attach(ifp); /* Must be called before additional assignments */
573
574 ifp->if_mtu = FDDIMTU;
575 ifp->if_output = fddi_output;
576 ifp->if_input = fddi_input;
577 ifp->if_resolvemulti = fddi_resolvemulti;
578 ifp->if_broadcastaddr = fddibroadcastaddr;
579 ifp->if_baudrate = 100000000;
580#ifdef IFF_NOTRAILERS
581 ifp->if_flags |= IFF_NOTRAILERS;
582#endif
583 ifa = ifp->if_addr;
584 KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
585
586 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
587 sdl->sdl_type = IFT_FDDI;
588 sdl->sdl_alen = ifp->if_addrlen;
589 bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
590
591 if (bpf)
592 bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN);
593
594 return;
595}
596
597void
598fddi_ifdetach(ifp, bpf)
599 struct ifnet *ifp;
600 int bpf;
601{
602
603 if (bpf)
604 bpfdetach(ifp);
605
606 if_detach(ifp);
607
608 return;
609}
610
611int
612fddi_ioctl (ifp, command, data)
613 struct ifnet *ifp;
614 int command;
615 caddr_t data;
616{
617 struct ifaddr *ifa;
618 struct ifreq *ifr;
619 int error;
620
621 ifa = (struct ifaddr *) data;
622 ifr = (struct ifreq *) data;
623 error = 0;
624
625 switch (command) {
626 case SIOCSIFADDR:
627 ifp->if_flags |= IFF_UP;
628
629 switch (ifa->ifa_addr->sa_family) {
630#ifdef INET
631 case AF_INET: /* before arpwhohas */
632 ifp->if_init(ifp->if_softc);
633 arp_ifinit(ifp, ifa);
634 break;
635#endif
636#ifdef IPX
637 /*
638 * XXX - This code is probably wrong
639 */
640 case AF_IPX: {
641 struct ipx_addr *ina;
642
643 ina = &(IA_SIPX(ifa)->sipx_addr);
644
645 if (ipx_nullhost(*ina)) {
646 ina->x_host = *(union ipx_host *)
647 IF_LLADDR(ifp);
648 } else {
649 bcopy((caddr_t) ina->x_host.c_host,
650 (caddr_t) IF_LLADDR(ifp),
651 ETHER_ADDR_LEN);
652 }
653
654 /*
655 * Set new address
656 */
657 ifp->if_init(ifp->if_softc);
658 }
659 break;
660#endif
661 default:
662 ifp->if_init(ifp->if_softc);
663 break;
664 }
665 break;
666 case SIOCGIFADDR: {
667 struct sockaddr *sa;
668
669 sa = (struct sockaddr *) & ifr->ifr_data;
670 bcopy(IF_LLADDR(ifp),
671 (caddr_t) sa->sa_data, FDDI_ADDR_LEN);
672
673 }
674 break;
675 case SIOCSIFMTU:
676 /*
677 * Set the interface MTU.
678 */
679 if (ifr->ifr_mtu > FDDIMTU) {
680 error = EINVAL;
681 } else {
682 ifp->if_mtu = ifr->ifr_mtu;
683 }
684 break;
685 default:
686 error = EINVAL;
687 break;
688 }
689
690 return (error);
691}
692
693static int
694fddi_resolvemulti(ifp, llsa, sa)
695 struct ifnet *ifp;
696 struct sockaddr **llsa;
697 struct sockaddr *sa;
698{
699 struct sockaddr_dl *sdl;
700 struct sockaddr_in *sin;
701#ifdef INET6
702 struct sockaddr_in6 *sin6;
703#endif
704 u_char *e_addr;
705
706 switch(sa->sa_family) {
707 case AF_LINK:
708 /*
709 * No mapping needed. Just check that it's a valid MC address.
710 */
711 sdl = (struct sockaddr_dl *)sa;
712 e_addr = LLADDR(sdl);
713 if ((e_addr[0] & 1) != 1)
714 return (EADDRNOTAVAIL);
715 *llsa = 0;
716 return (0);
717
718#ifdef INET
719 case AF_INET:
720 sin = (struct sockaddr_in *)sa;
721 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
722 return (EADDRNOTAVAIL);
723 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
724 M_NOWAIT | M_ZERO);
725 if (sdl == NULL)
726 return (ENOMEM);
727 sdl->sdl_len = sizeof *sdl;
728 sdl->sdl_family = AF_LINK;
729 sdl->sdl_index = ifp->if_index;
730 sdl->sdl_type = IFT_FDDI;
731 sdl->sdl_nlen = 0;
732 sdl->sdl_alen = FDDI_ADDR_LEN;
733 sdl->sdl_slen = 0;
734 e_addr = LLADDR(sdl);
735 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
736 *llsa = (struct sockaddr *)sdl;
737 return (0);
738#endif
739#ifdef INET6
740 case AF_INET6:
741 sin6 = (struct sockaddr_in6 *)sa;
742 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
743 /*
744 * An IP6 address of 0 means listen to all
745 * of the Ethernet multicast address used for IP6.
746 * (This is used for multicast routers.)
747 */
748 ifp->if_flags |= IFF_ALLMULTI;
749 *llsa = 0;
750 return (0);
751 }
752 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
753 return (EADDRNOTAVAIL);
754 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
755 M_NOWAIT | M_ZERO);
756 if (sdl == NULL)
757 return (ENOMEM);
758 sdl->sdl_len = sizeof *sdl;
759 sdl->sdl_family = AF_LINK;
760 sdl->sdl_index = ifp->if_index;
761 sdl->sdl_type = IFT_FDDI;
762 sdl->sdl_nlen = 0;
763 sdl->sdl_alen = FDDI_ADDR_LEN;
764 sdl->sdl_slen = 0;
765 e_addr = LLADDR(sdl);
766 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
767 *llsa = (struct sockaddr *)sdl;
768 return (0);
769#endif
770
771 default:
772 /*
773 * Well, the text isn't quite right, but it's the name
774 * that counts...
775 */
776 return (EAFNOSUPPORT);
777 }
778
779 return (0);
780}
781
782static moduledata_t fddi_mod = {
783 "fddi", /* module name */
784 NULL, /* event handler */
785 0 /* extra data */
786};
787
788DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
789MODULE_VERSION(fddi, 1);
208 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
209 llc.llc_control = LLC_UI;
210 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code));
211 llc.llc_snap.ether_type = htons(ETHERTYPE_AT);
212 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN);
213 type = 0;
214 } else {
215 type = htons(ETHERTYPE_AT);
216 }
217 break;
218 }
219#endif /* NETATALK */
220
221 case pseudo_AF_HDRCMPLT:
222 {
223 struct ether_header *eh;
224 hdrcmplt = 1;
225 eh = (struct ether_header *)dst->sa_data;
226 bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN);
227 /* FALLTHROUGH */
228 }
229
230 case AF_UNSPEC:
231 {
232 struct ether_header *eh;
233 loop_copy = -1;
234 eh = (struct ether_header *)dst->sa_data;
235 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN);
236 if (*edst & 1)
237 m->m_flags |= (M_BCAST|M_MCAST);
238 type = eh->ether_type;
239 break;
240 }
241
242 case AF_IMPLINK:
243 {
244 fh = mtod(m, struct fddi_header *);
245 error = EPROTONOSUPPORT;
246 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
247 case FDDIFC_LLC_ASYNC: {
248 /* legal priorities are 0 through 7 */
249 if ((fh->fddi_fc & FDDIFC_Z) > 7)
250 goto bad;
251 break;
252 }
253 case FDDIFC_LLC_SYNC: {
254 /* FDDIFC_Z bits reserved, must be zero */
255 if (fh->fddi_fc & FDDIFC_Z)
256 goto bad;
257 break;
258 }
259 case FDDIFC_SMT: {
260 /* FDDIFC_Z bits must be non zero */
261 if ((fh->fddi_fc & FDDIFC_Z) == 0)
262 goto bad;
263 break;
264 }
265 default: {
266 /* anything else is too dangerous */
267 goto bad;
268 }
269 }
270 error = 0;
271 if (fh->fddi_dhost[0] & 1)
272 m->m_flags |= (M_BCAST|M_MCAST);
273 goto queue_it;
274 }
275 default:
276 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
277 senderr(EAFNOSUPPORT);
278 }
279
280 /*
281 * Add LLC header.
282 */
283 if (type != 0) {
284 struct llc *l;
285 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
286 if (m == 0)
287 senderr(ENOBUFS);
288 l = mtod(m, struct llc *);
289 l->llc_control = LLC_UI;
290 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
291 l->llc_snap.org_code[0] =
292 l->llc_snap.org_code[1] =
293 l->llc_snap.org_code[2] = 0;
294 l->llc_snap.ether_type = htons(type);
295 }
296
297 /*
298 * Add local net header. If no space in first mbuf,
299 * allocate another.
300 */
301 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT);
302 if (m == 0)
303 senderr(ENOBUFS);
304 fh = mtod(m, struct fddi_header *);
305 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
306 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN);
307 queue_it:
308 if (hdrcmplt)
309 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN);
310 else
311 bcopy(IF_LLADDR(ifp), (caddr_t)fh->fddi_shost,
312 FDDI_ADDR_LEN);
313
314 /*
315 * If a simplex interface, and the packet is being sent to our
316 * Ethernet address or a broadcast address, loopback a copy.
317 * XXX To make a simplex device behave exactly like a duplex
318 * device, we should copy in the case of sending to our own
319 * ethernet address (thus letting the original actually appear
320 * on the wire). However, we don't do that here for security
321 * reasons and compatibility with the original behavior.
322 */
323 if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
324 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) {
325 struct mbuf *n;
326 n = m_copy(m, 0, (int)M_COPYALL);
327 (void) if_simloop(ifp, n, dst->sa_family,
328 FDDI_HDR_LEN);
329 } else if (bcmp(fh->fddi_dhost, fh->fddi_shost,
330 FDDI_ADDR_LEN) == 0) {
331 (void) if_simloop(ifp, m, dst->sa_family,
332 FDDI_HDR_LEN);
333 return (0); /* XXX */
334 }
335 }
336
337 IFQ_HANDOFF(ifp, m, error);
338 if (error)
339 ifp->if_oerrors++;
340
341 return (error);
342
343bad:
344 ifp->if_oerrors++;
345 if (m)
346 m_freem(m);
347 return (error);
348}
349
350/*
351 * Process a received FDDI packet.
352 */
353static void
354fddi_input(ifp, m)
355 struct ifnet *ifp;
356 struct mbuf *m;
357{
358 int isr;
359 struct llc *l;
360 struct fddi_header *fh;
361
362 /*
363 * Do consistency checks to verify assumptions
364 * made by code past this point.
365 */
366 if ((m->m_flags & M_PKTHDR) == 0) {
367 if_printf(ifp, "discard frame w/o packet header\n");
368 ifp->if_ierrors++;
369 m_freem(m);
370 return;
371 }
372 if (m->m_pkthdr.rcvif == NULL) {
373 if_printf(ifp, "discard frame w/o interface pointer\n");
374 ifp->if_ierrors++;
375 m_freem(m);
376 return;
377 }
378
379 m = m_pullup(m, FDDI_HDR_LEN);
380 if (m == NULL) {
381 ifp->if_ierrors++;
382 goto dropanyway;
383 }
384 fh = mtod(m, struct fddi_header *);
385 m->m_pkthdr.header = (void *)fh;
386
387 /*
388 * Discard packet if interface is not up.
389 */
390 if (!((ifp->if_flags & IFF_UP) &&
391 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
392 goto dropanyway;
393
394 /*
395 * Give bpf a chance at the packet.
396 */
397 BPF_MTAP(ifp, m);
398
399 /*
400 * Interface marked for monitoring; discard packet.
401 */
402 if (ifp->if_flags & IFF_MONITOR) {
403 m_freem(m);
404 return;
405 }
406
407#ifdef MAC
408 mac_ifnet_create_mbuf(ifp, m);
409#endif
410
411 /*
412 * Update interface statistics.
413 */
414 ifp->if_ibytes += m->m_pkthdr.len;
415 getmicrotime(&ifp->if_lastchange);
416
417 /*
418 * Discard non local unicast packets when interface
419 * is in promiscuous mode.
420 */
421 if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) &&
422 (bcmp(IF_LLADDR(ifp), (caddr_t)fh->fddi_dhost,
423 FDDI_ADDR_LEN) != 0))
424 goto dropanyway;
425
426 /*
427 * Set mbuf flags for bcast/mcast.
428 */
429 if (fh->fddi_dhost[0] & 1) {
430 if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost,
431 FDDI_ADDR_LEN) == 0)
432 m->m_flags |= M_BCAST;
433 else
434 m->m_flags |= M_MCAST;
435 ifp->if_imcasts++;
436 }
437
438#ifdef M_LINK0
439 /*
440 * If this has a LLC priority of 0, then mark it so upper
441 * layers have a hint that it really came via a FDDI/Ethernet
442 * bridge.
443 */
444 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
445 m->m_flags |= M_LINK0;
446#endif
447
448 /* Strip off FDDI header. */
449 m_adj(m, FDDI_HDR_LEN);
450
451 m = m_pullup(m, LLC_SNAPFRAMELEN);
452 if (m == 0) {
453 ifp->if_ierrors++;
454 goto dropanyway;
455 }
456 l = mtod(m, struct llc *);
457
458 switch (l->llc_dsap) {
459 case LLC_SNAP_LSAP:
460 {
461 u_int16_t type;
462 if ((l->llc_control != LLC_UI) ||
463 (l->llc_ssap != LLC_SNAP_LSAP)) {
464 ifp->if_noproto++;
465 goto dropanyway;
466 }
467#ifdef NETATALK
468 if (bcmp(&(l->llc_snap.org_code)[0], at_org_code,
469 sizeof(at_org_code)) == 0 &&
470 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) {
471 isr = NETISR_ATALK2;
472 m_adj(m, LLC_SNAPFRAMELEN);
473 break;
474 }
475
476 if (bcmp(&(l->llc_snap.org_code)[0], aarp_org_code,
477 sizeof(aarp_org_code)) == 0 &&
478 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) {
479 m_adj(m, LLC_SNAPFRAMELEN);
480 isr = NETISR_AARP;
481 break;
482 }
483#endif /* NETATALK */
484 if (l->llc_snap.org_code[0] != 0 ||
485 l->llc_snap.org_code[1] != 0 ||
486 l->llc_snap.org_code[2] != 0) {
487 ifp->if_noproto++;
488 goto dropanyway;
489 }
490
491 type = ntohs(l->llc_snap.ether_type);
492 m_adj(m, LLC_SNAPFRAMELEN);
493
494 switch (type) {
495#ifdef INET
496 case ETHERTYPE_IP:
497 if ((m = ip_fastforward(m)) == NULL)
498 return;
499 isr = NETISR_IP;
500 break;
501
502 case ETHERTYPE_ARP:
503 if (ifp->if_flags & IFF_NOARP)
504 goto dropanyway;
505 isr = NETISR_ARP;
506 break;
507#endif
508#ifdef INET6
509 case ETHERTYPE_IPV6:
510 isr = NETISR_IPV6;
511 break;
512#endif
513#ifdef IPX
514 case ETHERTYPE_IPX:
515 isr = NETISR_IPX;
516 break;
517#endif
518#ifdef DECNET
519 case ETHERTYPE_DECNET:
520 isr = NETISR_DECNET;
521 break;
522#endif
523#ifdef NETATALK
524 case ETHERTYPE_AT:
525 isr = NETISR_ATALK1;
526 break;
527 case ETHERTYPE_AARP:
528 isr = NETISR_AARP;
529 break;
530#endif /* NETATALK */
531 default:
532 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
533 ifp->if_noproto++;
534 goto dropanyway;
535 }
536 break;
537 }
538
539 default:
540 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
541 ifp->if_noproto++;
542 goto dropanyway;
543 }
544 netisr_dispatch(isr, m);
545 return;
546
547dropanyway:
548 ifp->if_iqdrops++;
549 if (m)
550 m_freem(m);
551 return;
552}
553
554/*
555 * Perform common duties while attaching to interface list
556 */
557void
558fddi_ifattach(ifp, lla, bpf)
559 struct ifnet *ifp;
560 const u_int8_t *lla;
561 int bpf;
562{
563 struct ifaddr *ifa;
564 struct sockaddr_dl *sdl;
565
566 ifp->if_type = IFT_FDDI;
567 ifp->if_addrlen = FDDI_ADDR_LEN;
568 ifp->if_hdrlen = 21;
569
570 if_attach(ifp); /* Must be called before additional assignments */
571
572 ifp->if_mtu = FDDIMTU;
573 ifp->if_output = fddi_output;
574 ifp->if_input = fddi_input;
575 ifp->if_resolvemulti = fddi_resolvemulti;
576 ifp->if_broadcastaddr = fddibroadcastaddr;
577 ifp->if_baudrate = 100000000;
578#ifdef IFF_NOTRAILERS
579 ifp->if_flags |= IFF_NOTRAILERS;
580#endif
581 ifa = ifp->if_addr;
582 KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
583
584 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
585 sdl->sdl_type = IFT_FDDI;
586 sdl->sdl_alen = ifp->if_addrlen;
587 bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
588
589 if (bpf)
590 bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN);
591
592 return;
593}
594
595void
596fddi_ifdetach(ifp, bpf)
597 struct ifnet *ifp;
598 int bpf;
599{
600
601 if (bpf)
602 bpfdetach(ifp);
603
604 if_detach(ifp);
605
606 return;
607}
608
609int
610fddi_ioctl (ifp, command, data)
611 struct ifnet *ifp;
612 int command;
613 caddr_t data;
614{
615 struct ifaddr *ifa;
616 struct ifreq *ifr;
617 int error;
618
619 ifa = (struct ifaddr *) data;
620 ifr = (struct ifreq *) data;
621 error = 0;
622
623 switch (command) {
624 case SIOCSIFADDR:
625 ifp->if_flags |= IFF_UP;
626
627 switch (ifa->ifa_addr->sa_family) {
628#ifdef INET
629 case AF_INET: /* before arpwhohas */
630 ifp->if_init(ifp->if_softc);
631 arp_ifinit(ifp, ifa);
632 break;
633#endif
634#ifdef IPX
635 /*
636 * XXX - This code is probably wrong
637 */
638 case AF_IPX: {
639 struct ipx_addr *ina;
640
641 ina = &(IA_SIPX(ifa)->sipx_addr);
642
643 if (ipx_nullhost(*ina)) {
644 ina->x_host = *(union ipx_host *)
645 IF_LLADDR(ifp);
646 } else {
647 bcopy((caddr_t) ina->x_host.c_host,
648 (caddr_t) IF_LLADDR(ifp),
649 ETHER_ADDR_LEN);
650 }
651
652 /*
653 * Set new address
654 */
655 ifp->if_init(ifp->if_softc);
656 }
657 break;
658#endif
659 default:
660 ifp->if_init(ifp->if_softc);
661 break;
662 }
663 break;
664 case SIOCGIFADDR: {
665 struct sockaddr *sa;
666
667 sa = (struct sockaddr *) & ifr->ifr_data;
668 bcopy(IF_LLADDR(ifp),
669 (caddr_t) sa->sa_data, FDDI_ADDR_LEN);
670
671 }
672 break;
673 case SIOCSIFMTU:
674 /*
675 * Set the interface MTU.
676 */
677 if (ifr->ifr_mtu > FDDIMTU) {
678 error = EINVAL;
679 } else {
680 ifp->if_mtu = ifr->ifr_mtu;
681 }
682 break;
683 default:
684 error = EINVAL;
685 break;
686 }
687
688 return (error);
689}
690
691static int
692fddi_resolvemulti(ifp, llsa, sa)
693 struct ifnet *ifp;
694 struct sockaddr **llsa;
695 struct sockaddr *sa;
696{
697 struct sockaddr_dl *sdl;
698 struct sockaddr_in *sin;
699#ifdef INET6
700 struct sockaddr_in6 *sin6;
701#endif
702 u_char *e_addr;
703
704 switch(sa->sa_family) {
705 case AF_LINK:
706 /*
707 * No mapping needed. Just check that it's a valid MC address.
708 */
709 sdl = (struct sockaddr_dl *)sa;
710 e_addr = LLADDR(sdl);
711 if ((e_addr[0] & 1) != 1)
712 return (EADDRNOTAVAIL);
713 *llsa = 0;
714 return (0);
715
716#ifdef INET
717 case AF_INET:
718 sin = (struct sockaddr_in *)sa;
719 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
720 return (EADDRNOTAVAIL);
721 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
722 M_NOWAIT | M_ZERO);
723 if (sdl == NULL)
724 return (ENOMEM);
725 sdl->sdl_len = sizeof *sdl;
726 sdl->sdl_family = AF_LINK;
727 sdl->sdl_index = ifp->if_index;
728 sdl->sdl_type = IFT_FDDI;
729 sdl->sdl_nlen = 0;
730 sdl->sdl_alen = FDDI_ADDR_LEN;
731 sdl->sdl_slen = 0;
732 e_addr = LLADDR(sdl);
733 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
734 *llsa = (struct sockaddr *)sdl;
735 return (0);
736#endif
737#ifdef INET6
738 case AF_INET6:
739 sin6 = (struct sockaddr_in6 *)sa;
740 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
741 /*
742 * An IP6 address of 0 means listen to all
743 * of the Ethernet multicast address used for IP6.
744 * (This is used for multicast routers.)
745 */
746 ifp->if_flags |= IFF_ALLMULTI;
747 *llsa = 0;
748 return (0);
749 }
750 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
751 return (EADDRNOTAVAIL);
752 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
753 M_NOWAIT | M_ZERO);
754 if (sdl == NULL)
755 return (ENOMEM);
756 sdl->sdl_len = sizeof *sdl;
757 sdl->sdl_family = AF_LINK;
758 sdl->sdl_index = ifp->if_index;
759 sdl->sdl_type = IFT_FDDI;
760 sdl->sdl_nlen = 0;
761 sdl->sdl_alen = FDDI_ADDR_LEN;
762 sdl->sdl_slen = 0;
763 e_addr = LLADDR(sdl);
764 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
765 *llsa = (struct sockaddr *)sdl;
766 return (0);
767#endif
768
769 default:
770 /*
771 * Well, the text isn't quite right, but it's the name
772 * that counts...
773 */
774 return (EAFNOSUPPORT);
775 }
776
777 return (0);
778}
779
780static moduledata_t fddi_mod = {
781 "fddi", /* module name */
782 NULL, /* event handler */
783 0 /* extra data */
784};
785
786DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
787MODULE_VERSION(fddi, 1);