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/netns/ns_output.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) 1984, 1985, 1986, 1987, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by the University of
   16  *      California, Berkeley and its contributors.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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  *      @(#)ns_output.c 8.1 (Berkeley) 6/10/93
   34  * $FreeBSD: src/sys/netns/ns_output.c,v 1.4.2.1 1999/09/05 08:19:23 peter Exp $
   35  */
   36 
   37 #include <sys/param.h>
   38 #include <sys/malloc.h>
   39 #include <sys/mbuf.h>
   40 #include <sys/errno.h>
   41 #include <sys/socket.h>
   42 #include <sys/socketvar.h>
   43 
   44 #include <net/if.h>
   45 #include <net/route.h>
   46 
   47 #include <netns/ns.h>
   48 #include <netns/ns_if.h>
   49 #include <netns/idp.h>
   50 #include <netns/idp_var.h>
   51 
   52 #ifdef vax
   53 #include <machine/mtpr.h>
   54 #endif
   55 int ns_hold_output = 0;
   56 int ns_copy_output = 0;
   57 int ns_output_cnt = 0;
   58 struct mbuf *ns_lastout;
   59 
   60 ns_output(m0, ro, flags)
   61         struct mbuf *m0;
   62         struct route *ro;
   63         int flags;
   64 {
   65         register struct idp *idp = mtod(m0, struct idp *);
   66         register struct ifnet *ifp = 0;
   67         int error = 0;
   68         struct route idproute;
   69         struct sockaddr_ns *dst;
   70         extern int idpcksum;
   71 
   72         if (ns_hold_output) {
   73                 if (ns_lastout) {
   74                         (void)m_free(ns_lastout);
   75                 }
   76                 ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
   77         }
   78         /*
   79          * Route packet.
   80          */
   81         if (ro == 0) {
   82                 ro = &idproute;
   83                 bzero((caddr_t)ro, sizeof (*ro));
   84         }
   85         dst = (struct sockaddr_ns *)&ro->ro_dst;
   86         if (ro->ro_rt == 0) {
   87                 dst->sns_family = AF_NS;
   88                 dst->sns_len = sizeof (*dst);
   89                 dst->sns_addr = idp->idp_dna;
   90                 dst->sns_addr.x_port = 0;
   91                 /*
   92                  * If routing to interface only,
   93                  * short circuit routing lookup.
   94                  */
   95                 if (flags & NS_ROUTETOIF) {
   96                         struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
   97 
   98                         if (ia == 0) {
   99                                 error = ENETUNREACH;
  100                                 goto bad;
  101                         }
  102                         ifp = ia->ia_ifp;
  103                         goto gotif;
  104                 }
  105                 rtalloc(ro);
  106         } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
  107                 /*
  108                  * The old route has gone away; try for a new one.
  109                  */
  110                 rtfree(ro->ro_rt);
  111                 ro->ro_rt = NULL;
  112                 rtalloc(ro);
  113         }
  114         if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
  115                 error = ENETUNREACH;
  116                 goto bad;
  117         }
  118         ro->ro_rt->rt_use++;
  119         if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
  120                 dst = (struct sockaddr_ns *)ro->ro_rt->rt_gateway;
  121 gotif:
  122 
  123         /*
  124          * Look for multicast addresses and
  125          * and verify user is allowed to send
  126          * such a packet.
  127          */
  128         if (dst->sns_addr.x_host.c_host[0]&1) {
  129                 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
  130                         error = EADDRNOTAVAIL;
  131                         goto bad;
  132                 }
  133                 if ((flags & NS_ALLOWBROADCAST) == 0) {
  134                         error = EACCES;
  135                         goto bad;
  136                 }
  137         }
  138 
  139         if (htons(idp->idp_len) <= ifp->if_mtu) {
  140                 ns_output_cnt++;
  141                 if (ns_copy_output) {
  142                         ns_watch_output(m0, ifp);
  143                 }
  144                 error = (*ifp->if_output)(ifp, m0,
  145                                         (struct sockaddr *)dst, ro->ro_rt);
  146                 goto done;
  147         } else error = EMSGSIZE;
  148 
  149 
  150 bad:
  151         if (ns_copy_output) {
  152                 ns_watch_output(m0, ifp);
  153         }
  154         m_freem(m0);
  155 done:
  156         if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt) {
  157                 RTFREE(ro->ro_rt);
  158                 ro->ro_rt = 0;
  159         }
  160         return (error);
  161 }

Cache object: b924925ff78b2421ceb9c5f964d2c23a


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