Skip to content

Commit f7fce98

Browse files
q2venkuba-moo
authored andcommitted
ipv6: Pass dev to inet6_addr_add().
inet6_addr_add() is called from inet6_rtm_newaddr() and addrconf_add_ifaddr(). inet6_addr_add() looks up dev by __dev_get_by_index(), but it's already done in inet6_rtm_newaddr(). Let's move the 2nd lookup to addrconf_add_ifaddr() and pass dev to inet6_addr_add(). Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250115080608.28127-8-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 832128c commit f7fce98

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

net/ipv6/addrconf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,13 +3007,12 @@ static int ipv6_mc_config(struct sock *sk, bool join,
30073007
/*
30083008
* Manual configuration of address on an interface
30093009
*/
3010-
static int inet6_addr_add(struct net *net, int ifindex,
3010+
static int inet6_addr_add(struct net *net, struct net_device *dev,
30113011
struct ifa6_config *cfg,
30123012
struct netlink_ext_ack *extack)
30133013
{
30143014
struct inet6_ifaddr *ifp;
30153015
struct inet6_dev *idev;
3016-
struct net_device *dev;
30173016
unsigned long timeout;
30183017
clock_t expires;
30193018
u32 flags;
@@ -3036,10 +3035,6 @@ static int inet6_addr_add(struct net *net, int ifindex,
30363035
return -EINVAL;
30373036
}
30383037

3039-
dev = __dev_get_by_index(net, ifindex);
3040-
if (!dev)
3041-
return -ENODEV;
3042-
30433038
idev = addrconf_add_dev(dev);
30443039
if (IS_ERR(idev)) {
30453040
NL_SET_ERR_MSG_MOD(extack, "IPv6 is disabled on this device");
@@ -3048,7 +3043,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
30483043

30493044
if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) {
30503045
int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk,
3051-
true, cfg->pfx, ifindex);
3046+
true, cfg->pfx, dev->ifindex);
30523047

30533048
if (ret < 0) {
30543049
NL_SET_ERR_MSG_MOD(extack, "Multicast auto join failed");
@@ -3103,7 +3098,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
31033098
return 0;
31043099
} else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) {
31053100
ipv6_mc_config(net->ipv6.mc_autojoin_sk, false,
3106-
cfg->pfx, ifindex);
3101+
cfg->pfx, dev->ifindex);
31073102
}
31083103

31093104
return PTR_ERR(ifp);
@@ -3169,6 +3164,7 @@ int addrconf_add_ifaddr(struct net *net, void __user *arg)
31693164
.preferred_lft = INFINITY_LIFE_TIME,
31703165
.valid_lft = INFINITY_LIFE_TIME,
31713166
};
3167+
struct net_device *dev;
31723168
struct in6_ifreq ireq;
31733169
int err;
31743170

@@ -3182,7 +3178,11 @@ int addrconf_add_ifaddr(struct net *net, void __user *arg)
31823178
cfg.plen = ireq.ifr6_prefixlen;
31833179

31843180
rtnl_net_lock(net);
3185-
err = inet6_addr_add(net, ireq.ifr6_ifindex, &cfg, NULL);
3181+
dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
3182+
if (dev)
3183+
err = inet6_addr_add(net, dev, &cfg, NULL);
3184+
else
3185+
err = -ENODEV;
31863186
rtnl_net_unlock(net);
31873187
return err;
31883188
}
@@ -5064,7 +5064,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
50645064
* It would be best to check for !NLM_F_CREATE here but
50655065
* userspace already relies on not having to provide this.
50665066
*/
5067-
return inet6_addr_add(net, ifm->ifa_index, &cfg, extack);
5067+
return inet6_addr_add(net, dev, &cfg, extack);
50685068
}
50695069

50705070
if (nlh->nlmsg_flags & NLM_F_EXCL ||

0 commit comments

Comments
 (0)