root/net/raw_cb.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. raw_attach
  2. raw_detach
  3. raw_disconnect
  4. raw_bind

    1 /*      $OpenBSD: raw_cb.c,v 1.5 2003/12/10 07:22:42 itojun Exp $       */
    2 /*      $NetBSD: raw_cb.c,v 1.9 1996/02/13 22:00:39 christos Exp $      */
    3 
    4 /*
    5  * Copyright (c) 1980, 1986, 1993
    6  *      The Regents of the University of California.  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. Neither the name of the University nor the names of its contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  *      @(#)raw_cb.c    8.1 (Berkeley) 6/10/93
   33  */
   34 
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/mbuf.h>
   38 #include <sys/socket.h>
   39 #include <sys/socketvar.h>
   40 #include <sys/domain.h>
   41 #include <sys/protosw.h>
   42 #include <sys/errno.h>
   43 
   44 #include <net/if.h>
   45 #include <net/route.h>
   46 #include <net/raw_cb.h>
   47 #include <netinet/in.h>
   48 
   49 /*
   50  * Routines to manage the raw protocol control blocks. 
   51  *
   52  * TODO:
   53  *      hash lookups by protocol family/protocol + address family
   54  *      take care of unique address problems per AF?
   55  *      redo address binding to allow wildcards
   56  */
   57 
   58 u_long  raw_sendspace = RAWSNDQ;
   59 u_long  raw_recvspace = RAWRCVQ;
   60 struct rawcbhead rawcb;
   61 
   62 /*
   63  * Allocate a control block and a nominal amount
   64  * of buffer space for the socket.
   65  */
   66 int
   67 raw_attach(so, proto)
   68         struct socket *so;
   69         int proto;
   70 {
   71         struct rawcb *rp = sotorawcb(so);
   72         int error;
   73 
   74         /*
   75          * It is assumed that raw_attach is called
   76          * after space has been allocated for the
   77          * rawcb.
   78          */
   79         if (rp == 0)
   80                 return (ENOBUFS);
   81         if ((error = soreserve(so, raw_sendspace, raw_recvspace)) != 0)
   82                 return (error);
   83         rp->rcb_socket = so;
   84         rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
   85         rp->rcb_proto.sp_protocol = proto;
   86         LIST_INSERT_HEAD(&rawcb, rp, rcb_list);
   87         return (0);
   88 }
   89 
   90 /*
   91  * Detach the raw connection block and discard
   92  * socket resources.
   93  */
   94 void
   95 raw_detach(rp)
   96         struct rawcb *rp;
   97 {
   98         struct socket *so = rp->rcb_socket;
   99 
  100         so->so_pcb = 0;
  101         sofree(so);
  102         LIST_REMOVE(rp, rcb_list);
  103 #ifdef notdef
  104         if (rp->rcb_laddr)
  105                 m_freem(dtom(rp->rcb_laddr));
  106         rp->rcb_laddr = 0;
  107 #endif
  108         free((caddr_t)(rp), M_PCB);
  109 }
  110 
  111 /*
  112  * Disconnect and possibly release resources.
  113  */
  114 void
  115 raw_disconnect(rp)
  116         struct rawcb *rp;
  117 {
  118 
  119 #ifdef notdef
  120         if (rp->rcb_faddr)
  121                 m_freem(dtom(rp->rcb_faddr));
  122         rp->rcb_faddr = 0;
  123 #endif
  124         if (rp->rcb_socket->so_state & SS_NOFDREF)
  125                 raw_detach(rp);
  126 }
  127 
  128 #ifdef notdef
  129 int
  130 raw_bind(so, nam)
  131         struct socket *so;
  132         struct mbuf *nam;
  133 {
  134         struct sockaddr *addr = mtod(nam, struct sockaddr *);
  135         struct rawcb *rp;
  136 
  137         if (ifnet == 0)
  138                 return (EADDRNOTAVAIL);
  139         rp = sotorawcb(so);
  140         nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
  141         rp->rcb_laddr = mtod(nam, struct sockaddr *);
  142         return (0);
  143 }
  144 #endif

/* [<][>][^][v][top][bottom][index][help] */