Linux Audio

Check our new training course

Loading...
v6.2
 1#include <linux/bpf.h>
 2#include <bpf/bpf_helpers.h>
 3#include <bpf/bpf_endian.h>
 
 4
 5struct {
 6	__uint(type, BPF_MAP_TYPE_SOCKMAP);
 7	__uint(max_entries, 20);
 8	__type(key, int);
 9	__type(value, int);
10} sock_map_rx SEC(".maps");
11
12struct {
13	__uint(type, BPF_MAP_TYPE_SOCKMAP);
14	__uint(max_entries, 20);
15	__type(key, int);
16	__type(value, int);
17} sock_map_tx SEC(".maps");
18
19struct {
20	__uint(type, BPF_MAP_TYPE_SOCKMAP);
21	__uint(max_entries, 20);
22	__type(key, int);
23	__type(value, int);
24} sock_map_msg SEC(".maps");
25
26struct {
27	__uint(type, BPF_MAP_TYPE_ARRAY);
28	__uint(max_entries, 20);
29	__type(key, int);
30	__type(value, int);
31} sock_map_break SEC(".maps");
32
33SEC("sk_skb2")
34int bpf_prog2(struct __sk_buff *skb)
35{
36	void *data_end = (void *)(long) skb->data_end;
37	void *data = (void *)(long) skb->data;
38	__u32 lport = skb->local_port;
39	__u32 rport = skb->remote_port;
40	__u8 *d = data;
41	__u8 sk, map;
 
 
 
42
43	if (data + 8 > data_end)
44		return SK_DROP;
45
46	map = d[0];
47	sk = d[1];
48
49	d[0] = 0xd;
50	d[1] = 0xe;
51	d[2] = 0xa;
52	d[3] = 0xd;
53	d[4] = 0xb;
54	d[5] = 0xe;
55	d[6] = 0xe;
56	d[7] = 0xf;
57
58	if (!map)
59		return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
60	return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
61}
62
63char _license[] SEC("license") = "GPL";
v6.9.4
 1#include <linux/bpf.h>
 2#include <bpf/bpf_helpers.h>
 3#include <bpf/bpf_endian.h>
 4#include "bpf_misc.h"
 5
 6struct {
 7	__uint(type, BPF_MAP_TYPE_SOCKMAP);
 8	__uint(max_entries, 20);
 9	__type(key, int);
10	__type(value, int);
11} sock_map_rx SEC(".maps");
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_tx SEC(".maps");
19
20struct {
21	__uint(type, BPF_MAP_TYPE_SOCKMAP);
22	__uint(max_entries, 20);
23	__type(key, int);
24	__type(value, int);
25} sock_map_msg SEC(".maps");
26
27struct {
28	__uint(type, BPF_MAP_TYPE_ARRAY);
29	__uint(max_entries, 20);
30	__type(key, int);
31	__type(value, int);
32} sock_map_break SEC(".maps");
33
34SEC("sk_skb2")
35int bpf_prog2(struct __sk_buff *skb)
36{
37	void *data_end = (void *)(long) skb->data_end;
38	void *data = (void *)(long) skb->data;
39	__u32 lport = skb->local_port;
40	__u32 rport = skb->remote_port;
41	__u8 *d = data;
42	__u8 sk, map;
43
44	__sink(lport);
45	__sink(rport);
46
47	if (data + 8 > data_end)
48		return SK_DROP;
49
50	map = d[0];
51	sk = d[1];
52
53	d[0] = 0xd;
54	d[1] = 0xe;
55	d[2] = 0xa;
56	d[3] = 0xd;
57	d[4] = 0xb;
58	d[5] = 0xe;
59	d[6] = 0xe;
60	d[7] = 0xf;
61
62	if (!map)
63		return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
64	return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
65}
66
67char _license[] SEC("license") = "GPL";