From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EE0A42C4FD for ; Mon, 10 Aug 2026 16:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786380470; cv=none; b=MF4rR+K2cwG0RcLch01ykF7z1OXvoS0YNFU8BRKGiqs86cwNaYHImjzvSfI+7K1uV6Qb2UxXv97Euhe3gJIyo6SCVocy2xcsJEbEV6YwtOxijkyocvOCId3u85qAjIsDEh8vVJIGORMTIikQk4j0oiVtkWdbh88lPqyHFTHiSA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786380470; c=relaxed/simple; bh=cpY+DK8gqI4J4uNkwtOBFgqQE1dbJzW2yuwhWHHyOb4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XXVRmkhDnoBEC9QRCth9uiUREYPp7WUqkPN6BaFC5nenVBFHd2xl4wpfcHD6Ul1P7bVglYHtkJQGvx7fo49lgEhZSxTu6iNCEps7/rGOz3J9xvkg8td+26qW5PkpoR4IO7tNUxihGE4XAxvbiC2ujxhi8oRi75e7r8MZYGFG8VE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YjW9HW1L; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YjW9HW1L" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4731f5ffa74so166606f8f.1 for ; Mon, 10 Aug 2026 09:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786380466; x=1786985266; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bvt91xN9n0oGfvLTCrwPfmjNKYb15JHWKisk1UsqQAA=; b=YjW9HW1LEft1jDnM75Wzlsv76CmT+PIxJI/pHC4iELExYIuqBuoOAYVMBCNzWFKwaF 2L25q53kvywNj1LRfBz+Lvyxon5KD7uj5UzXX+CRA+JRB7DTFVdRQ/mEGp6gxOobs+7l /KmNk/Q9IOH9Hbv9Coire7orl841X/wByrnrLiw7GeT63+0eTPCaBfkbJOBOdAGd485u XS8/MQea4F+mPZlvUcVkKlZtdgXeURvBJH8dbkjTHwrpH1F751q8AdN4NLEdG2/pLeFL 7818nztMpesF7A7v24TM2S7fSaBEGvjqV8YlxXP/lYbulgleQ1c5GXQbiOeQncJOBb3Y oFZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786380466; x=1786985266; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bvt91xN9n0oGfvLTCrwPfmjNKYb15JHWKisk1UsqQAA=; b=L5AU6WH33hMzVOcv1mwLSb3ZvuY2nZFHkEFn+gDAEDwILp6uCmQU/0wNvD1Vz9Bfnw z6waQTfQEy1NOd3t8BqY08CUcWFatk7/44O5ZeSfqm1HYx+f5Rtf+aTKyzH15KlXa8x/ HDZ2szK88iuCBPeYP4gdmgdXixqiSMRs+ZF2sSHJszZwBnnOiNYddiPcV/a4vOUqOY1B RQHQYLGox4E4aVl4ajph6SW/gNKMuetKOJRGT5tHz17w1tfSzipn5AlhWugHMOMVyceJ IUEvrs73zM5qZEHoaidTa8+UJqIrr0H8Mvi30/lMbM9NlM4Uq3/3SmG1uUgFVoZRoftX jkDg== X-Forwarded-Encrypted: i=1; AHgh+RoopKbQYKmpr54uZ9kf/xRadB7EkhI8BM03hGjxbIYqMPPWM+UtfP5rPBzEDAHfhkChpMsP7CVBdCl3XLw=@vger.kernel.org X-Gm-Message-State: AOJu0YwM8HN1CiHBEd8i5oyVL4WlHcQiW6NCoKVuuluZv/SzCU4lzIo0 iUETXRSj7caMTK8iZVsAd/bhZ6pyoNhm7zZYeRURo7httT0GOvtlXSTa X-Gm-Gg: AR+sD12aQJcrGxV3I9ywUeBGpMLRZvJvN9jq2xtmopFmwMRoXJ7AKDONE+e1J/DudYF q4VodmAYA3V+9x7P97JBLL+RCBkXzsYL63HFurH6mpS9x+unSvbSCtw2XlYp40QOr+p+YPr/v6+ cb9RoUG59p3EKxsdd98tHKytrKT7sZy+2h/4xVWzCKzlnbLVi8KqtSaTQQ2WKVFVF8n09/g3/bB SVWdiWDW52QqUMMr1+dYCWgMLIWCdCbsQya4LGeCW3FrELVm6L+2RqZh03b3WyAuvW45H4ElaRK N1uZaqCnA2NStgo2PcXwhGof39ma9JpVAeNVvx7Xx4ZiEv7AuPA353Z6Gzw44xbCUJRofhAg6Z9 nacxxSNizO0J/XKLBAGoITwRrgfZZ5WjzUfKbN53Or10+a7h+jWnzYccc4/V4MC0BPr0bcX2Wb/ RtTCzJ0+l5AHgmnv4CGUD7MyKPHxo7MhHBihHQiKWG1IDNYtJ3W7LZNQ== X-Received: by 2002:a05:600c:3594:b0:495:4126:1e55 with SMTP id 5b1f17b1804b1-4994e7bd084mr293278315e9.2.1786380466115; Mon, 10 Aug 2026 09:47:46 -0700 (PDT) Received: from localhost ([2620:10d:c092:500::7:692b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499740c1f61sm4713355e9.5.2026.08.10.09.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 09:47:45 -0700 (PDT) From: Gustavo Luiz Duarte Date: Mon, 10 Aug 2026 17:47:26 +0100 Subject: [PATCH net-next v2 2/6] netconsole: use the address family instead of the ipv6 flag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260810-netcons_ipv6-v2-2-3d4fc987a90f@gmail.com> References: <20260810-netcons_ipv6-v2-0-3d4fc987a90f@gmail.com> In-Reply-To: <20260810-netcons_ipv6-v2-0-3d4fc987a90f@gmail.com> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Gustavo Luiz Duarte X-Mailer: b4 0.15.2 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 --- 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 94a662c7369a..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` struct. 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