samples/bpf: split common macros to net_shared.h
authorDaniel T. Lee <danieltimlee@gmail.com>
Sun, 15 Jan 2023 07:16:10 +0000 (16:16 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 15 Jan 2023 21:32:45 +0000 (13:32 -0800)
commite69fe8459552f112d7327dff87953d40202c61f1
treecd49bb327ebbe0899dba2e60951c0a231f4bfa16
parenta1f93c8fb0a836b6c891e51729f6cb98a1da47ba
samples/bpf: split common macros to net_shared.h

Currently, many programs under sample/bpf often include individual
macros by directly including the header under "linux/" rather than
using the "vmlinux.h" header.

However, there are some problems with migrating to "vmlinux.h" because
there is no definition for utility functions such as endianness
conversion (ntohs/htons). Fortunately, the xdp_sample program already
has a function that can be replaced to solve this problem.

Therefore, this commit attempts to separate these functions into a file
called net_shared.h to make them universally available. Additionally,
this file includes network-related macros that are not defined in
"vmlinux.h". (inspired by 'selftests' bpf_tracing_net.h)

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230115071613.125791-8-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
samples/bpf/net_shared.h [new file with mode: 0644]
samples/bpf/xdp_sample.bpf.h