Skip to content

Commit cc56e24

Browse files
CKI Backport BotHangbin Liu
authored andcommitted
ipv6: anycast: Unify two error paths in ipv6_sock_ac_join().
JIRA: https://issues.redhat.com/browse/RHEL-115325 commit 976fa9b Author: Kuniyuki Iwashima <kuniyu@google.com> Date: Wed Jul 2 16:01:30 2025 -0700 ipv6: anycast: Unify two error paths in ipv6_sock_ac_join(). The next patch will replace __dev_get_by_index() and __dev_get_by_flags() to RCU + refcount version. Then, we will need to call dev_put() in some error paths. Let's unify two error paths to make the next patch cleaner. Note that we add READ_ONCE() for net->ipv6.devconf_all->forwarding and idev->conf.forwarding as we will drop RTNL that protects them. Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20250702230210.3115355-14-kuni1840@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 3d1ba63 commit cc56e24

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

net/ipv6/anycast.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ static u32 inet6_acaddr_hash(const struct net *net,
6767
int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
6868
{
6969
struct ipv6_pinfo *np = inet6_sk(sk);
70+
struct ipv6_ac_socklist *pac = NULL;
71+
struct net *net = sock_net(sk);
7072
struct net_device *dev = NULL;
7173
struct inet6_dev *idev;
72-
struct ipv6_ac_socklist *pac;
73-
struct net *net = sock_net(sk);
74-
int ishost = !net->ipv6.devconf_all->forwarding;
75-
int err = 0;
74+
int err = 0, ishost;
7675

7776
ASSERT_RTNL();
7877

@@ -84,15 +83,22 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
8483
if (ifindex)
8584
dev = __dev_get_by_index(net, ifindex);
8685

87-
if (ipv6_chk_addr_and_flags(net, addr, dev, true, 0, IFA_F_TENTATIVE))
88-
return -EINVAL;
86+
if (ipv6_chk_addr_and_flags(net, addr, dev, true, 0, IFA_F_TENTATIVE)) {
87+
err = -EINVAL;
88+
goto error;
89+
}
8990

9091
pac = sock_kmalloc(sk, sizeof(struct ipv6_ac_socklist), GFP_KERNEL);
91-
if (!pac)
92-
return -ENOMEM;
92+
if (!pac) {
93+
err = -ENOMEM;
94+
goto error;
95+
}
96+
9397
pac->acl_next = NULL;
9498
pac->acl_addr = *addr;
9599

100+
ishost = !READ_ONCE(net->ipv6.devconf_all->forwarding);
101+
96102
if (ifindex == 0) {
97103
struct rt6_info *rt;
98104

@@ -123,8 +129,9 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
123129
err = -EADDRNOTAVAIL;
124130
goto error;
125131
}
132+
126133
/* reset ishost, now that we have a specific device */
127-
ishost = !idev->cnf.forwarding;
134+
ishost = !READ_ONCE(idev->cnf.forwarding);
128135

129136
pac->acl_ifindex = dev->ifindex;
130137

0 commit comments

Comments
 (0)