Blame view

net/netfilter/nf_conntrack_proto_dccp.c 25.8 KB
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /*
   * DCCP connection tracking protocol helper
   *
   * Copyright (c) 2005, 2006, 2008 Patrick McHardy <kaber@trash.net>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   */
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/sysctl.h>
  #include <linux/spinlock.h>
  #include <linux/skbuff.h>
  #include <linux/dccp.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
18
  #include <linux/slab.h>
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
19

1546000fe   Cyrill Gorcunov   net: netfilter co...
20
21
  #include <net/net_namespace.h>
  #include <net/netns/generic.h>
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
22
23
24
  #include <linux/netfilter/nfnetlink_conntrack.h>
  #include <net/netfilter/nf_conntrack.h>
  #include <net/netfilter/nf_conntrack_l4proto.h>
b38b1f616   Pablo Neira Ayuso   netfilter: nf_ct_...
25
  #include <net/netfilter/nf_conntrack_ecache.h>
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
26
  #include <net/netfilter/nf_log.h>
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  /* Timeouts are based on values from RFC4340:
   *
   * - REQUEST:
   *
   *   8.1.2. Client Request
   *
   *   A client MAY give up on its DCCP-Requests after some time
   *   (3 minutes, for example).
   *
   * - RESPOND:
   *
   *   8.1.3. Server Response
   *
   *   It MAY also leave the RESPOND state for CLOSED after a timeout of
   *   not less than 4MSL (8 minutes);
   *
   * - PARTOPEN:
   *
   *   8.1.5. Handshake Completion
   *
   *   If the client remains in PARTOPEN for more than 4MSL (8 minutes),
   *   it SHOULD reset the connection with Reset Code 2, "Aborted".
   *
   * - OPEN:
   *
   *   The DCCP timestamp overflows after 11.9 hours. If the connection
   *   stays idle this long the sequence number won't be recognized
   *   as valid anymore.
   *
   * - CLOSEREQ/CLOSING:
   *
   *   8.3. Termination
   *
   *   The retransmission timer should initially be set to go off in two
   *   round-trip times and should back off to not less than once every
   *   64 seconds ...
   *
   * - TIMEWAIT:
   *
   *   4.3. States
   *
   *   A server or client socket remains in this state for 2MSL (4 minutes)
   *   after the connection has been town down, ...
   */
  
  #define DCCP_MSL (2 * 60 * HZ)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
  static const char * const dccp_state_names[] = {
  	[CT_DCCP_NONE]		= "NONE",
  	[CT_DCCP_REQUEST]	= "REQUEST",
  	[CT_DCCP_RESPOND]	= "RESPOND",
  	[CT_DCCP_PARTOPEN]	= "PARTOPEN",
  	[CT_DCCP_OPEN]		= "OPEN",
  	[CT_DCCP_CLOSEREQ]	= "CLOSEREQ",
  	[CT_DCCP_CLOSING]	= "CLOSING",
  	[CT_DCCP_TIMEWAIT]	= "TIMEWAIT",
  	[CT_DCCP_IGNORE]	= "IGNORE",
  	[CT_DCCP_INVALID]	= "INVALID",
  };
  
  #define sNO	CT_DCCP_NONE
  #define sRQ	CT_DCCP_REQUEST
  #define sRS	CT_DCCP_RESPOND
  #define sPO	CT_DCCP_PARTOPEN
  #define sOP	CT_DCCP_OPEN
  #define sCR	CT_DCCP_CLOSEREQ
  #define sCG	CT_DCCP_CLOSING
  #define sTW	CT_DCCP_TIMEWAIT
  #define sIG	CT_DCCP_IGNORE
  #define sIV	CT_DCCP_INVALID
  
  /*
   * DCCP state transistion table
   *
   * The assumption is the same as for TCP tracking:
   *
   * We are the man in the middle. All the packets go through us but might
   * get lost in transit to the destination. It is assumed that the destination
   * can't receive segments we haven't seen.
   *
   * The following states exist:
   *
   * NONE:	Initial state, expecting Request
   * REQUEST:	Request seen, waiting for Response from server
   * RESPOND:	Response from server seen, waiting for Ack from client
   * PARTOPEN:	Ack after Response seen, waiting for packet other than Response,
   * 		Reset or Sync from server
   * OPEN:	Packet other than Response, Reset or Sync seen
   * CLOSEREQ:	CloseReq from server seen, expecting Close from client
   * CLOSING:	Close seen, expecting Reset
   * TIMEWAIT:	Reset seen
   * IGNORE:	Not determinable whether packet is valid
   *
   * Some states exist only on one side of the connection: REQUEST, RESPOND,
   * PARTOPEN, CLOSEREQ. For the other side these states are equivalent to
   * the one it was in before.
   *
   * Packets are marked as ignored (sIG) if we don't know if they're valid
   * (for example a reincarnation of a connection we didn't notice is dead
   * already) and the server may send back a connection closing Reset or a
   * Response. They're also used for Sync/SyncAck packets, which we don't
   * care about.
   */
  static const u_int8_t
  dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
  	[CT_DCCP_ROLE_CLIENT] = {
  		[DCCP_PKT_REQUEST] = {
  		/*
  		 * sNO -> sRQ		Regular Request
  		 * sRQ -> sRQ		Retransmitted Request or reincarnation
  		 * sRS -> sRS		Retransmitted Request (apparently Response
  		 * 			got lost after we saw it) or reincarnation
  		 * sPO -> sIG		Ignore, conntrack might be out of sync
  		 * sOP -> sIG		Ignore, conntrack might be out of sync
  		 * sCR -> sIG		Ignore, conntrack might be out of sync
  		 * sCG -> sIG		Ignore, conntrack might be out of sync
  		 * sTW -> sRQ		Reincarnation
  		 *
  		 *	sNO, sRQ, sRS, sPO. sOP, sCR, sCG, sTW, */
  			sRQ, sRQ, sRS, sIG, sIG, sIG, sIG, sRQ,
  		},
  		[DCCP_PKT_RESPONSE] = {
  		/*
  		 * sNO -> sIV		Invalid
  		 * sRQ -> sIG		Ignore, might be response to ignored Request
  		 * sRS -> sIG		Ignore, might be response to ignored Request
  		 * sPO -> sIG		Ignore, might be response to ignored Request
  		 * sOP -> sIG		Ignore, might be response to ignored Request
  		 * sCR -> sIG		Ignore, might be response to ignored Request
  		 * sCG -> sIG		Ignore, might be response to ignored Request
  		 * sTW -> sIV		Invalid, reincarnation in reverse direction
  		 *			goes through sRQ
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIG, sIG, sIG, sIG, sIG, sIG, sIV,
  		},
  		[DCCP_PKT_ACK] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sPO		Ack for Response, move to PARTOPEN (8.1.5.)
  		 * sPO -> sPO		Retransmitted Ack for Response, remain in PARTOPEN
  		 * sOP -> sOP		Regular ACK, remain in OPEN
  		 * sCR -> sCR		Ack in CLOSEREQ MAY be processed (8.3.)
  		 * sCG -> sCG		Ack in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sPO, sPO, sOP, sCR, sCG, sIV
  		},
  		[DCCP_PKT_DATA] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sIV		MUST use DataAck in PARTOPEN state (8.1.5.)
  		 * sOP -> sOP		Regular Data packet
  		 * sCR -> sCR		Data in CLOSEREQ MAY be processed (8.3.)
  		 * sCG -> sCG		Data in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sIV, sOP, sCR, sCG, sIV,
  		},
  		[DCCP_PKT_DATAACK] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sPO		Ack for Response, move to PARTOPEN (8.1.5.)
  		 * sPO -> sPO		Remain in PARTOPEN state
  		 * sOP -> sOP		Regular DataAck packet in OPEN state
  		 * sCR -> sCR		DataAck in CLOSEREQ MAY be processed (8.3.)
  		 * sCG -> sCG		DataAck in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sPO, sPO, sOP, sCR, sCG, sIV
  		},
  		[DCCP_PKT_CLOSEREQ] = {
  		/*
  		 * CLOSEREQ may only be sent by the server.
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV
  		},
  		[DCCP_PKT_CLOSE] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sCG		Client-initiated close
  		 * sOP -> sCG		Client-initiated close
  		 * sCR -> sCG		Close in response to CloseReq (8.3.)
  		 * sCG -> sCG		Retransmit
  		 * sTW -> sIV		Late retransmit, already in TIME_WAIT
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sCG, sCG, sCG, sIV, sIV
  		},
  		[DCCP_PKT_RESET] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sTW		Sync received or timeout, SHOULD send Reset (8.1.1.)
  		 * sRS -> sTW		Response received without Request
  		 * sPO -> sTW		Timeout, SHOULD send Reset (8.1.5.)
  		 * sOP -> sTW		Connection reset
  		 * sCR -> sTW		Connection reset
  		 * sCG -> sTW		Connection reset
  		 * sTW -> sIG		Ignore (don't refresh timer)
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sTW, sTW, sTW, sTW, sTW, sTW, sIG
  		},
  		[DCCP_PKT_SYNC] = {
  		/*
  		 * We currently ignore Sync packets
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
  		},
  		[DCCP_PKT_SYNCACK] = {
  		/*
  		 * We currently ignore SyncAck packets
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
  		},
  	},
  	[CT_DCCP_ROLE_SERVER] = {
  		[DCCP_PKT_REQUEST] = {
  		/*
  		 * sNO -> sIV		Invalid
  		 * sRQ -> sIG		Ignore, conntrack might be out of sync
  		 * sRS -> sIG		Ignore, conntrack might be out of sync
  		 * sPO -> sIG		Ignore, conntrack might be out of sync
  		 * sOP -> sIG		Ignore, conntrack might be out of sync
  		 * sCR -> sIG		Ignore, conntrack might be out of sync
  		 * sCG -> sIG		Ignore, conntrack might be out of sync
  		 * sTW -> sRQ		Reincarnation, must reverse roles
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIG, sIG, sIG, sIG, sIG, sIG, sRQ
  		},
  		[DCCP_PKT_RESPONSE] = {
  		/*
  		 * sNO -> sIV		Response without Request
  		 * sRQ -> sRS		Response to clients Request
  		 * sRS -> sRS		Retransmitted Response (8.1.3. SHOULD NOT)
  		 * sPO -> sIG		Response to an ignored Request or late retransmit
  		 * sOP -> sIG		Ignore, might be response to ignored Request
  		 * sCR -> sIG		Ignore, might be response to ignored Request
  		 * sCG -> sIG		Ignore, might be response to ignored Request
  		 * sTW -> sIV		Invalid, Request from client in sTW moves to sRQ
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sRS, sRS, sIG, sIG, sIG, sIG, sIV
  		},
  		[DCCP_PKT_ACK] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sOP		Enter OPEN state (8.1.5.)
  		 * sOP -> sOP		Regular Ack in OPEN state
  		 * sCR -> sIV		Waiting for Close from client
  		 * sCG -> sCG		Ack in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sOP, sOP, sIV, sCG, sIV
  		},
  		[DCCP_PKT_DATA] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sOP		Enter OPEN state (8.1.5.)
  		 * sOP -> sOP		Regular Data packet in OPEN state
  		 * sCR -> sIV		Waiting for Close from client
  		 * sCG -> sCG		Data in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sOP, sOP, sIV, sCG, sIV
  		},
  		[DCCP_PKT_DATAACK] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sOP		Enter OPEN state (8.1.5.)
  		 * sOP -> sOP		Regular DataAck in OPEN state
  		 * sCR -> sIV		Waiting for Close from client
  		 * sCG -> sCG		Data in CLOSING MAY be processed (8.3.)
  		 * sTW -> sIV
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sOP, sOP, sIV, sCG, sIV
  		},
  		[DCCP_PKT_CLOSEREQ] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sOP -> sCR	Move directly to CLOSEREQ (8.1.5.)
  		 * sOP -> sCR		CloseReq in OPEN state
  		 * sCR -> sCR		Retransmit
  		 * sCG -> sCR		Simultaneous close, client sends another Close
  		 * sTW -> sIV		Already closed
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sCR, sCR, sCR, sCR, sIV
  		},
  		[DCCP_PKT_CLOSE] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sIV		No connection
  		 * sRS -> sIV		No connection
  		 * sPO -> sOP -> sCG	Move direcly to CLOSING
  		 * sOP -> sCG		Move to CLOSING
  		 * sCR -> sIV		Close after CloseReq is invalid
  		 * sCG -> sCG		Retransmit
  		 * sTW -> sIV		Already closed
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIV, sIV, sIV, sCG, sCG, sIV, sCG, sIV
  		},
  		[DCCP_PKT_RESET] = {
  		/*
  		 * sNO -> sIV		No connection
  		 * sRQ -> sTW		Reset in response to Request
  		 * sRS -> sTW		Timeout, SHOULD send Reset (8.1.3.)
  		 * sPO -> sTW		Timeout, SHOULD send Reset (8.1.3.)
  		 * sOP -> sTW
  		 * sCR -> sTW
  		 * sCG -> sTW
  		 * sTW -> sIG		Ignore (don't refresh timer)
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW, sTW */
  			sIV, sTW, sTW, sTW, sTW, sTW, sTW, sTW, sIG
  		},
  		[DCCP_PKT_SYNC] = {
  		/*
  		 * We currently ignore Sync packets
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
  		},
  		[DCCP_PKT_SYNCACK] = {
  		/*
  		 * We currently ignore SyncAck packets
  		 *
  		 *	sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
  			sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
  		},
  	},
  };
1546000fe   Cyrill Gorcunov   net: netfilter co...
383
  /* this module per-net specifics */
f99189b18   Eric Dumazet   netns: net_identi...
384
  static int dccp_net_id __read_mostly;
1546000fe   Cyrill Gorcunov   net: netfilter co...
385
386
387
388
389
390
391
392
393
394
395
396
397
  struct dccp_net {
  	int dccp_loose;
  	unsigned int dccp_timeout[CT_DCCP_MAX + 1];
  #ifdef CONFIG_SYSCTL
  	struct ctl_table_header *sysctl_header;
  	struct ctl_table *sysctl_table;
  #endif
  };
  
  static inline struct dccp_net *dccp_pernet(struct net *net)
  {
  	return net_generic(net, dccp_net_id);
  }
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
398
399
  static bool dccp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
  			      struct nf_conntrack_tuple *tuple)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
400
401
402
403
404
  {
  	struct dccp_hdr _hdr, *dh;
  
  	dh = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
  	if (dh == NULL)
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
405
  		return false;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
406
407
408
  
  	tuple->src.u.dccp.port = dh->dccph_sport;
  	tuple->dst.u.dccp.port = dh->dccph_dport;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
409
  	return true;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
410
  }
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
411
412
  static bool dccp_invert_tuple(struct nf_conntrack_tuple *inv,
  			      const struct nf_conntrack_tuple *tuple)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
413
414
415
  {
  	inv->src.u.dccp.port = tuple->dst.u.dccp.port;
  	inv->dst.u.dccp.port = tuple->src.u.dccp.port;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
416
  	return true;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
417
  }
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
418
419
  static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
  		     unsigned int dataoff)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
