]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf: Call __bpf_sk_lookup()/__bpf_skc_lookup() directly via TC hookpoint
authorGilad Sever <gilad9366@gmail.com>
Wed, 21 Jun 2023 10:42:09 +0000 (13:42 +0300)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Mon, 2 Oct 2023 15:19:36 +0000 (17:19 +0200)
BugLink: https://bugs.launchpad.net/bugs/2034469
[ Upstream commit 97fbfeb86917bdbe9c41d5143e335a929147f405 ]

skb->dev always exists in the tc flow. There is no need to use
bpf_skc_lookup(), bpf_sk_lookup() from this code path.

This change facilitates fixing the tc flow to be VRF aware.

Signed-off-by: Gilad Sever <gilad9366@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Reviewed-by: Eyal Birger <eyal.birger@gmail.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20230621104211.301902-3-gilad9366@gmail.com
Stable-dep-of: 9a5cb79762e0 ("bpf: Fix bpf socket lookup from tc/xdp to respect socket VRF bindings")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
net/core/filter.c

index 95e2cc6b9916db559b91be8461f3eb5bf032e3bb..b30137ccf0a6c366b80dcdffda08781fd55c5686 100644 (file)
@@ -6658,8 +6658,12 @@ static const struct bpf_func_proto bpf_sk_lookup_udp_proto = {
 BPF_CALL_5(bpf_tc_skc_lookup_tcp, struct sk_buff *, skb,
           struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
 {
-       return (unsigned long)bpf_skc_lookup(skb, tuple, len, IPPROTO_TCP,
-                                            netns_id, flags);
+       struct net *caller_net = dev_net(skb->dev);
+       int ifindex = skb->dev->ifindex;
+
+       return (unsigned long)__bpf_skc_lookup(skb, tuple, len, caller_net,
+                                              ifindex, IPPROTO_TCP, netns_id,
+                                              flags);
 }
 
 static const struct bpf_func_proto bpf_tc_skc_lookup_tcp_proto = {
@@ -6677,8 +6681,12 @@ static const struct bpf_func_proto bpf_tc_skc_lookup_tcp_proto = {
 BPF_CALL_5(bpf_tc_sk_lookup_tcp, struct sk_buff *, skb,
           struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
 {
-       return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_TCP,
-                                           netns_id, flags);
+       struct net *caller_net = dev_net(skb->dev);
+       int ifindex = skb->dev->ifindex;
+
+       return (unsigned long)__bpf_sk_lookup(skb, tuple, len, caller_net,
+                                             ifindex, IPPROTO_TCP, netns_id,
+                                             flags);
 }
 
 static const struct bpf_func_proto bpf_tc_sk_lookup_tcp_proto = {
@@ -6696,8 +6704,12 @@ static const struct bpf_func_proto bpf_tc_sk_lookup_tcp_proto = {
 BPF_CALL_5(bpf_tc_sk_lookup_udp, struct sk_buff *, skb,
           struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
 {
-       return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_UDP,
-                                           netns_id, flags);
+       struct net *caller_net = dev_net(skb->dev);
+       int ifindex = skb->dev->ifindex;
+
+       return (unsigned long)__bpf_sk_lookup(skb, tuple, len, caller_net,
+                                             ifindex, IPPROTO_UDP, netns_id,
+                                             flags);
 }
 
 static const struct bpf_func_proto bpf_tc_sk_lookup_udp_proto = {