Skip to contentSkip to conversation

Minor ipv6 mcast cleanups

PATCH In review Daniel Borkmann 3 participants 8 messages Aug 20, 2013 – Aug 21, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Minor ipv6 mcast cleanups

Daniel Borkmann (3):
net: ipv6: igmp6_event_query: use msecs_to_jiffies
net: ipv6: minor: *_start_timer: rather use unsigned long
net: ipv6: mcast: minor: use defines for rfc3810/8.1 lengths

 net/ipv6/mcast.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/3 net: ipv6: igmp6_event_query: use msecs_to_jiffies

Use proper API functions to calculate jiffies from milliseconds and not the crude method of dividing HZ by a value. This ensures more accurate values even in the case of strange HZ values. While at it, also simplify code in the mlh2 case by using max().

---
 net/ipv6/mcast.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
net/ipv6/mcast.c +5 -6
index 6c76df9..57863e2 100644
@@ -1150,9 +1150,7 @@ int igmp6_event_query(struct sk_buff *skb)
 		int switchback;
 		/* MLDv1 router present */
 
-		/* Translate milliseconds to jiffies */
-		max_delay = (ntohs(mld->mld_maxdelay)*HZ)/1000;
-
+		max_delay = msecs_to_jiffies(ntohs(mld->mld_maxdelay));
 		switchback = (idev->mc_qrv + 1) * max_delay;
 		idev->mc_v1_seen = jiffies + switchback;
 
@@ -1169,10 +1167,11 @@ int igmp6_event_query(struct sk_buff *skb)
 			return -EINVAL;
 
 		mlh2 = (struct mld2_query *)skb_transport_header(skb);
-		max_delay = (MLDV2_MRC(ntohs(mlh2->mld2q_mrc))*HZ)/1000;
-		if (!max_delay)
-			max_delay = 1;
+
+		max_delay = max(msecs_to_jiffies(MLDV2_MRC(ntohs(mlh2->mld2q_mrc))), 1UL);
+
 		idev->mc_maxdelay = max_delay;
+
 		if (mlh2->mld2q_qrv)
 			idev->mc_qrv = mlh2->mld2q_qrv;
 		if (group_type == IPV6_ADDR_ANY) { /* general query */
Signature · 1 line
1.7.11.7
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH net-next 1/3] net: ipv6: igmp6_event_query: use msecs_to_jiffies

Quoted 6 lines · Daniel Borkmann

Use proper API functions to calculate jiffies from milliseconds and not the crude method of dividing HZ by a value. This ensures more accurate values even in the case of strange HZ values. While at it, also simplify code in the mlh2 case by using max().

#3 lore raw

PATCH 2/3 net: ipv6: minor: *_start_timer: rather use unsigned long

In reply to Daniel Borkmann

For the functions mld_gq_start_timer(), mld_ifc_start_timer(), and mld_dad_start_timer(), rather use unsigned long than int as we operate only on unsigned values anyway. This seems more appropriate as there is no good reason to do type conversions to int, that could lead to future errors.

---
 net/ipv6/mcast.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/ipv6/mcast.c +5 -5
index 57863e2..33f98d9 100644
@@ -996,24 +996,24 @@ bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group,
 
 static void mld_gq_start_timer(struct inet6_dev *idev)
 {
-	int tv = net_random() % idev->mc_maxdelay;
+	unsigned long tv = net_random() % idev->mc_maxdelay;
 
 	idev->mc_gq_running = 1;
 	if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2))
 		in6_dev_hold(idev);
 }
 
-static void mld_ifc_start_timer(struct inet6_dev *idev, int delay)
+static void mld_ifc_start_timer(struct inet6_dev *idev, unsigned long delay)
 {
-	int tv = net_random() % delay;
+	unsigned long tv = net_random() % delay;
 
 	if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2))
 		in6_dev_hold(idev);
 }
 
-static void mld_dad_start_timer(struct inet6_dev *idev, int delay)
+static void mld_dad_start_timer(struct inet6_dev *idev, unsigned long delay)
 {
-	int tv = net_random() % delay;
+	unsigned long tv = net_random() % delay;
 
 	if (!mod_timer(&idev->mc_dad_timer, jiffies+tv+2))
 		in6_dev_hold(idev);
Signature · 1 line
1.7.11.7
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH net-next 2/3] net: ipv6: minor: *_start_timer: rather use unsigned long

Quoted 7 lines · Daniel Borkmann

For the functions mld_gq_start_timer(), mld_ifc_start_timer(), and mld_dad_start_timer(), rather use unsigned long than int as we operate only on unsigned values anyway. This seems more appropriate as there is no good reason to do type conversions to int, that could lead to future errors.

#5 lore raw

PATCH 3/3 net: ipv6: mcast: minor: use defines for rfc3810/8.1 lengths

In reply to Daniel Borkmann

Instead of hard-coding length values, use a define to make it clear where those lengths come from.

---
 net/ipv6/mcast.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv6/mcast.c +6 -3
index 33f98d9..98ead2b 100644
@@ -107,9 +107,12 @@ static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca,
 static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
 			    struct inet6_dev *idev);
 
-
 #define MLD_QRV_DEFAULT		2
 
+/* RFC3810, 8.1 Query Version Distinctions */
+#define MLD_V1_QUERY_LEN	24
+#define MLD_V2_QUERY_LEN_MIN	28
+
 #define MLD_V1_SEEN(idev) (dev_net((idev)->dev)->ipv6.devconf_all->force_mld_version == 1 || \
 		(idev)->cnf.force_mld_version == 1 || \
 		((idev)->mc_v1_seen && \
@@ -1146,7 +1149,7 @@ int igmp6_event_query(struct sk_buff *skb)
 	    !(group_type&IPV6_ADDR_MULTICAST))
 		return -EINVAL;
 
-	if (len == 24) {
+	if (len == MLD_V1_QUERY_LEN) {
 		int switchback;
 		/* MLDv1 router present */
 
@@ -1160,7 +1163,7 @@ int igmp6_event_query(struct sk_buff *skb)
 			__in6_dev_put(idev);
 		/* clear deleted report items */
 		mld_clear_delrec(idev);
-	} else if (len >= 28) {
+	} else if (len >= MLD_V2_QUERY_LEN_MIN) {
 		int srcs_offset = sizeof(struct mld2_query) -
 				  sizeof(struct icmp6hdr);
 		if (!pskb_may_pull(skb, srcs_offset))
Signature · 1 line
1.7.11.7
maintainer
#7 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Tue, 20 Aug 2013 12:21:59 +0200

Quoted 4 lines

Daniel Borkmann (3):
net: ipv6: igmp6_event_query: use msecs_to_jiffies
net: ipv6: minor: *_start_timer: rather use unsigned long
net: ipv6: mcast: minor: use defines for rfc3810/8.1 lengths

All applied, thanks Daniel.