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 master 40 lines 830 B 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> 5 6int cork_byte; 7int push_start; 8int push_end; 9int apply_bytes; 10int pop_start; 11int pop_end; 12 13struct { 14 __uint(type, BPF_MAP_TYPE_SOCKMAP); 15 __uint(max_entries, 20); 16 __type(key, int); 17 __type(value, int); 18} sock_map SEC(".maps"); 19 20SEC("sk_msg") 21int prog_sk_policy(struct sk_msg_md *msg) 22{ 23 if (cork_byte > 0) 24 bpf_msg_cork_bytes(msg, cork_byte); 25 if (push_start > 0 && push_end > 0) 26 bpf_msg_push_data(msg, push_start, push_end, 0); 27 if (pop_start >= 0 && pop_end > 0) 28 bpf_msg_pop_data(msg, pop_start, pop_end, 0); 29 30 return SK_PASS; 31} 32 33SEC("sk_msg") 34int prog_sk_policy_redir(struct sk_msg_md *msg) 35{ 36 int two = 2; 37 38 bpf_msg_apply_bytes(msg, apply_bytes); 39 return bpf_msg_redirect_map(msg, &sock_map, two, 0); 40}