History

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.

Richard Alpe committed 10 years ago

Commit 1ca73e31 parent ce984da1 file · +19 −15Browse files

Unified · Split

net/tipc/udp_media.c+19−15
@@ -84,6 +84,17 @@ struct udp_bearer { · 83 unmodified lines
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)
@@ -91,15 +102,9 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, · 1 unmodified line
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) · 149 unmodified lines
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, · 138 unmodified lines
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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t