Skip to content

bpf: add icmp_send kfunc#7858

Open
kernel-patches-daemon-bpf-rc[bot] wants to merge 8 commits into
bpf-next_basefrom
series/1101097=>bpf-next
Open

bpf: add icmp_send kfunc#7858
kernel-patches-daemon-bpf-rc[bot] wants to merge 8 commits into
bpf-next_basefrom
series/1101097=>bpf-next

Conversation

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown

Pull request for series with
subject: bpf: add icmp_send kfunc
version: 7
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 8496d90
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: e42e53a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: be4c6c7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: b23705e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: a4a5d4e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 7f9ce28
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 7f9ce28
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 9b435d2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 9a720e0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 9a720e0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 8ddce41
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: f6cd665
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 5b03831
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: c49f336
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 1444ee8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 63a6f3b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 50dff00
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: b9452b5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

Kernel Patches Daemon and others added 6 commits June 9, 2026 08:42
Move and rename nf_reject_fill_skb_dst from
ipv4/netfilter/nf_reject_ipv4 to ip_route_reply_fill_dst in ipv4/route.c
so that it can be reused in the following patches by BPF kfuncs.

Netfilter uses nf_ip_route that is almost a transparent wrapper around
ip_route_output_key so this patch inlines it.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Reviewed-by: Jordan Rife <jordan@jrife.io>
Move and rename nf_reject6_fill_skb_dst from
ipv6/netfilter/nf_reject_ipv6 to ip6_route_reply_fill_dst in
ipv6/route.c so that it can be reused in the following patches by BPF
kfuncs.

Netfilter uses nf_ip6_route that is almost a transparent wrapper around
ip6_route_output so this patch inlines it.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Reviewed-by: Jordan Rife <jordan@jrife.io>
This is needed in the context of Tetragon to provide improved feedback
(in contrast to just dropping packets) to east-west traffic when blocked
by policies using cgroup_skb programs. We also extend this kfunc to tc
program as a convenience.

This reuses concepts from netfilter reject target codepath with the
differences that:
* Packets are cloned since the BPF user can still let the packet pass
  (SK_PASS from the cgroup_skb progs for example) and the current skb
  need to stay untouched (cgroup_skb hooks only allow read-only skb
  payload).
* We protect against recursion since the kfunc, by generating an ICMP
  error message, could retrigger the BPF prog that invoked it.

For now, we support cgroup_skb and tc program types. For cgroup_skb and
tc egress, almost everything should be good. However for tc ingress:
- packet will not be routed yet: need to set the net device for
  icmp_send, thus the call to ip[6]_route_reply_fill_dst.
- fragments could trigger hook: icmp_send will only reply to fragment 0.
- ensure the ip headers is linearized before processing, and zero out
  the SKB control block after cloning to prevent icmp_send()/icmpv6_send()
  from misinterpreting garbage data as IP options.

Only ICMP_DEST_UNREACH and ICMPV6_DEST_UNREACH are currently supported.
The interface accepts a type parameter to facilitate future extension to
other ICMP control message types.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Reviewed-by: Jordan Rife <jordan@jrife.io>
This test opens a server and client, enters a new cgroup, attach a
cgroup_skb program on egress and calls the bpf_icmp_send function from
the client egress so that an ICMP unreach control message is sent back
to the client. It then fetches the message from the error queue to
confirm the correct ICMP unreach code has been sent.

Note that, for the client, we have to connect in non-blocking mode to
let the test execute faster. Otherwise, we need to wait for the TCP
three-way handshake to timeout in the kernel before reading the errno.

Also note that we don't set IP_RECVERR on the socket in
connect_to_fd_nonblock since the error will be transferred anyway in our
test because the connection is rejected at the beginning of the TCP
handshake. See in net/ipv4/tcp_ipv4.c:tcp_v4_err for more details.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Reviewed-by: Jordan Rife <jordan@jrife.io>
This test extends the existing cgroup_skb tests with IPv6 support.

Note that we need to set IPV6_RECVERR on the socket for IPv6 in
connect_to_fd_nonblock otherwise the error will be ignored even if we
are in the middle of the TCP handshake. See in
net/ipv6/datagram.c:ipv6_icmp_error for more details.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: dd0f968
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1101097
version: 7

mtardy added 2 commits June 9, 2026 08:46
This test is similar to the one with cgroup_skb programs but uses tc
egress instead.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
This test is similar to test_icmp_send_unreach_cgroup but checks that,
in case of recursion, meaning that the BPF program calling the kfunc was
re-triggered by the icmp_send done by the kfunc, the kfunc will stop
early and return -EBUSY.

The test attaches to the root cgroup to ensure the ICMP packet generated
by the kfunc re-triggers the BPF program. Since it's attached only for
this recursion test, it should not disrupt the whole network.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant