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.21 2006/11/16 01:33:45 christos 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.21 2006/11/16 01:33:45 christos 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 #define SDL(s) ((struct sockaddr_dl *)s)
   76 
   77 /*
   78  * atm_rtrequest: handle ATM rt request (in support of generic code)
   79  *   inputs: "req" = request code
   80  *           "rt" = route entry
   81  *           "sa" = sockaddr
   82  */
   83 
   84 void
   85 atm_rtrequest(int req, struct rtentry *rt, struct rt_addrinfo *info)
   86 {
   87         struct sockaddr *gate = rt->rt_gateway;
   88         struct atm_pseudoioctl api;
   89 #ifdef NATM
   90         struct sockaddr_in *sin;
   91         struct natmpcb *npcb = NULL;
   92         struct atm_pseudohdr *aph;
   93 #endif
   94         static const struct sockaddr_dl null_sdl = {
   95                 .sdl_len = sizeof(null_sdl),
   96                 .sdl_family = AF_LINK,
   97         };
   98 
   99         if (rt->rt_flags & RTF_GATEWAY)   /* link level requests only */
  100                 return;
  101 
  102         switch (req) {
  103 
  104         case RTM_RESOLVE: /* resolve: only happens when cloning */
  105                 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
  106                 break;
  107 
  108         case RTM_ADD:
  109 
  110                 /*
  111                  * route added by a command (e.g. ifconfig, route, arp...).
  112                  *
  113                  * first check to see if this is not a host route, in which
  114                  * case we are being called via "ifconfig" to set the address.
  115                  */
  116 
  117                 if ((rt->rt_flags & RTF_HOST) == 0) {
  118                         rt_setgate(rt, rt_key(rt),
  119                             (const struct sockaddr *)&null_sdl);
  120                         gate = rt->rt_gateway;
  121                         SDL(gate)->sdl_type = rt->rt_ifp->if_type;
  122                         SDL(gate)->sdl_index = rt->rt_ifp->if_index;
  123                         break;
  124                 }
  125 
  126                 if ((rt->rt_flags & RTF_CLONING) != 0) {
  127                         printf("atm_rtrequest: cloning route detected?\n");
  128                         break;
  129                 }
  130                 if (gate->sa_family != AF_LINK ||
  131                     gate->sa_len < sizeof(null_sdl)) {
  132                         log(LOG_DEBUG, "atm_rtrequest: bad gateway value");
  133                         break;
  134                 }
  135 
  136 #ifdef DIAGNOSTIC
  137                 if (rt->rt_ifp->if_ioctl == NULL) panic("atm null ioctl");
  138 #endif
  139 
  140 #ifdef NATM
  141                 /*
  142                  * let native ATM know we are using this VCI/VPI
  143                  * (i.e. reserve it)
  144                  */
  145                 sin = (struct sockaddr_in *) rt_key(rt);
  146                 if (sin->sin_family != AF_INET)
  147                         goto failed;
  148                 aph = (struct atm_pseudohdr *) LLADDR(SDL(gate));
  149                 npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph),
  150                                                 ATM_PH_VPI(aph));
  151                 if (npcb == NULL)
  152                         goto failed;
  153                 npcb->npcb_flags |= NPCB_IP;
  154                 npcb->ipaddr.s_addr = sin->sin_addr.s_addr;
  155                 /* XXX: move npcb to llinfo when ATM ARP is ready */
  156                 rt->rt_llinfo = (caddr_t) npcb;
  157                 rt->rt_flags |= RTF_LLINFO;
  158 #endif
  159                 /*
  160                  * let the lower level know this circuit is active
  161                  */
  162                 bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph));
  163                 api.rxhand = NULL;
  164                 if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA,
  165                                                         (caddr_t)&api) != 0) {
  166                         printf("atm: couldn't add VC\n");
  167                         goto failed;
  168                 }
  169 
  170                 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
  171                 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
  172 
  173                 break;
  174 
  175 failed:
  176 #ifdef NATM
  177                 if (npcb) {
  178                         npcb_free(npcb, NPCB_DESTROY);
  179                         rt->rt_llinfo = NULL;
  180                         rt->rt_flags &= ~RTF_LLINFO;
  181                 }
  182 #endif
  183                 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
  184                         rt_mask(rt), 0, (struct rtentry **) 0);
  185                 break;
  186 
  187         case RTM_DELETE:
  188 
  189 #ifdef NATM
  190                 /*
  191                  * tell native ATM we are done with this VC
  192                  */
  193 
  194                 if (rt->rt_flags & RTF_LLINFO) {
  195                         npcb_free((struct natmpcb *)rt->rt_llinfo,
  196                                                                 NPCB_DESTROY);
  197                         rt->rt_llinfo = NULL;
  198                         rt->rt_flags &= ~RTF_LLINFO;
  199                 }
  200 #endif
  201                 /*
  202                  * tell the lower layer to disable this circuit
  203                  */
  204 
  205                 bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph));
  206                 api.rxhand = NULL;
  207                 (void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS,
  208                                                         (caddr_t)&api);
  209 
  210                 break;
  211         }
  212 }
  213 
  214 /*
  215  * atmresolve:
  216  *   inputs:
  217  *     [1] "rt" = the link level route to use (or null if need to look one up)
  218  *     [2] "m" = mbuf containing the data to be sent
  219  *     [3] "dst" = sockaddr_in (IP) address of dest.
  220  *   output:
  221  *     [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
  222  *   return:
  223  *     0 == resolve FAILED; note that "m" gets m_freem'd in this case
  224  *     1 == resolve OK; desten contains result
  225  *
  226  *   XXX: will need more work if we wish to support ATMARP in the kernel,
  227  *   but this is enough for PVCs entered via the "route" command.
  228  */
  229 
  230 int
  231 atmresolve(struct rtentry *rt, struct mbuf *m, struct sockaddr *dst,
  232     struct atm_pseudohdr *desten /* OUT */)
  233 {
  234         struct sockaddr_dl *sdl;
  235 
  236         if (m->m_flags & (M_BCAST|M_MCAST)) {
  237                 log(LOG_INFO, "atmresolve: BCAST/MCAST packet detected/dumped");
  238                 goto bad;
  239         }
  240 
  241         if (rt == NULL) {
  242                 rt = RTALLOC1(dst, 0);
  243                 if (rt == NULL) goto bad; /* failed */
  244                 rt->rt_refcnt--;        /* don't keep LL references */
  245                 if ((rt->rt_flags & RTF_GATEWAY) != 0 ||
  246                         (rt->rt_flags & RTF_LLINFO) == 0 ||
  247                         /* XXX: are we using LLINFO? */
  248                         rt->rt_gateway->sa_family != AF_LINK) {
  249                                 goto bad;
  250                 }
  251         }
  252 
  253         /*
  254          * note that rt_gateway is a sockaddr_dl which contains the
  255          * atm_pseudohdr data structure for this route.   we currently
  256          * don't need any rt_llinfo info (but will if we want to support
  257          * ATM ARP [c.f. if_ether.c]).
  258          */
  259 
  260         sdl = SDL(rt->rt_gateway);
  261 
  262         /*
  263          * Check the address family and length is valid, the address
  264          * is resolved; otherwise, try to resolve.
  265          */
  266 
  267 
  268         if (sdl->sdl_family == AF_LINK && sdl->sdl_alen == sizeof(*desten)) {
  269                 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
  270                 return (1);     /* ok, go for it! */
  271         }
  272 
  273         /*
  274          * we got an entry, but it doesn't have valid link address
  275          * info in it (it is prob. the interface route, which has
  276          * sdl_alen == 0).    dump packet.  (fall through to "bad").
  277          */
  278 
  279 bad:
  280         m_freem(m);
  281         return (0);
  282 }
  283 #endif /* INET */

Cache object: 88429e9d442769d76636d9ae974ddba3


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