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