[PATCH 7/9] netconsole: move local_port from struct netpoll to netconsole_target
From: Breno Leitao
Date: Sun May 24 2026 - 12:17:39 EST
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@xxxxxxxxxx>
---
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