]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tcp: Use BPF timeout setting for SYN ACK RTO
authorAkhmat Karakotov <hmukos@yandex-team.ru>
Fri, 28 Jan 2022 19:26:21 +0000 (22:26 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 2 Feb 2022 14:45:18 +0000 (14:45 +0000)
When setting RTO through BPF program, some SYN ACK packets were unaffected
and continued to use TCP_TIMEOUT_INIT constant. This patch adds timeout
option to struct request_sock. Option is initialized with TCP_TIMEOUT_INIT
and is reassigned through BPF using tcp_timeout_init call. SYN ACK
retransmits now use newly added timeout option.

Signed-off-by: Akhmat Karakotov <hmukos@yandex-team.ru>
Acked-by: Martin KaFai Lau <kafai@fb.com>
v2:
- Add timeout option to struct request_sock. Do not call
  tcp_timeout_init on every syn ack retransmit.

v3:
- Use unsigned long for min. Bound tcp_timeout_init to TCP_RTO_MAX.

v4:
- Refactor duplicate code by adding reqsk_timeout function.
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_connection_sock.h
include/net/request_sock.h
include/net/tcp.h
net/ipv4/inet_connection_sock.c
net/ipv4/tcp_input.c
net/ipv4/tcp_minisocks.c

index 4ad47d9f9d271fcf8bb3c9d88ef2a602bdeffa54..3908296d103fd2de9284adea64dba94fe6b8720f 100644 (file)
@@ -285,6 +285,14 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
 bool inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
 void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
 
+static inline unsigned long
+reqsk_timeout(struct request_sock *req, unsigned long max_timeout)
+{
+       u64 timeout = (u64)req->timeout << req->num_timeout;
+
+       return (unsigned long)min_t(u64, timeout, max_timeout);
+}
+
 static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
 {
        /* The below has to be done to allow calling inet_csk_destroy_sock */
index 29e41ff3ec9333e66c3fc00f585e3b6a5b06bf8d..144c39db9898abcf8cc8582597d04a912ef53495 100644 (file)
@@ -70,6 +70,7 @@ struct request_sock {
        struct saved_syn                *saved_syn;
        u32                             secid;
        u32                             peer_secid;
+       u32                             timeout;
 };
 
 static inline struct request_sock *inet_reqsk(const struct sock *sk)
@@ -104,6 +105,7 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener,
        sk_node_init(&req_to_sk(req)->sk_node);
        sk_tx_queue_clear(req_to_sk(req));
        req->saved_syn = NULL;
+       req->timeout = 0;
        req->num_timeout = 0;
        req->num_retrans = 0;
        req->sk = NULL;
index b9fc978fb2cad600abee7ba9667f91769a390063..eff2487d972d2c41e568df50953b23fa77629d7b 100644 (file)
@@ -2358,7 +2358,7 @@ static inline u32 tcp_timeout_init(struct sock *sk)
 
        if (timeout <= 0)
                timeout = TCP_TIMEOUT_INIT;
-       return timeout;
+       return min_t(int, timeout, TCP_RTO_MAX);
 }
 
 static inline u32 tcp_rwnd_init_bpf(struct sock *sk)
index b81fb13fc5f446e065d00d5bbb2555a91d635dbd..1e5b53c2bb2670fc90b789e853458f5c86a00c27 100644 (file)
@@ -866,12 +866,9 @@ static void reqsk_timer_handler(struct timer_list *t)
            (!resend ||
             !inet_rtx_syn_ack(sk_listener, req) ||
             inet_rsk(req)->acked)) {
-               unsigned long timeo;
-
                if (req->num_timeout++ == 0)
                        atomic_dec(&queue->young);
-               timeo = min(TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
-               mod_timer(&req->rsk_timer, jiffies + timeo);
+               mod_timer(&req->rsk_timer, jiffies + reqsk_timeout(req, TCP_RTO_MAX));
 
                if (!nreq)
                        return;
index dc49a3d551eb919baf5ad812ef21698c5c7b9679..302744bec59e151cc6759b9ffeb6c8666ef91315 100644 (file)
@@ -6723,6 +6723,7 @@ struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops,
                ireq->ireq_state = TCP_NEW_SYN_RECV;
                write_pnet(&ireq->ireq_net, sock_net(sk_listener));
                ireq->ireq_family = sk_listener->sk_family;
+               req->timeout = TCP_TIMEOUT_INIT;
        }
 
        return req;
@@ -6939,9 +6940,10 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
                sock_put(fastopen_sk);
        } else {
                tcp_rsk(req)->tfo_listener = false;
-               if (!want_cookie)
-                       inet_csk_reqsk_queue_hash_add(sk, req,
-                               tcp_timeout_init((struct sock *)req));
+               if (!want_cookie) {
+                       req->timeout = tcp_timeout_init((struct sock *)req);
+                       inet_csk_reqsk_queue_hash_add(sk, req, req->timeout);
+               }
                af_ops->send_synack(sk, dst, &fl, req, &foc,
                                    !want_cookie ? TCP_SYNACK_NORMAL :
                                                   TCP_SYNACK_COOKIE,
index 3977257f80d9963c84a117d4d65d426f1952449f..6366df7aaf2a6d655162a73ae1b19205a5ca0a23 100644 (file)
@@ -583,7 +583,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
                         * it can be estimated (approximately)
                         * from another data.
                         */
-                       tmp_opt.ts_recent_stamp = ktime_get_seconds() - ((TCP_TIMEOUT_INIT/HZ)<<req->num_timeout);
+                       tmp_opt.ts_recent_stamp = ktime_get_seconds() - reqsk_timeout(req, TCP_RTO_MAX) / HZ;
                        paws_reject = tcp_paws_reject(&tmp_opt, th->rst);
                }
        }
@@ -622,8 +622,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
                    !inet_rtx_syn_ack(sk, req)) {
                        unsigned long expires = jiffies;
 
-                       expires += min(TCP_TIMEOUT_INIT << req->num_timeout,
-                                      TCP_RTO_MAX);
+                       expires += reqsk_timeout(req, TCP_RTO_MAX);
                        if (!fastopen)
                                mod_timer_pending(&req->rsk_timer, expires);
                        else