mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-09 23:34:42 +08:00
c22bdd2825
Convert all SEC("classifier*") uses to a new and strict SEC("tc") section name. In reference_tracking selftests switch from ambiguous searching by program title (section name) to non-ambiguous searching by name in some selftests, getting closer to completely removing bpf_object__find_program_by_title(). Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210928161946.2512801-4-andrii@kernel.org
54 lines
989 B
C
54 lines
989 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#define BPF_NO_PRESERVE_ACCESS_INDEX
|
|
#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";
|