Skip to content

Commit

Permalink
mptcp: drop struct mptcp_pm_local
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Oct 10, 2024
1 parent 7e19719 commit 5b27f7e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 52 deletions.
15 changes: 1 addition & 14 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,6 @@ __bpf_kfunc __u8 bpf_next_bit(struct mptcp_id_bitmap *bitmap)
return find_next_zero_bit(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1, 1);
}

__bpf_kfunc int bpf_mptcp_subflow_connect(struct sock *sk,
const struct mptcp_pm_addr_entry *entry,
const struct mptcp_addr_info *remote)
{
struct mptcp_pm_local local;

local.addr = entry->addr;
local.flags = entry->flags;
local.ifindex = entry->ifindex;

return __mptcp_subflow_connect(sk, &local, remote);
}

__bpf_kfunc_end_defs();

BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
Expand Down Expand Up @@ -591,7 +578,7 @@ BTF_ID_FLAGS(func, mptcp_wnd_end)
BTF_ID_FLAGS(func, tcp_stream_memory_free)
BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale)
BTF_ID_FLAGS(func, bpf_mptcp_subflow_connect, KF_SLEEPABLE)
BTF_ID_FLAGS(func, __mptcp_subflow_connect, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_subflow_shutdown, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_close_ssk, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_pm_nl_mp_prio_send_ack, KF_SLEEPABLE)
Expand Down
22 changes: 8 additions & 14 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static bool lookup_subflow_by_daddr(const struct list_head *list,
static bool
select_local_address(const struct pm_nl_pernet *pernet,
const struct mptcp_sock *msk,
struct mptcp_pm_local *new_local)
struct mptcp_pm_addr_entry *new_local)
{
struct mptcp_pm_addr_entry *entry;
bool found = false;
Expand All @@ -156,9 +156,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map))
continue;

new_local->addr = entry->addr;
new_local->flags = entry->flags;
new_local->ifindex = entry->ifindex;
*new_local = *entry;
found = true;
break;
}
Expand All @@ -169,7 +167,7 @@ select_local_address(const struct pm_nl_pernet *pernet,

static bool
select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,
struct mptcp_pm_local *new_local)
struct mptcp_pm_addr_entry *new_local)
{
struct mptcp_pm_addr_entry *entry;
bool found = false;
Expand All @@ -187,9 +185,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,
if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
continue;

new_local->addr = entry->addr;
new_local->flags = entry->flags;
new_local->ifindex = entry->ifindex;
*new_local = *entry;
found = true;
break;
}
Expand Down Expand Up @@ -526,11 +522,11 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
{
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_addr_entry local;
unsigned int add_addr_signal_max;
bool signal_and_subflow = false;
unsigned int local_addr_max;
struct pm_nl_pernet *pernet;
struct mptcp_pm_local local;
unsigned int subflows_max;

pernet = pm_nl_get_pernet(sock_net(sk));
Expand Down Expand Up @@ -652,7 +648,7 @@ static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
*/
static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
struct mptcp_addr_info *remote,
struct mptcp_pm_local *locals)
struct mptcp_pm_addr_entry *locals)
{
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_addr_entry *entry;
Expand All @@ -675,9 +671,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
continue;

if (msk->pm.subflows < subflows_max) {
locals[i].addr = entry->addr;
locals[i].flags = entry->flags;
locals[i].ifindex = entry->ifindex;
locals[i] = *entry;

/* Special case for ID0: set the correct ID */
if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.port))
Expand Down Expand Up @@ -713,7 +707,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,

static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
{
struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX];
struct mptcp_pm_addr_entry locals[MPTCP_PM_ADDR_MAX];
struct sock *sk = (struct sock *)msk;
unsigned int add_addr_accept_max;
struct mptcp_addr_info remote;
Expand Down
19 changes: 7 additions & 12 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,32 +362,27 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
}

static int userspace_pm_subflow_create(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *entry,
struct mptcp_pm_addr_entry *local,
struct mptcp_addr_info *remote)
{
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_local local;
int err;

if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
if (local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
return -EINVAL;
entry->flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;
local->flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;

if (!mptcp_pm_addr_families_match(sk, &entry->addr, remote))
if (!mptcp_pm_addr_families_match(sk, &local->addr, remote))
return -EINVAL;

err = mptcp_userspace_pm_append_new_local_addr(msk, entry, false);
err = mptcp_userspace_pm_append_new_local_addr(msk, local, false);
if (err < 0)
return err;

local.addr = entry->addr;
local.flags = entry->flags;
local.ifindex = entry->ifindex;

err = __mptcp_subflow_connect(sk, &local, remote);
err = __mptcp_subflow_connect(sk, local, remote);
spin_lock_bh(&msk->pm.lock);
if (err)
mptcp_userspace_pm_delete_local_addr(msk, entry);
mptcp_userspace_pm_delete_local_addr(msk, local);
else
msk->pm.subflows++;
spin_unlock_bh(&msk->pm.lock);
Expand Down
8 changes: 1 addition & 7 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,6 @@ struct mptcp_pm_data {
struct mptcp_rm_list rm_list_rx;
};

struct mptcp_pm_local {
struct mptcp_addr_info addr;
u8 flags;
int ifindex;
};

struct mptcp_pm_addr_entry {
struct list_head list;
struct mptcp_addr_info addr;
Expand Down Expand Up @@ -749,7 +743,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr);

/* called with sk socket lock held */
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_entry *local,
const struct mptcp_addr_info *remote);
int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
struct socket **new_sock);
Expand Down
2 changes: 1 addition & 1 deletion net/mptcp/subflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
#endif
}

int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_entry *local,
const struct mptcp_addr_info *remote)
{
struct mptcp_sock *msk = mptcp_sk(sk);
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ extern void bpf_list_add_tail_rcu(struct list_head *new,
extern struct mptcp_pm_addr_entry *
bpf_pm_alloc_entry(struct sock *sk, struct mptcp_pm_addr_entry *entry) __ksym;

extern int bpf_mptcp_subflow_connect(struct sock *sk,
const struct mptcp_pm_addr_entry *entry,
const struct mptcp_addr_info *remote) __ksym;
extern int __mptcp_subflow_connect(struct sock *sk,
const struct mptcp_pm_addr_entry *local,
const struct mptcp_addr_info *remote) __ksym;
extern void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how) __ksym;
extern void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
struct mptcp_subflow_context *subflow) __ksym;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/progs/mptcp_userspace_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int BPF_PROG(mptcp_pm_subflow_create, struct mptcp_sock *msk,
if (err < 0)
return err;

err = bpf_mptcp_subflow_connect(sk, local, remote);
err = __mptcp_subflow_connect(sk, local, remote);
bpf_spin_lock_bh(&msk->pm.lock);
if (err)
mptcp_userspace_pm_delete_local_addr(msk, local);
Expand Down

0 comments on commit 5b27f7e

Please sign in to comment.