mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-10-28 19:24:04 +08:00
* Make tutorials 50-53 safer to operate * Make pacer conflict recovery interface-safe * Keep tutorial prose on the user path * Allow focused excerpts for long user-space loaders --------- Co-authored-by: LinuxDev9002 <i@littlefisher.me>
38 lines
685 B
C
38 lines
685 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/bpf.h>
|
|
#include <bpf/bpf_endian.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
#ifndef TCX_NEXT
|
|
#define TCX_NEXT -1
|
|
#endif
|
|
|
|
#ifndef TCX_PASS
|
|
#define TCX_PASS 0
|
|
#endif
|
|
|
|
char LICENSE[] SEC("license") = "GPL";
|
|
|
|
__u64 stats_hits;
|
|
__u64 classifier_hits;
|
|
__u32 last_len;
|
|
__u16 last_protocol;
|
|
__u32 last_ifindex;
|
|
|
|
SEC("tcx/ingress")
|
|
int tcx_stats(struct __sk_buff *skb)
|
|
{
|
|
__sync_fetch_and_add(&stats_hits, 1);
|
|
last_len = skb->len;
|
|
last_protocol = bpf_ntohs(skb->protocol);
|
|
last_ifindex = skb->ifindex;
|
|
return TCX_NEXT;
|
|
}
|
|
|
|
SEC("tcx/ingress")
|
|
int tcx_classifier(struct __sk_buff *skb)
|
|
{
|
|
__sync_fetch_and_add(&classifier_hits, 1);
|
|
return TCX_PASS;
|
|
}
|