Skip to contentSkip to conversation

mptcp: add ADD_ADDR timeout test case

PATCH Superseded Geliang Tang 3 participants 9 messages Sep 22, 2020 – Sep 27, 2020

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

cover mptcp: add ADD_ADDR timeout test case

This patchset added two new sysctls and ADD_ADDR timeout test case.

Geliang Tang (3):
mptcp: add add_addr_echo sysctl
mptcp: add add_addr_timeout sysctl
selftests: mptcp: add ADD_ADDR timeout test case

 net/mptcp/ctrl.c                              | 28 +++++++++++++
 net/mptcp/pm.c                                |  9 +++--
 net/mptcp/pm_netlink.c                        | 12 ++++--
 net/mptcp/protocol.h                          |  2 +
 .../testing/selftests/net/mptcp/mptcp_join.sh | 39 +++++++++++++++++--
 5 files changed, 81 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 mptcp: add add_addr_echo sysctl

This patch added a new sysctl, named add_addr_echo, to control the ADD_ADDR echo ability.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/ctrl.c       | 14 ++++++++++++++
 net/mptcp/pm.c         |  9 ++++++---
 net/mptcp/pm_netlink.c |  4 +++-
 net/mptcp/protocol.h   |  1 +
 4 files changed, 24 insertions(+), 4 deletions(-)
net/mptcp/ctrl.c +14 -0
index 54b888f94009..2a250f2047a7 100644
@@ -18,6 +18,7 @@ struct mptcp_pernet {
 	struct ctl_table_header *ctl_table_hdr;
 
 	int mptcp_enabled;
+	int add_addr_echo;
 };
 
 static struct mptcp_pernet *mptcp_get_pernet(struct net *net)
@@ -30,6 +31,11 @@ int mptcp_is_enabled(struct net *net)
 	return mptcp_get_pernet(net)->mptcp_enabled;
 }
 
+int mptcp_add_addr_echo_is_enabled(struct net *net)
+{
+	return mptcp_get_pernet(net)->add_addr_echo;
+}
+
 static struct ctl_table mptcp_sysctl_table[] = {
 	{
 		.procname = "enabled",
@@ -40,12 +46,19 @@ static struct ctl_table mptcp_sysctl_table[] = {
 		 */
 		.proc_handler = proc_dointvec,
 	},
+	{
+		.procname = "add_addr_echo",
+		.maxlen = sizeof(int),
+		.mode = 0644,
+		.proc_handler = proc_dointvec,
+	},
 	{}
 };
 
 static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
 {
 	pernet->mptcp_enabled = 1;
+	pernet->add_addr_echo = 1;
 }
 
 static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
@@ -61,6 +74,7 @@ static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
 	}
 
 	table[0].data = &pernet->mptcp_enabled;
+	table[1].data = &pernet->add_addr_echo;
 
 	hdr = register_net_sysctl(net, MPTCP_SYSCTL_PATH, table);
 	if (!hdr)
net/mptcp/pm.c +6 -3
index 7e81f53d1e5d..01663ec0c7e2 100644
@@ -143,6 +143,7 @@ void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)
 void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 				const struct mptcp_addr_info *addr)
 {
+	struct net *net = sock_net((struct sock *)msk);
 	struct mptcp_pm_data *pm = &msk->pm;
 
 	pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id,
@@ -150,10 +151,12 @@ 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);
-	else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
+	if (!READ_ONCE(pm->accept_addr)) {
+		if (mptcp_add_addr_echo_is_enabled(net))
+			mptcp_pm_announce_addr(msk, addr, true);
+	} else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {
 		pm->remote = *addr;
+	}
 
 	spin_unlock_bh(&pm->lock);
 }
