diff options
author | Harald Welte <laforge@netfilter.org> | 2005-08-09 23:26:03 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2005-08-29 18:54:18 -0400 |
commit | 5a47a470e602eecb168ddd3b78841b84ceddd319 (patch) | |
tree | 9b2408cd295189662f4909522a15d24101bf3fdc /include/linux/dccp.h | |
parent | bb435b8d816582064ee0ddb1e2a6fbca67f34108 (diff) |
[DCCP]: make <linux/dccp.h> include-able from userspace
The protocol header files in <linux/foo.h> are usually structured in a
way to be included by userspace code. The top section consists of
general protocol structure definitions, typedefs, enums - followed by
an #ifdef __KERNEL__ section.
Currently <linux/dccp.h> doesn't follow that convention and can
therefore not be used from userspace. However, for example iptables'
libipt_dccp.c actually needs various definitions from there.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/dccp.h')
-rw-r--r-- | include/linux/dccp.h | 238 |
1 files changed, 121 insertions, 117 deletions
diff --git a/include/linux/dccp.h b/include/linux/dccp.h index e3b4bf7346bb..add4908b8e57 100644 --- a/include/linux/dccp.h +++ b/include/linux/dccp.h | |||
@@ -1,16 +1,8 @@ | |||
1 | #ifndef _LINUX_DCCP_H | 1 | #ifndef _LINUX_DCCP_H |
2 | #define _LINUX_DCCP_H | 2 | #define _LINUX_DCCP_H |
3 | 3 | ||
4 | #include <linux/in.h> | ||
5 | #include <linux/list.h> | ||
6 | #include <linux/types.h> | 4 | #include <linux/types.h> |
7 | #include <linux/uio.h> | 5 | #include <asm/byteorder.h> |
8 | #include <linux/workqueue.h> | ||
9 | |||
10 | #include <net/inet_connection_sock.h> | ||
11 | #include <net/sock.h> | ||
12 | #include <net/tcp_states.h> | ||
13 | #include <net/tcp.h> | ||
14 | 6 | ||
15 | /* FIXME: this is utterly wrong */ | 7 | /* FIXME: this is utterly wrong */ |
16 | struct sockaddr_dccp { | 8 | struct sockaddr_dccp { |
@@ -18,40 +10,6 @@ struct sockaddr_dccp { | |||
18 | unsigned int service; | 10 | unsigned int service; |
19 | }; | 11 | }; |
20 | 12 | ||
21 | enum dccp_state { | ||
22 | DCCP_OPEN = TCP_ESTABLISHED, | ||
23 | DCCP_REQUESTING = TCP_SYN_SENT, | ||
24 | DCCP_PARTOPEN = TCP_FIN_WAIT1, /* FIXME: | ||
25 | This mapping is horrible, but TCP has | ||
26 | no matching state for DCCP_PARTOPEN, | ||
27 | as TCP_SYN_RECV is already used by | ||
28 | DCCP_RESPOND, why don't stop using TCP | ||
29 | mapping of states? OK, now we don't use | ||
30 | sk_stream_sendmsg anymore, so doesn't | ||
31 | seem to exist any reason for us to | ||
32 | do the TCP mapping here */ | ||
33 | DCCP_LISTEN = TCP_LISTEN, | ||
34 | DCCP_RESPOND = TCP_SYN_RECV, | ||
35 | DCCP_CLOSING = TCP_CLOSING, | ||
36 | DCCP_TIME_WAIT = TCP_TIME_WAIT, | ||
37 | DCCP_CLOSED = TCP_CLOSE, | ||
38 | DCCP_MAX_STATES = TCP_MAX_STATES, | ||
39 | }; | ||
40 | |||
41 | #define DCCP_STATE_MASK 0xf | ||
42 | #define DCCP_ACTION_FIN (1<<7) | ||
43 | |||
44 | enum { | ||
45 | DCCPF_OPEN = TCPF_ESTABLISHED, | ||
46 | DCCPF_REQUESTING = TCPF_SYN_SENT, | ||
47 | DCCPF_PARTOPEN = TCPF_FIN_WAIT1, | ||
48 | DCCPF_LISTEN = TCPF_LISTEN, | ||
49 | DCCPF_RESPOND = TCPF_SYN_RECV, | ||
50 | DCCPF_CLOSING = TCPF_CLOSING, | ||
51 | DCCPF_TIME_WAIT = TCPF_TIME_WAIT, | ||
52 | DCCPF_CLOSED = TCPF_CLOSE, | ||
53 | }; | ||
54 | |||
55 | /** | 13 | /** |
56 | * struct dccp_hdr - generic part of DCCP packet header | 14 | * struct dccp_hdr - generic part of DCCP packet header |
57 | * | 15 | * |
@@ -94,11 +52,6 @@ struct dccp_hdr { | |||
94 | #endif | 52 | #endif |
95 | }; | 53 | }; |
96 | 54 | ||
97 | static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb) | ||
98 | { | ||
99 | return (struct dccp_hdr *)skb->h.raw; | ||
100 | } | ||
101 | |||
102 | /** | 55 | /** |
103 | * struct dccp_hdr_ext - the low bits of a 48 bit seq packet | 56 | * struct dccp_hdr_ext - the low bits of a 48 bit seq packet |
104 | * | 57 | * |
@@ -108,34 +61,6 @@ struct dccp_hdr_ext { | |||
108 | __u32 dccph_seq_low; | 61 | __u32 dccph_seq_low; |
109 | }; | 62 | }; |
110 | 63 | ||
111 | static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb) | ||
112 | { | ||
113 | return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr)); | ||
114 | } | ||
115 | |||
116 | static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb) | ||
117 | { | ||
118 | const struct dccp_hdr *dh = dccp_hdr(skb); | ||
119 | return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0); | ||
120 | } | ||
121 | |||
122 | static inline __u64 dccp_hdr_seq(const struct sk_buff *skb) | ||
123 | { | ||
124 | const struct dccp_hdr *dh = dccp_hdr(skb); | ||
125 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
126 | __u64 seq_nr = ntohl(dh->dccph_seq << 8); | ||
127 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
128 | __u64 seq_nr = ntohl(dh->dccph_seq); | ||
129 | #else | ||
130 | #error "Adjust your <asm/byteorder.h> defines" | ||
131 | #endif | ||
132 | |||
133 | if (dh->dccph_x != 0) | ||
134 | seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low); | ||
135 | |||
136 | return seq_nr; | ||
137 | } | ||
138 | |||
139 | /** | 64 | /** |
140 | * struct dccp_hdr_request - Conection initiation request header | 65 | * struct dccp_hdr_request - Conection initiation request header |
141 | * | 66 | * |
@@ -145,12 +70,6 @@ static inline __u64 dccp_hdr_seq(const struct sk_buff *skb) | |||
145 | struct dccp_hdr_request { | 70 | struct dccp_hdr_request { |
146 | __u32 dccph_req_service; | 71 | __u32 dccph_req_service; |
147 | }; | 72 | }; |
148 | |||
149 | static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb) | ||
150 | { | ||
151 | return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
152 | } | ||
153 | |||
154 | /** | 73 | /** |
155 | * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets | 74 | * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets |
156 | * | 75 | * |
@@ -162,24 +81,6 @@ struct dccp_hdr_ack_bits { | |||
162 | dccph_ack_nr_high:24; | 81 | dccph_ack_nr_high:24; |
163 | __u32 dccph_ack_nr_low; | 82 | __u32 dccph_ack_nr_low; |
164 | }; | 83 | }; |
165 | |||
166 | static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb) | ||
167 | { | ||
168 | return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
169 | } | ||
170 | |||
171 | static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb) | ||
172 | { | ||
173 | const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb); | ||
174 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
175 | return (((u64)ntohl(dhack->dccph_ack_nr_high << 8)) << 32) + ntohl(dhack->dccph_ack_nr_low); | ||
176 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
177 | return (((u64)ntohl(dhack->dccph_ack_nr_high)) << 32) + ntohl(dhack->dccph_ack_nr_low); | ||
178 | #else | ||
179 | #error "Adjust your <asm/byteorder.h> defines" | ||
180 | #endif | ||
181 | } | ||
182 | |||
183 | /** | 84 | /** |
184 | * struct dccp_hdr_response - Conection initiation response header | 85 | * struct dccp_hdr_response - Conection initiation response header |
185 | * | 86 | * |
@@ -193,11 +94,6 @@ struct dccp_hdr_response { | |||
193 | __u32 dccph_resp_service; | 94 | __u32 dccph_resp_service; |
194 | }; | 95 | }; |
195 | 96 | ||
196 | static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb) | ||
197 | { | ||
198 | return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
199 | } | ||
200 | |||
201 | /** | 97 | /** |
202 | * struct dccp_hdr_reset - Unconditionally shut down a connection | 98 | * struct dccp_hdr_reset - Unconditionally shut down a connection |
203 | * | 99 | * |
@@ -210,11 +106,6 @@ struct dccp_hdr_reset { | |||
210 | dccph_reset_data[3]; | 106 | dccph_reset_data[3]; |
211 | }; | 107 | }; |
212 | 108 | ||
213 | static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb) | ||
214 | { | ||
215 | return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
216 | } | ||
217 | |||
218 | enum dccp_pkt_type { | 109 | enum dccp_pkt_type { |
219 | DCCP_PKT_REQUEST = 0, | 110 | DCCP_PKT_REQUEST = 0, |
220 | DCCP_PKT_RESPONSE, | 111 | DCCP_PKT_RESPONSE, |
@@ -248,13 +139,6 @@ static inline unsigned int dccp_packet_hdr_len(const __u8 type) | |||
248 | return sizeof(struct dccp_hdr_response); | 139 | return sizeof(struct dccp_hdr_response); |
249 | return sizeof(struct dccp_hdr_reset); | 140 | return sizeof(struct dccp_hdr_reset); |
250 | } | 141 | } |
251 | |||
252 | static inline unsigned int dccp_hdr_len(const struct sk_buff *skb) | ||
253 | { | ||
254 | return dccp_basic_hdr_len(skb) + | ||
255 | dccp_packet_hdr_len(dccp_hdr(skb)->dccph_type); | ||
256 | } | ||
257 | |||
258 | enum dccp_reset_codes { | 142 | enum dccp_reset_codes { |
259 | DCCP_RESET_CODE_UNSPECIFIED = 0, | 143 | DCCP_RESET_CODE_UNSPECIFIED = 0, |
260 | DCCP_RESET_CODE_CLOSED, | 144 | DCCP_RESET_CODE_CLOSED, |
@@ -298,6 +182,124 @@ enum { | |||
298 | DCCPF_MAX_CCID_SPECIFIC = 255, | 182 | DCCPF_MAX_CCID_SPECIFIC = 255, |
299 | }; | 183 | }; |
300 | 184 | ||
185 | #ifdef __KERNEL__ | ||
186 | |||
187 | #include <linux/in.h> | ||
188 | #include <linux/list.h> | ||
189 | #include <linux/uio.h> | ||
190 | #include <linux/workqueue.h> | ||
191 | |||
192 | #include <net/inet_connection_sock.h> | ||
193 | #include <net/sock.h> | ||
194 | #include <net/tcp_states.h> | ||
195 | #include <net/tcp.h> | ||
196 | |||
197 | enum dccp_state { | ||
198 | DCCP_OPEN = TCP_ESTABLISHED, | ||
199 | DCCP_REQUESTING = TCP_SYN_SENT, | ||
200 | DCCP_PARTOPEN = TCP_FIN_WAIT1, /* FIXME: | ||
201 | This mapping is horrible, but TCP has | ||
202 | no matching state for DCCP_PARTOPEN, | ||
203 | as TCP_SYN_RECV is already used by | ||
204 | DCCP_RESPOND, why don't stop using TCP | ||
205 | mapping of states? OK, now we don't use | ||
206 | sk_stream_sendmsg anymore, so doesn't | ||
207 | seem to exist any reason for us to | ||
208 | do the TCP mapping here */ | ||
209 | DCCP_LISTEN = TCP_LISTEN, | ||
210 | DCCP_RESPOND = TCP_SYN_RECV, | ||
211 | DCCP_CLOSING = TCP_CLOSING, | ||
212 | DCCP_TIME_WAIT = TCP_TIME_WAIT, | ||
213 | DCCP_CLOSED = TCP_CLOSE, | ||
214 | DCCP_MAX_STATES = TCP_MAX_STATES, | ||
215 | }; | ||
216 | |||
217 | #define DCCP_STATE_MASK 0xf | ||
218 | #define DCCP_ACTION_FIN (1<<7) | ||
219 | |||
220 | enum { | ||
221 | DCCPF_OPEN = TCPF_ESTABLISHED, | ||
222 | DCCPF_REQUESTING = TCPF_SYN_SENT, | ||
223 | DCCPF_PARTOPEN = TCPF_FIN_WAIT1, | ||
224 | DCCPF_LISTEN = TCPF_LISTEN, | ||
225 | DCCPF_RESPOND = TCPF_SYN_RECV, | ||
226 | DCCPF_CLOSING = TCPF_CLOSING, | ||
227 | DCCPF_TIME_WAIT = TCPF_TIME_WAIT, | ||
228 | DCCPF_CLOSED = TCPF_CLOSE, | ||
229 | }; | ||
230 | |||
231 | static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb) | ||
232 | { | ||
233 | return (struct dccp_hdr *)skb->h.raw; | ||
234 | } | ||
235 | |||
236 | static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb) | ||
237 | { | ||
238 | return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr)); | ||
239 | } | ||
240 | |||
241 | static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb) | ||
242 | { | ||
243 | const struct dccp_hdr *dh = dccp_hdr(skb); | ||
244 | return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0); | ||
245 | } | ||
246 | |||
247 | static inline __u64 dccp_hdr_seq(const struct sk_buff *skb) | ||
248 | { | ||
249 | const struct dccp_hdr *dh = dccp_hdr(skb); | ||
250 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
251 | __u64 seq_nr = ntohl(dh->dccph_seq << 8); | ||
252 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
253 | __u64 seq_nr = ntohl(dh->dccph_seq); | ||
254 | #else | ||
255 | #error "Adjust your <asm/byteorder.h> defines" | ||
256 | #endif | ||
257 | |||
258 | if (dh->dccph_x != 0) | ||
259 | seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low); | ||
260 | |||
261 | return seq_nr; | ||
262 | } | ||
263 | |||
264 | static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb) | ||
265 | { | ||
266 | return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
267 | } | ||
268 | |||
269 | static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb) | ||
270 | { | ||
271 | return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
272 | } | ||
273 | |||
274 | static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb) | ||
275 | { | ||
276 | const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb); | ||
277 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
278 | return (((u64)ntohl(dhack->dccph_ack_nr_high << 8)) << 32) + ntohl(dhack->dccph_ack_nr_low); | ||
279 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
280 | return (((u64)ntohl(dhack->dccph_ack_nr_high)) << 32) + ntohl(dhack->dccph_ack_nr_low); | ||
281 | #else | ||
282 | #error "Adjust your <asm/byteorder.h> defines" | ||
283 | #endif | ||
284 | } | ||
285 | |||
286 | static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb) | ||
287 | { | ||
288 | return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
289 | } | ||
290 | |||
291 | static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb) | ||
292 | { | ||
293 | return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb)); | ||
294 | } | ||
295 | |||
296 | static inline unsigned int dccp_hdr_len(const struct sk_buff *skb) | ||
297 | { | ||
298 | return dccp_basic_hdr_len(skb) + | ||
299 | dccp_packet_hdr_len(dccp_hdr(skb)->dccph_type); | ||
300 | } | ||
301 | |||
302 | |||
301 | /* initial values for each feature */ | 303 | /* initial values for each feature */ |
302 | #define DCCPF_INITIAL_SEQUENCE_WINDOW 100 | 304 | #define DCCPF_INITIAL_SEQUENCE_WINDOW 100 |
303 | /* FIXME: for now we're using CCID 3 (TFRC) */ | 305 | /* FIXME: for now we're using CCID 3 (TFRC) */ |
@@ -429,4 +431,6 @@ static inline const char *dccp_role(const struct sock *sk) | |||
429 | return NULL; | 431 | return NULL; |
430 | } | 432 | } |
431 | 433 | ||
434 | #endif /* __KERNEL__ */ | ||
435 | |||
432 | #endif /* _LINUX_DCCP_H */ | 436 | #endif /* _LINUX_DCCP_H */ |