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) /* Copyright (c) 2016 Facebook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * modify it under the terms of version 2 of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * License as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #define KBUILD_MODNAME "foo"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <uapi/linux/bpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <bpf/bpf_helpers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "bpf_legacy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define DEFAULT_PKTGEN_UDP_PORT	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define IP_MF			0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define IP_OFFSET		0x1FFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static inline int ip_is_fragment(struct __sk_buff *ctx, __u64 nhoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	return load_half(ctx, nhoff + offsetof(struct iphdr, frag_off))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 		& (IP_MF | IP_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) SEC("ldabs")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int handle_ingress(struct __sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	__u64 troff = ETH_HLEN + sizeof(struct iphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (load_half(skb, offsetof(struct ethhdr, h_proto)) != ETH_P_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	if (load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol)) != IPPROTO_UDP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	    load_byte(skb, ETH_HLEN) != 0x45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	if (ip_is_fragment(skb, ETH_HLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (load_half(skb, troff + offsetof(struct udphdr, dest)) == DEFAULT_PKTGEN_UDP_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		return TC_ACT_SHOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) char _license[] SEC("license") = "GPL";