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