@@ -272,6 +272,18 @@ static inline void inet_csk_reqsk_queue_added(struct sock *sk)
reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
}
+static inline void inet_csk_reqsk_queue_migrated(struct sock *sk,
+ struct sock *nsk,
+ struct request_sock *req)
+{
+ reqsk_queue_migrated(&inet_csk(sk)->icsk_accept_queue,
+ &inet_csk(nsk)->icsk_accept_queue,
+ req);
+ sock_put(sk);
+ sock_hold(nsk);
+ req->rsk_listener = nsk;
+}
+
static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
{
return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
@@ -226,6 +226,19 @@ static inline void reqsk_queue_added(struct request_sock_queue *queue)
atomic_inc(&queue->qlen);
}
+static inline void reqsk_queue_migrated(struct request_sock_queue *old_accept_queue,
+ struct request_sock_queue *new_accept_queue,
+ const struct request_sock *req)
+{
+ atomic_dec(&old_accept_queue->qlen);
+ atomic_inc(&new_accept_queue->qlen);
+
+ if (req->num_timeout == 0) {
+ atomic_dec(&old_accept_queue->young);
+ atomic_inc(&new_accept_queue->young);
+ }
+}
+
static inline int reqsk_queue_len(const struct request_sock_queue *queue)
{
return atomic_read(&queue->qlen);
@@ -743,8 +743,16 @@ static void reqsk_timer_handler(struct timer_list *t)
struct request_sock_queue *queue = &icsk->icsk_accept_queue;
int max_syn_ack_retries, qlen, expire = 0, resend = 0;
- if (inet_sk_state_load(sk_listener) != TCP_LISTEN)
- goto drop;
+ if (inet_sk_state_load(sk_listener) != TCP_LISTEN) {
+ sk_listener = reuseport_select_sock(sk_listener, sk_listener->sk_hash, NULL, 0);
+ if (!sk_listener) {
+ sk_listener = req->rsk_listener;
+ goto drop;
+ }
+ inet_csk_reqsk_queue_migrated(req->rsk_listener, sk_listener, req);
+ icsk = inet_csk(sk_listener);
+ queue = &icsk->icsk_accept_queue;
+ }
max_syn_ack_retries = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_synack_retries;
/* Normally all the openreqs are young and become mature
@@ -1957,8 +1957,13 @@ int tcp_v4_rcv(struct sk_buff *skb)
goto csum_error;
}
if (unlikely(sk->sk_state != TCP_LISTEN)) {
- inet_csk_reqsk_queue_drop_and_put(sk, req);
- goto lookup;
+ nsk = reuseport_select_sock(sk, sk->sk_hash, NULL, 0);
+ if (!nsk) {
+ inet_csk_reqsk_queue_drop_and_put(sk, req);
+ goto lookup;
+ }
+ inet_csk_reqsk_queue_migrated(sk, nsk, req);
+ sk = nsk;
}
/* We own a reference on the listener, increase it again
* as we might lose it too soon.
@@ -1619,8 +1619,13 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
goto csum_error;
}
if (unlikely(sk->sk_state != TCP_LISTEN)) {
- inet_csk_reqsk_queue_drop_and_put(sk, req);
- goto lookup;
+ nsk = reuseport_select_sock(sk, sk->sk_hash, NULL, 0);
+ if (!nsk) {
+ inet_csk_reqsk_queue_drop_and_put(sk, req);
+ goto lookup;
+ }
+ inet_csk_reqsk_queue_migrated(sk, nsk, req);
+ sk = nsk;
}
sock_hold(sk);
refcounted = true;