Commit 96511278 authored by Petar Penkov's avatar Petar Penkov Committed by Alexei Starovoitov

tcp: tcp_syn_flood_action read port from socket

This allows us to call this function before an SKB has been
allocated.
Signed-off-by: default avatarPetar Penkov <ppenkov@google.com>
Reviewed-by: default avatarLorenz Bauer <lmb@cloudflare.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent d3406913
...@@ -6422,9 +6422,7 @@ EXPORT_SYMBOL(inet_reqsk_alloc); ...@@ -6422,9 +6422,7 @@ EXPORT_SYMBOL(inet_reqsk_alloc);
/* /*
* Return true if a syncookie should be sent * Return true if a syncookie should be sent
*/ */
static bool tcp_syn_flood_action(const struct sock *sk, static bool tcp_syn_flood_action(const struct sock *sk, const char *proto)
const struct sk_buff *skb,
const char *proto)
{ {
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue; struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
const char *msg = "Dropping request"; const char *msg = "Dropping request";
...@@ -6444,7 +6442,7 @@ static bool tcp_syn_flood_action(const struct sock *sk, ...@@ -6444,7 +6442,7 @@ static bool tcp_syn_flood_action(const struct sock *sk,
net->ipv4.sysctl_tcp_syncookies != 2 && net->ipv4.sysctl_tcp_syncookies != 2 &&
xchg(&queue->synflood_warned, 1) == 0) xchg(&queue->synflood_warned, 1) == 0)
net_info_ratelimited("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n", net_info_ratelimited("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n",
proto, ntohs(tcp_hdr(skb)->dest), msg); proto, sk->sk_num, msg);
return want_cookie; return want_cookie;
} }
...@@ -6487,7 +6485,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, ...@@ -6487,7 +6485,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
*/ */
if ((net->ipv4.sysctl_tcp_syncookies == 2 || if ((net->ipv4.sysctl_tcp_syncookies == 2 ||
inet_csk_reqsk_queue_is_full(sk)) && !isn) { inet_csk_reqsk_queue_is_full(sk)) && !isn) {
want_cookie = tcp_syn_flood_action(sk, skb, rsk_ops->slab_name); want_cookie = tcp_syn_flood_action(sk, rsk_ops->slab_name);
if (!want_cookie) if (!want_cookie)
goto drop; goto drop;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment