dns icon indicating copy to clipboard operation
dns copied to clipboard

Could not compile on Debian 12

Open l1x opened this issue 2 years ago • 6 comments

I'm using fbdns version:

Given:

uname -a
Linux deby.lan 6.1.0-8-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.25-1 (2023-04-22) x86_64 GNU/Linux

When I run:

doas apt install libbpf1 libbpf-dev libpcap0.8 libpcap0.8-dev make clang gcc-multilib
make

I expected this to happen:

Working compilation

But, instead this happened:

l1x@deby ~/c/d/dnswatch (main)> make
clang -g -O2 -Wall -fpie -fno-stack-protector -I /usr/include/bpf -target bpf -D__TARGET_ARCH_x86 -I bpf  -c bpf/dnswatch.bpf.c -o snoop/out/dnswatch_bpf_probe_core.o
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
/usr/include/bpf/bpf_helper_defs.h:78:83: error: unknown type name '__u64'
static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2;
                                                                                  ^
/usr/include/bpf/bpf_helper_defs.h:102:42: error: unknown type name '__u32'
static long (*bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
                                         ^
/usr/include/bpf/bpf_helper_defs.h:114:14: error: function cannot return function type 'int (void)'
static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5;
             ^
/usr/include/bpf/bpf_helper_defs.h:177:50: error: unknown type name '__u32'
static long (*bpf_trace_printk)(const char *fmt, __u32 fmt_size, ...) = (void *) 6;
                                                 ^
/usr/include/bpf/bpf_helper_defs.h:193:14: error: function cannot return function type 'int (void)'
static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7;
             ^
/usr/include/bpf/bpf_helper_defs.h:206:14: error: function cannot return function type 'int (void)'
static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;
             ^
/usr/include/bpf/bpf_helper_defs.h:227:59: error: unknown type name '__u32'
static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                          ^
/usr/include/bpf/bpf_helper_defs.h:227:91: error: unknown type name '__u32'
static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                                                          ^
/usr/include/bpf/bpf_helper_defs.h:227:102: error: unknown type name '__u64'
static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                                                                     ^
/usr/include/bpf/bpf_helper_defs.h:256:59: error: unknown type name '__u32'
static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                          ^
/usr/include/bpf/bpf_helper_defs.h:256:73: error: unknown type name '__u64'
static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                        ^
/usr/include/bpf/bpf_helper_defs.h:256:85: error: unknown type name '__u64'
static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                                    ^
/usr/include/bpf/bpf_helper_defs.h:256:95: error: unknown type name '__u64'
static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                                              ^
/usr/include/bpf/bpf_helper_defs.h:292:59: error: unknown type name '__u32'
static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                          ^
/usr/include/bpf/bpf_helper_defs.h:292:73: error: unknown type name '__u64'
static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                        ^
/usr/include/bpf/bpf_helper_defs.h:292:85: error: unknown type name '__u64'
static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                                    ^
/usr/include/bpf/bpf_helper_defs.h:292:95: error: unknown type name '__u64'
static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                                              ^
/usr/include/bpf/bpf_helper_defs.h:327:63: error: unknown type name '__u32'
static long (*bpf_tail_call)(void *ctx, void *prog_array_map, __u32 index) = (void *) 12;
                                                              ^
/usr/include/bpf/bpf_helper_defs.h:355:58: error: unknown type name '__u32'
static long (*bpf_clone_redirect)(struct __sk_buff *skb, __u32 ifindex, __u64 flags) = (void *) 13;
                                                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Makefile:7: snoop/out/dnswatch_bpf_probe_core.o] Error 1

l1x avatar May 14 '23 19:05 l1x

Just to confirm please check whether bpf/vmlinux.h is empty, if it is, please apt-get install bpftool , make clean, make

deathowl avatar May 15 '23 10:05 deathowl

@l1x please try pulling latest main, make should warn you about missing bpftool now. Please close the issue if this has been resolved for you

deathowl avatar May 15 '23 16:05 deathowl

> git pull origin  main
From github.com:facebookincubator/dns
 * branch            main       -> FETCH_HEAD
Already up to date.
l1x@deby ~/c/d/dnswatch (main)> make clean
rm -f snoop/out/dnswatch_bpf_probe_core.o
rm -f bpf/vmlinux.h
l1x@deby ~/c/d/dnswatch (main)> make
clang -g -O2 -Wall -fpie -fno-stack-protector -I /usr/include/bpf -target bpf -D__TARGET_ARCH_x86 -I bpf  -c bpf/dnswatch.bpf.c -o snoop/out/dnswatch_bpf_probe_core.o
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
/usr/include/linux/posix_types.h:27:3: error: typedef redefinition with different types ('struct __kernel_fd_set' vs 'struct __kernel_fd_set')
} __kernel_fd_set;
  ^
bpf/vmlinux.h:104571:3: note: previous definition is here
} __kernel_fd_set;
  ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:68:22: error: typedef redefinition with different types ('unsigned int' vs '__kernel_ulong_t' (aka 'unsigned long'))
typedef unsigned int    __kernel_size_t;
                        ^
bpf/vmlinux.h:55:26: note: previous definition is here
typedef __kernel_ulong_t __kernel_size_t;
                         ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:69:14: error: typedef redefinition with different types ('int' vs '__kernel_long_t' (aka 'long'))
