Martin KaFai Lau says:
====================
The earlier effort in BPF-TCP-CC allows the TCP Congestion Control
algorithm to be written in BPF. It opens up opportunities to allow
a faster turnaround time in testing/releasing new congestion control
ideas to production environment.
The same flexibility can be extended to writing TCP header option.
It is not uncommon that people want to test new TCP header option
to improve the TCP performance. Another use case is for data-center
that has a more controlled environment and has more flexibility in
putting header options for internal traffic only.
This patch set introduces the necessary BPF logic and API to
allow bpf program to write and parse header options.
There are also some changes to TCP and they are mostly to provide
the needed sk and skb info to the bpf program to make decision.
Patch 9 is the main patch and has more details on the API and design.
The set includes an example which sends the max delay ack in
the BPF TCP header option and the receiving side can
then adjust its RTO accordingly.
v5:
- Move some of the comments from git commit message to the UAPI bpf.h
in patch 9
- Some variable clean up in the tests (patch 11).
v4:
- Since bpf-next is currently closed, tag the set with RFC to keep the
review cadence
- Separate tcp changes in its own patches (5, 6, 7). It is a bit
tricky since most of the tcp changes is to call out the bpf prog to
write and parse the header. The write and parse callout has been
modularized into a few bpf_skops_* function in v3.
This revision (v4) tries to move those bpf_skops_* functions into separate
TCP patches. However, they will be half implemented to highlight
the changes to the TCP stack, mainly:
- when the bpf prog will be called in the TCP stack and
- what information needs to pump through the TCP stack to the actual bpf
prog callsite.
The bpf_skops_* functions will be fully implemented in patch 9 together
with other bpf pieces.
- Use struct_size() in patch 1 (Eric)
- Add saw_unknown to struct tcp_options_received in patch 4 (Eric)
v3:
- Add kdoc for tcp_make_synack (Jakub Kicinski)
- Add BPF_WRITE_HDR_TCP_CURRENT_MSS and BPF_WRITE_HDR_TCP_SYNACK_COOKIE
in bpf.h to give a clearer meaning to sock_ops->args[0] when
writing header option.
- Rename BPF_SOCK_OPS_PARSE_UNKWN_HDR_OPT_CB_FLAG
to BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG
v2:
- Instead of limiting the bpf prog to write experimental
option (kind:254, magic:0xeB9F), this revision allows the bpf prog to
write any TCP header option through the bpf_store_hdr_opt() helper.
That will allow different bpf-progs to write its own
option and the helper will guarantee there is no duplication.
- Add bpf_load_hdr_opt() helper to search a particular option by kind.
Some of the get_syn logic is refactored to bpf_sock_ops_get_syn().
- Since bpf prog is no longer limited to option (254, 0xeB9F),
the TCP_SKB_CB(skb)->bpf_hdr_opt_off is no longer needed.
Instead, when there is any option kernel cannot recognize,
the bpf prog will be called if the
BPF_SOCK_OPS_PARSE_UNKWN_HDR_OPT_CB_FLAG is set.
[ The "unknown_opt" is learned in tcp_parse_options() in patch 4. ]
- Add BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG.
If this flag is set, the bpf-prog will be called
on all tcp packet received at an established sk.
It will be useful to ensure a previously written header option is
received by the peer.
e.g. The latter test is using this on the active-side during syncookie.
- The test_tcp_hdr_options.c is adjusted accordingly
to test writing both experimental and regular TCP header option.
- The test_misc_tcp_hdr_options.c is added to mainly
test different cases on the new helpers.
- Break up the TCP_BPF_RTO_MIN and TCP_BPF_DELACK_MAX into
two patches.
- Directly store the tcp_hdrlen in "struct saved_syn" instead of
going back to the tcp header to obtain it by "th->doff * 4"
- Add a new optval(==2) for setsockopt(TCP_SAVE_SYN) such
that it will also store the mac header (patch 9).
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>