420
  {
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
421
  	struct net *net = nf_ct_net(ct);
1546000fe   Cyrill Gorcunov   net: netfilter co...
422
  	struct dccp_net *dn;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
423
424
425
426
427
428
429
430
431
432
  	struct dccp_hdr _dh, *dh;
  	const char *msg;
  	u_int8_t state;
  
  	dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
  	BUG_ON(dh == NULL);
  
  	state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
  	switch (state) {
  	default:
1546000fe   Cyrill Gorcunov   net: netfilter co...
433
434
  		dn = dccp_pernet(net);
  		if (dn->dccp_loose == 0) {
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
435
436
437
438
439
440
441
442
443
444
445
446
447
  			msg = "nf_ct_dccp: not picking up existing connection ";
  			goto out_invalid;
  		}
  	case CT_DCCP_REQUEST:
  		break;
  	case CT_DCCP_INVALID:
  		msg = "nf_ct_dccp: invalid state transition ";
  		goto out_invalid;
  	}
  
  	ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
  	ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
  	ct->proto.dccp.state = CT_DCCP_NONE;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
448
  	return true;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
449
450
  
  out_invalid:
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
451
  	if (LOG_INVALID(net, IPPROTO_DCCP))
5e8fbe2ac   Patrick McHardy   [NETFILTER]: nf_c...
452
  		nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, msg);
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
453
  	return false;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
