From patchwork Sat Feb 24 09:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 205792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1056517dyb; Sat, 24 Feb 2024 01:06:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXU3Lr0PXnWe1AQFVb3VVPBJTaFup8hgXPk5K8FWADoUrP1He749b+YD9LPnHfSnZH97I01f/S48qzwGyV/9MCa/NaXhQ== X-Google-Smtp-Source: AGHT+IHd35GgdTGFDJPAZcrkqv1uUuQfGvrpkYytDMvIxbKWdoGFpeRaMPu02tNAhIUvdINHF5SY X-Received: by 2002:a17:906:d0cc:b0:a3f:c3f0:68e0 with SMTP id bq12-20020a170906d0cc00b00a3fc3f068e0mr1161951ejb.42.1708765580109; Sat, 24 Feb 2024 01:06:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708765580; cv=pass; d=google.com; s=arc-20160816; b=vbMJGD1C1qfYwynefkWHMAIjM7KUt335T9X9tYABCND9rDwAQNy4ZPUJNt1OarvwLJ vX98A9nl8CMzGa6gnyvAu1tbjyxuAmTYikMjrECzNKwcuaeYN4GZMd6xYvJqqqvX/Oec qIevVwP2kBGBf5ZiovcGFi1VVd/6Ox7fw7/Gfhq92gPAL3baKeaLDrt+kX4Rozr37qAx 1oyF+xwyD5rAcmvUP3lqj3l6bBjAiy17LSxXEcMtS0FsLUGydbsFlV5zIUAwKRel9Gom bSQxXeq2IweWiqaJ5sknxCrCMoEGICpIlk97nvnhmYHeKq/D9zy2ItGWg/R20HtCy9bp RlVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GVf8ubtimcYBJcwjV010/pmV64cOLapisaNAn6DWlIA=; fh=Q8RGCX7fQhQCiHyKh9iofRtuiyMzpKAXlegOvGWDHw0=; b=IlISpuiq0eUjobqGhtuwWz5tVshfENFP5Ci8g8gAG9hUnn6Es3BALt2ZWkpN/g5JiX 4QUFU9+oUKQqc3j0zbKn8NgtoDglznUzDAENqgt4hqziHzcTQWyDh0BurjqmSrr1MIKx rsfIQlTT6cfMCpNhrig4HC1NgfeOqs2vvwNk76+xzIqdC9ERBvRZAP9Wi1MwSTK3mFIL lXPzp5KiomYgAAPrDgWmINdwE8PO7INj8R5dUhJWtgMkRON1KFYAc+BToqjaAK1uoPyj eOTLkH/eiFcCY5+5C5Ksf4ocSVksLs+t3umKdrS6HazfjowmFCg+MqK6r73ZML6DDx8y F6gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Y1KeiGhY; arc=pass (i=1 spf=pass spfdomain=arista.com dkim=pass dkdomain=arista.com dmarc=pass fromdomain=arista.com); spf=pass (google.com: domain of linux-kernel+bounces-79523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79523-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g26-20020a170906349a00b00a3d8a763267si363497ejb.953.2024.02.24.01.06.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 01:06:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Y1KeiGhY; arc=pass (i=1 spf=pass spfdomain=arista.com dkim=pass dkdomain=arista.com dmarc=pass fromdomain=arista.com); spf=pass (google.com: domain of linux-kernel+bounces-79523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79523-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B6DCB1F23D93 for ; Sat, 24 Feb 2024 09:06:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 549CD374F8; Sat, 24 Feb 2024 09:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="Y1KeiGhY" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA801B81F for ; Sat, 24 Feb 2024 09:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765490; cv=none; b=bYgQlvURK6oUS/0R4aJ14I/VpXjynWs7LWnnURx6p6vWV6DX3ggCrNj9qFGD9Lrfthq5FeFK4nZyIBdQm0NJVWLJRg66pP3PILpeUYGngrb/nH8pSMH3k+JuJDSw2Eib2hoUAfpZ5lgkh29D/MEMXGUHYwHMbu+K63OM4F6n+sA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765490; c=relaxed/simple; bh=dkVRlxZapEZPVo1HlQHs8NB5QOOr7LplY2MzBsV+hXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Qh2AyMYRtGBhtjdkIf8M7GhAHcKb5t4lrjacX8wr7h3eYNazwPfUh4uxyagHjYrPxEIB0VWH6V8JKKXZBL1Roo0D1qnmOwmdzf9U1zspRo3GDbUTSFvYRqIbeGpwt0yqv71X6U+OoxLTYQHDMxWJ4pQY42Gx2Ixay1yeVH8mUEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=arista.com; spf=pass smtp.mailfrom=arista.com; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b=Y1KeiGhY; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=arista.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arista.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4129f28a01eso398935e9.0 for ; Sat, 24 Feb 2024 01:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1708765486; x=1709370286; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GVf8ubtimcYBJcwjV010/pmV64cOLapisaNAn6DWlIA=; b=Y1KeiGhYmUO5yNXYu3tXNBNefWNzgQFKyVISJp771Q8EyXnqK0lgoU9UhWYPBUQrb0 cLkgL1G7x3Fktjkufv5JfYqfPEPjo5lCRYFrz+4xkzRt5JZxGEt+oFKQi9/4m+NcoJeC tfmaKACaswdRybDwXxxdq8I1fmoEHFf0clKHilnZtNldwVWDHE399H757spCU+nnj3tY Y8ML9T9fhjBSDjhhj3RU9Ukl/DKfjg4LQR028cNrrgVz8OSHQ1k5ISqfcYObWDKBW4DB dI8PIHut7hTdVMw039V/qszB/yzk8AZ2ZYhKAsQZP42wabxjtic3N6GN9nXMU9mEBbE1 bqKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708765486; x=1709370286; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GVf8ubtimcYBJcwjV010/pmV64cOLapisaNAn6DWlIA=; b=VUWLhz6zc5Ojx7L3GgVtVVXElSwNhSZXIPij5EUkwZTKV6ZQFYX/pVA/OFmfH8eWzO g7oIsSNeZ5rWr66s8x4B+BBpSsTJNJseKbRiQIFcH2Up1jdmCZuntt3CB3ilDIqZU4b6 3OxQYC4oWGyv50BnDKY+61crmLzq7MSwCnNZ4mhwK1aBXTmODBVkcxfOdqmcfBKLmI+D FDxpYSgGP9kUljS3Cr8I3LbwjUdeFk4HZ1F2DwMLWRIrEyMwec/cspVzOPdhmw2blMdZ +sn6d/XcbtUKWUL/wS/eeUI18AusIRcJ6ZOVxhJh6PwGX0ZG9ls6ZH16FCVNea20FlD/ n1mA== X-Forwarded-Encrypted: i=1; AJvYcCVivn0F3iYipRU1wkU1D7aIVIcSzz2WxI0c5fQbVQTUXjKSQr3sw+F7gyqxKr3GLsjvtKC3uEHago1tct6/mKX8hE/z5ffX4Hi8ERUM X-Gm-Message-State: AOJu0YwSOUwuvWEa6TQiJ4+DcCMl5MMZvKippyvnMV2/VzjMbLaN4ezP 6Y3d+xTIEsQTv8gTSHgobXBkvJ+Vby9e3PfT8gcXnB1Kp9AlLx7uv18l0sgzVA== X-Received: by 2002:a05:600c:384e:b0:412:7585:bea7 with SMTP id s14-20020a05600c384e00b004127585bea7mr1283665wmr.5.1708765486647; Sat, 24 Feb 2024 01:04:46 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m6-20020a7bce06000000b00410bca333b7sm5320593wmc.27.2024.02.24.01.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 01:04:45 -0800 (PST) From: Dmitry Safonov To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Shuah Khan , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Cc: Dmitry Safonov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> Subject: [PATCH net-next 03/10] net/tcp: Move tcp_inbound_hash() from headers Date: Sat, 24 Feb 2024 09:04:11 +0000 Message-ID: <20240224-tcp-ao-tracepoints-v1-3-15f31b7f30a7@arista.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240224-tcp-ao-tracepoints-v1-0-15f31b7f30a7@arista.com> References: <20240224-tcp-ao-tracepoints-v1-0-15f31b7f30a7@arista.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.13-dev-b6b4b X-Developer-Signature: v=1; a=ed25519-sha256; t=1708765347; l=5609; i=dima@arista.com; s=20231212; h=from:subject:message-id; bh=dkVRlxZapEZPVo1HlQHs8NB5QOOr7LplY2MzBsV+hXk=; b=HzEYB6ULcdQGce14J2gKFfRi/qiy0saSFeVJiAIyNQYfdgJYh26AS2kS5GQd2tsYsFbfJlDkt lVKpB4nMSWxC0MKnXOuOAu7E1YHjZ5/TdYZz3PxiEU+/cpbB4dzQ3YG X-Developer-Key: i=dima@arista.com; a=ed25519; pk=hXINUhX25b0D/zWBKvd6zkvH7W2rcwh/CH6cjEa3OTk= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791770576972763483 X-GMAIL-MSGID: 1791770576972763483 Two reasons: 1. It's grown up enough 2. In order to not do header spaghetti by including , which is necessary for TCP tracepoints. Signed-off-by: Dmitry Safonov --- include/net/tcp.h | 65 ++++--------------------------------------------- net/ipv4/tcp.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 61 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index c1fff9207e2d..c80bdfb5efe5 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2789,66 +2789,9 @@ static inline bool tcp_ao_required(struct sock *sk, const void *saddr, return false; } -/* Called with rcu_read_lock() */ -static inline enum skb_drop_reason -tcp_inbound_hash(struct sock *sk, const struct request_sock *req, - const struct sk_buff *skb, - const void *saddr, const void *daddr, - int family, int dif, int sdif) -{ - const struct tcphdr *th = tcp_hdr(skb); - const struct tcp_ao_hdr *aoh; - const __u8 *md5_location; - int l3index; - - /* Invalid option or two times meet any of auth options */ - if (tcp_parse_auth_options(th, &md5_location, &aoh)) { - tcp_hash_fail("TCP segment has incorrect auth options set", - family, skb, ""); - return SKB_DROP_REASON_TCP_AUTH_HDR; - } - - if (req) { - if (tcp_rsk_used_ao(req) != !!aoh) { - NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD); - tcp_hash_fail("TCP connection can't start/end using TCP-AO", - family, skb, "%s", - !aoh ? "missing AO" : "AO signed"); - return SKB_DROP_REASON_TCP_AOFAILURE; - } - } - - /* sdif set, means packet ingressed via a device - * in an L3 domain and dif is set to the l3mdev - */ - l3index = sdif ? dif : 0; - - /* Fast path: unsigned segments */ - if (likely(!md5_location && !aoh)) { - /* Drop if there's TCP-MD5 or TCP-AO key with any rcvid/sndid - * for the remote peer. On TCP-AO established connection - * the last key is impossible to remove, so there's - * always at least one current_key. - */ - if (tcp_ao_required(sk, saddr, family, l3index, true)) { - tcp_hash_fail("AO hash is required, but not found", - family, skb, "L3 index %d", l3index); - return SKB_DROP_REASON_TCP_AONOTFOUND; - } - if (unlikely(tcp_md5_do_lookup(sk, l3index, saddr, family))) { - NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); - tcp_hash_fail("MD5 Hash not found", - family, skb, "L3 index %d", l3index); - return SKB_DROP_REASON_TCP_MD5NOTFOUND; - } - return SKB_NOT_DROPPED_YET; - } - - if (aoh) - return tcp_inbound_ao_hash(sk, skb, family, req, l3index, aoh); - - return tcp_inbound_md5_hash(sk, skb, saddr, daddr, family, - l3index, md5_location); -} +enum skb_drop_reason tcp_inbound_hash(struct sock *sk, + const struct request_sock *req, const struct sk_buff *skb, + const void *saddr, const void *daddr, + int family, int dif, int sdif); #endif /* _TCP_H */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index c82dc42f57c6..5fd61ae6bcc9 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4485,6 +4485,78 @@ EXPORT_SYMBOL(tcp_inbound_md5_hash); #endif +/* Called with rcu_read_lock() */ +enum skb_drop_reason +tcp_inbound_hash(struct sock *sk, const struct request_sock *req, + const struct sk_buff *skb, + const void *saddr, const void *daddr, + int family, int dif, int sdif) +{ + const struct tcphdr *th = tcp_hdr(skb); + const struct tcp_ao_hdr *aoh; + const __u8 *md5_location; + int l3index; + + /* Invalid option or two times meet any of auth options */ + if (tcp_parse_auth_options(th, &md5_location, &aoh)) { + tcp_hash_fail("TCP segment has incorrect auth options set", + family, skb, ""); + return SKB_DROP_REASON_TCP_AUTH_HDR; + } + + if (req) { + if (tcp_rsk_used_ao(req) != !!aoh) { + u8 keyid, rnext, maclen; + + if (aoh) { + keyid = aoh->keyid; + rnext = aoh->rnext_keyid; + maclen = tcp_ao_hdr_maclen(aoh); + } else { + keyid = rnext = maclen = 0; + } + + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD); + tcp_hash_fail("TCP connection can't start/end using TCP-AO", + family, skb, "%s", + !aoh ? "missing AO" : "AO signed"); + return SKB_DROP_REASON_TCP_AOFAILURE; + } + } + + /* sdif set, means packet ingressed via a device + * in an L3 domain and dif is set to the l3mdev + */ + l3index = sdif ? dif : 0; + + /* Fast path: unsigned segments */ + if (likely(!md5_location && !aoh)) { + /* Drop if there's TCP-MD5 or TCP-AO key with any rcvid/sndid + * for the remote peer. On TCP-AO established connection + * the last key is impossible to remove, so there's + * always at least one current_key. + */ + if (tcp_ao_required(sk, saddr, family, l3index, true)) { + tcp_hash_fail("AO hash is required, but not found", + family, skb, "L3 index %d", l3index); + return SKB_DROP_REASON_TCP_AONOTFOUND; + } + if (unlikely(tcp_md5_do_lookup(sk, l3index, saddr, family))) { + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); + tcp_hash_fail("MD5 Hash not found", + family, skb, "L3 index %d", l3index); + return SKB_DROP_REASON_TCP_MD5NOTFOUND; + } + return SKB_NOT_DROPPED_YET; + } + + if (aoh) + return tcp_inbound_ao_hash(sk, skb, family, req, l3index, aoh); + + return tcp_inbound_md5_hash(sk, skb, saddr, daddr, family, + l3index, md5_location); +} + void tcp_done(struct sock *sk) { struct request_sock *req;