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