net/mptcp/pm_netlink.c +3 -1
index 5a0e4d11bcc3..d45f2320355a 100644
@@ -369,6 +369,7 @@ void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
 void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 {
 	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
 	struct mptcp_addr_info remote;
 	struct mptcp_addr_info local;
 
@@ -394,7 +395,8 @@ 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);
+	if (mptcp_add_addr_echo_is_enabled(net))
+		mptcp_pm_announce_addr(msk, &remote, true);
 }
 
 void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
net/mptcp/protocol.h +1 -0
index 7cfe52aeb2b8..e0b00cc8bfaf 100644
@@ -361,6 +361,7 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
 }
 
 int mptcp_is_enabled(struct net *net);
+int mptcp_add_addr_echo_is_enabled(struct net *net);
 void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
 				     struct mptcp_options_received *mp_opt);
 bool mptcp_subflow_data_available(struct sock *sk);
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH 2/3 mptcp: add add_addr_timeout sysctl

In reply to Geliang Tang

This patch added a new sysctl, named add_addr_timeout, to control the timeout value (in seconds) of the ADD_ADDR retransmission.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/ctrl.c       | 14 ++++++++++++++
 net/mptcp/pm_netlink.c |  8 ++++++--
 net/mptcp/protocol.h   |  1 +
 3 files changed, 21 insertions(+), 2 deletions(-)
net/mptcp/ctrl.c +14 -0
index 2a250f2047a7..4131f496cd84 100644
@@ -19,6 +19,7 @@ struct mptcp_pernet {
 
 	int mptcp_enabled;
 	int add_addr_echo;
+	u32 add_addr_timeout;
 };
 
 static struct mptcp_pernet *mptcp_get_pernet(struct net *net)
@@ -36,6 +37,11 @@ int mptcp_add_addr_echo_is_enabled(struct net *net)
 	return mptcp_get_pernet(net)->add_addr_echo;
 }
 
+unsigned long mptcp_get_add_addr_timeout(struct net *net)
+{
+	return jiffies + mptcp_get_pernet(net)->add_addr_timeout * HZ;
+}
+
 static struct ctl_table mptcp_sysctl_table[] = {
 	{
 		.procname = "enabled",
@@ -52,6 +58,12 @@ static struct ctl_table mptcp_sysctl_table[] = {
 		.mode = 0644,
 		.proc_handler = proc_dointvec,
 	},
+	{
+		.procname = "add_addr_timeout",
+		.maxlen = sizeof(u32),
+		.mode = 0644,
+		.proc_handler = proc_douintvec,
+	},
 	{}
 };
 
@@ -59,6 +71,7 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
 {
 	pernet->mptcp_enabled = 1;
 	pernet->add_addr_echo = 1;
+	pernet->add_addr_timeout = TCP_RTO_MAX / HZ;
 }
 
 static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
@@ -75,6 +88,7 @@ static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
 
 	table[0].data = &pernet->mptcp_enabled;
 	table[1].data = &pernet->add_addr_echo;
+	table[2].data = &pernet->add_addr_timeout;
 
 	hdr = register_net_sysctl(net, MPTCP_SYSCTL_PATH, table);
 	if (!hdr)
net/mptcp/pm_netlink.c +6 -2
index d45f2320355a..1d6d2840be7a 100644
@@ -206,6 +206,8 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 	struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
 	struct mptcp_sock *msk = entry->sock;
 	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
+	unsigned long timeout = mptcp_get_add_addr_timeout(net);
 
 	pr_debug("msk=%p", msk);
 
@@ -232,7 +234,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 	}
 
 	if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
-		sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX);
+		sk_reset_timer(sk, timer, timeout);
 
 	spin_unlock_bh(&msk->pm.lock);
 
@@ -264,6 +266,8 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 {
 	struct mptcp_pm_add_entry *add_entry = NULL;
 	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
+	unsigned long timeout = mptcp_get_add_addr_timeout(net);
 
 	if (lookup_anno_list_by_saddr(msk, &entry->addr))
 		return false;
@@ -279,7 +283,7 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 	add_entry->retrans_times = 0;
 
 	timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0);
