mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Andrew Lunn <andrew+netdev@lunn.ch>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 gustavold@gmail.com, asantostc@gmail.com,
	Breno Leitao <leitao@debian.org>,
	 kernel-team@meta.com
Subject: [PATCH 7/9] netconsole: move local_port from struct netpoll to netconsole_target
Date: Sun, 24 May 2026 09:12:23 -0700	[thread overview]
Message-ID: <20260524-netconsole_move_more-v1-7-909d1ab398b4@debian.org> (raw)
In-Reply-To: <20260524-netconsole_move_more-v1-0-909d1ab398b4@debian.org>

The UDP source port used to build outgoing log packets is pure
netconsole configuration. net/core/netpoll.c never reads it, and
no other struct netpoll consumer (bonding, bridge, team, vlan,
macvlan, dsa) touches it either.

Add local_port to struct netconsole_target, drop it from struct
netpoll, and update alloc_and_init(), the local_port_show /
local_port_store configfs handlers, push_udp(),
netconsole_print_banner() and netconsole_parser_cmdline() to read
it from nt-> rather than np->.

netconsole_print_banner(), push_udp() and netconsole_parser_cmdline()
gain a struct netconsole_target * parameter so they can reach the
new home; subsequent patches that move remote_port and remote_mac
reuse the same plumbing.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 45 +++++++++++++++++++++++----------------------
 include/linux/netpoll.h  |  2 +-
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index b8b1608d09e9..a4f34560cee5 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -172,15 +172,11 @@ enum target_state {
  * @extended:	Denotes whether console is extended or not.
  * @release:	Denotes whether kernel release version should be prepended
  *		to the message. Depends on extended console.
- * @np:		The netpoll structure for this target.
- *		Contains the other userspace visible parameters:
- *		dev_name	(read-write)
- *		local_port	(read-write)
- *		remote_port	(read-write)
- *		local_ip	(read-write)
- *		remote_ip	(read-write)
- *		local_mac	(read-only)
- *		remote_mac	(read-write)
+ * @np:		The netpoll structure for this target. Holds the
+ *		underlying net_device handle and the addressing fields
+ *		that netpoll core still reads (local_ip, remote_ip, ipv6,
+ *		dev_name, dev_mac).
+ * @local_port:	UDP source port used to build outgoing log packets.
  * @buf:	The buffer used to send the full msg to the network stack
  * @resume_wq:	Workqueue to resume deactivated target
  * @skb_pool:	Per-target fallback skb pool consulted by find_skb() when
@@ -208,6 +204,7 @@ struct netconsole_target {
 	bool			extended;
 	bool			release;
 	struct netpoll		np;
+	u16			local_port;
 	/* protected by target_list_lock */
 	char			buf[MAX_PRINT_CHUNK];
 	struct work_struct	resume_wq;
@@ -432,7 +429,7 @@ static struct netconsole_target *alloc_and_init(void)
 
 	nt->np.name = "netconsole";
 	strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
-	nt->np.local_port = 6665;
+	nt->local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
 	nt->state = STATE_DISABLED;
@@ -471,9 +468,11 @@ static void netconsole_process_cleanups_core(void)
 	mutex_unlock(&target_cleanup_list_lock);
 }
 
-static void netconsole_print_banner(struct netpoll *np)
+static void netconsole_print_banner(struct netconsole_target *nt)
 {
-	np_info(np, "local port %d\n", np->local_port);
+	struct netpoll *np = &nt->np;
+
+	np_info(np, "local port %d\n", nt->local_port);
 	if (np->ipv6)
 		np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
 	else
@@ -603,7 +602,7 @@ static ssize_t dev_name_show(struct config_item *item, char *buf)
 
 static ssize_t local_port_show(struct config_item *item, char *buf)
 {
-	return sysfs_emit(buf, "%d\n", to_target(item)->np.local_port);
+	return sysfs_emit(buf, "%d\n", to_target(item)->local_port);
 }
 
 static ssize_t remote_port_show(struct config_item *item, char *buf)
@@ -798,7 +797,7 @@ static ssize_t enabled_store(struct config_item *item,
 		 * Skip netconsole_parser_cmdline() -- all the attributes are
 		 * already configured via configfs. Just print them out.
 		 */
-		netconsole_print_banner(&nt->np);
+		netconsole_print_banner(nt);
 
 		/* Initialise the skb pool before netpoll_setup() so the pool
 		 * is valid as soon as nt->np.dev becomes visible to
@@ -937,7 +936,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf,
 		goto out_unlock;
 	}
 
-	ret = kstrtou16(buf, 10, &nt->np.local_port);
+	ret = kstrtou16(buf, 10, &nt->local_port);
 	if (ret < 0)
 		goto out_unlock;
 	ret = count;
@@ -1788,8 +1787,9 @@ static void netpoll_udp_checksum(struct netpoll *np, struct sk_buff *skb,
 		udph->check = CSUM_MANGLED_0;
 }
 
-static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
+static void push_udp(struct netconsole_target *nt, struct sk_buff *skb, int len)
 {
+	struct netpoll *np = &nt->np;
 	struct udphdr *udph;
 	int udp_len;
 
@@ -1799,7 +1799,7 @@ static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
 	skb_reset_transport_header(skb);
 
 	udph = udp_hdr(skb);
-	udph->source = htons(np->local_port);
+	udph->source = htons(nt->local_port);
 	udph->dest = htons(np->remote_port);
 	udph->len = htons(udp_len);
 
@@ -1896,7 +1896,7 @@ static int netpoll_send_udp(struct netconsole_target *nt, const char *msg,
 	skb_copy_to_linear_data(skb, msg, len);
 	skb_put(skb, len);
 
-	push_udp(np, skb, len);
+	push_udp(nt, skb, len);
 	if (np->ipv6)
 		push_ipv6(np, skb, len);
 	else
@@ -2214,8 +2214,9 @@ __releases(&target_list_lock)
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
-static int netconsole_parser_cmdline(struct netpoll *np, char *opt)
+static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt)
 {
+	struct netpoll *np = &nt->np;
 	bool ipversion_set = false;
 	char *cur = opt;
 	char *delim;
@@ -2226,7 +2227,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt)
 		if (!delim)
 			goto parse_failed;
 		*delim = 0;
-		if (kstrtou16(cur, 10, &np->local_port))
+		if (kstrtou16(cur, 10, &nt->local_port))
 			goto parse_failed;
 		cur = delim;
 	}
@@ -2299,7 +2300,7 @@ static int netconsole_parser_cmdline(struct netpoll *np, char *opt)
 			goto parse_failed;
 	}
 
-	netconsole_print_banner(np);
+	netconsole_print_banner(nt);
 
 	return 0;
 
@@ -2337,7 +2338,7 @@ static struct netconsole_target *alloc_param_target(char *target_config,
 	}
 
 	/* Parse parameters and setup netpoll */
-	err = netconsole_parser_cmdline(&nt->np, target_config);
+	err = netconsole_parser_cmdline(nt, target_config);
 	if (err)
 		goto fail;
 
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index 8344454df05d..dcea36713720 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -33,7 +33,7 @@ struct netpoll {
 
 	union inet_addr local_ip, remote_ip;
 	bool ipv6;
-	u16 local_port, remote_port;
+	u16 remote_port;
 	u8 remote_mac[ETH_ALEN];
 };
 

-- 
2.54.0


  parent reply	other threads:[~2026-05-24 16:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 16:12 [PATCH 0/9] netconsole: stop charging every netpoll user for netconsole-only state Breno Leitao
2026-05-24 16:12 ` [PATCH 1/9] netpoll: export refill_skbs(), refill_skbs_work_handler(), skb_pool_flush() Breno Leitao
2026-05-24 16:12 ` [PATCH 2/9] netconsole: take over skb pool lifecycle from netpoll Breno Leitao
2026-05-24 16:12 ` [PATCH 3/9] netconsole: move refill_skbs_work_handler() " Breno Leitao
2026-05-24 16:12 ` [PATCH 4/9] netconsole: move refill_skbs() and skb-pool sizing macros " Breno Leitao
2026-05-24 16:12 ` [PATCH 5/9] netconsole: move skb_pool_flush() " Breno Leitao
2026-05-24 16:12 ` [PATCH 6/9] netconsole: move skb_pool / refill_wq from struct netpoll to netconsole_target Breno Leitao
2026-05-24 16:12 ` Breno Leitao [this message]
2026-05-24 16:12 ` [PATCH 8/9] netconsole: move remote_port " Breno Leitao
2026-05-24 16:12 ` [PATCH 9/9] netconsole: move remote_mac " Breno Leitao
2026-05-27  2:00 ` [PATCH 0/9] netconsole: stop charging every netpoll user for netconsole-only state Jakub Kicinski
2026-05-27  9:07   ` Breno Leitao
2026-05-27 13:22     ` Breno Leitao
2026-05-27 22:59       ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260524-netconsole_move_more-v1-7-909d1ab398b4@debian.org \
    --to=leitao@debian.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=asantostc@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavold@gmail.com \
    --cc=horms@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®