Deleted Added
full compact
raw_cb.c (180305) raw_cb.c (180385)
1/*-
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * @(#)raw_cb.c 8.1 (Berkeley) 6/10/93
1/*-
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * @(#)raw_cb.c 8.1 (Berkeley) 6/10/93
31 * $FreeBSD: head/sys/net/raw_cb.c 180305 2008-07-05 18:03:39Z rwatson $
31 * $FreeBSD: head/sys/net/raw_cb.c 180385 2008-07-09 15:48:16Z rwatson $
32 */
33
34#include <sys/param.h>
35#include <sys/domain.h>
36#include <sys/lock.h>
37#include <sys/malloc.h>
38#include <sys/mutex.h>
39#include <sys/protosw.h>
40#include <sys/socket.h>
41#include <sys/socketvar.h>
42#include <sys/systm.h>
43
44#include <net/raw_cb.h>
45
46/*
47 * Routines to manage the raw protocol control blocks.
48 *
49 * TODO:
50 * hash lookups by protocol family/protocol + address family
51 * take care of unique address problems per AF?
52 * redo address binding to allow wildcards
53 */
54
55struct mtx rawcb_mtx;
56struct rawcb_list_head rawcb_list;
57
58const static u_long raw_sendspace = RAWSNDQ;
59const static u_long raw_recvspace = RAWRCVQ;
60
61/*
62 * Allocate a control block and a nominal amount of buffer space for the
63 * socket.
64 */
65int
66raw_attach(struct socket *so, int proto)
67{
68 struct rawcb *rp = sotorawcb(so);
69 int error;
70
71 /*
72 * It is assumed that raw_attach is called
73 * after space has been allocated for the
74 * rawcb.
75 */
76 if (rp == 0)
77 return (ENOBUFS);
78 error = soreserve(so, raw_sendspace, raw_recvspace);
79 if (error)
80 return (error);
81 rp->rcb_socket = so;
82 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
83 rp->rcb_proto.sp_protocol = proto;
84 mtx_lock(&rawcb_mtx);
85 LIST_INSERT_HEAD(&rawcb_list, rp, list);
86 mtx_unlock(&rawcb_mtx);
87 return (0);
88}
89
90/*
91 * Detach the raw connection block and discard socket resources.
92 */
93void
94raw_detach(struct rawcb *rp)
95{
96 struct socket *so = rp->rcb_socket;
97
98 KASSERT(so->so_pcb == rp, ("raw_detach: so_pcb != rp"));
99
100 so->so_pcb = NULL;
101 mtx_lock(&rawcb_mtx);
102 LIST_REMOVE(rp, list);
103 mtx_unlock(&rawcb_mtx);
32 */
33
34#include <sys/param.h>
35#include <sys/domain.h>
36#include <sys/lock.h>
37#include <sys/malloc.h>
38#include <sys/mutex.h>
39#include <sys/protosw.h>
40#include <sys/socket.h>
41#include <sys/socketvar.h>
42#include <sys/systm.h>
43
44#include <net/raw_cb.h>
45
46/*
47 * Routines to manage the raw protocol control blocks.
48 *
49 * TODO:
50 * hash lookups by protocol family/protocol + address family
51 * take care of unique address problems per AF?
52 * redo address binding to allow wildcards
53 */
54
55struct mtx rawcb_mtx;
56struct rawcb_list_head rawcb_list;
57
58const static u_long raw_sendspace = RAWSNDQ;
59const static u_long raw_recvspace = RAWRCVQ;
60
61/*
62 * Allocate a control block and a nominal amount of buffer space for the
63 * socket.
64 */
65int
66raw_attach(struct socket *so, int proto)
67{
68 struct rawcb *rp = sotorawcb(so);
69 int error;
70
71 /*
72 * It is assumed that raw_attach is called
73 * after space has been allocated for the
74 * rawcb.
75 */
76 if (rp == 0)
77 return (ENOBUFS);
78 error = soreserve(so, raw_sendspace, raw_recvspace);
79 if (error)
80 return (error);
81 rp->rcb_socket = so;
82 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
83 rp->rcb_proto.sp_protocol = proto;
84 mtx_lock(&rawcb_mtx);
85 LIST_INSERT_HEAD(&rawcb_list, rp, list);
86 mtx_unlock(&rawcb_mtx);
87 return (0);
88}
89
90/*
91 * Detach the raw connection block and discard socket resources.
92 */
93void
94raw_detach(struct rawcb *rp)
95{
96 struct socket *so = rp->rcb_socket;
97
98 KASSERT(so->so_pcb == rp, ("raw_detach: so_pcb != rp"));
99
100 so->so_pcb = NULL;
101 mtx_lock(&rawcb_mtx);
102 LIST_REMOVE(rp, list);
103 mtx_unlock(&rawcb_mtx);
104#ifdef notdef
105 if (rp->rcb_laddr)
106 m_freem(dtom(rp->rcb_laddr));
107 rp->rcb_laddr = 0;
108#endif
109 free((caddr_t)(rp), M_PCB);
110}
104 free((caddr_t)(rp), M_PCB);
105}
111
112/*
113 * Disconnect raw socket.
114 */
115void
116raw_disconnect(struct rawcb *rp)
117{
118
119#ifdef notdef
120 if (rp->rcb_faddr)
121 m_freem(dtom(rp->rcb_faddr));
122 rp->rcb_faddr = 0;
123#endif
124}
125
126#ifdef notdef
127#include <sys/mbuf.h>
128
129int
130raw_bind(struct socket *so, struct mbuf *nam)
131{
132 struct sockaddr *addr = mtod(nam, struct sockaddr *);
133 struct rawcb *rp;
134
135 if (ifnet == 0)
136 return (EADDRNOTAVAIL);
137 rp = sotorawcb(so);
138 nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
139 rp->rcb_laddr = mtod(nam, struct sockaddr *);
140 return (0);
141}
142#endif