454
455
456
457
458
459
460
461
462
463
464
465
466
  }
  
  static u64 dccp_ack_seq(const struct dccp_hdr *dh)
  {
  	const struct dccp_hdr_ack_bits *dhack;
  
  	dhack = (void *)dh + __dccp_basic_hdr_len(dh);
  	return ((u64)ntohs(dhack->dccph_ack_nr_high) << 32) +
  		     ntohl(dhack->dccph_ack_nr_low);
  }
  
  static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
  		       unsigned int dataoff, enum ip_conntrack_info ctinfo,
76108cea0   Jan Engelhardt   netfilter: Use un...
467
  		       u_int8_t pf, unsigned int hooknum)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
468
  {
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
469
  	struct net *net = nf_ct_net(ct);
1546000fe   Cyrill Gorcunov   net: netfilter co...
470
  	struct dccp_net *dn;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
471
472
473
474
475
476
477
478
479
480
481
482
  	enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
  	struct dccp_hdr _dh, *dh;
  	u_int8_t type, old_state, new_state;
  	enum ct_dccp_roles role;
  
  	dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
  	BUG_ON(dh == NULL);
  	type = dh->dccph_type;
  
  	if (type == DCCP_PKT_RESET &&
  	    !test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
  		/* Tear down connection immediately if only reply is a RESET */
718d4ad98   Fabian Hugelshofer   netfilter: nf_con...
483
  		nf_ct_kill_acct(ct, ctinfo, skb);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
484
485
  		return NF_ACCEPT;
  	}
440f0d588   Patrick McHardy   netfilter: nf_con...
486
  	spin_lock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
  
  	role = ct->proto.dccp.role[dir];
  	old_state = ct->proto.dccp.state;
  	new_state = dccp_state_table[role][type][old_state];
  
  	switch (new_state) {
  	case CT_DCCP_REQUEST:
  		if (old_state == CT_DCCP_TIMEWAIT &&
  		    role == CT_DCCP_ROLE_SERVER) {
  			/* Reincarnation in the reverse direction: reopen and
  			 * reverse client/server roles. */
  			ct->proto.dccp.role[dir] = CT_DCCP_ROLE_CLIENT;
  			ct->proto.dccp.role[!dir] = CT_DCCP_ROLE_SERVER;
  		}
  		break;
  	case CT_DCCP_RESPOND:
  		if (old_state == CT_DCCP_REQUEST)
  			ct->proto.dccp.handshake_seq = dccp_hdr_seq(dh);
  		break;
  	case CT_DCCP_PARTOPEN:
  		if (old_state == CT_DCCP_RESPOND &&
  		    type == DCCP_PKT_ACK &&
  		    dccp_ack_seq(dh) == ct->proto.dccp.handshake_seq)
  			set_bit(IPS_ASSURED_BIT, &ct->status);
  		break;
  	case CT_DCCP_IGNORE:
  		/*
  		 * Connection tracking might be out of sync, so we ignore
  		 * packets that might establish a new connection and resync
  		 * if the server responds with a valid Response.
  		 */
  		if (ct->proto.dccp.last_dir == !dir &&
  		    ct->proto.dccp.last_pkt == DCCP_PKT_REQUEST &&
  		    type == DCCP_PKT_RESPONSE) {
  			ct->proto.dccp.role[!dir] = CT_DCCP_ROLE_CLIENT;
  			ct->proto.dccp.role[dir] = CT_DCCP_ROLE_SERVER;
  			ct->proto.dccp.handshake_seq = dccp_hdr_seq(dh);
  			new_state = CT_DCCP_RESPOND;
  			break;
  		}
  		ct->proto.dccp.last_dir = dir;
  		ct->proto.dccp.last_pkt = type;
440f0d588   Patrick McHardy   netfilter: nf_con...
529
  		spin_unlock_bh(&ct->lock);
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
530
  		if (LOG_INVALID(net, IPPROTO_DCCP))
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
531
532
533
534
  			nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_dccp: invalid packet ignored ");
  		return NF_ACCEPT;
  	case CT_DCCP_INVALID:
440f0d588   Patrick McHardy   netfilter: nf_con...
535
  		spin_unlock_bh(&ct->lock);
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
536
  		if (LOG_INVALID(net, IPPROTO_DCCP))
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
537
538
539
540
541
542
543
544
  			nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_dccp: invalid state transition ");
  		return -NF_ACCEPT;
  	}
  
  	ct->proto.dccp.last_dir = dir;
  	ct->proto.dccp.last_pkt = type;
  	ct->proto.dccp.state = new_state;
440f0d588   Patrick McHardy   netfilter: nf_con...
545
  	spin_unlock_bh(&ct->lock);
1546000fe   Cyrill Gorcunov   net: netfilter co...
546

b38b1f616   Pablo Neira Ayuso   netfilter: nf_ct_...
547
548
  	if (new_state != old_state)
  		nf_conntrack_event_cache(IPCT_PROTOINFO, ct);
1546000fe   Cyrill Gorcunov   net: netfilter co...
549
550
  	dn = dccp_pernet(net);
  	nf_ct_refresh_acct(ct, ctinfo, skb, dn->dccp_timeout[new_state]);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
551
552
553
  
  	return NF_ACCEPT;
  }
