From: Gustavo Luiz Duarte <gustavold@gmail.com>
To: Breno Leitao <leitao@debian.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"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>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Gustavo Luiz Duarte <gustavold@gmail.com>
Subject: [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr
Date: Wed, 05 Aug 2026 22:33:01 +0100 [thread overview]
Message-ID: <20260805-netcons_ipv6-v1-1-170a35b92da1@gmail.com> (raw)
In-Reply-To: <20260805-netcons_ipv6-v1-0-170a35b92da1@gmail.com>
netconsole_target stores a single 'bool ipv6' to denote the target's
address family. This makes it hard to detect conditions like "no address
set" or ipv4/ipv6 mixup between local_ip and remote_ip.
Add a 'family' field to inet_addr so each address stores its own address
family: AF_UNSPEC while unset, else AF_INET or AF_INET6.
Nothing reads the new field yet. The next patch switches the users over
and removes the bool. No functional change.
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
drivers/net/netconsole.c | 22 ++++++++++++++--------
include/linux/netpoll.h | 10 +++++++---
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 03913302328c..d615a9256787 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -212,7 +212,7 @@ struct netconsole_target {
bool extended;
bool release;
struct netpoll np;
- union inet_addr local_ip, remote_ip;
+ struct inet_addr local_ip, remote_ip;
bool ipv6;
u16 local_port, remote_port;
u8 remote_mac[ETH_ALEN];
@@ -415,6 +415,7 @@ static int netcons_take_ipv6(struct netconsole_target *nt,
continue;
/* Got the IP, let's return */
nt->local_ip.in6 = ifp->addr;
+ nt->local_ip.family = AF_INET6;
err = 0;
break;
}
@@ -456,6 +457,7 @@ static int netcons_take_ipv4(struct netconsole_target *nt,
}
nt->local_ip.ip = ifa->ifa_local;
+ nt->local_ip.family = AF_INET;
np_info(np, "local IP %pI4\n", &nt->local_ip.ip);
return 0;
@@ -731,7 +733,7 @@ static void netconsole_print_banner(struct netconsole_target *nt)
/* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is
* populated, 1 if IPv6 is populated, and -1 upon failure.
*/
-static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
+static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr)
{
const char *end = NULL;
int len;
@@ -743,14 +745,18 @@ static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
if (str[len - 1] == '\n')
len -= 1;
- if (in4_pton(str, len, (void *)addr, -1, &end) > 0 &&
- (!end || *end == 0 || *end == '\n'))
+ if (in4_pton(str, len, (void *)&addr->ip, -1, &end) > 0 &&
+ (!end || *end == 0 || *end == '\n')) {
+ addr->family = AF_INET;
return 0;
+ }
if (IS_ENABLED(CONFIG_IPV6) &&
- in6_pton(str, len, (void *)addr, -1, &end) > 0 &&
- (!end || *end == 0 || *end == '\n'))
+ in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 &&
+ (!end || *end == 0 || *end == '\n')) {
+ addr->family = AF_INET6;
return 1;
+ }
return -1;
}
@@ -858,7 +864,7 @@ static ssize_t local_ip_show(struct config_item *item, char *buf)
if (nt->ipv6)
return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6);
else
- return sysfs_emit(buf, "%pI4\n", &nt->local_ip);
+ return sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip);
}
static ssize_t remote_ip_show(struct config_item *item, char *buf)
@@ -868,7 +874,7 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf)
if (nt->ipv6)
return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6);
else
- return sysfs_emit(buf, "%pI4\n", &nt->remote_ip);
+ return sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip);
}
static ssize_t local_mac_show(struct config_item *item, char *buf)
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index 1c6b1eec5efd..de97f001a0f9 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -16,9 +16,13 @@
#include <linux/ip.h>
#include <linux/udp.h>
-union inet_addr {
- __be32 ip;
- struct in6_addr in6;
+struct inet_addr {
+ /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */
+ u8 family;
+ union {
+ __be32 ip;
+ struct in6_addr in6;
+ };
};
struct netpoll {
--
2.55.0
next prev parent reply other threads:[~2026-08-05 21:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 21:33 [PATCH net-next 0/4] netconsole: validate a target's IP address configuration Gustavo Luiz Duarte
2026-08-05 21:33 ` Gustavo Luiz Duarte [this message]
2026-08-06 15:49 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr Breno Leitao
2026-08-07 11:21 ` Gustavo Luiz Duarte
2026-08-05 21:33 ` [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag Gustavo Luiz Duarte
2026-08-06 15:55 ` Breno Leitao
2026-08-07 12:00 ` Gustavo Luiz Duarte
2026-08-07 13:11 ` Breno Leitao
2026-08-05 21:33 ` [PATCH net-next 3/4] netconsole: reject enabling a target with no remote IP address Gustavo Luiz Duarte
2026-08-06 15:58 ` Breno Leitao
2026-08-07 12:11 ` Gustavo Luiz Duarte
2026-08-05 21:33 ` [PATCH net-next 4/4] netconsole: reject a target mixing IPv4 and IPv6 addresses Gustavo Luiz Duarte
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=20260805-netcons_ipv6-v1-1-170a35b92da1@gmail.com \
--to=gustavold@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.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