The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net/if_iso88025subr.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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: releng/7.3/sys/net/if_iso88025subr.c 184739 2008-11-06 22:11:57Z julian $
   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_check_ifnet_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_TRYWAIT);
  340                 if (m == 0)
  341                         senderr(ENOBUFS);
  342                 m = m_pullup(m, 3);
  343                 if (m == 0)
  344                         senderr(ENOBUFS);
  345                 cp = mtod(m, u_int8_t *);
  346                 *cp++ = ETHERTYPE_IPX_8022;
  347                 *cp++ = ETHERTYPE_IPX_8022;
  348                 *cp++ = LLC_UI;
  349         }
  350         break;
  351 #endif  /* IPX */
  352         case AF_UNSPEC:
  353         {
  354                 struct iso88025_sockaddr_data *sd;
  355                 /*
  356                  * For AF_UNSPEC sockaddr.sa_data must contain all of the
  357                  * mac information needed to send the packet.  This allows
  358                  * full mac, llc, and source routing function to be controlled.
  359                  * llc and source routing information must already be in the
  360                  * mbuf provided, ac/fc are set in sa_data.  sockaddr.sa_data
  361                  * should be an iso88025_sockaddr_data structure see iso88025.h
  362                  */
  363                 loop_copy = -1;
  364                 sd = (struct iso88025_sockaddr_data *)dst->sa_data;
  365                 gen_th.ac = sd->ac;
  366                 gen_th.fc = sd->fc;
  367                 (void)memcpy((caddr_t)edst, (caddr_t)sd->ether_dhost,
  368                              ISO88025_ADDR_LEN);
  369                 (void)memcpy((caddr_t)gen_th.iso88025_shost,
  370                              (caddr_t)sd->ether_shost, ISO88025_ADDR_LEN);
  371                 rif_len = 0;
  372                 break;
  373         }
  374         default:
  375                 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
  376                 senderr(EAFNOSUPPORT);
  377                 break;
  378         }
  379 
  380         /*
  381          * Add LLC header.
  382          */
  383         if (snap_type != 0) {
  384                 struct llc *l;
  385                 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
  386                 if (m == 0)
  387                         senderr(ENOBUFS);
  388                 l = mtod(m, struct llc *);
  389                 l->llc_control = LLC_UI;
  390                 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
  391                 l->llc_snap.org_code[0] =
  392                         l->llc_snap.org_code[1] =
  393                         l->llc_snap.org_code[2] = 0;
  394                 l->llc_snap.ether_type = htons(snap_type);
  395         }
  396 
  397         /*
  398          * Add local net header.  If no space in first mbuf,
  399          * allocate another.
  400          */
  401         M_PREPEND(m, ISO88025_HDR_LEN + rif_len, M_DONTWAIT);
  402         if (m == 0)
  403                 senderr(ENOBUFS);
  404         th = mtod(m, struct iso88025_header *);
  405         bcopy((caddr_t)edst, (caddr_t)&gen_th.iso88025_dhost, ISO88025_ADDR_LEN);
  406 
  407         /* Copy as much of the generic header as is needed into the mbuf */
  408         memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len);
  409 
  410         /*
  411          * If a simplex interface, and the packet is being sent to our
  412          * Ethernet address or a broadcast address, loopback a copy.
  413          * XXX To make a simplex device behave exactly like a duplex
  414          * device, we should copy in the case of sending to our own
  415          * ethernet address (thus letting the original actually appear
  416          * on the wire). However, we don't do that here for security
  417          * reasons and compatibility with the original behavior.
  418          */     
  419         if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
  420                 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { 
  421                         struct mbuf *n;
  422                         n = m_copy(m, 0, (int)M_COPYALL);
  423                         (void) if_simloop(ifp, n, dst->sa_family,
  424                                           ISO88025_HDR_LEN);
  425                 } else if (bcmp(th->iso88025_dhost, th->iso88025_shost,
  426                                  ETHER_ADDR_LEN) == 0) {
  427                         (void) if_simloop(ifp, m, dst->sa_family,
  428                                           ISO88025_HDR_LEN);
  429                         return(0);      /* XXX */
  430                 }       
  431         }      
  432 
  433         IFQ_HANDOFF_ADJ(ifp, m, ISO88025_HDR_LEN + LLC_SNAPFRAMELEN, error);
  434         if (error) {
  435                 printf("iso88025_output: packet dropped QFULL.\n");
  436                 ifp->if_oerrors++;
  437         }
  438         return (error);
  439 
  440 bad:
  441         ifp->if_oerrors++;
  442         if (m)
  443                 m_freem(m);
  444         return (error);
  445 }
  446 
  447 /*
  448  * ISO 88025 de-encapsulation
  449  */
  450 void
  451 iso88025_input(ifp, m)
  452         struct ifnet *ifp;
  453         struct mbuf *m;
  454 {
  455         struct iso88025_header *th;
  456         struct llc *l;
  457         int isr;
  458         int mac_hdr_len;
  459 
  460         /*
  461          * Do consistency checks to verify assumptions
  462          * made by code past this point.
  463          */
  464         if ((m->m_flags & M_PKTHDR) == 0) {
  465                 if_printf(ifp, "discard frame w/o packet header\n");
  466                 ifp->if_ierrors++;
  467                 m_freem(m);
  468                 return;
  469         }
  470         if (m->m_pkthdr.rcvif == NULL) {
  471                 if_printf(ifp, "discard frame w/o interface pointer\n");
  472                 ifp->if_ierrors++;
  473                 m_freem(m);
  474                 return;
  475         }
  476 
  477         m = m_pullup(m, ISO88025_HDR_LEN);
  478         if (m == NULL) {
  479                 ifp->if_ierrors++;
  480                 goto dropanyway;
  481         }
  482         th = mtod(m, struct iso88025_header *);
  483         m->m_pkthdr.header = (void *)th;
  484 
  485         /*
  486          * Discard packet if interface is not up.
  487          */
  488         if (!((ifp->if_flags & IFF_UP) &&
  489             (ifp->if_drv_flags & IFF_DRV_RUNNING)))
  490                 goto dropanyway;
  491 
  492         /*
  493          * Give bpf a chance at the packet.
  494          */
  495         BPF_MTAP(ifp, m);
  496 
  497         /*
  498          * Interface marked for monitoring; discard packet.
  499          */
  500         if (ifp->if_flags & IFF_MONITOR) {
  501                 m_freem(m);
  502                 return;
  503         }
  504 
  505 #ifdef MAC
  506         mac_create_mbuf_from_ifnet(ifp, m);
  507 #endif
  508 
  509         /*
  510          * Update interface statistics.
  511          */
  512         ifp->if_ibytes += m->m_pkthdr.len;
  513         getmicrotime(&ifp->if_lastchange);
  514 
  515         /*
  516          * Discard non local unicast packets when interface
  517          * is in promiscuous mode.
  518          */
  519         if ((ifp->if_flags & IFF_PROMISC) &&
  520             ((th->iso88025_dhost[0] & 1) == 0) &&
  521              (bcmp(IF_LLADDR(ifp), (caddr_t) th->iso88025_dhost,
  522              ISO88025_ADDR_LEN) != 0))
  523                 goto dropanyway;
  524 
  525         /*
  526          * Set mbuf flags for bcast/mcast.
  527          */
  528         if (th->iso88025_dhost[0] & 1) {
  529                 if (bcmp(iso88025_broadcastaddr, th->iso88025_dhost,
  530                     ISO88025_ADDR_LEN) == 0)
  531                         m->m_flags |= M_BCAST;
  532                 else
  533                         m->m_flags |= M_MCAST;
  534                 ifp->if_imcasts++;
  535         }
  536 
  537         mac_hdr_len = ISO88025_HDR_LEN;
  538         /* Check for source routing info */
  539         if (th->iso88025_shost[0] & TR_RII)
  540                 mac_hdr_len += TR_RCF_RIFLEN(th->rcf);
  541 
  542         /* Strip off ISO88025 header. */
  543         m_adj(m, mac_hdr_len);
  544 
  545         m = m_pullup(m, LLC_SNAPFRAMELEN);
  546         if (m == 0) {
  547                 ifp->if_ierrors++;
  548                 goto dropanyway;
  549         }
  550         l = mtod(m, struct llc *);
  551 
  552         switch (l->llc_dsap) {
  553 #ifdef IPX
  554         case ETHERTYPE_IPX_8022:        /* Thanks a bunch Novell */
  555                 if ((l->llc_control != LLC_UI) ||
  556                     (l->llc_ssap != ETHERTYPE_IPX_8022)) {
  557                         ifp->if_noproto++;
  558                         goto dropanyway;
  559                 }
  560 
  561                 th->iso88025_shost[0] &= ~(TR_RII); 
  562                 m_adj(m, 3);
  563                 isr = NETISR_IPX;
  564                 break;
  565 #endif  /* IPX */
  566         case LLC_SNAP_LSAP: {
  567                 u_int16_t type;
  568                 if ((l->llc_control != LLC_UI) ||
  569                     (l->llc_ssap != LLC_SNAP_LSAP)) {
  570                         ifp->if_noproto++;
  571                         goto dropanyway;
  572                 }
  573 
  574                 if (l->llc_snap.org_code[0] != 0 ||
  575                     l->llc_snap.org_code[1] != 0 ||
  576                     l->llc_snap.org_code[2] != 0) {
  577                         ifp->if_noproto++;
  578                         goto dropanyway;
  579                 }
  580 
  581                 type = ntohs(l->llc_snap.ether_type);
  582                 m_adj(m, LLC_SNAPFRAMELEN);
  583                 switch (type) {
  584 #ifdef INET
  585                 case ETHERTYPE_IP:
  586                         th->iso88025_shost[0] &= ~(TR_RII); 
  587                         if ((m = ip_fastforward(m)) == NULL)
  588                                 return;
  589                         isr = NETISR_IP;
  590                         break;
  591 
  592                 case ETHERTYPE_ARP:
  593                         if (ifp->if_flags & IFF_NOARP)
  594                                 goto dropanyway;
  595                         isr = NETISR_ARP;
  596                         break;
  597 #endif  /* INET */
  598 #ifdef IPX_SNAP /* XXX: Not supported! */
  599                 case ETHERTYPE_IPX:
  600                         th->iso88025_shost[0] &= ~(TR_RII); 
  601                         isr = NETISR_IPX;
  602                         break;
  603 #endif  /* IPX_SNAP */
  604 #ifdef INET6
  605                 case ETHERTYPE_IPV6:
  606                         th->iso88025_shost[0] &= ~(TR_RII); 
  607                         isr = NETISR_IPV6;
  608                         break;
  609 #endif  /* INET6 */
  610                 default:
  611                         printf("iso88025_input: unexpected llc_snap ether_type  0x%02x\n", type);
  612                         ifp->if_noproto++;
  613                         goto dropanyway;
  614                 }
  615                 break;
  616         }
  617 #ifdef ISO
  618         case LLC_ISO_LSAP:
  619                 switch (l->llc_control) {
  620                 case LLC_UI:
  621                         ifp->if_noproto++;
  622                         goto dropanyway;
  623                         break;
  624                 case LLC_XID:
  625                 case LLC_XID_P:
  626                         if(m->m_len < ISO88025_ADDR_LEN)
  627                                 goto dropanyway;
  628                         l->llc_window = 0;
  629                         l->llc_fid = 9;  
  630                         l->llc_class = 1;
  631                         l->llc_dsap = l->llc_ssap = 0;
  632                         /* Fall through to */  
  633                 case LLC_TEST:
  634                 case LLC_TEST_P:
  635                 {
  636                         struct sockaddr sa;
  637                         struct arpcom *ac;
  638                         struct iso88025_sockaddr_data *th2;
  639                         int i;
  640                         u_char c;
  641 
  642                         c = l->llc_dsap;
  643 
  644                         if (th->iso88025_shost[0] & TR_RII) { /* XXX */
  645                                 printf("iso88025_input: dropping source routed LLC_TEST\n");
  646                                 goto dropanyway;
  647                         }
  648                         l->llc_dsap = l->llc_ssap;
  649                         l->llc_ssap = c;
  650                         if (m->m_flags & (M_BCAST | M_MCAST))
  651                                 bcopy((caddr_t)IF_LLADDR(ifp),
  652                                       (caddr_t)th->iso88025_dhost,
  653                                         ISO88025_ADDR_LEN);
  654                         sa.sa_family = AF_UNSPEC;
  655                         sa.sa_len = sizeof(sa);
  656                         th2 = (struct iso88025_sockaddr_data *)sa.sa_data;
  657                         for (i = 0; i < ISO88025_ADDR_LEN; i++) {
  658                                 th2->ether_shost[i] = c = th->iso88025_dhost[i];
  659                                 th2->ether_dhost[i] = th->iso88025_dhost[i] =
  660                                         th->iso88025_shost[i];
  661                                 th->iso88025_shost[i] = c;
  662                         }
  663                         th2->ac = TR_AC;
  664                         th2->fc = TR_LLC_FRAME;
  665                         ifp->if_output(ifp, m, &sa, NULL);
  666                         return;
  667                 }
  668                 default:
  669                         printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control);
  670                         ifp->if_noproto++;
  671                         goto dropanyway;
  672                         break;
  673                 }
  674                 break;
  675 #endif  /* ISO */
  676         default:
  677                 printf("iso88025_input: unknown dsap 0x%x\n", l->llc_dsap);
  678                 ifp->if_noproto++;
  679                 goto dropanyway;
  680                 break;
  681         }
  682 
  683         netisr_dispatch(isr, m);
  684         return;
  685 
  686 dropanyway:
  687         ifp->if_iqdrops++;
  688         if (m)
  689                 m_freem(m);
  690         return;
  691 }
  692 
  693 static int
  694 iso88025_resolvemulti (ifp, llsa, sa)
  695         struct ifnet *ifp;
  696         struct sockaddr **llsa;
  697         struct sockaddr *sa;
  698 {
  699         struct sockaddr_dl *sdl;
  700         struct sockaddr_in *sin;
  701 #ifdef INET6
  702         struct sockaddr_in6 *sin6;
  703 #endif
  704         u_char *e_addr;
  705 
  706         switch(sa->sa_family) {
  707         case AF_LINK:
  708                 /*
  709                  * No mapping needed. Just check that it's a valid MC address.
  710                  */
  711                 sdl = (struct sockaddr_dl *)sa;
  712                 e_addr = LLADDR(sdl);
  713                 if ((e_addr[0] & 1) != 1) {
  714                         return (EADDRNOTAVAIL);
  715                 }
  716                 *llsa = 0;
  717                 return (0);
  718 
  719 #ifdef INET
  720         case AF_INET:
  721                 sin = (struct sockaddr_in *)sa;
  722                 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
  723                         return (EADDRNOTAVAIL);
  724                 }
  725                 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
  726                        M_NOWAIT|M_ZERO);
  727                 if (sdl == NULL)
  728                         return (ENOMEM);
  729                 sdl->sdl_len = sizeof *sdl;
  730                 sdl->sdl_family = AF_LINK;
  731                 sdl->sdl_index = ifp->if_index;
  732                 sdl->sdl_type = IFT_ISO88025;
  733                 sdl->sdl_alen = ISO88025_ADDR_LEN;
  734                 e_addr = LLADDR(sdl);
  735                 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
  736                 *llsa = (struct sockaddr *)sdl;
  737                 return (0);
  738 #endif
  739 #ifdef INET6
  740         case AF_INET6:
  741                 sin6 = (struct sockaddr_in6 *)sa;
  742                 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
  743                         /*
  744                          * An IP6 address of 0 means listen to all
  745                          * of the Ethernet multicast address used for IP6.
  746                          * (This is used for multicast routers.)
  747                          */
  748                         ifp->if_flags |= IFF_ALLMULTI;
  749                         *llsa = 0;
  750                         return (0);
  751                 }
  752                 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
  753                         return (EADDRNOTAVAIL);
  754                 }
  755                 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
  756                        M_NOWAIT|M_ZERO);
  757                 if (sdl == NULL)
  758                         return (ENOMEM);
  759                 sdl->sdl_len = sizeof *sdl;
  760                 sdl->sdl_family = AF_LINK;
  761                 sdl->sdl_index = ifp->if_index;
  762                 sdl->sdl_type = IFT_ISO88025;
  763                 sdl->sdl_alen = ISO88025_ADDR_LEN;
  764                 e_addr = LLADDR(sdl);
  765                 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
  766                 *llsa = (struct sockaddr *)sdl;
  767                 return (0);
  768 #endif
  769 
  770         default:
  771                 /*
  772                  * Well, the text isn't quite right, but it's the name
  773                  * that counts...
  774                  */
  775                 return (EAFNOSUPPORT);
  776         }
  777 
  778         return (0);
  779 }
  780 
  781 MALLOC_DEFINE(M_ISO88025, "arpcom", "802.5 interface internals");
  782 
  783 static void*
  784 iso88025_alloc(u_char type, struct ifnet *ifp)
  785 {
  786         struct arpcom   *ac;
  787  
  788         ac = malloc(sizeof(struct arpcom), M_ISO88025, M_WAITOK | M_ZERO);
  789         ac->ac_ifp = ifp;
  790 
  791         return (ac);
  792 } 
  793 
  794 static void
  795 iso88025_free(void *com, u_char type)
  796 {
  797  
  798         free(com, M_ISO88025);
  799 }
  800  
  801 static int
  802 iso88025_modevent(module_t mod, int type, void *data)
  803 {
  804   
  805         switch (type) {
  806         case MOD_LOAD:
  807                 if_register_com_alloc(IFT_ISO88025, iso88025_alloc,
  808                     iso88025_free);
  809                 break;
  810         case MOD_UNLOAD:
  811                 if_deregister_com_alloc(IFT_ISO88025);
  812                 break;
  813         default:
  814                 return EOPNOTSUPP;
  815         }
  816 
  817         return (0);
  818 }
  819 
  820 static moduledata_t iso88025_mod = {
  821         "iso88025",
  822         iso88025_modevent,
  823         0
  824 };
  825 
  826 DECLARE_MODULE(iso88025, iso88025_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
  827 MODULE_VERSION(iso88025, 1);

Cache object: d22b52774f2d5f6347770f61f0da3b29


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.