mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
bpf: add helper to check for a valid SYN cookie
Using bpf_skc_lookup_tcp it's possible to ascertain whether a packet belongs to a known connection. However, there is one corner case: no sockets are created if SYN cookies are active. This means that the final ACK in the 3WHS is misclassified. Using the helper, we can look up the listening socket via bpf_skc_lookup_tcp and then check whether a packet is a valid SYN cookie ACK. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
edbf8c01de
commit
3990408470
2 changed files with 89 additions and 1 deletions
|
@ -2448,6 +2448,21 @@ union bpf_attr {
|
|||
* Pointer to **struct bpf_sock**, or **NULL** in case of failure.
|
||||
* For sockets with reuseport option, the **struct bpf_sock**
|
||||
* result is from **reuse->socks**\ [] using the hash of the tuple.
|
||||
*
|
||||
* int bpf_tcp_check_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
|
||||
* Description
|
||||
* Check whether iph and th contain a valid SYN cookie ACK for
|
||||
* the listening socket in sk.
|
||||
*
|
||||
* iph points to the start of the IPv4 or IPv6 header, while
|
||||
* iph_len contains sizeof(struct iphdr) or sizeof(struct ip6hdr).
|
||||
*
|
||||
* th points to the start of the TCP header, while th_len contains
|
||||
* sizeof(struct tcphdr).
|
||||
*
|
||||
* Return
|
||||
* 0 if iph and th are a valid SYN cookie ACK, or a negative error
|
||||
* otherwise.
|
||||
*/
|
||||
#define __BPF_FUNC_MAPPER(FN) \
|
||||
FN(unspec), \
|
||||
|
@ -2549,7 +2564,8 @@ union bpf_attr {
|
|||
FN(tcp_sock), \
|
||||
FN(skb_ecn_set_ce), \
|
||||
FN(get_listener_sock), \
|
||||
FN(skc_lookup_tcp),
|
||||
FN(skc_lookup_tcp), \
|
||||
FN(tcp_check_syncookie),
|
||||
|
||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||
* function eBPF program intends to call
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue