]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net/if_iso88025subr.c
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[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 #include "opt_ipx.h"
46 #include "opt_mac.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mbuf.h>
53 #include <sys/module.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h> 
56
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_llc.h>
60 #include <net/if_types.h>
61
62 #include <net/netisr.h>
63 #include <net/route.h>
64 #include <net/bpf.h>
65 #include <net/iso88025.h>
66
67 #if defined(INET) || defined(INET6)
68 #include <netinet/in.h>
69 #include <netinet/in_var.h>
70 #include <netinet/if_ether.h>
71 #endif
72 #ifdef INET6
73 #include <netinet6/nd6.h>
74 #endif
75
76 #ifdef IPX
77 #include <netipx/ipx.h>
78 #include <netipx/ipx_if.h>
79 #endif
80
81 #include <security/mac/mac_framework.h>
82
83 static const u_char iso88025_broadcastaddr[ISO88025_ADDR_LEN] =
84                         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
85
86 static int iso88025_resolvemulti (struct ifnet *, struct sockaddr **,
87                                   struct sockaddr *);
88
89 #define senderr(e)      do { error = (e); goto bad; } while (0)
90
91 /*
92  * Perform common duties while attaching to interface list
93  */
94 void
95 iso88025_ifattach(struct ifnet *ifp, const u_int8_t *lla, int bpf)
96 {
97     struct ifaddr *ifa;
98     struct sockaddr_dl *sdl;
99
100     ifa = NULL;
101
102     ifp->if_type = IFT_ISO88025;
103     ifp->if_addrlen = ISO88025_ADDR_LEN;
104     ifp->if_hdrlen = ISO88025_HDR_LEN;
105
106     if_attach(ifp);     /* Must be called before additional assignments */
107
108     ifp->if_output = iso88025_output;
109     ifp->if_input = iso88025_input;
110     ifp->if_resolvemulti = iso88025_resolvemulti;
111     ifp->if_broadcastaddr = iso88025_broadcastaddr;
112
113     if (ifp->if_baudrate == 0)
114         ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */
115     if (ifp->if_mtu == 0)
116         ifp->if_mtu = ISO88025_DEFAULT_MTU;
117
118     ifa = ifp->if_addr;
119     KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
120
121     sdl = (struct sockaddr_dl *)ifa->ifa_addr;
122     sdl->sdl_type = IFT_ISO88025;
123     sdl->sdl_alen = ifp->if_addrlen;
124     bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
125
126     if (bpf)
127         bpfattach(ifp, DLT_IEEE802, ISO88025_HDR_LEN);
128
129     return;
130 }
131
132 /*
133  * Perform common duties while detaching a Token Ring interface
134  */
135 void
136 iso88025_ifdetach(ifp, bpf)
137         struct ifnet *ifp;
138         int bpf;
139 {
140
141         if (bpf)
142                 bpfdetach(ifp);
143
144         if_detach(ifp);
145
146         return;
147 }
148
149 int
150 iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data)
151 {
152         struct ifaddr *ifa;
153         struct ifreq *ifr;
154         int error;
155
156         ifa = (struct ifaddr *) data;
157         ifr = (struct ifreq *) data;
158         error = 0;
159
160         switch (command) {
161         case SIOCSIFADDR:
162                 ifp->if_flags |= IFF_UP;
163
164                 switch (ifa->ifa_addr->sa_family) {
165 #ifdef INET
166                 case AF_INET:
167                         ifp->if_init(ifp->if_softc);    /* before arpwhohas */
168                         arp_ifinit(ifp, ifa);
169                         break;
170 #endif  /* INET */
171 #ifdef IPX
172                 /*
173                  * XXX - This code is probably wrong
174                  */
175                 case AF_IPX: {
176                                 struct ipx_addr *ina;
177
178                                 ina = &(IA_SIPX(ifa)->sipx_addr);
179
180                                 if (ipx_nullhost(*ina))
181                                         ina->x_host = *(union ipx_host *)
182                                                         IF_LLADDR(ifp);
183                                 else
184                                         bcopy((caddr_t) ina->x_host.c_host,
185                                               (caddr_t) IF_LLADDR(ifp),
186                                               ISO88025_ADDR_LEN);
187
188                                 /*
189                                  * Set new address
190                                  */
191                                 ifp->if_init(ifp->if_softc);
192                         }
193                         break;
194 #endif  /* IPX */
195                 default:
196                         ifp->if_init(ifp->if_softc);
197                         break;
198                 }
199                 break;
200
201         case SIOCGIFADDR: {
202                         struct sockaddr *sa;
203
204                         sa = (struct sockaddr *) & ifr->ifr_data;
205                         bcopy(IF_LLADDR(ifp),
206                               (caddr_t) sa->sa_data, ISO88025_ADDR_LEN);
207                 }
208                 break;
209
210         case SIOCSIFMTU:
211                 /*
212                  * Set the interface MTU.
213                  */
214                 if (ifr->ifr_mtu > ISO88025_MAX_MTU) {
215                         error = EINVAL;
216                 } else {
217                         ifp->if_mtu = ifr->ifr_mtu;
218                 }
219                 break;
220         default:
221                 error = EINVAL;                 /* XXX netbsd has ENOTTY??? */
222                 break;
223         }
224
225         return (error);
226 }
227
228 /*
229  * ISO88025 encapsulation
230  */
231 int
232 iso88025_output(ifp, m, dst, rt0)
233         struct ifnet *ifp;
234         struct mbuf *m;
235         struct sockaddr *dst;
236         struct rtentry *rt0;
237 {
238         u_int16_t snap_type = 0;
239         int loop_copy = 0, error = 0, rif_len = 0;
240         u_char edst[ISO88025_ADDR_LEN];
241         struct iso88025_header *th;
242         struct iso88025_header gen_th;
243         struct sockaddr_dl *sdl = NULL;
244         struct rtentry *rt = NULL;
245
246 #ifdef MAC
247         error = mac_ifnet_check_transmit(ifp, m);
248         if (error)
249                 senderr(error);
250 #endif
251
252         if (ifp->if_flags & IFF_MONITOR)
253                 senderr(ENETDOWN);
254         if (!((ifp->if_flags & IFF_UP) &&
255             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
256                 senderr(ENETDOWN);
257         getmicrotime(&ifp->if_lastchange);
258
259         /* Calculate routing info length based on arp table entry */
260         /* XXX any better way to do this ? */
261         if (rt0 != NULL) {
262                 error = rt_check(&rt, &rt0, dst);
263                 if (error)
264                         goto bad;
265                 RT_UNLOCK(rt);
266         }
267
268         if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway))
269                 if (SDL_ISO88025(sdl)->trld_rcf != 0)
270                         rif_len = TR_RCF_RIFLEN(SDL_ISO88025(sdl)->trld_rcf);
271
272         /* Generate a generic 802.5 header for the packet */
273         gen_th.ac = TR_AC;
274         gen_th.fc = TR_LLC_FRAME;
275         (void)memcpy((caddr_t)gen_th.iso88025_shost, IF_LLADDR(ifp),
276                      ISO88025_ADDR_LEN);
277         if (rif_len) {
278                 gen_th.iso88025_shost[0] |= TR_RII;
279                 if (rif_len > 2) {
280                         gen_th.rcf = SDL_ISO88025(sdl)->trld_rcf;
281                         (void)memcpy((caddr_t)gen_th.rd,
282                                 (caddr_t)SDL_ISO88025(sdl)->trld_route,
283                                 rif_len - 2);
284                 }
285         }
286         
287         switch (dst->sa_family) {
288 #ifdef INET
289         case AF_INET:
290                 error = arpresolve(ifp, rt0, m, dst, edst);
291                 if (error)
292                         return (error == EWOULDBLOCK ? 0 : error);
293                 snap_type = ETHERTYPE_IP;
294                 break;
295         case AF_ARP:
296         {
297                 struct arphdr *ah;
298                 ah = mtod(m, struct arphdr *);
299                 ah->ar_hrd = htons(ARPHRD_IEEE802);
300
301                 loop_copy = -1; /* if this is for us, don't do it */
302
303                 switch(ntohs(ah->ar_op)) {
304                 case ARPOP_REVREQUEST:
305                 case ARPOP_REVREPLY:
306                         snap_type = ETHERTYPE_REVARP;
307                         break;
308                 case ARPOP_REQUEST:
309                 case ARPOP_REPLY:
310                 default:
311                         snap_type = ETHERTYPE_ARP;
312                         break;
313                 }
314
315                 if (m->m_flags & M_BCAST)
316                         bcopy(ifp->if_broadcastaddr, edst, ISO88025_ADDR_LEN);
317                 else
318                         bcopy(ar_tha(ah), edst, ISO88025_ADDR_LEN);
319
320         }
321         break;
322 #endif  /* INET */
323 #ifdef INET6
324         case AF_INET6:
325                 error = nd6_storelladdr(ifp, rt0, m, dst, (u_char *)edst);
326                 if (error)
327                         return (error);
328                 snap_type = ETHERTYPE_IPV6;
329                 break;
330 #endif  /* INET6 */
331 #ifdef IPX
332         case AF_IPX:
333         {
334                 u_int8_t        *cp;
335
336                 bcopy((caddr_t)&(satoipx_addr(dst).x_host), (caddr_t)edst,
337                       ISO88025_ADDR_LEN);
338
339                 M_PREPEND(m, 3, M_WAIT);
340                 m = m_pullup(m, 3);
341                 if (m == 0)
342                         senderr(ENOBUFS);
343                 cp = mtod(m, u_int8_t *);
344                 *cp++ = ETHERTYPE_IPX_8022;
345                 *cp++ = ETHERTYPE_IPX_8022;
346                 *cp++ = LLC_UI;
347         }
348         break;
349 #endif  /* IPX */
350         case AF_UNSPEC:
351         {
352                 struct iso88025_sockaddr_data *sd;
353                 /*
354                  * For AF_UNSPEC sockaddr.sa_data must contain all of the
355                  * mac information needed to send the packet.  This allows
356                  * full mac, llc, and source routing function to be controlled.
357                  * llc and source routing information must already be in the
358                  * mbuf provided, ac/fc are set in sa_data.  sockaddr.sa_data
359                  * should be an iso88025_sockaddr_data structure see iso88025.h
360                  */
361                 loop_copy = -1;
362                 sd = (struct iso88025_sockaddr_data *)dst->sa_data;
363                 gen_th.ac = sd->ac;
364                 gen_th.fc = sd->fc;
365                 (void)memcpy((caddr_t)edst, (caddr_t)sd->ether_dhost,
366                              ISO88025_ADDR_LEN);
367                 (void)memcpy((caddr_t)gen_th.iso88025_shost,
368                              (caddr_t)sd->ether_shost, ISO88025_ADDR_LEN);
369                 rif_len = 0;
370                 break;
371         }
372         default:
373                 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
374                 senderr(EAFNOSUPPORT);
375                 break;
376         }
377
378         /*
379          * Add LLC header.
380          */
381         if (snap_type != 0) {
382                 struct llc *l;
383                 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
384                 if (m == 0)
385                         senderr(ENOBUFS);
386                 l = mtod(m, struct llc *);
387                 l->llc_control = LLC_UI;
388                 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
389                 l->llc_snap.org_code[0] =
390                         l->llc_snap.org_code[1] =
391                         l->llc_snap.org_code[2] = 0;
392                 l->llc_snap.ether_type = htons(snap_type);
393         }
394
395         /*
396          * Add local net header.  If no space in first mbuf,
397          * allocate another.
398          */
399         M_PREPEND(m, ISO88025_HDR_LEN + rif_len, M_DONTWAIT);
400         if (m == 0)
401                 senderr(ENOBUFS);
402         th = mtod(m, struct iso88025_header *);
403         bcopy((caddr_t)edst, (caddr_t)&gen_th.iso88025_dhost, ISO88025_ADDR_LEN);
404
405         /* Copy as much of the generic header as is needed into the mbuf */
406         memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len);
407
408         /*
409          * If a simplex interface, and the packet is being sent to our
410          * Ethernet address or a broadcast address, loopback a copy.
411          * XXX To make a simplex device behave exactly like a duplex
412          * device, we should copy in the case of sending to our own
413          * ethernet address (thus letting the original actually appear
414          * on the wire). However, we don't do that here for security
415          * reasons and compatibility with the original behavior.
416          */     
417         if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
418                 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { 
419                         struct mbuf *n;
420                         n = m_copy(m, 0, (int)M_COPYALL);
421                         (void) if_simloop(ifp, n, dst->sa_family,
422                                           ISO88025_HDR_LEN);
423                 } else if (bcmp(th->iso88025_dhost, th->iso88025_shost,
424                                  ETHER_ADDR_LEN) == 0) {
425                         (void) if_simloop(ifp, m, dst->sa_family,
426                                           ISO88025_HDR_LEN);
427                         return(0);      /* XXX */
428                 }       
429         }      
430
431         IFQ_HANDOFF_ADJ(ifp, m, ISO88025_HDR_LEN + LLC_SNAPFRAMELEN, error);
432         if (error) {
433                 printf("iso88025_output: packet dropped QFULL.\n");
434                 ifp->if_oerrors++;
435         }
436         return (error);
437
438 bad:
439         ifp->if_oerrors++;
440         if (m)
441                 m_freem(m);
442         return (error);
443 }
444
445 /*
446  * ISO 88025 de-encapsulation
447  */
448 void
449 iso88025_input(ifp, m)
450         struct ifnet *ifp;
451         struct mbuf *m;
452 {
453         struct iso88025_header *th;
454         struct llc *l;
455         int isr;
456         int mac_hdr_len;
457
458         /*
459          * Do consistency checks to verify assumptions
460          * made by code past this point.
461          */
462         if ((m->m_flags & M_PKTHDR) == 0) {
463                 if_printf(ifp, "discard frame w/o packet header\n");
464                 ifp->if_ierrors++;
465                 m_freem(m);
466                 return;
467         }
468         if (m->m_pkthdr.rcvif == NULL) {
469                 if_printf(ifp, "discard frame w/o interface pointer\n");
470                 ifp->if_ierrors++;
471                 m_freem(m);
472                 return;
473         }
474
475         m = m_pullup(m, ISO88025_HDR_LEN);
476         if (m == NULL) {
477                 ifp->if_ierrors++;
478                 goto dropanyway;
479         }
480         th = mtod(m, struct iso88025_header *);
481         m->m_pkthdr.header = (void *)th;
482
483         /*
484          * Discard packet if interface is not up.
485          */
486         if (!((ifp->if_flags & IFF_UP) &&
487             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
488                 goto dropanyway;
489
490         /*
491          * Give bpf a chance at the packet.
492          */
493         BPF_MTAP(ifp, m);
494
495         /*
496          * Interface marked for monitoring; discard packet.
497          */
498         if (ifp->if_flags & IFF_MONITOR) {
499                 m_freem(m);
500                 return;
501         }
502
503 #ifdef MAC
504         mac_ifnet_create_mbuf(ifp, m);
505 #endif
506
507         /*
508          * Update interface statistics.
509          */
510         ifp->if_ibytes += m->m_pkthdr.len;
511         getmicrotime(&ifp->if_lastchange);
512
513         /*
514          * Discard non local unicast packets when interface
515          * is in promiscuous mode.
516          */
517         if ((ifp->if_flags & IFF_PROMISC) &&
518             ((th->iso88025_dhost[0] & 1) == 0) &&
519              (bcmp(IF_LLADDR(ifp), (caddr_t) th->iso88025_dhost,
520              ISO88025_ADDR_LEN) != 0))
521                 goto dropanyway;
522
523         /*
524          * Set mbuf flags for bcast/mcast.
525          */
526         if (th->iso88025_dhost[0] & 1) {
527                 if (bcmp(iso88025_broadcastaddr, th->iso88025_dhost,
528                     ISO88025_ADDR_LEN) == 0)
529                         m->m_flags |= M_BCAST;
530                 else
531                         m->m_flags |= M_MCAST;
532                 ifp->if_imcasts++;
533         }
534
535         mac_hdr_len = ISO88025_HDR_LEN;
536         /* Check for source routing info */
537         if (th->iso88025_shost[0] & TR_RII)
538                 mac_hdr_len += TR_RCF_RIFLEN(th->rcf);
539
540         /* Strip off ISO88025 header. */
541         m_adj(m, mac_hdr_len);
542
543         m = m_pullup(m, LLC_SNAPFRAMELEN);
544         if (m == 0) {
545                 ifp->if_ierrors++;
546                 goto dropanyway;
547         }
548         l = mtod(m, struct llc *);
549
550         switch (l->llc_dsap) {
551 #ifdef IPX
552         case ETHERTYPE_IPX_8022:        /* Thanks a bunch Novell */
553                 if ((l->llc_control != LLC_UI) ||
554                     (l->llc_ssap != ETHERTYPE_IPX_8022)) {
555                         ifp->if_noproto++;
556                         goto dropanyway;
557                 }
558
559                 th->iso88025_shost[0] &= ~(TR_RII); 
560                 m_adj(m, 3);
561                 isr = NETISR_IPX;
562                 break;
563 #endif  /* IPX */
564         case LLC_SNAP_LSAP: {
565                 u_int16_t type;
566                 if ((l->llc_control != LLC_UI) ||
567                     (l->llc_ssap != LLC_SNAP_LSAP)) {
568                         ifp->if_noproto++;
569                         goto dropanyway;
570                 }
571
572                 if (l->llc_snap.org_code[0] != 0 ||
573                     l->llc_snap.org_code[1] != 0 ||
574                     l->llc_snap.org_code[2] != 0) {
575                         ifp->if_noproto++;
576                         goto dropanyway;
577                 }
578
579                 type = ntohs(l->llc_snap.ether_type);
580                 m_adj(m, LLC_SNAPFRAMELEN);
581                 switch (type) {
582 #ifdef INET
583                 case ETHERTYPE_IP:
584                         th->iso88025_shost[0] &= ~(TR_RII); 
585                         if ((m = ip_fastforward(m)) == NULL)
586                                 return;
587                         isr = NETISR_IP;
588                         break;
589
590                 case ETHERTYPE_ARP:
591                         if (ifp->if_flags & IFF_NOARP)
592                                 goto dropanyway;
593                         isr = NETISR_ARP;
594                         break;
595 #endif  /* INET */
596 #ifdef IPX_SNAP /* XXX: Not supported! */
597                 case ETHERTYPE_IPX:
598                         th->iso88025_shost[0] &= ~(TR_RII); 
599                         isr = NETISR_IPX;
600                         break;
601 #endif  /* IPX_SNAP */
602 #ifdef INET6
603                 case ETHERTYPE_IPV6:
604                         th->iso88025_shost[0] &= ~(TR_RII); 
605                         isr = NETISR_IPV6;
606                         break;
607 #endif  /* INET6 */
608                 default:
609                         printf("iso88025_input: unexpected llc_snap ether_type  0x%02x\n", type);
610                         ifp->if_noproto++;
611                         goto dropanyway;
612                 }
613                 break;
614         }
615 #ifdef ISO
616         case LLC_ISO_LSAP:
617                 switch (l->llc_control) {
618                 case LLC_UI:
619                         ifp->if_noproto++;
620                         goto dropanyway;
621                         break;
622                 case LLC_XID:
623                 case LLC_XID_P:
624                         if(m->m_len < ISO88025_ADDR_LEN)
625                                 goto dropanyway;
626                         l->llc_window = 0;
627                         l->llc_fid = 9;  
628                         l->llc_class = 1;
629                         l->llc_dsap = l->llc_ssap = 0;
630                         /* Fall through to */  
631                 case LLC_TEST:
632                 case LLC_TEST_P:
633                 {
634                         struct sockaddr sa;
635                         struct arpcom *ac;
636                         struct iso88025_sockaddr_data *th2;
637                         int i;
638                         u_char c;
639
640                         c = l->llc_dsap;
641
642                         if (th->iso88025_shost[0] & TR_RII) { /* XXX */
643                                 printf("iso88025_input: dropping source routed LLC_TEST\n");
644                                 goto dropanyway;
645                         }
646                         l->llc_dsap = l->llc_ssap;
647                         l->llc_ssap = c;
648                         if (m->m_flags & (M_BCAST | M_MCAST))
649                                 bcopy((caddr_t)IF_LLADDR(ifp),
650                                       (caddr_t)th->iso88025_dhost,
651                                         ISO88025_ADDR_LEN);
652                         sa.sa_family = AF_UNSPEC;
653                         sa.sa_len = sizeof(sa);
654                         th2 = (struct iso88025_sockaddr_data *)sa.sa_data;
655                         for (i = 0; i < ISO88025_ADDR_LEN; i++) {
656                                 th2->ether_shost[i] = c = th->iso88025_dhost[i];
657                                 th2->ether_dhost[i] = th->iso88025_dhost[i] =
658                                         th->iso88025_shost[i];
659                                 th->iso88025_shost[i] = c;
660                         }
661                         th2->ac = TR_AC;
662                         th2->fc = TR_LLC_FRAME;
663                         ifp->if_output(ifp, m, &sa, NULL);
664                         return;
665                 }
666                 default:
667                         printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control);
668                         ifp->if_noproto++;
669                         goto dropanyway;
670                         break;
671                 }
672                 break;
673 #endif  /* ISO */
674         default:
675                 printf("iso88025_input: unknown dsap 0x%x\n", l->llc_dsap);
676                 ifp->if_noproto++;
677                 goto dropanyway;
678                 break;
679         }
680
681         netisr_dispatch(isr, m);
682         return;
683
684 dropanyway:
685         ifp->if_iqdrops++;
686         if (m)
687                 m_freem(m);
688         return;
689 }
690
691 static int
692 iso88025_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                 }
714                 *llsa = 0;
715                 return (0);
716
717 #ifdef INET
718         case AF_INET:
719                 sin = (struct sockaddr_in *)sa;
720                 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
721                         return (EADDRNOTAVAIL);
722                 }
723                 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
724                        M_NOWAIT|M_ZERO);
725                 if (sdl == NULL)
726                         return (ENOMEM);
727                 sdl->sdl_len = sizeof *sdl;
728                 sdl->sdl_family = AF_LINK;
729                 sdl->sdl_index = ifp->if_index;
730                 sdl->sdl_type = IFT_ISO88025;
731                 sdl->sdl_alen = ISO88025_ADDR_LEN;
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                 }
753                 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
754                        M_NOWAIT|M_ZERO);
755                 if (sdl == NULL)
756                         return (ENOMEM);
757                 sdl->sdl_len = sizeof *sdl;
758                 sdl->sdl_family = AF_LINK;
759                 sdl->sdl_index = ifp->if_index;
760                 sdl->sdl_type = IFT_ISO88025;
761                 sdl->sdl_alen = ISO88025_ADDR_LEN;
762                 e_addr = LLADDR(sdl);
763                 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
764                 *llsa = (struct sockaddr *)sdl;
765                 return (0);
766 #endif
767
768         default:
769                 /*
770                  * Well, the text isn't quite right, but it's the name
771                  * that counts...
772                  */
773                 return (EAFNOSUPPORT);
774         }
775
776         return (0);
777 }
778
779 MALLOC_DEFINE(M_ISO88025, "arpcom", "802.5 interface internals");
780
781 static void*
782 iso88025_alloc(u_char type, struct ifnet *ifp)
783 {
784         struct arpcom   *ac;
785  
786         ac = malloc(sizeof(struct arpcom), M_ISO88025, M_WAITOK | M_ZERO);
787         ac->ac_ifp = ifp;
788
789         return (ac);
790
791
792 static void
793 iso88025_free(void *com, u_char type)
794 {
795  
796         free(com, M_ISO88025);
797 }
798  
799 static int
800 iso88025_modevent(module_t mod, int type, void *data)
801 {
802   
803         switch (type) {
804         case MOD_LOAD:
805                 if_register_com_alloc(IFT_ISO88025, iso88025_alloc,
806                     iso88025_free);
807                 break;
808         case MOD_UNLOAD:
809                 if_deregister_com_alloc(IFT_ISO88025);
810                 break;
811         default:
812                 return EOPNOTSUPP;
813         }
814
815         return (0);
816 }
817
818 static moduledata_t iso88025_mod = {
819         "iso88025",
820         iso88025_modevent,
821         0
822 };
823
824 DECLARE_MODULE(iso88025, iso88025_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
825 MODULE_VERSION(iso88025, 1);