-	sk_reset_timer(sk, &add_entry->add_timer, jiffies + TCP_RTO_MAX);
+	sk_reset_timer(sk, &add_entry->add_timer, timeout);
 
 	return true;
 }
net/mptcp/protocol.h +1 -0
index e0b00cc8bfaf..d922884a1f96 100644
@@ -362,6 +362,7 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
 
 int mptcp_is_enabled(struct net *net);
 int mptcp_add_addr_echo_is_enabled(struct net *net);
+unsigned long mptcp_get_add_addr_timeout(struct net *net);
 void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
 				     struct mptcp_options_received *mp_opt);
 bool mptcp_subflow_data_available(struct sock *sk);
Signature · 1 line
2.17.1
author
#8 lore raw

PATCH 3/3 selftests: mptcp: add ADD_ADDR timeout test case

In reply to Geliang Tang

This patch added the test case for retransmitting ADD_ADDR when timeout. It set NS1's add_addr_timeout to 1 second, and disable NS2's add_addr_echo.

And we need to slow down the transfer process of all data to let the ADD_ADDR suboptions can be retransmitted three times.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 39 +++++++++++++++++--
 1 file changed, 36 insertions(+), 3 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +36 -3
index 08f53d86dedc..fa0011f2422e 100755
@@ -82,6 +82,14 @@ reset_with_cookies()
 	done
 }
 
+reset_with_timeout()
+{
+	reset
+
+	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
+	ip netns exec $ns2 sysctl -q net.mptcp.add_addr_echo=0
+}
+
 for arg in "$@"; do
 	if [ "$arg" = "-c" ]; then
 		capture=1
@@ -135,6 +143,7 @@ do_transfer()
 	connect_addr="$5"
 	rm_nr_ns1="$6"
 	rm_nr_ns2="$7"
+	slow="$8"
 
 	port=$((10000+$TEST_COUNT))
 	TEST_COUNT=$((TEST_COUNT+1))
@@ -159,7 +168,7 @@ do_transfer()
 		sleep 1
 	fi
 
-	if [[ $rm_nr_ns1 -eq 0 && $rm_nr_ns2 -eq 0 ]]; then
+	if [ $slow -eq 0 ]; then
 		mptcp_connect="./mptcp_connect -j"
 	else
 		mptcp_connect="./mptcp_connect -r"
@@ -252,7 +261,7 @@ run_tests()
 	connect_addr="$3"
 	lret=0
 
-	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 0 0
+	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 0 0 0
 	lret=$?
 	if [ $lret -ne 0 ]; then
 		ret=$lret
@@ -269,7 +278,22 @@ run_remove_tests()
 	rm_nr_ns2="$5"
 	lret=0
 
-	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} ${rm_nr_ns1} ${rm_nr_ns2}
+	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} ${rm_nr_ns1} ${rm_nr_ns2} 1
+	lret=$?
+	if [ $lret -ne 0 ]; then
+		ret=$lret
+		return
+	fi
+}
+
+run_timeout_tests()
+{
+	listener_ns="$1"
+	connector_ns="$2"
+	connect_addr="$3"
+	lret=0
+
+	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 0 0 1
 	lret=$?
 	if [ $lret -ne 0 ]; then
 		ret=$lret
@@ -491,6 +515,15 @@ run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "multiple subflows and signal" 3 3 3
 chk_add_nr 1 1
 
+# add_addr timeout
+reset_with_timeout
+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
+run_timeout_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "signal address, timeout" 1 1 1
+chk_add_nr 4 0
+
 # single subflow, remove
 reset
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.17.1
#2 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: add add_addr_echo sysctl

In reply to Geliang Tang
Quoted 5 lines · Geliang Tang

This patch added a new sysctl, named add_addr_echo, to control the ADD_ADDR
echo ability.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

If I read the series correctly, this sysctl is only needed for self- test's sake, right? can you instead drop the add_addr packet with some netfilter rules ? possibly matching on TCP PROTO, TCP len == 0 and the appropriate packet len should be sufficient.

Disabling the echo would likely violate the RFC, I think that exposing this ability to user-space would be too much even for unix philosophy[1] ;)

