Skip to content

Commit c67b2a6

Browse files
sm00thanakryiko
authored andcommitted
selftests/bpf: Fix compilation failure when CONFIG_NET_FOU!=y
Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue. Signed-off-by: Artem Savkov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 64d50da commit c67b2a6

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tools/testing/selftests/bpf/progs/test_tunnel_kern.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
*/
2727
#define ASSIGNED_ADDR_VETH1 0xac1001c8
2828

29+
struct bpf_fou_encap___local {
30+
__be16 sport;
31+
__be16 dport;
32+
} __attribute__((preserve_access_index));
33+
34+
enum bpf_fou_encap_type___local {
35+
FOU_BPF_ENCAP_FOU___local,
36+
FOU_BPF_ENCAP_GUE___local,
37+
};
38+
39+
struct bpf_fou_encap;
40+
2941
int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
3042
struct bpf_fou_encap *encap, int type) __ksym;
3143
int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
@@ -745,7 +757,7 @@ SEC("tc")
745757
int ipip_gue_set_tunnel(struct __sk_buff *skb)
746758
{
747759
struct bpf_tunnel_key key = {};
748-
struct bpf_fou_encap encap = {};
760+
struct bpf_fou_encap___local encap = {};
749761
void *data = (void *)(long)skb->data;
750762
struct iphdr *iph = data;
751763
void *data_end = (void *)(long)skb->data_end;
@@ -769,7 +781,9 @@ int ipip_gue_set_tunnel(struct __sk_buff *skb)
769781
encap.sport = 0;
770782
encap.dport = bpf_htons(5555);
771783

772-
ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE);
784+
ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
785+
bpf_core_enum_value(enum bpf_fou_encap_type___local,
786+
FOU_BPF_ENCAP_GUE___local));
773787
if (ret < 0) {
774788
log_err(ret);
775789
return TC_ACT_SHOT;
@@ -782,7 +796,7 @@ SEC("tc")
782796
int ipip_fou_set_tunnel(struct __sk_buff *skb)
783797
{
784798
struct bpf_tunnel_key key = {};
785-
struct bpf_fou_encap encap = {};
799+
struct bpf_fou_encap___local encap = {};
786800
void *data = (void *)(long)skb->data;
787801
struct iphdr *iph = data;
788802
void *data_end = (void *)(long)skb->data_end;
@@ -806,7 +820,8 @@ int ipip_fou_set_tunnel(struct __sk_buff *skb)
806820
encap.sport = 0;
807821
encap.dport = bpf_htons(5555);
808822

809-
ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU);
823+
ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
824+
FOU_BPF_ENCAP_FOU___local);
810825
if (ret < 0) {
811826
log_err(ret);
812827
return TC_ACT_SHOT;
@@ -820,15 +835,15 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
820835
{
821836
int ret;
822837
struct bpf_tunnel_key key = {};
823-
struct bpf_fou_encap encap = {};
838+
struct bpf_fou_encap___local encap = {};
824839

825840
ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
826841
if (ret < 0) {
827842
log_err(ret);
828843
return TC_ACT_SHOT;
829844
}
830845

831-
ret = bpf_skb_get_fou_encap(skb, &encap);
846+
ret = bpf_skb_get_fou_encap(skb, (struct bpf_fou_encap *)&encap);
832847
if (ret < 0) {
833848
log_err(ret);
834849
return TC_ACT_SHOT;

0 commit comments

Comments
 (0)