1 /*
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)raw_cb.c 8.1 (Berkeley) 06/10/93
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 int
raw_attach(so,proto)41 raw_attach(so, proto)
42 register struct socket *so;
43 int proto;
44 {
45 register struct rawcb *rp = sotorawcb(so);
46 int error;
47
48 /*
49 * It is assumed that raw_attach is called
50 * after space has been allocated for the
51 * rawcb.
52 */
53 if (rp == 0)
54 return (ENOBUFS);
55 if (error = soreserve(so, raw_sendspace, raw_recvspace))
56 return (error);
57 rp->rcb_socket = so;
58 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
59 rp->rcb_proto.sp_protocol = proto;
60 insque(rp, &rawcb);
61 return (0);
62 }
63
64 /*
65 * Detach the raw connection block and discard
66 * socket resources.
67 */
68 void
raw_detach(rp)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 void
raw_disconnect(rp)89 raw_disconnect(rp)
90 struct rawcb *rp;
91 {
92
93 #ifdef notdef
94 if (rp->rcb_faddr)
95 m_freem(dtom(rp->rcb_faddr));
96 rp->rcb_faddr = 0;
97 #endif
98 if (rp->rcb_socket->so_state & SS_NOFDREF)
99 raw_detach(rp);
100 }
101
102 #ifdef notdef
103 int
raw_bind(so,nam)104 raw_bind(so, nam)
105 register struct socket *so;
106 struct mbuf *nam;
107 {
108 struct sockaddr *addr = mtod(nam, struct sockaddr *);
109 register struct rawcb *rp;
110
111 if (ifnet == 0)
112 return (EADDRNOTAVAIL);
113 rp = sotorawcb(so);
114 nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
115 rp->rcb_laddr = mtod(nam, struct sockaddr *);
116 return (0);
117 }
118 #endif
119