Skip to content

Commit

Permalink
fix
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 31, 2024
1 parent 4f307aa commit 8f7432f
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 73 deletions.
20 changes: 10 additions & 10 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ struct bpf_iter_mptcp_subflow_kern {
struct list_head *pos;
} __aligned(8);

struct bpf_iter_mptcp_address {
struct bpf_iter_mptcp_userspace_pm_addr {
__u64 __opaque[2];
} __aligned(8);

struct bpf_iter_mptcp_address_kern {
struct bpf_iter_mptcp_userspace_pm_addr_kern {
struct mptcp_sock *msk;
struct list_head *pos;
} __aligned(8);
Expand Down Expand Up @@ -535,10 +535,10 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it)
}

__bpf_kfunc static int
bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it,
bpf_iter_mptcp_userspace_pm_addr_new(struct bpf_iter_mptcp_userspace_pm_addr *it,
struct mptcp_sock *msk)
{
struct bpf_iter_mptcp_address_kern *kit = (void *)it;
struct bpf_iter_mptcp_userspace_pm_addr_kern *kit = (void *)it;

kit->msk = msk;
if (!msk)
Expand All @@ -551,9 +551,9 @@ bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it,
}

__bpf_kfunc static struct mptcp_pm_addr_entry *
bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it)
bpf_iter_mptcp_userspace_pm_addr_next(struct bpf_iter_mptcp_userspace_pm_addr *it)
{
struct bpf_iter_mptcp_address_kern *kit = (void *)it;
struct bpf_iter_mptcp_userspace_pm_addr_kern *kit = (void *)it;

if (!kit->msk || list_is_last(kit->pos, &kit->msk->pm.userspace_pm_local_addr_list))
return NULL;
Expand All @@ -563,7 +563,7 @@ bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it)
}

__bpf_kfunc static void
bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it)
bpf_iter_mptcp_userspace_pm_addr_destroy(struct bpf_iter_mptcp_userspace_pm_addr *it)
{
}

Expand Down Expand Up @@ -706,9 +706,9 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock)
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
BTF_ID_FLAGS(func, bpf_iter_mptcp_address_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
BTF_ID_FLAGS(func, bpf_iter_mptcp_address_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_mptcp_address_destroy, KF_ITER_DESTROY)
BTF_ID_FLAGS(func, bpf_iter_mptcp_userspace_pm_addr_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
BTF_ID_FLAGS(func, bpf_iter_mptcp_userspace_pm_addr_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_mptcp_userspace_pm_addr_destroy, KF_ITER_DESTROY)
BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE)
BTF_ID_FLAGS(func, bpf_spin_lock_bh)
Expand Down
25 changes: 25 additions & 0 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,31 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc)
return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP);
}

int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_get_addr(id, addr, info);
return mptcp_pm_nl_get_addr(id, addr, info);
}

int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_dump_addr(bitmap, info);
return mptcp_pm_nl_dump_addr(bitmap, info);
}

int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_set_flags(loc, rem, info);
return mptcp_pm_nl_set_flags(loc, rem, info);
}

void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
{
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
Expand Down
39 changes: 7 additions & 32 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1780,8 +1780,8 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
return -EMSGSIZE;
}

static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info)
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info)
{
struct net *net = genl_info_net(info);
struct mptcp_pm_addr_entry *entry;
Expand All @@ -1801,14 +1801,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
return ret;
}

static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_get_addr(id, addr, info);
return mptcp_pm_nl_get_addr(id, addr, info);
}

int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
Expand Down Expand Up @@ -1852,8 +1844,8 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
return ret;
}

static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info)
int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info)
{
struct net *net = genl_info_net(info);
struct pm_nl_pernet *pernet;
Expand All @@ -1867,14 +1859,6 @@ static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
return 0;
}

static int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_dump_addr(bitmap, info);
return mptcp_pm_nl_dump_addr(bitmap, info);
}

int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
struct netlink_callback *cb)
{
Expand Down Expand Up @@ -2030,9 +2014,9 @@ static int mptcp_nl_set_flags(struct net *net,
return ret;
}

static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
{
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
MPTCP_PM_ADDR_FLAG_FULLMESH;
Expand Down Expand Up @@ -2079,15 +2063,6 @@ static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc,
return 0;
}

static int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
return mptcp_userspace_pm_set_flags(loc, rem, info);
return mptcp_pm_nl_set_flags(loc, rem, info);
}

int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
{
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
Expand Down
35 changes: 19 additions & 16 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "mib.h"
#include "mptcp_pm_gen.h"

#define mptcp_for_each_userspace_pm_addr(__msk, __entry) \
list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list), list)

static DEFINE_SPINLOCK(mptcp_pm_list_lock);
static LIST_HEAD(mptcp_pm_list);

Expand All @@ -32,11 +35,12 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk)
}

