]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net/if_iso88025subr.c
Remove SYSCTL_VNET_* macros, and simply put CTLFLAG_VNET where needed.
[FreeBSD/FreeBSD.git] / sys / net / if_iso88025subr.c
1 /*-
2  * Copyright (c) 1998, Larry Lile
3  * All rights reserved.
4  *
5  * For latest sources and information on this driver, please
6  * go to http://anarchy.stdio.com.
7  *
8  * Questions, comments or suggestions should be directed to
9  * Larry Lile <lile@stdio.com>.
10  * 
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice unmodified, this list of conditions, and the following
16  *    disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  *
35  */
36
37 /*
38  *
39  * General ISO 802.5 (Token Ring) support routines
40  * 
41  */
42
43 #include "opt_inet.h"
44 #include "opt_inet6.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.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_var.h>
57 #include <net/if_arp.h>
58 #include <net/if_dl.h>
59 #include <net/if_llc.h>
60 #include <net/if_types.h>
61 #include <net/if_llatbl.h>
62
63 #include <net/ethernet.h>
64 #include <net/netisr.h>
65 #include <net/route.h>
66 #include <net/bpf.h>
67 #include <net/iso88025.h>
68
69 #if defined(INET) || defined(INET6)
70 #include <netinet/in.h>
71 #include <netinet/in_var.h>
72 #include <netinet/if_ether.h>
73 #endif
74 #ifdef INET6
75 #include <netinet6/nd6.h>
76 #endif
77
78 #include <security/mac/mac_framework.h>
79
80 static const u_char iso88025_broadcastaddr[ISO88025_ADDR_LEN] =
81                         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
82
83 static int iso88025_resolvemulti (struct ifnet *, struct sockaddr **,
84                                   struct sockaddr *);
85
86 #define senderr(e)      do { error = (e); goto bad; } while (0)
87
88 /*
89  * Perform common duties while attaching to interface list
90  */
91 void
92 iso88025_ifattach(struct ifnet *ifp, const u_int8_t *lla, int bpf)
93 {
94     struct ifaddr *ifa;
95     struct sockaddr_dl *sdl;
96
97     ifa = NULL;
98
99     ifp->if_type = IFT_ISO88025;
100     ifp->if_addrlen = ISO88025_ADDR_LEN;
101     ifp->if_hdrlen = ISO88025_HDR_LEN;
102
103     if_attach(ifp);     /* Must be called before additional assignments */
104
105     ifp->if_output = iso88025_output;
106     ifp->if_input = iso88025_input;
107     ifp->if_resolvemulti = iso88025_resolvemulti;
108     ifp->if_broadcastaddr = iso88025_broadcastaddr;
109
110     if (ifp->if_baudrate == 0)
111         ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */
112     if (ifp->if_mtu == 0)
113         ifp->if_mtu = ISO88025_DEFAULT_MTU;
114
115     ifa = ifp->if_addr;
116     KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
117
118     sdl = (struct sockaddr_dl *)ifa->ifa_addr;
119     sdl->sdl_type = IFT_ISO88025;
120     sdl->sdl_alen = ifp->if_addrlen;
121     bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
122
123     if (bpf)
124         bpfattach(ifp, DLT_IEEE802, ISO88025_HDR_LEN);
125
126     return;
127 }
128
129 /*
130  * Perform common duties while detaching a Token Ring interface
131  */
132 void
133 iso88025_ifdetach(ifp, bpf)
134         struct ifnet *ifp;
135         int bpf;
136 {
137
138         if (bpf)
139                 bpfdetach(ifp);
140
141         if_detach(ifp);
142
143         return;
144 }
145
146 int
147 iso88025_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
148 {
149         struct ifaddr *ifa;
150         struct ifreq *ifr;
151         int error;
152
153         ifa = (struct ifaddr *) data;
154         ifr = (struct ifreq *) data;
155         error = 0;
156
157         switch (command) {
158         case SIOCSIFADDR:
159                 ifp->if_flags |= IFF_UP;
160
161                 switch (ifa->ifa_addr->sa_family) {
162 #ifdef INET
163                 case AF_INET:
164                         ifp->if_init(ifp->if_softc);    /* before arpwhohas */
165                         arp_ifinit(ifp, ifa);
166                         break;
167 #endif  /* INET */
168                 default:
169                         ifp->if_init(ifp->if_softc);
170                         break;
171                 }
172                 break;
173
174         case SIOCGIFADDR: {
175                         struct sockaddr *sa;
176
177                         sa = (struct sockaddr *) & ifr->ifr_data;
178                         bcopy(IF_LLADDR(ifp),
179                               (caddr_t) sa->sa_data, ISO88025_ADDR_LEN);
180                 }
181                 break;
182
183         case SIOCSIFMTU:
184                 /*
185                  * Set the interface MTU.
186                  */
187                 if (ifr->ifr_mtu > ISO88025_MAX_MTU) {
188                         error = EINVAL;
189                 } else {
190                         ifp->if_mtu = ifr->ifr_mtu;
191                 }
192                 break;
193         default:
194                 error = EINVAL;                 /* XXX netbsd has ENOTTY??? */
195                 break;
196         }
197
198         return (error);
199 }
200
201 /*
202  * ISO88025 encapsulation
203  */
204 int
205 iso88025_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
206         struct route *ro)
207 {
208         u_int16_t snap_type = 0;
209         int loop_copy = 0, error = 0, rif_len = 0;
210         u_char edst[ISO88025_ADDR_LEN];
211         struct iso88025_header *th;
212         struct iso88025_header gen_th;
213         struct sockaddr_dl *sdl = NULL;
214         struct rtentry *rt0 = NULL;
215 #if defined(INET) || defined(INET6)
216         struct llentry *lle;
217 #endif
218
219         if (ro != NULL)
220                 rt0 = ro->ro_rt;
221
222 #ifdef MAC
223         error = mac_ifnet_check_transmit(ifp, m);
224         if (error)
225                 senderr(error);
226 #endif
227
228         if (ifp->if_flags & IFF_MONITOR)
229                 senderr(ENETDOWN);
230         if (!((ifp->if_flags & IFF_UP) &&
231             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
232                 senderr(ENETDOWN);
233         getmicrotime(&ifp->if_lastchange);
234
235         /* Calculate routing info length based on arp table entry */
236         /* XXX any better way to do this ? */
237
238         if (rt0 && (sdl = (struct sockaddr_dl *)rt0->rt_gateway))
239                 if (SDL_ISO88025(sdl)->trld_rcf != 0)
240                         rif_len = TR_RCF_RIFLEN(SDL_ISO88025(sdl)->trld_rcf);
241
242         /* Generate a generic 802.5 header for the packet */
243         gen_th.ac = TR_AC;
244         gen_th.fc = TR_LLC_FRAME;
245         (void)memcpy((caddr_t)gen_th.iso88025_shost, IF_LLADDR(ifp),
246                      ISO88025_ADDR_LEN);
247         if (rif_len) {
248                 gen_th.iso88025_shost[0] |= TR_RII;
249                 if (rif_len > 2) {
250                         gen_th.rcf = SDL_ISO88025(sdl)->trld_rcf;
251                         (void)memcpy((caddr_t)gen_th.rd,
252                                 (caddr_t)SDL_ISO88025(sdl)->trld_route,
253                                 rif_len - 2);
254                 }
255         }
256         
257         switch (dst->sa_family) {
258 #ifdef INET
259         case AF_INET:
260                 error = arpresolve(ifp, rt0, m, dst, edst, &lle);
261                 if (error)
262                         return (error == EWOULDBLOCK ? 0 : error);
263                 snap_type = ETHERTYPE_IP;
264                 break;
265         case AF_ARP:
266         {
267                 struct arphdr *ah;
268                 ah = mtod(m, struct arphdr *);
269                 ah->ar_hrd = htons(ARPHRD_IEEE802);
270
271                 loop_copy = -1; /* if this is for us, don't do it */
272
273                 switch(ntohs(ah->ar_op)) {
274                 case ARPOP_REVREQUEST:
275                 case ARPOP_REVREPLY:
276                         snap_type = ETHERTYPE_REVARP;
277                         break;
278                 case ARPOP_REQUEST:
279                 case ARPOP_REPLY:
280                 default:
281                         snap_type = ETHERTYPE_ARP;
282                         break;
283                 }
284
285                 if (m->m_flags & M_BCAST)
286                         bcopy(ifp->if_broadcastaddr, edst, ISO88025_ADDR_LEN);
287                 else
288                         bcopy(ar_tha(ah), edst, ISO88025_ADDR_LEN);
289
290         }
291         break;
292 #endif  /* INET */
293 #ifdef INET6
294         case AF_INET6:
295                 error = nd6_storelladdr(ifp, m, dst, (u_char *)edst, &lle);
296                 if (error)
297                         return (error);
298                 snap_type = ETHERTYPE_IPV6;
299                 break;
300 #endif  /* INET6 */
301         case AF_UNSPEC:
302         {
303                 const struct iso88025_sockaddr_data *sd;
304                 /*
305                  * For AF_UNSPEC sockaddr.sa_data must contain all of the
306                  * mac information needed to send the packet.  This allows
307                  * full mac, llc, and source routing function to be controlled.
308                  * llc and source routing information must already be in the
309                  * mbuf provided, ac/fc are set in sa_data.  sockaddr.sa_data
310                  * should be an iso88025_sockaddr_data structure see iso88025.h
311                  */
312                 loop_copy = -1;
313                 sd = (const struct iso88025_sockaddr_data *)dst->sa_data;
314                 gen_th.ac = sd->ac;
315                 gen_th.fc = sd->fc;
316                 (void)memcpy(edst, sd->ether_dhost, ISO88025_ADDR_LEN);
317                 (void)memcpy(gen_th.iso88025_shost, sd->ether_shost,
318                     ISO88025_ADDR_LEN);
319                 rif_len = 0;
320                 break;
321         }
322         default:
323                 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
324                 senderr(EAFNOSUPPORT);
325                 break;
326         }
327
328         /*
329          * Add LLC header.
330          */
331         if (snap_type != 0) {
332                 struct llc *l;
333                 M_PREPEND(m, LLC_SNAPFRAMELEN, M_NOWAIT);
334                 if (m == 0)
335                         senderr(ENOBUFS);
336                 l = mtod(m, struct llc *);
337                 l->llc_control = LLC_UI;
338                 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
339                 l->llc_snap.org_code[0] =
340                         l->llc_snap.org_code[1] =
341                         l->llc_snap.org_code[2] = 0;
342                 l->llc_snap.ether_type = htons(snap_type);
343         }
344
345         /*
346          * Add local net header.  If no space in first mbuf,
347          * allocate another.
348          */
349         M_PREPEND(m, ISO88025_HDR_LEN + rif_len, M_NOWAIT);
350         if (m == 0)
351                 senderr(ENOBUFS);
352         th = mtod(m, struct iso88025_header *);
353         bcopy((caddr_t)edst, (caddr_t)&gen_th.iso88025_dhost, ISO88025_ADDR_LEN);
354
355         /* Copy as much of the generic header as is needed into the mbuf */
356         memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len);
357
358         /*
359          * If a simplex interface, and the packet is being sent to our
360          * Ethernet address or a broadcast address, loopback a copy.
361          * XXX To make a simplex device behave exactly like a duplex
362          * device, we should copy in the case of sending to our own
363          * ethernet address (thus letting the original actually appear
364          * on the wire). However, we don't do that here for security
365          * reasons and compatibility with the original behavior.
366          */     
367         if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
368                 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { 
369                         struct mbuf *n;
370                         n = m_copy(m, 0, (int)M_COPYALL);
371                         (void) if_simloop(ifp, n, dst->sa_family,
372                                           ISO88025_HDR_LEN);
373                 } else if (bcmp(th->iso88025_dhost, th->iso88025_shost,
374                                  ETHER_ADDR_LEN) == 0) {
375                         (void) if_simloop(ifp, m, dst->sa_family,
376                                           ISO88025_HDR_LEN);
377                         return(0);      /* XXX */
378                 }       
379         }      
380
381         IFQ_HANDOFF_ADJ(ifp, m, ISO88025_HDR_LEN + LLC_SNAPFRAMELEN, error);
382         if (error) {
383                 printf("iso88025_output: packet dropped QFULL.\n");
384                 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
385         }
386         return (error);
387
388 bad:
389         if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
390         if (m)
391                 m_freem(m);
392         return (error);
393 }
394
395 /*
396  * ISO 88025 de-encapsulation
397  */
398 void
399 iso88025_input(ifp, m)
400         struct ifnet *ifp;
401         struct mbuf *m;
402 {
403         struct iso88025_header *th;
404         struct llc *l;
405         int isr;
406         int mac_hdr_len;
407
408         /*
409          * Do consistency checks to verify assumptions
410          * made by code past this point.
411          */
412         if ((m->m_flags & M_PKTHDR) == 0) {
413                 if_printf(ifp, "discard frame w/o packet header\n");
414                 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
415                 m_freem(m);
416                 return;
417         }
418         if (m->m_pkthdr.rcvif == NULL) {
419                 if_printf(ifp, "discard frame w/o interface pointer\n");
420                 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
421                 m_freem(m);
422                 return;
423         }
424
425         m = m_pullup(m, ISO88025_HDR_LEN);
426         if (m == NULL) {
427                 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
428                 goto dropanyway;
429         }
430         th = mtod(m, struct iso88025_header *);
431
432         /*
433          * Discard packet if interface is not up.
434          */
435         if (!((ifp->if_flags & IFF_UP) &&
436             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
437                 goto dropanyway;
438
439         /*
440          * Give bpf a chance at the packet.
441          */
442         BPF_MTAP(ifp, m);
443
444         /*
445          * Interface marked for monitoring; discard packet.
446          */
447         if (ifp->if_flags & IFF_MONITOR) {
448                 m_freem(m);
449                 return;
450         }
451
452 #ifdef MAC
453         mac_ifnet_create_mbuf(ifp, m);
454 #endif
455
456         /*
457          * Update interface statistics.
458          */
459         if_inc_counter(ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len);
460         getmicrotime(&ifp->if_lastchange);
461
462         /*
463          * Discard non local unicast packets when interface
464          * is in promiscuous mode.
465          */
466         if ((ifp->if_flags & IFF_PROMISC) &&
467             ((th->iso88025_dhost[0] & 1) == 0) &&
468              (bcmp(IF_LLADDR(ifp), (caddr_t) th->iso88025_dhost,
469              ISO88025_ADDR_LEN) != 0))
470                 goto dropanyway;
471
472         /*
473          * Set mbuf flags for bcast/mcast.
474          */
475         if (th->iso88025_dhost[0] & 1) {
476                 if (bcmp(iso88025_broadcastaddr, th->iso88025_dhost,
477                     ISO88025_ADDR_LEN) == 0)
478                         m->m_flags |= M_BCAST;
479                 else
480                         m->m_flags |= M_MCAST;
481                 if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1);
482         }
483
484         mac_hdr_len = ISO88025_HDR_LEN;
485         /* Check for source routing info */
486         if (th->iso88025_shost[0] & TR_RII)
487                 mac_hdr_len += TR_RCF_RIFLEN(th->rcf);
488
489         /* Strip off ISO88025 header. */
490         m_adj(m, mac_hdr_len);
491
492         m = m_pullup(m, LLC_SNAPFRAMELEN);
493         if (m == 0) {
494                 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
495                 goto dropanyway;
496         }
497         l = mtod(m, struct llc *);
498
499         switch (l->llc_dsap) {
500         case LLC_SNAP_LSAP: {
501                 u_int16_t type;
502                 if ((l->llc_control != LLC_UI) ||
503                     (l->llc_ssap != LLC_SNAP_LSAP)) {
504                         if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
505                         goto dropanyway;
506                 }
507
508                 if (l->llc_snap.org_code[0] != 0 ||
509                     l->llc_snap.org_code[1] != 0 ||
510                     l->llc_snap.org_code[2] != 0) {
511                         if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
512                         goto dropanyway;
513                 }
514
515                 type = ntohs(l->llc_snap.ether_type);
516                 m_adj(m, LLC_SNAPFRAMELEN);
517                 switch (type) {
518 #ifdef INET
519                 case ETHERTYPE_IP:
520                         th->iso88025_shost[0] &= ~(TR_RII); 
521                         if ((m = ip_fastforward(m)) == NULL)
522                                 return;
523                         isr = NETISR_IP;
524                         break;
525
526                 case ETHERTYPE_ARP:
527                         if (ifp->if_flags & IFF_NOARP)
528                                 goto dropanyway;
529                         isr = NETISR_ARP;
530                         break;
531 #endif  /* INET */
532 #ifdef INET6
533                 case ETHERTYPE_IPV6:
534                         th->iso88025_shost[0] &= ~(TR_RII); 
535                         isr = NETISR_IPV6;
536                         break;
537 #endif  /* INET6 */
538                 default:
539                         printf("iso88025_input: unexpected llc_snap ether_type  0x%02x\n", type);
540                         if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
541                         goto dropanyway;
542                 }
543                 break;
544         }
545 #ifdef ISO
546         case LLC_ISO_LSAP:
547                 switch (l->llc_control) {
548                 case LLC_UI:
549                         if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
550                         goto dropanyway;
551                         break;
552                 case LLC_XID:
553                 case LLC_XID_P:
554                         if(m->m_len < ISO88025_ADDR_LEN)
555                                 goto dropanyway;
556                         l->llc_window = 0;
557                         l->llc_fid = 9;  
558                         l->llc_class = 1;
559                         l->llc_dsap = l->llc_ssap = 0;
560                         /* Fall through to */  
561                 case LLC_TEST:
562                 case LLC_TEST_P:
563                 {
564                         struct sockaddr sa;
565                         struct arpcom *ac;
566                         struct iso88025_sockaddr_data *th2;
567                         int i;
568                         u_char c;
569
570                         c = l->llc_dsap;
571
572                         if (th->iso88025_shost[0] & TR_RII) { /* XXX */
573                                 printf("iso88025_input: dropping source routed LLC_TEST\n");
574                                 goto dropanyway;
575                         }
576                         l->llc_dsap = l->llc_ssap;
577                         l->llc_ssap = c;
578                         if (m->m_flags & (M_BCAST | M_MCAST))
579                                 bcopy((caddr_t)IF_LLADDR(ifp),
580                                       (caddr_t)th->iso88025_dhost,
581                                         ISO88025_ADDR_LEN);
582                         sa.sa_family = AF_UNSPEC;
583                         sa.sa_len = sizeof(sa);
584                         th2 = (struct iso88025_sockaddr_data *)sa.sa_data;
585                         for (i = 0; i < ISO88025_ADDR_LEN; i++) {
586                                 th2->ether_shost[i] = c = th->iso88025_dhost[i];
587                                 th2->ether_dhost[i] = th->iso88025_dhost[i] =
588                                         th->iso88025_shost[i];
589                                 th->iso88025_shost[i] = c;
590                         }
591                         th2->ac = TR_AC;
592                         th2->fc = TR_LLC_FRAME;
593                         ifp->if_output(ifp, m, &sa, NULL);
594                         return;
595                 }
596                 default:
597                         printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control);
598                         if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
599                         goto dropanyway;
600                         break;
601                 }
602                 break;
603 #endif  /* ISO */
604         default:
605                 printf("iso88025_input: unknown dsap 0x%x\n", l->llc_dsap);
606                 if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1);
607                 goto dropanyway;
608                 break;
609         }
610
611         M_SETFIB(m, ifp->if_fib);
612         netisr_dispatch(isr, m);
613         return;
614
615 dropanyway:
616         if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
617         if (m)
618                 m_freem(m);
619         return;
620 }
621
622 static int
623 iso88025_resolvemulti (ifp, llsa, sa)
624         struct ifnet *ifp;
625         struct sockaddr **llsa;
626         struct sockaddr *sa;
627 {
628         struct sockaddr_dl *sdl;
629 #ifdef INET
630         struct sockaddr_in *sin;
631 #endif
632 #ifdef INET6
633         struct sockaddr_in6 *sin6;
634 #endif
635         u_char *e_addr;
636
637         switch(sa->sa_family) {
638         case AF_LINK:
639                 /*
640                  * No mapping needed. Just check that it's a valid MC address.
641                  */
642                 sdl = (struct sockaddr_dl *)sa;
643                 e_addr = LLADDR(sdl);
644                 if ((e_addr[0] & 1) != 1) {
645                         return (EADDRNOTAVAIL);
646                 }
647                 *llsa = 0;
648                 return (0);
649
650 #ifdef INET
651         case AF_INET:
652                 sin = (struct sockaddr_in *)sa;
653                 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
654                         return (EADDRNOTAVAIL);
655                 }
656                 sdl = link_init_sdl(ifp, *llsa, IFT_ISO88025);
657                 sdl->sdl_alen = ISO88025_ADDR_LEN;
658                 e_addr = LLADDR(sdl);
659                 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
660                 *llsa = (struct sockaddr *)sdl;
661                 return (0);
662 #endif
663 #ifdef INET6
664         case AF_INET6:
665                 sin6 = (struct sockaddr_in6 *)sa;
666                 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
667                         /*
668                          * An IP6 address of 0 means listen to all
669                          * of the Ethernet multicast address used for IP6.
670                          * (This is used for multicast routers.)
671                          */
672                         ifp->if_flags |= IFF_ALLMULTI;
673                         *llsa = 0;
674                         return (0);
675                 }
676                 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
677                         return (EADDRNOTAVAIL);
678                 }
679                 sdl = link_init_sdl(ifp, *llsa, IFT_ISO88025);
680                 sdl->sdl_alen = ISO88025_ADDR_LEN;
681                 e_addr = LLADDR(sdl);
682                 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
683                 *llsa = (struct sockaddr *)sdl;
684                 return (0);
685 #endif
686
687         default:
688                 /*
689                  * Well, the text isn't quite right, but it's the name
690                  * that counts...
691                  */
692                 return (EAFNOSUPPORT);
693         }
694
695         return (0);
696 }
697
698 static MALLOC_DEFINE(M_ISO88025, "arpcom", "802.5 interface internals");
699
700 static void*
701 iso88025_alloc(u_char type, struct ifnet *ifp)
702 {
703         struct arpcom   *ac;
704  
705         ac = malloc(sizeof(struct arpcom), M_ISO88025, M_WAITOK | M_ZERO);
706         ac->ac_ifp = ifp;
707
708         return (ac);
709
710
711 static void
712 iso88025_free(void *com, u_char type)
713 {
714  
715         free(com, M_ISO88025);
716 }
717  
718 static int
719 iso88025_modevent(module_t mod, int type, void *data)
720 {
721   
722         switch (type) {
723         case MOD_LOAD:
724                 if_register_com_alloc(IFT_ISO88025, iso88025_alloc,
725                     iso88025_free);
726                 break;
727         case MOD_UNLOAD:
728                 if_deregister_com_alloc(IFT_ISO88025);
729                 break;
730         default:
731                 return EOPNOTSUPP;
732         }
733
734         return (0);
735 }
736
737 static moduledata_t iso88025_mod = {
738         "iso88025",
739         iso88025_modevent,
740         0
741 };
742
743 DECLARE_MODULE(iso88025, iso88025_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
744 MODULE_VERSION(iso88025, 1);