mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 06:31:49 +00:00
bpf: sockmap, remove samples program
The BPF sample sockmap is redundant now that equivelant tests exist in the BPF selftests. Lets remove this sample and only keep the selftest version that will be run as part of the selftest suite. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
16962b2404
commit
2e04eb1dd1
@ -1,75 +0,0 @@
|
||||
# List of programs to build
|
||||
hostprogs-y := sockmap
|
||||
|
||||
# Libbpf dependencies
|
||||
LIBBPF := ../../tools/lib/bpf/bpf.o ../../tools/lib/bpf/nlattr.o
|
||||
|
||||
HOSTCFLAGS += -I$(objtree)/usr/include
|
||||
HOSTCFLAGS += -I$(srctree)/tools/lib/
|
||||
HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
|
||||
HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
|
||||
HOSTCFLAGS += -I$(srctree)/tools/perf
|
||||
|
||||
sockmap-objs := ../bpf/bpf_load.o $(LIBBPF) sockmap_user.o
|
||||
|
||||
# Tell kbuild to always build the programs
|
||||
always := $(hostprogs-y)
|
||||
always += sockmap_kern.o
|
||||
|
||||
HOSTLOADLIBES_sockmap += -lelf -lpthread
|
||||
|
||||
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
|
||||
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
|
||||
LLC ?= llc
|
||||
CLANG ?= clang
|
||||
|
||||
# Trick to allow make to be run from this directory
|
||||
all:
|
||||
$(MAKE) -C ../../ $(CURDIR)/
|
||||
|
||||
clean:
|
||||
$(MAKE) -C ../../ M=$(CURDIR) clean
|
||||
@rm -f *~
|
||||
|
||||
$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
|
||||
$(call if_changed_dep,cc_s_c)
|
||||
|
||||
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
|
||||
$(call filechk,offsets,__SYSCALL_NRS_H__)
|
||||
|
||||
clean-files += syscall_nrs.h
|
||||
|
||||
FORCE:
|
||||
|
||||
|
||||
# Verify LLVM compiler tools are available and bpf target is supported by llc
|
||||
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
|
||||
|
||||
verify_cmds: $(CLANG) $(LLC)
|
||||
@for TOOL in $^ ; do \
|
||||
if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
|
||||
echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
|
||||
exit 1; \
|
||||
else true; fi; \
|
||||
done
|
||||
|
||||
verify_target_bpf: verify_cmds
|
||||
@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
|
||||
echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
|
||||
echo " NOTICE: LLVM version >= 3.7.1 required" ;\
|
||||
exit 2; \
|
||||
else true; fi
|
||||
|
||||
$(src)/*.c: verify_target_bpf
|
||||
|
||||
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
|
||||
# But, there is no easy way to fix it, so just exclude it since it is
|
||||
# useless for BPF samples.
|
||||
$(obj)/%.o: $(src)/%.c
|
||||
$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
|
||||
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
|
||||
-Wno-compare-distinct-pointer-types \
|
||||
-Wno-gnu-variable-sized-type-not-at-end \
|
||||
-Wno-address-of-packed-member -Wno-tautological-compare \
|
||||
-Wno-unknown-warning-option \
|
||||
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
|
@ -1,341 +0,0 @@
|
||||
/* Copyright (c) 2017 Covalent IO, Inc. http://covalent.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*/
|
||||
#include <uapi/linux/bpf.h>
|
||||
#include <uapi/linux/if_ether.h>
|
||||
#include <uapi/linux/if_packet.h>
|
||||
#include <uapi/linux/ip.h>
|
||||
#include "../../tools/testing/selftests/bpf/bpf_helpers.h"
|
||||
#include "../../tools/testing/selftests/bpf/bpf_endian.h"
|
||||
|
||||
/* Sockmap sample program connects a client and a backend together
|
||||
* using cgroups.
|
||||
*
|
||||
* client:X <---> frontend:80 client:X <---> backend:80
|
||||
*
|
||||
* For simplicity we hard code values here and bind 1:1. The hard
|
||||
* coded values are part of the setup in sockmap.sh script that
|
||||
* is associated with this BPF program.
|
||||
*
|
||||
* The bpf_printk is verbose and prints information as connections
|
||||
* are established and verdicts are decided.
|
||||
*/
|
||||
|
||||
#define bpf_printk(fmt, ...) \
|
||||
({ \
|
||||
char ____fmt[] = fmt; \
|
||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
||||
##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_map = {
|
||||
.type = BPF_MAP_TYPE_SOCKMAP,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 20,
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_map_txmsg = {
|
||||
.type = BPF_MAP_TYPE_SOCKMAP,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 20,
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_map_redir = {
|
||||
.type = BPF_MAP_TYPE_SOCKMAP,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 20,
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_apply_bytes = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 1
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_cork_bytes = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 1
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_pull_bytes = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 2
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_redir_flags = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 1
|
||||
};
|
||||
|
||||
struct bpf_map_def SEC("maps") sock_skb_opts = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(int),
|
||||
.value_size = sizeof(int),
|
||||
.max_entries = 1
|
||||
};
|
||||
|
||||
SEC("sk_skb1")
|
||||
int bpf_prog1(struct __sk_buff *skb)
|
||||
{
|
||||
return skb->len;
|
||||
}
|
||||
|
||||
SEC("sk_skb2")
|
||||
int bpf_prog2(struct __sk_buff *skb)
|
||||
{
|
||||
__u32 lport = skb->local_port;
|
||||
__u32 rport = skb->remote_port;
|
||||
int len, *f, ret, zero = 0;
|
||||
__u64 flags = 0;
|
||||
|
||||
if (lport == 10000)
|
||||
ret = 10;
|
||||
else
|
||||
ret = 1;
|
||||
|
||||
len = (__u32)skb->data_end - (__u32)skb->data;
|
||||
f = bpf_map_lookup_elem(&sock_skb_opts, &zero);
|
||||
if (f && *f) {
|
||||
ret = 3;
|
||||
flags = *f;
|
||||
}
|
||||
|
||||
bpf_printk("sk_skb2: redirect(%iB) flags=%i\n",
|
||||
len, flags);
|
||||
return bpf_sk_redirect_map(skb, &sock_map, ret, flags);
|
||||
}
|
||||
|
||||
SEC("sockops")
|
||||
int bpf_sockmap(struct bpf_sock_ops *skops)
|
||||
{
|
||||
__u32 lport, rport;
|
||||
int op, err = 0, index, key, ret;
|
||||
|
||||
|
||||
op = (int) skops->op;
|
||||
|
||||
switch (op) {
|
||||
case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
|
||||
lport = skops->local_port;
|
||||
rport = skops->remote_port;
|
||||
|
||||
if (lport == 10000) {
|
||||
ret = 1;
|
||||
err = bpf_sock_map_update(skops, &sock_map, &ret,
|
||||
BPF_NOEXIST);
|
||||
bpf_printk("passive(%i -> %i) map ctx update err: %d\n",
|
||||
lport, bpf_ntohl(rport), err);
|
||||
}
|
||||
break;
|
||||
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
|
||||
lport = skops->local_port;
|
||||
rport = skops->remote_port;
|
||||
|
||||
if (bpf_ntohl(rport) == 10001) {
|
||||
ret = 10;
|
||||
err = bpf_sock_map_update(skops, &sock_map, &ret,
|
||||
BPF_NOEXIST);
|
||||
bpf_printk("active(%i -> %i) map ctx update err: %d\n",
|
||||
lport, bpf_ntohl(rport), err);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("sk_msg1")
|
||||
int bpf_prog4(struct sk_msg_md *msg)
|
||||
{
|
||||
int *bytes, zero = 0, one = 1;
|
||||
int *start, *end;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_apply_bytes(msg, *bytes);
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_cork_bytes(msg, *bytes);
|
||||
start = bpf_map_lookup_elem(&sock_pull_bytes, &zero);
|
||||
end = bpf_map_lookup_elem(&sock_pull_bytes, &one);
|
||||
if (start && end)
|
||||
bpf_msg_pull_data(msg, *start, *end, 0);
|
||||
return SK_PASS;
|
||||
}
|
||||
|
||||
SEC("sk_msg2")
|
||||
int bpf_prog5(struct sk_msg_md *msg)
|
||||
{
|
||||
int err1 = -1, err2 = -1, zero = 0, one = 1;
|
||||
int *bytes, *start, *end, len1, len2;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes)
|
||||
err1 = bpf_msg_apply_bytes(msg, *bytes);
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes)
|
||||
err2 = bpf_msg_cork_bytes(msg, *bytes);
|
||||
len1 = (__u64)msg->data_end - (__u64)msg->data;
|
||||
start = bpf_map_lookup_elem(&sock_pull_bytes, &zero);
|
||||
end = bpf_map_lookup_elem(&sock_pull_bytes, &one);
|
||||
if (start && end) {
|
||||
int err;
|
||||
|
||||
bpf_printk("sk_msg2: pull(%i:%i)\n",
|
||||
start ? *start : 0, end ? *end : 0);
|
||||
err = bpf_msg_pull_data(msg, *start, *end, 0);
|
||||
if (err)
|
||||
bpf_printk("sk_msg2: pull_data err %i\n",
|
||||
err);
|
||||
len2 = (__u64)msg->data_end - (__u64)msg->data;
|
||||
bpf_printk("sk_msg2: length update %i->%i\n",
|
||||
len1, len2);
|
||||
}
|
||||
bpf_printk("sk_msg2: data length %i err1 %i err2 %i\n",
|
||||
len1, err1, err2);
|
||||
return SK_PASS;
|
||||
}
|
||||
|
||||
SEC("sk_msg3")
|
||||
int bpf_prog6(struct sk_msg_md *msg)
|
||||
{
|
||||
int *bytes, zero = 0, one = 1, key = 0;
|
||||
int *start, *end, *f;
|
||||
__u64 flags = 0;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_apply_bytes(msg, *bytes);
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_cork_bytes(msg, *bytes);
|
||||
start = bpf_map_lookup_elem(&sock_pull_bytes, &zero);
|
||||
end = bpf_map_lookup_elem(&sock_pull_bytes, &one);
|
||||
if (start && end)
|
||||
bpf_msg_pull_data(msg, *start, *end, 0);
|
||||
f = bpf_map_lookup_elem(&sock_redir_flags, &zero);
|
||||
if (f && *f) {
|
||||
key = 2;
|
||||
flags = *f;
|
||||
}
|
||||
return bpf_msg_redirect_map(msg, &sock_map_redir, key, flags);
|
||||
}
|
||||
|
||||
SEC("sk_msg4")
|
||||
int bpf_prog7(struct sk_msg_md *msg)
|
||||
{
|
||||
int err1 = 0, err2 = 0, zero = 0, one = 1, key = 0;
|
||||
int *f, *bytes, *start, *end, len1, len2;
|
||||
__u64 flags = 0;
|
||||
|
||||
int err;
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes)
|
||||
err1 = bpf_msg_apply_bytes(msg, *bytes);
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes)
|
||||
err2 = bpf_msg_cork_bytes(msg, *bytes);
|
||||
len1 = (__u64)msg->data_end - (__u64)msg->data;
|
||||
start = bpf_map_lookup_elem(&sock_pull_bytes, &zero);
|
||||
end = bpf_map_lookup_elem(&sock_pull_bytes, &one);
|
||||
if (start && end) {
|
||||
|
||||
bpf_printk("sk_msg2: pull(%i:%i)\n",
|
||||
start ? *start : 0, end ? *end : 0);
|
||||
err = bpf_msg_pull_data(msg, *start, *end, 0);
|
||||
if (err)
|
||||
bpf_printk("sk_msg2: pull_data err %i\n",
|
||||
err);
|
||||
len2 = (__u64)msg->data_end - (__u64)msg->data;
|
||||
bpf_printk("sk_msg2: length update %i->%i\n",
|
||||
len1, len2);
|
||||
}
|
||||
f = bpf_map_lookup_elem(&sock_redir_flags, &zero);
|
||||
if (f && *f) {
|
||||
key = 2;
|
||||
flags = *f;
|
||||
}
|
||||
bpf_printk("sk_msg3: redirect(%iB) flags=%i err=%i\n",
|
||||
len1, flags, err1 ? err1 : err2);
|
||||
err = bpf_msg_redirect_map(msg, &sock_map_redir, key, flags);
|
||||
bpf_printk("sk_msg3: err %i\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
SEC("sk_msg5")
|
||||
int bpf_prog8(struct sk_msg_md *msg)
|
||||
{
|
||||
void *data_end = (void *)(long) msg->data_end;
|
||||
void *data = (void *)(long) msg->data;
|
||||
int ret = 0, *bytes, zero = 0;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes) {
|
||||
ret = bpf_msg_apply_bytes(msg, *bytes);
|
||||
if (ret)
|
||||
return SK_DROP;
|
||||
} else {
|
||||
return SK_DROP;
|
||||
}
|
||||
return SK_PASS;
|
||||
}
|
||||
SEC("sk_msg6")
|
||||
int bpf_prog9(struct sk_msg_md *msg)
|
||||
{
|
||||
void *data_end = (void *)(long) msg->data_end;
|
||||
void *data = (void *)(long) msg->data;
|
||||
int ret = 0, *bytes, zero = 0;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes) {
|
||||
if (((__u64)data_end - (__u64)data) >= *bytes)
|
||||
return SK_PASS;
|
||||
ret = bpf_msg_cork_bytes(msg, *bytes);
|
||||
if (ret)
|
||||
return SK_DROP;
|
||||
}
|
||||
return SK_PASS;
|
||||
}
|
||||
|
||||
SEC("sk_msg7")
|
||||
int bpf_prog10(struct sk_msg_md *msg)
|
||||
{
|
||||
int *bytes, zero = 0, one = 1;
|
||||
int *start, *end;
|
||||
|
||||
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_apply_bytes(msg, *bytes);
|
||||
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
|
||||
if (bytes)
|
||||
bpf_msg_cork_bytes(msg, *bytes);
|
||||
start = bpf_map_lookup_elem(&sock_pull_bytes, &zero);
|
||||
end = bpf_map_lookup_elem(&sock_pull_bytes, &one);
|
||||
if (start && end)
|
||||
bpf_msg_pull_data(msg, *start, *end, 0);
|
||||
|
||||
return SK_DROP;
|
||||
}
|
||||
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
@ -1,488 +0,0 @@
|
||||
#Test a bunch of positive cases to verify basic functionality
|
||||
for prog in "--txmsg_redir --txmsg_skb" "--txmsg_redir --txmsg_ingress" "--txmsg" "--txmsg_redir" "--txmsg_redir --txmsg_ingress" "--txmsg_drop"; do
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
for r in 1 10 100; do
|
||||
for i in 1 10 100; do
|
||||
for l in 1 10 100; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
#Test max iov
|
||||
t="sendmsg"
|
||||
r=1
|
||||
i=1024
|
||||
l=1
|
||||
prog="--txmsg"
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
prog="--txmsg_redir"
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
|
||||
# Test max iov with 1k send
|
||||
|
||||
t="sendmsg"
|
||||
r=1
|
||||
i=1024
|
||||
l=1024
|
||||
prog="--txmsg"
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
prog="--txmsg_redir"
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
# Test apply with 1B
|
||||
r=1
|
||||
i=1024
|
||||
l=1024
|
||||
prog="--txmsg_apply 1"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply with larger value than send
|
||||
r=1
|
||||
i=8
|
||||
l=1024
|
||||
prog="--txmsg_apply 2048"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply with apply that never reaches limit
|
||||
r=1024
|
||||
i=1
|
||||
l=1
|
||||
prog="--txmsg_apply 2048"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply and redirect with 1B
|
||||
r=1
|
||||
i=1024
|
||||
l=1024
|
||||
prog="--txmsg_redir --txmsg_apply 1"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
prog="--txmsg_redir --txmsg_apply 1 --txmsg_ingress"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
prog="--txmsg_redir --txmsg_apply 1 --txmsg_skb"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
# Test apply and redirect with larger value than send
|
||||
r=1
|
||||
i=8
|
||||
l=1024
|
||||
prog="--txmsg_redir --txmsg_apply 2048"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
prog="--txmsg_redir --txmsg_apply 2048 --txmsg_ingress"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
prog="--txmsg_redir --txmsg_apply 2048 --txmsg_skb"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
# Test apply and redirect with apply that never reaches limit
|
||||
r=1024
|
||||
i=1
|
||||
l=1
|
||||
prog="--txmsg_apply 2048"
|
||||
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with 1B not really useful but test it anyways
|
||||
r=1
|
||||
i=1024
|
||||
l=1024
|
||||
prog="--txmsg_cork 1"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with a more reasonable 100B
|
||||
r=1
|
||||
i=1000
|
||||
l=1000
|
||||
prog="--txmsg_cork 100"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with larger value than send
|
||||
r=1
|
||||
i=8
|
||||
l=1024
|
||||
prog="--txmsg_cork 2048"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with cork that never reaches limit
|
||||
r=1024
|
||||
i=1
|
||||
l=1
|
||||
prog="--txmsg_cork 2048"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
r=1
|
||||
i=1024
|
||||
l=1024
|
||||
prog="--txmsg_redir --txmsg_cork 1"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with a more reasonable 100B
|
||||
r=1
|
||||
i=1000
|
||||
l=1000
|
||||
prog="--txmsg_redir --txmsg_cork 100"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with larger value than send
|
||||
r=1
|
||||
i=8
|
||||
l=1024
|
||||
prog="--txmsg_redir --txmsg_cork 2048"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test cork with cork that never reaches limit
|
||||
r=1024
|
||||
i=1
|
||||
l=1
|
||||
prog="--txmsg_cork 2048"
|
||||
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
# mix and match cork and apply not really useful but valid programs
|
||||
|
||||
# Test apply < cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_apply 10 --txmsg_cork 100"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Try again with larger sizes so we hit overflow case
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_apply 4096 --txmsg_cork 8096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply > cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_apply 100 --txmsg_cork 10"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Again with larger sizes so we hit overflow cases
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_apply 8096 --txmsg_cork 4096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
# Test apply = cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_apply 10 --txmsg_cork 10"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_apply 4096 --txmsg_cork 4096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply < cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_redir --txmsg_apply 10 --txmsg_cork 100"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Try again with larger sizes so we hit overflow case
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_redir --txmsg_apply 4096 --txmsg_cork 8096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test apply > cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_redir --txmsg_apply 100 --txmsg_cork 10"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Again with larger sizes so we hit overflow cases
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_redir --txmsg_apply 8096 --txmsg_cork 4096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
# Test apply = cork
|
||||
r=100
|
||||
i=1
|
||||
l=5
|
||||
prog="--txmsg_redir --txmsg_apply 10 --txmsg_cork 10"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
r=100
|
||||
i=1000
|
||||
l=2048
|
||||
prog="--txmsg_redir --txmsg_apply 4096 --txmsg_cork 4096"
|
||||
for t in "sendpage" "sendmsg"; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Tests for bpf_msg_pull_data()
|
||||
for i in `seq 99 100 1600`; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 0 --txmsg_end $i --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
for i in `seq 199 100 1600`; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 100 --txmsg_end $i --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 1500 --txmsg_end 1600 --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 1111 --txmsg_end 1112 --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 1111 --txmsg_end 0 --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 0 --txmsg_end 1601 --txmsg_cork 1600"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t sendpage -r 16 -i 1 -l 100 \
|
||||
--txmsg --txmsg_start 0 --txmsg_end 1601 --txmsg_cork 1602"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
|
||||
# Run through gamut again with start and end
|
||||
for prog in "--txmsg" "--txmsg_redir" "--txmsg_drop"; do
|
||||
for t in "sendmsg" "sendpage"; do
|
||||
for r in 1 10 100; do
|
||||
for i in 1 10 100; do
|
||||
for l in 1 10 100; do
|
||||
TEST="./sockmap --cgroup /mnt/cgroup2/ -t $t -r $r -i $i -l $l $prog --txmsg_start 1 --txmsg_end 2"
|
||||
echo $TEST
|
||||
$TEST
|
||||
sleep 2
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
# Some specific tests to cover specific code paths
|
||||
./sockmap --cgroup /mnt/cgroup2/ -t sendpage \
|
||||
-r 5 -i 1 -l 1 --txmsg_redir --txmsg_cork 5 --txmsg_apply 3
|
||||
./sockmap --cgroup /mnt/cgroup2/ -t sendmsg \
|
||||
-r 5 -i 1 -l 1 --txmsg_redir --txmsg_cork 5 --txmsg_apply 3
|
||||
./sockmap --cgroup /mnt/cgroup2/ -t sendpage \
|
||||
-r 5 -i 1 -l 1 --txmsg_redir --txmsg_cork 5 --txmsg_apply 5
|
||||
./sockmap --cgroup /mnt/cgroup2/ -t sendmsg \
|
||||
-r 5 -i 1 -l 1 --txmsg_redir --txmsg_cork 5 --txmsg_apply 5
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user