1 /* 2 * Copyright (c) 1980, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)raw_cb.c 7.13 (Berkeley) 10/11/92 8 */ 9 10 #include <sys/param.h> 11 #include <sys/systm.h> 12 #include <sys/mbuf.h> 13 #include <sys/socket.h> 14 #include <sys/socketvar.h> 15 #include <sys/domain.h> 16 #include <sys/protosw.h> 17 #include <sys/errno.h> 18 19 #include <net/if.h> 20 #include <net/route.h> 21 #include <net/raw_cb.h> 22 #include <netinet/in.h> 23 24 /* 25 * Routines to manage the raw protocol control blocks. 26 * 27 * TODO: 28 * hash lookups by protocol family/protocol + address family 29 * take care of unique address problems per AF? 30 * redo address binding to allow wildcards 31 */ 32 33 u_long raw_sendspace = RAWSNDQ; 34 u_long raw_recvspace = RAWRCVQ; 35 36 /* 37 * Allocate a control block and a nominal amount 38 * of buffer space for the socket. 39 */ 40 raw_attach(so, proto) 41 register struct socket *so; 42 int proto; 43 { 44 register struct rawcb *rp = sotorawcb(so); 45 int error; 46 47 /* 48 * It is assumed that raw_attach is called 49 * after space has been allocated for the 50 * rawcb. 51 */ 52 if (rp == 0) 53 return (ENOBUFS); 54 if (error = soreserve(so, raw_sendspace, raw_recvspace)) 55 return (error); 56 rp->rcb_socket = so; 57 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family; 58 rp->rcb_proto.sp_protocol = proto; 59 insque(rp, &rawcb); 60 return (0); 61 } 62 63 /* 64 * Detach the raw connection block and discard 65 * socket resources. 66 */ 67 raw_detach(rp) 68 register struct rawcb *rp; 69 { 70 struct socket *so = rp->rcb_socket; 71 72 so->so_pcb = 0; 73 sofree(so); 74 remque(rp); 75 #ifdef notdef 76 if (rp->rcb_laddr) 77 m_freem(dtom(rp->rcb_laddr)); 78 rp->rcb_laddr = 0; 79 #endif 80 free((caddr_t)(rp), M_PCB); 81 } 82 83 /* 84 * Disconnect and possibly release resources. 85 */ 86 raw_disconnect(rp) 87 struct rawcb *rp; 88 { 89 90 #ifdef notdef 91 if (rp->rcb_faddr) 92 m_freem(dtom(rp->rcb_faddr)); 93 rp->rcb_faddr = 0; 94 #endif 95 if (rp->rcb_socket->so_state & SS_NOFDREF) 96 raw_detach(rp); 97 } 98 99 #ifdef notdef 100 raw_bind(so, nam) 101 register struct socket *so; 102 struct mbuf *nam; 103 { 104 struct sockaddr *addr = mtod(nam, struct sockaddr *); 105 register struct rawcb *rp; 106 107 if (ifnet == 0) 108 return (EADDRNOTAVAIL); 109 rp = sotorawcb(so); 110 nam = m_copym(nam, 0, M_COPYALL, M_WAITOK); 111 rp->rcb_laddr = mtod(nam, struct sockaddr *); 112 return (0); 113 } 114 #endif 115