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