Add a function to check if a tipc UDP media address is a multicast address or not. This is a purely cosmetic change.
Unified · Split
| @@ -84,6 +84,17 @@ struct udp_bearer { · 83 unmodified lines | ||
| 84 | 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 | 98 | /* udp_media_addr_set - convert a ip/udp address to a TIPC media address */ |
| 88 | 99 | static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, |
| 89 | 100 | struct udp_media_addr *ua) |
| @@ -91,15 +102,9 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, · 1 unmodified line | ||
| 91 | 102 | memset(addr, 0, sizeof(struct tipc_media_addr)); |
| 92 | 103 | addr->media_id = TIPC_MEDIA_TYPE_UDP; |
| 93 | 104 | 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; | |
| 103 | 108 | } |
| 104 | 109 | |
| 105 | 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) · 149 unmodified lines | ||
| 255 | 260 | struct sock *sk = ub->ubsock->sk; |
| 256 | 261 | |
| 257 | 262 | if (ntohs(remote->proto) == ETH_P_IP) { |
| 258 | − if (!ipv4_is_multicast(remote->ipv4.s_addr)) | |
| 259 | − return 0; | |
| 260 | 263 | mreqn.imr_multiaddr = remote->ipv4; |
| 261 | 264 | mreqn.imr_ifindex = ub->ifindex; |
| 262 | 265 | err = ip_mc_join_group(sk, &mreqn); |
| 263 | 266 | #if IS_ENABLED(CONFIG_IPV6) |
| 264 | 267 | } else { |
| 265 | − if (!ipv6_addr_is_multicast(&remote->ipv6)) | |
| 266 | − return 0; | |
| 267 | 268 | err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex, |
| 268 | 269 | &remote->ipv6); |
| 269 | 270 | #endif |
| @@ -408,8 +409,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, · 138 unmodified lines | ||
| 408 | 409 | tuncfg.encap_destroy = NULL; |
| 409 | 410 | setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg); |
| 410 | 411 | |
| 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 | + | |
| 413 | 417 | return 0; |
| 414 | 418 | err: |
| 415 | 419 | kfree(ub); |