Skip to content

RFC bpf: Add PPPoE encap/decap kfuncs

ThisSeanZhang bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 RFC Latest3 patches 1 replyIn review

Changes in v3 from the cover letter

- Replace the proposed BPF_F_ADJ_ROOM_ENCAP_PPPOE and BPF_F_ADJ_ROOM_DECAP_PPPOE UAPI flags with bpf_skb_pppoe_encap() and bpf_skb_pppoe_decap() kfuncs.
- Add KF_CHANGES_PKT so the verifier invalidates packet pointers across calls to packet-modifying kfuncs. bpf_xdp_pull_data() and dynptr writes retain their existing handling.
- Make the encap kfunc write the PPPoE session header itself, mirroring pppoe_xmit().
- Rebase onto the current bpf-next.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: Add KF_CHANGES_PKT kfunc flaginclude/linux/btf.h kernel/bpf/verifier.c+2 -00 replies
2/3bpf: Add PPPoE encap/decap kfuncsnet/core/filter.c+192 -01 reply
3/3selftests/bpf: Add a test for the PPPoE encap/decap kfuncstools/testing/selftests/bpf/prog_tests/tc_pppoe.c tools/testing/selftests/bpf/progs/tc_pppoe.c tools/testing/selftests/bpf/progs/tc_pppoe_fail.c+382 -00 replies

Reviews trailers per patch

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

Read the v3 thread

Cover letter [RFC bpf-next v3 0/3] bpf: Add PPPoE encap/decap kfuncs

Hello,

The motivating use case is a TC BPF PPPoE forwarding path. When such a path forwards a GSO packet larger than the negotiated PPPoE MTU, inserting the PPPoE header manually leaves skb->protocol set to the original IP protocol, so the stack cannot select the PPPoE GSO path and the packet may be dropped.

The kernel already supports PPPoE GRO/GSO for ETH_P_PPP_SES (introduced by commit 55a5d8fca836 ("net: pppoe: implement GRO/GSO support")), but a TC BPF program has no direct way to update skb->protocol and the associated skb metadata when adding or removing a PPPoE header, and bpf_skb_adjust_room() cannot decapsulate PPPoE packets either, as it only accepts ETH_P_IP and ETH_P_IPV6. The current workaround uses BPF_F_ADJ_ROOM_ENCAP_L3_IPV4/IPV6, which marks the skb as IP-in-IP even though the wire format is PPPoE. The BPF program must also adjust gso_size manually [1].

This series adds bpf_skb_pppoe_encap() and bpf_skb_pppoe_decap(), which insert or remove the PPPoE session header and keep the skb metadata consistent with the kernel's PPPoE GRO/GSO handlers; the encap kfunc writes the PPPoE session header itself, mirroring pppoe_xmit(), and the BPF program sets the MAC header's EtherType, as with the existing BPF_F_ADJ_ROOM_ENCAP_* flags:

    bpf_skb_pppoe_encap(skb, sid, flags);
    bpf_skb_pppoe_decap(skb, flags);

Based on the v1 discussion about whether new UAPI flags were warranted, this version uses kfuncs instead, following the existing bpf_skb_set_fou_encap() interface. No UAPI changes are needed.

Since the kfuncs may reallocate the skb head, patch 1 adds the KF_CHANGES_PKT flag so the verifier invalidates packet pointers after calls to packet-modifying kfuncs, analogous to its handling of packet-modifying helpers. bpf_xdp_pull_data() and dynptr writes retain their existing handling.

The selftests cover IPv4 and IPv6 round trips, the PPPoE header fields written by the encap kfunc, rejection of non-IP encapsulation input, non-PPPoE decapsulation input, unsupported PPP protocols and truncated input, and verifier rejection of packet pointers held across a kfunc call. All 9 subtests pass in QEMU/KVM.

[1] https://github.com/ThisSeanZhang/landscape/blob/80bc43eef7143ad029283fe2a8d510718c22af12/landscape-ebpf/src/bpf/tc_chain/tc_pppoe.bpf.c#L38-L47

ThisSeanZhang (3):
bpf: Add KF_CHANGES_PKT kfunc flag
bpf: Add PPPoE encap/decap kfuncs
selftests/bpf: Add a test for the PPPoE encap/decap kfuncs

 include/linux/btf.h                           |   1 +
 kernel/bpf/verifier.c                         |   1 +
 net/core/filter.c                             | 192 +++++++++++++
 .../selftests/bpf/prog_tests/tc_pppoe.c       | 269 ++++++++++++++++++
 tools/testing/selftests/bpf/progs/tc_pppoe.c  |  77 +++++
 .../selftests/bpf/progs/tc_pppoe_fail.c       |  36 +++
 6 files changed, 576 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/tc_pppoe.c
 create mode 100644 tools/testing/selftests/bpf/progs/tc_pppoe.c
 create mode 100644 tools/testing/selftests/bpf/progs/tc_pppoe_fail.c

---

Changes since v2:
- Replace the proposed BPF_F_ADJ_ROOM_ENCAP_PPPOE and BPF_F_ADJ_ROOM_DECAP_PPPOE UAPI flags with bpf_skb_pppoe_encap() and bpf_skb_pppoe_decap() kfuncs.
- Add KF_CHANGES_PKT so the verifier invalidates packet pointers across calls to packet-modifying kfuncs. bpf_xdp_pull_data() and dynptr writes retain their existing handling.
- Make the encap kfunc write the PPPoE session header itself, mirroring pppoe_xmit().
- Rebase onto the current bpf-next.

v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/bpf/[email protected]/

base-commit: 0fb18ce8a2e9de830433923cf65838933d615359

Signature · 1 line
2.47.3