<div dir="ltr">hmm, this looks interesting to a test & measurement guy. Can it be done with a setsockopt? I might want to add this as an iperf2 option, particularly if it's broadly available,<br><br>Thanks,<br>Bob</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 1, 2021 at 9:22 AM Luigi Rizzo <<a href="mailto:rizzo@iet.unipi.it">rizzo@iet.unipi.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Sep 29, 2021 at 1:17 AM Dave Taht <<a href="mailto:dave.taht@gmail.com" target="_blank">dave.taht@gmail.com</a>> wrote:<br>
><br>
> In today's rpm meeting I didn't quite manage to make a complicated<br>
> point. This long-ago proposal<br>
> of matt mathis's has often intrigued (inspired? frightened?) me:<br>
><br>
> <a href="https://datatracker.ietf.org/doc/html/draft-mathis-iccrg-relentless-tcp-00" rel="noreferrer" target="_blank">https://datatracker.ietf.org/doc/html/draft-mathis-iccrg-relentless-tcp-00</a><br>
><br>
> where he proposed that a tcp variant have no response at all to loss<br>
> or markings, merely<br>
> replacing lost segments as they are requested, continually ramping up<br>
> until the network<br>
> basically explodes.<br>
<br>
<br>
For a similar purpose, I use the following patch that ignores holes,<br>
thus mostly defeating congestion control.<br>
<br>
The nice thing is that you can just count sent and received bytes<br>
in the application to estimate losses<br>
<br>
commit 9c429c9644f2fd22d5fe2b6f2d4df6fb2a8962b2<br>
Author: Luigi Rizzo <<a href="mailto:lrizzo@google.com" target="_blank">lrizzo@google.com</a>><br>
Date: Fri Oct 1 09:10:44 2021 -0700<br>
<br>
test: module parameter to ignore holes in TCP<br>
<br>
Sometimes, for testing, it is useful to let the TCP receiver ignore<br>
drops (and defeat congestion control) and accept all packets as if they<br>
were in sequence. This will show whether a connection is sender or<br>
receiver throttled.<br>
<br>
This patch implements the above with 3 /sys/module/tcp_input/parameters :<br>
- lossy_local_port, lossy_remote_port<br>
if non zero, indicate that sockets matching one of these ports<br>
will be set to ignore drops. (This socker flag could be set with a<br>
setsockopt(), but would require changes in the caller);<br>
- drop_freq<br>
if non zero, one every drop_freq packets will be artificially<br>
dropped on the receive side.<br>
<br>
Example<br>
echo 2345 > /sys/module/tcp_input/parameters/lossy_local_port<br>
echo 10 > /sys/module/tcp_input/parameters/drop_freq # drop one in 10<br>
<br>
ifconfig lo mtu 600<br>
nc -l 2345 > /tmp/a &<br>
MSG="this is a test this is a test this is a test count is"<br>
(for ((i=0;i<10000;i++)); do echo "${MSG} ${i}; $i"; done) | nc<br>
127.0.0.1 2345<br>
<br>
The output file will have missing lines<br>
<br>
<br>
diff --git a/include/linux/tcp.h b/include/linux/tcp.h<br>
index 48d8a363319e..3bb8888a56af 100644<br>
--- a/include/linux/tcp.h<br>
+++ b/include/linux/tcp.h<br>
@@ -225,7 +225,8 @@ struct tcp_sock {<br>
u8 compressed_ack;<br>
u8 dup_ack_counter:2,<br>
tlp_retrans:1, /* TLP is a retransmission */<br>
- unused:5;<br>
+ ignore_holes:1, /* ignore holes on rx. test only */<br>
+ unused:4;<br>
u32 chrono_start; /* Start time in jiffies of a TCP chrono */<br>
u32 chrono_stat[3]; /* Time in jiffies for chrono_stat stats */<br>
u8 chrono_type:2, /* current chronograph type */<br>
@@ -250,6 +251,7 @@ struct tcp_sock {<br>
u32 tlp_high_seq; /* snd_nxt at the time of TLP */<br>
<br>
u32 tcp_tx_delay; /* delay (in usec) added to TX packets */<br>
+ u32 tcp_test_drops; /* artificial packet drops. test only */<br>
u64 tcp_wstamp_ns; /* departure time for next sent data packet */<br>
u64 tcp_clock_cache; /* cache last tcp_clock_ns() (see<br>
tcp_mstamp_refresh()) */<br>
<br>
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c<br>
index 414c179c28e0..fd770a176a68 100644<br>
--- a/net/ipv4/tcp.c<br>
+++ b/net/ipv4/tcp.c<br>
@@ -2344,6 +2344,9 @@ static int tcp_recvmsg_locked(struct sock *sk,<br>
struct msghdr *msg, size_t len,<br>
last = skb_peek_tail(&sk->sk_receive_queue);<br>
skb_queue_walk(&sk->sk_receive_queue, skb) {<br>
last = skb;<br>
+ /* XXX if we allow holes, update copied_seq */<br>
+ if (tp->ignore_holes && before(*seq,<br>
TCP_SKB_CB(skb)->seq))<br>
+ *seq = TCP_SKB_CB(skb)->seq;<br>
/* Now that we have two receive queues this<br>
* shouldn't happen.<br>
*/<br>
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c<br>
index 246ab7b5e857..a5161ce78171 100644<br>
--- a/net/ipv4/tcp_input.c<br>
+++ b/net/ipv4/tcp_input.c<br>
@@ -81,6 +81,14 @@<br>
#include <net/busy_poll.h><br>
#include <net/mptcp.h><br>
<br>
+#include <linux/module.h><br>
+static int drop_freq; /* drop one pkt ever this many */<br>
+module_param(drop_freq, int, 0644);<br>
+static int lossy_local_port = 2345; /* drop pkts, ignore holes on this port */<br>
+module_param(lossy_local_port, int, 0644);<br>
+static int lossy_remote_port = 0; /* drop pkts, ignore holes on this port */<br>
+module_param(lossy_remote_port, int, 0644);<br>
+<br>
int sysctl_tcp_max_orphans __read_mostly = NR_FILE;<br>
<br>
#define FLAG_DATA 0x01 /* Incoming frame contained data.<br>
*/<br>
@@ -5806,6 +5814,16 @@ void tcp_rcv_established(struct sock *sk,<br>
struct sk_buff *skb)<br>
<br>
tp->rx_opt.saw_tstamp = 0;<br>
<br>
+ if (tp->ignore_holes) {<br>
+ const u32 seq = TCP_SKB_CB(skb)->seq;<br>
+ if (drop_freq && tp->tcp_test_drops++ >= drop_freq) {<br>
+ tp->tcp_test_drops = 0;<br>
+ goto discard; /* artificial drop */<br>
+ }<br>
+ if (after(seq, tp->rcv_nxt)) /* Pretend this is in order */<br>
+ tcp_rcv_nxt_update(tp, seq);<br>
+ }<br>
+<br>
/* pred_flags is 0xS?10 << 16 + snd_wnd<br>
* if header_prediction is to be made<br>
* 'S' will always be tp->tcp_header_len >> 2<br>
@@ -5986,12 +6004,25 @@ void tcp_init_transfer(struct sock *sk, int<br>
bpf_op, struct sk_buff *skb)<br>
tcp_init_buffer_space(sk);<br>
}<br>
<br>
+/* Testing. Conditionally set tp->ignore_holes. Should be a setsockopt */<br>
+static void tcp_update_ignore_holes(struct sock *sk)<br>
+{<br>
+ if (READ_ONCE(lossy_local_port) == ntohs(inet_sk(sk)->inet_sport) ||<br>
+ READ_ONCE(lossy_remote_port) == ntohs(inet_sk(sk)->inet_dport)) {<br>
+ pr_info("XXX ignore holes for ports local %d remote %d\n",<br>
+ ntohs(inet_sk(sk)->inet_sport),<br>
+ ntohs(inet_sk(sk)->inet_dport));<br>
+ tcp_sk(sk)->ignore_holes = 1;<br>
+ }<br>
+}<br>
+<br>
void tcp_finish_connect(struct sock *sk, struct sk_buff *skb)<br>
{<br>
struct tcp_sock *tp = tcp_sk(sk);<br>
struct inet_connection_sock *icsk = inet_csk(sk);<br>
<br>
tcp_set_state(sk, TCP_ESTABLISHED);<br>
+ tcp_update_ignore_holes(sk);<br>
icsk->icsk_ack.lrcvtime = tcp_jiffies32;<br>
<br>
if (skb) {<br>
@@ -6476,6 +6507,7 @@ int tcp_rcv_state_process(struct sock *sk,<br>
struct sk_buff *skb)<br>
}<br>
smp_mb();<br>
tcp_set_state(sk, TCP_ESTABLISHED);<br>
+ tcp_update_ignore_holes(sk);<br>
sk->sk_state_change(sk);<br>
<br>
/* Note, that this wakeup is only for marginal crossed SYN case.<br>
</blockquote></div>
<br>
<span style="background-color:rgb(255,255,255)"><font size="2">This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.</font></span>