From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 B82672A1AA; Wed, 2 Jul 2025 10:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450809; cv=none; b=JU4OddMg7qWayFepp/+imPzfdnW7AJdNnUZe8YtaMBFRG+2NErtycDxNscRkftSTp1aJzJbWcDmtQ1wkmSW6vMydNA2HqHCzkKCY/ND9HmejI1Qv9Yo/MeTISvN780vh2jZlo3E3zYmEecI69itERs+TawGzZ+1eMKd6UjF0rxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450809; c=relaxed/simple; bh=jbCjWV/h7n2SHM7aPePgMluwf8TLq/orMZ98gJOmxn8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fM+VrCm1zuyWbqOUDSTT9kcEUtKYR3wQYTjub0gZKQN9bQs3GwKborCNxr2WH5Alb3327JdUNmrfAqoFnBeEm8idrVIUNoVDXv+VpbjvSftPdXNKJxVaK+DLM7KKqRZXA/MYR6fsGbtxL7wPT6hdYJJMV6ulqRdGe8po2b+pLlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-60c60f7eeaaso11050592a12.0; Wed, 02 Jul 2025 03:06:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450806; x=1752055606; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BdAqTjFNYTelvz4grTCp7T82BdTogW49IVN7Iv0xIeg=; b=UuXr8jZ+sqF9z621GySBnQy3CddAJb72sAeooMEnHqoejz410zC4AzzxwEOLeJ7wKk qv9+ynTkj8zDl3OllU0wuh5y39I9lVKTKFDjYvTX2N3BWQmLJbkH/oYHoo1o0A7dsztr 9ZUIJKmgAEoODOR/MaE76EXs7kvnWd/LewIRUxtAeHkhVzZNMrEGpjqitgkEICryqE2b HEHBquegfD219ZaB8Qpcy5cSSGPXY1pKEOBNPXfHFkjLtH8UHILiB0smkkdbNkrAUWcb jrNWfD8OQSkzx0YZmp6MI1fUDwyiemv6tKQNoNq0SHWHLBXR1FYIaMe5GRhoRs4td3/6 +OHg== X-Forwarded-Encrypted: i=1; AJvYcCVL3pQwfYQFWRPY2QlOHtby/OThJb9VW3y2PoDnfu1WgJLTN1Br0mr08kzlnZTqGGrr2lXCLU4Qq6yQwW3KB97H@vger.kernel.org, AJvYcCXe5uTLSL6Nccm2/+gEs3M5sywb1ZI5aHeZXKLw5JUI87ya//sltEmkd+dxW26X8wy8/+FgBC16UOAqCRY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4WaAyn+Xnt/Jz1D/BDjz4LyUAC0LgWDeoaBn1tyUBUk2Wacfk atMxyC9NytJXLAobrQRTgTxmTLhdhLTFRiqQF/LVLvX/huni8PRKbfgK X-Gm-Gg: ASbGncvkK1zKYXxIDhrXyf8anmwo2rQW0V9H0xQQXCQWIF+Y6aUKuUwWkHuzUbjQn7h OlhO7hr5m7qLjZfLOvJLVW1s0xi8knedcgQ0WGEoM3eIudk7SnEl/DijqzdaHUhLF/ngHk7/XQj 8upsm5vPdy6bV0nEi4/DeZW+VrQX9BYaY+B37VQLMc1lIFqjlbYVBPfqQ+HWhXfxWVkgnMiX4YW vpNK+gO5kESMnqkPVqSVHZ7kPFGddssdMqZx6ef6TPF37ZNqTfGVbPY7PvTQBfofjwIXfpWu0Lz uKrFNMhWN8aCORYxEdwxc1zDooHknRJhvWXLLClBuj5zZEuNqYwO5A== X-Google-Smtp-Source: AGHT+IFfl328+IlYGpptBsWQ455Ds8A/oKtoUN3qUBUcC1BpoxDjsVdMAlR+Sgxscnzkzq+ufFr2Lg== X-Received: by 2002:a05:6402:909:b0:604:e602:77a5 with SMTP id 4fb4d7f45d1cf-60e52d0457cmr1978769a12.15.1751450805619; Wed, 02 Jul 2025 03:06:45 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:71::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60c8319f50bsm8720744a12.50.2025.07.02.03.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:45 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:33 -0700 Subject: [PATCH net-next v2 1/7] netpoll: Improve code clarity with explicit struct size calculations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-1-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2146; i=leitao@debian.org; h=from:subject:message-id; bh=jbCjWV/h7n2SHM7aPePgMluwf8TLq/orMZ98gJOmxn8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyHxec+z/U1kefZ+yfGIkFInKDJ8GFFZDP4 FZAEQzvLIaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bS/iD/4l46DQVLcMEnWfnS6wuhf87uD8ChGV6CCtToYw3pqYzoha931JvB6USs18PfwvIz5GWaL mDTclwfuzyWIb7xqEBWlHgjPD/iYBc6X+j9KPZUWmcM5CSosJt0XbVi48v5Ss+TxnvIJG2LnzZU YuvQFJUZXG0iwN7MDKuT9duMOrVkGhiMmdWdOMs1m4+Z+QApFzNiPq2rZFqUJIsGRpC+JQ/HMLi i1iZQ8+tU45WppTAIo6PXAOhLuYoC0AjOKv7J7+H7hh9PHt5StC4pvo9nq2+oYIcLHlDTq61k5s iOG8iv/OK8mVy8wvKj7Fl/PAr5tmV776UQzT2rLgAG5GsatBGi6+0DsOPj5uc4KKCfo0Rvftw0T oEM+g86XrViKxTXQDD5az25xn8E1BZKexLikzoWAPDifKyYl7wZ6vZiu84t/GL9gjZ8Is0smLlT 2R3XlhSBY2dN/Y7Cm4j3RmEvkgt9fAJ7j6XWGgejS6OoYutGd5qFvlg8SRLN2Sqb6qYzjjAUd0Q Nekqxenz0gaL7/HdbcGAtDo6EOgUP41ujRo2ikr1N5eIk5sVbMD259Ry/MT0kpzpgB5BRcFMzB0 69hCMMFo1lXDwaI0TZr8iQ73WrWhyfATXYKDm4xgSGlfFz+nmQe8OCjhc8/A4wDwIWmI8tz18ek wF8X+Ur20qvRnaQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Replace pointer-dereference sizeof() operations with explicit struct names for improved readability and maintainability. This change: 1. Replaces `sizeof(*udph)` with `sizeof(struct udphdr)` 2. Replaces `sizeof(*ip6h)` with `sizeof(struct ipv6hdr)` 3. Replaces `sizeof(*iph)` with `sizeof(struct iphdr)` This will make it easy to move code in the upcoming patches. No functional changes are introduced by this patch. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 54f9d505895f6..ac0ae9630654a 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -402,11 +402,11 @@ int netpoll_send_udp(struct netpoll *np, const char *= msg, int len) if (!IS_ENABLED(CONFIG_PREEMPT_RT)) WARN_ON_ONCE(!irqs_disabled()); =20 - udp_len =3D len + sizeof(*udph); + udp_len =3D len + sizeof(struct udphdr); if (np->ipv6) - ip_len =3D udp_len + sizeof(*ip6h); + ip_len =3D udp_len + sizeof(struct ipv6hdr); else - ip_len =3D udp_len + sizeof(*iph); + ip_len =3D udp_len + sizeof(struct iphdr); =20 total_len =3D ip_len + LL_RESERVED_SPACE(np->dev); =20 @@ -418,7 +418,7 @@ int netpoll_send_udp(struct netpoll *np, const char *ms= g, int len) skb_copy_to_linear_data(skb, msg, len); skb_put(skb, len); =20 - skb_push(skb, sizeof(*udph)); + skb_push(skb, sizeof(struct udphdr)); skb_reset_transport_header(skb); udph =3D udp_hdr(skb); udph->source =3D htons(np->local_port); @@ -434,7 +434,7 @@ int netpoll_send_udp(struct netpoll *np, const char *ms= g, int len) if (udph->check =3D=3D 0) udph->check =3D CSUM_MANGLED_0; =20 - skb_push(skb, sizeof(*ip6h)); + skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); ip6h =3D ipv6_hdr(skb); =20 @@ -461,7 +461,7 @@ int netpoll_send_udp(struct netpoll *np, const char *ms= g, int len) if (udph->check =3D=3D 0) udph->check =3D CSUM_MANGLED_0; =20 - skb_push(skb, sizeof(*iph)); + skb_push(skb, sizeof(struct iphdr)); skb_reset_network_header(skb); iph =3D ip_hdr(skb); =20 --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 06944253938; Wed, 2 Jul 2025 10:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450810; cv=none; b=pcmSTN4I4CM4EOdyD4aiT6AzfkpIKpVjp1oDUZGKzePqdtoQW/5NF7tl9iMgCWljJH8t0rbTDYWliZbZKnyOOjZOAFQ45y03RFx79xlxhbFWT7jbWjZBwY5zWnkYnjgXMt6Rnm4H6L/x1KqrQ7fpaEenDG4VaY0HwpeAfo1Ljjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450810; c=relaxed/simple; bh=z6ZyZPgKMyV5y5bQXJoqji7LE1KbrdDAaxyolHnuv6Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TRo0dz3tiz8jh9H+LwGto13o84/6qCWd9zh1JNXqiHgGmfBzNkvd+YyKJNxqj4rnGUMFYuLKOG5aIDu6PXPw1IA+qX4gEUKExn+ezF8qmz+hB3SAhiQeeKLCnsiWoWymhPFwhp/voz8+YEHuEP44rXci9jphImX33G5E69KJYlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-60c5b8ee2d9so14336453a12.2; Wed, 02 Jul 2025 03:06:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450807; x=1752055607; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qUEhiAZpONXJUUW9QytxIAnMQmTyOeLbTuh7J5BUSs=; b=ooYEe9QfTVwYiKKXOS8kn+tbE76yaIwCwhAguKAvM4G58KPG71+W3SmJqcVbF0UGEt DjPa9bx7rUea/w0Vur1WFOQJjmnELxYEj2oeIHkY2Sbvt3Q0i6OLYngePzBA04Y+uAMg +9aBLgbs58isFotmNzP/HtRSpUdjF4/IesKWgKYtQu/Yt29CyErSthHCOL2NxWYVY8Wo YSHptZ60vNxtNYwV8heYDvKuvbfwcuP5jMAWPjh4asBozCRUHrvgNy4G9bnjuEktlEHE Y+1MZSJpEqAUYI116pNTX8Qc3zfPFbDN5UZiU/0j0jpJlFG17QBW5pB64ErD8knBOBTC AEgw== X-Forwarded-Encrypted: i=1; AJvYcCV76uTJ1mOt5Ks9kkMjrfAh67r1HLJZWkwH5k2nm1XlTNN7MtNcpFcJQbnmG1L4akyUyDsYaC/Og5G8SyIGowaj@vger.kernel.org, AJvYcCXsbvBi3/RWgg8tTFoVLPu1zUx93lt5W7YwsIPIBwj+46Gr/Y/KgMZkQDYdBh2NGa2kGT+GssZNIvzhinE=@vger.kernel.org X-Gm-Message-State: AOJu0YwGtuvdaoyAYjmY23T64CbDIRxgV0hbXYP7Ham6UF2H/58SNnVg cY4TwVDkqknCW9pN3u2l6m/+BP8pCEVU3EmwjZn3K3FhdrELbYgx7FWY69WJqA== X-Gm-Gg: ASbGnctiTEealxOcoZnuuHVWaxKdcqADRKMqPL6v5+5aauCxR71++av5StjhMhN4ZCE ASvGsBxniNMvHuovnPavGphwfAMNvuIBpGTPL/IGH3YKcm9AnY33wYa93up9QrEcacXKelJ/517 1zpunBd2WKsfir1231GesxADiK1XqYkNDuGFPrURyXhYf6WJDhU7j97dquolvfzpiCoKxsk4f34 ka179QvrZmBXyzTjn92J/QsnRxfHLn1UCD7k9AWQw9UJnouS054DnBt66JdNUFqpFWoBqpNqzVd tUWjgFLg/up4FpCqlyAe98bRiZigFwMvW2+Ji39xRgR4nqgqMSuzKA== X-Google-Smtp-Source: AGHT+IGi1P4JMcBZ7a2p0fE6Ncl0MFuNfZT+kiv+/pAZHdjnD5GYj+VXot80czFpuCROV0SK54qFuA== X-Received: by 2002:a05:6402:35d4:b0:601:f4ff:c637 with SMTP id 4fb4d7f45d1cf-60e52d19fadmr1790007a12.16.1751450807064; Wed, 02 Jul 2025 03:06:47 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:72::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60c8319f4dfsm8995534a12.41.2025.07.02.03.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:46 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:34 -0700 Subject: [PATCH net-next v2 2/7] netpoll: factor out UDP checksum calculation into helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-2-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2594; i=leitao@debian.org; h=from:subject:message-id; bh=z6ZyZPgKMyV5y5bQXJoqji7LE1KbrdDAaxyolHnuv6Y=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyv+Em8ezt6xanupTxc1wOZ+/b7ZvjABkP5 5VOnXqPAHqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bQAUEACde+aTQWX8+OkzokaT1Rs/ZTZQ60U9Atr7ytHd5cFEBwjtWo9P/74udnSJJjaKGOSerPE +A7l8AM4X0JthHw5izk/crzdlLq2oe44ZP1Ce5ZkhWy3trigOQ4qXF2rlQY3XS1Lj5f8TiKxunk w23OdF1RBHD+qoCah2QVm/XJ7XpqiG8o0TKNO6cgRwS7nst1BmrTCzaZcBqx8+pPlI2AwW3BsIB 9I6k71qjjmIpCnLEr+WiV5U5sZARP/JCmvYJRGv7GilyTcOq9HL+kHObtVJggCOGRLi4jAiR1O3 IZ34NVQwJlXnXfp9im+bNV5E33gYGo0fQe6GCt3TZ/60Owr2oTEEPwShPufNwkJ7bKyYpeYmJmJ pgYxElLQOx4NgC0U1YIuKx/v9Azp6Pp4MImfL1Sh6X+yanhMKOoLp9RhnP9+NHhJlz4lQffgdwu TSbPurYveeP5gl3Qb6b6yF8WC7isv7KtzleEypZdHZNUt6DOp2BI2bEHUoA5PcfdB9dO9Jlc/RV gxaj3VDuXhTr8oe+wz4kgG1G0jgAbRgHV22lHdtQGLVtfM6e6TmpeNPvj8yQN0ITsdgvhIbSrRm L+8x+qCHk7PSnzvJZ2IZF9nVY3O2jUJkD8hmIxvriYh5B5hgCpk30z86vzjeR0Bhqmfl6xEn5UB V9JWLwzaF2fwkjg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Extract UDP checksum calculation logic from netpoll_send_udp() into a new static helper function netpoll_udp_checksum(). This reduces code duplication and improves readability for both IPv4 and IPv6 cases. No functional change intended. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index ac0ae9630654a..24e6ad2da8096 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -372,6 +372,31 @@ static netdev_tx_t __netpoll_send_skb(struct netpoll *= np, struct sk_buff *skb) return ret; } =20 +static void netpoll_udp_checksum(struct netpoll *np, struct sk_buff *skb, + int len) +{ + struct udphdr *udph; + int udp_len; + + udp_len =3D len + sizeof(struct udphdr); + udph =3D udp_hdr(skb); + + /* check needs to be set, since it will be consumed in csum_partial */ + udph->check =3D 0; + if (np->ipv6) + udph->check =3D csum_ipv6_magic(&np->local_ip.in6, + &np->remote_ip.in6, + udp_len, IPPROTO_UDP, + csum_partial(udph, udp_len, 0)); + else + udph->check =3D csum_tcpudp_magic(np->local_ip.ip, + np->remote_ip.ip, + udp_len, IPPROTO_UDP, + csum_partial(udph, udp_len, 0)); + if (udph->check =3D=3D 0) + udph->check =3D CSUM_MANGLED_0; +} + netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) { unsigned long flags; @@ -425,15 +450,8 @@ int netpoll_send_udp(struct netpoll *np, const char *m= sg, int len) udph->dest =3D htons(np->remote_port); udph->len =3D htons(udp_len); =20 - udph->check =3D 0; + netpoll_udp_checksum(np, skb, len); if (np->ipv6) { - udph->check =3D csum_ipv6_magic(&np->local_ip.in6, - &np->remote_ip.in6, - udp_len, IPPROTO_UDP, - csum_partial(udph, udp_len, 0)); - if (udph->check =3D=3D 0) - udph->check =3D CSUM_MANGLED_0; - skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); ip6h =3D ipv6_hdr(skb); @@ -454,13 +472,6 @@ int netpoll_send_udp(struct netpoll *np, const char *m= sg, int len) skb_reset_mac_header(skb); skb->protocol =3D eth->h_proto =3D htons(ETH_P_IPV6); } else { - udph->check =3D csum_tcpudp_magic(np->local_ip.ip, - np->remote_ip.ip, - udp_len, IPPROTO_UDP, - csum_partial(udph, udp_len, 0)); - if (udph->check =3D=3D 0) - udph->check =3D CSUM_MANGLED_0; - skb_push(skb, sizeof(struct iphdr)); skb_reset_network_header(skb); iph =3D ip_hdr(skb); --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 9F378254B18; Wed, 2 Jul 2025 10:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450812; cv=none; b=p7qPUoMsnZiAl7GzhhLw+OJHCTVfHr9tsZAaDyh6qdn2vLeMdSP4TzVJX/pFNLa97EJbj2f7MGFkpduaeFjbpuWp1SsgMZtNN4ugqIga17mtI3pgkTiyibJ2q+3lcu7g5FxpVi9iZib7XsrCE/fpd9n6+sRKdqYPCVMUeAjKNys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450812; c=relaxed/simple; bh=S45p4GYDOIgPeogkQywbhpuBDiWH/N8B6jk1HuoCwrY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QEA9Y+ILB1LTZminMBj4t7rMH6Ft4tKINwJc+GRVxxCzS+Rj0jH0G/9Nmr4NKbBbF0T/G7KNnchfnDXVEy6+NTADl/kDbDUo0VMUYrJB9LpWcTY3QMPWr4aLt2vfqMz/pFzpnhLirs6kppOjsnJLjVGnV+303EL8znOSLH2X0l8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ae360b6249fso855317866b.1; Wed, 02 Jul 2025 03:06:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450809; x=1752055609; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qNF6KD9tDOu5iPqaXILqcxFXrB8p2Oad18HGGU/SHQ0=; b=XwHWm7y3OZHpzQIpK0POGFobiKaeBkCBtO4sVH3jT7e5bTmUSy6/cAH+l6F7IJtyU/ BEG6lWH7HNk+W0nuFehmLNlT1AYPiwbD3nkk1lvpbtfPvbJzeaHwXpY8MFYCxyewE2i4 2EbX8GAHBfD+WigY0yaxilsLTFnX70mxuahlw8GYt6FZRZXldWdpUXeuXNdk7uhHRxM6 09NSB7+Ee/DwMYAvD1KcnNGl7BE1/IXvgbZO/JdxzCycxhawrnazDxHLA7vf8hDa/bj3 HHTfIMMm9XZD43smj0FKgtjDmXi6qxw53ejEpSeJcciW47i550br8ZknyUQDn3X1X5VY S6sQ== X-Forwarded-Encrypted: i=1; AJvYcCVqh0ncG1GEfv47bnx5zO3lPeNqoA8HkvLRlsuHPeE2gLPsxsbdosIMaWFGavui6DcooTLs75jzy/hv3hQ=@vger.kernel.org, AJvYcCWGQSLMjtvmk/DbOlnDf4n2yf65at5Tb+LY02/jgvcn8rTVk0E3bN2OSnVe2Nmx6nJcevXYTdJlT/nqlgkvpXfC@vger.kernel.org X-Gm-Message-State: AOJu0Yyq+8v0L2bJuZQ16ihI/RRbbpjb1ByBGMnwrxjNzXu1MMD314NM o7ZEal0+gx2ZqX6gebMAXNeArxQQApHSQo5iY2HvOKnPX0Q9wbY8ZoZ6 X-Gm-Gg: ASbGnct0cp0zM3+qaOubUwjBFH4tYLYkYoC6CoZg1pVP83TSgxjmIawGz8eRbT9GHEJ bfQ3wqMXHSo1dBVxTPN9s35xvPCubNFWocVync/vjpsfJ122MuyR7FGasYjGcWt1ScSmQ4oK7Uw 1nk/qWzQEbbBtmns2zVnTrgLRRUN81rwK+35ZlKkFtE/AOP6oc0gllV6iDxpVvp5FEeVo9OJGXX XPwXq8QRRSJN3cRNQJi73esezmFk+S3FGwPpRQLsoSUIEYNz7HZ0mid7HCZtnbOh2QNI8j+M0up 0CYxHvvSeVEwmuMDCCJiFcHIAFBVQbgLpbkxMhcCmww2Gj8decL6pg== X-Google-Smtp-Source: AGHT+IEJrK5XzqrzJ4clbVrArMK+eIMUJ7/XFvME5fCNNH1oypj1tCzwunYcNTOceK/+ETZIusPKqw== X-Received: by 2002:a17:907:7f86:b0:ae0:c539:b89a with SMTP id a640c23a62f3a-ae3c2b5c41bmr216849866b.19.1751450808755; Wed, 02 Jul 2025 03:06:48 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60e26b7ac4esm3292426a12.7.2025.07.02.03.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:48 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:35 -0700 Subject: [PATCH net-next v2 3/7] netpoll: factor out IPv6 header setup into push_ipv6() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-3-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2665; i=leitao@debian.org; h=from:subject:message-id; bh=S45p4GYDOIgPeogkQywbhpuBDiWH/N8B6jk1HuoCwrY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyU+E0jTrWiXIiy637YsXp55CdyqkPSMv3X cJ873Q8tY6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bZxqD/9zqGFE16TouDilN3ybC7ba9L7l22PP57M8SHRqTuQuHLPzseuA23/dgCjxRl7X4qWLlOA vi7E04J6DOLHIjbL0y1a1HDuImEQaRG/RLWtO1lCDk7jWYGQ2EfChUpMm7IqpqwZfg5VXytukEo +ERNHe3DeEMOlf7Omd39HBhXXVHfbeGIaWzHH3JQETBlL9Z6OD615SYiqCHGphIG+tR3DKp2tgt UuAJILxdZ9x5uAzlK+SRrxekflPeDfzitgyByALRANMZX8/wY6DiIAW6uSq4VB+BMwHHYkmG/wK xG4NxjBIVYLVWPYAkeT3e84rR76L5hxOpPaxYxeRnswqUYJUWXlz8OG9cyIMDWlQhd4LN/k5Xhh CCfhNV/p/vR62TzV6U3dBPy6N0VgFG8FMztX4+xZrpnsh5TfwNmnUGyuC+APfkahtTEs2HBkEgj Fb+Rpv/Srt9IVFBGGEBu4Lwlp2irFy+3s/MshHCd3oiF/d0EoV+uivmqqm3zInlJC8yOUzeWuJg F4twpemzhW5EFX6u3ag/UGE70Z9fczcMt0EtN7FkCOInUuTXfLwIL2yYMb4/wlLhbKP5HH366P4 k4FJsPpfTHLTsicYC1ybwrQl2raR1NWaQ4tsU4X9WqmzJpgVA3oEE5eaGUFbv9fUfCK4arIbT1a T0g5wfTCQBh2kgg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Move IPv6 header construction from netpoll_send_udp() into a new static helper function, push_ipv6(). This refactoring reduces code duplication and improves readability in netpoll_send_udp(). Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 24e6ad2da8096..247a73762fc2c 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -414,6 +414,33 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struc= t sk_buff *skb) } EXPORT_SYMBOL(netpoll_send_skb); =20 +static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len) +{ + struct ipv6hdr *ip6h; + struct ethhdr *eth; + + skb_push(skb, sizeof(struct ipv6hdr)); + skb_reset_network_header(skb); + ip6h =3D ipv6_hdr(skb); + + /* ip6h->version =3D 6; ip6h->priority =3D 0; */ + *(unsigned char *)ip6h =3D 0x60; + ip6h->flow_lbl[0] =3D 0; + ip6h->flow_lbl[1] =3D 0; + ip6h->flow_lbl[2] =3D 0; + + ip6h->payload_len =3D htons(sizeof(struct udphdr) + len); + ip6h->nexthdr =3D IPPROTO_UDP; + ip6h->hop_limit =3D 32; + ip6h->saddr =3D np->local_ip.in6; + ip6h->daddr =3D np->remote_ip.in6; + + eth =3D skb_push(skb, ETH_HLEN); + skb_reset_mac_header(skb); + skb->protocol =3D htons(ETH_P_IPV6); + eth->h_proto =3D htons(ETH_P_IPV6); +} + int netpoll_send_udp(struct netpoll *np, const char *msg, int len) { int total_len, ip_len, udp_len; @@ -422,7 +449,6 @@ int netpoll_send_udp(struct netpoll *np, const char *ms= g, int len) struct iphdr *iph; struct ethhdr *eth; static atomic_t ip_ident; - struct ipv6hdr *ip6h; =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) WARN_ON_ONCE(!irqs_disabled()); @@ -452,25 +478,8 @@ int netpoll_send_udp(struct netpoll *np, const char *m= sg, int len) =20 netpoll_udp_checksum(np, skb, len); if (np->ipv6) { - skb_push(skb, sizeof(struct ipv6hdr)); - skb_reset_network_header(skb); - ip6h =3D ipv6_hdr(skb); - - /* ip6h->version =3D 6; ip6h->priority =3D 0; */ - *(unsigned char *)ip6h =3D 0x60; - ip6h->flow_lbl[0] =3D 0; - ip6h->flow_lbl[1] =3D 0; - ip6h->flow_lbl[2] =3D 0; - - ip6h->payload_len =3D htons(sizeof(struct udphdr) + len); - ip6h->nexthdr =3D IPPROTO_UDP; - ip6h->hop_limit =3D 32; - ip6h->saddr =3D np->local_ip.in6; - ip6h->daddr =3D np->remote_ip.in6; - - eth =3D skb_push(skb, ETH_HLEN); - skb_reset_mac_header(skb); - skb->protocol =3D eth->h_proto =3D htons(ETH_P_IPV6); + push_ipv6(np, skb, len); + eth =3D eth_hdr(skb); } else { skb_push(skb, sizeof(struct iphdr)); skb_reset_network_header(skb); --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 D8FB1253B67; Wed, 2 Jul 2025 10:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450813; cv=none; b=FcETcaztHdul+8mwoTF+sjSxlhTC5Nm97jfjL2yFSsK4Avs3rTrAU9FTuid66SmPRusUlcG4FRgeFdH7ZOR1DM2RKZZ1xrZjojPQEWx0cbX4V/xsbyJRVs8P1pwoTsIvzGPHOrHFK99lLaL9KhhtkbvXnSfob6o7bRRPCnjGJto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450813; c=relaxed/simple; bh=pcZpkL8/Vo5GDdA9GSNr5ZwCPZLTyJlooFlI1HTfP/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dDh6sHiA5CxyjuiMgPLeySBF0W4Jc7R/toIHCeeLZhmgOqMMjqOFgF9Q//M46oZGT05sKHP9cxfeCxufflewni+uLbR/0iHQEHvzduKIYmsH9Ur4JOVZQ1lAJ9SN9cjX6sEBNyfdUm60KuTSFBdZa8aRGBB5Urk03yOUTu48t40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ade5a0442dfso1263295766b.1; Wed, 02 Jul 2025 03:06:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450810; x=1752055610; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ClXLLoPFou/Zs3D5ISq3qOrdQw3SSzyGRonA8OwAUwc=; b=J34wp9yFUiBui2jdeUYKG3a6sGKMmqOkarsbbv78Yhleolv6sAuanyF4ZVs8yBIoua P0q8EWVLW3VxouwHk6in6WvL9pjjzE/0YnROLd/cVbLqRlUx6OBCFv8gSG9qDwSdikMC wnivlWdzgd/dVXU3M5PeHOpocbpiEdQxWpoe18nwk07/Wyau2tz7gjScPFLbdifLWp2t ZGojOAKVlSesb9zqCl/d4MqFZuUXuwBbimlVuLofF5KauGwLismAUdjTSA9OeJ7CYret sLpJEX36f3YpdUtLAjwFiJoTiJa1iwctEwBTldKfYu9mhKygiIGbMGbP8tEMt0NnGLyX bBNA== X-Forwarded-Encrypted: i=1; AJvYcCWYJ27FrcNH2q6gbxcvCE1owDz7qyguexlRzxIiHMiNgzpAkH5ORx18scaBzKdf//geOlt6X2ik6PgKXwdZiScP@vger.kernel.org, AJvYcCWrNQRsd2Q+a0iWK2zRrN25oU7T8xY5p/60BO9Ji+V3tVSDbbxhBfLAOWfKRkscztrfdfR0Oq4YWQff/po=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7pM7Nah6T9/s4f3OiquvfGHrQJC+0siNTKLbyo1hD9IL44k83 dyKj3B3a2oVWZEA4Odv4HFe98KLsvZqOXIn1NJ6SjqlVKS9iu7siuy/4 X-Gm-Gg: ASbGncvLzzbII1lmAViagiMcb8cRokWPWpfuQqa4enMXT/+Q4nkJqdsRFmmjf9K+Xx7 8TNd/CXg3+7KfAcTc4sO9vFH/Ab/RPQF8q/eVaXqTjQvP3UoJCF2Dbgr8BPK8bw7dbx2ARkcV2Y /WtxSoXZig9tq483R87QmjLye5RNzM1G2L0/Oz16wVIb+cZJdYJBJZhdf9Im29JPgKQHQSerKJy lPKdZQNr88aevHOQ6w1/EnwyFnTHwCXGD4XRGzV7B6HcCFqWEv6moW3c+7ZGam5VCg98kf6FTEq 1RH/yM0Jc4cvpZUlAR7Rs5hGtIV0bBTVY6hHUJK/Crbt0W942g== X-Google-Smtp-Source: AGHT+IEBHeDW/qHjY84o72AomKdwJUaEgc1blIazAL28t7JSVyH+PhHW6nJKpfvZZGaHrIhK7QDc+Q== X-Received: by 2002:a17:907:1ca3:b0:ae3:6d27:5246 with SMTP id a640c23a62f3a-ae3c2ce1f13mr207594066b.48.1751450810136; Wed, 02 Jul 2025 03:06:50 -0700 (PDT) Received: from localhost ([2a03:2880:30ff::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae353ca2159sm1071326566b.178.2025.07.02.03.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:49 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:36 -0700 Subject: [PATCH net-next v2 4/7] netpoll: factor out IPv4 header setup into push_ipv4() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-4-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=3390; i=leitao@debian.org; h=from:subject:message-id; bh=pcZpkL8/Vo5GDdA9GSNr5ZwCPZLTyJlooFlI1HTfP/A=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyh21HG91R+k7nQBnrk2vFjlUpfedC6xjcG nrf2hLy48CJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bZRQEACOow4bSHX75KePeP2Jk+s0+FyI484nTmb0m7teSV9sbr99NwIv9EEJMFKaPqBHdkCcl95 hsgcGwp7+TcHOLsgJSkNgxxrlnAqCwmFubfl6/8KOyRpNPL2RstfvTX7i/0VP6BYzcygDnN5ZY7 znC2/LK9CLfvsSHf52Im4iNrGW2ZRWDRFTyP5SKJlzNzYJUtu9keOQmxCZi/496Q2XD+M4ZOuAL VBzKBpK4s24AbDcA859TTNUjdqiO7/+pQqgvPAXD6B9y23AyKsl6wEEynNb0okLoAaOHTVyRRIy TzhMAyug3Xk7eCxKchcaD7yLozlqDTs4iyEpnloUmBK8W7w6JmVqt6sicZBP6D3He1FbNcsBMCO rNhS9uyPHiOwrBDTqsIMPLRRUnINn4FapyBLzBc9tvHtKElbMlD6cfH0qDXcQP6lghbi9Rls1YS UXlFwdaXvBc4k0RUbrIb4j6QcHioweFfP1LHhDsiLS494xhzAjf5PWyGpz2qNt9Of548ZOtrA5O XQIHzfom8pzERJbpPAyxPcA5KouGQmSJLVwF4X9aQjlgddJ71HcuZQIqW2S2nD77D7ftYAvUAy8 BKdglFEjFuId5oTlNrDOMOAKO6dCcacC429Np2wFXG+S6i3ssXUJDwX6g6JB9Gb4IUMWqQb+BfB P9YAeebJp1wWVpg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Move IPv4 header construction from netpoll_send_udp() into a new static helper function push_ipv4(). This completes the refactoring started with IPv6 header handling, creating symmetric helper functions for both IP versions. Changes include: 1. Extracting IPv4 header setup logic into push_ipv4() 2. Replacing inline IPv4 code with helper call 3. Moving eth assignment after helper calls for consistency The refactoring reduces code duplication and improves maintainability by isolating IP version-specific logic. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 62 +++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 247a73762fc2c..ff64e94df5351 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -441,14 +441,44 @@ static void push_ipv6(struct netpoll *np, struct sk_b= uff *skb, int len) eth->h_proto =3D htons(ETH_P_IPV6); } =20 +static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len) +{ + static atomic_t ip_ident; + struct ethhdr *eth; + struct iphdr *iph; + int ip_len; + + ip_len =3D len + sizeof(struct udphdr) + sizeof(struct iphdr); + + skb_push(skb, sizeof(struct iphdr)); + skb_reset_network_header(skb); + iph =3D ip_hdr(skb); + + /* iph->version =3D 4; iph->ihl =3D 5; */ + *(unsigned char *)iph =3D 0x45; + iph->tos =3D 0; + put_unaligned(htons(ip_len), &iph->tot_len); + iph->id =3D htons(atomic_inc_return(&ip_ident)); + iph->frag_off =3D 0; + iph->ttl =3D 64; + iph->protocol =3D IPPROTO_UDP; + iph->check =3D 0; + put_unaligned(np->local_ip.ip, &iph->saddr); + put_unaligned(np->remote_ip.ip, &iph->daddr); + iph->check =3D ip_fast_csum((unsigned char *)iph, iph->ihl); + + eth =3D skb_push(skb, ETH_HLEN); + skb_reset_mac_header(skb); + skb->protocol =3D htons(ETH_P_IP); + eth->h_proto =3D htons(ETH_P_IP); +} + int netpoll_send_udp(struct netpoll *np, const char *msg, int len) { int total_len, ip_len, udp_len; struct sk_buff *skb; struct udphdr *udph; - struct iphdr *iph; struct ethhdr *eth; - static atomic_t ip_ident; =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) WARN_ON_ONCE(!irqs_disabled()); @@ -477,32 +507,12 @@ int netpoll_send_udp(struct netpoll *np, const char *= msg, int len) udph->len =3D htons(udp_len); =20 netpoll_udp_checksum(np, skb, len); - if (np->ipv6) { + if (np->ipv6) push_ipv6(np, skb, len); - eth =3D eth_hdr(skb); - } else { - skb_push(skb, sizeof(struct iphdr)); - skb_reset_network_header(skb); - iph =3D ip_hdr(skb); - - /* iph->version =3D 4; iph->ihl =3D 5; */ - *(unsigned char *)iph =3D 0x45; - iph->tos =3D 0; - put_unaligned(htons(ip_len), &(iph->tot_len)); - iph->id =3D htons(atomic_inc_return(&ip_ident)); - iph->frag_off =3D 0; - iph->ttl =3D 64; - iph->protocol =3D IPPROTO_UDP; - iph->check =3D 0; - put_unaligned(np->local_ip.ip, &(iph->saddr)); - put_unaligned(np->remote_ip.ip, &(iph->daddr)); - iph->check =3D ip_fast_csum((unsigned char *)iph, iph->ihl); - - eth =3D skb_push(skb, ETH_HLEN); - skb_reset_mac_header(skb); - skb->protocol =3D eth->h_proto =3D htons(ETH_P_IP); - } + else + push_ipv4(np, skb, len); =20 + eth =3D eth_hdr(skb); ether_addr_copy(eth->h_source, np->dev->dev_addr); ether_addr_copy(eth->h_dest, np->remote_mac); =20 --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 90B6F25B2E7; Wed, 2 Jul 2025 10:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450815; cv=none; b=qkNS2eWOBKSFveZ6gm6cgBYY6J6iL8w8bGFPBXTFRKqMhNqYhgXZfHwqKZx72FNl3Nd0kMbshGTudLBx3k5RG76M94gZftu6dOA+AnTjudaP6WtMMH/9+wv/yi/rx2EY2L4dVEJ7SfI/l1eIWRHUtIChFZhojwDaJIldHBVlUwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450815; c=relaxed/simple; bh=oMOUjvb17dkMjNgn7pjR5NW3PcafE7gyNJxjq175LMk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MSBryDN7tke4PlSJU+NRDhuK3l2CEFpbKMCG7R+BdRl43CmZYdyHzMri8DXpsx62C/+aLb/YfJpnWTuzSfuT/ZMG0IwFRIT80pPdM1orPtRLpj1VrkOJcA03flP/YhN+g9LSB4PVYQLIBzpYnmr/7Wd7xC9cyQl8gmn9luM+CTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-60c5b8ee2d9so14336578a12.2; Wed, 02 Jul 2025 03:06:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450812; x=1752055612; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYDZVXt1K3tFXA7SAWfw+XZ1JpA27F2JTM3+wG8ec70=; b=a1u+cGG0AFhFzVmAWPs1Bt0cMG9q0hcmHlJjYDzdi+uKXk9l0SATKAlpk4A8W0lnmu RQCJNY3UZLuYvZ1JTQ2syCF66wFWB+3AIeZqsZFJt6sae0ABiofEP6w73urKGipw2aMH hpImXTO1tq8Lswfcm/vq1FgsV42+fKMptOlqJqSkqtJnxJ0doSLYGbmfWIko+Qanzvur lFrhy+x7KCZZrmwIiWgua/SoOthuPZI7lFK2FSEAHY6f0Pq4jvbSiv9uA6q8z5QGcCyF 2syuyZPtvCO39qfLBSlyDnM30GHf87/67xLLYmZ/wD0U8totTAvdXcQetyyqjwwqkzvZ HA0A== X-Forwarded-Encrypted: i=1; AJvYcCU++h0ZgNByAKJNlQJA/u7ti3u1rycoPRdgVGuUC564cAhGWyhO6wPDEGxmyDLV2K53rwbUZ3m49DCTJ+k=@vger.kernel.org, AJvYcCUlQcdgmTFr7hHLWIFM3EjYe6l6zbLT4YBPfeQgJCoIOVUT8QY4y2Psi40IoN3hwsSSKx0qUQ4TWJ6G/PsNgtBT@vger.kernel.org X-Gm-Message-State: AOJu0YwNxSOxKeO3QBkXGAhAmtjlio7hMSQY/7sGRo4wx6N9ZlNLCTsC SqFmBufMTnhMbNQSsLWVkTG3yXQW9JSV5LMM618c0Dm1nywntIbWvgrz X-Gm-Gg: ASbGnctopeNXAMSVX1DExjNA82arCSNU6y9OK6Ab3PWIXML4OUiFmlkIVnsBnW/fHlL 8Fg8KHjlmJ32ve6Un3x+yxHBiGu8qWmkqabBN6T3AuE8cxJc1xeIY8MU9ywqWFfsgwhYbj4kf+e HybhZsXp7gJgcCgOzmOWAF6GQULfLDQVHpGtIi+MG1kz232iejA59h/T/EFnipNNVDiAqqXnsgl bRjnkatWb2GrPGkiKtMnFI8zlkkgm/CWhP2MKm0i2nER+WK/eBUCVIWK6AaveRtAJZKsCLTBAHW fLfqORTo8XoGReE1n3GSWEXbnpl2hG5ENfZL1oUmeAMcO81qU3orZw== X-Google-Smtp-Source: AGHT+IGLvkSbIcm/mfbJ+4gubk6cb7/AvlNNnXZdZh//1fmXsRceD9x5Iy3vrthD/0W6F9pTA5bL/g== X-Received: by 2002:a05:6402:3198:b0:60e:4157:5922 with SMTP id 4fb4d7f45d1cf-60e536028ddmr1504392a12.34.1751450811572; Wed, 02 Jul 2025 03:06:51 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60c8319f4d0sm9175363a12.44.2025.07.02.03.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:51 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:37 -0700 Subject: [PATCH net-next v2 5/7] netpoll: factor out UDP header setup into push_udp() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-5-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2123; i=leitao@debian.org; h=from:subject:message-id; bh=oMOUjvb17dkMjNgn7pjR5NW3PcafE7gyNJxjq175LMk=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyYSEZGBhGA9/pFF1KG/lEfJzCVnTqsDI4x a62WnrCzAyJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bctqEACauk9TlH2dLQLApUx/pP00mMdAFEBKrE04SIdamFcjXZdXfviDgj9c0lCLAe0f0Dj0khu H5RvCuAUwJGwdpO6F/OxQGa13yHaqakxnJDL+JXBA6oZLdMFUbLyMN0EVSPeMNWYFhmvW1s0o7o DWNji5DtDYzEEWHNkaNh5Nc6dC4Mb9LvIpyVQn6KxrLRkIzIhIP72RN2zNQrbi+FS70tem+ANoR /S9pTM259ynF3BK2VonIqm3q5nB35NYHq9XGFXDjsJeqHRWbH8yMdmISUTBOkhLQz3PebmCWVlF Dwl4XPPs9eJhTrwwIpNhYmmj1y4d67uZkCoGbAywvkmCmT9TVZUSFqshlx7ZgAg8pRKiYrz1sss UFQhtpDuJESyD2c1rlyF0m2zPX9Ak8/ghIx5Dwf2ssKWS2gQ/Da1FzbsLYBcJMcHKMcgajkTaxx RwQzJoHkgWhdxLT4KHgwyRrqxMYrgQ1XZ4SmPQxcVtbINFK1KEWqKm/7oU2vnNbRM9GgIUeqdUo 0nGgApAz4CmqfA9bFPJpDX1JDDB0ao9Uxe3tcaZPbsSWn6tAxqy1eGzRJNjjp2E3rZDleq7Lj25 PrmJ2KiE0+R+tKIGzHD2bnAmMzux6abJC0hTRe3/32Y3LeXDPi0ktqybxxr2HuEU1/ySiJDIX4C 2bs84ycp4YIU+wg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Move UDP header construction from netpoll_send_udp() into a new static helper function push_udp(). This completes the protocol layer refactoring by: 1. Creating a dedicated helper for UDP header assembly 2. Removing UDP-specific logic from the main send function 3. Establishing a consistent pattern with existing IPv4/IPv6 helpers: - push_udp() - push_ipv4() - push_ipv6() The change improves code organization and maintains the encapsulation pattern established in previous refactorings. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index ff64e94df5351..70035e27d91cc 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -473,11 +473,28 @@ static void push_ipv4(struct netpoll *np, struct sk_b= uff *skb, int len) eth->h_proto =3D htons(ETH_P_IP); } =20 +static void push_udp(struct netpoll *np, struct sk_buff *skb, int len) +{ + struct udphdr *udph; + int udp_len; + + udp_len =3D len + sizeof(struct udphdr); + + skb_push(skb, sizeof(struct udphdr)); + skb_reset_transport_header(skb); + + udph =3D udp_hdr(skb); + udph->source =3D htons(np->local_port); + udph->dest =3D htons(np->remote_port); + udph->len =3D htons(udp_len); + + netpoll_udp_checksum(np, skb, len); +} + int netpoll_send_udp(struct netpoll *np, const char *msg, int len) { int total_len, ip_len, udp_len; struct sk_buff *skb; - struct udphdr *udph; struct ethhdr *eth; =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) @@ -499,14 +516,7 @@ int netpoll_send_udp(struct netpoll *np, const char *m= sg, int len) skb_copy_to_linear_data(skb, msg, len); skb_put(skb, len); =20 - skb_push(skb, sizeof(struct udphdr)); - skb_reset_transport_header(skb); - udph =3D udp_hdr(skb); - udph->source =3D htons(np->local_port); - udph->dest =3D htons(np->remote_port); - udph->len =3D htons(udp_len); - - netpoll_udp_checksum(np, skb, len); + push_udp(np, skb, len); if (np->ipv6) push_ipv6(np, skb, len); else --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 11FE725DB0D; Wed, 2 Jul 2025 10:06:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450816; cv=none; b=NVXxicR11dbZoe5e4e3JoBmyMKO3w/f92zkoFZKQfp3m/Vy/v0DtaXcw5qhw82XYY00TIinMIMTNIBxBDvV4CUKulDYJXL5rtKElezNZjG/t88bcFXyg+hkyzX2T/3PvWfXPNjme88PDPA9R9jvvH/T8vxv/ciCHJaOCq/91Uw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450816; c=relaxed/simple; bh=BWXMBrzktLJVPVW0gEBEfBlMgYZkbD9tXz+iG00Ovik=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YIorDTJZG1AYjVnPn+KfgbU7PyoL1t6xAhafUVnrm4/u5RbX/oLlbW1o0DyguULwqM+eUNx9hxqR2ZWt93Xolo0UoEb/e3ARqoMSCI1a+UN9xTt2TlIqM2ihsF7KTFhFAvGcbdkYeCLn5I/1zZYU+aC8zzvjczk3qPOiBXGEo9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-60bf5a08729so8737726a12.0; Wed, 02 Jul 2025 03:06:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450813; x=1752055613; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bh7hV7ctYhjTTncRGyylmO0Rhxv+CmqALT9eq61GbDc=; b=SCyxasgoOeBZZU8QISm9EQP83wvXnOGngbVnWvtvboFmXCd2b2KS2M32BBT2AU+mrS p8p0UJvUSA96ych7ZnDJybAUTQiUDEp6HVrN+lLGoHe6J1pih6N9iWlVfxlhb6vudwlP jQRiV14rnGJoQgSL0e+Rsasi/H7uBMJ4I1j4qxowyXVoiJGOP/ajQD1ucL7weGHEA82i E6brOFeXY5trRJ+WIgSTUK1Wct1py229G9opKYdV8zf75YvyKehelzHMwuW9SUDwMA3y FCiP8uwpyVmSFhFCW5BKb0jEq82soXR/SStftyzbmUvMka8s6P1Hu1EDYwPDAFl2V6Se cuKA== X-Forwarded-Encrypted: i=1; AJvYcCVBODul753GkPRQxzKAzEuMk6Ddv4K6MnTQVk/naiILwD6gbvVU2AtZtqwKk8t2j8NF6r4hzcWL2BMHmnJvyga+@vger.kernel.org, AJvYcCWOZW3so8+n8cEloJkE2TJ5e0OeOWWwQVJktV8GjUMKoU2OR1xQQrU3jl/6aSYgVdb9rJHFjmEh2YGt/ss=@vger.kernel.org X-Gm-Message-State: AOJu0YzZK6Ct02E6cHHVrcy5TZtSRzjWv72WHdVSKngia5yQb7geWsCd P0V6y9VuSoCE+Pi7shHRWkx22aBvQgdPJORN8ACduMXfu0uev7ff8P64 X-Gm-Gg: ASbGncvK1kgnDR+YwZSzfdodF+KqDoCyImKBXKslydn5KG0cQZg33ri4gUNILAlVofx cqNonWUQQrl62lUqGAQzI5ZBF7eT7TYVQEKY0K2AklnyY3RO8KzruJ7HWZ8YGqv0HTe5vjTtXE3 ls0QqYwpo2wQXjJHnBiCbsRezbUlyZLQWNYpCtKTSKLk36B9PmaDA5QVUSHgpRYB4Nc9OwpsUoX uAlnW0QBD18nmAUOPM/41UqjyrBC5Sqxuyr84HTAqhLOs5EH78LNyagAsQ1Nyj/n2ss6pUwsgfJ mlSKSXcmW0R3/BeIObIVehlIOvmnE62mvDgKMbpPKbgqs0n8KqWJ2g== X-Google-Smtp-Source: AGHT+IFDOSH/fmcOYJ7xuZSfDeU/TGgSuwONn32IlSEXUtYp2uXLPWT364bDENeL0HYNFD3MaHcBJA== X-Received: by 2002:a50:9f08:0:b0:608:f493:871c with SMTP id 4fb4d7f45d1cf-60e52cd1564mr1471797a12.14.1751450812923; Wed, 02 Jul 2025 03:06:52 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60c828e3b49sm9050377a12.22.2025.07.02.03.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:52 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:38 -0700 Subject: [PATCH net-next v2 6/7] netpoll: move Ethernet setup to push_eth() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-6-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2865; i=leitao@debian.org; h=from:subject:message-id; bh=BWXMBrzktLJVPVW0gEBEfBlMgYZkbD9tXz+iG00Ovik=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyyq+B+OlGSkSZHokNTuleYo55kMw3rzKuV V0rb4PYQfKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 beYxEACvKiY3H0DVJa6SeQpEncR2LdDUT9M5erAZpoPo2hyo3KPwYeIoQeabKqU1JR9eBE+GgJ8 n3v8UTOfgzfJJKW4L3SwUUYQA0rVSXR9mQ06sDYrNYvAu/+z9zP5hAx/OBL3n17zuZ9Wv3Zaw0S 4/xTlWkXIdb5q9KD7sx7GASQqOninvM9ZB+86ThWv8aob2TLf3CJbEhEMDeGoshprTC9SKunnor X8OT1v3uzE+VIGdL54g6ahs8US3FZI7OJBiDbGM3fr7G3l57R4+nKrxX2D3i0RH2LSaSCxiTypF 87tOBD1+rSZZ+sDvAZUtDLjjGEyZ1qSg5mt9TKiQIs+Of8AYtFT5k6+//bhjWLEvJ7IPNKkKt/y kCbVrY75IY/3aknotaGba8DfXX865SouBEt6y7YFXX1Po85JVqxvPgEmEiMBbok9QgXPr/emLEs XNNOUR4kuFkOrzttuCuqxiFL0aYJUiqkfnQ8FrNzFX9hLovVsVFIZwLwElapzcuw/fl5Z2bHzeN AqiDYxmT38Trzslx8mfVI25frLlYaZqo9ORrqO0UaGxefuqqFw1tTd2UYPnN+r0BDRzQzvNd78g r4Am23L1w0e1vFmtsmVbxVAIKKEynhZV0oe6aXSRTqBCBY/eJxa23XlAOjQ9eiGp0iFRj/2tLRm IDwAwwepfAIH5/g== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Refactor Ethernet header population into dedicated function, completing the layered abstraction with: - push_eth() for link layer - push_udp() for transport - push_ipv4()/push_ipv6() for network Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 70035e27d91cc..a1da97b5b30b6 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -417,7 +417,6 @@ EXPORT_SYMBOL(netpoll_send_skb); static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len) { struct ipv6hdr *ip6h; - struct ethhdr *eth; =20 skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); @@ -435,16 +434,12 @@ static void push_ipv6(struct netpoll *np, struct sk_b= uff *skb, int len) ip6h->saddr =3D np->local_ip.in6; ip6h->daddr =3D np->remote_ip.in6; =20 - eth =3D skb_push(skb, ETH_HLEN); - skb_reset_mac_header(skb); skb->protocol =3D htons(ETH_P_IPV6); - eth->h_proto =3D htons(ETH_P_IPV6); } =20 static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len) { static atomic_t ip_ident; - struct ethhdr *eth; struct iphdr *iph; int ip_len; =20 @@ -466,11 +461,7 @@ static void push_ipv4(struct netpoll *np, struct sk_bu= ff *skb, int len) put_unaligned(np->local_ip.ip, &iph->saddr); put_unaligned(np->remote_ip.ip, &iph->daddr); iph->check =3D ip_fast_csum((unsigned char *)iph, iph->ihl); - - eth =3D skb_push(skb, ETH_HLEN); - skb_reset_mac_header(skb); skb->protocol =3D htons(ETH_P_IP); - eth->h_proto =3D htons(ETH_P_IP); } =20 static void push_udp(struct netpoll *np, struct sk_buff *skb, int len) @@ -491,11 +482,24 @@ static void push_udp(struct netpoll *np, struct sk_bu= ff *skb, int len) netpoll_udp_checksum(np, skb, len); } =20 +static void push_eth(struct netpoll *np, struct sk_buff *skb) +{ + struct ethhdr *eth; + + eth =3D skb_push(skb, ETH_HLEN); + skb_reset_mac_header(skb); + ether_addr_copy(eth->h_source, np->dev->dev_addr); + ether_addr_copy(eth->h_dest, np->remote_mac); + if (np->ipv6) + eth->h_proto =3D htons(ETH_P_IPV6); + else + eth->h_proto =3D htons(ETH_P_IP); +} + int netpoll_send_udp(struct netpoll *np, const char *msg, int len) { int total_len, ip_len, udp_len; struct sk_buff *skb; - struct ethhdr *eth; =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) WARN_ON_ONCE(!irqs_disabled()); @@ -521,11 +525,7 @@ int netpoll_send_udp(struct netpoll *np, const char *m= sg, int len) push_ipv6(np, skb, len); else push_ipv4(np, skb, len); - - eth =3D eth_hdr(skb); - ether_addr_copy(eth->h_source, np->dev->dev_addr); - ether_addr_copy(eth->h_dest, np->remote_mac); - + push_eth(np, skb); skb->dev =3D np->dev; =20 return (int)netpoll_send_skb(np, skb); --=20 2.47.1 From nobody Wed Oct 8 04:05:58 2025 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 882DB26056A; Wed, 2 Jul 2025 10:06:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450818; cv=none; b=Miu2RJCJtq3HITrZ55BCz+SZY71zAXOehLcqkKOr5ncLxdQ8BxDXWHmG5XR7LJjTuEm5LpU14L+XD3ZoW/BSz2axkKIKNelNFV6m0pXOGY5M3n2+JKiGZrSPWhaDDndiArkuSnLyW2qrdJkWQEDwi5/WpBLp5jrTFmp7gvNeOLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751450818; c=relaxed/simple; bh=IEN/3Z+UWhk5jMFCChvc7TP1+KKOS3v2GWdCHvOX+KY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L4qiHL4KFQaniLk88OjBoDTAf8lOoSAWwjGuLK14wEAwVA9D6OPpD3stEk/BtfMYM84MUF0jq4lHpI5TzvKth2MLfWCg7jIWFl9hA9eAcNkmv0Y5ALPB6sm6WgcH8Z7oqMXALdIGbiPxUi+J4EtxpCWmRtJiZNXXYuXl7TT3F8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-608acb0a27fso6826560a12.0; Wed, 02 Jul 2025 03:06:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751450815; x=1752055615; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CyQkKEuXt0zodu2bhGjSzRNR14sGEqYd0//T8QpmKWk=; b=Tytx//JIq5dRdn0MpvJMSryjaQxTUXktyRqaxV1sKErrhaN5TEiLRm+YPuDQgo6GOL a1DRPcxkSr8X6/MIbG8nyEO4UHWcLAc1HvOUwZe8X/4OBbhCoSGmr8TeRxxclJxGoJya kysMrqFHw0zWtiwwUfDaWAGiIK14rOUuWLaY9dKRrWn/OojqCJlNVyfhuCxsbVKbRq1m O3DBqj4wH9jHojjk4GCZdxaYWV14pIpS+rtmUv2ZJU1+51XZt8IxzPgAEH81yNUXz5eK FG4qsDHw4pr1nLRFz9K1KBTDMK0ea4hBCFt88jBeTbB0N/NOjdHIllrgI7466xtKginP qq9g== X-Forwarded-Encrypted: i=1; AJvYcCUztaZAw2v8C2RuDg5Hmkcv8M92Mf17cXOta4Z75ydyJ4VZUTBDOYAs0tsnlX5dxNxPndH1vslbRUye5OI=@vger.kernel.org, AJvYcCXk/GWbGesFLXWlwf4/NX5JFSdTjUo1laK86brJGImTbHAJCLuw2XRaz3Itl+q0kbCWmfN8175Xi5qbKiBK2dTK@vger.kernel.org X-Gm-Message-State: AOJu0Yw0AsxTsc5UjK19r+a2m4BrIsdsGwVtu71W/js6hO6abmHREypZ sxAcOvjNsTPLjZ55r0qGWuWl8Apv9mxNYRqyWLyFduPReEIZo65mKs5IuOdtpg== X-Gm-Gg: ASbGncualCushneBSbUSgsCO1HIXbIPgt/6EX4WdKiAAaYLEeeUos1QMrXx7voutnRV TB0CGHgPwlm7cC6IRCbmmwyS0Vq4NHX+YuUdhNKUURbKdnKeShv9+MxAxOc68ZksE7NidQS+qAR rjuAJAcG6Kez+s8XXJHLna5HRrJcF/qxsa+Yl97tcxypIJY27UflTUUmZ0+xYgmyMqOLf8rbiIq JNr2+xnYD5jaoNGtfcsSDIBhK5ljhkqZ9S9xtNhw9gFnFqzMlG4S5EGt/6HfNVyW0lLOs1koxW0 xyXM5vYubILM+ekvOZbEeC32XYB/dxQNd5lHp5BKp3kaWEe5CuDMV6KCOfDTv/c= X-Google-Smtp-Source: AGHT+IHVRuZTYecb/ojIzCm6KbwYGWvp3+E8ZT5TXJcKXjI5OfttPdRkBQnK64YkfkrY5Qm+GL0YsA== X-Received: by 2002:a17:906:5604:b0:ae0:dd95:1991 with SMTP id a640c23a62f3a-ae3c2c37f41mr188044066b.51.1751450814294; Wed, 02 Jul 2025 03:06:54 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:7::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363a167sm1036631366b.21.2025.07.02.03.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 03:06:53 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 03:06:39 -0700 Subject: [PATCH net-next v2 7/7] selftests: net: Add IPv6 support to netconsole basic tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_untagle_ip-v2-7-13cf3db24e2b@debian.org> References: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> In-Reply-To: <20250702-netpoll_untagle_ip-v2-0-13cf3db24e2b@debian.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=7464; i=leitao@debian.org; h=from:subject:message-id; bh=IEN/3Z+UWhk5jMFCChvc7TP1+KKOS3v2GWdCHvOX+KY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZQSyTcY3cKY0Nh/T8PKgBSSLHVphn1elq+VN6 HLMeoRIaYWJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUEsgAKCRA1o5Of/Hh3 bYaCD/9r8SJHY5sP1Ex54og5L6j1zx2NvmEDRT1z7LE7YbNO8oLSgoDiZC1qiSrh2Al5KVHZFCc bBdiEt0EU1f2Trv1AkxgSmtrzu4yoCVS96PrRZJoU8gpFta9j5Qx+qHEtkea11G/nOkSvflOM/c pjZI3F5RYJQe61WmUDwcW2OGWR8IrDY1hdADFlQab94A/Ngr3M0MyGMSQ7uvAKYWnLG1w692LUU hwSqIZbR+ZF7SYlJP0hyxcK6YbhF+jYJ6x7izwQKe3mHYaipvr2sYyxUwCtT5U3beUMCw1WSFRi hvAlU7xE0dcCIldMQh1rsJtDib7xTZly/s0E5GTsVnEe094c1bKzI7MH2D0s/c/e5Dq9ERQ5ysm zbZDcJxRzWrSp0qAMNpC8eSnE1YXngEY8DJBK2JkRVi4Pv4Fx0WxwucvHLokDRHwoRUUNmMyFEy 9pmPspm+KyzS9JbdutuDj92m0mPj/DZCOhi0JgbDHX+NYadRxrFGN5CSXdzeBnV+geC+8BfWZgY ZJyud33muL+PaCv0+msspl7OtX+OkZbAMqEcQRdyW/z6OiqHYvMUTNgl3tqmbQhNMMijZxeDmae YPE1tysAi1hILuhsVDZcKBzE5hfVb3GcoSGtAhPHqMbTs9DZA3vNWVrcDpvHV0POyRE3hYApZcq kn1DX2edtu6wb3Q== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Add IPv6 support to the netconsole basic functionality tests by: - Introducing separate IPv4 and IPv6 address variables (SRCIP4/SRCIP6, DSTIP4/DSTIP6) to replace the single SRCIP/DSTIP variables - Adding select_ipv4_or_ipv6() function to choose protocol version - Updating socat configuration to use UDP6-LISTEN for IPv6 tests - Adding wait_for_port() wrapper to handle protocol-specific port waiting - Expanding test matrix to run both basic and extended formats against both IPv4 and IPv6 protocols - Improving cleanup to kill any remaining socat processes - Adding sleep delays for better IPv6 packet handling reliability The test now validates netconsole functionality across both IP versions, improving test coverage for dual-stack network environments. This test would avoid the regression fixed by commit f59902070269 ("net: netpoll: Initialize UDP checksum field before checksumming") Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- .../selftests/drivers/net/lib/sh/lib_netcons.sh | 76 ++++++++++++++++++= ++-- .../testing/selftests/drivers/net/netcons_basic.sh | 53 ++++++++------- 2 files changed, 99 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/to= ols/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 3fcf85a345969..258af805497b4 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -11,9 +11,11 @@ set -euo pipefail LIBDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") =20 SRCIF=3D"" # to be populated later -SRCIP=3D192.0.2.1 +SRCIP4=3D"192.0.2.1" +SRCIP6=3D"fc00::1" DSTIF=3D"" # to be populated later -DSTIP=3D192.0.2.2 +DSTIP4=3D"192.0.2.2" +DSTIP6=3D"fc00::2" =20 PORT=3D"6666" MSG=3D"netconsole selftest" @@ -80,7 +82,23 @@ function configure_ip() { ip link set "${SRCIF}" up } =20 +function select_ipv4_or_ipv6() +{ + local VERSION=3D${1} + + if [[ "$VERSION" =3D=3D "ipv6" ]] + then + DSTIP=3D"${DSTIP6}" + SRCIP=3D"${SRCIP6}" + else + DSTIP=3D"${DSTIP4}" + SRCIP=3D"${SRCIP4}" + fi +} + function set_network() { + local IP_VERSION=3D${1:-"ipv4"} + # setup_ns function is coming from lib.sh setup_ns NAMESPACE =20 @@ -91,6 +109,7 @@ function set_network() { # Link both interfaces back to back link_ifaces =20 + select_ipv4_or_ipv6 "${IP_VERSION}" configure_ip } =20 @@ -119,6 +138,11 @@ function create_dynamic_target() { fi =20 echo 1 > "${NETCONS_PATH}"/enabled + + # This will make sure that the kernel was able to + # load the netconsole driver configuration. The console message + # gets more organized/sequential as well. + sleep 1 } =20 # Generate the command line argument for netconsole following: @@ -179,9 +203,18 @@ function set_user_data() { =20 function listen_port_and_save_to() { local OUTPUT=3D${1} + local IPVERSION=3D${2:-"ipv4"} + + if [ "${IPVERSION}" =3D=3D "ipv4" ] + then + SOCAT_MODE=3D"UDP-LISTEN" + else + SOCAT_MODE=3D"UDP6-LISTEN" + fi + # Just wait for 2 seconds timeout 2 ip netns exec "${NAMESPACE}" \ - socat UDP-LISTEN:"${PORT}",fork "${OUTPUT}" + socat "${SOCAT_MODE}":"${PORT}",fork "${OUTPUT}" } =20 # Only validate that the message arrived properly @@ -263,8 +296,15 @@ function check_for_dependencies() { exit "${ksft_skip}" fi =20 - if ip addr list | grep -E "inet.*(${SRCIP}|${DSTIP})" 2> /dev/null; then - echo "SKIP: IPs already in use. Skipping it" >&2 + REGEXP4=3D"inet.*(${SRCIP4}|${DSTIP4})" + REGEXP6=3D"inet.*(${SRCIP6}|${DSTIP6})" + if ip addr list | grep -E "${REGEXP4}" 2> /dev/null; then + echo "SKIP: IPv4s already in use. Skipping it" >&2 + exit "${ksft_skip}" + fi + + if ip addr list | grep -E "${REGEXP6}" 2> /dev/null; then + echo "SKIP: IPv6s already in use. Skipping it" >&2 exit "${ksft_skip}" fi } @@ -278,11 +318,13 @@ function check_for_taskset() { =20 # This is necessary if running multiple tests in a row function pkill_socat() { - PROCESS_NAME=3D"socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}" + PROCESS_NAME4=3D"socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}" + PROCESS_NAME6=3D"socat UDP6-LISTEN:6666,fork ${OUTPUT_FILE}" # socat runs under timeout(1), kill it if it is still alive # do not fail if socat doesn't exist anymore set +e - pkill -f "${PROCESS_NAME}" + pkill -f "${PROCESS_NAME4}" + pkill -f "${PROCESS_NAME6}" set -e } =20 @@ -294,3 +336,23 @@ function check_netconsole_module() { exit "${ksft_skip}" fi } + +# A wrapper to translate protocol version to udp version +function wait_for_port() { + local NAMESPACE=3D${1} + local PORT=3D${2} + IP_VERSION=3D${3} + + if [ "${IP_VERSION}" =3D=3D "ipv6" ] + then + PROTOCOL=3D"udp6" + else + PROTOCOL=3D"udp" + fi + + wait_local_port_listen "${NAMESPACE}" "${PORT}" "${PROTOCOL}" + # even after the port is open, let's wait 1 second before writing + # otherwise the packet could be missed, and the test will fail. Happens + # more frequently on IPv6 + sleep 1 +} diff --git a/tools/testing/selftests/drivers/net/netcons_basic.sh b/tools/t= esting/selftests/drivers/net/netcons_basic.sh index 40a6ac6191b8b..a3446b5699764 100755 --- a/tools/testing/selftests/drivers/net/netcons_basic.sh +++ b/tools/testing/selftests/drivers/net/netcons_basic.sh @@ -36,30 +36,37 @@ trap cleanup EXIT # Run the test twice, with different format modes for FORMAT in "basic" "extended" do - echo "Running with target mode: ${FORMAT}" - # Create one namespace and two interfaces - set_network - # Create a dynamic target for netconsole - create_dynamic_target "${FORMAT}" - # Only set userdata for extended format - if [ "$FORMAT" =3D=3D "extended" ] - then - # Set userdata "key" with the "value" value - set_user_data - fi - # Listed for netconsole port inside the namespace and destination interfa= ce - listen_port_and_save_to "${OUTPUT_FILE}" & - # Wait for socat to start and listen to the port. - wait_local_port_listen "${NAMESPACE}" "${PORT}" udp - # Send the message - echo "${MSG}: ${TARGET}" > /dev/kmsg - # Wait until socat saves the file to disk - busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" + for IP_VERSION in "ipv6" "ipv4" + do + echo "Running with target mode: ${FORMAT} (${IP_VERSION})" + # Create one namespace and two interfaces + set_network "${IP_VERSION}" + # Create a dynamic target for netconsole + create_dynamic_target "${FORMAT}" + # Only set userdata for extended format + if [ "$FORMAT" =3D=3D "extended" ] + then + # Set userdata "key" with the "value" value + set_user_data + fi + # Listed for netconsole port inside the namespace and + # destination interface + listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" & + # Wait for socat to start and listen to the port. + wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}" + # Send the message + echo "${MSG}: ${TARGET}" > /dev/kmsg + # Wait until socat saves the file to disk + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" =20 - # Make sure the message was received in the dst part - # and exit - validate_result "${OUTPUT_FILE}" "${FORMAT}" - cleanup + # Make sure the message was received in the dst part + # and exit + validate_result "${OUTPUT_FILE}" "${FORMAT}" + # kill socat in case it is still running + pkill_socat + cleanup + echo "${FORMAT} : ${IP_VERSION} : Test passed" >&2 + done done =20 trap - EXIT --=20 2.47.1