From patchwork Tue Dec 19 06:21:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Brakmo X-Patchwork-Id: 850629 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="lFXKFCuC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z179S5922z9s81 for ; Tue, 19 Dec 2017 17:22:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934216AbdLSGWR (ORCPT ); Tue, 19 Dec 2017 01:22:17 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:39522 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761364AbdLSGWI (ORCPT ); Tue, 19 Dec 2017 01:22:08 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBJ6IraI021288 for ; Mon, 18 Dec 2017 22:22:07 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=JIvpt3L4J1k/TuewckuEOIRJPMuTZwdSpw11cHefWiY=; b=lFXKFCuCVnBvec0R34J/2nDMnXyHep02y0jDoG3YE/BSZzyN3S9eswgoohXKX6EfS9xD Icet5UItclGXjBqOIAmIhjyHTzeNYRfla3HdSDqsAi4UHEO7fgoJcGXDx9bICnES3N/Y t9oXJlVWPD3XZFEAMwwg+XyR/X5hk0iE9Rk= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2exqrvgnne-5 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 18 Dec 2017 22:22:07 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB07.TheFacebook.com (192.168.16.17) with Microsoft SMTP Server id 14.3.361.1; Mon, 18 Dec 2017 22:22:05 -0800 Received: by dev15893.prn1.facebook.com (Postfix, from userid 10340) id A4107C2462A; Mon, 18 Dec 2017 22:22:05 -0800 (PST) Smtp-Origin-Hostprefix: dev From: Lawrence Brakmo Smtp-Origin-Hostname: dev15893.prn1.facebook.com To: netdev CC: Kernel Team , Blake Matheny , Alexei Starovoitov , Daniel Borkmann Smtp-Origin-Cluster: prn1c29 Subject: [PATCH bpf 06/11] bpf: Add sock_ops RTO callback Date: Mon, 18 Dec 2017 22:21:55 -0800 Message-ID: <20171219062200.372711-7-brakmo@fb.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171219062200.372711-1-brakmo@fb.com> References: <20171219062200.372711-1-brakmo@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-19_04:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index dfbf43a..1c36795 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -989,6 +989,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 16df6dd..e6afd93 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -230,9 +230,18 @@ static int tcp_write_timeout(struct sock *sk) } if (expired) { /* Has it gone just too far? */ + 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, 1); tcp_write_err(sk); return 1; } + + 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, 0); return 0; }