Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2930622lqp; Mon, 25 Mar 2024 13:28:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5m/0MwbZFWvnuZw1wrk7csrQXnl98umFx0BL5MO6HpScApBdQ9aeHDIS0GJg/DnTkSTWeInygbKW+Zv/xdCoqpgR9+4WRC81BHHMS2g== X-Google-Smtp-Source: AGHT+IHB1e/bonzT6/vmNIPORiRSDjA0e7p2riopYxVLi0FTxtgtNV0zXhBioL2fooo5bfGW7KU9 X-Received: by 2002:a05:6a21:3983:b0:1a3:cec6:17a4 with SMTP id ad3-20020a056a21398300b001a3cec617a4mr2800591pzc.62.1711398516987; Mon, 25 Mar 2024 13:28:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711398516; cv=pass; d=google.com; s=arc-20160816; b=uz1u/hEAr8SA57m0talOEhmOcfgDdsCzuggdtHHmTa2QHPkcHV8p/KXqq/jotKulJ9 4DGQimMlGWi9fZTxJqQboXKXPgJc952FJDsQwrHpmjwpWlgmypu6mNogIFveFrNOeeJr jNE+w7f/F4ZNLWCZdLmGbgpe4xpxwefVGameMp4jBstQPbpjmeq6axq6ZrlSEv6HE/im MqkK1N1n6QHrZOG/YhpulIzc9A2SsOvHdT/mvkeZxq/3K6mMHrsnmFC1Uwr97D5fCsZ4 ohdozR54D6xUKxuMC80imdLnlLDM9oEbTTRBDeebEzVYKyVInk8hS5eSpbvCYv6BdzaB 8v6g== 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=/EabZCAmYyC9fAriiA6X6yV4dOCGsBHE168qYS8MPOw=; fh=oEv5vhnEPzk6kjWGGgqiwMUQWCLBHU42xgtvgKU5c3Y=; b=f/yzNGaMEG7krAkI3Aq1bg/WcmjsbUGX9gNE8WVgK7XLf0Zioc2hISO9ElG0AGiDGj 5yOOBr030p0MSVAKds0pNyNquZAQWypo1wVxYP7MMILgAMU1vbQI7pBKO1GNVyaAany9 MnBfmQGP0nrR6lws9bK/NIHbRolPJ6refe0cc9qt1KDLS9mnV7ViUWsPIFFFSxdil8hF zZQbEEFeLjADeJ8bNaUPQry1F2gITR/GBUU6l/Oph53ezoVt4KAZbBuTrWI8EujAC6Mv 2x+9YSfFHEVoHvqzD3THaY1fS5az++/NJVzilkG0KSsEY5Hzo9GnuYXguDzAFi9vIjQo oLPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="l0/ZyBh7"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-116839-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116839-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s25-20020a056a00179900b006e6cc7b96a5si6122816pfg.60.2024.03.25.13.28.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:28:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116839-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="l0/ZyBh7"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-116839-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116839-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AF020B278B9 for ; Mon, 25 Mar 2024 14:26:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 459A114F9DE; Mon, 25 Mar 2024 11:07:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l0/ZyBh7" Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 B8C7413CA9B; Mon, 25 Mar 2024 10:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711362567; cv=none; b=XsKXv0ESWf0DhUgVxTQQ8RSvoz4TCnKyWPGVAapJc/HVeCwX8Fn81hN6WB2BeveB9pv4OIaWEI0ECwGtzOqFYO7eb+ldLozG8sOlCwFZjQGMA/ZIBHBG5JRtRPApRD3o4+biMnY2OclwpLWo/f2uTHOTphtxjV5KnRIrfW9Rn7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711362567; c=relaxed/simple; bh=AEkgv8xYLM1Y6P5xl+hZbNb+Us9X3rjZQ/skIPmLP8U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C/S5eO4Br0OVirDY3c3D0pVP5pRCLGOPZSQrqc8yV76r6Vd+iKeg6lZMZZz9NiB0dpVqJwl8+oDUubtLaextxk7aG5uBWFfBnUXGy8Pof5pO7u4jdAUtSl2OSiPBIdXTR/gcdybMGAGhMpfxuxkqEOr7mbkrls6nDm5E220XGi8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l0/ZyBh7; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33fd8a2a407so2859851f8f.2; Mon, 25 Mar 2024 03:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711362564; x=1711967364; 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=/EabZCAmYyC9fAriiA6X6yV4dOCGsBHE168qYS8MPOw=; b=l0/ZyBh7p69zKfiQXj5yQB8I3ks5k37fVDejAv2n3p8U3KCtNlcwZV0vsZZIpU9Qii NsCKIqRkhBdoJ8FSdlE57MLvAxj9UAly2XLQ7gAgimjRmoRCfh7g05g1iwlIz1TTkccL rwUIhdyQ5uA1pjEiJ9TwGJHK0Druatk6bqkbRx4Axa3HiXY0YXhRMa/XN2PDS7ZyNUBi +xLEoN5NSKlzA+LP6T16n2bWNuhH5BfBkHv6FSrJ/y8dCaBLeluWI5bYuaoVpkMV6fYO GAac2+po/HF+u56WJlnI5SazQyhoEkeh0d8lRf1726MlY7enZC4kJhaP8Qdu0bokWNCW Xz8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711362564; x=1711967364; 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=/EabZCAmYyC9fAriiA6X6yV4dOCGsBHE168qYS8MPOw=; b=jbpmtDfUHGNkit735fRqUeVm8ouUUqe4UNppFG/2ppE6Nli5V2DGzdI0R4uq4UKlIg DTLvY90QN7oidoP9E2vQ/fBqvzg9qAt6IItfCqlI8Yzrwm0ifVuvwM2vY6KRT78zeyp5 liMAHqXACWJDGmc3sylm2iKWfbuxIhTHIrq0VTvM5+Ge1zn4HhD7Z8UW3IQVCec6+OSu Ega8ZYH4bfDCNSfHIYZzg0aitTpuN7Fm0aQuODVTKvlXygujEGfitLWL0956NBYxD+Ro cuUabEQb1XjL6TBqKQdMC6ehQqBoyQew4bCUwCJPRfgCiBm3i4w27pZ7sQKWr+hd0E7x uqwQ== X-Forwarded-Encrypted: i=1; AJvYcCUeQSyE4BL3dGFIK4MjBTNUOa1VfQaJM6swXXFQbVlOIoH96hgyRWnhWmUz+QFrVsN29uN2E3zlCJuzX2wviM/h18Gky27IACdBw2cOCDuXy1fUis6+/xWlDre6RtQ8pKvB6VrEcXTVW+UZ3UuVkqtfwSmr+3nOHDc8YL2fmiZGBfLUQkcfKNLp X-Gm-Message-State: AOJu0YxqGR0dXJvCJwOpylGYhyAXB2famobQDn5B5HRW++RMH84qnyDF hpIhSjSB+DJID4NGPEYvF7D+Nc4an0mm/w8ckOQ4DGc7qSjHqw35 X-Received: by 2002:adf:e94a:0:b0:33e:d470:da8f with SMTP id m10-20020adfe94a000000b0033ed470da8fmr3937861wrn.17.1711362564039; Mon, 25 Mar 2024 03:29:24 -0700 (PDT) Received: from localhost.localdomain (91-83-10-45.pool.digikabel.hu. [91.83.10.45]) by smtp.gmail.com with ESMTPSA id bq22-20020a5d5a16000000b00341d0458950sm1394958wrb.15.2024.03.25.03.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:29:23 -0700 (PDT) From: Balazs Scheidler X-Google-Original-From: Balazs Scheidler To: kerneljasonxing@gmail.com, kuniyu@amazon.com, netdev@vger.kernel.org, Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Eric Dumazet Cc: Balazs Scheidler , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH net-next v3 1/2] net: port TP_STORE_ADDR_PORTS_SKB macro to be tcp/udp independent Date: Mon, 25 Mar 2024 11:29:17 +0100 Message-Id: <394f9d55197681e910d104dbd35e62fb4098712b.1711361723.git.balazs.scheidler@axoflow.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch moves TP_STORE_ADDR_PORTS_SKB() to a common header and removes the TCP specific implementation details. Previously the macro assumed the skb passed as an argument is a TCP packet, the implementation now uses an argument to the L4 header and uses that to extract the source/destination ports, which happen to be named the same in "struct tcphdr" and "struct udphdr" Signed-off-by: Balazs Scheidler --- include/trace/events/net_probe_common.h | 41 ++++++++++++++++++++++ include/trace/events/tcp.h | 45 ++----------------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/trace/events/net_probe_common.h b/include/trace/events/net_probe_common.h index 3930119cab08..50c083b5687d 100644 --- a/include/trace/events/net_probe_common.h +++ b/include/trace/events/net_probe_common.h @@ -41,4 +41,45 @@ #endif +#define TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb, protoh) \ + do { \ + struct sockaddr_in *v4 = (void *)__entry->saddr; \ + \ + v4->sin_family = AF_INET; \ + v4->sin_port = protoh->source; \ + v4->sin_addr.s_addr = ip_hdr(skb)->saddr; \ + v4 = (void *)__entry->daddr; \ + v4->sin_family = AF_INET; \ + v4->sin_port = protoh->dest; \ + v4->sin_addr.s_addr = ip_hdr(skb)->daddr; \ + } while (0) + +#if IS_ENABLED(CONFIG_IPV6) + +#define TP_STORE_ADDR_PORTS_SKB(__entry, skb, protoh) \ + do { \ + const struct iphdr *iph = ip_hdr(skb); \ + \ + if (iph->version == 6) { \ + struct sockaddr_in6 *v6 = (void *)__entry->saddr; \ + \ + v6->sin6_family = AF_INET6; \ + v6->sin6_port = protoh->source; \ + v6->sin6_addr = ipv6_hdr(skb)->saddr; \ + v6 = (void *)__entry->daddr; \ + v6->sin6_family = AF_INET6; \ + v6->sin6_port = protoh->dest; \ + v6->sin6_addr = ipv6_hdr(skb)->daddr; \ + } else \ + TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb, protoh); \ + } while (0) + +#else + +#define TP_STORE_ADDR_PORTS_SKB(__entry, skb, protoh) \ + TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb, protoh) + +#endif + + #endif diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h index 699dafd204ea..5f19c5c6cda8 100644 --- a/include/trace/events/tcp.h +++ b/include/trace/events/tcp.h @@ -302,48 +302,6 @@ TRACE_EVENT(tcp_probe, __entry->skbaddr, __entry->skaddr) ); -#define TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb) \ - do { \ - const struct tcphdr *th = (const struct tcphdr *)skb->data; \ - struct sockaddr_in *v4 = (void *)__entry->saddr; \ - \ - v4->sin_family = AF_INET; \ - v4->sin_port = th->source; \ - v4->sin_addr.s_addr = ip_hdr(skb)->saddr; \ - v4 = (void *)__entry->daddr; \ - v4->sin_family = AF_INET; \ - v4->sin_port = th->dest; \ - v4->sin_addr.s_addr = ip_hdr(skb)->daddr; \ - } while (0) - -#if IS_ENABLED(CONFIG_IPV6) - -#define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \ - do { \ - const struct iphdr *iph = ip_hdr(skb); \ - \ - if (iph->version == 6) { \ - const struct tcphdr *th = (const struct tcphdr *)skb->data; \ - struct sockaddr_in6 *v6 = (void *)__entry->saddr; \ - \ - v6->sin6_family = AF_INET6; \ - v6->sin6_port = th->source; \ - v6->sin6_addr = ipv6_hdr(skb)->saddr; \ - v6 = (void *)__entry->daddr; \ - v6->sin6_family = AF_INET6; \ - v6->sin6_port = th->dest; \ - v6->sin6_addr = ipv6_hdr(skb)->daddr; \ - } else \ - TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb); \ - } while (0) - -#else - -#define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \ - TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb) - -#endif - /* * tcp event with only skb */ @@ -360,12 +318,13 @@ DECLARE_EVENT_CLASS(tcp_event_skb, ), TP_fast_assign( + const struct tcphdr *th = (const struct tcphdr *)skb->data; __entry->skbaddr = skb; memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); - TP_STORE_ADDR_PORTS_SKB(__entry, skb); + TP_STORE_ADDR_PORTS_SKB(__entry, skb, th); ), TP_printk("skbaddr=%p src=%pISpc dest=%pISpc", -- 2.40.1