Skip to content

RFC Introduce a BPF helper to generate SYN cookies

Petar Penkov bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6tcp: tcp_syn_flood_action read port from socketnet/ipv4/tcp_input.c+3 -50 replies
2/6tcp: add skb-less helpers to retrieve SYN cookieinclude/net/tcp.h net/ipv4/tcp_input.c net/ipv4/tcp_ipv4.c +1 more+106 -02 replies
3/6bpf: add bpf_tcp_gen_syncookie helperinclude/uapi/linux/bpf.h net/core/filter.c+91 -16 replies
4/6bpf: sync bpf.h to tools/tools/include/uapi/linux/bpf.h+34 -30 replies
5/6selftests/bpf: bpf_tcp_gen_syncookie->bpf_helperstools/testing/selftests/bpf/bpf_helpers.h+3 -00 replies
6/6selftests/bpf: add test for bpf_tcp_gen_syncookietools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c+76 -130 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [bpf-next RFC 0/6] Introduce a BPF helper to generate SYN cookies

From: Petar Penkov <[email protected]>

This patch series introduces a BPF helper function that allows generating SYN cookies from BPF.

The first two patches in the series modify several TCP helper functions to allow for SKB-less operation, as is the case with XDP.

The third patch introduces the bpf_tcp_gen_syncookie helper function which generates a SYN cookie for either XDP or TC programs.

The last three patches sync tools/ and add a test.

The primary design consideration I see in the patch series is the return value of the helper function. Currently bpf_tcp_gen_syncookie returns a 64-bit value that contains both the 32-bit syncookie, and the 16-bit mss value which is encoded in the cookie. On error, it would return a negative value instead. I chose this over writing the cookie into the provided TCP packet to avoid writing packet data as currently if a helper changes the packet data, the first argument has to point to the context (can this be relaxed?).

To make the API cleaner we can instead return something like the struct below though the return type would then not really be RET_INTEGER or any of the currently existing return types.

struct bpf_syncookie {
	u16 error; // or u8 error, u8 unused for future use
	u16 mss;
	u32 syncookie;
}

Petar Penkov (6):
tcp: tcp_syn_flood_action read port from socket
tcp: add skb-less helpers to retrieve SYN cookie
bpf: add bpf_tcp_gen_syncookie helper
bpf: sync bpf.h to tools/
selftests/bpf: bpf_tcp_gen_syncookie->bpf_helpers selftests/bpf: add test for bpf_tcp_gen_syncookie

 include/net/tcp.h                             | 11 +++
 include/uapi/linux/bpf.h                      | 30 ++++++-
 net/core/filter.c                             | 62 +++++++++++++
 net/ipv4/tcp_input.c                          | 87 +++++++++++++++++--
 net/ipv4/tcp_ipv4.c                           |  8 ++
 net/ipv6/tcp_ipv6.c                           |  8 ++
 tools/include/uapi/linux/bpf.h                | 37 +++++++-
 tools/testing/selftests/bpf/bpf_helpers.h     |  3 +
 .../bpf/progs/test_tcp_check_syncookie_kern.c | 28 ++++--
 .../bpf/test_tcp_check_syncookie_user.c       | 61 +++++++++++--
 10 files changed, 313 insertions(+), 22 deletions(-)
Signature · 1 line
2.22.0.510.g264f2c817a-goog