aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLawrence Brakmo <brakmo@fb.com>2018-01-25 19:14:11 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-01-25 19:41:14 -0500
commitf89013f66d0f1a0dad44c513318efb706399a36b (patch)
tree7589bf9c59c29c7fef4bfb2a7f7d98f679715a42
parentb13d880721729384757f235166068c315326f4a1 (diff)
bpf: Add sock_ops RTO callback
Adds an optional call to sock_ops BPF program based on whether the BPF_SOCK_OPS_RTO_CB_FLAG is set in bpf_sock_ops_flags. The BPF program is passed 2 arguments: icsk_retransmits and whether the RTO has expired. Signed-off-by: Lawrence Brakmo <brakmo@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--include/uapi/linux/bpf.h8
-rw-r--r--net/ipv4/tcp_timer.c7
2 files changed, 14 insertions, 1 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index aa128407c44d..c8cecf9cf5bd 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -982,7 +982,8 @@ struct bpf_sock_ops {
982}; 982};
983 983
984/* Definitions for bpf_sock_ops_cb_flags */ 984/* Definitions for bpf_sock_ops_cb_flags */
985#define BPF_SOCK_OPS_ALL_CB_FLAGS 0 /* Mask of all currently 985#define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0)
986#define BPF_SOCK_OPS_ALL_CB_FLAGS 0x1 /* Mask of all currently
986 * supported cb flags 987 * supported cb flags
987 */ 988 */
988 989
@@ -1019,6 +1020,11 @@ enum {
1019 * a congestion threshold. RTTs above 1020 * a congestion threshold. RTTs above
1020 * this indicate congestion 1021 * this indicate congestion
1021 */ 1022 */
1023 BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered.
1024 * Arg1: value of icsk_retransmits
1025 * Arg2: value of icsk_rto
1026 * Arg3: whether RTO has expired
1027 */
1022}; 1028};
1023 1029
1024#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */ 1030#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 6db3124cdbda..257abdde23b0 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -213,11 +213,18 @@ static int tcp_write_timeout(struct sock *sk)
213 icsk->icsk_user_timeout); 213 icsk->icsk_user_timeout);
214 } 214 }
215 tcp_fastopen_active_detect_blackhole(sk, expired); 215 tcp_fastopen_active_detect_blackhole(sk, expired);
216
217 if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))
218 tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB,
219 icsk->icsk_retransmits,
220 icsk->icsk_rto, (int)expired);
221
216 if (expired) { 222 if (expired) {
217 /* Has it gone just too far? */ 223 /* Has it gone just too far? */
218 tcp_write_err(sk); 224 tcp_write_err(sk);
219 return 1; 225 return 1;
220 } 226 }
227
221 return 0; 228 return 0;
222} 229}
223 230