8fea97ec1   Patrick McHardy   netfilter: nf_con...
554
555
556
  static int dccp_error(struct net *net, struct nf_conn *tmpl,
  		      struct sk_buff *skb, unsigned int dataoff,
  		      enum ip_conntrack_info *ctinfo,
74c51a149   Alexey Dobriyan   netfilter: netns ...
557
  		      u_int8_t pf, unsigned int hooknum)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  {
  	struct dccp_hdr _dh, *dh;
  	unsigned int dccp_len = skb->len - dataoff;
  	unsigned int cscov;
  	const char *msg;
  
  	dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
  	if (dh == NULL) {
  		msg = "nf_ct_dccp: short packet ";
  		goto out_invalid;
  	}
  
  	if (dh->dccph_doff * 4 < sizeof(struct dccp_hdr) ||
  	    dh->dccph_doff * 4 > dccp_len) {
  		msg = "nf_ct_dccp: truncated/malformed packet ";
  		goto out_invalid;
  	}
  
  	cscov = dccp_len;
  	if (dh->dccph_cscov) {
  		cscov = (dh->dccph_cscov - 1) * 4;
  		if (cscov > dccp_len) {
  			msg = "nf_ct_dccp: bad checksum coverage ";
  			goto out_invalid;
  		}
  	}
c04d05529   Alexey Dobriyan   netfilter: netns ...
584
  	if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
  	    nf_checksum_partial(skb, hooknum, dataoff, cscov, IPPROTO_DCCP,
  				pf)) {
  		msg = "nf_ct_dccp: bad checksum ";
  		goto out_invalid;
  	}
  
  	if (dh->dccph_type >= DCCP_PKT_INVALID) {
  		msg = "nf_ct_dccp: reserved packet type ";
  		goto out_invalid;
  	}
  
  	return NF_ACCEPT;
  
  out_invalid:
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
599
  	if (LOG_INVALID(net, IPPROTO_DCCP))
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
600
601
602
603
604
605
606
607
608
609
610
  		nf_log_packet(pf, 0, skb, NULL, NULL, NULL, msg);
  	return -NF_ACCEPT;
  }
  
  static int dccp_print_tuple(struct seq_file *s,
  			    const struct nf_conntrack_tuple *tuple)
  {
  	return seq_printf(s, "sport=%hu dport=%hu ",
  			  ntohs(tuple->src.u.dccp.port),
  			  ntohs(tuple->dst.u.dccp.port));
  }
