diff options
author | Richard Alpe <richard.alpe@ericsson.com> | 2016-08-26 04:52:52 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-08-27 00:38:40 -0400 |
commit | 1ca73e3fa12531bbbc854329cd02a887f986a02a (patch) | |
tree | 39251d32c707cdf6e854832dde6452633aa5e359 /net/tipc | |
parent | ce984da36e11c1e6db6002ea4f8a4b54e46f45c0 (diff) |
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>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/udp_media.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 7033b4a1a655..b8ec1a18241e 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c | |||
@@ -84,6 +84,17 @@ struct udp_bearer { | |||
84 | struct work_struct work; | 84 | struct work_struct work; |
85 | }; | 85 | }; |
86 | 86 | ||
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 | |||
87 | /* udp_media_addr_set - convert a ip/udp address to a TIPC media address */ | 98 | /* udp_media_addr_set - convert a ip/udp address to a TIPC media address */ |
88 | static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, | 99 | static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, |
89 | struct udp_media_addr *ua) | 100 | struct udp_media_addr *ua) |
@@ -91,15 +102,9 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, | |||
91 | memset(addr, 0, sizeof(struct tipc_media_addr)); | 102 | memset(addr, 0, sizeof(struct tipc_media_addr)); |
92 | addr->media_id = TIPC_MEDIA_TYPE_UDP; | 103 | addr->media_id = TIPC_MEDIA_TYPE_UDP; |
93 | memcpy(addr->value, ua, sizeof(struct udp_media_addr)); | 104 | memcpy(addr->value, ua, sizeof(struct udp_media_addr)); |
94 | if (ntohs(ua->proto) == ETH_P_IP) { | 105 | |
95 | if (ipv4_is_multicast(ua->ipv4.s_addr)) | 106 | if (tipc_udp_is_mcast_addr(ua)) |
96 | addr->broadcast = 1; | 107 | 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 | } | ||
103 | } | 108 | } |
104 | 109 | ||
105 | /* tipc_udp_addr2str - convert ip/udp address to string */ | 110 | /* 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) | |||
255 | struct sock *sk = ub->ubsock->sk; | 260 | struct sock *sk = ub->ubsock->sk; |
256 | 261 | ||
257 | if (ntohs(remote->proto) == ETH_P_IP) { | 262 | if (ntohs(remote->proto) == ETH_P_IP) { |
258 | if (!ipv4_is_multicast(remote->ipv4.s_addr)) | ||
259 | return 0; | ||
260 | mreqn.imr_multiaddr = remote->ipv4; | 263 | mreqn.imr_multiaddr = remote->ipv4; |
261 | mreqn.imr_ifindex = ub->ifindex; | 264 | mreqn.imr_ifindex = ub->ifindex; |
262 | err = ip_mc_join_group(sk, &mreqn); | 265 | err = ip_mc_join_group(sk, &mreqn); |
263 | #if IS_ENABLED(CONFIG_IPV6) | 266 | #if IS_ENABLED(CONFIG_IPV6) |
264 | } else { | 267 | } else { |
265 | if (!ipv6_addr_is_multicast(&remote->ipv6)) | ||
266 | return 0; | ||
267 | err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex, | 268 | err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex, |
268 | &remote->ipv6); | 269 | &remote->ipv6); |
269 | #endif | 270 | #endif |
@@ -408,8 +409,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, | |||
408 | tuncfg.encap_destroy = NULL; | 409 | tuncfg.encap_destroy = NULL; |
409 | setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg); | 410 | setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg); |
410 | 411 | ||
411 | if (enable_mcast(ub, remote)) | 412 | if (tipc_udp_is_mcast_addr(remote)) { |
412 | goto err; | 413 | if (enable_mcast(ub, remote)) |
414 | goto err; | ||
415 | } | ||
416 | |||
413 | return 0; | 417 | return 0; |
414 | err: | 418 | err: |
415 | kfree(ub); | 419 | kfree(ub); |