Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) #include <uapi/linux/bpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <uapi/linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <uapi/linux/if_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <uapi/linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <bpf/bpf_helpers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include "bpf_legacy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 	__uint(type, BPF_MAP_TYPE_ARRAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 	__type(key, u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 	__type(value, long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 	__uint(max_entries, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) } my_map SEC(".maps");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) SEC("socket1")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int bpf_prog1(struct __sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	long *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	if (skb->pkt_type != PACKET_OUTGOING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	value = bpf_map_lookup_elem(&my_map, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		__sync_fetch_and_add(value, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) char _license[] SEC("license") = "GPL";