Merge tag 'ceph-for-5.12-rc1' of git://github.com/ceph/ceph-client
[linux-block.git] / net / dccp / ipv4.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
7c657876
ACM
2/*
3 * net/dccp/ipv4.c
4 *
5 * An implementation of the DCCP protocol
6 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7c657876
ACM
7 */
8
7c657876
ACM
9#include <linux/dccp.h>
10#include <linux/icmp.h>
5a0e3ad6 11#include <linux/slab.h>
7c657876
ACM
12#include <linux/module.h>
13#include <linux/skbuff.h>
14#include <linux/random.h>
15
16#include <net/icmp.h>
b61fafc4 17#include <net/inet_common.h>
7c657876 18#include <net/inet_hashtables.h>
14c85021 19#include <net/inet_sock.h>
b61fafc4 20#include <net/protocol.h>
7c657876 21#include <net/sock.h>
6d6ee43e 22#include <net/timewait_sock.h>
7c657876
ACM
23#include <net/tcp_states.h>
24#include <net/xfrm.h>
6e5714ea 25#include <net/secure_seq.h>
7c657876 26
ae31c339 27#include "ackvec.h"
7c657876
ACM
28#include "ccid.h"
29#include "dccp.h"
afe00251 30#include "feat.h"
7c657876 31
72478873 32/*
13f51d82 33 * The per-net dccp.v4_ctl_sk socket is used for responding to
72478873
ACM
34 * the Out-of-the-blue (OOTB) packets. A control sock will be created
35 * for this socket at the initialization time.
36 */
72478873 37
f21e68ca 38int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
7c657876 39{
2d7192d6 40 const struct sockaddr_in *usin = (struct sockaddr_in *)uaddr;
7c657876
ACM
41 struct inet_sock *inet = inet_sk(sk);
42 struct dccp_sock *dp = dccp_sk(sk);
dca8b089 43 __be16 orig_sport, orig_dport;
bada8adc 44 __be32 daddr, nexthop;
2c42758c 45 struct flowi4 *fl4;
2d7192d6 46 struct rtable *rt;
7c657876 47 int err;
f6d8bd05 48 struct ip_options_rcu *inet_opt;
7c657876
ACM
49
50 dp->dccps_role = DCCP_ROLE_CLIENT;
51
52 if (addr_len < sizeof(struct sockaddr_in))
53 return -EINVAL;
54
55 if (usin->sin_family != AF_INET)
56 return -EAFNOSUPPORT;
57
58 nexthop = daddr = usin->sin_addr.s_addr;
f6d8bd05
ED
59
60 inet_opt = rcu_dereference_protected(inet->inet_opt,
1e1d04e6 61 lockdep_sock_is_held(sk));
f6d8bd05 62 if (inet_opt != NULL && inet_opt->opt.srr) {
7c657876
ACM
63 if (daddr == 0)
64 return -EINVAL;
f6d8bd05 65 nexthop = inet_opt->opt.faddr;
7c657876
ACM
66 }
67
dca8b089
DM
68 orig_sport = inet->inet_sport;
69 orig_dport = usin->sin_port;
2c42758c
DM
70 fl4 = &inet->cork.fl.u.ip4;
71 rt = ip_route_connect(fl4, nexthop, inet->inet_saddr,
b23dd4fe
DM
72 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
73 IPPROTO_DCCP,
0e0d44ab 74 orig_sport, orig_dport, sk);
b23dd4fe
DM
75 if (IS_ERR(rt))
76 return PTR_ERR(rt);
7c657876
ACM
77
78 if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
79 ip_rt_put(rt);
80 return -ENETUNREACH;
81 }
82
f6d8bd05 83 if (inet_opt == NULL || !inet_opt->opt.srr)
2c42758c 84 daddr = fl4->daddr;
7c657876 85
c720c7e8 86 if (inet->inet_saddr == 0)
2c42758c 87 inet->inet_saddr = fl4->saddr;
d1e559d0 88 sk_rcv_saddr_set(sk, inet->inet_saddr);
c720c7e8 89 inet->inet_dport = usin->sin_port;
d1e559d0 90 sk_daddr_set(sk, daddr);
7c657876 91
d83d8461 92 inet_csk(sk)->icsk_ext_hdr_len = 0;
f6d8bd05
ED
93 if (inet_opt)
94 inet_csk(sk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
7c657876
ACM
95 /*
96 * Socket identity is still unknown (sport may be zero).
97 * However we set state to DCCP_REQUESTING and not releasing socket
98 * lock select source port, enter ourselves into the hash tables and
99 * complete initialization after this.
100 */
101 dccp_set_state(sk, DCCP_REQUESTING);
a7f5e7f1 102 err = inet_hash_connect(&dccp_death_row, sk);
7c657876
ACM
103 if (err != 0)
104 goto failure;
105
2c42758c 106 rt = ip_route_newports(fl4, rt, orig_sport, orig_dport,
b23dd4fe
DM
107 inet->inet_sport, inet->inet_dport, sk);
108 if (IS_ERR(rt)) {
525c6465 109 err = PTR_ERR(rt);
b23dd4fe 110 rt = NULL;
7c657876 111 goto failure;
b23dd4fe 112 }
7c657876 113 /* OK, now commit destination to socket. */
d8d1f30b 114 sk_setup_caps(sk, &rt->dst);
7c657876 115
c720c7e8
ED
116 dp->dccps_iss = secure_dccp_sequence_number(inet->inet_saddr,
117 inet->inet_daddr,
118 inet->inet_sport,
119 inet->inet_dport);
a904a069 120 inet->inet_id = prandom_u32();
7c657876
ACM
121
122 err = dccp_connect(sk);
123 rt = NULL;
124 if (err != 0)
125 goto failure;
126out:
127 return err;
128failure:
7690af3f
ACM
129 /*
130 * This unhashes the socket and releases the local port, if necessary.
131 */
7c657876
ACM
132 dccp_set_state(sk, DCCP_CLOSED);
133 ip_rt_put(rt);
134 sk->sk_route_caps = 0;
c720c7e8 135 inet->inet_dport = 0;
7c657876
ACM
136 goto out;
137}
f21e68ca
ACM
138EXPORT_SYMBOL_GPL(dccp_v4_connect);
139
7c657876
ACM
140/*
141 * This routine does path mtu discovery as defined in RFC1191.
142 */
143static inline void dccp_do_pmtu_discovery(struct sock *sk,
144 const struct iphdr *iph,
145 u32 mtu)
146{
147 struct dst_entry *dst;
148 const struct inet_sock *inet = inet_sk(sk);
149 const struct dccp_sock *dp = dccp_sk(sk);
150
151 /* We are not interested in DCCP_LISTEN and request_socks (RESPONSEs
152 * send out by Linux are always < 576bytes so they should go through
153 * unfragmented).
154 */
155 if (sk->sk_state == DCCP_LISTEN)
156 return;
157
80d0a69f
DM
158 dst = inet_csk_update_pmtu(sk, mtu);
159 if (!dst)
7c657876
ACM
160 return;
161
7c657876
ACM
162 /* Something is about to be wrong... Remember soft error
163 * for the case, if this connection will not able to recover.
164 */
165 if (mtu < dst_mtu(dst) && ip_dont_fragment(sk, dst))
166 sk->sk_err_soft = EMSGSIZE;
167
168 mtu = dst_mtu(dst);
169
170 if (inet->pmtudisc != IP_PMTUDISC_DONT &&
482fc609 171 ip_sk_accept_pmtu(sk) &&
d83d8461 172 inet_csk(sk)->icsk_pmtu_cookie > mtu) {
7c657876
ACM
173 dccp_sync_mss(sk, mtu);
174
175 /*
0e64e94e 176 * From RFC 4340, sec. 14.1:
7c657876 177 *
7690af3f
ACM
178 * DCCP-Sync packets are the best choice for upward
179 * probing, since DCCP-Sync probes do not risk application
180 * data loss.
7c657876 181 */
e92ae93a 182 dccp_send_sync(sk, dp->dccps_gsr, DCCP_PKT_SYNC);
7c657876
ACM
183 } /* else let the usual retransmit timer handle it */
184}
185
55be7a9c
DM
186static void dccp_do_redirect(struct sk_buff *skb, struct sock *sk)
187{
188 struct dst_entry *dst = __sk_dst_check(sk, 0);
189
1ed5c48f 190 if (dst)
6700c270 191 dst->ops->redirect(dst, sk, skb);
55be7a9c
DM
192}
193
85645bab
ED
194void dccp_req_err(struct sock *sk, u64 seq)
195 {
196 struct request_sock *req = inet_reqsk(sk);
197 struct net *net = sock_net(sk);
198
199 /*
200 * ICMPs are not backlogged, hence we cannot get an established
201 * socket here.
202 */
85645bab 203 if (!between48(seq, dccp_rsk(req)->dreq_iss, dccp_rsk(req)->dreq_gss)) {
02a1d6e7 204 __NET_INC_STATS(net, LINUX_MIB_OUTOFWINDOWICMPS);
85645bab
ED
205 } else {
206 /*
207 * Still in RESPOND, just remove it silently.
208 * There is no good way to pass the error to the newly
209 * created socket, and POSIX does not want network
210 * errors returned from accept().
211 */
212 inet_csk_reqsk_queue_drop(req->rsk_listener, req);
213 }
ef84d8ce 214 reqsk_put(req);
85645bab
ED
215}
216EXPORT_SYMBOL(dccp_req_err);
217
7c657876
ACM
218/*
219 * This routine is called by the ICMP module when it gets some sort of error
220 * condition. If err < 0 then the socket should be closed and the error
221 * returned to the user. If err > 0 it's just the icmp type << 8 | icmp code.
222 * After adjustment header points to the first 8 bytes of the tcp header. We
223 * need to find the appropriate port.
224 *
225 * The locking strategy used here is very "optimistic". When someone else
226 * accesses the socket the ICMP is just dropped and for some paths there is no
227 * check at all. A more general error queue to queue errors for later handling
228 * is probably better.
229 */
32bbd879 230static int dccp_v4_err(struct sk_buff *skb, u32 info)
7c657876
ACM
231{
232 const struct iphdr *iph = (struct iphdr *)skb->data;
18e1d836 233 const u8 offset = iph->ihl << 2;
6706a97f 234 const struct dccp_hdr *dh;
7c657876
ACM
235 struct dccp_sock *dp;
236 struct inet_sock *inet;
88c7664f
ACM
237 const int type = icmp_hdr(skb)->type;
238 const int code = icmp_hdr(skb)->code;
7c657876
ACM
239 struct sock *sk;
240 __u64 seq;
241 int err;
fd54d716 242 struct net *net = dev_net(skb->dev);
7c657876 243
6706a97f
ED
244 /* Only need dccph_dport & dccph_sport which are the first
245 * 4 bytes in dccp header.
246 * Our caller (icmp_socket_deliver()) already pulled 8 bytes for us.
247 */
248 BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_sport) > 8);
249 BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_dport) > 8);
250 dh = (struct dccp_hdr *)(skb->data + offset);
7c657876 251
85645bab
ED
252 sk = __inet_lookup_established(net, &dccp_hashinfo,
253 iph->daddr, dh->dccph_dport,
254 iph->saddr, ntohs(dh->dccph_sport),
3fa6f616 255 inet_iif(skb), 0);
85645bab 256 if (!sk) {
5d3848bc 257 __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
32bbd879 258 return -ENOENT;
7c657876
ACM
259 }
260
261 if (sk->sk_state == DCCP_TIME_WAIT) {
9469c7b4 262 inet_twsk_put(inet_twsk(sk));
32bbd879 263 return 0;
7c657876 264 }
85645bab 265 seq = dccp_hdr_seq(dh);
32bbd879
SB
266 if (sk->sk_state == DCCP_NEW_SYN_RECV) {
267 dccp_req_err(sk, seq);
268 return 0;
269 }
7c657876
ACM
270
271 bh_lock_sock(sk);
272 /* If too many ICMPs get dropped on busy
273 * servers this needs to be solved differently.
274 */
275 if (sock_owned_by_user(sk))
02a1d6e7 276 __NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS);
7c657876
ACM
277
278 if (sk->sk_state == DCCP_CLOSED)
279 goto out;
280
281 dp = dccp_sk(sk);
1238d087 282 if ((1 << sk->sk_state) & ~(DCCPF_REQUESTING | DCCPF_LISTEN) &&
d68f0866 283 !between48(seq, dp->dccps_awl, dp->dccps_awh)) {
02a1d6e7 284 __NET_INC_STATS(net, LINUX_MIB_OUTOFWINDOWICMPS);
7c657876
ACM
285 goto out;
286 }
287
288 switch (type) {
55be7a9c 289 case ICMP_REDIRECT:
45caeaa5
JM
290 if (!sock_owned_by_user(sk))
291 dccp_do_redirect(skb, sk);
55be7a9c 292 goto out;
7c657876
ACM
293 case ICMP_SOURCE_QUENCH:
294 /* Just silently ignore these. */
295 goto out;
296 case ICMP_PARAMETERPROB:
297 err = EPROTO;
298 break;
299 case ICMP_DEST_UNREACH:
300 if (code > NR_ICMP_UNREACH)
301 goto out;
302
303 if (code == ICMP_FRAG_NEEDED) { /* PMTU discovery (RFC1191) */
304 if (!sock_owned_by_user(sk))
305 dccp_do_pmtu_discovery(sk, iph, info);
306 goto out;
307 }
308
309 err = icmp_err_convert[code].errno;
310 break;
311 case ICMP_TIME_EXCEEDED:
312 err = EHOSTUNREACH;
313 break;
314 default:
315 goto out;
316 }
317
318 switch (sk->sk_state) {
7c657876
ACM
319 case DCCP_REQUESTING:
320 case DCCP_RESPOND:
321 if (!sock_owned_by_user(sk)) {
aa62d76b 322 __DCCP_INC_STATS(DCCP_MIB_ATTEMPTFAILS);
7c657876
ACM
323 sk->sk_err = err;
324
325 sk->sk_error_report(sk);
326
327 dccp_done(sk);
328 } else
329 sk->sk_err_soft = err;
330 goto out;
331 }
332
333 /* If we've already connected we will keep trying
334 * until we time out, or the user gives up.
335 *
336 * rfc1122 4.2.3.9 allows to consider as hard errors
337 * only PROTO_UNREACH and PORT_UNREACH (well, FRAG_FAILED too,
338 * but it is obsoleted by pmtu discovery).
339 *
340 * Note, that in modern internet, where routing is unreliable
341 * and in each dark corner broken firewalls sit, sending random
342 * errors ordered by their masters even this two messages finally lose
343 * their original sense (even Linux sends invalid PORT_UNREACHs)
344 *
345 * Now we are in compliance with RFCs.
346 * --ANK (980905)
347 */
348
349 inet = inet_sk(sk);
350 if (!sock_owned_by_user(sk) && inet->recverr) {
351 sk->sk_err = err;
352 sk->sk_error_report(sk);
353 } else /* Only an error on timeout */
354 sk->sk_err_soft = err;
355out:
356 bh_unlock_sock(sk);
357 sock_put(sk);
32bbd879 358 return 0;
7c657876
ACM
359}
360
2bda2853 361static inline __sum16 dccp_v4_csum_finish(struct sk_buff *skb,
6f4e5fff
GR
362 __be32 src, __be32 dst)
363{
364 return csum_tcpudp_magic(src, dst, skb->len, IPPROTO_DCCP, skb->csum);
365}
366
bb296246 367void dccp_v4_send_check(struct sock *sk, struct sk_buff *skb)
57cca05a
ACM
368{
369 const struct inet_sock *inet = inet_sk(sk);
370 struct dccp_hdr *dh = dccp_hdr(skb);
371
6f4e5fff 372 dccp_csum_outgoing(skb);
c720c7e8
ED
373 dh->dccph_checksum = dccp_v4_csum_finish(skb,
374 inet->inet_saddr,
375 inet->inet_daddr);
57cca05a 376}
f21e68ca
ACM
377EXPORT_SYMBOL_GPL(dccp_v4_send_check);
378
865e9022 379static inline u64 dccp_v4_init_sequence(const struct sk_buff *skb)
7c657876 380{
eddc9ec5
ACM
381 return secure_dccp_sequence_number(ip_hdr(skb)->daddr,
382 ip_hdr(skb)->saddr,
7c657876
ACM
383 dccp_hdr(skb)->dccph_dport,
384 dccp_hdr(skb)->dccph_sport);
385}
386
7c657876
ACM
387/*
388 * The three way handshake has completed - we got a valid ACK or DATAACK -
389 * now create the new socket.
390 *
391 * This is the equivalent of TCP's tcp_v4_syn_recv_sock
392 */
0c27171e
ED
393struct sock *dccp_v4_request_recv_sock(const struct sock *sk,
394 struct sk_buff *skb,
7c657876 395 struct request_sock *req,
5e0724d0
ED
396 struct dst_entry *dst,
397 struct request_sock *req_unhash,
398 bool *own_req)
7c657876
ACM
399{
400 struct inet_request_sock *ireq;
401 struct inet_sock *newinet;
7c657876
ACM
402 struct sock *newsk;
403
404 if (sk_acceptq_is_full(sk))
405 goto exit_overflow;
406
7c657876
ACM
407 newsk = dccp_create_openreq_child(sk, req, skb);
408 if (newsk == NULL)
093d2823 409 goto exit_nonewsk;
7c657876 410
7c657876
ACM
411 newinet = inet_sk(newsk);
412 ireq = inet_rsk(req);
d1e559d0
ED
413 sk_daddr_set(newsk, ireq->ir_rmt_addr);
414 sk_rcv_saddr_set(newsk, ireq->ir_loc_addr);
634fb979 415 newinet->inet_saddr = ireq->ir_loc_addr;
c92e8c02 416 RCU_INIT_POINTER(newinet->inet_opt, rcu_dereference(ireq->ireq_opt));
7c657876 417 newinet->mc_index = inet_iif(skb);
eddc9ec5 418 newinet->mc_ttl = ip_hdr(skb)->ttl;
3d1e5039 419 newinet->inet_id = prandom_u32();
7c657876 420
0e734419
DM
421 if (dst == NULL && (dst = inet_csk_route_child_sock(sk, newsk, req)) == NULL)
422 goto put_and_exit;
423
424 sk_setup_caps(newsk, dst);
425
7c657876
ACM
426 dccp_sync_mss(newsk, dst_mtu(dst));
427
0e734419
DM
428 if (__inet_inherit_port(sk, newsk) < 0)
429 goto put_and_exit;
01770a16 430 *own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash), NULL);
c92e8c02
ED
431 if (*own_req)
432 ireq->ireq_opt = NULL;
433 else
434 newinet->inet_opt = NULL;
7c657876
ACM
435 return newsk;
436
437exit_overflow:
02a1d6e7 438 __NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS);
093d2823
BS
439exit_nonewsk:
440 dst_release(dst);
7c657876 441exit:
02a1d6e7 442 __NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS);
7c657876 443 return NULL;
0e734419 444put_and_exit:
c92e8c02 445 newinet->inet_opt = NULL;
e337e24d
CP
446 inet_csk_prepare_forced_close(newsk);
447 dccp_done(newsk);
0e734419 448 goto exit;
7c657876 449}
f21e68ca
ACM
450EXPORT_SYMBOL_GPL(dccp_v4_request_recv_sock);
451
f5487398 452static struct dst_entry* dccp_v4_route_skb(struct net *net, struct sock *sk,
7c657876
ACM
453 struct sk_buff *skb)
454{
455 struct rtable *rt;
898f7358 456 const struct iphdr *iph = ip_hdr(skb);
9d6ec938 457 struct flowi4 fl4 = {
92101b3b 458 .flowi4_oif = inet_iif(skb),
898f7358
DM
459 .daddr = iph->saddr,
460 .saddr = iph->daddr,
9d6ec938
DM
461 .flowi4_tos = RT_CONN_FLAGS(sk),
462 .flowi4_proto = sk->sk_protocol,
9cce96df
DM
463 .fl4_sport = dccp_hdr(skb)->dccph_dport,
464 .fl4_dport = dccp_hdr(skb)->dccph_sport,
1d28f42c 465 };
7c657876 466
3df98d79 467 security_skb_classify_flow(skb, flowi4_to_flowi_common(&fl4));
9d6ec938 468 rt = ip_route_output_flow(net, &fl4, sk);
b23dd4fe 469 if (IS_ERR(rt)) {
95556a88 470 IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
7c657876
ACM
471 return NULL;
472 }
473
d8d1f30b 474 return &rt->dst;
7c657876
ACM
475}
476
ea3bea3a 477static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req)
3d2fe62b
GR
478{
479 int err = -1;
480 struct sk_buff *skb;
fd80eb94 481 struct dst_entry *dst;
6bd023f3 482 struct flowi4 fl4;
3d2fe62b 483
ba3f7f04 484 dst = inet_csk_route_req(sk, &fl4, req);
fd80eb94 485 if (dst == NULL)
3d2fe62b
GR
486 goto out;
487
488 skb = dccp_make_response(sk, dst, req);
489 if (skb != NULL) {
490 const struct inet_request_sock *ireq = inet_rsk(req);
491 struct dccp_hdr *dh = dccp_hdr(skb);
492
634fb979
ED
493 dh->dccph_checksum = dccp_v4_csum_finish(skb, ireq->ir_loc_addr,
494 ireq->ir_rmt_addr);
2ab2ddd3 495 rcu_read_lock();
634fb979
ED
496 err = ip_build_and_send_pkt(skb, sk, ireq->ir_loc_addr,
497 ireq->ir_rmt_addr,
de033b7d
WW
498 rcu_dereference(ireq->ireq_opt),
499 inet_sk(sk)->tos);
2ab2ddd3 500 rcu_read_unlock();
b9df3cb8 501 err = net_xmit_eval(err);
3d2fe62b
GR
502 }
503
504out:
505 dst_release(dst);
506 return err;
507}
508
a00e7444 509static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
7c657876
ACM
510{
511 int err;
eddc9ec5 512 const struct iphdr *rxiph;
7c657876
ACM
513 struct sk_buff *skb;
514 struct dst_entry *dst;
adf30907 515 struct net *net = dev_net(skb_dst(rxskb)->dev);
b76c4b27 516 struct sock *ctl_sk = net->dccp.v4_ctl_sk;
7c657876
ACM
517
518 /* Never send a reset in response to a reset. */
e356d37a 519 if (dccp_hdr(rxskb)->dccph_type == DCCP_PKT_RESET)
7c657876
ACM
520 return;
521
511c3f92 522 if (skb_rtable(rxskb)->rt_type != RTN_LOCAL)
7c657876
ACM
523 return;
524
f5487398 525 dst = dccp_v4_route_skb(net, ctl_sk, rxskb);
7c657876
ACM
526 if (dst == NULL)
527 return;
528
7b1cffa8 529 skb = dccp_ctl_make_reset(ctl_sk, rxskb);
7c657876
ACM
530 if (skb == NULL)
531 goto out;
532
eddc9ec5 533 rxiph = ip_hdr(rxskb);
e356d37a
GR
534 dccp_hdr(skb)->dccph_checksum = dccp_v4_csum_finish(skb, rxiph->saddr,
535 rxiph->daddr);
adf30907 536 skb_dst_set(skb, dst_clone(dst));
7c657876 537
95556a88 538 local_bh_disable();
7b1cffa8
PE
539 bh_lock_sock(ctl_sk);
540 err = ip_build_and_send_pkt(skb, ctl_sk,
de033b7d
WW
541 rxiph->daddr, rxiph->saddr, NULL,
542 inet_sk(ctl_sk)->tos);
7b1cffa8 543 bh_unlock_sock(ctl_sk);
7c657876 544
b9df3cb8 545 if (net_xmit_eval(err) == 0) {
95556a88
ED
546 __DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
547 __DCCP_INC_STATS(DCCP_MIB_OUTRSTS);
7c657876 548 }
95556a88 549 local_bh_enable();
7c657876 550out:
95556a88 551 dst_release(dst);
7c657876
ACM
552}
553
3d2fe62b
GR
554static void dccp_v4_reqsk_destructor(struct request_sock *req)
555{
d99a7bd2 556 dccp_feat_list_purge(&dccp_rsk(req)->dreq_featneg);
c92e8c02 557 kfree(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1));
3d2fe62b
GR
558}
559
42cb80a2 560void dccp_syn_ack_timeout(const struct request_sock *req)
c72e1183
ED
561{
562}
563EXPORT_SYMBOL(dccp_syn_ack_timeout);
564
3d2fe62b
GR
565static struct request_sock_ops dccp_request_sock_ops __read_mostly = {
566 .family = PF_INET,
567 .obj_size = sizeof(struct dccp_request_sock),
568 .rtx_syn_ack = dccp_v4_send_response,
569 .send_ack = dccp_reqsk_send_ack,
570 .destructor = dccp_v4_reqsk_destructor,
571 .send_reset = dccp_v4_ctl_send_reset,
c72e1183 572 .syn_ack_timeout = dccp_syn_ack_timeout,
3d2fe62b
GR
573};
574
575int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
576{
577 struct inet_request_sock *ireq;
3d2fe62b
GR
578 struct request_sock *req;
579 struct dccp_request_sock *dreq;
8109b02b 580 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
3d2fe62b 581 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
3d2fe62b
GR
582
583 /* Never answer to DCCP_PKT_REQUESTs send to broadcast or multicast */
511c3f92 584 if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
4a5409a5 585 return 0; /* discard, don't send a reset here */
3d2fe62b
GR
586
587 if (dccp_bad_service_code(sk, service)) {
4a5409a5 588 dcb->dccpd_reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE;
3d2fe62b 589 goto drop;
8109b02b 590 }
3d2fe62b
GR
591 /*
592 * TW buckets are converted to open requests without
593 * limitations, they conserve resources and peer is
594 * evidently real one.
595 */
4a5409a5 596 dcb->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY;
3d2fe62b
GR
597 if (inet_csk_reqsk_queue_is_full(sk))
598 goto drop;
599
5ea8ea2c 600 if (sk_acceptq_is_full(sk))
3d2fe62b
GR
601 goto drop;
602
a1a5344d 603 req = inet_reqsk_alloc(&dccp_request_sock_ops, sk, true);
3d2fe62b
GR
604 if (req == NULL)
605 goto drop;
606
ac75773c
GR
607 if (dccp_reqsk_init(req, dccp_sk(sk), skb))
608 goto drop_and_free;
3d2fe62b 609
8b819412
GR
610 dreq = dccp_rsk(req);
611 if (dccp_parse_options(sk, dreq, skb))
612 goto drop_and_free;
613
3d2fe62b
GR
614 if (security_inet_conn_request(sk, skb, req))
615 goto drop_and_free;
616
617 ireq = inet_rsk(req);
08d2cc3b
ED
618 sk_rcv_saddr_set(req_to_sk(req), ip_hdr(skb)->daddr);
619 sk_daddr_set(req_to_sk(req), ip_hdr(skb)->saddr);
b855ff82 620 ireq->ir_mark = inet_request_mark(sk, skb);
3f66b083 621 ireq->ireq_family = AF_INET;
16f86165 622 ireq->ir_iif = sk->sk_bound_dev_if;
3d2fe62b 623
8109b02b 624 /*
3d2fe62b
GR
625 * Step 3: Process LISTEN state
626 *
627 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
628 *
f541fb7e 629 * Setting S.SWL/S.SWH to is deferred to dccp_create_openreq_child().
3d2fe62b 630 */
3d2fe62b 631 dreq->dreq_isr = dcb->dccpd_seq;
f541fb7e 632 dreq->dreq_gsr = dreq->dreq_isr;
865e9022 633 dreq->dreq_iss = dccp_v4_init_sequence(skb);
f541fb7e 634 dreq->dreq_gss = dreq->dreq_iss;
3d2fe62b
GR
635 dreq->dreq_service = service;
636
1a2c6181 637 if (dccp_v4_send_response(sk, req))
3d2fe62b
GR
638 goto drop_and_free;
639
640 inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
b7953d3c 641 reqsk_put(req);
3d2fe62b
GR
642 return 0;
643
644drop_and_free:
645 reqsk_free(req);
646drop:
aa62d76b 647 __DCCP_INC_STATS(DCCP_MIB_ATTEMPTFAILS);
3d2fe62b
GR
648 return -1;
649}
3d2fe62b
GR
650EXPORT_SYMBOL_GPL(dccp_v4_conn_request);
651
7c657876
ACM
652int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
653{
654 struct dccp_hdr *dh = dccp_hdr(skb);
655
656 if (sk->sk_state == DCCP_OPEN) { /* Fast path */
657 if (dccp_rcv_established(sk, skb, dh, skb->len))
658 goto reset;
659 return 0;
660 }
661
662 /*
663 * Step 3: Process LISTEN state
d83ca5ac
GR
664 * If P.type == Request or P contains a valid Init Cookie option,
665 * (* Must scan the packet's options to check for Init
666 * Cookies. Only Init Cookies are processed here,
667 * however; other options are processed in Step 8. This
668 * scan need only be performed if the endpoint uses Init
669 * Cookies *)
670 * (* Generate a new socket and switch to that socket *)
671 * Set S := new socket for this port pair
672 * S.state = RESPOND
673 * Choose S.ISS (initial seqno) or set from Init Cookies
674 * Initialize S.GAR := S.ISS
675 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookies
676 * Continue with S.state == RESPOND
677 * (* A Response packet will be generated in Step 11 *)
678 * Otherwise,
679 * Generate Reset(No Connection) unless P.type == Reset
680 * Drop packet and return
7c657876 681 *
7690af3f
ACM
682 * NOTE: the check for the packet types is done in
683 * dccp_rcv_state_process
7c657876 684 */
7c657876
ACM
685
686 if (dccp_rcv_state_process(sk, skb, dh, skb->len))
687 goto reset;
688 return 0;
689
690reset:
cfb6eeb4 691 dccp_v4_ctl_send_reset(sk, skb);
7c657876
ACM
692 kfree_skb(skb);
693 return 0;
694}
f21e68ca
ACM
695EXPORT_SYMBOL_GPL(dccp_v4_do_rcv);
696
09dbc389
GR
697/**
698 * dccp_invalid_packet - check for malformed packets
d0b1101b
AL
699 * @skb: Packet to validate
700 *
09dbc389
GR
701 * Implements RFC 4340, 8.5: Step 1: Check header basics
702 * Packets that fail these checks are ignored and do not receive Resets.
703 */
f21e68ca 704int dccp_invalid_packet(struct sk_buff *skb)
7c657876
ACM
705{
706 const struct dccp_hdr *dh;
6f4e5fff 707 unsigned int cscov;
648f0c28 708 u8 dccph_doff;
7c657876
ACM
709
710 if (skb->pkt_type != PACKET_HOST)
711 return 1;
712
09dbc389 713 /* If the packet is shorter than 12 bytes, drop packet and return */
7c657876 714 if (!pskb_may_pull(skb, sizeof(struct dccp_hdr))) {
59348b19 715 DCCP_WARN("pskb_may_pull failed\n");
7c657876
ACM
716 return 1;
717 }
718
719 dh = dccp_hdr(skb);
720
09dbc389 721 /* If P.type is not understood, drop packet and return */
7c657876 722 if (dh->dccph_type >= DCCP_PKT_INVALID) {
59348b19 723 DCCP_WARN("invalid packet type\n");
7c657876
ACM
724 return 1;
725 }
726
727 /*
09dbc389 728 * If P.Data Offset is too small for packet type, drop packet and return
7c657876 729 */
648f0c28
ED
730 dccph_doff = dh->dccph_doff;
731 if (dccph_doff < dccp_hdr_len(skb) / sizeof(u32)) {
732 DCCP_WARN("P.Data Offset(%u) too small\n", dccph_doff);
7c657876
ACM
733 return 1;
734 }
09dbc389 735 /*
54633527 736 * If P.Data Offset is too large for packet, drop packet and return
09dbc389 737 */
648f0c28
ED
738 if (!pskb_may_pull(skb, dccph_doff * sizeof(u32))) {
739 DCCP_WARN("P.Data Offset(%u) too large\n", dccph_doff);
7c657876
ACM
740 return 1;
741 }
648f0c28 742 dh = dccp_hdr(skb);
7c657876
ACM
743 /*
744 * If P.type is not Data, Ack, or DataAck and P.X == 0 (the packet
745 * has short sequence numbers), drop packet and return
746 */
6079a463
WY
747 if ((dh->dccph_type < DCCP_PKT_DATA ||
748 dh->dccph_type > DCCP_PKT_DATAACK) && dh->dccph_x == 0) {
59348b19
GR
749 DCCP_WARN("P.type (%s) not Data || [Data]Ack, while P.X == 0\n",
750 dccp_packet_name(dh->dccph_type));
7c657876
ACM
751 return 1;
752 }
753
6f4e5fff
GR
754 /*
755 * If P.CsCov is too large for the packet size, drop packet and return.
756 * This must come _before_ checksumming (not as RFC 4340 suggests).
757 */
758 cscov = dccp_csum_coverage(skb);
759 if (cscov > skb->len) {
59348b19
GR
760 DCCP_WARN("P.CsCov %u exceeds packet length %d\n",
761 dh->dccph_cscov, skb->len);
6f4e5fff
GR
762 return 1;
763 }
764
765 /* If header checksum is incorrect, drop packet and return.
766 * (This step is completed in the AF-dependent functions.) */
767 skb->csum = skb_checksum(skb, 0, cscov, 0);
768
7c657876
ACM
769 return 0;
770}
f21e68ca
ACM
771EXPORT_SYMBOL_GPL(dccp_invalid_packet);
772
7c657876 773/* this is called when real data arrives */
b61fafc4 774static int dccp_v4_rcv(struct sk_buff *skb)
7c657876
ACM
775{
776 const struct dccp_hdr *dh;
eddc9ec5 777 const struct iphdr *iph;
3b24d854 778 bool refcounted;
7c657876 779 struct sock *sk;
6f4e5fff 780 int min_cov;
7c657876 781
6f4e5fff 782 /* Step 1: Check header basics */
7c657876
ACM
783
784 if (dccp_invalid_packet(skb))
785 goto discard_it;
786
eddc9ec5 787 iph = ip_hdr(skb);
6f4e5fff 788 /* Step 1: If header checksum is incorrect, drop packet and return */
eddc9ec5 789 if (dccp_v4_csum_finish(skb, iph->saddr, iph->daddr)) {
59348b19 790 DCCP_WARN("dropped packet with invalid checksum\n");
f21e68ca
ACM
791 goto discard_it;
792 }
793
7c657876 794 dh = dccp_hdr(skb);
7c657876 795
fde20105 796 DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh);
7c657876
ACM
797 DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
798
21454aaa 799 dccp_pr_debug("%8.8s src=%pI4@%-5d dst=%pI4@%-5d seq=%llu",
7c657876 800 dccp_packet_name(dh->dccph_type),
21454aaa
HH
801 &iph->saddr, ntohs(dh->dccph_sport),
802 &iph->daddr, ntohs(dh->dccph_dport),
f6ccf554 803 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq);
7c657876
ACM
804
805 if (dccp_packet_without_ack(skb)) {
806 DCCP_SKB_CB(skb)->dccpd_ack_seq = DCCP_PKT_WITHOUT_ACK_SEQ;
807 dccp_pr_debug_cat("\n");
808 } else {
809 DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb);
d23c7107 810 dccp_pr_debug_cat(", ack=%llu\n", (unsigned long long)
f6ccf554 811 DCCP_SKB_CB(skb)->dccpd_ack_seq);
7c657876
ACM
812 }
813
4bdc3d66 814lookup:
a583636a 815 sk = __inet_lookup_skb(&dccp_hashinfo, skb, __dccp_hdr_len(dh),
3fa6f616 816 dh->dccph_sport, dh->dccph_dport, 0, &refcounted);
4bdc3d66 817 if (!sk) {
7c657876
ACM
818 dccp_pr_debug("failed to look up flow ID in table and "
819 "get corresponding socket\n");
820 goto no_dccp_socket;
821 }
822
8109b02b 823 /*
7c657876 824 * Step 2:
8109b02b 825 * ... or S.state == TIMEWAIT,
7c657876
ACM
826 * Generate Reset(No Connection) unless P.type == Reset
827 * Drop packet and return
828 */
7c657876 829 if (sk->sk_state == DCCP_TIME_WAIT) {
d23c7107
GR
830 dccp_pr_debug("sk->sk_state == DCCP_TIME_WAIT: do_time_wait\n");
831 inet_twsk_put(inet_twsk(sk));
832 goto no_dccp_socket;
7c657876
ACM
833 }
834
079096f1
ED
835 if (sk->sk_state == DCCP_NEW_SYN_RECV) {
836 struct request_sock *req = inet_reqsk(sk);
7716682c 837 struct sock *nsk;
079096f1
ED
838
839 sk = req->rsk_listener;
7716682c 840 if (unlikely(sk->sk_state != DCCP_LISTEN)) {
f03f2e15 841 inet_csk_reqsk_queue_drop_and_put(sk, req);
4bdc3d66
ED
842 goto lookup;
843 }
7716682c 844 sock_hold(sk);
3b24d854 845 refcounted = true;
7716682c 846 nsk = dccp_check_req(sk, skb, req);
079096f1
ED
847 if (!nsk) {
848 reqsk_put(req);
7716682c 849 goto discard_and_relse;
079096f1
ED
850 }
851 if (nsk == sk) {
079096f1
ED
852 reqsk_put(req);
853 } else if (dccp_child_process(sk, nsk, skb)) {
854 dccp_v4_ctl_send_reset(sk, skb);
7716682c 855 goto discard_and_relse;
079096f1 856 } else {
7716682c 857 sock_put(sk);
079096f1
ED
858 return 0;
859 }
860 }
6f4e5fff
GR
861 /*
862 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage
8109b02b
ACM
863 * o if MinCsCov = 0, only packets with CsCov = 0 are accepted
864 * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov
6f4e5fff
GR
865 */
866 min_cov = dccp_sk(sk)->dccps_pcrlen;
867 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) {
868 dccp_pr_debug("Packet CsCov %d does not satisfy MinCsCov %d\n",
869 dh->dccph_cscov, min_cov);
870 /* FIXME: "Such packets SHOULD be reported using Data Dropped
871 * options (Section 11.7) with Drop Code 0, Protocol
872 * Constraints." */
873 goto discard_and_relse;
874 }
875
25995ff5 876 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
7c657876 877 goto discard_and_relse;
895b5c9f 878 nf_reset_ct(skb);
7c657876 879
c3f24cfb 880 return __sk_receive_skb(sk, skb, 1, dh->dccph_doff * 4, refcounted);
7c657876
ACM
881
882no_dccp_socket:
883 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
884 goto discard_it;
885 /*
886 * Step 2:
8109b02b 887 * If no socket ...
7c657876
ACM
888 * Generate Reset(No Connection) unless P.type == Reset
889 * Drop packet and return
890 */
891 if (dh->dccph_type != DCCP_PKT_RESET) {
7690af3f
ACM
892 DCCP_SKB_CB(skb)->dccpd_reset_code =
893 DCCP_RESET_CODE_NO_CONNECTION;
cfb6eeb4 894 dccp_v4_ctl_send_reset(sk, skb);
7c657876
ACM
895 }
896
897discard_it:
7c657876
ACM
898 kfree_skb(skb);
899 return 0;
900
901discard_and_relse:
3b24d854
ED
902 if (refcounted)
903 sock_put(sk);
7c657876
ACM
904 goto discard_it;
905}
906
3b401a81 907static const struct inet_connection_sock_af_ops dccp_ipv4_af_ops = {
543d9cfe
ACM
908 .queue_xmit = ip_queue_xmit,
909 .send_check = dccp_v4_send_check,
910 .rebuild_header = inet_sk_rebuild_header,
911 .conn_request = dccp_v4_conn_request,
912 .syn_recv_sock = dccp_v4_request_recv_sock,
913 .net_header_len = sizeof(struct iphdr),
914 .setsockopt = ip_setsockopt,
915 .getsockopt = ip_getsockopt,
916 .addr2sockaddr = inet_csk_addr2sockaddr,
917 .sockaddr_len = sizeof(struct sockaddr_in),
57cca05a
ACM
918};
919
3e0fadc5 920static int dccp_v4_init_sock(struct sock *sk)
7c657876 921{
72478873
ACM
922 static __u8 dccp_v4_ctl_sock_initialized;
923 int err = dccp_init_sock(sk, dccp_v4_ctl_sock_initialized);
f21e68ca 924
72478873
ACM
925 if (err == 0) {
926 if (unlikely(!dccp_v4_ctl_sock_initialized))
927 dccp_v4_ctl_sock_initialized = 1;
3e0fadc5 928 inet_csk(sk)->icsk_af_ops = &dccp_ipv4_af_ops;
72478873
ACM
929 }
930
3e0fadc5 931 return err;
7c657876
ACM
932}
933
6d6ee43e
ACM
934static struct timewait_sock_ops dccp_timewait_sock_ops = {
935 .twsk_obj_size = sizeof(struct inet_timewait_sock),
936};
937
5e0817f8 938static struct proto dccp_v4_prot = {
7c657876
ACM
939 .name = "DCCP",
940 .owner = THIS_MODULE,
941 .close = dccp_close,
942 .connect = dccp_v4_connect,
943 .disconnect = dccp_disconnect,
944 .ioctl = dccp_ioctl,
945 .init = dccp_v4_init_sock,
946 .setsockopt = dccp_setsockopt,
947 .getsockopt = dccp_getsockopt,
948 .sendmsg = dccp_sendmsg,
949 .recvmsg = dccp_recvmsg,
950 .backlog_rcv = dccp_v4_do_rcv,
ab1e0a13
ACM
951 .hash = inet_hash,
952 .unhash = inet_unhash,
7c657876 953 .accept = inet_csk_accept,
ab1e0a13 954 .get_port = inet_csk_get_port,
7c657876 955 .shutdown = dccp_shutdown,
3e0fadc5 956 .destroy = dccp_destroy_sock,
7c657876
ACM
957 .orphan_count = &dccp_orphan_count,
958 .max_header = MAX_DCCP_HEADER,
959 .obj_size = sizeof(struct dccp_sock),
5f0d5a3a 960 .slab_flags = SLAB_TYPESAFE_BY_RCU,
7c657876 961 .rsk_prot = &dccp_request_sock_ops,
6d6ee43e 962 .twsk_prot = &dccp_timewait_sock_ops,
39d8cda7 963 .h.hashinfo = &dccp_hashinfo,
7c657876 964};
6d6ee43e 965
32613090 966static const struct net_protocol dccp_v4_protocol = {
b61fafc4
ACM
967 .handler = dccp_v4_rcv,
968 .err_handler = dccp_v4_err,
969 .no_policy = 1,
fc5f8580 970 .netns_ok = 1,
8ed1dc44 971 .icmp_strict_tag_validation = 1,
b61fafc4
ACM
972};
973
974static const struct proto_ops inet_dccp_ops = {
543d9cfe
ACM
975 .family = PF_INET,
976 .owner = THIS_MODULE,
977 .release = inet_release,
978 .bind = inet_bind,
979 .connect = inet_stream_connect,
980 .socketpair = sock_no_socketpair,
981 .accept = inet_accept,
982 .getname = inet_getname,
b61fafc4 983 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */
a11e1d43 984 .poll = dccp_poll,
543d9cfe 985 .ioctl = inet_ioctl,
c7cbdbf2 986 .gettstamp = sock_gettstamp,
b61fafc4 987 /* FIXME: work on inet_listen to rename it to sock_common_listen */
543d9cfe
ACM
988 .listen = inet_dccp_listen,
989 .shutdown = inet_shutdown,
990 .setsockopt = sock_common_setsockopt,
991 .getsockopt = sock_common_getsockopt,
992 .sendmsg = inet_sendmsg,
993 .recvmsg = sock_common_recvmsg,
994 .mmap = sock_no_mmap,
995 .sendpage = sock_no_sendpage,
b61fafc4
ACM
996};
997
998static struct inet_protosw dccp_v4_protosw = {
999 .type = SOCK_DCCP,
1000 .protocol = IPPROTO_DCCP,
1001 .prot = &dccp_v4_prot,
1002 .ops = &inet_dccp_ops,
b61fafc4
ACM
1003 .flags = INET_PROTOSW_ICSK,
1004};
1005
2c8c1e72 1006static int __net_init dccp_v4_init_net(struct net *net)
72a2d613 1007{
d14a0ebd
GR
1008 if (dccp_hashinfo.bhash == NULL)
1009 return -ESOCKTNOSUPPORT;
b76c4b27 1010
d14a0ebd
GR
1011 return inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET,
1012 SOCK_DCCP, IPPROTO_DCCP, net);
72a2d613
PE
1013}
1014
2c8c1e72 1015static void __net_exit dccp_v4_exit_net(struct net *net)
72a2d613 1016{
b76c4b27 1017 inet_ctl_sock_destroy(net->dccp.v4_ctl_sk);
72a2d613
PE
1018}
1019
ec7cb62d
AR
1020static void __net_exit dccp_v4_exit_batch(struct list_head *net_exit_list)
1021{
1022 inet_twsk_purge(&dccp_hashinfo, AF_INET);
1023}
1024
72a2d613
PE
1025static struct pernet_operations dccp_v4_ops = {
1026 .init = dccp_v4_init_net,
1027 .exit = dccp_v4_exit_net,
ec7cb62d 1028 .exit_batch = dccp_v4_exit_batch,
72a2d613
PE
1029};
1030
b61fafc4
ACM
1031static int __init dccp_v4_init(void)
1032{
1033 int err = proto_register(&dccp_v4_prot, 1);
1034
d5494acb 1035 if (err)
b61fafc4
ACM
1036 goto out;
1037
b61fafc4
ACM
1038 inet_register_protosw(&dccp_v4_protosw);
1039
72a2d613
PE
1040 err = register_pernet_subsys(&dccp_v4_ops);
1041 if (err)
1042 goto out_destroy_ctl_sock;
d5494acb
XL
1043
1044 err = inet_add_protocol(&dccp_v4_protocol, IPPROTO_DCCP);
1045 if (err)
1046 goto out_proto_unregister;
1047
b61fafc4
ACM
1048out:
1049 return err;
d5494acb
XL
1050out_proto_unregister:
1051 unregister_pernet_subsys(&dccp_v4_ops);
72a2d613 1052out_destroy_ctl_sock:
b61fafc4 1053 inet_unregister_protosw(&dccp_v4_protosw);
b61fafc4
ACM
1054 proto_unregister(&dccp_v4_prot);
1055 goto out;
1056}
1057
1058static void __exit dccp_v4_exit(void)
1059{
d5494acb 1060 inet_del_protocol(&dccp_v4_protocol, IPPROTO_DCCP);
72a2d613 1061 unregister_pernet_subsys(&dccp_v4_ops);
b61fafc4 1062 inet_unregister_protosw(&dccp_v4_protosw);
b61fafc4
ACM
1063 proto_unregister(&dccp_v4_prot);
1064}
1065
1066module_init(dccp_v4_init);
1067module_exit(dccp_v4_exit);
1068
1069/*
1070 * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
1071 * values directly, Also cover the case where the protocol is not specified,
1072 * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP
1073 */
7131c6c7
JD
1074MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, 33, 6);
1075MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, 0, 6);
b61fafc4
ACM
1076MODULE_LICENSE("GPL");
1077MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
1078MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol");