This little patch is a follow-up to: https://lore.kernel.org/bpf/20240507095011.15867-1-jose.marchesi@oracle.com/T/#u The temporary workaround of passing -DBPF_NO_PRESERVE_ACCESS_INDEX when building with GCC triggers a redefinition preprocessor error when building progs/skb_pkt_end.c. This patch adds a guard to avoid redefinition. Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com> Cc: david.faust@oracle.com Cc: cupertino.miranda@oracle.com Cc: Eduard Zingerman <eddyz87@gmail.com> Cc: Yonghong Song <yonghong.song@linux.dev> Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20240508110332.17332-1-jose.marchesi@oracle.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
55 lines
1 KiB
C
55 lines
1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
|
|
#define BPF_NO_PRESERVE_ACCESS_INDEX
|
|
#endif
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_core_read.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
#define INLINE __always_inline
|
|
|
|
#define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
|
|
|
|
#define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
|
|
|
|
static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
|
|
{
|
|
struct iphdr *ip = NULL;
|
|
struct ethhdr *eth;
|
|
|
|
if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
|
|
goto out;
|
|
|
|
eth = (void *)(long)skb->data;
|
|
ip = (void *)(eth + 1);
|
|
|
|
out:
|
|
return ip;
|
|
}
|
|
|
|
SEC("tc")
|
|
int main_prog(struct __sk_buff *skb)
|
|
{
|
|
struct iphdr *ip = NULL;
|
|
struct tcphdr *tcp;
|
|
__u8 proto = 0;
|
|
|
|
if (!(ip = get_iphdr(skb)))
|
|
goto out;
|
|
|
|
proto = ip->protocol;
|
|
|
|
if (proto != IPPROTO_TCP)
|
|
goto out;
|
|
|
|
tcp = (void*)(ip + 1);
|
|
if (tcp->dest != 0)
|
|
goto out;
|
|
if (!tcp)
|
|
goto out;
|
|
|
|
return tcp->urg_ptr;
|
|
out:
|
|
return -1;
|
|
}
|
|
char _license[] SEC("license") = "GPL";
|