Skip to content

Commit

Permalink
selftests/bpf: Test bpf_mptcpify helper
Browse files Browse the repository at this point in the history
This patch tests the new helper bpf_mptcpify(). Store the new protocol
value after invoking the helper to a local BSS variable.

This is defined in a 'sock_create' SEC, so it will be invoked in
BPF_CGROUP_RUN_PROG_INET_SOCK() in inet_create().

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Jul 1, 2023
1 parent 96703c9 commit c67ffc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/bpf_tcp_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct sock {
#define sk_state __sk_common.skc_state
unsigned long sk_pacing_rate;
__u32 sk_pacing_status; /* see enum sk_pacing */
__u16 sk_protocol;
} __attribute__((preserve_access_index));

struct inet_sock {
Expand Down
26 changes: 26 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcpify.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023, SUSE. */

#include <sys/socket.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_tcp_helpers.h"

char _license[] SEC("license") = "GPL";
__u16 protocol = 0;

SEC("cgroup/sock_create")
int sock(struct bpf_sock *ctx)
{
struct sock *sk;

if (ctx->type != SOCK_STREAM)
return 1;

sk = bpf_mptcpify(ctx);
if (!sk)
return 1;

protocol = sk->sk_protocol;
return 1;
}

0 comments on commit c67ffc5

Please sign in to comment.