Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpftune: enable -Wall for clang compilation and fix issues
fix unused variable warnings

Suggested-by: https://github.com/pavlinux
  • Loading branch information
alan-maguire committed Jul 11, 2023
commit 5ad929f93db62a9debe73a013b5a2255f730ffb2
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LLC ?= llc
LLVM_STRIP ?= llvm-strip
BPFTOOL ?= bpftool
BPF_INCLUDE := /usr/include
BPF_CFLAGS := -g -fno-stack-protector
BPF_CFLAGS := -g -fno-stack-protector -Wall
NL_INCLUDE := /usr/include/libnl3
INCLUDES := -I../include -I$(BPF_INCLUDE) -I$(NL_INCLUDE) -I../include/uapi

Expand Down
1 change: 0 additions & 1 deletion src/netns_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ SEC("kretprobe/setup_net")
int BPF_KRETPROBE(bpftune_setup_net_return, int ret)
{
struct bpftune_event event = {};
__u64 current, *netnsp;
struct net *netns;

if (ret != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/route_table_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SEC("kprobe/fib6_run_gc")
int BPF_KPROBE(bpftune_fib6_run_gc_entry, unsigned long expires,
struct net *net, bool force)
{
struct dst_net *dst_netp, dst_net = {};
struct dst_net *dst_netp;

get_entry_struct(dst_net_map, dst_netp);
/* already in gc, skip */
Expand Down
4 changes: 1 addition & 3 deletions src/sysctl_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int BPF_KPROBE(bpftune_sysctl, struct ctl_table_header *head,
struct bpftune_event event = {};
struct ctl_dir *root, *parent, *gparent, *ggparent;
struct ctl_dir *gggparent;
struct ctl_table *tbl, *parent_table;
struct ctl_table *parent_table;
int len = sizeof(event.str);
const char *procname;
int current_pid = 0;
Expand Down Expand Up @@ -81,8 +81,6 @@ int BPF_KPROBE(bpftune_sysctl, struct ctl_table_header *head,
procname = BPF_CORE_READ(parent_table, procname);
if (procname) {
if (!bpf_probe_read(event.str, sizeof(event.str), procname)) {
int i;

for (; len > 0 && *str; len--, str++) {}
if (len == 0)
return 0;
Expand Down
37 changes: 16 additions & 21 deletions src/tcp_cong_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@ retransmit_threshold(struct remote_host *remote_host,
return remote_host->retransmit_threshold;
}

static __always_inline int get_sk_key(struct sock *sk, struct in6_addr *key)
{
int family = BPF_CORE_READ(sk, sk_family);
switch (family) {
case AF_INET:
return bpf_probe_read_kernel(key, sizeof(sk->sk_daddr),
__builtin_preserve_access_index(&sk->sk_daddr));

case AF_INET6:
return bpf_probe_read_kernel(key, sizeof(*key),
__builtin_preserve_access_index(&sk->sk_v6_daddr));
default:
return -EINVAL;
}
}

static __always_inline struct remote_host *get_remote_host(struct in6_addr *key)
{
struct remote_host *remote_host = NULL;
Expand Down Expand Up @@ -129,8 +113,6 @@ int cong_tuner_sockops(struct bpf_sock_ops *ops)
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&event.raw_data;
struct in6_addr *key = &sin6->sin6_addr;
bool prior_retransmit_threshold;
char buf[CONG_MAXNAME] = {};
int ret;

switch (ops->op) {
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
Expand Down Expand Up @@ -179,6 +161,22 @@ int cong_tuner_sockops(struct bpf_sock_ops *ops)
return 1;
}
#else
static __always_inline int get_sk_key(struct sock *sk, struct in6_addr *key)
{
int family = BPF_CORE_READ(sk, sk_family);

switch (family) {
case AF_INET:
return bpf_probe_read_kernel(key, sizeof(sk->sk_daddr),
__builtin_preserve_access_index(&sk->sk_daddr));
case AF_INET6:
return bpf_probe_read_kernel(key, sizeof(*key),
__builtin_preserve_access_index(&sk->sk_v6_daddr));
default:
return -EINVAL;
}
}

SEC("tp_btf/tcp_retransmit_skb")
int BPF_PROG(cong_retransmit, struct sock *sk, struct sk_buff *skb)
{
Expand All @@ -188,7 +186,6 @@ int BPF_PROG(cong_retransmit, struct sock *sk, struct sk_buff *skb)
struct tcp_sock *tp = (struct tcp_sock *)sk;
struct in6_addr *key = &sin6->sin6_addr;
__u32 segs_out = 0, total_retrans = 0;
const char bbr[CONG_MAXNAME] = "bbr";
int id = TCP_CONG_BBR;
struct net *net;

Expand Down Expand Up @@ -232,10 +229,8 @@ int bpftune_cong_iter(struct bpf_iter__tcp *ctx)
{
struct sock_common *skc = ctx->sk_common;
struct remote_host *remote_host;
char buf[CONG_MAXNAME] = {};
struct in6_addr key = {};
struct sock *sk = NULL;
int ret;

if (skc)
sk = (struct sock *)bpf_skc_to_tcp_sock(skc);
Expand Down