Skip to content

Commit ebeb841

Browse files
leitaogregkh
authored andcommitted
netpoll: extract IPv4 address retrieval into helper function
[ Upstream commit 3699f99 ] Move the IPv4 address retrieval logic from netpoll_setup() into a separate netpoll_take_ipv4() function to improve code organization and readability. This change consolidates the IPv4-specific logic and error handling into a dedicated function while maintaining the same functionality. No functional changes. Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250618-netpoll_ip_ref-v1-2-c2ac00fe558f@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: 3bc179b ("netpoll: fix IPv6 local-address corruption") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ea97750 commit ebeb841

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

net/core/netpoll.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,41 @@ static void netpoll_wait_carrier(struct netpoll *np, struct net_device *ndev,
721721
}
722722
}
723723

724+
/*
725+
* Take the IPv4 from ndev and populate local_ip structure in netpoll
726+
*/
727+
static int netpoll_take_ipv4(struct netpoll *np, struct net_device *ndev)
728+
{
729+
char buf[MAC_ADDR_STR_LEN + 1];
730+
const struct in_ifaddr *ifa;
731+
struct in_device *in_dev;
732+
733+
in_dev = __in_dev_get_rtnl(ndev);
734+
if (!in_dev) {
735+
np_err(np, "no IP address for %s, aborting\n",
736+
egress_dev(np, buf));
737+
return -EDESTADDRREQ;
738+
}
739+
740+
ifa = rtnl_dereference(in_dev->ifa_list);
741+
if (!ifa) {
742+
np_err(np, "no IP address for %s, aborting\n",
743+
egress_dev(np, buf));
744+
return -EDESTADDRREQ;
745+
}
746+
747+
np->local_ip.ip = ifa->ifa_local;
748+
np_info(np, "local IP %pI4\n", &np->local_ip.ip);
749+
750+
return 0;
751+
}
752+
724753
int netpoll_setup(struct netpoll *np)
725754
{
726755
struct net *net = current->nsproxy->net_ns;
727756
char buf[MAC_ADDR_STR_LEN + 1];
728757
struct net_device *ndev = NULL;
729758
bool ip_overwritten = false;
730-
struct in_device *in_dev;
731759
int err;
732760

733761
rtnl_lock();
@@ -767,24 +795,10 @@ int netpoll_setup(struct netpoll *np)
767795

768796
if (!np->local_ip.ip) {
769797
if (!np->ipv6) {
770-
const struct in_ifaddr *ifa;
771-
772-
in_dev = __in_dev_get_rtnl(ndev);
773-
if (!in_dev)
774-
goto put_noaddr;
775-
776-
ifa = rtnl_dereference(in_dev->ifa_list);
777-
if (!ifa) {
778-
put_noaddr:
779-
np_err(np, "no IP address for %s, aborting\n",
780-
egress_dev(np, buf));
781-
err = -EDESTADDRREQ;
798+
err = netpoll_take_ipv4(np, ndev);
799+
if (err)
782800
goto put;
783-
}
784-
785-
np->local_ip.ip = ifa->ifa_local;
786801
ip_overwritten = true;
787-
np_info(np, "local IP %pI4\n", &np->local_ip.ip);
788802
} else {
789803
#if IS_ENABLED(CONFIG_IPV6)
790804
struct inet6_dev *idev;

0 commit comments

Comments
 (0)