From 8f7432f5aa5158951cfc1f9fa036d600f64d550e Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 31 Oct 2024 09:48:45 +0800 Subject: [PATCH] fix Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 20 +++++----- net/mptcp/pm.c | 25 ++++++++++++ net/mptcp/pm_netlink.c | 39 ++++--------------- net/mptcp/pm_userspace.c | 35 +++++++++-------- net/mptcp/protocol.h | 19 ++++++--- .../testing/selftests/bpf/bpf_experimental.h | 8 ++-- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 2 +- .../selftests/bpf/progs/mptcp_bpf_iters.c | 2 +- .../bpf/progs/mptcp_bpf_userspace_pm.c | 8 ++-- 9 files changed, 85 insertions(+), 73 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 8259ccf2e4392..1b01f195b426d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -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); @@ -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) @@ -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; @@ -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) { } @@ -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) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index ee8921bf73925..95e7e36a5dd80 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -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); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 593c42ac9c299..15a818879d2c2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -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; @@ -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]; @@ -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; @@ -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) { @@ -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; @@ -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 }, }; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 1af863e6a25e0..b45b9dad4d79f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -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); @@ -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; } @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 34fee6cc438ec..1b1af8556e6cf 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -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) @@ -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); @@ -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); diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index 305c19fb377bb..8723b212e0228 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -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; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index be4ce246b89b8..2540f38f2cdb2 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -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) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c index 6ed14d41a247b..48511faf7a2d0 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -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. diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c index 934dba9357ea8..95274fa577817 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c @@ -33,7 +33,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bpf_bitmap_zero(&id_bitmap); bpf_spin_lock_bh(&msk->pm.lock); - bpf_for_each(mptcp_address, e, msk) { + bpf_for_each(mptcp_userspace_pm_addr, e, msk) { addr_match = bpf_mptcp_addresses_equal(&e->addr, &entry->addr, true); if (addr_match && entry->addr.id == 0 && needs_id) entry->addr.id = e->addr.id; @@ -139,7 +139,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) { struct mptcp_pm_addr_entry *entry; - bpf_for_each(mptcp_address, entry, msk) { + bpf_for_each(mptcp_userspace_pm_addr, entry, msk) { if (entry->addr.id == id) return entry; } @@ -183,7 +183,7 @@ mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, const struct mptcp_addr_i { struct mptcp_pm_addr_entry *entry; - bpf_for_each(mptcp_address, entry, msk) { + bpf_for_each(mptcp_userspace_pm_addr, entry, msk) { if (bpf_mptcp_addresses_equal(&entry->addr, addr, false)) return entry; } @@ -395,7 +395,7 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, bpf_bitmap_zero(bitmap); - mptcp_for_each_address(msk, entry) { + mptcp_for_each_userspace_pm_addr(msk, entry) { entry = bpf_core_cast(entry, struct mptcp_pm_addr_entry); if (bpf_test_bit(entry->addr.id, bitmap))