Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1a5344d authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

tcp: avoid two atomic ops for syncookies



inet_reqsk_alloc() is used to allocate a temporary request
in order to generate a SYNACK with a cookie. Then later,
syncookie validation also uses a temporary request.

These paths already took a reference on listener refcount,
we can avoid a couple of atomic operations.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 004a5d01
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -245,7 +245,8 @@ static inline unsigned int __inet_ehashfn(const __be32 laddr,
}

struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops,
				      struct sock *sk_listener);
				      struct sock *sk_listener,
				      bool attach_listener);

static inline __u8 inet_sk_flowi_flags(const struct sock *sk)
{
+8 −3
Original line number Diff line number Diff line
@@ -80,7 +80,8 @@ static inline struct sock *req_to_sk(struct request_sock *req)
}

static inline struct request_sock *
reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener)
reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener,
	    bool attach_listener)
{
	struct request_sock *req;

@@ -88,8 +89,12 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener)

	if (req) {
		req->rsk_ops = ops;
		if (attach_listener) {
			sock_hold(sk_listener);
			req->rsk_listener = sk_listener;
		} else {
			req->rsk_listener = NULL;
		}
		req_to_sk(req)->sk_prot = sk_listener->sk_prot;
		sk_node_init(&req_to_sk(req)->sk_node);
		sk_tx_queue_clear(req_to_sk(req));
+1 −1
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
	if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
		goto drop;

	req = inet_reqsk_alloc(&dccp_request_sock_ops, sk);
	req = inet_reqsk_alloc(&dccp_request_sock_ops, sk, true);
	if (req == NULL)
		goto drop;

+1 −1
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
	if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
		goto drop;

	req = inet_reqsk_alloc(&dccp6_request_sock_ops, sk);
	req = inet_reqsk_alloc(&dccp6_request_sock_ops, sk, true);
	if (req == NULL)
		goto drop;

+1 −1
Original line number Diff line number Diff line
@@ -326,7 +326,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
		goto out;

	ret = NULL;
	req = inet_reqsk_alloc(&tcp_request_sock_ops, sk); /* for safety */
	req = inet_reqsk_alloc(&tcp_request_sock_ops, sk, false); /* for safety */
	if (!req)
		goto out;

Loading