From patchwork Tue Dec 19 06:21:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Brakmo X-Patchwork-Id: 850628 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="X9qkLD+H"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z179P6QM5z9s81 for ; Tue, 19 Dec 2017 17:22:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934092AbdLSGWP (ORCPT ); Tue, 19 Dec 2017 01:22:15 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:33480 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1761363AbdLSGWH (ORCPT ); Tue, 19 Dec 2017 01:22:07 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.21/8.16.0.21) with SMTP id vBJ6IdpJ015933 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=LrXpSUwCebxHs1RRr62edN5tCOjSui1HEf7NbUzsF84=; b=X9qkLD+HG+5JBdlRtGjwXKUwejAGczxX+LPVLscKmNH8VpsuyEv3QcqbU44le1nPOUdL QXrepxTM6jlNLSGe4bbPKBqYrEZ0JCQ0TKgPHz1Axiz1Ps73sWbbvRPb853rrdn/dPbZ r7cgf938xgJ0poU9gwdT4L9H48a+iwj0dkI= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 2exvc103r4-1 (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-CHUB09.TheFacebook.com (192.168.16.19) with Microsoft SMTP Server id 14.3.361.1; Mon, 18 Dec 2017 22:22:06 -0800 Received: by dev15893.prn1.facebook.com (Postfix, from userid 10340) id 8FE28C245E6; Mon, 18 Dec 2017 22:22:04 -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 02/11] bpf: Make SOCK_OPS_GET_TCP struct independent Date: Mon, 18 Dec 2017 22:21:51 -0800 Message-ID: <20171219062200.372711-3-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 Changed SOCK_OPS_GET_TCP to SOCK_OPS_GET_FIELD and added a new argument so now it can also work with struct sock fields. Previous: SOCK_OPS_GET_TCP(FIELD_NAME) New: SOCK_OPS_GET_FIELD(FIELD_NAME, OBJ) Where OBJ is either "struct tcp_sock" or "struct sock" (without quotation). Assumes FIELD_NAME is a field in the struct bpf_sock_ops and in the OBJ specified. Signed-off-by: Lawrence Brakmo --- net/core/filter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index d47d126..f808269 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4447,10 +4447,10 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, is_fullsock)); break; -/* Helper macro for adding read access to tcp_sock fields. */ -#define SOCK_OPS_GET_TCP(FIELD_NAME) \ +/* Helper macro for adding read access to tcp_sock or sock fields. */ +#define SOCK_OPS_GET_FIELD(FIELD_NAME, OBJ) \ do { \ - BUILD_BUG_ON(FIELD_SIZEOF(struct tcp_sock, FIELD_NAME) > \ + BUILD_BUG_ON(FIELD_SIZEOF(OBJ, FIELD_NAME) > \ FIELD_SIZEOF(struct bpf_sock_ops, FIELD_NAME)); \ *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF( \ struct bpf_sock_ops_kern, \ @@ -4463,18 +4463,18 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, struct bpf_sock_ops_kern, sk),\ si->dst_reg, si->src_reg, \ offsetof(struct bpf_sock_ops_kern, sk));\ - *insn++ = BPF_LDX_MEM(FIELD_SIZEOF(struct tcp_sock, \ - FIELD_NAME), si->dst_reg, \ - si->dst_reg, \ - offsetof(struct tcp_sock, FIELD_NAME)); \ + *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(OBJ, \ + FIELD_NAME), \ + si->dst_reg, si->dst_reg, \ + offsetof(OBJ, FIELD_NAME)); \ } while (0) case offsetof(struct bpf_sock_ops, snd_cwnd): - SOCK_OPS_GET_TCP(snd_cwnd); + SOCK_OPS_GET_FIELD(snd_cwnd, struct tcp_sock); break; case offsetof(struct bpf_sock_ops, srtt_us): - SOCK_OPS_GET_TCP(srtt_us); + SOCK_OPS_GET_FIELD(srtt_us, struct tcp_sock); break; } return insn - insn_buf;