Cheers,

Paolo

[1] http://www.anvari.org/fortune/Miscellaneous_Collections/412232_the-unix-philosophy-basically-involves-giving-you-enough-rope-to-hang-yourself.html

author
#3 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: add add_addr_echo sysctl

Hi Paolo,

Quoted 6 lines · Paolo Abeni <pabeni(a)redhat.com> 于2020年9月23日周三 下午6:26写道:
Quoted 4 lines · Geliang Tang

This patch added a new sysctl, named add_addr_echo, to control the ADD_ADDR
echo ability.

Quoted 6 lines
Quoted 1 line
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

If I read the series correctly, this sysctl is only needed for self- test's sake, right? can you instead drop the add_addr packet with some netfilter rules ? possibly matching on TCP PROTO, TCP len == 0 and the appropriate packet len should be sufficient.

I still have not found the rules that can drop ADD_ADDR packets. But I found something useful like this:

# iptables -A OUTPUT -p tcp --tcp-option 30 -m length --length 0:100 -j DROP

"tcp-option 30" can match MPTCP packets, and "length" can match the IP packet's total length. But they are not sufficient.

Could you please give me some suggestions about this? Can I write a new netfiler module to do this? Is this acceptable?

Thanks.

-Geliang

Quoted 11 lines

Disabling the echo would likely violate the RFC, I think that exposing this ability to user-space would be too much even for unix philosophy[1] ;)

Cheers,

Paolo

[1] http://www.anvari.org/fortune/Miscellaneous_Collections/412232_the-unix-philosophy-basically-involves-giving-you-enough-rope-to-hang-yourself.html

#4 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: add add_addr_echo sysctl

Quoted 21 lines · Geliang Tang
Quoted 8 lines · Paolo Abeni <pabeni(a)redhat.com> 于2020年9月23日周三 下午6:26写道:
Quoted 6 lines · Geliang Tang

This patch added a new sysctl, named add_addr_echo, to control the
ADD_ADDR
echo ability.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Quoted 7 lines

If I read the series correctly, this sysctl is only needed for self-
test's sake, right? can you instead drop the add_addr packet with some
netfilter rules ? possibly matching on TCP PROTO, TCP len == 0 and the
appropriate packet len should be sufficient.

I still have not found the rules that can drop ADD_ADDR packets. But I found
something useful like this:

Quoted 6 lines
# iptables -A OUTPUT -p tcp --tcp-option 30 -m length --length 0:100
-j DROP

"tcp-option 30" can match MPTCP packets, and "length" can match the IP
packet's total length. But they are not sufficient.

You can use u32 to check that the sub-option type is 3 (== ADD_ADDR), with something alike:

iptables -A OUTPUT -p tcp --tcp-option 30 -m length 80 -m u32 "37&0xFF==0x1 && 38&0xFF==0x1 && 39&0xFF==0x8 && 49&0xFF==0x1e && 51&0xFF==0x3" -j DROP

The basic u32 match syntax is:

<offset> & <mask> = <value>

u32 will read the 4 bytes from the packet at starting from <offset> intepreting them a little-endian integer, will mask (bitwise 'and') with <mask> and will compare the result with the provided <value>. More expression can be concatenated with '&&'.

The above u32 match assumes there are no IP options, so that the TCP header starts at offset 20 and the first TCP option starts at offset
40. To read a byte a such offset we must actually load the 4bytes integer starting 3 bytes earlier so that bytes with offset 40 will be the least significant one in the loaded (little-endian) u32.

Overall the above checks that the TCP options are 2 nops (37&0xFF==0x1 && 38&0xFF==0x1), a timestamp (&& 39&0x8=0x8), an MPTCP (&& 49&0xFF==0x1e) with suboption 3 (&& 51=0x3), which means ADD_ADDR.

