add locking to PM APis, implement PM netlink
Subsystems (3)
Paolo Abeni
v4 cover add locking to PM APis, implement PM netlink
This implement the locking required by the PM to allow concurent subflow accessing the msk PM data in a safe way. Such data is protected via a msk-level spinlock. It relies on the Double checked locking to avoid contention in the most common scenarion (no or very little PM "actions").
Additionally changes more than a bit the PM hooks/APIs, to be hopefully simpler and avoiding duplicate code (no v4/v6 variant, work queue management done by the core PM infra).
It also introduce the PM netlink - it replace the current basic ones, the related patch has been dropped locally.
git tree available at:
https://github.com/pabeni/mptcp/tree/mptcp_net-next_part3_7
changes from v3:
- many cleanup and netlink fixes (Matt) - see individual patches changelog for the details
changes from v2:
- hook the new tests into the self-tests infra
changes from v1:
- 2 new patches: mp_join self-tests (9/9) and a specific mp_join fix (6/9)
- fixed several bugs as pointed out by the above tests
- added support for bind to interface
changes from RFC:
- cleanup uAPIs
- added self-tests for the uAPIs
- fixed ton of bugs
- included feedback from Mat
include/uapi/linux/mptcp.h | 53 + net/mptcp/Makefile | 3 net/mptcp/options.c | 60 - net/mptcp/pm.c | 361 +++------ net/mptcp/pm_netlink.c | 829 ++++++++++++++++++++++ net/mptcp/protocol.c | 14 net/mptcp/protocol.h | 113 +- net/mptcp/subflow.c | 65 + tools/testing/selftests/net/mptcp/Makefile | 9 tools/testing/selftests/net/mptcp/mptcp_connect.c | 19 tools/testing/selftests/net/mptcp/mptcp_join.sh | 296 +++++++ tools/testing/selftests/net/mptcp/pm_netlink.sh | 123 +++ tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 604 ++++++++++++++++ 13 files changed, 2230 insertions(+), 319 deletions(-)
Paolo Abeni
PATCH v4 1/9 Squash-to: "mptcp: Add ADD_ADDR handling"
Drop addr_signal flag: it belong to the PM and
needs additional locking
--- net/mptcp/options.c | 5 ----- net/mptcp/protocol.h | 1 - 2 files changed, 6 deletions(-)
net/mptcp/options.c +0 -5
@@ -438,9 +438,6 @@ static bool mptcp_established_options_addr(struct sock *sk,if (!msk)return false; -if (!msk->addr_signal) -return false; - id =0 ;memset (&saddr,0 ,sizeof (saddr));
@@ -463,8 +460,6 @@ static bool mptcp_established_options_addr(struct sock *sk, }#endif - msk->addr_signal =0 ; -return true; }
net/mptcp/protocol.h +0 -1
@@ -91,7 +91,6 @@ struct mptcp_sock {struct skb_ext *cached_ext;/* for the next sendmsg */ struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct sock *first; -u8 addr_signal; };#define mptcp_for_each_subflow (__msk, __subflow) \
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 2/9 Squash-to: "mptcp: Add path manager interface"
In reply to Paolo AbeniFactor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.
The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.
Account the number of created subflow and received addresses, to enforce limits.
Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.
Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.
v3 -> v4:
- mptcp_pm_add_addr -> mptcp_pm_add_addr_received
v1 -> v2:
- be sure to initialize the address port before calling mptcp_pm_add_addr()
--- net/mptcp/options.c | 46 +++++++++-------- net/mptcp/pm.c | 116 ++++++++++++++----------------------------- net/mptcp/protocol.c | 2 + net/mptcp/protocol.h | 98 ++++++++++++++++++++++-------------- 4 files changed, 123 insertions(+), 139 deletions(-)
net/mptcp/options.c +25 -21
@@ -432,34 +432,30 @@ static bool mptcp_established_options_addr(struct sock *sk, {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct mptcp_sock *msk =mptcp_sk (subflow->conn); -struct sockaddr_storage saddr; -u8 id; +struct mptcp_addr_info saddr; +int len;if (!msk)return false; -if (!msk->pm.fully_established) +if (!mptcp_pm_should_signal (msk) || + !(mptcp_pm_addr_signal (msk, remaining, &saddr)))return false; -if (mptcp_pm_addr_signal (msk, &id, &saddr)) + len =mptcp_add_addr_len (saddr.family); +if (remaining < len)return false; -if (saddr.ss_family ==AF_INET ) { -if (remaining <TCPOLEN_MPTCP_ADD_ADDR ) -return false; + *size = len; + opts->addr_id = saddr.id; +if (saddr.family ==AF_INET ) { opts->suboptions |=OPTION_MPTCP_ADD_ADDR ; - opts->addr_id = id; - opts->addr = ((struct sockaddr_in *)&saddr)->sin_addr; - *size =TCPOLEN_MPTCP_ADD_ADDR ; + opts->addr = saddr.addr; }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (saddr.ss_family == AF_INET6) { -if (remaining <TCPOLEN_MPTCP_ADD_ADDR6 ) -return false; + else if (saddr.family == AF_INET6) { opts->suboptions |=OPTION_MPTCP_ADD_ADDR6 ; - opts->addr_id = id; - opts->addr6 = ((struct sockaddr_in6 *)&saddr)->sin6_addr; - *size =TCPOLEN_MPTCP_ADD_ADDR6 ; + opts->addr6 = saddr.addr6; }#endif
@@ -557,13 +553,21 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,return ;if (msk && mp_opt->add_addr) { -if (mp_opt->family ==MPTCP_ADDR_IPVERSION_4 ) -mptcp_pm_add_addr (msk, &mp_opt->addr, mp_opt->addr_id); +struct mptcp_addr_info addr; + + addr.port =0 ; + addr.id = mp_opt->addr_id; +if (mp_opt->family ==MPTCP_ADDR_IPVERSION_4 ) { + addr.family =AF_INET ; + addr.addr = mp_opt->addr; + }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6) - mptcp_pm_add_addr6(msk, &mp_opt->addr6, - mp_opt->addr_id); + else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6) { + addr.family =AF_INET6 ; + addr.addr6 = mp_opt->addr6; + }#endif +mptcp_pm_add_addr_received (msk, &addr); mp_opt->add_addr =0 ; }
net/mptcp/pm.c +36 -80
171 lines not on this page · raw message
net/mptcp/protocol.c +2 -0
@@ -552,6 +552,8 @@ static int __mptcp_init_sock(struct sock *sk) msk->first =NULL ; +mptcp_pm_data_init (msk); +return 0 ; }
net/mptcp/protocol.h +60 -38
121 lines not on this page · raw message
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 3/9 Squash-to: "mptcp: Add handling of incoming MP_JOIN requests"
In reply to Paolo AbeniUpdate mptcp_pm_get_local_id() callers to new API.
Hook mptcp_pm_subflow_established() when MP_JOIN completes successfully
--- net/mptcp/options.c | 7 +++++-- net/mptcp/subflow.c | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-)
net/mptcp/options.c +5 -2
@@ -128,7 +128,6 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr, }break ; -case MPTCPOPT_DSS :pr_debug ("DSS" ); ptr++;
@@ -565,8 +564,12 @@ static bool check_fourth_ack(struct mptcp_subflow_context *subflow, TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1))return true; -if (mp_opt->use_ack) +if (mp_opt->use_ack) { subflow->fourth_ack =1 ; +if (subflow->mp_join) +mptcp_pm_subflow_established (mptcp_sk (subflow->conn), + subflow); + }if (subflow->can_ack)return true;
net/mptcp/subflow.c +4 -1
@@ -55,6 +55,7 @@ static bool subflow_token_join_request(struct request_sock *req,struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req);u8 hmac[MPTCPOPT_HMAC_LEN ];struct mptcp_sock *msk; +int local_id; msk =mptcp_token_get_sock (subflow_req->token);if (!msk) {
@@ -63,10 +64,12 @@ static bool subflow_token_join_request(struct request_sock *req,return false; } -if (mptcp_pm_get_local_id (req, (struct sock *)msk, skb)) { + local_id =mptcp_pm_get_local_id (msk, (struct sock_common *)req); +if (local_id <0 ) {sock_put ((struct sock *)msk);return false; } + subflow_req->local_id = local_id;get_random_bytes (&subflow_req->local_nonce,sizeof (u32));
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 4/9 Squash-to: "mptcp: Add handling of outgoing MP_JOIN requests"
In reply to Paolo Abenirecord local id for outgoing MP_JOIN connection.
join_id is the local address id, set as such in mptcp_syn_options()
--- net/mptcp/options.c | 2 +- net/mptcp/protocol.h | 7 ++++-- net/mptcp/subflow.c | 60 ++++++++++++++++++++++++++++++++------------ 3 files changed, 50 insertions(+), 19 deletions(-)
net/mptcp/options.c +1 -1
@@ -309,7 +309,7 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,pr_debug ("remote_token=%u, nonce=%u" , subflow->remote_token, subflow->local_nonce); opts->suboptions =OPTION_MPTCP_MPJ_SYN ; - opts->join_id = subflow->remote_id; + opts->join_id = subflow->local_id; opts->token = subflow->remote_token; opts->nonce = subflow->local_nonce; opts->backup = subflow->request_bkup;
net/mptcp/protocol.h +5 -2
@@ -256,8 +256,11 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)int mptcp_is_enabled (struct net *net);bool mptcp_subflow_data_available (struct sock *sk);void mptcp_subflow_init (void ); -int mptcp_subflow_connect (struct sock *sk,struct sockaddr *local, -struct sockaddr *remote,u8 remote_id); + +/* called with sk socket lock held */ +int __mptcp_subflow_connect (struct sock *sk,int ifindex, +const struct mptcp_addr_info *loc, +const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
net/mptcp/subflow.c +44 -16
122 lines not on this page · raw message
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 5/9 Squash-to: "mptcp: Implement path manager interface commands"
In reply to Paolo AbeniImplement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.
Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.
v1 -> v2:
- fix several issues in mptcp_pm_addr_signal()
RFC -> v1:
- simplify/cleanup mptcp_pm_work_pending() - Mat
- likewise simplify/cleanup mptcp_pm_add_addr()
--- net/mptcp/pm.c | 227 ++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 137 deletions(-)
net/mptcp/pm.c +90 -137
@@ -15,147 +15,17 @@ static struct workqueue_struct *pm_wq;int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_sock *msk =mptcp_token_get_sock (token); -int err =0 ; +pr_debug ("msk=%p, local_id=%d" , msk, addr->id); -if (!msk) -return -EINVAL ; - -if (msk->pm.local_valid) { - err = -EBADR ; - goto announce_put; - } - -pr_debug ("msk=%p, local_id=%d" , msk, local_id); - msk->pm.local_valid =1 ; - msk->pm.local_id = local_id; - msk->pm.local_family =AF_INET ; - msk->pm.local_addr = *addr; - msk->addr_signal =1 ; - -announce_put: -sock_put ((struct sock *)msk); -return err; -} - -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -int mptcp_pm_announce_addr6 (u32 token,u8 local_id,struct in6_addr *addr) -{ -struct mptcp_sock *msk =mptcp_token_get_sock (token); -int err =0 ; - -if (!msk) -return -EINVAL ; - -if (msk->pm.local_valid) { - err = -EBADR ; - goto announce_put; - } - -pr_debug ("msk=%p, local_id=%d" , msk, local_id); - msk->pm.local_valid =1 ; - msk->pm.local_id = local_id; - msk->pm.local_family =AF_INET6 ; - msk->pm.local_addr6 = *addr; - msk->addr_signal =1 ; - -announce_put: -sock_put ((struct sock *)msk); -return err; -} -#endif - -int mptcp_pm_remove_addr (u32 token,u8 local_id) -{ -struct mptcp_sock *msk =mptcp_token_get_sock (token); - -if (!msk) -return -EINVAL ; - -pr_debug ("msk=%p" , msk); - msk->pm.local_valid =0 ; - -sock_put ((struct sock *)msk); + msk->pm.local = *addr; +WRITE_ONCE (msk->pm.addr_signal, true);return 0 ; } -int mptcp_pm_create_subflow (u32 token,u8 remote_id,struct in_addr *addr) +int mptcp_pm_remove_addr (struct mptcp_sock *msk,u8 local_id) { -struct mptcp_sock *msk =mptcp_token_get_sock (token); -struct sockaddr_in remote; -struct sockaddr_in local; -struct sock *sk; -int err; - -if (!msk) -return -EINVAL ; - -pr_debug ("msk=%p" , msk); - - sk = (struct sock *)msk; -if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) { - err = -EBADR ; - goto create_put; - } - - local.sin_family =AF_INET ; - local.sin_port =0 ; -if (addr) - local.sin_addr = *addr; -else - local.sin_addr.s_addr =htonl (INADDR_ANY ); - - remote.sin_family = msk->pm.remote_family; - remote.sin_port =inet_sk (sk)->inet_dport; - remote.sin_addr = msk->pm.remote_addr; - - err =mptcp_subflow_connect (sk, (struct sockaddr *)&local, - (struct sockaddr *)&remote, remote_id); - -create_put: -sock_put (sk); -return err; -} - -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -int mptcp_pm_create_subflow6 (u32 token,u8 remote_id,struct in6_addr *addr) -{ -struct mptcp_sock *msk =mptcp_token_get_sock (token); -struct sockaddr_in6 remote; -struct sockaddr_in6 local; -struct sock *sk; -int err; - -if (!msk) -return -EINVAL ; - -pr_debug ("msk=%p" , msk); - sk = (struct sock *)msk; - -if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) { - err = -EBADR ; - goto create_put; - } - - local.sin6_family =AF_INET6 ; - local.sin6_port =0 ; -if (addr) - local.sin6_addr = *addr; -else - local.sin6_addr = in6addr_any; - - remote.sin6_family = msk->pm.remote_family; - remote.sin6_port =inet_sk (sk)->inet_dport; - remote.sin6_addr = msk->pm.remote_addr6; - - err =mptcp_subflow_connect (sk, (struct sockaddr *)&local, - (struct sockaddr *)&remote, remote_id); - -create_put: -sock_put (sk); -return err; +return -ENOTSUPP ; } -#endif int mptcp_pm_remove_subflow (struct mptcp_sock *msk,u8 remote_id) {
@@ -173,9 +43,36 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)WRITE_ONCE (pm->server_side, server_side); } +static bool mptcp_pm_schedule_work (struct mptcp_sock *msk, +enum mptcp_pm_status new_status) +{ +if (msk->pm.status !=MPTCP_PM_IDLE ) +return false; + +if (queue_work (pm_wq, &msk->pm.work)) { + msk->pm.status = new_status; +sock_hold ((struct sock *)msk); +return true; + } +return false; +} +void mptcp_pm_fully_established (struct mptcp_sock *msk) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p" , msk); + +/* try to avoid acquiring the lock below */ +if (READ_ONCE (pm->fully_established)) +return ; + +spin_lock_bh (&pm->lock); +if (!READ_ONCE (pm->fully_established) && +mptcp_pm_schedule_work (msk,MPTCP_PM_ESTABLISHED )) +WRITE_ONCE (pm->fully_established, true); + +spin_unlock_bh (&pm->lock); }void mptcp_pm_connection_closed (struct mptcp_sock *msk)
@@ -186,7 +83,19 @@ void mptcp_pm_connection_closed(struct mptcp_sock *msk)void mptcp_pm_subflow_established (struct mptcp_sock *msk,struct mptcp_subflow_context *subflow) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p" , msk); + +if (!READ_ONCE (pm->work_pending)) +return ; + +spin_lock_bh (&pm->lock); + +if (READ_ONCE (pm->work_pending)) +mptcp_pm_schedule_work (msk,MPTCP_PM_SUBFLOW_ESTABLISHED ); + +spin_unlock_bh (&pm->lock); }void mptcp_pm_subflow_closed (struct mptcp_sock *msk,u8 id)
@@ -197,7 +106,23 @@ void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)void mptcp_pm_add_addr_received (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -pr_debug ("msk=%p, remote_id=%d" , msk, addr->id); +struct mptcp_pm_data *pm = &msk->pm; + +pr_debug ("msk=%p remote_id=%d accept=%d" , msk, addr->id, +READ_ONCE (pm->accept_addr)); + +/* avoid acquiring the lock if there is no room for fouther addresses */ +if (!READ_ONCE (pm->accept_addr)) +return ; + +spin_lock_bh (&pm->lock); + +/* be sure there is something to signal re-checking under PM lock */ +if (READ_ONCE (pm->accept_addr) && +mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_RECEIVED )) + pm->remote = *addr; + +spin_unlock_bh (&pm->lock); }/* path manager helpers */
@@ -205,7 +130,24 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,bool mptcp_pm_addr_signal (struct mptcp_sock *msk,unsigned int remaining,struct mptcp_addr_info *saddr) { -return false; +int ret = false; + +spin_lock_bh (&msk->pm.lock); + +/* double check after the lock is acquired */ +if (!mptcp_pm_should_signal (msk)) + goto out_unlock; + +if (remaining <mptcp_add_addr_len (msk->pm.local.family)) + goto out_unlock; + + *saddr = msk->pm.local; +WRITE_ONCE (msk->pm.addr_signal, false); + ret = true; + +out_unlock: +spin_unlock_bh (&msk->pm.lock); +return ret; }int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc)
@@ -215,6 +157,17 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)static void pm_worker (struct work_struct *work) { + struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data, + work); + struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm); +struct sock *sk = (struct sock *)msk; + +switch (READ_ONCE (pm->status)) { +default : +break ; + } + +sock_put (sk); }void mptcp_pm_data_init (struct mptcp_sock *msk)
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 6/9 Squash-to: subflow: place further subflows on new 'join_list'
In reply to Paolo Abenimptcp_finish_join() may race with __mptcp_subflow_connect(). If mptcp_finish_join() completes before we reach the list_add_tail() call in __mptcp_subflow_connect() we get a data corruption due to double list add.
We need add to join_list only passive sockets, so fix the above avoiding the add for client socks.
--- net/mptcp/protocol.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/mptcp/protocol.c +5 -7
@@ -1400,16 +1400,14 @@ bool mptcp_finish_join(struct sock *sk)return false; parent_sock =READ_ONCE (parent->sk_socket); -if (parent_sock) { -if (!sk->sk_socket) -mptcp_sock_graft (sk, parent_sock); +if (parent_sock && !sk->sk_socket) { +mptcp_sock_graft (sk, parent_sock);/* active connections are already on conn_list */ -if (list_empty (&subflow->node)) { -spin_lock_bh (&msk->join_list_lock); +spin_lock_bh (&msk->join_list_lock); +if (!WARN_ON_ONCE (!list_empty (&subflow->node)))list_add_tail (&subflow->node, &msk->join_list); -spin_unlock_bh (&msk->join_list_lock); - } +spin_unlock_bh (&msk->join_list_lock); }return true; }
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 7/9 mptcp: add netlink based PM
In reply to Paolo AbeniExpose to U/S a netlink family to control the PM, setting:
- list of local addresses to be signalled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react
When the msk is fully established, the PM netlink attempts to announce the 'signal' list via the ADD_ADDR option. Since we currently lack the ADD_ADDR echo (and related event) only the first addr is sent.
After exhausting the 'annunce' list, the PM tries to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.
Idea is to add an additional PM hook for ADD_ADDR echo, to allow the PM netlink announcing multiple addresses, in sequence.
v3 -> v4:
- fixed several NL parsing issues
- give announce priority to subflow creation
- added '_PM' prefix to command names
- renamed 'addr_list' to 'local_addr_list'
- renamed mptcp_pm_create_subflow_or_signal ->
mptcp_pm_create_subflow_or_signal_addr
- renamed mptcp_pm_nl_add_addr ->
mptcp_pm_nl_add_addr_received
v1 -> v2:
- explicitly reset pm status to idle after processing a command
- fix msk pm initialization
- fix mptcp_pm_nl_add_addr bugs
- added ifindex support
- hopefully clearer local function names
- always use IS_ENABLED(CONFIG_MPTCP_IPV6) instead of IS_ENABLED(CONFIG_IPV6)
RFC -> v1:
- simplified NL API
- reduced {WRITE,READ}_ONCE boilerplate due to PM changes
- add check for duplicate addresses
--- include/uapi/linux/mptcp.h | 53 +++ net/mptcp/Makefile | 3 +- net/mptcp/pm.c | 18 +- net/mptcp/pm_netlink.c | 829 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 7 + 5 files changed, 908 insertions(+), 2 deletions(-) create mode 100644 net/mptcp/pm_netlink.c
include/uapi/linux/mptcp.h +53 -0
@@ -31,4 +31,57 @@ enum { };#define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1) + +/* netlink interface */ +#define MPTCP_PM_NAME "mptcp_pm" +#define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds" +#define MPTCP_PM_VER 0x1 + +/* +* ATTR types defined for MPTCP +*/ +enum mptcp_pm_attrs { +MPTCP_PM_ATTR_UNSPEC , + +MPTCP_PM_ATTR_ADDR ,/* nested address */ +MPTCP_PM_ATTR_RCV_ADD_ADDRS ,/* u32 */ + + __MPTCP_PM_ATTR_MAX +}; + +#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1) + +enum mptcp_pm_addr_addrs { +MPTCP_PM_ADDR_ATTR_UNSPEC , + +MPTCP_PM_ADDR_ATTR_FAMILY ,/* u16 */ +MPTCP_PM_ADDR_ATTR_ID ,/* u8 */ +MPTCP_PM_ADDR_ATTR_ADDR4 ,/* struct in_addr */ +MPTCP_PM_ADDR_ATTR_ADDR6 ,/* struct in6_addr */ +MPTCP_PM_ADDR_ATTR_PORT ,/* u16 */ +MPTCP_PM_ADDR_ATTR_FLAGS ,/* u32 */ +MPTCP_PM_ADDR_ATTR_IF_IDX ,/* s32 */ + + __MPTCP_PM_ADDR_ATTR_MAX +}; + +#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1) + +#define MPTCP_PM_ADDR_FLAG_SIGNAL (1 << 0) +#define MPTCP_PM_ADDR_FLAG_SUBFLOW (1 << 1) +#define MPTCP_PM_ADDR_FLAG_BACKUP (1 << 2) + +enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_RCV_ADD_ADDRS , +MPTCP_PM_CMD_GET_RCV_ADD_ADDRS , + + __MPTCP_PM_CMD_AFTER_LAST +}; +#endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o mib.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ + mib.o pm_netlink.o
net/mptcp/pm.c +17 -1
@@ -152,7 +152,7 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc) { -return 0 ; +return mptcp_pm_nl_get_local_id (msk, skc); }static void pm_worker (struct work_struct *work)
@@ -163,6 +163,18 @@ static void pm_worker(struct work_struct *work)struct sock *sk = (struct sock *)msk;switch (READ_ONCE (pm->status)) { +case MPTCP_PM_ADD_ADDR_RECEIVED : +mptcp_pm_nl_add_addr_received (msk); +break ; + +case MPTCP_PM_ESTABLISHED : +mptcp_pm_nl_fully_established (msk); +break ; + +case MPTCP_PM_SUBFLOW_ESTABLISHED : +mptcp_pm_nl_subflow_established (msk); +break ; +default :break ; }
@@ -183,6 +195,8 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)spin_lock_init (&msk->pm.lock);INIT_WORK (&msk->pm.work, pm_worker); + +mptcp_pm_nl_data_init (msk); }void mptcp_pm_init (void )
@@ -190,4 +204,6 @@ void mptcp_pm_init(void) pm_wq =alloc_workqueue ("pm_wq" ,WQ_UNBOUND |WQ_MEM_RECLAIM ,8 );if (!pm_wq)panic ("Failed to allocate workqueue" ); + +mptcp_pm_nl_init (); }
net/mptcp/pm_netlink.c new file +829 -0
829 lines not on this page · raw message
net/mptcp/protocol.h +7 -0
@@ -391,6 +391,13 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_addr_info *saddr);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc); +void mptcp_pm_nl_init (void ); +void mptcp_pm_nl_data_init (struct mptcp_sock *msk); +void mptcp_pm_nl_fully_established (struct mptcp_sock *msk); +void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk); +void mptcp_pm_nl_add_addr_received (struct mptcp_sock *msk); +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct sock_common *skc); +static inline struct mptcp_ext *mptcp_get_ext (struct sk_buff *skb) {return (struct mptcp_ext *)skb_ext_find (skb,SKB_EXT_MPTCP );
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 8/9 selftests: add PM netlink functional tests
In reply to Paolo AbeniThis introduces basic self-tests for the PM netlink, checking the basic APIs and possible exceptional values.
---
v3 -> v4:
- adapted to new CMD names
v2 -> v3:
- include the newly added self-test script into self-tests infra
--- tools/testing/selftests/net/mptcp/Makefile | 7 +- .../testing/selftests/net/mptcp/pm_netlink.sh | 123 ++++ tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 604 ++++++++++++++++++ 3 files changed, 731 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/pm_netlink.sh create mode 100644 tools/testing/selftests/net/mptcp/pm_nl_ctl.c
tools/testing/selftests/net/mptcp/Makefile +4 -3
@@ -1,12 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 top_srcdir = ../../../../.. +KSFT_KHDR_INSTALL := 1 -CFLAGS = -Wall -Wl,--no-as-needed -O2 -g +CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include -TEST_PROGS := mptcp_connect.sh +TEST_PROGS := mptcp_connect.sh pm_netlink.sh -TEST_GEN_FILES = mptcp_connect +TEST_GEN_FILES = mptcp_connect pm_nl_ctl EXTRA_CLEAN := *.pcap
tools/testing/selftests/net/mptcp/pm_netlink.sh new file +123 -0
123 lines not on this page · raw message
tools/testing/selftests/net/mptcp/pm_nl_ctl.c new file +604 -0
604 lines not on this page · raw message
Signature · 1 line
2.21.1
Paolo Abeni
PATCH v4 9/9 selftests: add test-cases for MPTCP MP_JOIN
In reply to Paolo AbeniUse the pm netlink to configure the creation of several subflows, and verify that via MIB counters.
Update the mptcp_connect program to allow reliable MP_JOIN handshake even on small data file
---
v2 -> v3:
- update self-tests Makefile, too
- really return an error code on error
Notes:
- all the tests trying to establish subflows using multiple local addresses currently fail because we currently don' t send the 4th ack for subflows, so we don't trigger the mptcp_pm_subflow_established() function (subflows are in PREESTABLISHED status)
- need more MIB for more reliable checks,
e.g. MPTcpExtMPJoinSynTx, MPTcpExtMPJoinSynAckRx, AddAddrRx,
AddAddrTx
--- tools/testing/selftests/net/mptcp/Makefile | 2 +- .../selftests/net/mptcp/mptcp_connect.c | 19 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 296 ++++++++++++++++++ 3 files changed, 314 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/Makefile +1 -1
@@ -5,7 +5,7 @@ KSFT_KHDR_INSTALL := 1 CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include -TEST_PROGS := mptcp_connect.sh pm_netlink.sh +TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh TEST_GEN_FILES = mptcp_connect pm_nl_ctl
tools/testing/selftests/net/mptcp/mptcp_connect.c +17 -2
@@ -50,6 +50,7 @@ static int cfg_sock_proto = IPPROTO_MPTCP;static bool tcpulp_audit;static int pf =AF_INET ;static int cfg_sndbuf; +static bool cfg_join;static void die_usage (void ) {
@@ -230,6 +231,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,static size_t do_rnd_write (const int fd,char *buf,const size_t len) { +static bool first = true;unsigned int do_w;ssize_t bw;
@@ -237,10 +239,19 @@ static size_t do_rnd_write(const int fd, char *buf, const size_t len)if (do_w ==0 || do_w > len) do_w = len; +if (cfg_join && first && do_w >100 ) + do_w =100 ; + bw =write (fd, buf, do_w);if (bw <0 )perror ("write" ); +/* let the join handshake complete, before going on */ +if (cfg_join && first) { +sleep (1 ); + first = false; + } +return bw; }
@@ -638,7 +649,7 @@ static void maybe_close(int fd) {unsigned int r =rand (); -if (r &1 ) +if (!cfg_join && (r &1 ))close (fd); }
@@ -774,8 +785,12 @@ static void parse_opts(int argc, char **argv) {int c; -while ((c =getopt (argc, argv,"6lp:s:hut:m:b:" )) !=-1 ) { +while ((c =getopt (argc, argv,"6jlp:s:hut:m:b:" )) !=-1 ) {switch (c) { +case 'j' : + cfg_join = true; + cfg_mode =CFG_MODE_POLL ; +break ;case 'l' : listen_mode = true;break ;
tools/testing/selftests/net/mptcp/mptcp_join.sh new file +296 -0
297 lines not on this page · raw message
Signature · 1 line
2.21.1
Paolo Abeni
[MPTCP] Re: [PATCH v4 7/9] mptcp: add netlink based PM
In reply to Paolo Abeniinclude/uapi/linux/mptcp.h enum { · line 82
Quoted 9 lines · Paolo Abeni
include/uapi/linux/mptcp.h +9
-0+enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_RCV_ADD_ADDRS , +MPTCP_PM_CMD_GET_RCV_ADD_ADDRS ,
To enforce the server subflow limits, the idea would be to change (in a separated series) the above 2 commands to:
MPTCP_PM_CMD_SET_LIMITS,
MPTCP_PM_CMD_GET_LIMITS,
and add a new attribute for the max subflow limits
Plus the core infrastructure/hooks to let the PM really enforce such limit.
WDYT?
Cheers,
Paolo
Matthieu Baerts
[MPTCP] Re: [PATCH v4 7/9] mptcp: add netlink based PM
Hi Paolo,
Quoted 16 lines · Paolo Abeni
include/uapi/linux/mptcp.h enum { · line 82
Quoted 9 lines · Paolo Abeni
include/uapi/linux/mptcp.h +9
-0+enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_RCV_ADD_ADDRS , +MPTCP_PM_CMD_GET_RCV_ADD_ADDRS ,To enforce the server subflow limits, the idea would be to change (in a separated series) the above 2 commands to:
MPTCP_PM_CMD_SET_LIMITS,
MPTCP_PM_CMD_GET_LIMITS,
Quoted 6 lines
and add a new attribute for the max subflow limits
Plus the core infrastructure/hooks to let the PM really enforce such limit.
WDYT?
That sounds good to me and more "natural". Thank you for looking at this!
Just one question: would they be generic commands to add/get limits? Or should we set a more specific name, e.g.:
MPTCP_PM_CMD_SET_MAX_SUBFLOWS
MPTCP_PM_CMD_GET_MAX_SUBFLOWS
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Paolo Abeni
[MPTCP] Re: [PATCH v4 7/9] mptcp: add netlink based PM
Quoted 26 lines · Matthieu Baerts
Hi Paolo,
Quoted 16 lines · Paolo Abeni
include/uapi/linux/mptcp.h enum { · line 82
Quoted 9 lines · Paolo Abeni
include/uapi/linux/mptcp.h +9
-0+enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_RCV_ADD_ADDRS , +MPTCP_PM_CMD_GET_RCV_ADD_ADDRS ,To enforce the server subflow limits, the idea would be to change (in a separated series) the above 2 commands to:
MPTCP_PM_CMD_SET_LIMITS,
MPTCP_PM_CMD_GET_LIMITS,Quoted 6 lines
and add a new attribute for the max subflow limits
Plus the core infrastructure/hooks to let the PM really enforce such limit.
WDYT?
Quoted 7 lines
That sounds good to me and more "natural". Thank you for looking at this!
Just one question: would they be generic commands to add/get limits? Or should we set a more specific name, e.g.:
MPTCP_PM_CMD_SET_MAX_SUBFLOWS
MPTCP_PM_CMD_GET_MAX_SUBFLOWS
Before doing the actual coding, I think the first option would lead to smaller/simpler implementation (no duplicate boilerplates) and should be also more easily extendible for the same reason.
But I guess is mostly a matter of taste, and I know I'm moslty wrong on that kind of topics - except for important subjects like pizza and coffee ;)
/P
Matthieu Baerts
[MPTCP] Re: [PATCH v4 7/9] mptcp: add netlink based PM
Hi Paolo,
Quoted 32 lines · Paolo Abeni
Quoted 31 lines · Matthieu Baerts
Hi Paolo,
Quoted 16 lines · Paolo Abeni
include/uapi/linux/mptcp.h enum { · line 82
Quoted 9 lines · Paolo Abeni
include/uapi/linux/mptcp.h +9
-0+enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_RCV_ADD_ADDRS , +MPTCP_PM_CMD_GET_RCV_ADD_ADDRS ,To enforce the server subflow limits, the idea would be to change (in a separated series) the above 2 commands to:
MPTCP_PM_CMD_SET_LIMITS,
MPTCP_PM_CMD_GET_LIMITS,Quoted 6 lines
and add a new attribute for the max subflow limits
Plus the core infrastructure/hooks to let the PM really enforce such limit.
WDYT?
That sounds good to me and more "natural". Thank you for looking at this!
Just one question: would they be generic commands to add/get limits? Or should we set a more specific name, e.g.:
Quoted 6 lines
Quoted 2 lines
MPTCP_PM_CMD_SET_MAX_SUBFLOWS
MPTCP_PM_CMD_GET_MAX_SUBFLOWSBefore doing the actual coding, I think the first option would lead to smaller/simpler implementation (no duplicate boilerplates) and should be also more easily extendible for the same reason.
I guess you will have MPTCP_PM_CMD_SET_LIMITS only accepting MPTCP_PM_LIMITS_ATTR_MAX_SUBFLOW for the moment.
It can indeed be extended later.
Quoted 3 lines
But I guess is mostly a matter of taste, and I know I'm moslty wrong on that kind of topics - except for important subjects like pizza and coffee ;)
🍍
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Matthieu Baerts
Hi Paolo,
Quoted 9 lines · Paolo Abeni
This implement the locking required by the PM to allow concurent subflow accessing the msk PM data in a safe way. Such data is protected via a msk-level spinlock. It relies on the Double checked locking to avoid contention in the most common scenarion (no or very little PM "actions").
Additionally changes more than a bit the PM hooks/APIs, to be hopefully simpler and avoiding duplicate code (no v4/v6 variant, work queue management done by the core PM infra).
Quoted 6 lines
It also introduce the PM netlink - it replace the current basic ones, the related patch has been dropped locally.
git tree available at:
Thank you for the good and huge work!
- 74d2503e1c62: mptcp: remove 'basic' PM → empty
t/mptcp-Implement-basic-path-manager topic.
- cb84d6f267fe..54c154e2c0ac: result
- b2f4dc591ecd: "squashed" patch 1/9 in "mptcp: Add ADD_ADDR handling"
- fa8348e24d53: "Signed-off-by" + "Co-developed-by"
- 2d125a76bc1e: conflict in t/mptcp-Add-path-manager-interface
- 54c154e2c0ac..66aa68608025: result
- cb6c1764eb31: "squashed" patch 2/9 in "mptcp: Add path manager interface"
- e16ecd3f2df3: "Signed-off-by" + "Co-developed-by"
- f8513e13c445: conflict in t/mptcp-Implement-path-manager-interface-commands
- ce2d7fb36478: conflict in t/mptcp-introduce-MPTCP-retransmission-timer
- 66aa68608025..930fad27493a: result
- f990e741f3e8: "squashed" patch 3/9 in "mptcp: Add handling of incoming MP_JOIN requests"
- 930fad27493a..928bf2dd018c: result
- f88ff34735b9: "squashed" patch 4/9 in "mptcp: Add handling of outgoing MP_JOIN requests"
- a0a90d3f6dcd: conflict in t/subflow-place-further-subflows-on-new-join_list
- 928bf2dd018c..9cb150eeeed4: result
- d90e5e0f64eb: "squashed" patch 5/9 (with conflicts) in "mptcp:
Implement path manager interface commands"
- a28e79bf6de0: "Signed-off-by" + "Co-developed-by"
- 9cb150eeeed4..cadd51934361: result
- 959311c1ef2e: "squashed" patch 6/9 in "subflow: place further subflows on new 'join_list'"
- 78b52ea186cb: "Signed-off-by" + "Co-developed-by"
- cadd51934361..74cd9cb07e28: result
The 3 last patches have been added at the end of the series:
- c3a214585944: mptcp: add netlink based PM
- simple conflict with MPTCP_SUBFLOW_ATTR_MAX
- 46dcb6276168: selftests: add PM netlink functional tests
- no conflict
- a17132c420b0: selftests: add test-cases for MPTCP MP_JOIN
- no conflict
- 74cd9cb07e28..fa603a295c69: result
Tests + export are in progress.
Please tell me if there is anything wrong.
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium