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