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/netinet/if_atm.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 /*      $NetBSD: if_atm.c,v 1.29 2008/10/24 17:07:33 dyoung Exp $       */
    2 
    3 /*
    4  *
    5  * Copyright (c) 1996 Charles D. Cranor and Washington University.
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Charles D. Cranor and
   19  *      Washington University.
   20  * 4. The name of the author may not be used to endorse or promote products
   21  *    derived from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33  */
   34 
   35 /*
   36  * IP <=> ATM address resolution.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: if_atm.c,v 1.29 2008/10/24 17:07:33 dyoung Exp $");
   41 
   42 #include "opt_inet.h"
   43 #include "opt_natm.h"
   44 
   45 #if defined(INET) || defined(INET6)
   46 
   47 #include <sys/param.h>
   48 #include <sys/systm.h>
   49 #include <sys/malloc.h>
   50 #include <sys/mbuf.h>
   51 #include <sys/socket.h>
   52 #include <sys/time.h>
   53 #include <sys/kernel.h>
   54 #include <sys/errno.h>
   55 #include <sys/ioctl.h>
   56 #include <sys/syslog.h>
   57 #include <sys/proc.h>
   58 
   59 #include <net/if.h>
   60 #include <net/if_dl.h>
   61 #include <net/route.h>
   62 #include <net/if_atm.h>
   63 
   64 #include <netinet/in.h>
   65 #include <netinet/in_systm.h>
   66 #include <netinet/in_var.h>
   67 #include <netinet/ip.h>
   68 #include <netinet/if_atm.h>
   69 
   70 #ifdef NATM
   71 #include <netnatm/natm.h>
   72 #endif
   73 
   74 
   75 /*
   76  * atm_rtrequest: handle ATM rt request (in support of generic code)
   77  *   inputs: "req" = request code
   78  *           "rt" = route entry
   79  *           "sa" = sockaddr
   80  */
   81 
   82 void
   83 atm_rtrequest(int req, struct rtentry *rt, const struct rt_addrinfo *info)
   84 {
   85         struct sockaddr *gate = rt->rt_gateway;
   86         struct atm_pseudoioctl api;
   87 #ifdef NATM
   88         const struct sockaddr_in *sin;
   89         struct natmpcb *npcb = NULL;
   90         const struct atm_pseudohdr *aph;
   91 #endif
   92         const struct ifnet *ifp = rt->rt_ifp;
   93         uint8_t namelen = strlen(ifp->if_xname);
   94         uint8_t addrlen = ifp->if_addrlen;
   95 
   96         if (rt->rt_flags & RTF_GATEWAY)   /* link level requests only */
   97                 return;
   98 
   99         switch (req) {
  100 
  101         case RTM_RESOLVE: /* resolve: only happens when cloning */
  102                 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
  103                 break;
  104 
  105         case RTM_ADD:
  106 
  107                 /*
  108                  * route added by a command (e.g. ifconfig, route, arp...).
  109                  *
  110                  * first check to see if this is not a host route, in which
  111                  * case we are being called via "ifconfig" to set the address.
  112                  */
  113 
  114                 if ((rt->rt_flags & RTF_HOST) == 0) {
  115                         union {
  116                                 struct sockaddr sa;
  117                                 struct sockaddr_dl sdl;
  118                                 struct sockaddr_storage ss;
  119                         } u;
  120 
  121                         sockaddr_dl_init(&u.sdl, sizeof(u.ss),
  122                             ifp->if_index, ifp->if_type,
  123                             NULL, namelen, NULL, addrlen);
  124                         rt_setgate(rt, &u.sa);
  125                         gate = rt->rt_gateway;
  126                         break;
  127                 }
  128 
  129                 if ((rt->rt_flags & RTF_CLONING) != 0) {
  130                         printf("atm_rtrequest: cloning route detected?\n");
  131                         break;
  132                 }
  133                 if (gate->sa_family != AF_LINK ||
  134                     gate->sa_len < sockaddr_dl_measure(namelen, addrlen)) {
  135                         log(LOG_DEBUG, "atm_rtrequest: bad gateway value");
  136                         break;
  137                 }
  138 
  139 #ifdef DIAGNOSTIC
  140                 if (rt->rt_ifp->if_ioctl == NULL) panic("atm null ioctl");
  141 #endif
  142 
  143 #ifdef NATM
  144                 /*
  145                  * let native ATM know we are using this VCI/VPI
  146                  * (i.e. reserve it)
  147                  */
  148                 sin = satocsin(rt_getkey(rt));
  149                 if (sin->sin_family != AF_INET)
  150                         goto failed;
  151                 aph = (const struct atm_pseudohdr *)CLLADDR(satosdl(gate));
  152                 npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph),
  153                                                 ATM_PH_VPI(aph));
  154                 if (npcb == NULL)
  155                         goto failed;
  156                 npcb->npcb_flags |= NPCB_IP;
  157                 npcb->ipaddr.s_addr = sin->sin_addr.s_addr;
  158                 /* XXX: move npcb to llinfo when ATM ARP is ready */
  159                 rt->rt_llinfo = (void *) npcb;
  160                 rt->rt_flags |= RTF_LLINFO;
  161 #endif
  162                 /*
  163                  * let the lower level know this circuit is active
  164                  */
  165                 bcopy(CLLADDR(satocsdl(gate)), &api.aph, sizeof(api.aph));
  166                 api.rxhand = NULL;
  167                 if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, &api) != 0) {
  168                         printf("atm: couldn't add VC\n");
  169                         goto failed;
  170                 }
  171 
  172                 satosdl(gate)->sdl_type = rt->rt_ifp->if_type;
  173                 satosdl(gate)->sdl_index = rt->rt_ifp->if_index;
  174 
  175                 break;
  176 
  177 failed:
  178 #ifdef NATM
  179                 if (npcb) {
  180                         npcb_free(npcb, NPCB_DESTROY);
  181                         rt->rt_llinfo = NULL;
  182                         rt->rt_flags &= ~RTF_LLINFO;
  183                 }
  184 #endif
  185                 rtrequest(RTM_DELETE, rt_getkey(rt), NULL,
  186                         rt_mask(rt), 0, NULL);
  187                 break;
  188 
  189         case RTM_DELETE:
  190 
  191 #ifdef NATM
  192                 /*
  193                  * tell native ATM we are done with this VC
  194                  */
  195 
  196                 if (rt->rt_flags & RTF_LLINFO) {
  197                         npcb_free((struct natmpcb *)rt->rt_llinfo,
  198                                                                 NPCB_DESTROY);
  199                         rt->rt_llinfo = NULL;
  200                         rt->rt_flags &= ~RTF_LLINFO;
  201                 }
  202 #endif
  203                 /*
  204                  * tell the lower layer to disable this circuit
  205                  */
  206 
  207                 bcopy(CLLADDR(satocsdl(gate)), &api.aph, sizeof(api.aph));
  208                 api.rxhand = NULL;
  209                 (void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS, &api);
  210 
  211                 break;
  212         }
  213 }
  214 
  215 /*
  216  * atmresolve:
  217  *   inputs:
  218  *     [1] "rt" = the link level route to use (or null if need to look one up)
  219  *     [2] "m" = mbuf containing the data to be sent
  220  *     [3] "dst" = sockaddr_in (IP) address of dest.
  221  *   output:
  222  *     [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
  223  *   return:
  224  *     0 == resolve FAILED; note that "m" gets m_freem'd in this case
  225  *     1 == resolve OK; desten contains result
  226  *
  227  *   XXX: will need more work if we wish to support ATMARP in the kernel,
  228  *   but this is enough for PVCs entered via the "route" command.
  229  */
  230 
  231 int
  232 atmresolve(struct rtentry *rt, struct mbuf *m, const struct sockaddr *dst,
  233     struct atm_pseudohdr *desten /* OUT */)
  234 {
  235         const struct sockaddr_dl *sdl;
  236 
  237         if (m->m_flags & (M_BCAST|M_MCAST)) {
  238                 log(LOG_INFO, "atmresolve: BCAST/MCAST packet detected/dumped");
  239                 goto bad;
  240         }
  241 
  242         if (rt == NULL) {
  243                 rt = RTALLOC1(dst, 0);
  244                 if (rt == NULL) goto bad; /* failed */
  245                 rt->rt_refcnt--;        /* don't keep LL references */
  246                 if ((rt->rt_flags & RTF_GATEWAY) != 0 ||
  247                         (rt->rt_flags & RTF_LLINFO) == 0 ||
  248                         /* XXX: are we using LLINFO? */
  249                         rt->rt_gateway->sa_family != AF_LINK) {
  250                                 goto bad;
  251                 }
  252         }
  253 
  254         /*
  255          * note that rt_gateway is a sockaddr_dl which contains the
  256          * atm_pseudohdr data structure for this route.   we currently
  257          * don't need any rt_llinfo info (but will if we want to support
  258          * ATM ARP [c.f. if_ether.c]).
  259          */
  260 
  261         sdl = satocsdl(rt->rt_gateway);
  262 
  263         /*
  264          * Check the address family and length is valid, the address
  265          * is resolved; otherwise, try to resolve.
  266          */
  267 
  268 
  269         if (sdl->sdl_family == AF_LINK && sdl->sdl_alen == sizeof(*desten)) {
  270                 bcopy(CLLADDR(sdl), desten, sdl->sdl_alen);
  271                 return (1);     /* ok, go for it! */
  272         }
  273 
  274         /*
  275          * we got an entry, but it doesn't have valid link address
  276          * info in it (it is prob. the interface route, which has
  277          * sdl_alen == 0).    dump packet.  (fall through to "bad").
  278          */
  279 
  280 bad:
  281         m_freem(m);
  282         return (0);
  283 }
  284 #endif /* INET */

Cache object: 3802121aca41bee0db697287a6f7c940


[ 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.