2 * DCCP connection tracking protocol helper
4 * Copyright (c) 2005, 2006, 2008 Patrick McHardy <kaber@trash.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/sysctl.h>
15 #include <linux/spinlock.h>
16 #include <linux/skbuff.h>
17 #include <linux/dccp.h>
19 #include <linux/netfilter/nfnetlink_conntrack.h>
20 #include <net/netfilter/nf_conntrack.h>
21 #include <net/netfilter/nf_conntrack_l4proto.h>
22 #include <net/netfilter/nf_log.h>
24 static DEFINE_RWLOCK(dccp_lock
);
26 static int nf_ct_dccp_loose __read_mostly
= 1;
28 /* Timeouts are based on values from RFC4340:
32 * 8.1.2. Client Request
34 * A client MAY give up on its DCCP-Requests after some time
35 * (3 minutes, for example).
39 * 8.1.3. Server Response
41 * It MAY also leave the RESPOND state for CLOSED after a timeout of
42 * not less than 4MSL (8 minutes);
46 * 8.1.5. Handshake Completion
48 * If the client remains in PARTOPEN for more than 4MSL (8 minutes),
49 * it SHOULD reset the connection with Reset Code 2, "Aborted".
53 * The DCCP timestamp overflows after 11.9 hours. If the connection
54 * stays idle this long the sequence number won't be recognized
61 * The retransmission timer should initially be set to go off in two
62 * round-trip times and should back off to not less than once every
69 * A server or client socket remains in this state for 2MSL (4 minutes)
70 * after the connection has been town down, ...
73 #define DCCP_MSL (2 * 60 * HZ)
75 static unsigned int dccp_timeout
[CT_DCCP_MAX
+ 1] __read_mostly
= {
76 [CT_DCCP_REQUEST
] = 2 * DCCP_MSL
,
77 [CT_DCCP_RESPOND
] = 4 * DCCP_MSL
,
78 [CT_DCCP_PARTOPEN
] = 4 * DCCP_MSL
,
79 [CT_DCCP_OPEN
] = 12 * 3600 * HZ
,
80 [CT_DCCP_CLOSEREQ
] = 64 * HZ
,
81 [CT_DCCP_CLOSING
] = 64 * HZ
,
82 [CT_DCCP_TIMEWAIT
] = 2 * DCCP_MSL
,
85 static const char * const dccp_state_names
[] = {
86 [CT_DCCP_NONE
] = "NONE",
87 [CT_DCCP_REQUEST
] = "REQUEST",
88 [CT_DCCP_RESPOND
] = "RESPOND",
89 [CT_DCCP_PARTOPEN
] = "PARTOPEN",
90 [CT_DCCP_OPEN
] = "OPEN",
91 [CT_DCCP_CLOSEREQ
] = "CLOSEREQ",
92 [CT_DCCP_CLOSING
] = "CLOSING",
93 [CT_DCCP_TIMEWAIT
] = "TIMEWAIT",
94 [CT_DCCP_IGNORE
] = "IGNORE",
95 [CT_DCCP_INVALID
] = "INVALID",
98 #define sNO CT_DCCP_NONE
99 #define sRQ CT_DCCP_REQUEST
100 #define sRS CT_DCCP_RESPOND
101 #define sPO CT_DCCP_PARTOPEN
102 #define sOP CT_DCCP_OPEN
103 #define sCR CT_DCCP_CLOSEREQ
104 #define sCG CT_DCCP_CLOSING
105 #define sTW CT_DCCP_TIMEWAIT
106 #define sIG CT_DCCP_IGNORE
107 #define sIV CT_DCCP_INVALID
110 * DCCP state transistion table
112 * The assumption is the same as for TCP tracking:
114 * We are the man in the middle. All the packets go through us but might
115 * get lost in transit to the destination. It is assumed that the destination
116 * can't receive segments we haven't seen.
118 * The following states exist:
120 * NONE: Initial state, expecting Request
121 * REQUEST: Request seen, waiting for Response from server
122 * RESPOND: Response from server seen, waiting for Ack from client
123 * PARTOPEN: Ack after Response seen, waiting for packet other than Response,
124 * Reset or Sync from server
125 * OPEN: Packet other than Response, Reset or Sync seen
126 * CLOSEREQ: CloseReq from server seen, expecting Close from client
127 * CLOSING: Close seen, expecting Reset
128 * TIMEWAIT: Reset seen
129 * IGNORE: Not determinable whether packet is valid
131 * Some states exist only on one side of the connection: REQUEST, RESPOND,
132 * PARTOPEN, CLOSEREQ. For the other side these states are equivalent to
133 * the one it was in before.
135 * Packets are marked as ignored (sIG) if we don't know if they're valid
136 * (for example a reincarnation of a connection we didn't notice is dead
137 * already) and the server may send back a connection closing Reset or a
138 * Response. They're also used for Sync/SyncAck packets, which we don't
141 static const u_int8_t
142 dccp_state_table
[CT_DCCP_ROLE_MAX
+ 1][DCCP_PKT_SYNCACK
+ 1][CT_DCCP_MAX
+ 1] = {
143 [CT_DCCP_ROLE_CLIENT
] = {
144 [DCCP_PKT_REQUEST
] = {
146 * sNO -> sRQ Regular Request
147 * sRQ -> sRQ Retransmitted Request or reincarnation
148 * sRS -> sRS Retransmitted Request (apparently Response
149 * got lost after we saw it) or reincarnation
150 * sPO -> sIG Ignore, conntrack might be out of sync
151 * sOP -> sIG Ignore, conntrack might be out of sync
152 * sCR -> sIG Ignore, conntrack might be out of sync
153 * sCG -> sIG Ignore, conntrack might be out of sync
154 * sTW -> sRQ Reincarnation
156 * sNO, sRQ, sRS, sPO. sOP, sCR, sCG, sTW, */
157 sRQ
, sRQ
, sRS
, sIG
, sIG
, sIG
, sIG
, sRQ
,
159 [DCCP_PKT_RESPONSE
] = {
162 * sRQ -> sIG Ignore, might be response to ignored Request
163 * sRS -> sIG Ignore, might be response to ignored Request
164 * sPO -> sIG Ignore, might be response to ignored Request
165 * sOP -> sIG Ignore, might be response to ignored Request
166 * sCR -> sIG Ignore, might be response to ignored Request
167 * sCG -> sIG Ignore, might be response to ignored Request
168 * sTW -> sIV Invalid, reincarnation in reverse direction
171 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
172 sIV
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIV
,
176 * sNO -> sIV No connection
177 * sRQ -> sIV No connection
178 * sRS -> sPO Ack for Response, move to PARTOPEN (8.1.5.)
179 * sPO -> sPO Retransmitted Ack for Response, remain in PARTOPEN
180 * sOP -> sOP Regular ACK, remain in OPEN
181 * sCR -> sCR Ack in CLOSEREQ MAY be processed (8.3.)
182 * sCG -> sCG Ack in CLOSING MAY be processed (8.3.)
185 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
186 sIV
, sIV
, sPO
, sPO
, sOP
, sCR
, sCG
, sIV
190 * sNO -> sIV No connection
191 * sRQ -> sIV No connection
192 * sRS -> sIV No connection
193 * sPO -> sIV MUST use DataAck in PARTOPEN state (8.1.5.)
194 * sOP -> sOP Regular Data packet
195 * sCR -> sCR Data in CLOSEREQ MAY be processed (8.3.)
196 * sCG -> sCG Data in CLOSING MAY be processed (8.3.)
199 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
200 sIV
, sIV
, sIV
, sIV
, sOP
, sCR
, sCG
, sIV
,
202 [DCCP_PKT_DATAACK
] = {
204 * sNO -> sIV No connection
205 * sRQ -> sIV No connection
206 * sRS -> sPO Ack for Response, move to PARTOPEN (8.1.5.)
207 * sPO -> sPO Remain in PARTOPEN state
208 * sOP -> sOP Regular DataAck packet in OPEN state
209 * sCR -> sCR DataAck in CLOSEREQ MAY be processed (8.3.)
210 * sCG -> sCG DataAck in CLOSING MAY be processed (8.3.)
213 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
214 sIV
, sIV
, sPO
, sPO
, sOP
, sCR
, sCG
, sIV
216 [DCCP_PKT_CLOSEREQ
] = {
218 * CLOSEREQ may only be sent by the server.
220 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
221 sIV
, sIV
, sIV
, sIV
, sIV
, sIV
, sIV
, sIV
225 * sNO -> sIV No connection
226 * sRQ -> sIV No connection
227 * sRS -> sIV No connection
228 * sPO -> sCG Client-initiated close
229 * sOP -> sCG Client-initiated close
230 * sCR -> sCG Close in response to CloseReq (8.3.)
231 * sCG -> sCG Retransmit
232 * sTW -> sIV Late retransmit, already in TIME_WAIT
234 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
235 sIV
, sIV
, sIV
, sCG
, sCG
, sCG
, sIV
, sIV
239 * sNO -> sIV No connection
240 * sRQ -> sTW Sync received or timeout, SHOULD send Reset (8.1.1.)
241 * sRS -> sTW Response received without Request
242 * sPO -> sTW Timeout, SHOULD send Reset (8.1.5.)
243 * sOP -> sTW Connection reset
244 * sCR -> sTW Connection reset
245 * sCG -> sTW Connection reset
246 * sTW -> sIG Ignore (don't refresh timer)
248 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
249 sIV
, sTW
, sTW
, sTW
, sTW
, sTW
, sTW
, sIG
253 * We currently ignore Sync packets
255 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
256 sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
,
258 [DCCP_PKT_SYNCACK
] = {
260 * We currently ignore SyncAck packets
262 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
263 sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
,
266 [CT_DCCP_ROLE_SERVER
] = {
267 [DCCP_PKT_REQUEST
] = {
270 * sRQ -> sIG Ignore, conntrack might be out of sync
271 * sRS -> sIG Ignore, conntrack might be out of sync
272 * sPO -> sIG Ignore, conntrack might be out of sync
273 * sOP -> sIG Ignore, conntrack might be out of sync
274 * sCR -> sIG Ignore, conntrack might be out of sync
275 * sCG -> sIG Ignore, conntrack might be out of sync
276 * sTW -> sRQ Reincarnation, must reverse roles
278 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
279 sIV
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sRQ
281 [DCCP_PKT_RESPONSE
] = {
283 * sNO -> sIV Response without Request
284 * sRQ -> sRS Response to clients Request
285 * sRS -> sRS Retransmitted Response (8.1.3. SHOULD NOT)
286 * sPO -> sIG Response to an ignored Request or late retransmit
287 * sOP -> sIG Ignore, might be response to ignored Request
288 * sCR -> sIG Ignore, might be response to ignored Request
289 * sCG -> sIG Ignore, might be response to ignored Request
290 * sTW -> sIV Invalid, Request from client in sTW moves to sRQ
292 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
293 sIV
, sRS
, sRS
, sIG
, sIG
, sIG
, sIG
, sIV
297 * sNO -> sIV No connection
298 * sRQ -> sIV No connection
299 * sRS -> sIV No connection
300 * sPO -> sOP Enter OPEN state (8.1.5.)
301 * sOP -> sOP Regular Ack in OPEN state
302 * sCR -> sIV Waiting for Close from client
303 * sCG -> sCG Ack in CLOSING MAY be processed (8.3.)
306 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
307 sIV
, sIV
, sIV
, sOP
, sOP
, sIV
, sCG
, sIV
311 * sNO -> sIV No connection
312 * sRQ -> sIV No connection
313 * sRS -> sIV No connection
314 * sPO -> sOP Enter OPEN state (8.1.5.)
315 * sOP -> sOP Regular Data packet in OPEN state
316 * sCR -> sIV Waiting for Close from client
317 * sCG -> sCG Data in CLOSING MAY be processed (8.3.)
320 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
321 sIV
, sIV
, sIV
, sOP
, sOP
, sIV
, sCG
, sIV
323 [DCCP_PKT_DATAACK
] = {
325 * sNO -> sIV No connection
326 * sRQ -> sIV No connection
327 * sRS -> sIV No connection
328 * sPO -> sOP Enter OPEN state (8.1.5.)
329 * sOP -> sOP Regular DataAck in OPEN state
330 * sCR -> sIV Waiting for Close from client
331 * sCG -> sCG Data in CLOSING MAY be processed (8.3.)
334 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
335 sIV
, sIV
, sIV
, sOP
, sOP
, sIV
, sCG
, sIV
337 [DCCP_PKT_CLOSEREQ
] = {
339 * sNO -> sIV No connection
340 * sRQ -> sIV No connection
341 * sRS -> sIV No connection
342 * sPO -> sOP -> sCR Move directly to CLOSEREQ (8.1.5.)
343 * sOP -> sCR CloseReq in OPEN state
344 * sCR -> sCR Retransmit
345 * sCG -> sCR Simultaneous close, client sends another Close
346 * sTW -> sIV Already closed
348 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
349 sIV
, sIV
, sIV
, sCR
, sCR
, sCR
, sCR
, sIV
353 * sNO -> sIV No connection
354 * sRQ -> sIV No connection
355 * sRS -> sIV No connection
356 * sPO -> sOP -> sCG Move direcly to CLOSING
357 * sOP -> sCG Move to CLOSING
358 * sCR -> sIV Close after CloseReq is invalid
359 * sCG -> sCG Retransmit
360 * sTW -> sIV Already closed
362 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
363 sIV
, sIV
, sIV
, sCG
, sCG
, sIV
, sCG
, sIV
367 * sNO -> sIV No connection
368 * sRQ -> sTW Reset in response to Request
369 * sRS -> sTW Timeout, SHOULD send Reset (8.1.3.)
370 * sPO -> sTW Timeout, SHOULD send Reset (8.1.3.)
374 * sTW -> sIG Ignore (don't refresh timer)
376 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW, sTW */
377 sIV
, sTW
, sTW
, sTW
, sTW
, sTW
, sTW
, sTW
, sIG
381 * We currently ignore Sync packets
383 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
384 sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
,
386 [DCCP_PKT_SYNCACK
] = {
388 * We currently ignore SyncAck packets
390 * sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
391 sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
, sIG
,
396 static bool dccp_pkt_to_tuple(const struct sk_buff
*skb
, unsigned int dataoff
,
397 struct nf_conntrack_tuple
*tuple
)
399 struct dccp_hdr _hdr
, *dh
;
401 dh
= skb_header_pointer(skb
, dataoff
, sizeof(_hdr
), &_hdr
);
405 tuple
->src
.u
.dccp
.port
= dh
->dccph_sport
;
406 tuple
->dst
.u
.dccp
.port
= dh
->dccph_dport
;
410 static bool dccp_invert_tuple(struct nf_conntrack_tuple
*inv
,
411 const struct nf_conntrack_tuple
*tuple
)
413 inv
->src
.u
.dccp
.port
= tuple
->dst
.u
.dccp
.port
;
414 inv
->dst
.u
.dccp
.port
= tuple
->src
.u
.dccp
.port
;
418 static bool dccp_new(struct nf_conn
*ct
, const struct sk_buff
*skb
,
419 unsigned int dataoff
)
421 struct dccp_hdr _dh
, *dh
;
425 dh
= skb_header_pointer(skb
, dataoff
, sizeof(_dh
), &dh
);
428 state
= dccp_state_table
[CT_DCCP_ROLE_CLIENT
][dh
->dccph_type
][CT_DCCP_NONE
];
431 if (nf_ct_dccp_loose
== 0) {
432 msg
= "nf_ct_dccp: not picking up existing connection ";
435 case CT_DCCP_REQUEST
:
437 case CT_DCCP_INVALID
:
438 msg
= "nf_ct_dccp: invalid state transition ";
442 ct
->proto
.dccp
.role
[IP_CT_DIR_ORIGINAL
] = CT_DCCP_ROLE_CLIENT
;
443 ct
->proto
.dccp
.role
[IP_CT_DIR_REPLY
] = CT_DCCP_ROLE_SERVER
;
444 ct
->proto
.dccp
.state
= CT_DCCP_NONE
;
448 if (LOG_INVALID(IPPROTO_DCCP
))
449 nf_log_packet(nf_ct_l3num(ct
), 0, skb
, NULL
, NULL
, NULL
, msg
);
453 static u64
dccp_ack_seq(const struct dccp_hdr
*dh
)
455 const struct dccp_hdr_ack_bits
*dhack
;
457 dhack
= (void *)dh
+ __dccp_basic_hdr_len(dh
);
458 return ((u64
)ntohs(dhack
->dccph_ack_nr_high
) << 32) +
459 ntohl(dhack
->dccph_ack_nr_low
);
462 static int dccp_packet(struct nf_conn
*ct
, const struct sk_buff
*skb
,
463 unsigned int dataoff
, enum ip_conntrack_info ctinfo
,
464 int pf
, unsigned int hooknum
)
466 enum ip_conntrack_dir dir
= CTINFO2DIR(ctinfo
);
467 struct dccp_hdr _dh
, *dh
;
468 u_int8_t type
, old_state
, new_state
;
469 enum ct_dccp_roles role
;
471 dh
= skb_header_pointer(skb
, dataoff
, sizeof(_dh
), &dh
);
473 type
= dh
->dccph_type
;
475 if (type
== DCCP_PKT_RESET
&&
476 !test_bit(IPS_SEEN_REPLY_BIT
, &ct
->status
)) {
477 /* Tear down connection immediately if only reply is a RESET */
478 if (del_timer(&ct
->timeout
))
479 ct
->timeout
.function((unsigned long)ct
);
483 write_lock_bh(&dccp_lock
);
485 role
= ct
->proto
.dccp
.role
[dir
];
486 old_state
= ct
->proto
.dccp
.state
;
487 new_state
= dccp_state_table
[role
][type
][old_state
];
490 case CT_DCCP_REQUEST
:
491 if (old_state
== CT_DCCP_TIMEWAIT
&&
492 role
== CT_DCCP_ROLE_SERVER
) {
493 /* Reincarnation in the reverse direction: reopen and
494 * reverse client/server roles. */
495 ct
->proto
.dccp
.role
[dir
] = CT_DCCP_ROLE_CLIENT
;
496 ct
->proto
.dccp
.role
[!dir
] = CT_DCCP_ROLE_SERVER
;
499 case CT_DCCP_RESPOND
:
500 if (old_state
== CT_DCCP_REQUEST
)
501 ct
->proto
.dccp
.handshake_seq
= dccp_hdr_seq(dh
);
503 case CT_DCCP_PARTOPEN
:
504 if (old_state
== CT_DCCP_RESPOND
&&
505 type
== DCCP_PKT_ACK
&&
506 dccp_ack_seq(dh
) == ct
->proto
.dccp
.handshake_seq
)
507 set_bit(IPS_ASSURED_BIT
, &ct
->status
);
511 * Connection tracking might be out of sync, so we ignore
512 * packets that might establish a new connection and resync
513 * if the server responds with a valid Response.
515 if (ct
->proto
.dccp
.last_dir
== !dir
&&
516 ct
->proto
.dccp
.last_pkt
== DCCP_PKT_REQUEST
&&
517 type
== DCCP_PKT_RESPONSE
) {
518 ct
->proto
.dccp
.role
[!dir
] = CT_DCCP_ROLE_CLIENT
;
519 ct
->proto
.dccp
.role
[dir
] = CT_DCCP_ROLE_SERVER
;
520 ct
->proto
.dccp
.handshake_seq
= dccp_hdr_seq(dh
);
521 new_state
= CT_DCCP_RESPOND
;
524 ct
->proto
.dccp
.last_dir
= dir
;
525 ct
->proto
.dccp
.last_pkt
= type
;
527 write_unlock_bh(&dccp_lock
);
528 if (LOG_INVALID(IPPROTO_DCCP
))
529 nf_log_packet(pf
, 0, skb
, NULL
, NULL
, NULL
,
530 "nf_ct_dccp: invalid packet ignored ");
532 case CT_DCCP_INVALID
:
533 write_unlock_bh(&dccp_lock
);
534 if (LOG_INVALID(IPPROTO_DCCP
))
535 nf_log_packet(pf
, 0, skb
, NULL
, NULL
, NULL
,
536 "nf_ct_dccp: invalid state transition ");
540 ct
->proto
.dccp
.last_dir
= dir
;
541 ct
->proto
.dccp
.last_pkt
= type
;
542 ct
->proto
.dccp
.state
= new_state
;
543 write_unlock_bh(&dccp_lock
);
544 nf_ct_refresh_acct(ct
, ctinfo
, skb
, dccp_timeout
[new_state
]);
549 static int dccp_error(struct sk_buff
*skb
, unsigned int dataoff
,
550 enum ip_conntrack_info
*ctinfo
, int pf
,
551 unsigned int hooknum
)
553 struct dccp_hdr _dh
, *dh
;
554 unsigned int dccp_len
= skb
->len
- dataoff
;
558 dh
= skb_header_pointer(skb
, dataoff
, sizeof(_dh
), &dh
);
560 msg
= "nf_ct_dccp: short packet ";
564 if (dh
->dccph_doff
* 4 < sizeof(struct dccp_hdr
) ||
565 dh
->dccph_doff
* 4 > dccp_len
) {
566 msg
= "nf_ct_dccp: truncated/malformed packet ";
571 if (dh
->dccph_cscov
) {
572 cscov
= (dh
->dccph_cscov
- 1) * 4;
573 if (cscov
> dccp_len
) {
574 msg
= "nf_ct_dccp: bad checksum coverage ";
579 if (nf_conntrack_checksum
&& hooknum
== NF_INET_PRE_ROUTING
&&
580 nf_checksum_partial(skb
, hooknum
, dataoff
, cscov
, IPPROTO_DCCP
,
582 msg
= "nf_ct_dccp: bad checksum ";
586 if (dh
->dccph_type
>= DCCP_PKT_INVALID
) {
587 msg
= "nf_ct_dccp: reserved packet type ";
594 if (LOG_INVALID(IPPROTO_DCCP
))
595 nf_log_packet(pf
, 0, skb
, NULL
, NULL
, NULL
, msg
);
599 static int dccp_print_tuple(struct seq_file
*s
,
600 const struct nf_conntrack_tuple
*tuple
)
602 return seq_printf(s
, "sport=%hu dport=%hu ",
603 ntohs(tuple
->src
.u
.dccp
.port
),
604 ntohs(tuple
->dst
.u
.dccp
.port
));
607 static int dccp_print_conntrack(struct seq_file
*s
, const struct nf_conn
*ct
)
609 return seq_printf(s
, "%s ", dccp_state_names
[ct
->proto
.dccp
.state
]);
612 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
613 static int dccp_to_nlattr(struct sk_buff
*skb
, struct nlattr
*nla
,
614 const struct nf_conn
*ct
)
616 struct nlattr
*nest_parms
;
618 read_lock_bh(&dccp_lock
);
619 nest_parms
= nla_nest_start(skb
, CTA_PROTOINFO_DCCP
| NLA_F_NESTED
);
621 goto nla_put_failure
;
622 NLA_PUT_U8(skb
, CTA_PROTOINFO_DCCP_STATE
, ct
->proto
.dccp
.state
);
623 nla_nest_end(skb
, nest_parms
);
624 read_unlock_bh(&dccp_lock
);
628 read_unlock_bh(&dccp_lock
);
632 static const struct nla_policy dccp_nla_policy
[CTA_PROTOINFO_DCCP_MAX
+ 1] = {
633 [CTA_PROTOINFO_DCCP_STATE
] = { .type
= NLA_U8
},
636 static int nlattr_to_dccp(struct nlattr
*cda
[], struct nf_conn
*ct
)
638 struct nlattr
*attr
= cda
[CTA_PROTOINFO_DCCP
];
639 struct nlattr
*tb
[CTA_PROTOINFO_DCCP_MAX
+ 1];
645 err
= nla_parse_nested(tb
, CTA_PROTOINFO_DCCP_MAX
, attr
,
650 if (!tb
[CTA_PROTOINFO_DCCP_STATE
] ||
651 nla_get_u8(tb
[CTA_PROTOINFO_DCCP_STATE
]) >= CT_DCCP_IGNORE
)
654 write_lock_bh(&dccp_lock
);
655 ct
->proto
.dccp
.state
= nla_get_u8(tb
[CTA_PROTOINFO_DCCP_STATE
]);
656 write_unlock_bh(&dccp_lock
);
662 static unsigned int dccp_sysctl_table_users
;
663 static struct ctl_table_header
*dccp_sysctl_header
;
664 static ctl_table dccp_sysctl_table
[] = {
666 .ctl_name
= CTL_UNNUMBERED
,
667 .procname
= "nf_conntrack_dccp_timeout_request",
668 .data
= &dccp_timeout
[CT_DCCP_REQUEST
],
669 .maxlen
= sizeof(unsigned int),
671 .proc_handler
= proc_dointvec_jiffies
,
674 .ctl_name
= CTL_UNNUMBERED
,
675 .procname
= "nf_conntrack_dccp_timeout_respond",
676 .data
= &dccp_timeout
[CT_DCCP_RESPOND
],
677 .maxlen
= sizeof(unsigned int),
679 .proc_handler
= proc_dointvec_jiffies
,
682 .ctl_name
= CTL_UNNUMBERED
,
683 .procname
= "nf_conntrack_dccp_timeout_partopen",
684 .data
= &dccp_timeout
[CT_DCCP_PARTOPEN
],
685 .maxlen
= sizeof(unsigned int),
687 .proc_handler
= proc_dointvec_jiffies
,
690 .ctl_name
= CTL_UNNUMBERED
,
691 .procname
= "nf_conntrack_dccp_timeout_open",
692 .data
= &dccp_timeout
[CT_DCCP_OPEN
],
693 .maxlen
= sizeof(unsigned int),
695 .proc_handler
= proc_dointvec_jiffies
,
698 .ctl_name
= CTL_UNNUMBERED
,
699 .procname
= "nf_conntrack_dccp_timeout_closereq",
700 .data
= &dccp_timeout
[CT_DCCP_CLOSEREQ
],
701 .maxlen
= sizeof(unsigned int),
703 .proc_handler
= proc_dointvec_jiffies
,
706 .ctl_name
= CTL_UNNUMBERED
,
707 .procname
= "nf_conntrack_dccp_timeout_closing",
708 .data
= &dccp_timeout
[CT_DCCP_CLOSING
],
709 .maxlen
= sizeof(unsigned int),
711 .proc_handler
= proc_dointvec_jiffies
,
714 .ctl_name
= CTL_UNNUMBERED
,
715 .procname
= "nf_conntrack_dccp_timeout_timewait",
716 .data
= &dccp_timeout
[CT_DCCP_TIMEWAIT
],
717 .maxlen
= sizeof(unsigned int),
719 .proc_handler
= proc_dointvec_jiffies
,
722 .ctl_name
= CTL_UNNUMBERED
,
723 .procname
= "nf_conntrack_dccp_loose",
724 .data
= &nf_ct_dccp_loose
,
725 .maxlen
= sizeof(nf_ct_dccp_loose
),
727 .proc_handler
= proc_dointvec
,
733 #endif /* CONFIG_SYSCTL */
735 static struct nf_conntrack_l4proto dccp_proto4 __read_mostly
= {
737 .l4proto
= IPPROTO_DCCP
,
739 .pkt_to_tuple
= dccp_pkt_to_tuple
,
740 .invert_tuple
= dccp_invert_tuple
,
742 .packet
= dccp_packet
,
744 .print_tuple
= dccp_print_tuple
,
745 .print_conntrack
= dccp_print_conntrack
,
746 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
747 .to_nlattr
= dccp_to_nlattr
,
748 .from_nlattr
= nlattr_to_dccp
,
749 .tuple_to_nlattr
= nf_ct_port_tuple_to_nlattr
,
750 .nlattr_to_tuple
= nf_ct_port_nlattr_to_tuple
,
751 .nla_policy
= nf_ct_port_nla_policy
,
754 .ctl_table_users
= &dccp_sysctl_table_users
,
755 .ctl_table_header
= &dccp_sysctl_header
,
756 .ctl_table
= dccp_sysctl_table
,
760 static struct nf_conntrack_l4proto dccp_proto6 __read_mostly
= {
762 .l4proto
= IPPROTO_DCCP
,
764 .pkt_to_tuple
= dccp_pkt_to_tuple
,
765 .invert_tuple
= dccp_invert_tuple
,
767 .packet
= dccp_packet
,
769 .print_tuple
= dccp_print_tuple
,
770 .print_conntrack
= dccp_print_conntrack
,
771 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
772 .to_nlattr
= dccp_to_nlattr
,
773 .from_nlattr
= nlattr_to_dccp
,
774 .tuple_to_nlattr
= nf_ct_port_tuple_to_nlattr
,
775 .nlattr_to_tuple
= nf_ct_port_nlattr_to_tuple
,
776 .nla_policy
= nf_ct_port_nla_policy
,
779 .ctl_table_users
= &dccp_sysctl_table_users
,
780 .ctl_table_header
= &dccp_sysctl_header
,
781 .ctl_table
= dccp_sysctl_table
,
785 static int __init
nf_conntrack_proto_dccp_init(void)
789 err
= nf_conntrack_l4proto_register(&dccp_proto4
);
793 err
= nf_conntrack_l4proto_register(&dccp_proto6
);
799 nf_conntrack_l4proto_unregister(&dccp_proto4
);
804 static void __exit
nf_conntrack_proto_dccp_fini(void)
806 nf_conntrack_l4proto_unregister(&dccp_proto6
);
807 nf_conntrack_l4proto_unregister(&dccp_proto4
);
810 module_init(nf_conntrack_proto_dccp_init
);
811 module_exit(nf_conntrack_proto_dccp_fini
);
813 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
814 MODULE_DESCRIPTION("DCCP connection tracking protocol helper");
815 MODULE_LICENSE("GPL");