The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Gustavo Luiz Duarte <gustavold@gmail.com>
Cc: 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>,
	 netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 2/4] netconsole: use the address family instead of the ipv6 flag
Date: Thu, 6 Aug 2026 08:55:51 -0700	[thread overview]
Message-ID: <anSte7-WkTYU4MnC@gmail.com> (raw)
In-Reply-To: <20260805-netcons_ipv6-v1-2-170a35b92da1@gmail.com>

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;

  reply	other threads:[~2026-08-06 15:56 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 ` [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 [this message]
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=anSte7-WkTYU4MnC@gmail.com \
    --to=leitao@debian.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavold@gmail.com \
    --cc=horms@kernel.org \
    --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