Adds a new bpf_setsockopt for TCP sockets, TCP_BPF_IW, which sets the
initial congestion window. This can be used when the hosts are far
apart (large RTTs) and it is safe to start with a large inital cwnd.

Signed-off-by: Lawrence Brakmo <bra...@fb.com>
---
 include/uapi/linux/bpf.h |  2 ++
 net/core/filter.c        | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 8d1d2b7..ecb28e2 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -781,4 +781,6 @@ enum {
                                         */
 };
 
+#define TCP_BPF_IW             1001    /* Set TCP initial congestion window */
+
 #endif /* _UAPI__LINUX_BPF_H__ */
diff --git a/net/core/filter.c b/net/core/filter.c
index 4325aba..a1d9214 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2723,7 +2723,19 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_socket_ops_kern *, 
bpf_socket,
                                tcp_reinit_congestion_control(sk,
                                        inet_csk(sk)->icsk_ca_ops);
                } else {
-                       ret = -EINVAL;
+                       struct tcp_sock *tp = tcp_sk(sk);
+
+                       val = *((int *)optval);
+                       switch (optname) {
+                       case TCP_BPF_IW:
+                               if (val <= 0 || tp->data_segs_out > 0)
+                                       ret = -EINVAL;
+                               else
+                                       tp->snd_cwnd = val;
+                               break;
+                       default:
+                               ret = -EINVAL;
+                       }
                }
        } else {
                ret = -EINVAL;
-- 
2.9.3

Reply via email to