440f0d588   Patrick McHardy   netfilter: nf_con...
611
  static int dccp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
612
613
614
615
616
617
  {
  	return seq_printf(s, "%s ", dccp_state_names[ct->proto.dccp.state]);
  }
  
  #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
  static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
440f0d588   Patrick McHardy   netfilter: nf_con...
618
  			  struct nf_conn *ct)
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
619
620
  {
  	struct nlattr *nest_parms;
440f0d588   Patrick McHardy   netfilter: nf_con...
621
  	spin_lock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
622
623
624
625
  	nest_parms = nla_nest_start(skb, CTA_PROTOINFO_DCCP | NLA_F_NESTED);
  	if (!nest_parms)
  		goto nla_put_failure;
  	NLA_PUT_U8(skb, CTA_PROTOINFO_DCCP_STATE, ct->proto.dccp.state);
71951b64a   Pablo Neira Ayuso   netfilter: nf_ct_...
626
627
  	NLA_PUT_U8(skb, CTA_PROTOINFO_DCCP_ROLE,
  		   ct->proto.dccp.role[IP_CT_DIR_ORIGINAL]);
a17c85984   Pablo Neira Ayuso   netfilter: conntr...
628
629
  	NLA_PUT_BE64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
  		     cpu_to_be64(ct->proto.dccp.handshake_seq));
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
630
  	nla_nest_end(skb, nest_parms);
