From: Richard Alpe <richard.alpe@ericsson.com>
To: <netdev@vger.kernel.org>
Cc: tipc-discussion@lists.sourceforge.net
Subject: [PATCH net-next 3/7] tipc: refactor multicast ip check
Date: Fri, 26 Aug 2016 10:52:52 +0200 [thread overview]
Message-ID: <1472201576-26588-4-git-send-email-richard.alpe@ericsson.com> (raw)
In-Reply-To: <1472201576-26588-1-git-send-email-richard.alpe@ericsson.com>
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>
---
net/tipc/udp_media.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
index 7033b4a..b8ec1a1 100644
--- a/net/tipc/udp_media.c
+++ b/net/tipc/udp_media.c
@@ -84,6 +84,17 @@ struct udp_bearer {
struct work_struct work;
};
+static int tipc_udp_is_mcast_addr(struct udp_media_addr *addr)
+{
+ if (ntohs(addr->proto) == ETH_P_IP)
+ return ipv4_is_multicast(addr->ipv4.s_addr);
+#if IS_ENABLED(CONFIG_IPV6)
+ else
+ return ipv6_addr_is_multicast(&addr->ipv6);
+#endif
+ return 0;
+}
+
/* udp_media_addr_set - convert a ip/udp address to a TIPC media address */
static void tipc_udp_media_addr_set(struct tipc_media_addr *addr,
struct udp_media_addr *ua)
@@ -91,15 +102,9 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr,
memset(addr, 0, sizeof(struct tipc_media_addr));
addr->media_id = TIPC_MEDIA_TYPE_UDP;
memcpy(addr->value, ua, sizeof(struct udp_media_addr));
- if (ntohs(ua->proto) == ETH_P_IP) {
- if (ipv4_is_multicast(ua->ipv4.s_addr))
- addr->broadcast = 1;
- } else if (ntohs(ua->proto) == ETH_P_IPV6) {
- if (ipv6_addr_type(&ua->ipv6) & IPV6_ADDR_MULTICAST)
- addr->broadcast = 1;
- } else {
- pr_err("Invalid UDP media address\n");
- }
+
+ if (tipc_udp_is_mcast_addr(ua))
+ addr->broadcast = 1;
}
/* 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)
struct sock *sk = ub->ubsock->sk;
if (ntohs(remote->proto) == ETH_P_IP) {
- if (!ipv4_is_multicast(remote->ipv4.s_addr))
- return 0;
mreqn.imr_multiaddr = remote->ipv4;
mreqn.imr_ifindex = ub->ifindex;
err = ip_mc_join_group(sk, &mreqn);
#if IS_ENABLED(CONFIG_IPV6)
} else {
- if (!ipv6_addr_is_multicast(&remote->ipv6))
- return 0;
err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex,
&remote->ipv6);
#endif
@@ -408,8 +409,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
tuncfg.encap_destroy = NULL;
setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg);
- if (enable_mcast(ub, remote))
- goto err;
+ if (tipc_udp_is_mcast_addr(remote)) {
+ if (enable_mcast(ub, remote))
+ goto err;
+ }
+
return 0;
err:
kfree(ub);
--
2.1.4
------------------------------------------------------------------------------
next prev parent reply other threads:[~2016-08-26 8:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-26 8:52 [PATCH net-next 0/7] tipc: introduce UDP replicast Richard Alpe
2016-08-26 8:52 ` [PATCH net-next 1/7] tipc: split UDP nl address parsing Richard Alpe
2016-08-26 8:52 ` [PATCH net-next 2/7] tipc: split UDP send function Richard Alpe
2016-08-26 8:52 ` Richard Alpe [this message]
2016-08-26 8:52 ` [PATCH net-next 4/7] tipc: introduce UDP replicast Richard Alpe
2016-08-26 8:52 ` [PATCH net-next 5/7] tipc: add replicast peer discovery Richard Alpe
2016-08-26 8:52 ` [PATCH net-next 6/7] tipc: add the ability to get UDP options via netlink Richard Alpe
2016-08-26 8:52 ` [PATCH net-next 7/7] tipc: add UDP remoteip dump to netlink API Richard Alpe
2016-08-27 4:40 ` [PATCH net-next 0/7] tipc: introduce UDP replicast David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472201576-26588-4-git-send-email-richard.alpe@ericsson.com \
--to=richard.alpe@ericsson.com \
--cc=netdev@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).