|
@@ -464,15 +464,17 @@ static void test_devmap(int task, void *data)
|
|
|
#include <linux/err.h>
|
|
|
#define SOCKMAP_PARSE_PROG "./sockmap_parse_prog.o"
|
|
|
#define SOCKMAP_VERDICT_PROG "./sockmap_verdict_prog.o"
|
|
|
+#define SOCKMAP_TCP_MSG_PROG "./sockmap_tcp_msg_prog.o"
|
|
|
static void test_sockmap(int tasks, void *data)
|
|
|
{
|
|
|
- int one = 1, map_fd_rx = 0, map_fd_tx = 0, map_fd_break, s, sc, rc;
|
|
|
- struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break;
|
|
|
+ struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_msg, *bpf_map_break;
|
|
|
+ int map_fd_msg = 0, map_fd_rx = 0, map_fd_tx = 0, map_fd_break;
|
|
|
int ports[] = {50200, 50201, 50202, 50204};
|
|
|
int err, i, fd, udp, sfd[6] = {0xdeadbeef};
|
|
|
u8 buf[20] = {0x0, 0x5, 0x3, 0x2, 0x1, 0x0};
|
|
|
- int parse_prog, verdict_prog;
|
|
|
+ int parse_prog, verdict_prog, msg_prog;
|
|
|
struct sockaddr_in addr;
|
|
|
+ int one = 1, s, sc, rc;
|
|
|
struct bpf_object *obj;
|
|
|
struct timeval to;
|
|
|
__u32 key, value;
|
|
@@ -584,6 +586,12 @@ static void test_sockmap(int tasks, void *data)
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
|
+ err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0);
|
|
|
+ if (!err) {
|
|
|
+ printf("Failed invalid msg verdict prog attach\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0);
|
|
|
if (!err) {
|
|
|
printf("Failed unknown prog attach\n");
|
|
@@ -602,6 +610,12 @@ static void test_sockmap(int tasks, void *data)
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
|
+ err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);
|
|
|
+ if (err) {
|
|
|
+ printf("Failed empty msg verdict prog detach\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE);
|
|
|
if (!err) {
|
|
|
printf("Detach invalid prog successful\n");
|
|
@@ -616,6 +630,13 @@ static void test_sockmap(int tasks, void *data)
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
|
+ err = bpf_prog_load(SOCKMAP_TCP_MSG_PROG,
|
|
|
+ BPF_PROG_TYPE_SK_MSG, &obj, &msg_prog);
|
|
|
+ if (err) {
|
|
|
+ printf("Failed to load SK_SKB msg prog\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
err = bpf_prog_load(SOCKMAP_VERDICT_PROG,
|
|
|
BPF_PROG_TYPE_SK_SKB, &obj, &verdict_prog);
|
|
|
if (err) {
|
|
@@ -631,7 +652,7 @@ static void test_sockmap(int tasks, void *data)
|
|
|
|
|
|
map_fd_rx = bpf_map__fd(bpf_map_rx);
|
|
|
if (map_fd_rx < 0) {
|
|
|
- printf("Failed to get map fd\n");
|
|
|
+ printf("Failed to get map rx fd\n");
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
@@ -647,6 +668,18 @@ static void test_sockmap(int tasks, void *data)
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
|
+ bpf_map_msg = bpf_object__find_map_by_name(obj, "sock_map_msg");
|
|
|
+ if (IS_ERR(bpf_map_msg)) {
|
|
|
+ printf("Failed to load map msg from msg_verdict prog\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
+ map_fd_msg = bpf_map__fd(bpf_map_msg);
|
|
|
+ if (map_fd_msg < 0) {
|
|
|
+ printf("Failed to get map msg fd\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
bpf_map_break = bpf_object__find_map_by_name(obj, "sock_map_break");
|
|
|
if (IS_ERR(bpf_map_break)) {
|
|
|
printf("Failed to load map tx from verdict prog\n");
|
|
@@ -680,6 +713,12 @@ static void test_sockmap(int tasks, void *data)
|
|
|
goto out_sockmap;
|
|
|
}
|
|
|
|
|
|
+ err = bpf_prog_attach(msg_prog, map_fd_msg, BPF_SK_MSG_VERDICT, 0);
|
|
|
+ if (err) {
|
|
|
+ printf("Failed msg verdict bpf prog attach\n");
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
err = bpf_prog_attach(verdict_prog, map_fd_rx,
|
|
|
__MAX_BPF_ATTACH_TYPE, 0);
|
|
|
if (!err) {
|
|
@@ -719,6 +758,14 @@ static void test_sockmap(int tasks, void *data)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /* Put sfd[2] (sending fd below) into msg map to test sendmsg bpf */
|
|
|
+ i = 0;
|
|
|
+ err = bpf_map_update_elem(map_fd_msg, &i, &sfd[2], BPF_ANY);
|
|
|
+ if (err) {
|
|
|
+ printf("Failed map_fd_msg update sockmap %i\n", err);
|
|
|
+ goto out_sockmap;
|
|
|
+ }
|
|
|
+
|
|
|
/* Test map send/recv */
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
buf[0] = i;
|