440f0d588   Patrick McHardy   netfilter: nf_con...
631
  	spin_unlock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
632
633
634
  	return 0;
  
  nla_put_failure:
440f0d588   Patrick McHardy   netfilter: nf_con...
635
  	spin_unlock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
636
637
638
639
640
  	return -1;
  }
  
  static const struct nla_policy dccp_nla_policy[CTA_PROTOINFO_DCCP_MAX + 1] = {
  	[CTA_PROTOINFO_DCCP_STATE]	= { .type = NLA_U8 },
71951b64a   Pablo Neira Ayuso   netfilter: nf_ct_...
641
  	[CTA_PROTOINFO_DCCP_ROLE]	= { .type = NLA_U8 },
a17c85984   Pablo Neira Ayuso   netfilter: conntr...
642
  	[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ] = { .type = NLA_U64 },
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
  };
  
  static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
  {
  	struct nlattr *attr = cda[CTA_PROTOINFO_DCCP];
  	struct nlattr *tb[CTA_PROTOINFO_DCCP_MAX + 1];
  	int err;
  
  	if (!attr)
  		return 0;
  
  	err = nla_parse_nested(tb, CTA_PROTOINFO_DCCP_MAX, attr,
  			       dccp_nla_policy);
  	if (err < 0)
  		return err;
  
  	if (!tb[CTA_PROTOINFO_DCCP_STATE] ||
71951b64a   Pablo Neira Ayuso   netfilter: nf_ct_...
660
661
662
  	    !tb[CTA_PROTOINFO_DCCP_ROLE] ||
  	    nla_get_u8(tb[CTA_PROTOINFO_DCCP_ROLE]) > CT_DCCP_ROLE_MAX ||
  	    nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]) >= CT_DCCP_IGNORE) {
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
663
  		return -EINVAL;
71951b64a   Pablo Neira Ayuso   netfilter: nf_ct_...
664
  	}
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
665

440f0d588   Patrick McHardy   netfilter: nf_con...
666
  	spin_lock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
667
  	ct->proto.dccp.state = nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]);
71951b64a   Pablo Neira Ayuso   netfilter: nf_ct_...
668
669
670
671
672
673
674
  	if (nla_get_u8(tb[CTA_PROTOINFO_DCCP_ROLE]) == CT_DCCP_ROLE_CLIENT) {
  		ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
  		ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
  	} else {
  		ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_SERVER;
  		ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_CLIENT;
  	}
