Re: [PATCH net-next 4/9] netconsole: move netpoll_local_ip_unset() as netcons_local_ip_unset()
From: Breno Leitao
Date: Wed Jul 29 2026 - 06:39:44 EST
On Tue, Jul 28, 2026 at 12:49:46AM +0100, Gustavo Luiz Duarte wrote:
> On Fri, Jul 24, 2026 at 4:05 PM Breno Leitao <leitao@xxxxxxxxxx> wrote:
> >
> > Move netpoll_local_ip_unset() from netpoll to netconsole and rename it
> > to netcons_local_ip_unset();
> >
> > The body is otherwise unchanged, only the comment's setup-function
> > reference is updated.
> >
> > Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> > ---
> > drivers/net/netconsole.c | 19 ++++++++++++++++++-
> > include/linux/netpoll.h | 1 -
> > net/core/netpoll.c | 18 ------------------
> > 3 files changed, 18 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > index 3a7a2cafc6276..70f9c5bfb3720 100644
> > --- a/drivers/net/netconsole.c
> > +++ b/drivers/net/netconsole.c
> > @@ -351,6 +351,23 @@ static void netconsole_skb_pool_flush(struct netconsole_target *nt)
> > skb_queue_purge_reason(&nt->skb_pool, SKB_CONSUMED);
> > }
> >
> > +/*
> > + * Test whether the caller left np->local_ip unset, so that
> > + * netcons_netpoll_setup() should auto-populate it from the egress device.
> > + *
> > + * np->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 netpoll *np)
> > +{
> > + if (np->ipv6)
> > + return ipv6_addr_any(&np->local_ip.in6);
> > + return !np->local_ip.ip;
> > +}
>
>
> This whole checking if it is all zeroes in netcons_local_ip_unset()
> looks very cumbersome.
> Perhaps instead of storing 'bool ipv6' we could have something like
> 'u8 family', which would contain AF_INET for ipv4, AF_INET6 for ipv6,
> or AF_UNSPEC if unset.
Agree, an explicit state machine would clarify the three cases: IPv4,
IPv6, or unspecified (with netconsole deriving it from the device).
Now that the helper lives in netconsole, the awkwardness is more visible.
> But that would be another patch separate from this refactoring, so for
> this patch:
Thanks for the review. Would you be interested in pursuing that change
once this lands?