static struct mptcp_pm_addr_entry *
mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr)
mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr)
{
struct mptcp_pm_addr_entry *entry, *tmp;
struct mptcp_pm_addr_entry *entry;

mptcp_for_each_address_safe(msk, entry, tmp) {
mptcp_for_each_userspace_pm_addr(msk, entry) {
if (mptcp_addresses_equal(&entry->addr, addr, false))
return entry;
}
Expand All @@ -58,7 +62,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);

spin_lock_bh(&msk->pm.lock);
mptcp_for_each_address(msk, e) {
mptcp_for_each_userspace_pm_addr(msk, e) {
addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true);
if (addr_match && entry->addr.id == 0 && needs_id)
entry->addr.id = e->addr.id;
Expand Down Expand Up @@ -128,7 +132,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id)
{
struct mptcp_pm_addr_entry *entry;

mptcp_for_each_address(msk, entry) {
mptcp_for_each_userspace_pm_addr(msk, entry) {
if (entry->addr.id == id)
return entry;
}
Expand Down Expand Up @@ -188,26 +192,25 @@ u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk,
static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info)
{
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
struct mptcp_sock *msk = NULL;
struct mptcp_sock *msk;

if (!token) {
GENL_SET_ERR_MSG(info, "missing required inputs");
goto out;
GENL_SET_ERR_MSG(info, "missing required token");
return NULL;
}

msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token));
if (!msk) {
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
goto out;
return NULL;
}

if (!mptcp_pm_is_userspace(msk)) {
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
sock_put((struct sock *)msk);
msk = NULL;
return NULL;
}

out:
return msk;
}

Expand Down Expand Up @@ -251,7 +254,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
struct sock *sk;

if (!addr) {
GENL_SET_ERR_MSG(info, "missing required inputs");
GENL_SET_ERR_MSG(info, "missing required address");
return err;
}

Expand Down Expand Up @@ -350,7 +353,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
u8 id_val;

if (!id) {
GENL_SET_ERR_MSG(info, "missing required inputs");
GENL_SET_ERR_MSG(info, "missing required ID");
return err;
}

Expand Down Expand Up @@ -421,7 +424,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
struct sock *sk;

if (!laddr || !raddr) {
GENL_SET_ERR_MSG(info, "missing required inputs");
GENL_SET_ERR_MSG(info, "missing required address(es)");
return err;
}

Expand Down Expand Up @@ -562,7 +565,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
struct sock *sk;

if (!laddr || !raddr) {
GENL_SET_ERR_MSG(info, "missing required inputs");
GENL_SET_ERR_MSG(info, "missing required address(es)");
return err;
}

Expand Down Expand Up @@ -663,7 +666,7 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk,

bitmap_zero(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1);

mptcp_for_each_address(msk, entry) {
mptcp_for_each_userspace_pm_addr(msk, entry) {
if (test_bit(entry->addr.id, bitmap->map))
continue;

Expand Down
19 changes: 14 additions & 5 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,6 @@ struct mptcp_sock {
#define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \
list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node)

#define mptcp_for_each_address(__msk, __entry) \
list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list), list)
#define mptcp_for_each_address_safe(__msk, __entry, __tmp) \
list_for_each_entry_safe(__entry, __tmp, &((__msk)->pm.userspace_pm_local_addr_list), list)

extern struct genl_family mptcp_genl_family;

static inline void msk_owned_by_me(const struct mptcp_sock *msk)
Expand Down Expand Up @@ -1050,6 +1045,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *
mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
const struct mptcp_addr_info *addr);
int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info);
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info);
int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info);
Expand Down Expand Up @@ -1150,8 +1151,16 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr
bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc);
u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info);
int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info);
int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info);
int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info);
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info);
int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info);

Expand Down
8 changes: 4 additions & 4 deletions tools/testing/selftests/bpf/bpf_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,13 @@ bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ksym;
extern void
bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak __ksym;

struct bpf_iter_mptcp_address;
extern int bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it,
struct bpf_iter_mptcp_userspace_pm_addr;
extern int bpf_iter_mptcp_userspace_pm_addr_new(struct bpf_iter_mptcp_userspace_pm_addr *it,
struct mptcp_sock *msk) __weak __ksym;
extern struct mptcp_pm_addr_entry *
bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it) __weak __ksym;
bpf_iter_mptcp_userspace_pm_addr_next(struct bpf_iter_mptcp_userspace_pm_addr *it) __weak __ksym;
extern void
bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it) __weak __ksym;
bpf_iter_mptcp_userspace_pm_addr_destroy(struct bpf_iter_mptcp_userspace_pm_addr *it) __weak __ksym;

extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static inline int list_is_head(const struct list_head *list,
#define mptcp_for_each_subflow(__msk, __subflow) \
list_for_each_entry(__subflow, &((__msk)->conn_list), node)

#define mptcp_for_each_address(__msk, __entry) \
#define mptcp_for_each_userspace_pm_addr(__msk, __entry) \
list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list), list)

#define inet_sk(ptr) container_of(ptr, struct inet_sock, sk)
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int iters_address(struct bpf_sockopt *ctx)
if (!msk)
return 1;
bpf_spin_lock_bh(&msk->pm.lock);
bpf_for_each(mptcp_address, entry, msk) {
bpf_for_each(mptcp_userspace_pm_addr, entry, msk) {
/* Here MPTCP-specific path manager kfunc can be called:
* this test is not doing anything really useful, only to
* verify the iteration works.
Expand Down
Loading

0 comments on commit 8f7432f

Please sign in to comment.