Commit 8ea71e23 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'ip-random-cleanup-for-devinet-c'

Kuniyuki Iwashima says:

====================
ip: Random cleanup for devinet.c

patch 1 ~ 3 remove defensive !ifa->ifa_dev tests.
patch 4 & 5 deduplicate common code.
====================

Link: https://patch.msgid.link/20240809235406.50187-1-kuniyu@amazon.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 7cb43579 de67763c
...@@ -3185,8 +3185,7 @@ netxen_list_config_ip(struct netxen_adapter *adapter, ...@@ -3185,8 +3185,7 @@ netxen_list_config_ip(struct netxen_adapter *adapter,
struct list_head *head; struct list_head *head;
bool ret = false; bool ret = false;
dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; dev = ifa->ifa_dev->dev;
if (dev == NULL) if (dev == NULL)
goto out; goto out;
...@@ -3379,7 +3378,7 @@ netxen_inetaddr_event(struct notifier_block *this, ...@@ -3379,7 +3378,7 @@ netxen_inetaddr_event(struct notifier_block *this,
struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
unsigned long ip_event; unsigned long ip_event;
dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; dev = ifa->ifa_dev->dev;
ip_event = (event == NETDEV_UP) ? NX_IP_UP : NX_IP_DOWN; ip_event = (event == NETDEV_UP) ? NX_IP_UP : NX_IP_DOWN;
recheck: recheck:
if (dev == NULL) if (dev == NULL)
......
...@@ -4146,7 +4146,7 @@ qlcnic_inetaddr_event(struct notifier_block *this, ...@@ -4146,7 +4146,7 @@ qlcnic_inetaddr_event(struct notifier_block *this,
struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; dev = ifa->ifa_dev->dev;
recheck: recheck:
if (dev == NULL) if (dev == NULL)
......
...@@ -187,10 +187,12 @@ static inline int addrconf_ifid_eui48(u8 *eui, struct net_device *dev) ...@@ -187,10 +187,12 @@ static inline int addrconf_ifid_eui48(u8 *eui, struct net_device *dev)
return 0; return 0;
} }
#define INFINITY_LIFE_TIME 0xFFFFFFFF
static inline unsigned long addrconf_timeout_fixup(u32 timeout, static inline unsigned long addrconf_timeout_fixup(u32 timeout,
unsigned int unit) unsigned int unit)
{ {
if (timeout == 0xffffffff) if (timeout == INFINITY_LIFE_TIME)
return ~0UL; return ~0UL;
/* /*
......
...@@ -216,17 +216,27 @@ static void devinet_sysctl_unregister(struct in_device *idev) ...@@ -216,17 +216,27 @@ static void devinet_sysctl_unregister(struct in_device *idev)
/* Locks all the inet devices. */ /* Locks all the inet devices. */
static struct in_ifaddr *inet_alloc_ifa(void) static struct in_ifaddr *inet_alloc_ifa(struct in_device *in_dev)
{ {
return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL_ACCOUNT); struct in_ifaddr *ifa;
ifa = kzalloc(sizeof(*ifa), GFP_KERNEL_ACCOUNT);
if (!ifa)
return NULL;
in_dev_hold(in_dev);
ifa->ifa_dev = in_dev;
INIT_HLIST_NODE(&ifa->hash);
return ifa;
} }
static void inet_rcu_free_ifa(struct rcu_head *head) static void inet_rcu_free_ifa(struct rcu_head *head)
{ {
struct in_ifaddr *ifa = container_of(head, struct in_ifaddr, rcu_head); struct in_ifaddr *ifa = container_of(head, struct in_ifaddr, rcu_head);
if (ifa->ifa_dev) in_dev_put(ifa->ifa_dev);
in_dev_put(ifa->ifa_dev);
kfree(ifa); kfree(ifa);
} }
...@@ -574,17 +584,9 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa) ...@@ -574,17 +584,9 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
ASSERT_RTNL(); ASSERT_RTNL();
if (!in_dev) {
inet_free_ifa(ifa);
return -ENOBUFS;
}
ipv4_devconf_setall(in_dev); ipv4_devconf_setall(in_dev);
neigh_parms_data_state_setall(in_dev->arp_parms); neigh_parms_data_state_setall(in_dev->arp_parms);
if (ifa->ifa_dev != in_dev) {
WARN_ON(ifa->ifa_dev);
in_dev_hold(in_dev);
ifa->ifa_dev = in_dev;
}
if (ipv4_is_loopback(ifa->ifa_local)) if (ipv4_is_loopback(ifa->ifa_local))
ifa->ifa_scope = RT_SCOPE_HOST; ifa->ifa_scope = RT_SCOPE_HOST;
return inet_insert_ifa(ifa); return inet_insert_ifa(ifa);
...@@ -701,8 +703,6 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -701,8 +703,6 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
return err; return err;
} }
#define INFINITY_LIFE_TIME 0xFFFFFFFF
static void check_lifetime(struct work_struct *work) static void check_lifetime(struct work_struct *work)
{ {
unsigned long now, next, next_sec, next_sched; unsigned long now, next, next_sec, next_sched;
...@@ -875,7 +875,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, ...@@ -875,7 +875,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
if (!in_dev) if (!in_dev)
goto errout; goto errout;
ifa = inet_alloc_ifa(); ifa = inet_alloc_ifa(in_dev);
if (!ifa) if (!ifa)
/* /*
* A potential indev allocation can be left alive, it stays * A potential indev allocation can be left alive, it stays
...@@ -885,19 +885,15 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, ...@@ -885,19 +885,15 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
ipv4_devconf_setall(in_dev); ipv4_devconf_setall(in_dev);
neigh_parms_data_state_setall(in_dev->arp_parms); neigh_parms_data_state_setall(in_dev->arp_parms);
in_dev_hold(in_dev);
if (!tb[IFA_ADDRESS]) if (!tb[IFA_ADDRESS])
tb[IFA_ADDRESS] = tb[IFA_LOCAL]; tb[IFA_ADDRESS] = tb[IFA_LOCAL];
INIT_HLIST_NODE(&ifa->hash);
ifa->ifa_prefixlen = ifm->ifa_prefixlen; ifa->ifa_prefixlen = ifm->ifa_prefixlen;
ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen); ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen);
ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) :
ifm->ifa_flags; ifm->ifa_flags;
ifa->ifa_scope = ifm->ifa_scope; ifa->ifa_scope = ifm->ifa_scope;
ifa->ifa_dev = in_dev;
ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]); ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]);
ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]); ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]);
...@@ -1184,10 +1180,12 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr) ...@@ -1184,10 +1180,12 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
if (!ifa) { if (!ifa) {
ret = -ENOBUFS; ret = -ENOBUFS;
ifa = inet_alloc_ifa(); if (!in_dev)
break;
ifa = inet_alloc_ifa(in_dev);
if (!ifa) if (!ifa)
break; break;
INIT_HLIST_NODE(&ifa->hash);
if (colon) if (colon)
memcpy(ifa->ifa_label, ifr->ifr_name, IFNAMSIZ); memcpy(ifa->ifa_label, ifr->ifr_name, IFNAMSIZ);
else else
...@@ -1586,16 +1584,13 @@ static int inetdev_event(struct notifier_block *this, unsigned long event, ...@@ -1586,16 +1584,13 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
if (!inetdev_valid_mtu(dev->mtu)) if (!inetdev_valid_mtu(dev->mtu))
break; break;
if (dev->flags & IFF_LOOPBACK) { if (dev->flags & IFF_LOOPBACK) {
struct in_ifaddr *ifa = inet_alloc_ifa(); struct in_ifaddr *ifa = inet_alloc_ifa(in_dev);
if (ifa) { if (ifa) {
INIT_HLIST_NODE(&ifa->hash);
ifa->ifa_local = ifa->ifa_local =
ifa->ifa_address = htonl(INADDR_LOOPBACK); ifa->ifa_address = htonl(INADDR_LOOPBACK);
ifa->ifa_prefixlen = 8; ifa->ifa_prefixlen = 8;
ifa->ifa_mask = inet_make_mask(8); ifa->ifa_mask = inet_make_mask(8);
in_dev_hold(in_dev);
ifa->ifa_dev = in_dev;
ifa->ifa_scope = RT_SCOPE_HOST; ifa->ifa_scope = RT_SCOPE_HOST;
memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
set_ifa_lifetime(ifa, INFINITY_LIFE_TIME, set_ifa_lifetime(ifa, INFINITY_LIFE_TIME,
......
...@@ -92,8 +92,6 @@ ...@@ -92,8 +92,6 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/ioam6.h> #include <linux/ioam6.h>
#define INFINITY_LIFE_TIME 0xFFFFFFFF
#define IPV6_MAX_STRLEN \ #define IPV6_MAX_STRLEN \
sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment