13 #include <linux/dccp.h>
14 #include <linux/icmp.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
18 #include <linux/random.h>
47 __be16 orig_sport, orig_dport;
62 nexthop = daddr = usin->
sin_addr.s_addr;
66 if (inet_opt !=
NULL && inet_opt->
opt.srr) {
69 nexthop = inet_opt->
opt.faddr;
74 fl4 = &inet->
cork.fl.u.ip4;
75 rt = ip_route_connect(fl4, nexthop, inet->
inet_saddr,
78 orig_sport, orig_dport, sk,
true);
87 if (inet_opt ==
NULL || !inet_opt->
opt.srr)
95 inet->inet_daddr =
daddr;
97 inet_csk(sk)->icsk_ext_hdr_len = 0;
99 inet_csk(sk)->icsk_ext_hdr_len = inet_opt->
opt.optlen;
111 rt = ip_route_newports(fl4, rt, orig_sport, orig_dport,
149 static inline void dccp_do_pmtu_discovery(
struct sock *
sk,
150 const struct iphdr *iph,
154 const struct inet_sock *inet = inet_sk(sk);
171 if (mtu < dst_mtu(dst) && ip_dont_fragment(sk, dst))
177 inet_csk(sk)->icsk_pmtu_cookie > mtu) {
191 static void dccp_do_redirect(
struct sk_buff *
skb,
struct sock *sk)
196 dst->
ops->redirect(dst, sk, skb);
218 const int type = icmp_hdr(skb)->type;
219 const int code = icmp_hdr(skb)->code;
226 skb->
len <
offset + __dccp_basic_hdr_len(dh)) {
231 sk = inet_lookup(net, &dccp_hashinfo,
232 iph->
daddr, dh->dccph_dport,
233 iph->
saddr, dh->dccph_sport, inet_iif(skb));
255 seq = dccp_hdr_seq(dh);
264 dccp_do_redirect(skb, sk);
278 dccp_do_pmtu_discovery(sk, iph, info);
291 switch (sk->sk_state) {
307 if (!between48(seq, dccp_rsk(req)->dreq_iss,
308 dccp_rsk(req)->dreq_gss)) {
318 inet_csk_reqsk_queue_drop(sk, req, prev);
370 const struct inet_sock *inet = inet_sk(sk);
373 dccp_csum_outgoing(skb);
381 static inline u64 dccp_v4_init_sequence(
const struct sk_buff *skb)
403 if (sk_acceptq_is_full(sk))
410 newinet = inet_sk(newsk);
411 ireq = inet_rsk(req);
412 newinet->inet_daddr = ireq->
rmt_addr;
413 newinet->inet_rcv_saddr = ireq->
loc_addr;
418 newinet->
mc_ttl = ip_hdr(skb)->ttl;
449 static struct sock *dccp_v4_hnd_req(
struct sock *sk,
struct sk_buff *skb)
452 const struct iphdr *iph = ip_hdr(skb);
462 nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo,
478 static struct dst_entry* dccp_v4_route_skb(
struct net *net,
struct sock *sk,
482 const struct iphdr *iph = ip_hdr(skb);
484 .flowi4_oif = inet_iif(skb),
493 security_skb_classify_flow(skb, flowi4_to_flowi(&fl4));
533 static void dccp_v4_ctl_send_reset(
struct sock *sk,
struct sk_buff *rxskb)
536 const struct iphdr *rxiph;
539 struct net *net = dev_net(skb_dst(rxskb)->
dev);
540 struct sock *ctl_sk = net->dccp.v4_ctl_sk;
546 if (skb_rtable(rxskb)->rt_type !=
RTN_LOCAL)
549 dst = dccp_v4_route_skb(net, ctl_sk, rxskb);
557 rxiph = ip_hdr(rxskb);
560 skb_dst_set(skb, dst_clone(dst));
575 static void dccp_v4_reqsk_destructor(
struct request_sock *req)
589 .rtx_syn_ack = dccp_v4_send_response,
591 .destructor = dccp_v4_reqsk_destructor,
592 .send_reset = dccp_v4_ctl_send_reset,
608 if (dccp_bad_service_code(sk, service)) {
618 if (inet_csk_reqsk_queue_is_full(sk))
627 if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
630 req = inet_reqsk_alloc(&dccp_request_sock_ops);
637 dreq = dccp_rsk(req);
641 if (security_inet_conn_request(sk, skb, req))
644 ireq = inet_rsk(req);
645 ireq->
loc_addr = ip_hdr(skb)->daddr;
646 ireq->
rmt_addr = ip_hdr(skb)->saddr;
657 dreq->
dreq_iss = dccp_v4_init_sequence(skb);
661 if (dccp_v4_send_response(sk, req,
NULL))
710 struct sock *nsk = dccp_v4_hnd_req(sk, skb);
727 dccp_v4_ctl_send_reset(sk, skb);
749 if (!pskb_may_pull(skb,
sizeof(
struct dccp_hdr))) {
783 DCCP_WARN(
"P.type (%s) not Data || [Data]Ack, while P.X == 0\n",
792 cscov = dccp_csum_coverage(skb);
793 if (cscov > skb->
len) {
794 DCCP_WARN(
"P.CsCov %u exceeds packet length %d\n",
795 dh->dccph_cscov, skb->
len);
809 static int dccp_v4_rcv(
struct sk_buff *skb)
812 const struct iphdr *iph;
823 if (dccp_v4_csum_finish(skb, iph->
saddr, iph->
daddr)) {
824 DCCP_WARN(
"dropped packet with invalid checksum\n");
839 if (dccp_packet_without_ack(skb)) {
843 DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb);
850 sk = __inet_lookup_skb(&dccp_hashinfo, skb,
858 "get corresponding socket\n");
869 dccp_pr_debug(
"sk->sk_state == DCCP_TIME_WAIT: do_time_wait\n");
879 min_cov = dccp_sk(sk)->dccps_pcrlen;
880 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) {
881 dccp_pr_debug(
"Packet CsCov %d does not satisfy MinCsCov %d\n",
882 dh->dccph_cscov, min_cov);
886 goto discard_and_relse;
890 goto discard_and_relse;
907 dccp_v4_ctl_send_reset(sk, skb);
925 .net_header_len =
sizeof(
struct iphdr),
937 static int dccp_v4_init_sock(
struct sock *sk)
939 static __u8 dccp_v4_ctl_sock_initialized;
943 if (
unlikely(!dccp_v4_ctl_sock_initialized))
944 dccp_v4_ctl_sock_initialized = 1;
945 inet_csk(sk)->icsk_af_ops = &dccp_ipv4_af_ops;
955 static struct proto dccp_v4_prot = {
962 .init = dccp_v4_init_sock,
978 .rsk_prot = &dccp_request_sock_ops,
979 .twsk_prot = &dccp_timewait_sock_ops,
982 .compat_setsockopt = compat_dccp_setsockopt,
983 .compat_getsockopt = compat_dccp_getsockopt,
988 .handler = dccp_v4_rcv,
989 .err_handler = dccp_v4_err,
994 static const struct proto_ops inet_dccp_ops = {
1015 #ifdef CONFIG_COMPAT
1024 .prot = &dccp_v4_prot,
1025 .ops = &inet_dccp_ops,
1030 static int __net_init dccp_v4_init_net(
struct net *net)
1039 static void __net_exit dccp_v4_exit_net(
struct net *net)
1041 inet_ctl_sock_destroy(net->dccp.v4_ctl_sk);
1045 .init = dccp_v4_init_net,
1046 .exit = dccp_v4_exit_net,
1049 static int __init dccp_v4_init(
void)
1058 goto out_proto_unregister;
1064 goto out_destroy_ctl_sock;
1067 out_destroy_ctl_sock:
1070 out_proto_unregister:
1075 static void __exit dccp_v4_exit(
void)