ADD_ADDR: ports support
Subsystems (3)
Geliang Tang
v10 cover ADD_ADDR: ports support
v10:
- use &w->rwork in mptcp_pm_free_addr_entry instead of casting w
- rebase on export/20210113T185637
- please apply this patchset after the following patchsets:
add IPv4-mapped address support (v5)
mptcp: create subflow for newly added address and testcases (v5)
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 v10 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 {
@@ -677,6 +678,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;
@@ -721,6 +769,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);
@@ -890,9 +940,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; }
@@ -976,6 +1036,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 (&w->rwork, mptcp_pm_release_addr_entry); + w->entry = entry; +queue_rcu_work (system_wq, &w->rwork); + } +} +static int mptcp_nl_cmd_del_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];
@@ -1010,7 +1102,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; }
@@ -1024,7 +1116,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
@@ -470,11 +470,15 @@ void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, struct mptcp_subflow_context *subflow);void mptcp_subflow_reset (struct sock *ssk);void mptcp_sock_graft (struct sock *sk,struct socket *parent); +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
@@ -1080,9 +1080,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 v10 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 v10 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 v10 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 )
@@ -251,6 +251,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
@@ -582,6 +582,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);
@@ -399,6 +423,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);
@@ -661,6 +691,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 v10 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; }
@@ -244,7 +244,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; }
@@ -772,7 +772,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 v10 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
@@ -910,6 +910,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 ; }
@@ -1176,6 +1179,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 v10 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 v10 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);
@@ -428,6 +430,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:
@@ -696,8 +699,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 v10 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
Quoted 7 lines · Geliang Tang
v10:
- use&w->rworkinmptcp_pm_free_addr_entryinstead of casting w
- rebase on export/20210113T185637
- please apply this patchset after the following patchsets:
add IPv4-mapped address support (v5)
mptcp: create subflow for newly added address and testcases (v5)
Hi Geliang -
v10 looks ready for the export branch. Thanks for the fixes!
--
Mat Martineau
Intel
Matthieu Baerts
Hi Geliang, Mat,
Quoted 11 lines · Mat Martineau
Quoted 7 lines · Geliang Tang
v10:
- use&w->rworkinmptcp_pm_free_addr_entryinstead of casting w
- rebase on export/20210113T185637
- please apply this patchset after the following patchsets:
add IPv4-mapped address support (v5)
mptcp: create subflow for newly added address and testcases (v5)v10 looks ready for the export branch. Thanks for the fixes!
Thank you for the nice new feature and reviews!
Just added in our repo with Mat's RvB tags (and one typo detected by "checkpatch.pl --codespell").
Tests + export are in progress!
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Matthieu Baerts
Quoted 13 lines · Matthieu Baerts
Hi Geliang, Mat,
Quoted 10 lines · Mat Martineau
Quoted 7 lines · Geliang Tang
v10:
- use&w->rworkinmptcp_pm_free_addr_entryinstead of casting w
- rebase on export/20210113T185637
- please apply this patchset after the following patchsets:
add IPv4-mapped address support (v5)
mptcp: create subflow for newly added address and testcases (v5)
Quoted 6 lines
Quoted 1 line
v10 looks ready for the export branch. Thanks for the fixes!
Thank you for the nice new feature and reviews!
Just added in our repo with Mat's RvB tags (and one typo detected by "checkpatch.pl --codespell").
(I forgot the refs, just in case)
- 439600160048: mptcp: create the listening socket for new port
- 3122c6542e4f: mptcp: drop unused skb in subflow_token_join_request
- 9dfc9b337d4f: mptcp: add a new helper subflow_req_create_thmac
- 551edb8d92ab: mptcp: add port number check for MP_JOIN
- 3f96f48fbd19: mptcp: enable use_port when invoke addresses_equal
- 60e993388f4f: mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink
- 7e876f36d164: selftests: mptcp: add port argument for pm_nl_ctl
- e7b4ca22e5fb: mptcp: add the mibs for ADD_ADDR with port
- 4eed52217818: selftests: mptcp: add testcases for ADD_ADDR with port
- Results: 2535f605affc..5f5277ef3bf4
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net