a17c85984   Pablo Neira Ayuso   netfilter: conntr...
675
676
677
678
  	if (tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]) {
  		ct->proto.dccp.handshake_seq =
  		be64_to_cpu(nla_get_be64(tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]));
  	}
440f0d588   Patrick McHardy   netfilter: nf_con...
679
  	spin_unlock_bh(&ct->lock);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
680
681
  	return 0;
  }
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
682
683
684
685
686
687
  
  static int dccp_nlattr_size(void)
  {
  	return nla_total_size(0)	/* CTA_PROTOINFO_DCCP */
  		+ nla_policy_len(dccp_nla_policy, CTA_PROTOINFO_DCCP_MAX + 1);
  }
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
688
689
690
  #endif
  
  #ifdef CONFIG_SYSCTL
1546000fe   Cyrill Gorcunov   net: netfilter co...
691
692
  /* template, data assigned later */
  static struct ctl_table dccp_sysctl_table[] = {
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
693
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
694
  		.procname	= "nf_conntrack_dccp_timeout_request",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
695
696
697
698
699
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
700
  		.procname	= "nf_conntrack_dccp_timeout_respond",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
701
702
703
704
705
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
706
  		.procname	= "nf_conntrack_dccp_timeout_partopen",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
707
708
709
710
711
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
712
  		.procname	= "nf_conntrack_dccp_timeout_open",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
713
714
715
716
717
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
718
  		.procname	= "nf_conntrack_dccp_timeout_closereq",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
719
720
721
722
723
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
724
  		.procname	= "nf_conntrack_dccp_timeout_closing",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
725
726
727
728
729
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
730
  		.procname	= "nf_conntrack_dccp_timeout_timewait",
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
731
732
733
734
735
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec_jiffies,
  	},
  	{
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
736
  		.procname	= "nf_conntrack_dccp_loose",
1546000fe   Cyrill Gorcunov   net: netfilter co...
737
  		.maxlen		= sizeof(int),
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
738
739
740
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec,
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
741
  	{ }
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
  };
  #endif /* CONFIG_SYSCTL */
  
  static struct nf_conntrack_l4proto dccp_proto4 __read_mostly = {
  	.l3proto		= AF_INET,
  	.l4proto		= IPPROTO_DCCP,
  	.name			= "dccp",
  	.pkt_to_tuple		= dccp_pkt_to_tuple,
  	.invert_tuple		= dccp_invert_tuple,
  	.new			= dccp_new,
  	.packet			= dccp_packet,
  	.error			= dccp_error,
  	.print_tuple		= dccp_print_tuple,
  	.print_conntrack	= dccp_print_conntrack,
  #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
  	.to_nlattr		= dccp_to_nlattr,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
758
  	.nlattr_size		= dccp_nlattr_size,
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
759
760
  	.from_nlattr		= nlattr_to_dccp,
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
761
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
762
763
764
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
  	.nla_policy		= nf_ct_port_nla_policy,
  #endif
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
  };
  
  static struct nf_conntrack_l4proto dccp_proto6 __read_mostly = {
  	.l3proto		= AF_INET6,
  	.l4proto		= IPPROTO_DCCP,
  	.name			= "dccp",
  	.pkt_to_tuple		= dccp_pkt_to_tuple,
  	.invert_tuple		= dccp_invert_tuple,
  	.new			= dccp_new,
  	.packet			= dccp_packet,
  	.error			= dccp_error,
  	.print_tuple		= dccp_print_tuple,
  	.print_conntrack	= dccp_print_conntrack,
  #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
  	.to_nlattr		= dccp_to_nlattr,
5ff482940   Patrick McHardy   netfilter: nf_ct_...
780
  	.nlattr_size		= dccp_nlattr_size,
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
781
782
  	.from_nlattr		= nlattr_to_dccp,
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
783
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
784
785
786
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
  	.nla_policy		= nf_ct_port_nla_policy,
  #endif
1546000fe   Cyrill Gorcunov   net: netfilter co...
787
788
789
790
  };
  
  static __net_init int dccp_net_init(struct net *net)
  {
32b51f92d   Eric W. Biederman   net: Simplify con...
791
  	struct dccp_net *dn = dccp_pernet(net);
1546000fe   Cyrill Gorcunov   net: netfilter co...
792
793
794
795
796
797
798
799
800
801
  
  	/* default values */
  	dn->dccp_loose = 1;
  	dn->dccp_timeout[CT_DCCP_REQUEST]	= 2 * DCCP_MSL;
  	dn->dccp_timeout[CT_DCCP_RESPOND]	= 4 * DCCP_MSL;
  	dn->dccp_timeout[CT_DCCP_PARTOPEN]	= 4 * DCCP_MSL;
  	dn->dccp_timeout[CT_DCCP_OPEN]		= 12 * 3600 * HZ;
  	dn->dccp_timeout[CT_DCCP_CLOSEREQ]	= 64 * HZ;
  	dn->dccp_timeout[CT_DCCP_CLOSING]	= 64 * HZ;
  	dn->dccp_timeout[CT_DCCP_TIMEWAIT]	= 2 * DCCP_MSL;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
802
  #ifdef CONFIG_SYSCTL
1546000fe   Cyrill Gorcunov   net: netfilter co...
803
804
805
  	dn->sysctl_table = kmemdup(dccp_sysctl_table,
  			sizeof(dccp_sysctl_table), GFP_KERNEL);
  	if (!dn->sysctl_table)
32b51f92d   Eric W. Biederman   net: Simplify con...
806
  		return -ENOMEM;
1546000fe   Cyrill Gorcunov   net: netfilter co...
807
808
809
810
811
812
813
814
815
816
817
818
819
820
  
  	dn->sysctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST];
  	dn->sysctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND];
  	dn->sysctl_table[2].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN];
  	dn->sysctl_table[3].data = &dn->dccp_timeout[CT_DCCP_OPEN];
  	dn->sysctl_table[4].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ];
  	dn->sysctl_table[5].data = &dn->dccp_timeout[CT_DCCP_CLOSING];
  	dn->sysctl_table[6].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT];
  	dn->sysctl_table[7].data = &dn->dccp_loose;
  
  	dn->sysctl_header = register_net_sysctl_table(net,
  			nf_net_netfilter_sysctl_path, dn->sysctl_table);
  	if (!dn->sysctl_header) {
  		kfree(dn->sysctl_table);
32b51f92d   Eric W. Biederman   net: Simplify con...
821
  		return -ENOMEM;
1546000fe   Cyrill Gorcunov   net: netfilter co...
822
  	}
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
823
  #endif
