* [PATCH net-next 0/4] netconsole: validate a target's IP address configuration
@ 2026-08-05 21:33 Gustavo Luiz Duarte
2026-08-05 21:33 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr Gustavo Luiz Duarte
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Gustavo Luiz Duarte @ 2026-08-05 21:33 UTC (permalink / raw)
To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Gustavo Luiz Duarte
This series adds two validations to the target configuration when the
user tries to enable it: first whether remote_ip was set, and second
whether local_ip and remote_ip address families match. Refuse to enable
the target if any of those validations fail.
These validations are already done for the target passed on the
command-line, so this aligns dynamic targets with the command-line
behavior.
The first two patches replace the per-target 'ipv6' flag with a
per-address 'family' field, which makes it easier to detect these error
conditions. Patches 3 and 4 implement the actual validations.
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
Gustavo Luiz Duarte (4):
netconsole: add an address family to struct inet_addr
netconsole: use the address family instead of the ipv6 flag
netconsole: reject enabling a target with no remote IP address
netconsole: reject a target mixing IPv4 and IPv6 addresses
drivers/net/netconsole.c | 117 ++++++++++++++++++++---------------------------
include/linux/netpoll.h | 10 ++--
2 files changed, 57 insertions(+), 70 deletions(-)
---
base-commit: a23b36233d4103def55dc8cf65698106d0bd1e62
change-id: 20260730-netcons_ipv6-565d55f55729
Best regards,
--
Gustavo Luiz Duarte <gustavold@gmail.com>
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr 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 2026-08-06 15:49 ` Breno Leitao 2026-08-05 21:33 ` [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag Gustavo Luiz Duarte ` (2 subsequent siblings) 3 siblings, 1 reply; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-05 21:33 UTC (permalink / raw) To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman Cc: netdev, linux-kernel, Gustavo Luiz Duarte 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 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr 2026-08-05 21:33 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr Gustavo Luiz Duarte @ 2026-08-06 15:49 ` Breno Leitao 2026-08-07 11:21 ` Gustavo Luiz Duarte 0 siblings, 1 reply; 12+ messages in thread From: Breno Leitao @ 2026-08-06 15:49 UTC (permalink / raw) To: Gustavo Luiz Duarte Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Wed, Aug 05, 2026 at 10:33:01PM +0100, Gustavo Luiz Duarte wrote: > @@ -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 ^-> there is no more union. I think there are other references for union that needs to be updated as well. > +static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) ... > return -1; Should the failure path set addr->family = AF_UNSPEC? > +++ b/include/linux/netpoll.h > +struct inet_addr { > + /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */ > + u8 family; > + union { > + __be32 ip; > + struct in6_addr in6; > + }; > }; Since a1116396476f6 ("netconsole: move local_ip/remote_ip/ipv6 to netconsole_target") struct netpoll has no address member, and netconsole is the only user left in the tree: drivers/net/netconsole.c: union inet_addr local_ip, remote_ip; drivers/net/netconsole.c:static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr) Since you touched it, can you move it to netconsole headers, please? --breno ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr 2026-08-06 15:49 ` Breno Leitao @ 2026-08-07 11:21 ` Gustavo Luiz Duarte 0 siblings, 0 replies; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-07 11:21 UTC (permalink / raw) To: Breno Leitao Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Thu, Aug 6, 2026 at 4:49 PM Breno Leitao <leitao@debian.org> wrote: > > On Wed, Aug 05, 2026 at 10:33:01PM +0100, Gustavo Luiz Duarte wrote: > > @@ -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 > ^-> there is no more union. > > I think there are other references for union that needs to be updated as > well. I fixed this in the next patch, but let me do it here for consistency. I didn't find any other reference to union. > > > +static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) > ... > > return -1; > > Should the failure path set addr->family = AF_UNSPEC? The failure path leaves addr untouched, so if the user writes an invalid value to local_ip or remote_ip the write fails and the original value is maintained. > > > +++ b/include/linux/netpoll.h > > +struct inet_addr { > > + /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */ > > + u8 family; > > + union { > > + __be32 ip; > > + struct in6_addr in6; > > + }; > > }; > > Since a1116396476f6 ("netconsole: move local_ip/remote_ip/ipv6 to > netconsole_target") struct netpoll has no address member, and netconsole > is the only user left in the tree: > > drivers/net/netconsole.c: union inet_addr local_ip, remote_ip; > drivers/net/netconsole.c:static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr) > > Since you touched it, can you move it to netconsole headers, please? Sure, will do it in v2. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag 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 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr Gustavo Luiz Duarte @ 2026-08-05 21:33 ` Gustavo Luiz Duarte 2026-08-06 15:55 ` 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-05 21:33 ` [PATCH net-next 4/4] netconsole: reject a target mixing IPv4 and IPv6 addresses Gustavo Luiz Duarte 3 siblings, 1 reply; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-05 21:33 UTC (permalink / raw) To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman Cc: netdev, linux-kernel, Gustavo Luiz Duarte Now that we have the address family in inet_addr, use that and remove nt->ipv6. We no longer need netcons_local_ip_unset() to check that all bytes are zeroes, as that is now denoted by (family == AF_UNSPEC). Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> --- drivers/net/netconsole.c | 82 ++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 59 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index d615a9256787..070bae7b4fd7 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -181,7 +181,6 @@ enum target_state { * local_mac (read-only) * @local_ip: Source IP address of the target (read-write). * @remote_ip: Destination IP address of the target (read-write). - * @ipv6: Whether the target addresses are IPv6 (read-write). * @local_port: Source UDP port of the target (read-write). * @remote_port: Destination UDP port of the target (read-write). * @remote_mac: Destination ethernet address of the target (read-write). @@ -213,7 +212,6 @@ struct netconsole_target { bool release; struct netpoll np; struct inet_addr local_ip, remote_ip; - bool ipv6; u16 local_port, remote_port; u8 remote_mac[ETH_ALEN]; /* protected by target_list_lock; +1 gives scnprintf() room for its @@ -463,23 +461,6 @@ static int netcons_take_ipv4(struct netconsole_target *nt, return 0; } -/* - * Test whether the caller left nt->local_ip unset, so that - * netcons_netpoll_setup() should auto-populate it from the egress device. - * - * nt->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6), - * so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2, - * IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm — - * doing so would misclassify a caller-supplied address as unset and - * silently overwrite it with whatever address the device exposes. - */ -static bool netcons_local_ip_unset(const struct netconsole_target *nt) -{ - if (nt->ipv6) - return ipv6_addr_any(&nt->local_ip.in6); - return !nt->local_ip.ip; -} - static int netcons_netpoll_setup(struct netconsole_target *nt) { struct net *net = current->nsproxy->net_ns; @@ -525,16 +506,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) rtnl_lock(); } - if (netcons_local_ip_unset(nt)) { - if (!nt->ipv6) { - err = netcons_take_ipv4(nt, ndev); - if (err) - goto put; - } else { + if (nt->local_ip.family == AF_UNSPEC) { + if (nt->remote_ip.family == AF_INET6) err = netcons_take_ipv6(nt, ndev); - if (err) - goto put; - } + else + err = netcons_take_ipv4(nt, ndev); + if (err) + goto put; ip_overwritten = true; } @@ -716,22 +694,22 @@ static void netconsole_print_banner(struct netconsole_target *nt) struct netpoll *np = &nt->np; np_info(np, "local port %d\n", nt->local_port); - if (nt->ipv6) + if (nt->local_ip.family == AF_INET6) np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); else np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); np_info(np, "interface name '%s'\n", np->dev_name); np_info(np, "local ethernet address '%pM'\n", np->dev_mac); np_info(np, "remote port %d\n", nt->remote_port); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) np_info(np, "remote IPv6 address %pI6c\n", &nt->remote_ip.in6); else np_info(np, "remote IPv4 address %pI4\n", &nt->remote_ip.ip); np_info(np, "remote ethernet address %pM\n", nt->remote_mac); } -/* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is - * populated, 1 if IPv6 is populated, and -1 upon failure. +/* Parse the string and populate the `inet_addr` struct. Return 0 on success + * and -1 upon failure. */ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) { @@ -755,7 +733,7 @@ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && (!end || *end == 0 || *end == '\n')) { addr->family = AF_INET6; - return 1; + return 0; } return -1; @@ -861,7 +839,7 @@ static ssize_t local_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); - if (nt->ipv6) + if (nt->local_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6); else return sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip); @@ -871,7 +849,7 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6); else return sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip); @@ -1219,7 +1197,6 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); ssize_t ret = -EINVAL; - int ipv6; dynamic_netconsole_mutex_lock(); if (nt->state == STATE_ENABLED) { @@ -1228,10 +1205,8 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - ipv6 = netpoll_parse_ip_addr(buf, &nt->local_ip); - if (ipv6 == -1) + if (netpoll_parse_ip_addr(buf, &nt->local_ip) < 0) goto out_unlock; - nt->ipv6 = !!ipv6; ret = count; out_unlock: @@ -1244,7 +1219,6 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); ssize_t ret = -EINVAL; - int ipv6; dynamic_netconsole_mutex_lock(); if (nt->state == STATE_ENABLED) { @@ -1253,10 +1227,8 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - ipv6 = netpoll_parse_ip_addr(buf, &nt->remote_ip); - if (ipv6 == -1) + if (netpoll_parse_ip_addr(buf, &nt->remote_ip) < 0) goto out_unlock; - nt->ipv6 = !!ipv6; ret = count; out_unlock: @@ -2067,7 +2039,7 @@ static void netpoll_udp_checksum(struct netconsole_target *nt, /* check needs to be set, since it will be consumed in csum_partial */ udph->check = 0; - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) udph->check = csum_ipv6_magic(&nt->local_ip.in6, &nt->remote_ip.in6, udp_len, IPPROTO_UDP, @@ -2108,7 +2080,7 @@ static void push_eth(struct netconsole_target *nt, struct sk_buff *skb) skb_reset_mac_header(skb); ether_addr_copy(eth->h_source, np->dev->dev_addr); ether_addr_copy(eth->h_dest, nt->remote_mac); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) eth->h_proto = htons(ETH_P_IPV6); else eth->h_proto = htons(ETH_P_IP); @@ -2177,7 +2149,7 @@ static int netpoll_send_udp(struct netconsole_target *nt, const char *msg, WARN_ON_ONCE(!irqs_disabled()); udp_len = len + sizeof(struct udphdr); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) ip_len = udp_len + sizeof(struct ipv6hdr); else ip_len = udp_len + sizeof(struct iphdr); @@ -2193,7 +2165,7 @@ static int netpoll_send_udp(struct netconsole_target *nt, const char *msg, skb_put(skb, len); push_udp(nt, skb, len); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) push_ipv6(nt, skb, len); else push_ipv4(nt, skb, len); @@ -2513,10 +2485,8 @@ __releases(&target_list_lock) 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; - int ipv6; if (*cur != '@') { delim = strchr(cur, '@'); @@ -2530,16 +2500,12 @@ static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) cur++; if (*cur != '/') { - ipversion_set = true; delim = strchr(cur, '/'); if (!delim) goto parse_failed; *delim = 0; - ipv6 = netpoll_parse_ip_addr(cur, &nt->local_ip); - if (ipv6 < 0) + if (netpoll_parse_ip_addr(cur, &nt->local_ip) < 0) goto parse_failed; - else - nt->ipv6 = (bool)ipv6; cur = delim; } cur++; @@ -2581,13 +2547,11 @@ static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) if (!delim) goto parse_failed; *delim = 0; - ipv6 = netpoll_parse_ip_addr(cur, &nt->remote_ip); - if (ipv6 < 0) + if (netpoll_parse_ip_addr(cur, &nt->remote_ip) < 0) goto parse_failed; - else if (ipversion_set && nt->ipv6 != (bool)ipv6) + if (nt->local_ip.family != AF_UNSPEC && + nt->local_ip.family != nt->remote_ip.family) goto parse_failed; - else - nt->ipv6 = (bool)ipv6; cur = delim + 1; if (*cur != 0) { -- 2.55.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag 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 0 siblings, 1 reply; 12+ messages in thread From: Breno Leitao @ 2026-08-06 15:55 UTC (permalink / raw) To: Gustavo Luiz Duarte Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Wed, Aug 05, 2026 at 10:33:02PM +0100, Gustavo Luiz Duarte wrote: > Now that we have the address family in inet_addr, use that and remove > nt->ipv6. > > We no longer need netcons_local_ip_unset() to check that all bytes are > zeroes, as that is now denoted by (family == AF_UNSPEC). > > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> > --- > drivers/net/netconsole.c | 82 ++++++++++++++---------------------------------- > 1 file changed, 23 insertions(+), 59 deletions(-) > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > index d615a9256787..070bae7b4fd7 100644 > --- a/drivers/net/netconsole.c > +++ b/drivers/net/netconsole.c > @@ -181,7 +181,6 @@ enum target_state { > * local_mac (read-only) > * @local_ip: Source IP address of the target (read-write). > * @remote_ip: Destination IP address of the target (read-write). > - * @ipv6: Whether the target addresses are IPv6 (read-write). > * @local_port: Source UDP port of the target (read-write). > * @remote_port: Destination UDP port of the target (read-write). > * @remote_mac: Destination ethernet address of the target (read-write). > @@ -213,7 +212,6 @@ struct netconsole_target { > bool release; > struct netpoll np; > struct inet_addr local_ip, remote_ip; > - bool ipv6; > u16 local_port, remote_port; > u8 remote_mac[ETH_ALEN]; > /* protected by target_list_lock; +1 gives scnprintf() room for its > @@ -463,23 +461,6 @@ static int netcons_take_ipv4(struct netconsole_target *nt, > return 0; > } > > -/* > - * Test whether the caller left nt->local_ip unset, so that > - * netcons_netpoll_setup() should auto-populate it from the egress device. > - * > - * nt->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6), > - * so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2, > - * IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm — > - * doing so would misclassify a caller-supplied address as unset and > - * silently overwrite it with whatever address the device exposes. > - */ > -static bool netcons_local_ip_unset(const struct netconsole_target *nt) > -{ > - if (nt->ipv6) > - return ipv6_addr_any(&nt->local_ip.in6); > - return !nt->local_ip.ip; > -} > - > static int netcons_netpoll_setup(struct netconsole_target *nt) > { > struct net *net = current->nsproxy->net_ns; > @@ -525,16 +506,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) > rtnl_lock(); > } > > - if (netcons_local_ip_unset(nt)) { > - if (!nt->ipv6) { > - err = netcons_take_ipv4(nt, ndev); > - if (err) > - goto put; > - } else { > + if (nt->local_ip.family == AF_UNSPEC) { > + if (nt->remote_ip.family == AF_INET6) > err = netcons_take_ipv6(nt, ndev); > - if (err) > - goto put; > - } > + else > + err = netcons_take_ipv4(nt, ndev); > + if (err) > + goto put; nice, that is much clearer. > ip_overwritten = true; > } > > @@ -716,22 +694,22 @@ static void netconsole_print_banner(struct netconsole_target *nt) > struct netpoll *np = &nt->np; > > np_info(np, "local port %d\n", nt->local_port); > - if (nt->ipv6) > + if (nt->local_ip.family == AF_INET6) > np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); > else > np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); Any chance it can be UNSPEC? > np_info(np, "interface name '%s'\n", np->dev_name); > np_info(np, "local ethernet address '%pM'\n", np->dev_mac); > np_info(np, "remote port %d\n", nt->remote_port); > - if (nt->ipv6) > + if (nt->remote_ip.family == AF_INET6) > np_info(np, "remote IPv6 address %pI6c\n", &nt->remote_ip.in6); > else Same question > @@ -755,7 +733,7 @@ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) > in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && > (!end || *end == 0 || *end == '\n')) { > addr->family = AF_INET6; Why not setting family for for IPV4? In if (in4_pton(str, len, (void *)addr, -1, &end) > 0 && (!end || *end == 0 || *end == '\n')) return 0; ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag 2026-08-06 15:55 ` Breno Leitao @ 2026-08-07 12:00 ` Gustavo Luiz Duarte 2026-08-07 13:11 ` Breno Leitao 0 siblings, 1 reply; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-07 12:00 UTC (permalink / raw) To: Breno Leitao Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Thu, Aug 6, 2026 at 4:55 PM Breno Leitao <leitao@debian.org> wrote: > > On Wed, Aug 05, 2026 at 10:33:02PM +0100, Gustavo Luiz Duarte wrote: > > Now that we have the address family in inet_addr, use that and remove > > nt->ipv6. > > > > We no longer need netcons_local_ip_unset() to check that all bytes are > > zeroes, as that is now denoted by (family == AF_UNSPEC). > > > > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> > > --- > > drivers/net/netconsole.c | 82 ++++++++++++++---------------------------------- > > 1 file changed, 23 insertions(+), 59 deletions(-) > > > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > > index d615a9256787..070bae7b4fd7 100644 > > --- a/drivers/net/netconsole.c > > +++ b/drivers/net/netconsole.c > > @@ -181,7 +181,6 @@ enum target_state { > > * local_mac (read-only) > > * @local_ip: Source IP address of the target (read-write). > > * @remote_ip: Destination IP address of the target (read-write). > > - * @ipv6: Whether the target addresses are IPv6 (read-write). > > * @local_port: Source UDP port of the target (read-write). > > * @remote_port: Destination UDP port of the target (read-write). > > * @remote_mac: Destination ethernet address of the target (read-write). > > @@ -213,7 +212,6 @@ struct netconsole_target { > > bool release; > > struct netpoll np; > > struct inet_addr local_ip, remote_ip; > > - bool ipv6; > > u16 local_port, remote_port; > > u8 remote_mac[ETH_ALEN]; > > /* protected by target_list_lock; +1 gives scnprintf() room for its > > @@ -463,23 +461,6 @@ static int netcons_take_ipv4(struct netconsole_target *nt, > > return 0; > > } > > > > -/* > > - * Test whether the caller left nt->local_ip unset, so that > > - * netcons_netpoll_setup() should auto-populate it from the egress device. > > - * > > - * nt->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6), > > - * so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2, > > - * IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm — > > - * doing so would misclassify a caller-supplied address as unset and > > - * silently overwrite it with whatever address the device exposes. > > - */ > > -static bool netcons_local_ip_unset(const struct netconsole_target *nt) > > -{ > > - if (nt->ipv6) > > - return ipv6_addr_any(&nt->local_ip.in6); > > - return !nt->local_ip.ip; > > -} > > - > > static int netcons_netpoll_setup(struct netconsole_target *nt) > > { > > struct net *net = current->nsproxy->net_ns; > > @@ -525,16 +506,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) > > rtnl_lock(); > > } > > > > - if (netcons_local_ip_unset(nt)) { > > - if (!nt->ipv6) { > > - err = netcons_take_ipv4(nt, ndev); > > - if (err) > > - goto put; > > - } else { > > + if (nt->local_ip.family == AF_UNSPEC) { > > + if (nt->remote_ip.family == AF_INET6) > > err = netcons_take_ipv6(nt, ndev); > > - if (err) > > - goto put; > > - } > > + else > > + err = netcons_take_ipv4(nt, ndev); > > + if (err) > > + goto put; > > nice, that is much clearer. > > > ip_overwritten = true; > > } > > > > @@ -716,22 +694,22 @@ static void netconsole_print_banner(struct netconsole_target *nt) > > struct netpoll *np = &nt->np; > > > > np_info(np, "local port %d\n", nt->local_port); > > - if (nt->ipv6) > > + if (nt->local_ip.family == AF_INET6) > > np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); > > else > > np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); > > Any chance it can be UNSPEC? Yes. Since this is a refactoring patch, I didn't want to change behavior here. So I kept the original behavior which is print "0.0.0.0". I was planning to send a separate patch set to change this: a) Print an empty string if unset (AF_UNSPEC). b) Allow the user to write an empty string to local_ip or remote_ip to denote unset. This can be useful in case the user is reconfiguring the target and wants to make use of the local_ip automatic discovery logic from netconsole. > > > np_info(np, "interface name '%s'\n", np->dev_name); > > np_info(np, "local ethernet address '%pM'\n", np->dev_mac); > > np_info(np, "remote port %d\n", nt->remote_port); > > - if (nt->ipv6) > > + if (nt->remote_ip.family == AF_INET6) > > np_info(np, "remote IPv6 address %pI6c\n", &nt->remote_ip.in6); > > else > > Same question > > > @@ -755,7 +733,7 @@ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) > > in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && > > (!end || *end == 0 || *end == '\n')) { > > addr->family = AF_INET6; > > Why not setting family for for IPV4? In > > if (in4_pton(str, len, (void *)addr, -1, &end) > 0 && > (!end || *end == 0 || *end == '\n')) > return 0; I did that in the previous patch. Here we are just changing the return code convention for netpoll_parse_ip_addr(). We no longer need to return the address family because it is now baked into inet_address. So instead of returning 0 for ipv4, 1 for ipv6, and -1 for failure, we just return -1 for failure and 0 for success. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag 2026-08-07 12:00 ` Gustavo Luiz Duarte @ 2026-08-07 13:11 ` Breno Leitao 0 siblings, 0 replies; 12+ messages in thread From: Breno Leitao @ 2026-08-07 13:11 UTC (permalink / raw) To: Gustavo Luiz Duarte Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Fri, Aug 07, 2026 at 01:00:51PM +0100, Gustavo Luiz Duarte wrote: > On Thu, Aug 6, 2026 at 4:55 PM Breno Leitao <leitao@debian.org> wrote: > > > > On Wed, Aug 05, 2026 at 10:33:02PM +0100, Gustavo Luiz Duarte wrote: > > > Now that we have the address family in inet_addr, use that and remove > > > nt->ipv6. > > > > > > We no longer need netcons_local_ip_unset() to check that all bytes are > > > zeroes, as that is now denoted by (family == AF_UNSPEC). > > > > > > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> > > > --- > > > drivers/net/netconsole.c | 82 ++++++++++++++---------------------------------- > > > 1 file changed, 23 insertions(+), 59 deletions(-) > > > > > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > > > index d615a9256787..070bae7b4fd7 100644 > > > --- a/drivers/net/netconsole.c > > > +++ b/drivers/net/netconsole.c > > > @@ -181,7 +181,6 @@ enum target_state { > > > * local_mac (read-only) > > > * @local_ip: Source IP address of the target (read-write). > > > * @remote_ip: Destination IP address of the target (read-write). > > > - * @ipv6: Whether the target addresses are IPv6 (read-write). > > > * @local_port: Source UDP port of the target (read-write). > > > * @remote_port: Destination UDP port of the target (read-write). > > > * @remote_mac: Destination ethernet address of the target (read-write). > > > @@ -213,7 +212,6 @@ struct netconsole_target { > > > bool release; > > > struct netpoll np; > > > struct inet_addr local_ip, remote_ip; > > > - bool ipv6; > > > u16 local_port, remote_port; > > > u8 remote_mac[ETH_ALEN]; > > > /* protected by target_list_lock; +1 gives scnprintf() room for its > > > @@ -463,23 +461,6 @@ static int netcons_take_ipv4(struct netconsole_target *nt, > > > return 0; > > > } > > > > > > -/* > > > - * Test whether the caller left nt->local_ip unset, so that > > > - * netcons_netpoll_setup() should auto-populate it from the egress device. > > > - * > > > - * nt->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6), > > > - * so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2, > > > - * IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm — > > > - * doing so would misclassify a caller-supplied address as unset and > > > - * silently overwrite it with whatever address the device exposes. > > > - */ > > > -static bool netcons_local_ip_unset(const struct netconsole_target *nt) > > > -{ > > > - if (nt->ipv6) > > > - return ipv6_addr_any(&nt->local_ip.in6); > > > - return !nt->local_ip.ip; > > > -} > > > - > > > static int netcons_netpoll_setup(struct netconsole_target *nt) > > > { > > > struct net *net = current->nsproxy->net_ns; > > > @@ -525,16 +506,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) > > > rtnl_lock(); > > > } > > > > > > - if (netcons_local_ip_unset(nt)) { > > > - if (!nt->ipv6) { > > > - err = netcons_take_ipv4(nt, ndev); > > > - if (err) > > > - goto put; > > > - } else { > > > + if (nt->local_ip.family == AF_UNSPEC) { > > > + if (nt->remote_ip.family == AF_INET6) > > > err = netcons_take_ipv6(nt, ndev); > > > - if (err) > > > - goto put; > > > - } > > > + else > > > + err = netcons_take_ipv4(nt, ndev); > > > + if (err) > > > + goto put; > > > > nice, that is much clearer. > > > > > ip_overwritten = true; > > > } > > > > > > @@ -716,22 +694,22 @@ static void netconsole_print_banner(struct netconsole_target *nt) > > > struct netpoll *np = &nt->np; > > > > > > np_info(np, "local port %d\n", nt->local_port); > > > - if (nt->ipv6) > > > + if (nt->local_ip.family == AF_INET6) > > > np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); > > > else > > > np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); > > > > Any chance it can be UNSPEC? > > Yes. Since this is a refactoring patch, I didn't want to change behavior here. > So I kept the original behavior which is print "0.0.0.0". > > I was planning to send a separate patch set to change this: > a) Print an empty string if unset (AF_UNSPEC). Please add it to this patchset. > b) Allow the user to write an empty string to local_ip or remote_ip to > denote unset. > > This can be useful in case the user is reconfiguring the target and > wants to make use of the local_ip automatic discovery logic from > netconsole. Cool, this could come later. > > > @@ -755,7 +733,7 @@ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) > > > in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && > > > (!end || *end == 0 || *end == '\n')) { > > > addr->family = AF_INET6; > > > > Why not setting family for for IPV4? In > > > > if (in4_pton(str, len, (void *)addr, -1, &end) > 0 && > > (!end || *end == 0 || *end == '\n')) > > return 0; > > I did that in the previous patch. Here we are just changing the return code > convention for netpoll_parse_ip_addr(). We no longer need to return the address > family because it is now baked into inet_address. So instead of returning 0 for > ipv4, 1 for ipv6, and -1 for failure, we just return -1 for failure and 0 for > success. Would it make sense to change it here, together and close to the detection? ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 3/4] netconsole: reject enabling a target with no remote IP address 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 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr 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-05 21:33 ` Gustavo Luiz Duarte 2026-08-06 15:58 ` Breno Leitao 2026-08-05 21:33 ` [PATCH net-next 4/4] netconsole: reject a target mixing IPv4 and IPv6 addresses Gustavo Luiz Duarte 3 siblings, 1 reply; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-05 21:33 UTC (permalink / raw) To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman Cc: netdev, linux-kernel, Gustavo Luiz Duarte The command-line path already requires a remote address, but if a user creates a dynamic target and enables it without setting a remote address, we currently try sending netconsole traffic to "0.0.0.0". Refuse to enable a target if the remote address is unset. Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> --- drivers/net/netconsole.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 070bae7b4fd7..a41b0a5ce64f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -471,6 +471,12 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) int err; rtnl_lock(); + if (nt->remote_ip.family == AF_UNSPEC) { + np_err(np, "remote IP address not configured, aborting\n"); + err = -EDESTADDRREQ; + goto unlock; + } + if (np->dev_name[0]) ndev = __dev_get_by_name(net, np->dev_name); else if (is_valid_ether_addr(np->dev_mac)) -- 2.55.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 3/4] netconsole: reject enabling a target with no remote IP address 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 0 siblings, 1 reply; 12+ messages in thread From: Breno Leitao @ 2026-08-06 15:58 UTC (permalink / raw) To: Gustavo Luiz Duarte Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Wed, Aug 05, 2026 at 10:33:03PM +0100, Gustavo Luiz Duarte wrote: > The command-line path already requires a remote address, but if a user > creates a dynamic target and enables it without setting a remote > address, we currently try sending netconsole traffic to "0.0.0.0". > > Refuse to enable a target if the remote address is unset. > > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> > --- > drivers/net/netconsole.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > index 070bae7b4fd7..a41b0a5ce64f 100644 > --- a/drivers/net/netconsole.c > +++ b/drivers/net/netconsole.c > @@ -471,6 +471,12 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) > int err; > > rtnl_lock(); > + if (nt->remote_ip.family == AF_UNSPEC) { > + np_err(np, "remote IP address not configured, aborting\n"); > + err = -EDESTADDRREQ; > + goto unlock; > + } Why not doing it before the rtnl lock? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 3/4] netconsole: reject enabling a target with no remote IP address 2026-08-06 15:58 ` Breno Leitao @ 2026-08-07 12:11 ` Gustavo Luiz Duarte 0 siblings, 0 replies; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-07 12:11 UTC (permalink / raw) To: Breno Leitao Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel On Thu, Aug 6, 2026 at 4:58 PM Breno Leitao <leitao@debian.org> wrote: > > On Wed, Aug 05, 2026 at 10:33:03PM +0100, Gustavo Luiz Duarte wrote: > > The command-line path already requires a remote address, but if a user > > creates a dynamic target and enables it without setting a remote > > address, we currently try sending netconsole traffic to "0.0.0.0". > > > > Refuse to enable a target if the remote address is unset. > > > > Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> > > --- > > drivers/net/netconsole.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > > index 070bae7b4fd7..a41b0a5ce64f 100644 > > --- a/drivers/net/netconsole.c > > +++ b/drivers/net/netconsole.c > > @@ -471,6 +471,12 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) > > int err; > > > > rtnl_lock(); > > + if (nt->remote_ip.family == AF_UNSPEC) { > > + np_err(np, "remote IP address not configured, aborting\n"); > > + err = -EDESTADDRREQ; > > + goto unlock; > > + } > > Why not doing it before the rtnl lock? Oh, you are right, there is no reason for holding the lock here. Thanks for pointing it out. I will fix it in v2. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 4/4] netconsole: reject a target mixing IPv4 and IPv6 addresses 2026-08-05 21:33 [PATCH net-next 0/4] netconsole: validate a target's IP address configuration Gustavo Luiz Duarte ` (2 preceding siblings ...) 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-05 21:33 ` Gustavo Luiz Duarte 3 siblings, 0 replies; 12+ messages in thread From: Gustavo Luiz Duarte @ 2026-08-05 21:33 UTC (permalink / raw) To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman Cc: netdev, linux-kernel, Gustavo Luiz Duarte The local_ip and remote_ip configfs attributes are written independently and nothing stops a user from mixing ipv4 and ipv6. This leads to an ipv4 address being zero-extended into an ipv6 header or an ipv6 address being truncated to its first 4 bytes for an ipv4 header. The command-line parser already refuses such a mismatch. This adds a similar check when a dynamic target is being enabled. Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com> --- drivers/net/netconsole.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index a41b0a5ce64f..69621705d68d 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -477,6 +477,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) goto unlock; } + if (nt->local_ip.family != AF_UNSPEC && + nt->local_ip.family != nt->remote_ip.family) { + np_err(np, "local and remote IP address families differ, aborting\n"); + err = -EINVAL; + goto unlock; + } + if (np->dev_name[0]) ndev = __dev_get_by_name(net, np->dev_name); else if (is_valid_ether_addr(np->dev_mac)) -- 2.55.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-08-07 13:12 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH net-next 1/4] netconsole: add an address family to struct inet_addr Gustavo Luiz Duarte 2026-08-06 15:49 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox