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