Skip to contentSkip to conversation

bpf: Extend the sk_lookup() helper to XDP hookpoint.

PATCH In review Nitin Hande 2 participants 2 messages Oct 29, 2018 – Nov 9, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: Extend the sk_lookup() helper to XDP hookpoint.

This patch proposes to extend the sk_lookup() BPF API to the XDP hookpoint. The sk_lookup() helper supports a lookup on incoming packet to find the corresponding socket that will receive this packet. Current support for this BPF API is at the tc hookpoint. This patch will extend this API at XDP hookpoint. A XDP program can map the incoming packet to the 5-tuple parameter and invoke the API to find the corresponding socket structure.

---
v1->v2
- For sockets with reuseport socket option, there was a case where the sk returned by the helper can vary due to the absence of skb at XDP hookpoint as compared to TC. v2 removes that variance by passing NULL for skb from both TC and XDP hookpoint. As a result, for reuseport sockets, the helper will now consistently return the same sk from reuse->socks[] using the hash of the packet after being invoked from either TC or XDP hookpoint. This also makes the helper stateless, else there are certain scenarios where upper layer records skb.
- Add relevant documentation to the helper.

---
 include/uapi/linux/bpf.h |   4 ++
 net/core/filter.c        | 105 ++++++++++++++++++++++++++++++++-------
 2 files changed, 90 insertions(+), 19 deletions(-)
include/uapi/linux/bpf.h +4 -0
index 852dc17ab47a..47d606d744cc 100644
@@ -2201,6 +2201,8 @@ union bpf_attr {
  *		**CONFIG_NET** configuration option.
  *	Return
  *		Pointer to *struct bpf_sock*, or NULL in case of failure.
+ *		For sockets with reuseport option, *struct bpf_sock*
+ *		return is from reuse->socks[] using hash of the packet.
  *
  * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u32 netns, u64 flags)
  *	Description
@@ -2233,6 +2235,8 @@ union bpf_attr {
  *		**CONFIG_NET** configuration option.
  *	Return
  *		Pointer to *struct bpf_sock*, or NULL in case of failure.
+ *		For sockets with reuseport option, *struct bpf_sock*
+ *		return is from reuse->socks[] using hash of the packet.
  *
  * int bpf_sk_release(struct bpf_sock *sk)
  *	Description
net/core/filter.c +86 -19

180 lines not on this page · raw message

Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 11 lines · Nitin Hande

This patch proposes to extend the sk_lookup() BPF API to the XDP hookpoint. The sk_lookup() helper supports a lookup on incoming packet to find the corresponding socket that will receive this packet. Current support for this BPF API is at the tc hookpoint. This patch will extend this API at XDP hookpoint. A XDP program can map the incoming packet to the 5-tuple parameter and invoke the API to find the corresponding socket structure.

Looks good to me, applied to bpf-next, thanks Nitin!