raw_cb.c revision 3443
1139749Simp/* 250702Swpaul * Copyright (c) 1980, 1986, 1993 350702Swpaul * The Regents of the University of California. All rights reserved. 450702Swpaul * 550702Swpaul * Redistribution and use in source and binary forms, with or without 650702Swpaul * modification, are permitted provided that the following conditions 750702Swpaul * are met: 850702Swpaul * 1. Redistributions of source code must retain the above copyright 950702Swpaul * notice, this list of conditions and the following disclaimer. 1050702Swpaul * 2. Redistributions in binary form must reproduce the above copyright 1150702Swpaul * notice, this list of conditions and the following disclaimer in the 1250702Swpaul * documentation and/or other materials provided with the distribution. 1350702Swpaul * 3. All advertising materials mentioning features or use of this software 1450702Swpaul * must display the following acknowledgement: 1550702Swpaul * This product includes software developed by the University of 1650702Swpaul * California, Berkeley and its contributors. 1750702Swpaul * 4. Neither the name of the University nor the names of its contributors 1850702Swpaul * may be used to endorse or promote products derived from this software 1950702Swpaul * without specific prior written permission. 2050702Swpaul * 2150702Swpaul * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2250702Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2350702Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2450702Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2550702Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2650702Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2750702Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2850702Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2950702Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3050702Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3150702Swpaul * SUCH DAMAGE. 3250702Swpaul * 33119418Sobrien * @(#)raw_cb.c 8.1 (Berkeley) 6/10/93 34119418Sobrien * $Id: raw_cb.c,v 1.2 1994/08/02 07:46:34 davidg Exp $ 35119418Sobrien */ 3650702Swpaul 3750702Swpaul#include <sys/param.h> 3850702Swpaul#include <sys/systm.h> 3950702Swpaul#include <sys/mbuf.h> 4050702Swpaul#include <sys/socket.h> 4150702Swpaul#include <sys/socketvar.h> 4250702Swpaul#include <sys/domain.h> 43129876Sphk#include <sys/protosw.h> 4450702Swpaul#include <sys/errno.h> 4550702Swpaul 46257184Sglebius#include <net/if.h> 4750702Swpaul#include <net/route.h> 4850702Swpaul#include <net/raw_cb.h> 4994149Swpaul#include <netinet/in.h> 5050702Swpaul 5150702Swpaul/* 5250702Swpaul * Routines to manage the raw protocol control blocks. 5350702Swpaul * 54109514Sobrien * TODO: 5550702Swpaul * hash lookups by protocol family/protocol + address family 5694149Swpaul * take care of unique address problems per AF? 5794149Swpaul * redo address binding to allow wildcards 5894149Swpaul */ 5950702Swpaul 6050702Swpaulu_long raw_sendspace = RAWSNDQ; 61105135Salfredu_long raw_recvspace = RAWRCVQ; 62105135Salfred 6350702Swpaul/* 6450702Swpaul * Allocate a control block and a nominal amount 6550702Swpaul * of buffer space for the socket. 6650702Swpaul */ 6750702Swpaulint 6895722Sphkraw_attach(so, proto) 6950702Swpaul register struct socket *so; 70227908Smarius int proto; 7150702Swpaul{ 7250702Swpaul register struct rawcb *rp = sotorawcb(so); 7350702Swpaul int error; 7450702Swpaul 7550702Swpaul /* 7650702Swpaul * It is assumed that raw_attach is called 7750702Swpaul * after space has been allocated for the 78221407Smarius * rawcb. 7950702Swpaul */ 8050702Swpaul if (rp == 0) 8150702Swpaul return (ENOBUFS); 8250702Swpaul error = soreserve(so, raw_sendspace, raw_recvspace); 8392739Salfred if (error) 8494149Swpaul return (error); 8550702Swpaul rp->rcb_socket = so; 86165991Smarius rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family; 87165991Smarius rp->rcb_proto.sp_protocol = proto; 88165991Smarius insque(rp, &rawcb); 89165991Smarius return (0); 90165991Smarius} 91165991Smarius 92165991Smarius/* 93165991Smarius * Detach the raw connection block and discard 94165991Smarius * socket resources. 95164827Smarius */ 96221407Smariusvoid 97221407Smariusraw_detach(rp) 98221407Smarius register struct rawcb *rp; 99164827Smarius{ 100164827Smarius struct socket *so = rp->rcb_socket; 101164827Smarius 102221407Smarius so->so_pcb = 0; 103221407Smarius sofree(so); 104221407Smarius remque(rp); 105221407Smarius#ifdef notdef 106221407Smarius if (rp->rcb_laddr) 107221407Smarius m_freem(dtom(rp->rcb_laddr)); 108105135Salfred rp->rcb_laddr = 0; 109150763Simp#endif 11050702Swpaul free((caddr_t)(rp), M_PCB); 111164827Smarius} 112164827Smarius 11350702Swpaul/* 114164827Smarius * Disconnect and possibly release resources. 115164827Smarius */ 116164827Smariusvoid 11750702Swpaulraw_disconnect(rp) 118164827Smarius struct rawcb *rp; 119166164Smarius{ 120165991Smarius 121165991Smarius#ifdef notdef 12250702Swpaul if (rp->rcb_faddr) 12350702Swpaul m_freem(dtom(rp->rcb_faddr)); 124105135Salfred rp->rcb_faddr = 0; 125150763Simp#endif 12650702Swpaul if (rp->rcb_socket->so_state & SS_NOFDREF) 12750702Swpaul raw_detach(rp); 128213364Smarius} 129213364Smarius 130213364Smarius#ifdef notdef 131221407Smariusint 132221407Smariusraw_bind(so, nam) 133164711Smarius register struct socket *so; 13450702Swpaul struct mbuf *nam; 13550702Swpaul{ 13684145Sjlemon struct sockaddr *addr = mtod(nam, struct sockaddr *); 137150763Simp register struct rawcb *rp; 13850702Swpaul 13950702Swpaul if (ifnet == 0) 14050702Swpaul return (EADDRNOTAVAIL); 14150702Swpaul rp = sotorawcb(so); 14250702Swpaul nam = m_copym(nam, 0, M_COPYALL, M_WAITOK); 14350702Swpaul rp->rcb_laddr = mtod(nam, struct sockaddr *); 14450702Swpaul return (0); 145164711Smarius} 14650702Swpaul#endif 14750702Swpaul