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