@@ -16,6 +16,10 @@ BPF_PROG(name, args)
#define SOL_TCP 6
#endif
+#ifndef TCP_CA_NAME_MAX
+#define TCP_CA_NAME_MAX 16
+#endif
+
#define tcp_jiffies32 ((__u32)bpf_jiffies64())
struct sock_common {
@@ -230,6 +234,7 @@ struct mptcp_sock {
struct inet_connection_sock sk;
__u32 token;
+ char ca_name[TCP_CA_NAME_MAX];
} __attribute__((preserve_access_index));
#endif
@@ -7,10 +7,15 @@
#include "network_helpers.h"
#include "mptcp_sock.skel.h"
+#ifndef TCP_CA_NAME_MAX
+#define TCP_CA_NAME_MAX 16
+#endif
+
struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
__u32 token;
+ char ca_name[TCP_CA_NAME_MAX];
};
static int verify_tsk(int map_fd, int client_fd)
@@ -31,14 +36,37 @@ static int verify_tsk(int map_fd, int client_fd)
return err;
}
+void get_msk_ca_name(char ca_name[])
+{
+ size_t len;
+ int fd;
+
+ fd = open("/proc/sys/net/ipv4/tcp_congestion_control", O_RDONLY);
+ if (!ASSERT_GE(fd, 0, "failed to open tcp_congestion_control"))
+ return;
+
+ len = read(fd, ca_name, TCP_CA_NAME_MAX);
+ if (!ASSERT_GT(len, 0, "failed to read ca_name"))
+ goto err;
+
+ if (len > 0 && ca_name[len - 1] == '\n')
+ ca_name[len - 1] = '\0';
+
+err:
+ close(fd);
+}
+
static int verify_msk(int map_fd, int client_fd, __u32 token)
{
+ char ca_name[TCP_CA_NAME_MAX];
int err, cfd = client_fd;
struct mptcp_storage val;
if (!ASSERT_GT(token, 0, "invalid token"))
return -1;
+ get_msk_ca_name(ca_name);
+
err = bpf_map_lookup_elem(map_fd, &cfd, &val);
if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
return err;
@@ -52,6 +80,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)
if (!ASSERT_EQ(val.token, token, "unexpected token"))
err++;
+ if (!ASSERT_STRNEQ(val.ca_name, ca_name, TCP_CA_NAME_MAX, "unexpected ca_name"))
+ err++;
+
return err;
}
@@ -2,6 +2,7 @@
/* Copyright (c) 2020, Tessares SA. */
/* Copyright (c) 2022, SUSE. */
+#include <string.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_tcp_helpers.h"
@@ -13,6 +14,7 @@ struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
__u32 token;
+ char ca_name[TCP_CA_NAME_MAX];
};
struct {
@@ -51,6 +53,7 @@ int _sockops(struct bpf_sock_ops *ctx)
return 1;
storage->token = 0;
+ bzero(storage->ca_name, TCP_CA_NAME_MAX);
} else {
msk = bpf_skc_to_mptcp_sock(sk);
if (!msk)
@@ -62,6 +65,7 @@ int _sockops(struct bpf_sock_ops *ctx)
return 1;
storage->token = msk->token;
+ memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX);
}
storage->invoked++;
storage->is_mptcp = is_mptcp;