samples/bpf: replace BPF programs header with net_shared.h

This commit applies "net_shared.h" to BPF programs to remove existing
network related header dependencies. Also, this commit removes
unnecessary headers before applying "vmlinux.h" to the BPF programs.

Mostly, endianness conversion function has been applied to the source.
In addition, several macros have been defined to fulfill the INET,
TC-related constants.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230115071613.125791-9-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Daniel T. Lee
2023-01-15 16:16:11 +09:00
committed by Alexei Starovoitov
parent e69fe84595
commit c2f4f5593e
4 changed files with 15 additions and 10 deletions

View File

@@ -2,6 +2,9 @@
#ifndef _NET_SHARED_H
#define _NET_SHARED_H
#define AF_INET 2
#define AF_INET6 10
#define ETH_ALEN 6
#define ETH_P_802_3_MIN 0x0600
#define ETH_P_8021Q 0x8100
@@ -11,6 +14,9 @@
#define ETH_P_ARP 0x0806
#define IPPROTO_ICMPV6 58
#define TC_ACT_OK 0
#define TC_ACT_SHOT 2
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define bpf_ntohs(x) __builtin_bswap16(x)