ADD_ADDR: ports support
Subsystems (3)
Geliang Tang
v9 cover ADD_ADDR: ports support
v9:
- use queue_rcu_work to release the listening socket.
- squash v8's patch 2 with patch 3.
- add two new patches, "mptcp: drop unused skb insubflow_token_join_request" and "mptcp: add a new helper subflow_req_create_thmac"
v8:
- release the listening socket when removing the entry.
- initialize addr.port and lsk in mptcp_pm_nl_get_local_id().
- change kernel_listen's backlog to 1024.
- enable address_zero's use_port.
v7:
- use the MPTCP listening socket instead of TCP one
- release subflow_req->msk in subflow_init_req
- add mismatched port MIBs
- use sock_common in source_address
v6:
- create and bind the listening socket in mptcp_nl_cmd_add_addr.
- drop the patch "mptcp: add port number listened in kernel check" in v5.
v5:
- use the per netns listening socket.
- First 8 patches in v4 had been merged to the export branch, drop them from this patchset.
v4:
- hold msk->pm.lock in mptcp_pm_sport_in_anno_list.
- Merge the patchset 'Squash to "ADD_ADDR: ports support v3"' into v4.
v3:
- add two new patches, 8 and 11
- add more IS_ENABLED(CONFIG_MPTCP_IPV6) in patch 2
- define TCPOLEN_MPTCP_ADD_ADDR_HMAC in patch 4
- add flags check in patch 10
- update the testcases
v2:
- change mptcp_out_options's port field in CPU bype order.
- keep mptcp_options_received's port field in CPU bype order.
- add two new patches to simplify ADD_ADDR suboption writing.
- update mptcp_add_addr_len helper use adding up size.
- add more commit messages.
v1:
This series is the first version of ADD_ADDR ports support. I have solved the listener problem which I mentioned at the meeting on 15th of October by adding a new listening socket from the userspace (see patch 8). Up to now this patchset works well.
Geliang Tang (9):
mptcp: create the listening socket for new port
mptcp: drop unused skb in subflow_token_join_request
mptcp: add a new helper subflow_req_create_thmac
mptcp: add port number check for MP_JOIN
mptcp: enable use_port when invoke addresses_equal
mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink
selftests: mptcp: add port argument for pm_nl_ctl
mptcp: add the mibs for ADD_ADDR with port
selftests: mptcp: add testcases for ADD_ADDR with port
net/mptcp/mib.c | 6 + net/mptcp/mib.h | 6 + net/mptcp/options.c | 4 + net/mptcp/pm_netlink.c | 132 ++++++++++++++- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 5 + net/mptcp/subflow.c | 79 +++++++-- .../testing/selftests/net/mptcp/mptcp_join.sh | 160 +++++++++++++++++- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 24 ++- 9 files changed, 393 insertions(+), 25 deletions(-)
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 1/9 mptcp: create the listening socket for new port
This patch created a listening socket when an address with a port-number is added by PM netlink. Then binded the new port to the socket, and listened for the connection.
When the address is removed or the addresses are flushed by PM netlink, release the listening socket.
--- net/mptcp/pm_netlink.c | 96 +++++++++++++++++++++++++++++++++++++++++- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++ net/mptcp/subflow.c | 6 +-- 4 files changed, 102 insertions(+), 6 deletions(-)
net/mptcp/pm_netlink.c +94 -2
@@ -26,6 +26,7 @@ struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr;struct rcu_head rcu; +struct socket *lsk; };struct mptcp_pm_add_entry {
@@ -673,6 +674,53 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,return ret; } +static int mptcp_pm_nl_create_listen_socket (struct sock *sk, +struct mptcp_pm_addr_entry *entry) +{ +struct sockaddr_storage addr; +struct mptcp_sock *msk; +struct socket *ssock; +int backlog =1024 ; +int err; + + err =sock_create_kern (sock_net (sk), entry->addr.family, +SOCK_STREAM ,IPPROTO_MPTCP , &entry->lsk); +if (err) +return err; + + msk =mptcp_sk (entry->lsk->sk); +if (!msk) { + err = -EINVAL ; + goto out; + } + + ssock =__mptcp_nmpc_socket (msk); +if (!ssock) { + err = -EINVAL ; + goto out; + } + +mptcp_info2sockaddr (&entry->addr, &addr, entry->addr.family); + err =kernel_bind (ssock, (struct sockaddr *)&addr, +sizeof (struct sockaddr_in )); +if (err) { +pr_warn ("kernel_bind error, err=%d" , err); + goto out; + } + + err =kernel_listen (ssock, backlog); +if (err) { +pr_warn ("kernel_listen error, err=%d" , err); + goto out; + } + +return 0 ; + +out: +sock_release (entry->lsk); +return err; +} +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct sock_common *skc) {struct mptcp_pm_addr_entry *entry;
@@ -717,6 +765,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) entry->addr.ifindex =0 ; entry->addr.flags =0 ; entry->addr.id =0 ; + entry->addr.port =0 ; + entry->lsk =NULL ; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )kfree (entry);
@@ -886,9 +936,19 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) } *entry = addr; +if (entry->addr.port) { + ret =mptcp_pm_nl_create_listen_socket (skb->sk, entry); +if (ret) { +GENL_SET_ERR_MSG (info,"create listen socket error" ); +kfree (entry); +return ret; + } + } ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 ) {GENL_SET_ERR_MSG (info,"too many addresses or duplicate one" ); +if (entry->lsk) +sock_release (entry->lsk);kfree (entry);return ret; }
@@ -972,6 +1032,38 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,return 0 ; } +struct addr_entry_release_work { +struct rcu_work rwork; +struct mptcp_pm_addr_entry *entry; +}; + +static void mptcp_pm_release_addr_entry (struct work_struct *work) +{ +struct addr_entry_release_work *w; +struct mptcp_pm_addr_entry *entry; + + w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork); + entry = w->entry; +if (entry) { +if (entry->lsk) +sock_release (entry->lsk); +kfree (entry); + } +kfree (w); +} + +static void mptcp_pm_free_addr_entry (struct mptcp_pm_addr_entry *entry) +{ +struct addr_entry_release_work *w; + + w =kmalloc (sizeof (*w),GFP_ATOMIC ); +if (w) { +INIT_RCU_WORK ((struct rcu_work *)w, mptcp_pm_release_addr_entry); + w->entry = entry; +queue_rcu_work (system_wq, (struct rcu_work *)w); + } +} +static int mptcp_nl_cmd_del_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];
@@ -1001,7 +1093,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)spin_unlock_bh (&pernet->lock);mptcp_nl_remove_subflow_and_signal_addr (sock_net (skb->sk), &entry->addr); -kfree_rcu (entry, rcu); +mptcp_pm_free_addr_entry (entry);return ret; }
@@ -1015,7 +1107,7 @@ static void __flush_addrs(struct net *net, struct list_head *list) struct mptcp_pm_addr_entry, list);mptcp_nl_remove_subflow_and_signal_addr (net, &cur->addr);list_del_rcu (&cur->list); -kfree_rcu (cur, rcu); +mptcp_pm_free_addr_entry (cur); } }
net/mptcp/protocol.c +1 -1
@@ -49,7 +49,7 @@ static void __mptcp_check_send_data_fin(struct sock *sk);* completed yet or has failed, return the subflow socket. * Otherwise return NULL. */ -static struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) {if (!msk->subflow ||READ_ONCE (msk->can_ack))return NULL ;
net/mptcp/protocol.h +4 -0
@@ -469,11 +469,15 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);void __mptcp_close_ssk (struct sock *sk,struct sock *ssk,struct mptcp_subflow_context *subflow);void mptcp_subflow_reset (struct sock *ssk); +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk);/* called with sk socket lock held */ int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_addr_info *loc,const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family);static inline void mptcp_subflow_tcp_fallback (struct sock *sk,struct mptcp_subflow_context *ctx)
net/mptcp/subflow.c +3 -3
@@ -1073,9 +1073,9 @@ void mptcpv6_handle_mapped(struct sock *sk, bool mapped) }#endif -static void mptcp_info2sockaddr (const struct mptcp_addr_info *info, -struct sockaddr_storage *addr, -unsigned short family) +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family) {memset (addr,0 ,sizeof (*addr)); addr->ss_family = family;
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 2/9 mptcp: drop unused skb in subflow_token_join_request
This patch dropped the unused parameter skb in subflow_token_join_request.
--- net/mptcp/subflow.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/mptcp/subflow.c +2 -3
@@ -61,8 +61,7 @@ static bool mptcp_can_accept_new_subflow(const struct mptcp_sock *msk) }/* validate received token and create truncated hmac and nonce for SYN-ACK */ -static struct mptcp_sock *subflow_token_join_request (struct request_sock *req, -const struct sk_buff *skb) +static struct mptcp_sock *subflow_token_join_request (struct request_sock *req) {struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req);u8 hmac[SHA256_DIGEST_SIZE ];
@@ -178,7 +177,7 @@ static int subflow_init_req(struct request_sock *req, subflow_req->remote_id = mp_opt.join_id; subflow_req->token = mp_opt.token; subflow_req->remote_nonce = mp_opt.nonce; - subflow_req->msk =subflow_token_join_request (req, skb); + subflow_req->msk =subflow_token_join_request (req);/* Can't fall back to TCP in this case. */ if (!subflow_req->msk)
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 3/9 mptcp: add a new helper subflow_req_create_thmac
This patch added a new helper named subflow_req_create_thmac, which split from subflow_token_join_request. It initialized subflow_req's local_nonce and thmac fields, those are the more expensive to populate.
--- net/mptcp/subflow.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +16 -8
@@ -61,10 +61,23 @@ static bool mptcp_can_accept_new_subflow(const struct mptcp_sock *msk) }/* validate received token and create truncated hmac and nonce for SYN-ACK */ +static void subflow_req_create_thmac (struct mptcp_subflow_request_sock *subflow_req) +{ +struct mptcp_sock *msk = subflow_req->msk; +u8 hmac[SHA256_DIGEST_SIZE ]; + +get_random_bytes (&subflow_req->local_nonce,sizeof (u32)); + +subflow_generate_hmac (msk->local_key, msk->remote_key, + subflow_req->local_nonce, + subflow_req->remote_nonce, hmac); + + subflow_req->thmac =get_unaligned_be64 (hmac); +} +static struct mptcp_sock *subflow_token_join_request (struct request_sock *req) {struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); -u8 hmac[SHA256_DIGEST_SIZE ];struct mptcp_sock *msk;int local_id;
@@ -81,13 +94,6 @@ static struct mptcp_sock *subflow_token_join_request(struct request_sock *req) } subflow_req->local_id = local_id; -get_random_bytes (&subflow_req->local_nonce,sizeof (u32)); - -subflow_generate_hmac (msk->local_key, msk->remote_key, - subflow_req->local_nonce, - subflow_req->remote_nonce, hmac); - - subflow_req->thmac =get_unaligned_be64 (hmac);return msk; }
@@ -183,6 +189,8 @@ static int subflow_init_req(struct request_sock *req,if (!subflow_req->msk)return -EPERM ; +subflow_req_create_thmac (subflow_req); +if (unlikely (req->syncookie)) {if (mptcp_can_accept_new_subflow (subflow_req->msk))subflow_init_req_cookie_join_save (subflow_req, skb);
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 4/9 mptcp: add port number check for MP_JOIN
This patch adds two new helpers, subflow_use_different_sport and subflow_use_different_dport, to check whether the subflow's source or destination port number is different from the msk's port number. When receiving the MP_JOIN's SYN/SYNACK/ACK, we do these port number checks and print out the different port numbers.
And furthermore, when receiving the MP_JOIN's SYN/ACK, we also use a new helper mptcp_pm_sport_in_anno_list to check whether this port number is announced. If it isn't, we need to abort this connection.
This patch alse populates the local address's port field in local_address.
--- net/mptcp/pm_netlink.c | 23 ++++++++++++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-)
net/mptcp/pm_netlink.c +22 -1
@@ -97,8 +97,8 @@ static bool address_zero(const struct mptcp_addr_info *addr)static void local_address (const struct sock_common *skc,struct mptcp_addr_info *addr) { - addr->port =0 ; addr->family = skc->skc_family; + addr->port =htons (skc->skc_num);if (addr->family ==AF_INET ) addr->addr.s_addr = skc->skc_rcv_saddr;#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -252,6 +252,27 @@ lookup_anno_list_by_saddr(struct mptcp_sock *msk,return NULL ; } +bool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk) +{ +struct mptcp_pm_add_entry *entry; +struct mptcp_addr_info saddr; +bool ret = false; + +local_address ((struct sock_common *)sk, &saddr); + +spin_lock_bh (&msk->pm.lock); +list_for_each_entry (entry, &msk->pm.anno_list, list) { +if (addresses_equal (&entry->addr, &saddr, true)) { + ret = true; + goto out; + } + } + +out: +spin_unlock_bh (&msk->pm.lock); +return ret; +} +static void mptcp_pm_add_timer (struct timer_list *timer) {struct mptcp_pm_add_entry *entry =from_timer (entry, timer, add_timer);
net/mptcp/protocol.h +1 -0
@@ -562,6 +562,7 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,struct mptcp_addr_info *addr, u8 bkup);void mptcp_pm_free_anno_list (struct mptcp_sock *msk); +bool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk);struct mptcp_pm_add_entry *mptcp_pm_del_add_timer (struct mptcp_sock *msk,struct mptcp_addr_info *addr);
net/mptcp/subflow.c +38 -0
@@ -117,6 +117,11 @@ static int __subflow_init_req(struct request_sock *req, const struct sock *sk_lireturn 0 ; } +static bool subflow_use_different_sport (struct mptcp_sock *msk,const struct sock *sk) +{ +return inet_sk (sk)->inet_sport !=inet_sk ((struct sock *)msk)->inet_sport; +} +/* Init mptcp request socket. * * Returns an error code if a JOIN has failed and a TCP reset
@@ -189,6 +194,20 @@ static int subflow_init_req(struct request_sock *req,if (!subflow_req->msk)return -EPERM ; +if (subflow_use_different_sport (subflow_req->msk, sk_listener)) { +pr_debug ("syn inet_sport=%d %d" , +ntohs (inet_sk (sk_listener)->inet_sport), +ntohs (inet_sk ((struct sock *)subflow_req->msk)->inet_sport)); +if (!mptcp_pm_sport_in_anno_list (subflow_req->msk, sk_listener)) { +sock_put ((struct sock *)subflow_req->msk); +mptcp_token_destroy_request (req); + tcp_request_sock_ops.destructor (req); + subflow_req->msk =NULL ; + subflow_req->mp_join =0 ; +return -EPERM ; + } + } +subflow_req_create_thmac (subflow_req);if (unlikely (req->syncookie)) {
@@ -333,6 +352,11 @@ void mptcp_subflow_reset(struct sock *ssk)sock_put (sk); } +static bool subflow_use_different_dport (struct mptcp_sock *msk,const struct sock *sk) +{ +return inet_sk (sk)->inet_dport !=inet_sk ((struct sock *)msk)->inet_dport; +} +static void subflow_finish_connect (struct sock *sk,const struct sk_buff *skb) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);
@@ -398,6 +422,12 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) subflow->mp_join =1 ;MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_JOINSYNACKRX ); + +if (subflow_use_different_dport (mptcp_sk (parent), sk)) { +pr_debug ("synack inet_dport=%d %d" , +ntohs (inet_sk (sk)->inet_dport), +ntohs (inet_sk (parent)->inet_dport)); + } }else if (mptcp_check_fallback (sk)) { fallback:mptcp_rcv_space_init (mptcp_sk (parent), sk);
@@ -660,6 +690,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX );tcp_rsk (req)->drop_req = true; + +if (subflow_use_different_sport (owner, sk)) { +pr_debug ("ack inet_sport=%d %d" , +ntohs (inet_sk (sk)->inet_sport), +ntohs (inet_sk ((struct sock *)owner)->inet_sport)); +if (!mptcp_pm_sport_in_anno_list (owner, sk)) + goto out; + } } }
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 5/9 mptcp: enable use_port when invoke addresses_equal
When dealing with the addresses list local_addr_list or anno_list, we should enable the function addresses_equal's parameter use_port. And enable it in address_zero too.
--- net/mptcp/pm_netlink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/mptcp/pm_netlink.c +4 -4
@@ -91,7 +91,7 @@ static bool address_zero(const struct mptcp_addr_info *addr)memset (&zero,0 ,sizeof (zero)); zero.family = addr->family; -return addresses_equal (addr, &zero, false); +return addresses_equal (addr, &zero, true); } static void local_address(const struct sock_common *skc,
@@ -131,7 +131,7 @@ static bool lookup_subflow_by_saddr(const struct list_head *list, skc = (struct sock_common *)mptcp_subflow_tcp_sock (subflow);local_address (skc, &cur); -if (addresses_equal (&cur, saddr, false)) +if (addresses_equal (&cur, saddr, saddr->port))return true; }
@@ -245,7 +245,7 @@ lookup_anno_list_by_saddr(struct mptcp_sock *msk,struct mptcp_pm_add_entry *entry;list_for_each_entry (entry, &msk->pm.anno_list, list) { -if (addresses_equal (&entry->addr, addr, false)) +if (addresses_equal (&entry->addr, addr, true))return entry; }
@@ -768,7 +768,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)rcu_read_lock ();list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (addresses_equal (&entry->addr, &skc_local, false)) { +if (addresses_equal (&entry->addr, &skc_local, entry->addr.port)) { ret = entry->addr.id;break ; }
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 6/9 mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink
This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing in PM netlink.
--- net/mptcp/pm_netlink.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mptcp/pm_netlink.c +5 -0
@@ -906,6 +906,9 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,if (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]) entry->addr.flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]); +if (tb[MPTCP_PM_ADDR_ATTR_PORT ]) + entry->addr.port =htons (nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_PORT ])); +return 0 ; }
@@ -1167,6 +1170,8 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,if (nla_put_u16 (skb,MPTCP_PM_ADDR_ATTR_FAMILY , addr->family)) goto nla_put_failure; +if (nla_put_u16 (skb,MPTCP_PM_ADDR_ATTR_PORT ,ntohs (addr->port))) + goto nla_put_failure;if (nla_put_u8 (skb,MPTCP_PM_ADDR_ATTR_ID , addr->id)) goto nla_put_failure;if (nla_put_u32 (skb,MPTCP_PM_ADDR_ATTR_FLAGS , entry->addr.flags))
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 7/9 selftests: mptcp: add port argument for pm_nl_ctl
This patch added a new argument for pm_nl_ctl tool. We can use it like this:
# pm_nl_ctl add 10.0.2.1 flags signal port 10100 # pm_nl_ctl dump id 1 flags signal 10.0.2.1 10100
--- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +22 -2
@@ -177,8 +177,8 @@ int add_addr(int fd, int pm_family, int argc, char *argv[]) 1024];struct rtattr *rta, *nest;struct nlmsghdr *nh; +u_int32_t flags =0 ;u_int16_t family; -u_int32_t flags;int nest_start;u_int8_t id;int off =0 ;
@@ -224,7 +224,6 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])char *tok, *str;/* flags */ - flags =0 ;if (++arg >= argc)error (1 ,0 ," missing flags value" );
@@ -272,6 +271,20 @@ int add_addr(int fd, int pm_family, int argc, char *argv[]) rta->rta_len =RTA_LENGTH (4 );memcpy (RTA_DATA (rta), &ifindex,4 ); off +=NLMSG_ALIGN (rta->rta_len); + }else if (!strcmp (argv[arg],"port" )) { +u_int16_t port; + +if (++arg >= argc) +error (1 ,0 ," missing port value" ); +if (!(flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) +error (1 ,0 ," flags must be signal when using port" ); + + port =atoi (argv[arg]); + rta = (void *)(data + off); + rta->rta_type =MPTCP_PM_ADDR_ATTR_PORT ; + rta->rta_len =RTA_LENGTH (2 ); +memcpy (RTA_DATA (rta), &port,2 ); + off +=NLMSG_ALIGN (rta->rta_len); }else error (1 ,0 ,"unknown keyword %s" , argv[arg]); }
@@ -324,6 +337,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])static void print_addr (struct rtattr *attrs,int len) {uint16_t family =0 ; +uint16_t port =0 ;char str[1024 ];uint32_t flags;uint8_t id;
@@ -331,12 +345,16 @@ static void print_addr(struct rtattr *attrs, int len)while (RTA_OK (attrs, len)) {if (attrs->rta_type ==MPTCP_PM_ADDR_ATTR_FAMILY )memcpy (&family,RTA_DATA (attrs),2 ); +if (attrs->rta_type ==MPTCP_PM_ADDR_ATTR_PORT ) +memcpy (&port,RTA_DATA (attrs),2 );if (attrs->rta_type ==MPTCP_PM_ADDR_ATTR_ADDR4 ) {if (family !=AF_INET )error (1 , errno,"wrong IP (v4) for family %d" , family);inet_ntop (AF_INET ,RTA_DATA (attrs), str,sizeof (str));printf ("%s" , str); +if (port) +printf (" %d" , port); }if (attrs->rta_type ==MPTCP_PM_ADDR_ATTR_ADDR6 ) {if (family !=AF_INET6 )
@@ -344,6 +362,8 @@ static void print_addr(struct rtattr *attrs, int len) family);inet_ntop (AF_INET6 ,RTA_DATA (attrs), str,sizeof (str));printf ("%s" , str); +if (port) +printf (" %d" , port); }if (attrs->rta_type ==MPTCP_PM_ADDR_ATTR_ID ) {memcpy (&id,RTA_DATA (attrs),1 );
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 8/9 mptcp: add the mibs for ADD_ADDR with port
This patch added the mibs for ADD_ADDR with port:
MPTCP_MIB_PORTADD for receiving of the ADD_ADDR suboption with a port number.
MPTCP_MIB_PORTSYNRX, MPTCP_MIB_PORTSYNACKRX, MPTCP_MIB_PORTACKRX, for receiving of the MP_JOIN's SYN or SYN/ACK or ACK with a port number which is different from the msk's port number.
MPTCP_MIB_MISMATCHPORTSYNRX and MPTCP_MIB_MISMATCHPORTACKRX, for receiving a SYN or ACK MP_JOIN with a mismatched port-number.
--- net/mptcp/mib.c | 6 ++++++ net/mptcp/mib.h | 6 ++++++ net/mptcp/options.c | 4 ++++ net/mptcp/subflow.c | 8 +++++++- 4 files changed, 23 insertions(+), 1 deletion(-)
net/mptcp/mib.c +6 -0
@@ -29,6 +29,12 @@ static const struct snmp_mib mptcp_snmp_list[] = {SNMP_MIB_ITEM ("DuplicateData" ,MPTCP_MIB_DUPDATA ),SNMP_MIB_ITEM ("AddAddr" ,MPTCP_MIB_ADDADDR ),SNMP_MIB_ITEM ("EchoAdd" ,MPTCP_MIB_ECHOADD ), +SNMP_MIB_ITEM ("PortAdd" ,MPTCP_MIB_PORTADD ), +SNMP_MIB_ITEM ("MPJoinPortSynRx" ,MPTCP_MIB_JOINPORTSYNRX ), +SNMP_MIB_ITEM ("MPJoinPortSynAckRx" ,MPTCP_MIB_JOINPORTSYNACKRX ), +SNMP_MIB_ITEM ("MPJoinPortAckRx" ,MPTCP_MIB_JOINPORTACKRX ), +SNMP_MIB_ITEM ("MismatchPortSynRx" ,MPTCP_MIB_MISMATCHPORTSYNRX ), +SNMP_MIB_ITEM ("MismatchPortAckRx" ,MPTCP_MIB_MISMATCHPORTACKRX ),SNMP_MIB_ITEM ("RmAddr" ,MPTCP_MIB_RMADDR ),SNMP_MIB_ITEM ("RmSubflow" ,MPTCP_MIB_RMSUBFLOW ), SNMP_MIB_ITEM("MPPrioTx", MPTCP_MIB_MPPRIOTX),
net/mptcp/mib.h +6 -0
@@ -22,6 +22,12 @@ enum linux_mptcp_mib_field {MPTCP_MIB_DUPDATA ,/* Segments discarded due to duplicate DSS */ MPTCP_MIB_ADDADDR ,/* Received ADD_ADDR with echo-flag=0 */ MPTCP_MIB_ECHOADD ,/* Received ADD_ADDR with echo-flag=1 */ +MPTCP_MIB_PORTADD ,/* Received ADD_ADDR with a port-number */ +MPTCP_MIB_JOINPORTSYNRX ,/* Received a SYN MP_JOIN with a different port-number */ +MPTCP_MIB_JOINPORTSYNACKRX ,/* Received a SYNACK MP_JOIN with a different port-number */ +MPTCP_MIB_JOINPORTACKRX ,/* Received an ACK MP_JOIN with a different port-number */ +MPTCP_MIB_MISMATCHPORTSYNRX ,/* Received a SYN MP_JOIN with a mismatched port-number */ +MPTCP_MIB_MISMATCHPORTACKRX ,/* Received an ACK MP_JOIN with a mismatched port-number */ MPTCP_MIB_RMADDR ,/* Received RM_ADDR */ MPTCP_MIB_RMSUBFLOW ,/* Remove a subflow */ MPTCP_MIB_MPPRIOTX, /* Transmit a MP_PRIO */
net/mptcp/options.c +4 -0
@@ -1024,6 +1024,10 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)mptcp_pm_del_add_timer (msk, &addr);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_ECHOADD ); } + +if (mp_opt.port) +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_PORTADD ); + mp_opt.add_addr =0 ; }
net/mptcp/subflow.c +7 -1
@@ -204,8 +204,10 @@ static int subflow_init_req(struct request_sock *req, tcp_request_sock_ops.destructor (req); subflow_req->msk =NULL ; subflow_req->mp_join =0 ; +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_MISMATCHPORTSYNRX );return -EPERM ; } +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINPORTSYNRX ); }subflow_req_create_thmac (subflow_req);
@@ -427,6 +429,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)pr_debug ("synack inet_dport=%d %d" ,ntohs (inet_sk (sk)->inet_dport),ntohs (inet_sk (parent)->inet_dport)); +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_JOINPORTSYNACKRX ); } }else if (mptcp_check_fallback (sk)) { fallback:
@@ -695,8 +698,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,pr_debug ("ack inet_sport=%d %d" ,ntohs (inet_sk (sk)->inet_sport),ntohs (inet_sk ((struct sock *)owner)->inet_sport)); -if (!mptcp_pm_sport_in_anno_list (owner, sk)) +if (!mptcp_pm_sport_in_anno_list (owner, sk)) { +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_MISMATCHPORTACKRX ); goto out; + } +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINPORTACKRX ); } } }
Signature · 1 line
2.29.2
Geliang Tang
PATCH v9 9/9 selftests: mptcp: add testcases for ADD_ADDR with port
This patch added testcases for ADD_ADDR with port and the related MIB counters check in chk_add_nr. The output looks like this:
24 signal address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
25 subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
26 remove single address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
rm [ ok ] - sf [ ok ]
--- .../testing/selftests/net/mptcp/mptcp_join.sh | 160 +++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +159 -1
@@ -487,6 +487,12 @@ chk_add_nr() { local add_nr=$1 local echo_nr=$2 + local port_nr=${3:-0} + local syn_nr=${4:-$port_nr} + local syn_ack_nr=${5:-$port_nr} + local ack_nr=${6:-$port_nr} + local mis_syn_nr=${7:-0} + local mis_ack_nr=${8:-0} local count local dump_stats
@@ -509,7 +515,87 @@ chk_add_nr() ret=1 dump_stats=1 else - echo "[ ok ]" + echo -n "[ ok ]" + fi + + if [ $port_nr -gt 0 ]; then + echo -n " - pt " + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$port_nr" ]; then + echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a different \ + port-number expected $syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - synack" + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_ack_nr" ]; then + echo "[fail] got $count JOIN[s] synack with a different \ + port-number expected $syn_ack_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a different \ + port-number expected $ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a mismatched \ + port-number expected $mis_syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack " + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a mismatched \ + port-number expected $mis_ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + else + echo "" fi if [ "${dump_stats}" = 1 ]; then
@@ -955,6 +1041,78 @@ chk_join_nr "single address, backup" 1 1 1 chk_add_nr 1 1 chk_prio_nr 1 0 +# signal address with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "signal address with port" 1 1 1 +chk_add_nr 1 1 1 + +# subflow and signal with port +reset +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 + +# single address with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow +chk_join_nr "remove single address with port" 1 1 1 +chk_add_nr 1 1 1 +chk_rm_nr 0 0 + +# subflow and signal with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow +chk_join_nr "remove subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 +chk_rm_nr 1 1 + +# subflows and signal with port, flush +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 3 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 3 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow +chk_join_nr "flush subflows and signal with port" 3 3 3 +chk_add_nr 1 1 +chk_rm_nr 2 2 + +# multiple addresses with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with port" 2 2 2 +chk_add_nr 2 2 2 + +# multiple addresses with ports +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with ports" 2 2 2 +chk_add_nr 2 2 2 + # single subflow, syncookies reset_with_cookies ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.29.2
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v9 mptcp-next 9/9] selftests: mptcp: add testcases for ADD_ADDR with port
Quoted 40 lines · Geliang Tang
This patch added testcases for
ADD_ADDRwith port and the related MIB counters check inchk_add_nr. The output looks like this:24 signal address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
25 subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
26 remove single address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
rm [ ok ] - sf [ ok ]Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
.../testing/selftests/net/mptcp/mptcp_join.sh| 160 +++++++++++++++++-1 file changed, 159 insertions(+), 1 deletion(-)tools/testing/selftests/net/mptcp/mptcp_join.sh +6
-0@@ -487,6 +487,12 @@ chk_add_nr() { local add_nr=$1 local echo_nr=$2 + local port_nr=${3:-0} + local syn_nr=${4:-$port_nr} + local syn_ack_nr=${5:-$port_nr} + local ack_nr=${6:-$port_nr} + local mis_syn_nr=${7:-0} + local mis_ack_nr=${8:-0} local count local dump_stats
tools/testing/selftests/net/mptcp/mptcp_join.sh chk_add_nr() · line 521
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +4
-1@@ -509,7 +515,87 @@ chk_add_nr() ret=1 dump_stats=1 else - echo "[ ok ]" + echo -n "[ ok ]" + fi + + if [ $port_nr -gt 0 ]; then
I get a lot of these errors in the existing tests:
./mptcp_join.sh: line 524: [: -gt: unary operator expected
Quoted 126 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +77
-0+ echo -n " - pt " + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$port_nr" ]; then + echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a different \ + port-number expected $syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - synack" + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_ack_nr" ]; then + echo "[fail] got $count JOIN[s] synack with a different \ + port-number expected $syn_ack_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a different \ + port-number expected $ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a mismatched \ + port-number expected $mis_syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack " + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a mismatched \ + port-number expected $mis_ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + else + echo "" fi if [ "${dump_stats}" = 1 ]; then@@ -955,6 +1041,78 @@ chk_join_nr "single address, backup" 1 1 1
chk_add_nr1 1chk_prio_nr1 0tools/testing/selftests/net/mptcp/mptcp_join.sh +42
-0+# signal address with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "signal address with port" 1 1 1 +chk_add_nr 1 1 1 + +# subflow and signal with port +reset +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 + +# single address with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow +chk_join_nr "remove single address with port" 1 1 1 +chk_add_nr 1 1 1 +chk_rm_nr 0 0 + +# subflow and signal with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow +chk_join_nr "remove subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 +chk_rm_nr 1 1 + +# subflows and signal with port, flush +reset
tools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "single address, backup" 1 1 1 · line 1095
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +10
-0+ip netns exec $ns1 ./pm_nl_ctl limits 0 3 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 3 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow +chk_join_nr "flush subflows and signal with port" 3 3 3 +chk_add_nr 1 1 +chk_rm_nr 2 2 +
These last two tests failed for me:
38 remove subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] rm [fail] got 0 RM_ADDR[s]
expected 1
- sf [fail] got 0 RM_SUBFLOW[s] expected 1
./mptcp_join.sh: line 524: [: -gt: unary operator expected
Server ns stats
MPTcpExtMPCapableSYNRX 1 0.0 MPTcpExtMPCapableACKRX 1 0.0 MPTcpExtMPJoinSynRx 2 0.0 MPTcpExtMPJoinAckRx 2 0.0 MPTcpExtEchoAdd 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynRx 1 0.0 MPTcpExtMPJoinPortAckRx 1 0.0 Client ns stats MPTcpExtMPJoinSynAckRx 2 0.0 MPTcpExtAddAddr 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynAckRx 1 0.0
39 flush subflows and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] rm [fail] got 0 RM_ADDR[s]
expected 2
- sf [fail] got 0 RM_SUBFLOW[s] expected 2
./mptcp_join.sh: line 524: [: -gt: unary operator expected
Server ns stats
MPTcpExtMPCapableSYNRX 1 0.0 MPTcpExtMPCapableACKRX 1 0.0 MPTcpExtMPJoinSynRx 3 0.0 MPTcpExtMPJoinAckRx 3 0.0 MPTcpExtEchoAdd 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynRx 1 0.0 MPTcpExtMPJoinPortAckRx 1 0.0 Client ns stats MPTcpExtMPJoinSynAckRx 3 0.0 MPTcpExtAddAddr 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynAckRx 1 0.0
Are these passing for you with the latest export branch?
Quoted 20 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +20
-0+# multiple addresses with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with port" 2 2 2 +chk_add_nr 2 2 2 + +# multiple addresses with ports +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with ports" 2 2 2 +chk_add_nr 2 2 2 +
Quoted 9 lines
# single subflow, syncookies reset_with_cookies ip netns exec $ns1 ./pm_nl_ctl limits 0 1Signature · 4 lines
2.29.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
--
Mat Martineau
Intel
Geliang Tang
[MPTCP] Re: [MPTCP][PATCH v9 mptcp-next 9/9] selftests: mptcp: add testcases for ADD_ADDR with port
Hi Mat,
Quoted 243 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2021年1月9日周六 上午7:01写道:
Quoted 40 lines · Geliang Tang
This patch added testcases for
ADD_ADDRwith port and the related MIB counters check inchk_add_nr. The output looks like this:24 signal address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
25 subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
26 remove single address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ] syn[ ok ] - synack[ ok ] - ack[ ok ]
syn[ ok ] - ack [ ok ]
rm [ ok ] - sf [ ok ]Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
.../testing/selftests/net/mptcp/mptcp_join.sh| 160 +++++++++++++++++-1 file changed, 159 insertions(+), 1 deletion(-)tools/testing/selftests/net/mptcp/mptcp_join.sh +6
-0@@ -487,6 +487,12 @@ chk_add_nr() { local add_nr=$1 local echo_nr=$2 + local port_nr=${3:-0} + local syn_nr=${4:-$port_nr} + local syn_ack_nr=${5:-$port_nr} + local ack_nr=${6:-$port_nr} + local mis_syn_nr=${7:-0} + local mis_ack_nr=${8:-0} local count local dump_statstools/testing/selftests/net/mptcp/mptcp_join.sh chk_add_nr() · line 521
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +4
-1@@ -509,7 +515,87 @@ chk_add_nr() ret=1 dump_stats=1 else - echo "[ ok ]" + echo -n "[ ok ]" + fi + + if [ $port_nr -gt 0 ]; thenI get a lot of these errors in the existing tests:
./mptcp_join.sh: line 524: [: -gt: unary operator expected
Quoted 126 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +77
-0+ echo -n " - pt " + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$port_nr" ]; then + echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a different \ + port-number expected $syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - synack" + count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$syn_ack_nr" ]; then + echo "[fail] got $count JOIN[s] synack with a different \ + port-number expected $syn_ack_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a different \ + port-number expected $ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + + printf "%-39s %s" " " "syn" + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_syn_nr" ]; then + echo "[fail] got $count JOIN[s] syn with a mismatched \ + port-number expected $mis_syn_nr" + ret=1 + dump_stats=1 + else + echo -n "[ ok ]" + fi + + echo -n " - ack " + count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | + awk '{print $2}'` + [ -z "$count" ] && count=0 + if [ "$count" != "$mis_ack_nr" ]; then + echo "[fail] got $count JOIN[s] ack with a mismatched \ + port-number expected $mis_ack_nr" + ret=1 + dump_stats=1 + else + echo "[ ok ]" + fi + else + echo "" fi if [ "${dump_stats}" = 1 ]; then@@ -955,6 +1041,78 @@ chk_join_nr "single address, backup" 1 1 1
chk_add_nr1 1chk_prio_nr1 0tools/testing/selftests/net/mptcp/mptcp_join.sh +42
-0+# signal address with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "signal address with port" 1 1 1 +chk_add_nr 1 1 1 + +# subflow and signal with port +reset +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 + +# single address with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 1 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 1 +run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow +chk_join_nr "remove single address with port" 1 1 1 +chk_add_nr 1 1 1 +chk_rm_nr 0 0 + +# subflow and signal with port, remove +reset +ip netns exec $ns1 ./pm_nl_ctl limits 0 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 2 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow +chk_join_nr "remove subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 +chk_rm_nr 1 1 + +# subflows and signal with port, flush +resettools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "single address, backup" 1 1 1 · line 1095
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +10
-0+ip netns exec $ns1 ./pm_nl_ctl limits 0 3 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 1 3 +ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow +ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow +run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow +chk_join_nr "flush subflows and signal with port" 3 3 3 +chk_add_nr 1 1 +chk_rm_nr 2 2 +These last two tests failed for me:
38 remove subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] rm [fail] got 0 RM_ADDR[s]
expected 1
- sf [fail] got 0 RM_SUBFLOW[s] expected 1
./mptcp_join.sh: line 524: [: -gt: unary operator expectedServer ns stats
MPTcpExtMPCapableSYNRX 1 0.0 MPTcpExtMPCapableACKRX 1 0.0 MPTcpExtMPJoinSynRx 2 0.0 MPTcpExtMPJoinAckRx 2 0.0 MPTcpExtEchoAdd 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynRx 1 0.0 MPTcpExtMPJoinPortAckRx 1 0.0 Client ns stats MPTcpExtMPJoinSynAckRx 2 0.0 MPTcpExtAddAddr 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynAckRx 1 0.039 flush subflows and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] rm [fail] got 0 RM_ADDR[s]
expected 2
- sf [fail] got 0 RM_SUBFLOW[s] expected 2
./mptcp_join.sh: line 524: [: -gt: unary operator expectedServer ns stats
MPTcpExtMPCapableSYNRX 1 0.0 MPTcpExtMPCapableACKRX 1 0.0 MPTcpExtMPJoinSynRx 3 0.0 MPTcpExtMPJoinAckRx 3 0.0 MPTcpExtEchoAdd 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynRx 1 0.0 MPTcpExtMPJoinPortAckRx 1 0.0 Client ns stats MPTcpExtMPJoinSynAckRx 3 0.0 MPTcpExtAddAddr 1 0.0 MPTcpExtPortAdd 1 0.0 MPTcpExtMPJoinPortSynAckRx 1 0.0
Quoted 1 line
Are these passing for you with the latest export branch?
Sorry, please apply the patchset (mptcp: create subflow for newly added address and testcases) first, then these testcases will pass.
Thanks,
-Geliang
Quoted 35 lines
Quoted 22 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +20
-0+# multiple addresses with port +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with port" 2 2 2 +chk_add_nr 2 2 2 + +# multiple addresses with ports +reset +ip netns exec $ns1 ./pm_nl_ctl limits 2 2 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100 +ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101 +ip netns exec $ns2 ./pm_nl_ctl limits 2 2 +run_tests $ns1 $ns2 10.0.1.1 +chk_join_nr "multiple addresses with ports" 2 2 2 +chk_add_nr 2 2 2 +Quoted 9 lines
# single subflow, syncookies reset_with_cookies ip netns exec $ns1 ./pm_nl_ctl limits 0 1 -- 2.29.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org--
Mat Martineau
Intel
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v9 mptcp-next 1/9] mptcp: create the listening socket for new port
In reply to Geliang TangQuoted 133 lines · Geliang Tang
This patch created a listening socket when an address with a port-number is added by PM netlink. Then binded the new port to the socket, and listened for the connection.
When the address is removed or the addresses are flushed by PM netlink, release the listening socket.
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
net/mptcp/pm_netlink.c | 96 +++++++++++++++++++++++++++++++++++++++++- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++ net/mptcp/subflow.c | 6 +-- 4 files changed, 102 insertions(+), 6 deletions(-)net/mptcp/pm_netlink.c +79
-0@@ -26,6 +26,7 @@ struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr;struct rcu_head rcu; +struct socket *lsk; };struct mptcp_pm_add_entry {@@ -673,6 +674,53 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,return ret; } +static int mptcp_pm_nl_create_listen_socket (struct sock *sk, +struct mptcp_pm_addr_entry *entry) +{ +struct sockaddr_storage addr; +struct mptcp_sock *msk; +struct socket *ssock; +int backlog =1024 ; +int err; + + err =sock_create_kern (sock_net (sk), entry->addr.family, +SOCK_STREAM ,IPPROTO_MPTCP , &entry->lsk); +if (err) +return err; + + msk =mptcp_sk (entry->lsk->sk); +if (!msk) { + err = -EINVAL ; + goto out; + } + + ssock =__mptcp_nmpc_socket (msk); +if (!ssock) { + err = -EINVAL ; + goto out; + } + +mptcp_info2sockaddr (&entry->addr, &addr, entry->addr.family); + err =kernel_bind (ssock, (struct sockaddr *)&addr, +sizeof (struct sockaddr_in )); +if (err) { +pr_warn ("kernel_bind error, err=%d" , err); + goto out; + } + + err =kernel_listen (ssock, backlog); +if (err) { +pr_warn ("kernel_listen error, err=%d" , err); + goto out; + } + +return 0 ; + +out: +sock_release (entry->lsk); +return err; +} +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct sock_common *skc) {struct mptcp_pm_addr_entry *entry;@@ -717,6 +765,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) entry->addr.ifindex =0 ; entry->addr.flags =0 ; entry->addr.id =0 ; + entry->addr.port =0 ; + entry->lsk =NULL ; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )kfree (entry);@@ -886,9 +936,19 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) } *entry = addr; +if (entry->addr.port) { + ret =mptcp_pm_nl_create_listen_socket (skb->sk, entry); +if (ret) { +GENL_SET_ERR_MSG (info,"create listen socket error" ); +kfree (entry); +return ret; + } + } ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 ) {GENL_SET_ERR_MSG (info,"too many addresses or duplicate one" ); +if (entry->lsk) +sock_release (entry->lsk);kfree (entry);return ret; }@@ -972,6 +1032,38 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,return 0 ; } +struct addr_entry_release_work { +struct rcu_work rwork; +struct mptcp_pm_addr_entry *entry; +}; + +static void mptcp_pm_release_addr_entry (struct work_struct *work) +{ +struct addr_entry_release_work *w; +struct mptcp_pm_addr_entry *entry; + + w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork); + entry = w->entry; +if (entry) { +if (entry->lsk) +sock_release (entry->lsk); +kfree (entry); + } +kfree (w); +}
net/mptcp/pm_netlink.c static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, · line 1063
Quoted 10 lines
net/mptcp/pm_netlink.c +10
-0+ +static void mptcp_pm_free_addr_entry (struct mptcp_pm_addr_entry *entry) +{ +struct addr_entry_release_work *w; + + w =kmalloc (sizeof (*w),GFP_ATOMIC ); +if (w) { +INIT_RCU_WORK ((struct rcu_work *)w, mptcp_pm_release_addr_entry); + w->entry = entry; +queue_rcu_work (system_wq, (struct rcu_work *)w);
Rather than casting the second arg, please use &w->rwork
Thanks,
Mat
Quoted 80 lines
net/mptcp/pm_netlink.c +5
-2+ } +} +static int mptcp_nl_cmd_del_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];@@ -1001,7 +1093,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)spin_unlock_bh (&pernet->lock);mptcp_nl_remove_subflow_and_signal_addr (sock_net (skb->sk), &entry->addr); -kfree_rcu (entry, rcu); +mptcp_pm_free_addr_entry (entry);return ret; }@@ -1015,7 +1107,7 @@ static void __flush_addrs(struct net *net, struct list_head *list) struct mptcp_pm_addr_entry, list);mptcp_nl_remove_subflow_and_signal_addr (net, &cur->addr);list_del_rcu (&cur->list); -kfree_rcu (cur, rcu); +mptcp_pm_free_addr_entry (cur); } }net/mptcp/protocol.c +1
-1@@ -49,7 +49,7 @@ static void __mptcp_check_send_data_fin(struct sock *sk);* completed yet or has failed, return the subflow socket. * Otherwise return NULL. */ -static struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) {if (!msk->subflow ||READ_ONCE (msk->can_ack))return NULL ;net/mptcp/protocol.h +4
-0@@ -469,11 +469,15 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);void __mptcp_close_ssk (struct sock *sk,struct sock *ssk,struct mptcp_subflow_context *subflow);void mptcp_subflow_reset (struct sock *ssk); +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk);/* called with sk socket lock held */ int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_addr_info *loc,const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family);static inline void mptcp_subflow_tcp_fallback (struct sock *sk,struct mptcp_subflow_context *ctx)net/mptcp/subflow.c +3
-3@@ -1073,9 +1073,9 @@ void mptcpv6_handle_mapped(struct sock *sk, bool mapped) }#endif -static void mptcp_info2sockaddr (const struct mptcp_addr_info *info, -struct sockaddr_storage *addr, -unsigned short family) +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family) {memset (addr,0 ,sizeof (*addr)); addr->ss_family = family;Signature · 4 lines
2.29.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
--
Mat Martineau
Intel
Geliang Tang
[MPTCP] Re: [MPTCP][PATCH v9 mptcp-next 1/9] mptcp: create the listening socket for new port
Hi Mat,
Quoted 140 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2021年1月9日周六 上午6:56写道:
Quoted 137 lines · Geliang Tang
This patch created a listening socket when an address with a port-number is added by PM netlink. Then binded the new port to the socket, and listened for the connection.
When the address is removed or the addresses are flushed by PM netlink, release the listening socket.
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
net/mptcp/pm_netlink.c | 96 +++++++++++++++++++++++++++++++++++++++++- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++ net/mptcp/subflow.c | 6 +-- 4 files changed, 102 insertions(+), 6 deletions(-)net/mptcp/pm_netlink.c +83
-0@@ -26,6 +26,7 @@ struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr;struct rcu_head rcu; +struct socket *lsk; };struct mptcp_pm_add_entry {@@ -673,6 +674,53 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,return ret; } +static int mptcp_pm_nl_create_listen_socket (struct sock *sk, +struct mptcp_pm_addr_entry *entry) +{ +struct sockaddr_storage addr; +struct mptcp_sock *msk; +struct socket *ssock; +int backlog =1024 ; +int err; + + err =sock_create_kern (sock_net (sk), entry->addr.family, +SOCK_STREAM ,IPPROTO_MPTCP , &entry->lsk); +if (err) +return err; + + msk =mptcp_sk (entry->lsk->sk); +if (!msk) { + err = -EINVAL ; + goto out; + } + + ssock =__mptcp_nmpc_socket (msk); +if (!ssock) { + err = -EINVAL ; + goto out; + } + +mptcp_info2sockaddr (&entry->addr, &addr, entry->addr.family); + err =kernel_bind (ssock, (struct sockaddr *)&addr, +sizeof (struct sockaddr_in )); +if (err) { +pr_warn ("kernel_bind error, err=%d" , err); + goto out; + } + + err =kernel_listen (ssock, backlog); +if (err) { +pr_warn ("kernel_listen error, err=%d" , err); + goto out; + } + +return 0 ; + +out: +sock_release (entry->lsk); +return err; +} +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct sock_common *skc) {struct mptcp_pm_addr_entry *entry;@@ -717,6 +765,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) entry->addr.ifindex =0 ; entry->addr.flags =0 ; entry->addr.id =0 ; + entry->addr.port =0 ; + entry->lsk =NULL ; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )kfree (entry);@@ -886,9 +936,19 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) } *entry = addr; +if (entry->addr.port) { + ret =mptcp_pm_nl_create_listen_socket (skb->sk, entry); +if (ret) { +GENL_SET_ERR_MSG (info,"create listen socket error" ); +kfree (entry); +return ret; + } + } ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 ) {GENL_SET_ERR_MSG (info,"too many addresses or duplicate one" ); +if (entry->lsk) +sock_release (entry->lsk);kfree (entry);return ret; }@@ -972,6 +1032,38 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,return 0 ; } +struct addr_entry_release_work { +struct rcu_work rwork; +struct mptcp_pm_addr_entry *entry; +}; + +static void mptcp_pm_release_addr_entry (struct work_struct *work) +{ +struct addr_entry_release_work *w; +struct mptcp_pm_addr_entry *entry; + + w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork); + entry = w->entry; +if (entry) { +if (entry->lsk) +sock_release (entry->lsk); +kfree (entry); + } +kfree (w); +} + +static void mptcp_pm_free_addr_entry (struct mptcp_pm_addr_entry *entry) +{ +struct addr_entry_release_work *w;
Quoted 9 lines
net/mptcp/pm_netlink.c static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, · line 1063
Quoted 6 lines
net/mptcp/pm_netlink.c +6
-0+ + w =kmalloc (sizeof (*w),GFP_ATOMIC ); +if (w) { +INIT_RCU_WORK ((struct rcu_work *)w, mptcp_pm_release_addr_entry); + w->entry = entry; +queue_rcu_work (system_wq, (struct rcu_work *)w);Rather than casting the second arg, please use
&w->rwork
May I send a squash-to patch to fix this?
-Geliang
Quoted 90 lines
Thanks,
Mat
Quoted 75 lines
net/mptcp/pm_netlink.c +5
-2+ } +} +static int mptcp_nl_cmd_del_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];@@ -1001,7 +1093,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)spin_unlock_bh (&pernet->lock);mptcp_nl_remove_subflow_and_signal_addr (sock_net (skb->sk), &entry->addr); -kfree_rcu (entry, rcu); +mptcp_pm_free_addr_entry (entry);return ret; }@@ -1015,7 +1107,7 @@ static void __flush_addrs(struct net *net, struct list_head *list) struct mptcp_pm_addr_entry, list);mptcp_nl_remove_subflow_and_signal_addr (net, &cur->addr);list_del_rcu (&cur->list); -kfree_rcu (cur, rcu); +mptcp_pm_free_addr_entry (cur); } }net/mptcp/protocol.c +1
-1@@ -49,7 +49,7 @@ static void __mptcp_check_send_data_fin(struct sock *sk);* completed yet or has failed, return the subflow socket. * Otherwise return NULL. */ -static struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) {if (!msk->subflow ||READ_ONCE (msk->can_ack))return NULL ;net/mptcp/protocol.h +4
-0@@ -469,11 +469,15 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);void __mptcp_close_ssk (struct sock *sk,struct sock *ssk,struct mptcp_subflow_context *subflow);void mptcp_subflow_reset (struct sock *ssk); +struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk);/* called with sk socket lock held */ int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_addr_info *loc,const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family);static inline void mptcp_subflow_tcp_fallback (struct sock *sk,struct mptcp_subflow_context *ctx)net/mptcp/subflow.c +3
-4@@ -1073,9 +1073,9 @@ void mptcpv6_handle_mapped(struct sock *sk, bool mapped) }#endif -static void mptcp_info2sockaddr (const struct mptcp_addr_info *info, -struct sockaddr_storage *addr, -unsigned short family) +void mptcp_info2sockaddr (const struct mptcp_addr_info *info, +struct sockaddr_storage *addr, +unsigned short family) {memset (addr,0 ,sizeof (*addr)); addr->ss_family = family; --Quoted 5 lines
2.29.2
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org--
Mat Martineau
Intel
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v9 mptcp-next 1/9] mptcp: create the listening socket for new port
Quoted 20 lines · Geliang Tang
Hi Mat,
Quoted 17 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2021年1月9日周六 上午6:56写道:
Quoted 14 lines · Geliang Tang
This patch created a listening socket when an address with a port-number is added by PM netlink. Then binded the new port to the socket, and listened for the connection.
When the address is removed or the addresses are flushed by PM netlink, release the listening socket.
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
net/mptcp/pm_netlink.c | 96 +++++++++++++++++++++++++++++++++++++++++- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++ net/mptcp/subflow.c | 6 +-- 4 files changed, 102 insertions(+), 6 deletions(-)
...
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
net/mptcp/pm_netlink.c +23
-0@@ -972,6 +1032,38 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,return 0 ; } +struct addr_entry_release_work { +struct rcu_work rwork; +struct mptcp_pm_addr_entry *entry; +}; + +static void mptcp_pm_release_addr_entry (struct work_struct *work) +{ +struct addr_entry_release_work *w; +struct mptcp_pm_addr_entry *entry; + + w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork); + entry = w->entry; +if (entry) { +if (entry->lsk) +sock_release (entry->lsk); +kfree (entry); + } +kfree (w); +} + +static void mptcp_pm_free_addr_entry (struct mptcp_pm_addr_entry *entry) +{ +struct addr_entry_release_work *w;Quoted 9 lines
net/mptcp/pm_netlink.c static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, · line 1063
Quoted 6 lines
net/mptcp/pm_netlink.c +6
-0+ + w =kmalloc (sizeof (*w),GFP_ATOMIC ); +if (w) { +INIT_RCU_WORK ((struct rcu_work *)w, mptcp_pm_release_addr_entry); + w->entry = entry; +queue_rcu_work (system_wq, (struct rcu_work *)w);Rather than casting the second arg, please use
&w->rwork
Quoted 2 lines
May I send a squash-to patch to fix this?
Hi Geliang -
Since I'm asking for a rebased version of this series anyway (to get rid of all the 'git am' conflicts in the pending patch sets), please include this change in v10.
Thanks,
--
Mat Martineau
Intel
Mat Martineau
Quoted 7 lines · Geliang Tang
v9:
- usequeue_rcu_workto release the listening socket.
- squash v8's patch 2 with patch 3.
- add two new patches, "mptcp: drop unused skb insubflow_token_join_request" and "mptcp: add a new helpersubflow_req_create_thmac"
Hi Geliang -
I'd like to make a request to make review easier: Please include in the cover letter the base commit where the patches apply successfully, or a reference to a public git repo showing the full commit history. It took some trial and error to figure out that this patch set only applied on top of the export branch with the "add-IPv4-mapped address support v4" patch set applied too.
For example, referencing the export tag from the mptcp_net-next repo (like export/20201217T083536) and the patch set name and revision for any prerequisite patch sets would really help.
Thanks!
--
Mat Martineau
Intel
Geliang Tang
Hi Mat,
Quoted 21 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2021年1月9日周六 上午7:19写道:
Quoted 7 lines · Geliang Tang
v9:
- usequeue_rcu_workto release the listening socket.
- squash v8's patch 2 with patch 3.
- add two new patches, "mptcp: drop unused skb insubflow_token_join_request" and "mptcp: add a new helpersubflow_req_create_thmac"Hi Geliang -
I'd like to make a request to make review easier: Please include in the cover letter the base commit where the patches apply successfully, or a reference to a public git repo showing the full commit history. It took some trial and error to figure out that this patch set only applied on top of the export branch with the "add-IPv4-mapped address support v4" patch set applied too.
Quoted 3 lines
For example, referencing the export tag from the mptcp_net-next repo (like export/20201217T083536) and the patch set name and revision for any prerequisite patch sets would really help.
Sorry for the trouble, I just sent my commit log to you.
Thanks.
-Geliang
Quoted 6 lines
Thanks!
--
Mat Martineau
Intel