merge in vnodes
[unix-history] / usr / src / sys / net / raw_cb.c
CommitLineData
cb1c44c2 1/*
1810611d 2 * Copyright (c) 1980, 1986 Regents of the University of California.
5b519e94 3 * All rights reserved.
cb1c44c2 4 *
5b519e94 5 * Redistribution and use in source and binary forms are permitted
50c7758a
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5b519e94 16 *
0e6c0944 17 * @(#)raw_cb.c 7.9 (Berkeley) %G%
cb1c44c2 18 */
785d93ac 19
20666ad3
JB
20#include "param.h"
21#include "systm.h"
22#include "mbuf.h"
23#include "socket.h"
24#include "socketvar.h"
829f867e
MK
25#include "domain.h"
26#include "protosw.h"
20666ad3 27#include "errno.h"
f4d55810 28
20666ad3
JB
29#include "if.h"
30#include "route.h"
31#include "raw_cb.h"
9e9695c7 32#include "../netinet/in.h"
f4d55810 33
0e6c0944 34#include "machine/mtpr.h"
785d93ac
BJ
35
36/*
37 * Routines to manage the raw protocol control blocks.
38 *
39 * TODO:
40 * hash lookups by protocol family/protocol + address family
ee787340 41 * take care of unique address problems per AF?
1e25d807 42 * redo address binding to allow wildcards
785d93ac
BJ
43 */
44
73379934
MK
45u_long raw_sendspace = RAWSNDQ;
46u_long raw_recvspace = RAWRCVQ;
47
785d93ac
BJ
48/*
49 * Allocate a control block and a nominal amount
50 * of buffer space for the socket.
51 */
829f867e 52raw_attach(so, proto)
785d93ac 53 register struct socket *so;
829f867e 54 int proto;
785d93ac 55{
b72a6efb 56 register struct rawcb *rp = sotorawcb(so);
785d93ac 57
b72a6efb
KS
58 /*
59 * It is assumed that raw_attach is called
60 * after space has been allocated for the
61 * rawcb.
62 */
63 if (rp == 0)
785d93ac 64 return (ENOBUFS);
73379934 65 if (sbreserve(&so->so_snd, raw_sendspace) == 0)
785d93ac 66 goto bad;
73379934 67 if (sbreserve(&so->so_rcv, raw_recvspace) == 0)
785d93ac 68 goto bad2;
785d93ac 69 rp->rcb_socket = so;
829f867e
MK
70 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
71 rp->rcb_proto.sp_protocol = proto;
72 insque(rp, &rawcb);
785d93ac
BJ
73 return (0);
74bad2:
75 sbrelease(&so->so_snd);
76bad:
785d93ac
BJ
77 return (ENOBUFS);
78}
79
80/*
81 * Detach the raw connection block and discard
82 * socket resources.
83 */
84raw_detach(rp)
85 register struct rawcb *rp;
86{
87 struct socket *so = rp->rcb_socket;
88
785d93ac
BJ
89 so->so_pcb = 0;
90 sofree(so);
91 remque(rp);
b72a6efb
KS
92#ifdef notdef
93 if (rp->rcb_laddr)
94 m_freem(dtom(rp->rcb_laddr));
95 rp->rcb_laddr = 0;
96#endif
97 free((caddr_t)(rp), M_PCB);
785d93ac
BJ
98}
99
100/*
101 * Disconnect and possibly release resources.
102 */
103raw_disconnect(rp)
104 struct rawcb *rp;
105{
4053be18 106
b72a6efb
KS
107#ifdef notdef
108 if (rp->rcb_faddr)
109 m_freem(dtom(rp->rcb_faddr));
110 rp->rcb_faddr = 0;
111#endif
f832270b 112 if (rp->rcb_socket->so_state & SS_NOFDREF)
785d93ac
BJ
113 raw_detach(rp);
114}
115
b72a6efb 116#ifdef notdef
14fa60f2
BJ
117raw_bind(so, nam)
118 register struct socket *so;
119 struct mbuf *nam;
120{
121 struct sockaddr *addr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
122 register struct rawcb *rp;
123
124 if (ifnet == 0)
125 return (EADDRNOTAVAIL);
af0b24db 126 rp = sotorawcb(so);
b72a6efb
KS
127 nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
128 rp->rcb_laddr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
129 return (0);
130}
b72a6efb 131#endif