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 6 int cork_byte; 7 int push_start; 8 int push_end; 9 int apply_bytes; 10 int pop_start; 11 int pop_end; 12 13 struct { 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 20 SEC("sk_msg") 21 int 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 33 SEC("sk_msg") 34 int 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 } 41