[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251105161450.1730216-14-skorodumov.dmitry@huawei.com>
Date: Wed, 5 Nov 2025 19:14:49 +0300
From: Dmitry Skorodumov <skorodumov.dmitry@...wei.com>
To: <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC: <andrey.bokhanko@...wei.com>, Dmitry Skorodumov
<skorodumov.dmitry@...wei.com>, Andrew Lunn <andrew+netdev@...n.ch>, "David
S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub
Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next 13/14] ipvlan: common code to handle ipv6/ipv4 address events
Both IPv4 and IPv6 addr-event functions are very similar. Refactor
to use common funcitons.
Signed-off-by: Dmitry Skorodumov <skorodumov.dmitry@...wei.com>
---
drivers/net/ipvlan/ipvlan_main.c | 117 ++++++++++---------------------
1 file changed, 37 insertions(+), 80 deletions(-)
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index 5b4bfd00544b..bc6db32f59bf 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -1195,33 +1195,39 @@ static int ipvlan_addr_validator_event(struct net_device *dev,
return NOTIFY_OK;
}
-#if IS_ENABLED(CONFIG_IPV6)
-static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
+static int ipvlan_add_addr_event(struct ipvl_dev *ipvlan, const void *iaddr,
+ bool is_v6)
{
int ret = -EINVAL;
spin_lock_bh(&ipvlan->port->addrs_lock);
- if (ipvlan_addr_busy(ipvlan->port, ip6_addr, true))
- netif_err(ipvlan, ifup, ipvlan->dev,
- "Failed to add IPv6=%pI6c addr for %s intf\n",
- ip6_addr, ipvlan->dev->name);
- else
- ret = ipvlan_add_addr(ipvlan, ip6_addr, true, NULL);
+ if (ipvlan_addr_busy(ipvlan->port, iaddr, is_v6)) {
+ if (is_v6) {
+ netif_err(ipvlan, ifup, ipvlan->dev,
+ "Failed to add IPv6=%pI6c on %s intf.\n",
+ iaddr, ipvlan->dev->name);
+ } else {
+ netif_err(ipvlan, ifup, ipvlan->dev,
+ "Failed to add IPv4=%pI4 on %s intf.\n",
+ iaddr, ipvlan->dev->name);
+ }
+ } else {
+ ret = ipvlan_add_addr(ipvlan, iaddr, is_v6, NULL);
+ }
spin_unlock_bh(&ipvlan->port->addrs_lock);
return ret;
}
-static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
+static void ipvlan_del_addr_event(struct ipvl_dev *ipvlan, const void *iaddr,
+ bool is_v6)
{
- return ipvlan_del_addr(ipvlan, ip6_addr, true);
+ return ipvlan_del_addr(ipvlan, iaddr, is_v6);
}
-static int ipvlan_addr6_event(struct notifier_block *unused,
- unsigned long event, void *ptr)
+static int ipvlan_addr_event(struct net_device *dev, unsigned long event,
+ const void *iaddr, bool is_v6)
{
- struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
- struct net_device *dev = (struct net_device *)if6->idev->dev;
- struct ipvl_dev *ipvlan = netdev_priv(dev);
+ struct ipvl_dev *ipvlan;
if (netif_is_ipvlan_port(dev)) {
struct ipvl_port *port = ipvlan_port_get_rcu(dev);
@@ -1231,11 +1237,9 @@ static int ipvlan_addr6_event(struct notifier_block *unused,
switch (event) {
case NETDEV_UP:
- return ipvlan_port_add_addr_event(port, &if6->addr,
- true);
+ return ipvlan_port_add_addr_event(port, iaddr, is_v6);
case NETDEV_DOWN:
- return ipvlan_port_del_addr_event(port, &if6->addr,
- true);
+ return ipvlan_port_del_addr_event(port, iaddr, is_v6);
default:
return NOTIFY_OK;
}
@@ -1244,20 +1248,31 @@ static int ipvlan_addr6_event(struct notifier_block *unused,
if (!ipvlan_is_valid_dev(dev))
return NOTIFY_DONE;
+ ipvlan = netdev_priv(dev);
switch (event) {
case NETDEV_UP:
- if (ipvlan_add_addr6(ipvlan, &if6->addr))
+ if (ipvlan_add_addr_event(ipvlan, iaddr, is_v6))
return NOTIFY_BAD;
break;
case NETDEV_DOWN:
- ipvlan_del_addr6(ipvlan, &if6->addr);
+ ipvlan_del_addr_event(ipvlan, iaddr, is_v6);
break;
}
return NOTIFY_OK;
}
+#if IS_ENABLED(CONFIG_IPV6)
+static int ipvlan_addr6_event(struct notifier_block *unused,
+ unsigned long event, void *ptr)
+{
+ struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
+ struct net_device *dev = (struct net_device *)if6->idev->dev;
+
+ return ipvlan_addr_event(dev, event, &if6->addr, true);
+}
+
static int ipvlan_addr6_validator_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
@@ -1269,71 +1284,13 @@ static int ipvlan_addr6_validator_event(struct notifier_block *unused,
}
#endif
-static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
-{
- int ret = -EINVAL;
-
- spin_lock_bh(&ipvlan->port->addrs_lock);
- if (ipvlan_addr_busy(ipvlan->port, ip4_addr, false))
- netif_err(ipvlan, ifup, ipvlan->dev,
- "Failed to add IPv4=%pI4 on %s intf.\n",
- ip4_addr, ipvlan->dev->name);
- else
- ret = ipvlan_add_addr(ipvlan, ip4_addr, false, NULL);
- spin_unlock_bh(&ipvlan->port->addrs_lock);
- return ret;
-}
-
-static void ipvlan_del_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
-{
- return ipvlan_del_addr(ipvlan, ip4_addr, false);
-}
-
static int ipvlan_addr4_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct in_ifaddr *if4 = (struct in_ifaddr *)ptr;
struct net_device *dev = (struct net_device *)if4->ifa_dev->dev;
- struct ipvl_dev *ipvlan = netdev_priv(dev);
- struct in_addr ip4_addr;
-
- if (netif_is_ipvlan_port(dev)) {
- struct ipvl_port *port = ipvlan_port_get_rcu(dev);
-
- if (!ipvlan_is_macnat(port))
- return NOTIFY_DONE;
-
- switch (event) {
- case NETDEV_UP:
- return ipvlan_port_add_addr_event(port,
- &if4->ifa_address,
- false);
- case NETDEV_DOWN:
- return ipvlan_port_del_addr_event(port,
- &if4->ifa_address,
- false);
- default:
- return NOTIFY_OK;
- }
- }
-
- if (!ipvlan_is_valid_dev(dev))
- return NOTIFY_DONE;
- switch (event) {
- case NETDEV_UP:
- ip4_addr.s_addr = if4->ifa_address;
- if (ipvlan_add_addr4(ipvlan, &ip4_addr))
- return NOTIFY_BAD;
- break;
-
- case NETDEV_DOWN:
- ip4_addr.s_addr = if4->ifa_address;
- ipvlan_del_addr4(ipvlan, &ip4_addr);
- break;
- }
-
- return NOTIFY_OK;
+ return ipvlan_addr_event(dev, event, &if4->ifa_address, false);
}
static int ipvlan_addr4_validator_event(struct notifier_block *unused,
--
2.25.1
Powered by blists - more mailing lists