Minor ipv6 mcast cleanups
Subsystems (3)
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
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
@@ -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
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().Signed-off-by Daniel Borkmann <[email protected]>
PATCH 2/3 net: ipv6: minor: *_start_timer: rather use unsigned long
In reply to Daniel BorkmannFor 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
@@ -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
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(), andmld_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.Signed-off-by Daniel Borkmann <[email protected]>
PATCH 3/3 net: ipv6: mcast: minor: use defines for rfc3810/8.1 lengths
In reply to Daniel BorkmannInstead 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
@@ -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
Re: [PATCH net-next 3/3] net: ipv6: mcast: minor: use defines for rfc3810/8.1 lengths
Quoted 4 lines · Daniel Borkmann
Instead of hard-coding length values, use a define to make it clear where those lengths come from.
Signed-off-by Daniel Borkmann <[email protected]>
Nice cleanups, thanks Daniel!
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Tue, 20 Aug 2013 12:21:59 +0200
Quoted 4 lines
Daniel Borkmann (3):
net: ipv6:igmp6_event_query: usemsecs_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.