File: test_sockmap_ktls.c

package info (click to toggle)
linux 6.16.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,724,504 kB
  • sloc: ansic: 26,560,901; asm: 271,339; sh: 144,033; python: 72,469; makefile: 57,129; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (36 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

int cork_byte;
int push_start;
int push_end;
int apply_bytes;

struct {
	__uint(type, BPF_MAP_TYPE_SOCKMAP);
	__uint(max_entries, 20);
	__type(key, int);
	__type(value, int);
} sock_map SEC(".maps");

SEC("sk_msg")
int prog_sk_policy(struct sk_msg_md *msg)
{
	if (cork_byte > 0)
		bpf_msg_cork_bytes(msg, cork_byte);
	if (push_start > 0 && push_end > 0)
		bpf_msg_push_data(msg, push_start, push_end, 0);

	return SK_PASS;
}

SEC("sk_msg")
int prog_sk_policy_redir(struct sk_msg_md *msg)
{
	int two = 2;

	bpf_msg_apply_bytes(msg, apply_bytes);
	return bpf_msg_redirect_map(msg, &sock_map, two, 0);
}