1546000fe   Cyrill Gorcunov   net: netfilter co...
824
825
  
  	return 0;
1546000fe   Cyrill Gorcunov   net: netfilter co...
826
827
828
829
830
831
832
833
834
  }
  
  static __net_exit void dccp_net_exit(struct net *net)
  {
  	struct dccp_net *dn = dccp_pernet(net);
  #ifdef CONFIG_SYSCTL
  	unregister_net_sysctl_table(dn->sysctl_header);
  	kfree(dn->sysctl_table);
  #endif
1546000fe   Cyrill Gorcunov   net: netfilter co...
835
836
837
838
839
  }
  
  static struct pernet_operations dccp_net_ops = {
  	.init = dccp_net_init,
  	.exit = dccp_net_exit,
32b51f92d   Eric W. Biederman   net: Simplify con...
840
841
  	.id   = &dccp_net_id,
  	.size = sizeof(struct dccp_net),
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
842
843
844
845
846
  };
  
  static int __init nf_conntrack_proto_dccp_init(void)
  {
  	int err;
32b51f92d   Eric W. Biederman   net: Simplify con...
847
  	err = register_pernet_subsys(&dccp_net_ops);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
848
849
  	if (err < 0)
  		goto err1;
1546000fe   Cyrill Gorcunov   net: netfilter co...
850
  	err = nf_conntrack_l4proto_register(&dccp_proto4);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
851
852
  	if (err < 0)
  		goto err2;
1546000fe   Cyrill Gorcunov   net: netfilter co...
853
854
855
856
  
  	err = nf_conntrack_l4proto_register(&dccp_proto6);
  	if (err < 0)
  		goto err3;
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
857
  	return 0;
1546000fe   Cyrill Gorcunov   net: netfilter co...
858
  err3:
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
859
  	nf_conntrack_l4proto_unregister(&dccp_proto4);
1546000fe   Cyrill Gorcunov   net: netfilter co...
860
  err2:
32b51f92d   Eric W. Biederman   net: Simplify con...
861
  	unregister_pernet_subsys(&dccp_net_ops);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
862
863
864
865
866
867
  err1:
  	return err;
  }
  
  static void __exit nf_conntrack_proto_dccp_fini(void)
  {
32b51f92d   Eric W. Biederman   net: Simplify con...
868
  	unregister_pernet_subsys(&dccp_net_ops);
2bc780499   Patrick McHardy   [NETFILTER]: nf_c...
869
870
871
872
873
874
875
876
877
878
  	nf_conntrack_l4proto_unregister(&dccp_proto6);
  	nf_conntrack_l4proto_unregister(&dccp_proto4);
  }
  
  module_init(nf_conntrack_proto_dccp_init);
  module_exit(nf_conntrack_proto_dccp_fini);
  
  MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
  MODULE_DESCRIPTION("DCCP connection tracking protocol helper");
  MODULE_LICENSE("GPL");