From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lawrence Brakmo Subject: [PATCH bpf-next v4 06/11] bpf: Add sock_ops RTO callback Date: Thu, 4 Jan 2018 15:55:28 -0800 Message-ID: <20180104235533.3672006-7-brakmo@fb.com> References: <20180104235533.3672006-1-brakmo@fb.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Kernel Team , Blake Matheny , Alexei Starovoitov , Daniel Borkmann , Eric Dumazet , Neal Cardwell , Yuchung Cheng To: netdev Return-path: Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:59618 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751116AbeADXzh (ORCPT ); Thu, 4 Jan 2018 18:55:37 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w04Nsfhh028484 for ; Thu, 4 Jan 2018 15:55:37 -0800 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2f9sdvgt9q-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 04 Jan 2018 15:55:37 -0800 In-Reply-To: <20180104235533.3672006-1-brakmo@fb.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- include/uapi/linux/bpf.h | 5 +++++ include/uapi/linux/tcp.h | 3 +++ net/ipv4/tcp_timer.c | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index f7adeca..a1316c7 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -998,6 +998,11 @@ enum { * a congestion threshold. RTTs above * this indicate congestion */ + BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered. + * Arg1: value of icsk_retransmits + * Arg2: value of icsk_rto + * Arg3: whether RTO has expired + */ }; #define TCP_BPF_IW 1001 /* Set TCP initial congestion window */ diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index b4a4f64..089c19e 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -259,6 +259,9 @@ struct tcp_md5sig { __u8 tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* key (binary) */ }; +/* Definitions for bpf_sock_ops_flags */ +#define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0) + /* INET_DIAG_MD5SIG */ struct tcp_diag_md5sig { __u8 tcpm_family; diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 6db3124..257abdd 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) icsk->icsk_user_timeout); } tcp_fastopen_active_detect_blackhole(sk, expired); + + if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG)) + tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB, + icsk->icsk_retransmits, + icsk->icsk_rto, (int)expired); + if (expired) { /* Has it gone just too far? */ tcp_write_err(sk); return 1; } + return 0; } -- 2.9.5