That is the layout I observe here with wireshark for an MPTCP ADD_ADDR packet over ipv4. Generally speaking this kind of matches are fragile, but in this case should be roboust enough.

I also refined the IP len to 80, which is the value I observe here. Again I think should be stable enough in this case.

All the above is completely non tested, so it may include syntax errors and could be inaccurate, please double check!

@Florian: do you think something alike the above could be enough to drop ADD_ADDR only? any better option? (likely nft is the tool here ;)

Thanks!

Paolo

#5 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: add add_addr_echo sysctl

Hi Geliang, Paolo,

Quoted 25 lines · Paolo Abeni
Quoted 24 lines · Geliang Tang
Quoted 8 lines · Paolo Abeni <pabeni(a)redhat.com> 于2020年9月23日周三 下午6:26写道:
Quoted 6 lines · Geliang Tang

This patch added a new sysctl, named add_addr_echo, to control the
ADD_ADDR
echo ability.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Quoted 7 lines

If I read the series correctly, this sysctl is only needed for self-
test's sake, right? can you instead drop the add_addr packet with some
netfilter rules ? possibly matching on TCP PROTO, TCP len == 0 and the
appropriate packet len should be sufficient.

I still have not found the rules that can drop ADD_ADDR packets. But I found
something useful like this:

# iptables -A OUTPUT -p tcp --tcp-option 30 -m length --length 0:100
-j DROP
Quoted 8 lines
Quoted 3 lines

"tcp-option 30" can match MPTCP packets, and "length" can match the IP
packet's total length. But they are not sufficient.

You can use u32 to check that the sub-option type is 3 (== ADD_ADDR), with something alike:

iptables -A OUTPUT -p tcp --tcp-option 30 -m length 80 -m u32 "37&0xFF==0x1 && 38&0xFF==0x1 && 39&0xFF==0x8 && 49&0xFF==0x1e && 51&0xFF==0x3" -j DROP

Another technique is to use libpcap filter and then convert it to cBPF filter. That's very similar to Paolo's technique using offsets but maybe easier to validate:

- first, find the libpcap filter:
- Manual: https://www.tcpdump.org/manpages/pcap-filter.7.html
- You can use offset from TCP layer: tcp[<offset>] & <mask> == <value>
- e.g. check MPTCP is used at the offset 20(tcp)+12(timestamps):

     tcp[32]==30

- and check the subtype is 3: (tcp[34] & 0xf0) == 0x30
- (of course, feel free to check the length, the protocol, etc.)

- try it:

   $ tcpdump -nr trace.pcap "tcp[32] == 30 and (tcp[34] & 0xf0) == 0x30"
     16:58:30.494716 IP 1.2.3.4.5001 > 4.3.2.1.38900: Flags [.], ack 
3693886387, win 224, options [nop,nop,TS val 525599374 ecr 
341597418,mptcp add-addr id 3 2.2.2.2,mptcp dss ack 419984920], length 0

- convert it to cBPF:

   $ docker run quay.io/casey_callendrello/nfbpf_compile "tcp[32] == 30 
and (tcp[34] & 0xf0) == 0x30"
   15,48 0 0 0,84 0 0 240,21 0 11 64,48 0 0 9,21 0 9 6,40 0 0 6,69 7 0 
8191,177 0 0 0,80 0 0 32,21 0 4 30,80 0 0 34,84 0 0 240,21 0 1 48,6 0 0 
65535,6 0 0 0

- Use it with IPTables:

   $ iptables -w -A OUTPUT -m bpf --bytecode '15,48 0 0 0,84 0 0 240,21 
0 11 64,48 0 0 9,21 0 9 6,40 0 0 6,69 7 0 8191,177 0 0 0,80 0 0 32,21 0 
4 30,80 0 0 34,84 0 0 240,21 0 1 48,6 0 0 65535,6 0 0 0' -j DROP
   - feel free to combine that with other matcher, e.g. "-p tcp 
