]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/net/if_fddisubr.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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_dl.h>
55 #include <net/if_llc.h>
56 #include <net/if_types.h>
57 #include <net/if_llatbl.h>
58
59 #include <net/ethernet.h>
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
88 extern u_char   at_org_code[ 3 ];
89 extern u_char   aarp_org_code[ 3 ];
90 #endif /* NETATALK */
91
92 #include <security/mac/mac_framework.h>
93
94 static const u_char fddibroadcastaddr[FDDI_ADDR_LEN] =
95                         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96
97 static int fddi_resolvemulti(struct ifnet *, struct sockaddr **,
98                               struct sockaddr *);
99 static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
100                        struct route *); 
101 static void fddi_input(struct ifnet *ifp, struct mbuf *m);
102
103 #define senderr(e)      do { error = (e); goto bad; } while (0)
104
105 /*
106  * FDDI output routine.
107  * Encapsulate a packet of type family for the local net.
108  * Use trailer local net encapsulation if enough data in first
109  * packet leaves a multiple of 512 bytes of data in remainder.
110  * Assumes that ifp is actually pointer to arpcom structure.
111  */
112 static int
113 fddi_output(ifp, m, dst, ro)
114         struct ifnet *ifp;
115         struct mbuf *m;
116         struct sockaddr *dst;
117         struct route *ro;
118 {
119         u_int16_t type;
120         int loop_copy = 0, error = 0, hdrcmplt = 0;
121         u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN];
122         struct fddi_header *fh;
123 #if defined(INET) || defined(INET6)
124         struct llentry *lle;
125 #endif
126
127 #ifdef MAC
128         error = mac_ifnet_check_transmit(ifp, m);
129         if (error)
130                 senderr(error);
131 #endif
132
133         if (ifp->if_flags & IFF_MONITOR)
134                 senderr(ENETDOWN);
135         if (!((ifp->if_flags & IFF_UP) &&
136             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
137                 senderr(ENETDOWN);
138         getmicrotime(&ifp->if_lastchange);
139
140         switch (dst->sa_family) {
141 #ifdef INET
142         case AF_INET: {
143                 struct rtentry *rt0 = NULL;
144
145                 if (ro != NULL)
146                         rt0 = ro->ro_rt;
147                 error = arpresolve(ifp, rt0, m, dst, edst, &lle);
148                 if (error)
149                         return (error == EWOULDBLOCK ? 0 : error);
150                 type = htons(ETHERTYPE_IP);
151                 break;
152         }
153         case AF_ARP:
154         {
155                 struct arphdr *ah;
156                 ah = mtod(m, struct arphdr *);
157                 ah->ar_hrd = htons(ARPHRD_ETHER);
158
159                 loop_copy = -1; /* if this is for us, don't do it */
160
161                 switch (ntohs(ah->ar_op)) {
162                 case ARPOP_REVREQUEST:
163                 case ARPOP_REVREPLY:
164                         type = htons(ETHERTYPE_REVARP);
165                         break;
166                 case ARPOP_REQUEST:
167                 case ARPOP_REPLY:
168                 default:
169                         type = htons(ETHERTYPE_ARP);
170                         break;
171                 }
172
173                 if (m->m_flags & M_BCAST)
174                         bcopy(ifp->if_broadcastaddr, edst, FDDI_ADDR_LEN);
175                 else
176                         bcopy(ar_tha(ah), edst, FDDI_ADDR_LEN);
177
178         }
179         break;
180 #endif /* INET */
181 #ifdef INET6
182         case AF_INET6:
183                 error = nd6_storelladdr(ifp, m, dst, (u_char *)edst, &lle);
184                 if (error)
185                         return (error); /* Something bad happened */
186                 type = htons(ETHERTYPE_IPV6);
187                 break;
188 #endif /* INET6 */
189 #ifdef IPX
190         case AF_IPX:
191                 type = htons(ETHERTYPE_IPX);
192                 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
193                     (caddr_t)edst, FDDI_ADDR_LEN);
194                 break;
195 #endif /* IPX */
196 #ifdef NETATALK
197         case AF_APPLETALK: {
198             struct at_ifaddr *aa;
199             if (!aarpresolve(ifp, m, (struct sockaddr_at *)dst, edst))
200                 return (0);
201             /*
202              * ifaddr is the first thing in at_ifaddr
203              */
204             if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
205                 goto bad;
206             
207             /*
208              * In the phase 2 case, we need to prepend an mbuf for the llc header.
209              * Since we must preserve the value of m, which is passed to us by
210              * value, we m_copy() the first mbuf, and use it for our llc header.
211              */
212             if (aa->aa_flags & AFA_PHASE2) {
213                 struct llc llc;
214
215                 M_PREPEND(m, LLC_SNAPFRAMELEN, M_WAIT);
216                 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
217                 llc.llc_control = LLC_UI;
218                 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code));
219                 llc.llc_snap.ether_type = htons(ETHERTYPE_AT);
220                 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN);
221                 type = 0;
222             } else {
223                 type = htons(ETHERTYPE_AT);
224             }
225             ifa_free(&aa->aa_ifa);
226             break;
227         }
228 #endif /* NETATALK */
229
230         case pseudo_AF_HDRCMPLT:
231         {
232                 struct ether_header *eh;
233                 hdrcmplt = 1;
234                 eh = (struct ether_header *)dst->sa_data;
235                 bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN);
236                 /* FALLTHROUGH */
237         }
238
239         case AF_UNSPEC:
240         {
241                 struct ether_header *eh;
242                 loop_copy = -1;
243                 eh = (struct ether_header *)dst->sa_data;
244                 bcopy((caddr_t)eh->ether_dhost, (caddr_t)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_DONTWAIT);
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_DONTWAIT);
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         m->m_pkthdr.header = (void *)fh;
395
396         /*
397          * Discard packet if interface is not up.
398          */
399         if (!((ifp->if_flags & IFF_UP) &&
400             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
401                 goto dropanyway;
402
403         /*
404          * Give bpf a chance at the packet.
405          */
406         BPF_MTAP(ifp, m);
407
408         /*
409          * Interface marked for monitoring; discard packet.
410          */
411         if (ifp->if_flags & IFF_MONITOR) {
412                 m_freem(m);
413                 return;
414         }
415
416 #ifdef MAC
417         mac_ifnet_create_mbuf(ifp, m);
418 #endif
419
420         /*
421          * Update interface statistics.
422          */
423         ifp->if_ibytes += m->m_pkthdr.len;
424         getmicrotime(&ifp->if_lastchange);
425
426         /*
427          * Discard non local unicast packets when interface
428          * is in promiscuous mode.
429          */
430         if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) &&
431             (bcmp(IF_LLADDR(ifp), (caddr_t)fh->fddi_dhost,
432              FDDI_ADDR_LEN) != 0))
433                 goto dropanyway;
434
435         /*
436          * Set mbuf flags for bcast/mcast.
437          */
438         if (fh->fddi_dhost[0] & 1) {
439                 if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost,
440                     FDDI_ADDR_LEN) == 0)
441                         m->m_flags |= M_BCAST;
442                 else
443                         m->m_flags |= M_MCAST;
444                 ifp->if_imcasts++;
445         }
446
447 #ifdef M_LINK0
448         /*
449          * If this has a LLC priority of 0, then mark it so upper
450          * layers have a hint that it really came via a FDDI/Ethernet
451          * bridge.
452          */
453         if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
454                 m->m_flags |= M_LINK0;
455 #endif
456
457         /* Strip off FDDI header. */
458         m_adj(m, FDDI_HDR_LEN);
459
460         m = m_pullup(m, LLC_SNAPFRAMELEN);
461         if (m == 0) {
462                 ifp->if_ierrors++;
463                 goto dropanyway;
464         }
465         l = mtod(m, struct llc *);
466
467         switch (l->llc_dsap) {
468         case LLC_SNAP_LSAP:
469         {
470                 u_int16_t type;
471                 if ((l->llc_control != LLC_UI) ||
472                     (l->llc_ssap != LLC_SNAP_LSAP)) {
473                         ifp->if_noproto++;
474                         goto dropanyway;
475                 }
476 #ifdef NETATALK
477                 if (bcmp(&(l->llc_snap.org_code)[0], at_org_code,
478                     sizeof(at_org_code)) == 0 &&
479                     ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) {
480                         isr = NETISR_ATALK2;
481                         m_adj(m, LLC_SNAPFRAMELEN);
482                         break;
483                 }
484
485                 if (bcmp(&(l->llc_snap.org_code)[0], aarp_org_code,
486                     sizeof(aarp_org_code)) == 0 &&
487                     ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) {
488                         m_adj(m, LLC_SNAPFRAMELEN);
489                         isr = NETISR_AARP;
490                         break;
491                 }
492 #endif /* NETATALK */
493                 if (l->llc_snap.org_code[0] != 0 ||
494                     l->llc_snap.org_code[1] != 0 ||
495                     l->llc_snap.org_code[2] != 0) {
496                         ifp->if_noproto++;
497                         goto dropanyway;
498                 }
499
500                 type = ntohs(l->llc_snap.ether_type);
501                 m_adj(m, LLC_SNAPFRAMELEN);
502
503                 switch (type) {
504 #ifdef INET
505                 case ETHERTYPE_IP:
506                         if ((m = ip_fastforward(m)) == NULL)
507                                 return;
508                         isr = NETISR_IP;
509                         break;
510
511                 case ETHERTYPE_ARP:
512                         if (ifp->if_flags & IFF_NOARP)
513                                 goto dropanyway;
514                         isr = NETISR_ARP;
515                         break;
516 #endif
517 #ifdef INET6
518                 case ETHERTYPE_IPV6:
519                         isr = NETISR_IPV6;
520                         break;
521 #endif
522 #ifdef IPX      
523                 case ETHERTYPE_IPX: 
524                         isr = NETISR_IPX;
525                         break;  
526 #endif   
527 #ifdef DECNET
528                 case ETHERTYPE_DECNET:
529                         isr = NETISR_DECNET;
530                         break;
531 #endif
532 #ifdef NETATALK 
533                 case ETHERTYPE_AT:
534                         isr = NETISR_ATALK1;
535                         break;
536                 case ETHERTYPE_AARP:
537                         isr = NETISR_AARP;
538                         break;
539 #endif /* NETATALK */
540                 default:
541                         /* printf("fddi_input: unknown protocol 0x%x\n", type); */
542                         ifp->if_noproto++;
543                         goto dropanyway;
544                 }
545                 break;
546         }
547                 
548         default:
549                 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
550                 ifp->if_noproto++;
551                 goto dropanyway;
552         }
553         M_SETFIB(m, ifp->if_fib);
554         netisr_dispatch(isr, m);
555         return;
556
557 dropanyway:
558         ifp->if_iqdrops++;
559         if (m)
560                 m_freem(m);
561         return;
562 }
563
564 /*
565  * Perform common duties while attaching to interface list
566  */
567 void
568 fddi_ifattach(ifp, lla, bpf)
569         struct ifnet *ifp;
570         const u_int8_t *lla;
571         int bpf;
572 {
573         struct ifaddr *ifa;
574         struct sockaddr_dl *sdl;
575
576         ifp->if_type = IFT_FDDI;
577         ifp->if_addrlen = FDDI_ADDR_LEN;
578         ifp->if_hdrlen = 21;
579
580         if_attach(ifp);         /* Must be called before additional assignments */
581
582         ifp->if_mtu = FDDIMTU;
583         ifp->if_output = fddi_output;
584         ifp->if_input = fddi_input;
585         ifp->if_resolvemulti = fddi_resolvemulti;
586         ifp->if_broadcastaddr = fddibroadcastaddr;
587         ifp->if_baudrate = 100000000;
588 #ifdef IFF_NOTRAILERS
589         ifp->if_flags |= IFF_NOTRAILERS;
590 #endif
591         ifa = ifp->if_addr;
592         KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
593
594         sdl = (struct sockaddr_dl *)ifa->ifa_addr;
595         sdl->sdl_type = IFT_FDDI;
596         sdl->sdl_alen = ifp->if_addrlen;
597         bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
598
599         if (bpf)
600                 bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN);
601
602         return;
603 }
604
605 void
606 fddi_ifdetach(ifp, bpf)
607         struct ifnet *ifp;
608         int bpf;
609 {
610      
611         if (bpf)
612                 bpfdetach(ifp);
613
614         if_detach(ifp);
615
616         return;
617 }
618
619 int
620 fddi_ioctl (ifp, command, data)
621         struct ifnet *ifp;
622         u_long command;
623         caddr_t data;
624 {
625         struct ifaddr *ifa;
626         struct ifreq *ifr;
627         int error;
628
629         ifa = (struct ifaddr *) data;
630         ifr = (struct ifreq *) data;
631         error = 0;
632
633         switch (command) {
634         case SIOCSIFADDR:
635                 ifp->if_flags |= IFF_UP;
636
637                 switch (ifa->ifa_addr->sa_family) {
638 #ifdef INET
639                 case AF_INET:   /* before arpwhohas */
640                         ifp->if_init(ifp->if_softc);
641                         arp_ifinit(ifp, ifa);
642                         break;
643 #endif
644 #ifdef IPX
645                 /*
646                  * XXX - This code is probably wrong
647                  */
648                 case AF_IPX: {
649                                 struct ipx_addr *ina;
650
651                                 ina = &(IA_SIPX(ifa)->sipx_addr);
652
653                                 if (ipx_nullhost(*ina)) {
654                                         ina->x_host = *(union ipx_host *)
655                                                         IF_LLADDR(ifp);
656                                 } else {
657                                         bcopy((caddr_t) ina->x_host.c_host,
658                                               (caddr_t) IF_LLADDR(ifp),
659                                               ETHER_ADDR_LEN);
660                                 }
661         
662                                 /*
663                                  * Set new address
664                                  */
665                                 ifp->if_init(ifp->if_softc);
666                         }
667                         break;
668 #endif
669                 default:
670                         ifp->if_init(ifp->if_softc);
671                         break;
672                 }
673                 break;
674         case SIOCGIFADDR: {
675                         struct sockaddr *sa;
676
677                         sa = (struct sockaddr *) & ifr->ifr_data;
678                         bcopy(IF_LLADDR(ifp),
679                               (caddr_t) sa->sa_data, FDDI_ADDR_LEN);
680
681                 }
682                 break;
683         case SIOCSIFMTU:
684                 /*
685                  * Set the interface MTU.
686                  */
687                 if (ifr->ifr_mtu > FDDIMTU) {
688                         error = EINVAL;
689                 } else {
690                         ifp->if_mtu = ifr->ifr_mtu;
691                 }
692                 break;
693         default:
694                 error = EINVAL;
695                 break;
696         }
697
698         return (error);
699 }
700
701 static int
702 fddi_resolvemulti(ifp, llsa, sa)
703         struct ifnet *ifp;
704         struct sockaddr **llsa;
705         struct sockaddr *sa;
706 {
707         struct sockaddr_dl *sdl;
708 #ifdef INET
709         struct sockaddr_in *sin;
710 #endif
711 #ifdef INET6
712         struct sockaddr_in6 *sin6;
713 #endif
714         u_char *e_addr;
715
716         switch(sa->sa_family) {
717         case AF_LINK:
718                 /*
719                  * No mapping needed. Just check that it's a valid MC address.
720                  */
721                 sdl = (struct sockaddr_dl *)sa;
722                 e_addr = LLADDR(sdl);
723                 if ((e_addr[0] & 1) != 1)
724                         return (EADDRNOTAVAIL);
725                 *llsa = 0;
726                 return (0);
727
728 #ifdef INET
729         case AF_INET:
730                 sin = (struct sockaddr_in *)sa;
731                 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
732                         return (EADDRNOTAVAIL);
733                 sdl = malloc(sizeof *sdl, M_IFMADDR,
734                        M_NOWAIT | M_ZERO);
735                 if (sdl == NULL)
736                         return (ENOMEM);
737                 sdl->sdl_len = sizeof *sdl;
738                 sdl->sdl_family = AF_LINK;
739                 sdl->sdl_index = ifp->if_index;
740                 sdl->sdl_type = IFT_FDDI;
741                 sdl->sdl_nlen = 0;
742                 sdl->sdl_alen = FDDI_ADDR_LEN;
743                 sdl->sdl_slen = 0;
744                 e_addr = LLADDR(sdl);
745                 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
746                 *llsa = (struct sockaddr *)sdl;
747                 return (0);
748 #endif
749 #ifdef INET6
750         case AF_INET6:
751                 sin6 = (struct sockaddr_in6 *)sa;
752                 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
753                         /*
754                          * An IP6 address of 0 means listen to all
755                          * of the Ethernet multicast address used for IP6.
756                          * (This is used for multicast routers.)
757                          */
758                         ifp->if_flags |= IFF_ALLMULTI;
759                         *llsa = 0;
760                         return (0);
761                 }
762                 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
763                         return (EADDRNOTAVAIL);
764                 sdl = malloc(sizeof *sdl, M_IFMADDR,
765                        M_NOWAIT | M_ZERO);
766                 if (sdl == NULL)
767                         return (ENOMEM);
768                 sdl->sdl_len = sizeof *sdl;
769                 sdl->sdl_family = AF_LINK;
770                 sdl->sdl_index = ifp->if_index;
771                 sdl->sdl_type = IFT_FDDI;
772                 sdl->sdl_nlen = 0;
773                 sdl->sdl_alen = FDDI_ADDR_LEN;
774                 sdl->sdl_slen = 0;
775                 e_addr = LLADDR(sdl);
776                 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
777                 *llsa = (struct sockaddr *)sdl;
778                 return (0);
779 #endif
780
781         default:
782                 /*
783                  * Well, the text isn't quite right, but it's the name
784                  * that counts...
785                  */
786                 return (EAFNOSUPPORT);
787         }
788
789         return (0);
790 }
791
792 static moduledata_t fddi_mod = {
793         "fddi", /* module name */
794         NULL,   /* event handler */
795         0       /* extra data */
796 };
797
798 DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
799 MODULE_VERSION(fddi, 1);