Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.17-rc2 53 lines 1.1 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2#include <linux/bpf.h> 3#include <bpf/bpf_helpers.h> 4#include <bpf/bpf_endian.h> 5int verdict_max_size = 10000; 6struct { 7 __uint(type, BPF_MAP_TYPE_SOCKMAP); 8 __uint(max_entries, 20); 9 __type(key, int); 10 __type(value, int); 11} sock_map SEC(".maps"); 12 13SEC("sk_skb/stream_verdict") 14int prog_skb_verdict(struct __sk_buff *skb) 15{ 16 __u32 one = 1; 17 18 if (skb->len > verdict_max_size) 19 return SK_PASS; 20 21 return bpf_sk_redirect_map(skb, &sock_map, one, 0); 22} 23 24SEC("sk_skb/stream_verdict") 25int prog_skb_verdict_pass(struct __sk_buff *skb) 26{ 27 return SK_PASS; 28} 29 30SEC("sk_skb/stream_parser") 31int prog_skb_parser(struct __sk_buff *skb) 32{ 33 return skb->len; 34} 35 36SEC("sk_skb/stream_parser") 37int prog_skb_parser_partial(struct __sk_buff *skb) 38{ 39 /* agreement with the test program on a 4-byte size header 40 * and 6-byte body. 41 */ 42 if (skb->len < 4) { 43 /* need more header to determine full length */ 44 return 0; 45 } 46 /* return full length decoded from header. 47 * the return value may be larger than skb->len which 48 * means framework must wait body coming. 49 */ 50 return 10; 51} 52 53char _license[] SEC("license") = "GPL";