Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv6: mcast: Add ip6_mc_find_idev() helper

Extract the same code logic from __ipv6_sock_mc_join() and
ip6_mc_find_dev(), also add new helper ip6_mc_find_idev() to
reduce redundancy and enhance readability.

No functional changes intended.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Reviewed-by: Dawid Osuchowski <dawid.osuchowski@linux.intel.com>
Link: https://patch.msgid.link/20250822064051.2991480-1-yuehaibing@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yue Haibing and committed by
Jakub Kicinski
60c481d4 411d7d70

+31 -36
+31 -36
net/ipv6/mcast.c
··· 169 169 return iv > 0 ? iv : 1; 170 170 } 171 171 172 + static struct net_device *ip6_mc_find_dev(struct net *net, 173 + const struct in6_addr *group, 174 + int ifindex) 175 + { 176 + struct net_device *dev = NULL; 177 + struct rt6_info *rt; 178 + 179 + if (ifindex == 0) { 180 + rcu_read_lock(); 181 + rt = rt6_lookup(net, group, NULL, 0, NULL, 0); 182 + if (rt) { 183 + dev = dst_dev(&rt->dst); 184 + dev_hold(dev); 185 + ip6_rt_put(rt); 186 + } 187 + rcu_read_unlock(); 188 + } else { 189 + dev = dev_get_by_index(net, ifindex); 190 + } 191 + 192 + return dev; 193 + } 194 + 172 195 /* 173 196 * socket join on multicast group 174 197 */ ··· 214 191 } 215 192 216 193 mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL); 217 - 218 194 if (!mc_lst) 219 195 return -ENOMEM; 220 196 221 197 mc_lst->next = NULL; 222 198 mc_lst->addr = *addr; 223 199 224 - if (ifindex == 0) { 225 - struct rt6_info *rt; 226 - 227 - rcu_read_lock(); 228 - rt = rt6_lookup(net, addr, NULL, 0, NULL, 0); 229 - if (rt) { 230 - dev = dst_dev(&rt->dst); 231 - dev_hold(dev); 232 - ip6_rt_put(rt); 233 - } 234 - rcu_read_unlock(); 235 - } else { 236 - dev = dev_get_by_index(net, ifindex); 237 - } 238 - 200 + dev = ip6_mc_find_dev(net, addr, ifindex); 239 201 if (!dev) { 240 202 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); 241 203 return -ENODEV; ··· 310 302 } 311 303 EXPORT_SYMBOL(ipv6_sock_mc_drop); 312 304 313 - static struct inet6_dev *ip6_mc_find_dev(struct net *net, 314 - const struct in6_addr *group, 315 - int ifindex) 305 + static struct inet6_dev *ip6_mc_find_idev(struct net *net, 306 + const struct in6_addr *group, 307 + int ifindex) 316 308 { 317 - struct net_device *dev = NULL; 309 + struct net_device *dev; 318 310 struct inet6_dev *idev; 319 311 320 - if (ifindex == 0) { 321 - struct rt6_info *rt; 322 - 323 - rcu_read_lock(); 324 - rt = rt6_lookup(net, group, NULL, 0, NULL, 0); 325 - if (rt) { 326 - dev = dst_dev(&rt->dst); 327 - dev_hold(dev); 328 - ip6_rt_put(rt); 329 - } 330 - rcu_read_unlock(); 331 - } else { 332 - dev = dev_get_by_index(net, ifindex); 333 - } 312 + dev = ip6_mc_find_dev(net, group, ifindex); 334 313 if (!dev) 335 314 return NULL; 336 315 ··· 369 374 if (!ipv6_addr_is_multicast(group)) 370 375 return -EINVAL; 371 376 372 - idev = ip6_mc_find_dev(net, group, pgsr->gsr_interface); 377 + idev = ip6_mc_find_idev(net, group, pgsr->gsr_interface); 373 378 if (!idev) 374 379 return -ENODEV; 375 380 ··· 504 509 gsf->gf_fmode != MCAST_EXCLUDE) 505 510 return -EINVAL; 506 511 507 - idev = ip6_mc_find_dev(net, group, gsf->gf_interface); 512 + idev = ip6_mc_find_idev(net, group, gsf->gf_interface); 508 513 if (!idev) 509 514 return -ENODEV; 510 515