--tcp-option 30" and just use cBPF to find the subtype: "(tcp[34] & 
0xf0) == 0x30"

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#6 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: add add_addr_echo sysctl

Hi Matt, Paolo,

Quoted 63 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年9月26日周六 上午4:45写道:

Hi Geliang, Paolo,

Quoted 25 lines · Paolo Abeni
Quoted 24 lines · Geliang Tang
Quoted 8 lines · Paolo Abeni <pabeni(a)redhat.com> 于2020年9月23日周三 下午6:26写道:
Quoted 6 lines · Geliang Tang

This patch added a new sysctl, named add_addr_echo, to control the
ADD_ADDR
echo ability.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Quoted 7 lines

If I read the series correctly, this sysctl is only needed for self-
test's sake, right? can you instead drop the add_addr packet with some
netfilter rules ? possibly matching on TCP PROTO, TCP len == 0 and the
appropriate packet len should be sufficient.

I still have not found the rules that can drop ADD_ADDR packets. But I found
something useful like this:

# iptables -A OUTPUT -p tcp --tcp-option 30 -m length --length 0:100
-j DROP
Quoted 8 lines
Quoted 3 lines

"tcp-option 30" can match MPTCP packets, and "length" can match the IP
packet's total length. But they are not sufficient.

You can use u32 to check that the sub-option type is 3 (== ADD_ADDR), with something alike:

iptables -A OUTPUT -p tcp --tcp-option 30 -m length 80 -m u32 "37&0xFF==0x1 && 38&0xFF==0x1 && 39&0xFF==0x8 && 49&0xFF==0x1e && 51&0xFF==0x3" -j DROP

Another technique is to use libpcap filter and then convert it to cBPF filter. That's very similar to Paolo's technique using offsets but maybe easier to validate:

- first, find the libpcap filter:
- Manual: https://www.tcpdump.org/manpages/pcap-filter.7.html
- You can use offset from TCP layer: tcp[<offset>] & <mask> == <value>
- e.g. check MPTCP is used at the offset 20(tcp)+12(timestamps):

     tcp[32]==30

- and check the subtype is 3: (tcp[34] & 0xf0) == 0x30
- (of course, feel free to check the length, the protocol, etc.)

- try it:

   $ tcpdump -nr trace.pcap "tcp[32] == 30 and (tcp[34] & 0xf0) == 0x30"
     16:58:30.494716 IP 1.2.3.4.5001 > 4.3.2.1.38900: Flags [.], ack
3693886387, win 224, options [nop,nop,TS val 525599374 ecr
341597418,mptcp add-addr id 3 2.2.2.2,mptcp dss ack 419984920], length 0

- convert it to cBPF:

   $ docker run quay.io/casey_callendrello/nfbpf_compile "tcp[32] == 30
and (tcp[34] & 0xf0) == 0x30"
   15,48 0 0 0,84 0 0 240,21 0 11 64,48 0 0 9,21 0 9 6,40 0 0 6,69 7 0
8191,177 0 0 0,80 0 0 32,21 0 4 30,80 0 0 34,84 0 0 240,21 0 1 48,6 0 0
65535,6 0 0 0
Quoted 7 lines

- Use it with IPTables:

   $ iptables -w -A OUTPUT -m bpf --bytecode '15,48 0 0 0,84 0 0 240,21
0 11 64,48 0 0 9,21 0 9 6,40 0 0 6,69 7 0 8191,177 0 0 0,80 0 0 32,21 0
4 30,80 0 0 34,84 0 0 240,21 0 1 48,6 0 0 65535,6 0 0 0' -j DROP
   - feel free to combine that with other matcher, e.g. "-p tcp
--tcp-option 30" and just use cBPF to find the subtype: "(tcp[34] &
0xf0) == 0x30"

Thanks for your help. I added this in patch v2.

-Geliang

Quoted 6 lines

Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net