typedef int             __kernel_ssize_t;
                        ^
bpf/vmlinux.h:57:25: note: previous definition is here
typedef __kernel_long_t __kernel_ssize_t;
                        ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:70:14: error: typedef redefinition with different types ('int' vs '__kernel_long_t' (aka 'long'))
typedef int             __kernel_ptrdiff_t;
                        ^
bpf/vmlinux.h:69816:25: note: previous definition is here
typedef __kernel_long_t __kernel_ptrdiff_t;
                        ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:81:3: error: typedef redefinition with different types ('struct __kernel_fsid_t' vs 'struct __kernel_fsid_t')
} __kernel_fsid_t;
  ^
bpf/vmlinux.h:19770:3: note: previous definition is here
} __kernel_fsid_t;
  ^
bpf/dnswatch.bpf.c:151:21: warning: unused variable 'inet' [-Wunused-variable]
  struct inet_sock* inet = (struct inet_sock*)sk;
                    ^
bpf/dnswatch.bpf.c:176:21: warning: unused variable 'inet' [-Wunused-variable]
  struct inet_sock* inet = (struct inet_sock*)sk;
                    ^
2 warnings and 5 errors generated.
make: *** [Makefile:9: snoop/out/dnswatch_bpf_probe_core.o] Error 1

l1x avatar May 17 '23 11:05 l1x

I am updating everything to latest greatest and try to figure out what is causing this.

l1x avatar May 17 '23 11:05 l1x

l1x@deby ~/c/d/dnswatch (main) [2]> apt list | egrep 'bpftool|headers' | egrep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bpftool/testing,now 7.1.0+6.1.27-1 amd64 [installed]
linux-headers-6.1.0-8-amd64/now 6.1.25-1 amd64 [installed,local]
linux-headers-6.1.0-8-common/now 6.1.25-1 all [installed,local]
l1x@deby ~/c/d/dnswatch (main)> make clean && make
rm -f snoop/out/dnswatch_bpf_probe_core.o
rm -f bpf/vmlinux.h
bpftool btf dump file /sys/kernel/btf/vmlinux format c > bpf/vmlinux.h
clang -g -O2 -Wall -fpie -fno-stack-protector -I /usr/include/bpf -target bpf -D__TARGET_ARCH_x86 -I bpf  -c bpf/dnswatch.bpf.c -o snoop/out/dnswatch_bpf_probe_core.o
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
/usr/include/linux/posix_types.h:27:3: error: typedef redefinition with different types ('struct __kernel_fd_set' vs 'struct __kernel_fd_set')
} __kernel_fd_set;
  ^
bpf/vmlinux.h:104571:3: note: previous definition is here
} __kernel_fd_set;
  ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:68:22: error: typedef redefinition with different types ('unsigned int' vs '__kernel_ulong_t' (aka 'unsigned long'))
typedef unsigned int    __kernel_size_t;
                        ^
bpf/vmlinux.h:55:26: note: previous definition is here
typedef __kernel_ulong_t __kernel_size_t;
                         ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:69:14: error: typedef redefinition with different types ('int' vs '__kernel_long_t' (aka 'long'))
typedef int             __kernel_ssize_t;
                        ^
bpf/vmlinux.h:57:25: note: previous definition is here
typedef __kernel_long_t __kernel_ssize_t;
                        ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:70:14: error: typedef redefinition with different types ('int' vs '__kernel_long_t' (aka 'long'))
typedef int             __kernel_ptrdiff_t;
                        ^
bpf/vmlinux.h:69816:25: note: previous definition is here
typedef __kernel_long_t __kernel_ptrdiff_t;
                        ^
In file included from bpf/dnswatch.bpf.c:23:
In file included from /usr/include/bpf/bpf_helpers.h:11:
In file included from /usr/include/linux/types.h:9:
In file included from /usr/include/linux/posix_types.h:36:
In file included from /usr/include/asm/posix_types.h:7:
In file included from /usr/include/asm/posix_types_64.h:18:
/usr/include/asm-generic/posix_types.h:81:3: error: typedef redefinition with different types ('struct __kernel_fsid_t' vs 'struct __kernel_fsid_t')
} __kernel_fsid_t;
  ^
bpf/vmlinux.h:19770:3: note: previous definition is here
} __kernel_fsid_t;
  ^
bpf/dnswatch.bpf.c:151:21: warning: unused variable 'inet' [-Wunused-variable]
  struct inet_sock* inet = (struct inet_sock*)sk;
                    ^
bpf/dnswatch.bpf.c:176:21: warning: unused variable 'inet' [-Wunused-variable]
  struct inet_sock* inet = (struct inet_sock*)sk;
                    ^
2 warnings and 5 errors generated.
make: *** [Makefile:9: snoop/out/dnswatch_bpf_probe_core.o] Error 1

l1x avatar May 17 '23 19:05 l1x

So far what I understand is that we have a duplicated definition:

/usr/include/linux/posix_types.h:27:3: error: typedef redefinition with different types ('struct __kernel_fd_set' vs 'struct __kernel_fd_set')
} __kernel_fd_set;
  ^
bpf/vmlinux.h:104571:3: note: previous definition is here
} __kernel_fd_set;

/usr/include/linux/posix_types.h and bpf/vmlinux.h both have the same __kernel_fd_set type.

l1x avatar May 17 '23 19:05 l1x