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