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/raw_cb.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1980, 1986, 1993
    3  *      The Regents of the University of California.
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 4. Neither the name of the University nor the names of its contributors
   15  *    may be used to endorse or promote products derived from this software
   16  *    without specific prior written permission.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28  * SUCH DAMAGE.
   29  *
   30  *      @(#)raw_cb.c    8.1 (Berkeley) 6/10/93
   31  * $FreeBSD$
   32  */
   33 
   34 #include <sys/param.h>
   35 #include <sys/domain.h>
   36 #include <sys/lock.h>
   37 #include <sys/kernel.h>
   38 #include <sys/malloc.h>
   39 #include <sys/mutex.h>
   40 #include <sys/protosw.h>
   41 #include <sys/socket.h>
   42 #include <sys/socketvar.h>
   43 #include <sys/sysctl.h>
   44 #include <sys/systm.h>
   45 
   46 #include <net/if.h>
   47 #include <net/raw_cb.h>
   48 #include <net/vnet.h>
   49 
   50 /*
   51  * Routines to manage the raw protocol control blocks.
   52  *
   53  * TODO:
   54  *      hash lookups by protocol family/protocol + address family
   55  *      take care of unique address problems per AF?
   56  *      redo address binding to allow wildcards
   57  */
   58 
   59 struct mtx rawcb_mtx;
   60 VNET_DEFINE(struct rawcb_list_head, rawcb_list);
   61 
   62 SYSCTL_NODE(_net, OID_AUTO, raw, CTLFLAG_RW, 0, "Raw socket infrastructure");
   63 
   64 static u_long   raw_sendspace = RAWSNDQ;
   65 SYSCTL_ULONG(_net_raw, OID_AUTO, sendspace, CTLFLAG_RW, &raw_sendspace, 0,
   66     "Default raw socket send space");
   67 
   68 static u_long   raw_recvspace = RAWRCVQ;
   69 SYSCTL_ULONG(_net_raw, OID_AUTO, recvspace, CTLFLAG_RW, &raw_recvspace, 0,
   70     "Default raw socket receive space");
   71 
   72 /*
   73  * Allocate a control block and a nominal amount of buffer space for the
   74  * socket.
   75  */
   76 int
   77 raw_attach(struct socket *so, int proto)
   78 {
   79         struct rawcb *rp = sotorawcb(so);
   80         int error;
   81 
   82         /*
   83          * It is assumed that raw_attach is called after space has been
   84          * allocated for the rawcb; consumer protocols may simply allocate
   85          * type struct rawcb, or a wrapper data structure that begins with a
   86          * struct rawcb.
   87          */
   88         KASSERT(rp != NULL, ("raw_attach: rp == NULL"));
   89 
   90         error = soreserve(so, raw_sendspace, raw_recvspace);
   91         if (error)
   92                 return (error);
   93         rp->rcb_socket = so;
   94         rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
   95         rp->rcb_proto.sp_protocol = proto;
   96         mtx_lock(&rawcb_mtx);
   97         LIST_INSERT_HEAD(&V_rawcb_list, rp, list);
   98         mtx_unlock(&rawcb_mtx);
   99         return (0);
  100 }
  101 
  102 /*
  103  * Detach the raw connection block and discard socket resources.
  104  */
  105 void
  106 raw_detach(struct rawcb *rp)
  107 {
  108         struct socket *so = rp->rcb_socket;
  109 
  110         KASSERT(so->so_pcb == rp, ("raw_detach: so_pcb != rp"));
  111 
  112         so->so_pcb = NULL;
  113         mtx_lock(&rawcb_mtx);
  114         LIST_REMOVE(rp, list);
  115         mtx_unlock(&rawcb_mtx);
  116         free((caddr_t)(rp), M_PCB);
  117 }

Cache object: 91af8451959daca7b32348ad3e6ba77d


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