Skip to content

Commit 1ca73e3

Browse files
Richard Alpedavem330
authored andcommitted
tipc: refactor multicast ip check
Add a function to check if a tipc UDP media address is a multicast address or not. This is a purely cosmetic change. Signed-off-by: Richard Alpe <richard.alpe@ericsson.com> Reviewed-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ce984da commit 1ca73e3

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

net/tipc/udp_media.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,27 @@ struct udp_bearer {
8484
struct work_struct work;
8585
};
8686

87+
static int tipc_udp_is_mcast_addr(struct udp_media_addr *addr)
88+
{
89+
if (ntohs(addr->proto) == ETH_P_IP)
90+
return ipv4_is_multicast(addr->ipv4.s_addr);
91+
#if IS_ENABLED(CONFIG_IPV6)
92+
else
93+
return ipv6_addr_is_multicast(&addr->ipv6);
94+
#endif
95+
return 0;
96+
}
97+
8798
/* udp_media_addr_set - convert a ip/udp address to a TIPC media address */
8899
static void tipc_udp_media_addr_set(struct tipc_media_addr *addr,
89100
struct udp_media_addr *ua)
90101
{
91102
memset(addr, 0, sizeof(struct tipc_media_addr));
92103
addr->media_id = TIPC_MEDIA_TYPE_UDP;
93104
memcpy(addr->value, ua, sizeof(struct udp_media_addr));
94-
if (ntohs(ua->proto) == ETH_P_IP) {
95-
if (ipv4_is_multicast(ua->ipv4.s_addr))
96-
addr->broadcast = 1;
97-
} else if (ntohs(ua->proto) == ETH_P_IPV6) {
98-
if (ipv6_addr_type(&ua->ipv6) & IPV6_ADDR_MULTICAST)
99-
addr->broadcast = 1;
100-
} else {
101-
pr_err("Invalid UDP media address\n");
102-
}
105+
106+
if (tipc_udp_is_mcast_addr(ua))
107+
addr->broadcast = 1;
103108
}
104109

105110
/* tipc_udp_addr2str - convert ip/udp address to string */
@@ -255,15 +260,11 @@ static int enable_mcast(struct udp_bearer *ub, struct udp_media_addr *remote)
255260
struct sock *sk = ub->ubsock->sk;
256261

257262
if (ntohs(remote->proto) == ETH_P_IP) {
258-
if (!ipv4_is_multicast(remote->ipv4.s_addr))
259-
return 0;
260263
mreqn.imr_multiaddr = remote->ipv4;
261264
mreqn.imr_ifindex = ub->ifindex;
262265
err = ip_mc_join_group(sk, &mreqn);
263266
#if IS_ENABLED(CONFIG_IPV6)
264267
} else {
265-
if (!ipv6_addr_is_multicast(&remote->ipv6))
266-
return 0;
267268
err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex,
268269
&remote->ipv6);
269270
#endif
@@ -408,8 +409,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
408409
tuncfg.encap_destroy = NULL;
409410
setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg);
410411

411-
if (enable_mcast(ub, remote))
412-
goto err;
412+
if (tipc_udp_is_mcast_addr(remote)) {
413+
if (enable_mcast(ub, remote))
414+
goto err;
415+
}
416+
413417
return 0;
414418
err:
415419
kfree(ub);

0 commit comments

Comments
 (0)