ADD_ADDR: ports support
Subsystems (3)
Geliang Tang
v3 cover ADD_ADDR: ports support
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 (12):
mptcp: unify ADD_ADDR and echo suboptions writing
mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing
mptcp: add port support for ADD_ADDR suboption writing
mptcp: use adding up size to get ADD_ADDR length
mptcp: add the outgoing ADD_ADDR port support
mptcp: send out dedicated packet for ADD_ADDR using port
mptcp: add port parameter for mptcp_pm_announce_addr
mptcp: print out port and ahmac when receiving ADD_ADDR
mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink
selftests: mptcp: add port argument for pm_nl_ctl
mptcp: add the mib for ADD_ADDR with port
selftests: mptcp: add testcases for ADD_ADDR with port
include/net/mptcp.h | 1 + net/mptcp/mib.c | 1 + net/mptcp/mib.h | 1 + net/mptcp/options.c | 104 +++++++++++------- net/mptcp/pm.c | 14 ++- net/mptcp/pm_netlink.c | 28 ++++- net/mptcp/protocol.h | 37 +++++-- .../testing/selftests/net/mptcp/mptcp_join.sh | 61 +++++++++- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 24 +++- 9 files changed, 207 insertions(+), 64 deletions(-)
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 1/12 mptcp: unify ADD_ADDR and echo suboptions writing
There are two differences between ADD_ADDR suboption and ADD_ADDR echo
suboption: The length of the former is 8 octets longer than the length of the latter. The former's echo-flag is 0, and latter's echo-flag is 1.
This patch added two local variables, len and echo, to unify ADD_ADDR and ADD_ADDR echo suboptions writing.
--- net/mptcp/options.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
net/mptcp/options.c +19 -18
@@ -1067,15 +1067,16 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, mp_capable_done:if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { -if (opts->ahmac) - *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , -TCPOLEN_MPTCP_ADD_ADDR ,0 , - opts->addr_id); -else - *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , -TCPOLEN_MPTCP_ADD_ADDR_BASE , -MPTCP_ADDR_ECHO , - opts->addr_id); +u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ; +u8 echo =MPTCP_ADDR_ECHO ; + +if (opts->ahmac) { + len +=sizeof (opts->ahmac); + echo =0 ; + } + + *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , + len, echo, opts->addr_id);memcpy ((u8 *)ptr, (u8 *)&opts->addr.s_addr,4 ); ptr +=1 ;if (opts->ahmac) {
@@ -1086,15 +1087,15 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { -if (opts->ahmac) - *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , -TCPOLEN_MPTCP_ADD_ADDR6 ,0 , - opts->addr_id); -else - *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , -TCPOLEN_MPTCP_ADD_ADDR6_BASE , -MPTCP_ADDR_ECHO , - opts->addr_id); +u8 len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; +u8 echo =MPTCP_ADDR_ECHO ; + +if (opts->ahmac) { + len +=sizeof (opts->ahmac); + echo =0 ; + } + *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , + len, echo, opts->addr_id);memcpy ((u8 *)ptr, opts->addr6.s6_addr,16 ); ptr +=4 ;if (opts->ahmac) {
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 2/12 mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing
The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the only difference between them.
This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6 suboptions writing, and unify them into one.
--- net/mptcp/options.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
net/mptcp/options.c +17 -20
@@ -1066,10 +1066,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, } mp_capable_done: -if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { + if ((OPTION_MPTCP_ADD_ADDR +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + |OPTION_MPTCP_ADD_ADDR6 +#endif + ) & opts->suboptions) {u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;u8 echo =MPTCP_ADDR_ECHO ; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) + len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; +#endif +if (opts->ahmac) { len +=sizeof (opts->ahmac); echo =0 ;
@@ -1077,33 +1086,21 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , len, echo, opts->addr_id); -memcpy ((u8 *)ptr, (u8 *)&opts->addr.s_addr,4 ); - ptr +=1 ; -if (opts->ahmac) { -put_unaligned_be64 (opts->ahmac, ptr); - ptr +=2 ; +if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { +memcpy ((u8 *)ptr, (u8 *)&opts->addr.s_addr,4 ); + ptr +=1 ; } - } -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { -u8 len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; -u8 echo =MPTCP_ADDR_ECHO ; - -if (opts->ahmac) { - len +=sizeof (opts->ahmac); - echo =0 ; + else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { +memcpy ((u8 *)ptr, opts->addr6.s6_addr,16 ); + ptr +=4 ; } - *ptr++ =mptcp_option (MPTCPOPT_ADD_ADDR , - len, echo, opts->addr_id); -memcpy ((u8 *)ptr, opts->addr6.s6_addr,16 ); - ptr +=4 ; +#endif if (opts->ahmac) {put_unaligned_be64 (opts->ahmac, ptr); ptr +=2 ; } } -#endif if (OPTION_MPTCP_RM_ADDR & opts->suboptions) { *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 3/12 mptcp: add port support for ADD_ADDR suboption writing
In rfc8684, the length of ADD_ADDR suboption with IPv4 address and port is 18 octets, but mptcp_write_options is 32-bit aligned, so we need to pad it to 20 octets.
This patch added a new field 'port' in mptcp_out_options. When this field is set with a port number, we need to add up 4 octets for the ADD_ADDR suboption, and put the port number into the suboption.
--- include/net/mptcp.h | 1 + net/mptcp/options.c | 27 ++++++++++++++++++++++++--- net/mptcp/protocol.h | 10 +++++----- 3 files changed, 30 insertions(+), 8 deletions(-)
include/net/mptcp.h +1 -0
@@ -46,6 +46,7 @@ struct mptcp_out_options {#endif };u8 addr_id; +u16 port;u64 ahmac;u8 rm_id;u8 join_id;
net/mptcp/options.c +24 -3
@@ -1079,6 +1079,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ;#endif +if (opts->port) + len +=TCPOLEN_MPTCP_PORT_LEN ; +if (opts->ahmac) { len +=sizeof (opts->ahmac); echo =0 ;
@@ -1096,9 +1099,27 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ptr += 4; }#endif -if (opts->ahmac) { -put_unaligned_be64 (opts->ahmac, ptr); - ptr +=2 ; + +if (!opts->port) { +if (opts->ahmac) { +put_unaligned_be64 (opts->ahmac, ptr); + ptr +=2 ; + } + }else { +if (opts->ahmac) { +put_unaligned_be32 (opts->port <<16 | + opts->ahmac >>48 , ptr); + ptr +=1 ; +put_unaligned_be64 (opts->ahmac <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=2 ; + }else { +put_unaligned_be32 (opts->port <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=1 ; + } } }
net/mptcp/protocol.h +5 -5
@@ -49,14 +49,14 @@#define TCPOLEN_MPTCP_DSS_MAP64 14#define TCPOLEN_MPTCP_DSS_CHECKSUM 2#define TCPOLEN_MPTCP_ADD_ADDR 16 -#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 +#define TCPOLEN_MPTCP_ADD_ADDR_PORT 20#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 -#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 +#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 12#define TCPOLEN_MPTCP_ADD_ADDR6 28 -#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 +#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 32#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 -#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 -#define TCPOLEN_MPTCP_PORT_LEN 2 +#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 24 +#define TCPOLEN_MPTCP_PORT_LEN 4#define TCPOLEN_MPTCP_RM_ADDR_BASE 4/* MPTCP MP_JOIN flags */
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 4/12 mptcp: use adding up size to get ADD_ADDR length
This patch uses adding up size to get the ADD_ADDR suboption length rather than returning the ADD_ADDR size constants.
--- net/mptcp/protocol.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +9 -4
@@ -57,6 +57,7 @@#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 24#define TCPOLEN_MPTCP_PORT_LEN 4 +#define TCPOLEN_MPTCP_ADD_ADDR_HMAC 8#define TCPOLEN_MPTCP_RM_ADDR_BASE 4/* MPTCP MP_JOIN flags */
@@ -546,10 +547,14 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)static inline unsigned int mptcp_add_addr_len (int family,bool echo) { -if (family ==AF_INET ) -return echo ?TCPOLEN_MPTCP_ADD_ADDR_BASE - :TCPOLEN_MPTCP_ADD_ADDR ; -return echo ?TCPOLEN_MPTCP_ADD_ADDR6_BASE :TCPOLEN_MPTCP_ADD_ADDR6 ; +u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ; + +if (family ==AF_INET6 ) + len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ; +if (!echo) + len +=TCPOLEN_MPTCP_ADD_ADDR_HMAC ; + +return len; } bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 5/12 mptcp: add the outgoing ADD_ADDR port support
This patch added a new add_addr_signal type named MPTCP_ADD_ADDR_PORT, to identify it is an address with port to be added.
It also added a new parameter 'port' for both mptcp_add_addr_len and mptcp_pm_add_addr_signal.
In mptcp_established_options_add_addr, we check whether the announced address is added with port. If it is, we put this port number to mptcp_out_options's port field.
--- net/mptcp/options.c | 10 +++++++--- net/mptcp/pm.c | 5 +++-- net/mptcp/protocol.h | 12 ++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-)
net/mptcp/options.c +7 -3
@@ -586,6 +586,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *unsigned int opt_size = *size;struct mptcp_addr_info saddr;bool echo; +bool port;int len; if (mptcp_pm_should_add_signal_ipv6(msk) &&
@@ -597,10 +598,10 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * }if (!mptcp_pm_should_add_signal (msk) || - !(mptcp_pm_add_addr_signal (msk, remaining, &saddr, &echo))) + !(mptcp_pm_add_addr_signal (msk, remaining, &saddr, &echo, &port)))return false; - len =mptcp_add_addr_len (saddr.family, echo); + len =mptcp_add_addr_len (saddr.family, echo, port);if (remaining < len)return false;
@@ -608,6 +609,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *if (drop_other_suboptions) *size -= opt_size; opts->addr_id = saddr.id; +if (port) + opts->port =ntohs (saddr.port);if (saddr.family ==AF_INET ) { opts->suboptions |=OPTION_MPTCP_ADD_ADDR ; opts->addr = saddr.addr;
@@ -630,7 +633,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * } }#endif -pr_debug ("addr_id=%d, ahmac=%llu, echo=%d" , opts->addr_id, opts->ahmac, echo); +pr_debug ("addr_id=%d, ahmac=%llu, echo=%d, port=%d" , + opts->addr_id, opts->ahmac, echo, opts->port);return true; }
net/mptcp/pm.c +3 -2
@@ -188,7 +188,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)/* path manager helpers */ bool mptcp_pm_add_addr_signal (struct mptcp_sock *msk,unsigned int remaining, -struct mptcp_addr_info *saddr,bool *echo) +struct mptcp_addr_info *saddr,bool *echo,bool *port) {int ret = false;
@@ -199,8 +199,9 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining, goto out_unlock; *echo =mptcp_pm_should_add_signal_echo (msk); + *port =mptcp_pm_should_add_signal_port (msk); -if (remaining <mptcp_add_addr_len (msk->pm.local.family, *echo)) +if (remaining <mptcp_add_addr_len (msk->pm.local.family, *echo, *port)) goto out_unlock; *saddr = msk->pm.local;
net/mptcp/protocol.h +10 -2
@@ -172,6 +172,7 @@ enum mptcp_add_addr_status {MPTCP_ADD_ADDR_SIGNAL ,MPTCP_ADD_ADDR_ECHO ,MPTCP_ADD_ADDR_IPV6 , + MPTCP_ADD_ADDR_PORT, }; struct mptcp_pm_data {
@@ -540,12 +541,17 @@ static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk)return READ_ONCE (msk->pm.add_addr_signal) &BIT (MPTCP_ADD_ADDR_IPV6 ); } +static inline bool mptcp_pm_should_add_signal_port (struct mptcp_sock *msk) +{ +return READ_ONCE (msk->pm.add_addr_signal) &BIT (MPTCP_ADD_ADDR_PORT ); +} +static inline bool mptcp_pm_should_rm_signal (struct mptcp_sock *msk) {return READ_ONCE (msk->pm.rm_addr_signal); } -static inline unsigned int mptcp_add_addr_len (int family,bool echo) +static inline unsigned int mptcp_add_addr_len (int family,bool echo,bool port) {u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;
@@ -553,12 +559,14 @@ static inline unsigned int mptcp_add_addr_len(int family, bool echo) len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ;if (!echo) len +=TCPOLEN_MPTCP_ADD_ADDR_HMAC ; +if (port) + len +=TCPOLEN_MPTCP_PORT_LEN ;return len; }bool mptcp_pm_add_addr_signal (struct mptcp_sock *msk,unsigned int remaining, -struct mptcp_addr_info *saddr,bool *echo); +struct mptcp_addr_info *saddr,bool *echo,bool *port);bool mptcp_pm_rm_addr_signal (struct mptcp_sock *msk,unsigned int remaining,u8 *rm_id);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 6/12 mptcp: send out dedicated packet for ADD_ADDR using port
The process is similar to that of the ADD_ADDR IPv6, this patch also sent out a pure ack for the ADD_ADDR using port.
--- net/mptcp/options.c | 3 ++- net/mptcp/pm.c | 3 ++- net/mptcp/pm_netlink.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-)
net/mptcp/options.c +2 -1
@@ -589,7 +589,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *bool port;int len; -if (mptcp_pm_should_add_signal_ipv6 (msk) && +if ((mptcp_pm_should_add_signal_ipv6 (msk) || +mptcp_pm_should_add_signal_port (msk)) && skb &&skb_is_tcp_pure_ack (skb)) {pr_debug ("drop other suboptions" ); opts->suboptions =0 ;
net/mptcp/pm.c +2 -1
@@ -167,7 +167,8 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,void mptcp_pm_add_addr_send_ack (struct mptcp_sock *msk) { -if (!mptcp_pm_should_add_signal_ipv6 (msk)) +if (!mptcp_pm_should_add_signal_ipv6 (msk) && + !mptcp_pm_should_add_signal_port (msk))return ;mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_SEND_ACK );
net/mptcp/pm_netlink.c +11 -3
@@ -408,7 +408,8 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow; -if (!mptcp_pm_should_add_signal_ipv6 (msk)) +if (!mptcp_pm_should_add_signal_ipv6 (msk) && + !mptcp_pm_should_add_signal_port (msk))return ;__mptcp_flush_join_list (msk);
@@ -418,14 +419,21 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk)u8 add_addr;spin_unlock_bh (&msk->pm.lock); -pr_debug ("send ack for add_addr6" ); +if (mptcp_pm_should_add_signal_ipv6 (msk)) +pr_debug ("send ack for add_addr6" ); +if (mptcp_pm_should_add_signal_port (msk)) +pr_debug ("send ack for add_addr_port" ); +lock_sock (ssk);tcp_send_ack (ssk);release_sock (ssk);spin_lock_bh (&msk->pm.lock); add_addr =READ_ONCE (msk->pm.add_addr_signal); - add_addr &= ~BIT (MPTCP_ADD_ADDR_IPV6 ); +if (mptcp_pm_should_add_signal_ipv6 (msk)) + add_addr &= ~BIT (MPTCP_ADD_ADDR_IPV6 ); +if (mptcp_pm_should_add_signal_port (msk)) + add_addr &= ~BIT (MPTCP_ADD_ADDR_PORT );WRITE_ONCE (msk->pm.add_addr_signal, add_addr); } }
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 7/12 mptcp: add port parameter for mptcp_pm_announce_addr
This patch added a new parameter 'port' for mptcp_pm_announce_addr. If this parameter is true, we set the MPTCP_ADD_ADDR_PORT bit of the add_addr_signal. That means the announced address is added with a port number.
--- net/mptcp/pm.c | 6 ++++-- net/mptcp/pm_netlink.c | 9 ++++++--- net/mptcp/protocol.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-)
net/mptcp/pm.c +4 -2
@@ -14,7 +14,7 @@int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr, -bool echo) +bool echo,bool port) {u8 add_addr =READ_ONCE (msk->pm.add_addr_signal);
@@ -26,6 +26,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, add_addr |=BIT (MPTCP_ADD_ADDR_ECHO );if (addr->family ==AF_INET6 ) add_addr |=BIT (MPTCP_ADD_ADDR_IPV6 ); +if (port) + add_addr |=BIT (MPTCP_ADD_ADDR_PORT );WRITE_ONCE (msk->pm.add_addr_signal, add_addr);return 0 ; }
@@ -156,7 +158,7 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,spin_lock_bh (&pm->lock);if (!READ_ONCE (pm->accept_addr)) { -mptcp_pm_announce_addr (msk, addr, true); +mptcp_pm_announce_addr (msk, addr, true, addr->port);mptcp_pm_add_addr_send_ack (msk); }else if (mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_RECEIVED )) { pm->remote = *addr;
net/mptcp/pm_netlink.c +6 -3
@@ -228,7 +228,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer)if (!mptcp_pm_should_add_signal (msk)) {pr_debug ("retransmit ADD_ADDR id=%d" , entry->addr.id); -mptcp_pm_announce_addr (msk, &entry->addr, false); +mptcp_pm_announce_addr (msk, &entry->addr, false, entry->addr.port);mptcp_pm_add_addr_send_ack (msk); entry->retrans_times++; }
@@ -329,7 +329,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)if (local) {if (mptcp_pm_alloc_anno_list (msk, local)) { msk->pm.add_addr_signaled++; -mptcp_pm_announce_addr (msk, &local->addr, false); +mptcp_pm_announce_addr (msk, &local->addr, false, local->addr.port);mptcp_pm_nl_add_addr_send_ack (msk); } }else {
@@ -377,6 +377,7 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)struct sock *sk = (struct sock *)msk;struct mptcp_addr_info remote;struct mptcp_addr_info local; +bool use_port = false; pr_debug("accepted %d:%d remote family %d", msk->pm.add_addr_accepted, msk->pm.add_addr_accept_max,
@@ -393,6 +394,8 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) remote = msk->pm.remote;if (!remote.port) remote.port = sk->sk_dport; +else + use_port = true;memset (&local,0 ,sizeof (local)); local.family = remote.family;
@@ -400,7 +403,7 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)__mptcp_subflow_connect ((struct sock *)msk, &local, &remote);spin_lock_bh (&msk->pm.lock); -mptcp_pm_announce_addr (msk, &remote, true); +mptcp_pm_announce_addr (msk, &remote, true, use_port);mptcp_pm_nl_add_addr_send_ack (msk); }
net/mptcp/protocol.h +1 -1
@@ -522,7 +522,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr, -bool echo); +bool echo,bool port);int mptcp_pm_remove_addr (struct mptcp_sock *msk,u8 local_id);int mptcp_pm_remove_subflow (struct mptcp_sock *msk,u8 local_id);
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 8/12 mptcp: print out port and ahmac when receiving ADD_ADDR
This patch printed out more debugging information for the ADD_ADDR suboption parsing on the incoming path.
--- net/mptcp/options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/options.c +3 -3
@@ -242,9 +242,6 @@ static void mptcp_parse_option(const struct sk_buff *skb, mp_opt->add_addr =1 ; mp_opt->addr_id = *ptr++; -pr_debug ("ADD_ADDR%s: id=%d, echo=%d" , - (mp_opt->family ==MPTCP_ADDR_IPVERSION_6 ) ?"6" :"" , - mp_opt->addr_id, mp_opt->echo);if (mp_opt->family ==MPTCP_ADDR_IPVERSION_4 ) {memcpy ((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr,4 ); ptr +=4 ;
@@ -269,6 +266,9 @@ static void mptcp_parse_option(const struct sk_buff *skb, mp_opt->ahmac =get_unaligned_be64 (ptr); ptr +=8 ; } +pr_debug ("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d" , + (mp_opt->family ==MPTCP_ADDR_IPVERSION_6 ) ?"6" :"" , + mp_opt->addr_id, mp_opt->ahmac, mp_opt->echo, mp_opt->port);break ;case MPTCPOPT_RM_ADDR :
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 9/12 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
@@ -725,6 +725,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 ; }
@@ -911,6 +914,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.26.2
Geliang Tang
PATCH v3 10/12 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:
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
@@ -176,8 +176,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 ;
@@ -223,7 +223,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" );
@@ -271,6 +270,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]); }
@@ -323,6 +336,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;
@@ -330,12 +344,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 )
@@ -343,6 +361,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.26.2
Geliang Tang
PATCH v3 11/12 mptcp: add the mib for ADD_ADDR with port
This patch added the mib for ADD_ADDR with port, named MPTCP_MIB_PORTADD, for receiving of the ADD_ADDR suboption with a port number.
--- net/mptcp/mib.c | 1 + net/mptcp/mib.h | 1 + net/mptcp/options.c | 4 ++++ 3 files changed, 6 insertions(+)
net/mptcp/mib.c +1 -0
@@ -29,6 +29,7 @@ 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 ("RmAddr" ,MPTCP_MIB_RMADDR ),SNMP_MIB_ITEM ("RmSubflow" ,MPTCP_MIB_RMSUBFLOW ),SNMP_MIB_SENTINEL
net/mptcp/mib.h +1 -0
@@ -22,6 +22,7 @@ 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 port */ MPTCP_MIB_RMADDR ,/* Received RM_ADDR */ MPTCP_MIB_RMSUBFLOW ,/* Remove a subflow */ __MPTCP_MIB_MAX
net/mptcp/options.c +4 -0
@@ -955,6 +955,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 ; }
Signature · 1 line
2.26.2
Geliang Tang
PATCH v3 12/12 selftests: mptcp: add testcases for ADD_ADDR with port
This patch added a new argument for run_tests. When an address with a port number has been added, the new port number will be passed to this with_port argument, and then passed to do_transfer.
In do_transfer, if the with_port argument is set, we need to establish a new connection to listen for the new port. To make sure the peer can connect with it using the new port.
It checked the MPTcpExtPortAdd MIB counter in chk_add_nr, and added the testcases for ADD_ADDR with port.
The output looks like this:
24 signal address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
25 subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
26 remove single address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
rm [ ok ] - sf [ ok ]
--- .../testing/selftests/net/mptcp/mptcp_join.sh | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +60 -1
@@ -212,6 +212,7 @@ do_transfer() rm_nr_ns1="$7" rm_nr_ns2="$8" speed="$9" + with_port="${10}" port=$((10000+$TEST_COUNT)) TEST_COUNT=$((TEST_COUNT+1))
@@ -253,6 +254,11 @@ do_transfer() -s ${srv_proto} ${local_addr} < "$sin" > "$sout" & spid=$! + if [ "$with_port" -gt 0 ];then + ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $with_port \ + -s ${srv_proto} ${local_addr} < "$sin" > "$sout" & + fi + sleep 1 if [ "$test_link_fail" -eq 0 ];then
@@ -348,6 +354,7 @@ run_tests() rm_nr_ns1="${5:-0}" rm_nr_ns2="${6:-0}" speed="${7:-fast}" + with_port="${8:-0}" lret=0 oldin=""
@@ -362,7 +369,7 @@ run_tests() fi do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \ - ${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed} + ${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed} ${with_port} lret=$? if [ "$test_linkfail" -eq 1 ];then
@@ -429,6 +436,7 @@ chk_add_nr() { local add_nr=$1 local echo_nr=$2 + local port_nr=${3:-0} local count local dump_stats
@@ -450,6 +458,17 @@ chk_add_nr() echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr" ret=1 dump_stats=1 + else + echo -n "[ ok ]" + fi + + 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 with port[s] expected $port_nr" + ret=1 + dump_stats=1 else echo "[ ok ]" fi
@@ -717,6 +736,46 @@ chk_join_nr "remove subflow and signal IPv6" 2 2 2 chk_add_nr 1 1 chk_rm_nr 1 1 +# 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 0 0 0 fast 10100 +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 0 0 0 fast 10100 +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 10100 +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 10100 +chk_join_nr "remove subflow and signal with port" 2 2 2 +chk_add_nr 1 1 1 +chk_rm_nr 1 1 + # single subflow, syncookies reset_with_cookies ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.26.2
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v3 mptcp-next 12/12] selftests: mptcp: add testcases for ADD_ADDR with port
Quoted 21 lines · Geliang Tang
This patch added a new argument for
run_tests. When an address with a port number has been added, the new port number will be passed to thiswith_portargument, and then passed todo_transfer.In
do_transfer, if thewith_portargument is set, we need to establish a new connection to listen for the new port. To make sure the peer can connect with it using the new port.It checked the MPTcpExtPortAdd MIB counter in
chk_add_nr, and added the testcases forADD_ADDRwith port.The output looks like this:
24 signal address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
25 subflow and signal with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
26 remove single address with port syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ] - pt [ ok ]
rm [ ok ] - sf [ ok ]
Quoted 4 lines
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
.../testing/selftests/net/mptcp/mptcp_join.sh| 61 ++++++++++++++++++-1 file changed, 60 insertions(+), 1 deletion(-)
I don't have any other comments on patches 4-12, thanks again for the series.
--
Mat Martineau
Intel
Matthieu Baerts
[MPTCP] Re: [MPTCP][PATCH v3 mptcp-next 11/12] mptcp: add the mib for ADD_ADDR with port
In reply to Geliang TangHi Geliang,
Quoted 2 lines · Geliang Tang
This patch added the mib for
ADD_ADDRwith port, namedMPTCP_MIB_PORTADD, for receiving of theADD_ADDRsuboption with a port number.
This MIB is useful!
I think what could also be useful is a MIB counter we would increase when we receive an MP_JOIN to a different port than the original one. What do you think?
It can be useful for those using this feature and also for our
selftests: to validate we correctly receive the SYN+MPJ on a different port than the original one as expected, no?
I just see a risk with the new selftests that we don't see the new subflow is in fact established to the wrong port, not the one we expected. Or do we have a check for that?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Geliang Tang
[MPTCP] Re: [MPTCP][PATCH v3 mptcp-next 11/12] mptcp: add the mib for ADD_ADDR with port
Hi Matt,
Thanks for your review.
Quoted 9 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年11月5日周四 下午10:04写道:
Hi Geliang,
Quoted 2 lines · Geliang Tang
This patch added the mib for
ADD_ADDRwith port, namedMPTCP_MIB_PORTADD, for receiving of theADD_ADDRsuboption with a port number.This MIB is useful!
Quoted 7 lines
I think what could also be useful is a MIB counter we would increase when we receive an
MP_JOINto a different port than the original one. What do you think?It can be useful for those using this feature and also for our
selftests: to validate we correctly receive the SYN+MPJ on a different port than the original one as expected, no?
I have sent out two squash-to patches to add more MIBs:
Squash to "mptcp: add the mib for ADD_ADDR with port" Squash to "selftests: mptcp: add testcases for ADD_ADDR with port"
Quoted 5 lines
I just see a risk with the new selftests that we don't see the new subflow is in fact established to the wrong port, not the one we expected. Or do we have a check for that?
And I have sent out a new patch named "mptcp: add port number check for MP_JOIN" to do this check.
-Geliang
Quoted 7 lines
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Mat Martineau
[MPTCP] Re: [MPTCP][PATCH v3 mptcp-next 03/12] mptcp: add port support for ADD_ADDR suboption writing
In reply to Geliang TangQuoted 10 lines · Geliang Tang
In rfc8684, the length of
ADD_ADDRsuboption with IPv4 address and port is 18 octets, butmptcp_write_optionsis 32-bit aligned, so we need to pad it to 20 octets.This patch added a new field 'port' in
mptcp_out_options. When this field is set with a port number, we need to add up 4 octets for theADD_ADDRsuboption, and put the port number into the suboption.Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
Thanks for the v3! First two patches look good.
Quoted 43 lines
include/net/mptcp.h | 1 + net/mptcp/options.c | 27 ++++++++++++++++++++++++--- net/mptcp/protocol.h | 10 +++++----- 3 files changed, 30 insertions(+), 8 deletions(-)include/net/mptcp.h +1
-0@@ -46,6 +46,7 @@ struct mptcp_out_options {#endif };u8 addr_id; +u16 port;u64 ahmac;u8 rm_id;u8 join_id;net/mptcp/options.c +8
-3@@ -1079,6 +1079,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ;#endif +if (opts->port) + len +=TCPOLEN_MPTCP_PORT_LEN ; +if (opts->ahmac) { len +=sizeof (opts->ahmac); echo =0 ;@@ -1096,9 +1099,27 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ptr += 4; }#endif -if (opts->ahmac) { -put_unaligned_be64 (opts->ahmac, ptr); - ptr +=2 ; + +if (!opts->port) { +if (opts->ahmac) { +put_unaligned_be64 (opts->ahmac, ptr); + ptr +=2 ;
net/mptcp/options.c void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, · line 1116
Quoted 10 lines
net/mptcp/options.c +10
-0+ } + }else { +if (opts->ahmac) { +put_unaligned_be32 (opts->port <<16 | + opts->ahmac >>48 , ptr); + ptr +=1 ; +put_unaligned_be64 (opts->ahmac <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=2 ;
I made a comment about the byte ordering conversions in v1, and I was incorrect about shifting and combining the values before the endian conversion. The above code does work fine, sorry about that - and please reply if you ever think I have requested an incorrect change! That feedback is helpful.
I do still think it would be clearer to use a temporary u8 pointer to write the values rather than splitting the ahmac across two calls, like this:
u8 *bptr = (u8 *)ptr;
put_unaligned_be16(opts->port, bptr);
bptr += 2;put_unaligned_be64(opts->ahmac, bptr);
bptr += 8;put_unaligned_u16(TCPOPT_NOP << 8 | TCPOPT_NOP, bptr);
ptr += 3;
What do you think?
Quoted 35 lines
net/mptcp/options.c +6
-0+ }else { +put_unaligned_be32 (opts->port <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=1 ; + } } }net/mptcp/protocol.h +5
-5@@ -49,14 +49,14 @@#define TCPOLEN_MPTCP_DSS_MAP64 14#define TCPOLEN_MPTCP_DSS_CHECKSUM 2#define TCPOLEN_MPTCP_ADD_ADDR 16 -#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 +#define TCPOLEN_MPTCP_ADD_ADDR_PORT 20#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 -#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 +#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 12#define TCPOLEN_MPTCP_ADD_ADDR6 28 -#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 +#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 32#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 -#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 -#define TCPOLEN_MPTCP_PORT_LEN 2 +#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 24 +#define TCPOLEN_MPTCP_PORT_LEN 4#define TCPOLEN_MPTCP_RM_ADDR_BASE 4/* MPTCP MP_JOIN flags */ Signature · 1 line
2.26.2
--
Mat Martineau
Intel
Geliang Tang
[MPTCP] Re: [MPTCP][PATCH v3 mptcp-next 03/12] mptcp: add port support for ADD_ADDR suboption writing
Hi Mat,
Quoted 77 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2020年11月7日周六 上午8:46写道:
Quoted 10 lines · Geliang Tang
In rfc8684, the length of
ADD_ADDRsuboption with IPv4 address and port is 18 octets, butmptcp_write_optionsis 32-bit aligned, so we need to pad it to 20 octets.This patch added a new field 'port' in
mptcp_out_options. When this field is set with a port number, we need to add up 4 octets for theADD_ADDRsuboption, and put the port number into the suboption.Signed-off-by Geliang Tang <geliangtang(a)gmail.com>---
Thanks for the v3! First two patches look good.
Quoted 43 lines
include/net/mptcp.h | 1 + net/mptcp/options.c | 27 ++++++++++++++++++++++++--- net/mptcp/protocol.h | 10 +++++----- 3 files changed, 30 insertions(+), 8 deletions(-)include/net/mptcp.h +1
-0@@ -46,6 +46,7 @@ struct mptcp_out_options {#endif };u8 addr_id; +u16 port;u64 ahmac;u8 rm_id;u8 join_id;net/mptcp/options.c +8
-3@@ -1079,6 +1079,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, len =TCPOLEN_MPTCP_ADD_ADDR6_BASE ;#endif +if (opts->port) + len +=TCPOLEN_MPTCP_PORT_LEN ; +if (opts->ahmac) { len +=sizeof (opts->ahmac); echo =0 ;@@ -1096,9 +1099,27 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ptr += 4; }#endif -if (opts->ahmac) { -put_unaligned_be64 (opts->ahmac, ptr); - ptr +=2 ; + +if (!opts->port) { +if (opts->ahmac) { +put_unaligned_be64 (opts->ahmac, ptr); + ptr +=2 ;net/mptcp/options.c void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, · line 1116
Quoted 10 lines
net/mptcp/options.c +10
-0+ } + }else { +if (opts->ahmac) { +put_unaligned_be32 (opts->port <<16 | + opts->ahmac >>48 , ptr); + ptr +=1 ; +put_unaligned_be64 (opts->ahmac <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=2 ;I made a comment about the byte ordering conversions in v1, and I was incorrect about shifting and combining the values before the endian conversion. The above code does work fine, sorry about that - and please reply if you ever think I have requested an incorrect change! That feedback is helpful.
Quoted 3 lines
I do still think it would be clearer to use a temporary u8 pointer to write the values rather than splitting the ahmac across two calls, like this:
Thanks for your review, I have send out a squash-to patch to fix this.
Quoted 8 lines
u8 *bptr = (u8 *)ptr;
put_unaligned_be16(opts->port, bptr);
bptr += 2;put_unaligned_be64(opts->ahmac, bptr);
bptr += 8;put_unaligned_u16(TCPOPT_NOP << 8 | TCPOPT_NOP, bptr);
I only changed this put_unaligned_u16 to put_unaligned_be16 in my patch. The other code is the same as yours.
-Geliang
Quoted 45 lines
ptr += 3;
What do you think?
Quoted 34 lines
net/mptcp/options.c +6
-0+ }else { +put_unaligned_be32 (opts->port <<16 | +TCPOPT_NOP <<8 | +TCPOPT_NOP , ptr); + ptr +=1 ; + } } }net/mptcp/protocol.h +5
-6@@ -49,14 +49,14 @@#define TCPOLEN_MPTCP_DSS_MAP64 14#define TCPOLEN_MPTCP_DSS_CHECKSUM 2#define TCPOLEN_MPTCP_ADD_ADDR 16 -#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 +#define TCPOLEN_MPTCP_ADD_ADDR_PORT 20#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 -#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 +#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 12#define TCPOLEN_MPTCP_ADD_ADDR6 28 -#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 +#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 32#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 -#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 -#define TCPOLEN_MPTCP_PORT_LEN 2 +#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 24 +#define TCPOLEN_MPTCP_PORT_LEN 4#define TCPOLEN_MPTCP_RM_ADDR_BASE 4/* MPTCP MP_JOIN flags */ --Quoted 1 line
2.26.2
--
Mat Martineau
Intel