]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - net/ipv4/syncookies.c
Merge tag 'uuid-for-4.13-2' of git://git.infradead.org/users/hch/uuid
[linux.git] / net / ipv4 / syncookies.c
index 0257d965f11119acf8c55888d6e672d171ef5f08..03ad8778c395334ed53a250bccc0b991cd85c2f2 100644 (file)
@@ -66,10 +66,10 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
  * Since subsequent timestamps use the normal tcp_time_stamp value, we
  * must make sure that the resulting initial timestamp is <= tcp_time_stamp.
  */
-__u32 cookie_init_timestamp(struct request_sock *req)
+u64 cookie_init_timestamp(struct request_sock *req)
 {
        struct inet_request_sock *ireq;
-       u32 ts, ts_now = tcp_time_stamp;
+       u32 ts, ts_now = tcp_time_stamp_raw();
        u32 options = 0;
 
        ireq = inet_rsk(req);
@@ -88,7 +88,7 @@ __u32 cookie_init_timestamp(struct request_sock *req)
                ts <<= TSBITS;
                ts |= options;
        }
-       return ts;
+       return (u64)ts * (USEC_PER_SEC / TCP_TS_HZ);
 }
 
 
@@ -213,7 +213,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,
        child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
                                                 NULL, &own_req);
        if (child) {
-               atomic_set(&req->rsk_refcnt, 1);
+               refcount_set(&req->rsk_refcnt, 1);
                tcp_sk(child)->tsoffset = tsoff;
                sock_rps_save_rxhash(child, skb);
                inet_csk_reqsk_queue_add(sk, req, child);
@@ -232,7 +232,8 @@ EXPORT_SYMBOL(tcp_get_cookie_sock);
  * return false if we decode a tcp option that is disabled
  * on the host.
  */
-bool cookie_timestamp_decode(struct tcp_options_received *tcp_opt)
+bool cookie_timestamp_decode(const struct net *net,
+                            struct tcp_options_received *tcp_opt)
 {
        /* echoed timestamp, lowest bits contain options */
        u32 options = tcp_opt->rcv_tsecr;
@@ -242,12 +243,12 @@ bool cookie_timestamp_decode(struct tcp_options_received *tcp_opt)
                return true;
        }
 
-       if (!sysctl_tcp_timestamps)
+       if (!net->ipv4.sysctl_tcp_timestamps)
                return false;
 
        tcp_opt->sack_ok = (options & TS_OPT_SACK) ? TCP_SACK_SEEN : 0;
 
-       if (tcp_opt->sack_ok && !sysctl_tcp_sack)
+       if (tcp_opt->sack_ok && !net->ipv4.sysctl_tcp_sack)
                return false;
 
        if ((options & TS_OPT_WSCALE_MASK) == TS_OPT_WSCALE_MASK)
@@ -256,7 +257,7 @@ bool cookie_timestamp_decode(struct tcp_options_received *tcp_opt)
        tcp_opt->wscale_ok = 1;
        tcp_opt->snd_wscale = options & TS_OPT_WSCALE_MASK;
 
-       return sysctl_tcp_window_scaling != 0;
+       return net->ipv4.sysctl_tcp_window_scaling != 0;
 }
 EXPORT_SYMBOL(cookie_timestamp_decode);
 
@@ -312,14 +313,16 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
        /* check for timestamp cookie support */
        memset(&tcp_opt, 0, sizeof(tcp_opt));
-       tcp_parse_options(skb, &tcp_opt, 0, NULL);
+       tcp_parse_options(sock_net(sk), skb, &tcp_opt, 0, NULL);
 
        if (tcp_opt.saw_tstamp && tcp_opt.rcv_tsecr) {
-               tsoff = secure_tcp_ts_off(ip_hdr(skb)->daddr, ip_hdr(skb)->saddr);
+               tsoff = secure_tcp_ts_off(sock_net(sk),
+                                         ip_hdr(skb)->daddr,
+                                         ip_hdr(skb)->saddr);
                tcp_opt.rcv_tsecr -= tsoff;
        }
 
-       if (!cookie_timestamp_decode(&tcp_opt))
+       if (!cookie_timestamp_decode(sock_net(sk), &tcp_opt))
                goto out;
 
        ret = NULL;
@@ -332,6 +335,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
        treq->rcv_isn           = ntohl(th->seq) - 1;
        treq->snt_isn           = cookie;
        treq->ts_off            = 0;
+       treq->txhash            = net_tx_rndhash();
        req->mss                = mss;
        ireq->ir_num            = ntohs(th->dest);
        ireq->ir_rmt_port       = th->source;
@@ -343,7 +347,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
        ireq->wscale_ok         = tcp_opt.wscale_ok;
        ireq->tstamp_ok         = tcp_opt.saw_tstamp;
        req->ts_recent          = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval : 0;
-       treq->snt_synack.v64    = 0;
+       treq->snt_synack        = 0;
        treq->tfo_listener      = false;
 
        ireq->ir_iif = inet_request_bound_dev_if(sk, skb);