IPv6 MLD updates
Subsystems (5)
v2 cover IPv6 MLD updates
This set contains the non-RFC version of the previous submission entitled "[RFC PATCH net-next 0/7] IPv6 MLD updates". Most importantly it contains a fix for MLDv1/v2 switchback timeout where hosts currently are switching back from v1 compat mode to normal v2 too early (i.e. switchback time was <= 30secs instead of >= 260secs on default), and the set also contains a patch that allows for v2-only mode as per RFC recommendation. The rest is related to cleanups that make the code more readable resp. maintainable.
Changes from RFC to non-RFC:
We ignore v2 messages now when in v1 compat mode, otherwise report timers are reset and triggered, also stop current v2 report timer in case it is currently running and we received a v1 query; use WARN_ON instead of BUG_ON for RV of 0 (patch1).
Two more patches have been added that makes to code more readable, that is "net: ipv6: mld: refactor query processing into v1/v2 functions" and "net: ipv6: mld: introduce mld_{gq,ifc,dad}_stop_timer functions", the sysctl patch "net: ipv6: mld: restrict min/max of sysctl force_mld_version" has been dropped as extra1 and extra2 vars are overwritten with idev and net anyway when addrconf sysctl is registered, hence dropped for now. The rest is unchanged, only adapted to take changes into account.
Changes from v1 to v2:
Minor update in "net: ipv6: mld: implement RFC3810 MLDv2 mode only" in MLD version selection. Rest stays the same, added Acked-bys from Hannes in unchanged patches.
Thanks!
Daniel Borkmann (8):
net: ipv6: mld: fix v1/v2 switchback timeout to rfc3810, 9.12.
net: ipv6: mld: clean up MLD_V1_SEEN macro
net: ipv6: mld: get rid of MLDV2_MRC and simplify calculation
net: ipv6: mld: implement RFC3810 MLDv2 mode only
net: ipv6: mld: similarly to MLDv2 have min max_delay of 1
net: ipv6: mld: refactor query processing into v1/v2 functions
net: ipv6: mld: introduce mld_{gq,ifc,dad}_stop_timer functions
net: ipv6: mld: document force_mld_version in ip-sysctl.txt
Documentation/networking/ip-sysctl.txt | 5 + include/net/if_inet6.h | 9 +- include/net/mld.h | 51 +++++-- net/bridge/br_multicast.c | 3 +- net/ipv6/mcast.c | 248 +++++++++++++++++++++++++++------ 5 files changed, 259 insertions(+), 57 deletions(-)
Signature · 1 line
1.7.11.7
PATCH v2 1/8 net: ipv6: mld: fix v1/v2 switchback timeout to rfc3810, 9.12.
i) RFC3810, 9.2. Query Interval [QI] says:
The Query Interval variable denotes the interval between General Queries sent by the Querier. Default value: 125 seconds. [...]
ii) RFC3810, 9.3. Query Response Interval [QRI] says:
The Maximum Response Delay used to calculate the Maximum Response Code inserted into the periodic General Queries. Default value:
10000 (10 seconds) [...] The number of seconds represented by the [Query Response Interval] must be less than the [Query Interval].
iii) RFC3810, 9.12. Older Version Querier Present Timeout [OVQPT] says:
The Older Version Querier Present Timeout is the time-out for transitioning a host back to MLDv2 Host Compatibility Mode. When an MLDv1 query is received, MLDv2 hosts set their Older Version Querier Present Timer to [Older Version Querier Present Timeout].
This value MUST be ([Robustness Variable] times (the [Query Interval] in the last Query received)) plus ([Query Response Interval]).
Hence, on *default* the timeout results in:
[RV] = 2, [QI] = 125sec, [QRI] = 10sec
[OVQPT] = [RV] * [QI] + [QRI] = 260sec
Having that said, we currently calculate [OVQPT] (here given as 'switchback' variable) as ...
switchback = (idev->mc_qrv + 1) * max_delay
RFC3810, 9.12. says "the [Query Interval] in the last Query received". In section "9.14. Configuring timers", it is said:
This section is meant to provide advice to network administrators on how to tune these settings to their network. Ambitious router implementations might tune these settings dynamically based upon changing characteristics of the network. [...]
iv) RFC38010, 9.14.2. Query Interval:
The overall level of periodic MLD traffic is inversely proportional to the Query Interval. A longer Query Interval results in a lower overall level of MLD traffic. The value of the Query Interval MUST be equal to or greater than the Maximum Response Delay used to calculate the Maximum Response Code inserted in General Query messages.
I assume that was why switchback is calculated as is (3 * max_delay), although this setting seems to be meant for routers only to configure their [QI] interval for non-default intervals. So usage here like this is clearly wrong.
Concluding, the current behaviour in IPv6's multicast code is not conform to the RFC as switch back is calculated wrongly. That is, it has a too small value, so MLDv2 hosts switch back again to MLDv2 way too early, i.e. ~30secs instead of ~260secs on default.
Hence, introduce necessary helper functions and fix this up properly as it should be.
Introduced in 06da92283 ("[IPV6]: Add MLDv2 support."). Credits to Hannes Frederic Sowa who also had a hand in this as well. Also thanks to Hangbin Liu who did initial testing.
---
06da92283 is linux-history tree.
include/net/if_inet6.h | 9 +++- include/net/mld.h | 27 +++++++++++- net/ipv6/mcast.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 143 insertions(+), 9 deletions(-)
include/net/if_inet6.h +7 -2
@@ -171,12 +171,17 @@ struct inet6_dev {struct ifmcaddr6 *mc_list;struct ifmcaddr6 *mc_tomb;spinlock_t mc_lock; -unsigned char mc_qrv; + +unsigned char mc_qrv;/* Query Robustness Variable */ unsigned char mc_gq_running;unsigned char mc_ifc_count;unsigned char mc_dad_count; -unsigned long mc_v1_seen; + +unsigned long mc_v1_seen;/* Max time we stay in MLDv1 mode */ +unsigned long mc_qi;/* Query Interval */ +unsigned long mc_qri;/* Query Response Interval */ unsigned long mc_maxdelay; +struct timer_list mc_gq_timer;/* general query timer */ struct timer_list mc_ifc_timer;/* interface change timer */ struct timer_list mc_dad_timer;/* dad complete mc timer */
include/net/mld.h +26 -1
@@ -63,7 +63,7 @@ struct mld2_query {#define mld2q_mrc mld2q_hdr.icmp6_maxdelay#define mld2q_resv1 mld2q_hdr.icmp6_dataun.un_data16[1] -/* Max Response Code */ +/* Max Response Code, TODO: transform this to use the below */ #define MLDV2_MASK (value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))#define MLDV2_EXP (thresh, nbmant, nbexp, value) \ ((value) < (thresh) ? (value) : \
@@ -72,4 +72,29 @@ struct mld2_query {#define MLDV2_MRC (value) MLDV2_EXP(0x8000, 12, 3, value) +/* RFC3810, 5.1.3. Maximum Response Code: +* +* If Maximum Response Code >= 32768, Maximum Response Code represents a +* floating-point value as follows: +* +* 0 1 2 3 4 5 6 7 8 9 A B C D E F +* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +* |1| exp | mant | +* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ +#define MLDV2_MRC_EXP (value) (((value) >> 12) & 0x0007) +#define MLDV2_MRC_MAN (value) ((value) & 0x0fff) + +/* RFC3810, 5.1.9. QQIC (Querier's Query Interval Code): +* +* If QQIC >= 128, QQIC represents a floating-point value as follows: +* +* 0 1 2 3 4 5 6 7 +* +-+-+-+-+-+-+-+-+ +* |1| exp | mant | +* +-+-+-+-+-+-+-+-+ +*/ +#define MLDV2_QQIC_EXP (value) (((value) >> 4) & 0x07) +#define MLDV2_QQIC_MAN (value) ((value) & 0x0f) +#endif
net/ipv6/mcast.c +110 -6
155 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v2 2/8 net: ipv6: mld: clean up MLD_V1_SEEN macro
In reply to Daniel BorkmannReplace the macro with a function to make it more readable. GCC will eventually decide whether to inline this or not (also, that's not fast-path anyway).
--- net/ipv6/mcast.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
net/ipv6/mcast.c +21 -13
@@ -95,6 +95,7 @@ static void mld_ifc_event(struct inet6_dev *idev);static void mld_add_delrec (struct inet6_dev *idev,struct ifmcaddr6 *pmc);static void mld_del_delrec (struct inet6_dev *idev,const struct in6_addr *addr);static void mld_clear_delrec (struct inet6_dev *idev); +static bool mld_in_v1_mode (const struct inet6_dev *idev);static int sf_setstate (struct ifmcaddr6 *pmc);static void sf_markstate (struct ifmcaddr6 *pmc);static void ip6_mc_clear_src (struct ifmcaddr6 *pmc);
@@ -117,11 +118,6 @@ static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,#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 && \ - time_before(jiffies, (idev)->mc_v1_seen))) -#define IPV6_MLD_MAX_MSF 64int sysctl_mld_max_msf__read_mostly =IPV6_MLD_MAX_MSF ;
@@ -139,7 +135,7 @@ static int unsolicited_report_interval(struct inet6_dev *idev) {int iv; -if (MLD_V1_SEEN (idev)) +if (mld_in_v1_mode (idev)) iv = idev->cnf.mldv1_unsolicited_report_interval;else iv = idev->cnf.mldv2_unsolicited_report_interval;
@@ -695,7 +691,7 @@ static void igmp6_group_added(struct ifmcaddr6 *mc)if (!(dev->flags &IFF_UP ) || (mc->mca_flags &MAF_NOREPORT ))return ; -if (MLD_V1_SEEN (mc->idev)) { +if (mld_in_v1_mode (mc->idev)) {igmp6_join_group (mc);return ; }
@@ -1116,6 +1112,18 @@ static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs,return true; } +static bool mld_in_v1_mode (const struct inet6_dev *idev) +{ +if (dev_net (idev->dev)->ipv6.devconf_all->force_mld_version ==1 ) +return true; +if (idev->cnf.force_mld_version ==1 ) +return true; +if (idev->mc_v1_seen &&time_before (jiffies, idev->mc_v1_seen)) +return true; + +return false; +} +static void mld_set_v1_mode (struct inet6_dev *idev) {/* RFC3810, relevant sections:
@@ -1262,7 +1270,7 @@ int igmp6_event_query(struct sk_buff *skb)sizeof (struct icmp6hdr );/* hosts need to stay in MLDv1 mode, discard MLDv2 queries */ -if (MLD_V1_SEEN (idev)) +if (mld_in_v1_mode (idev))return 0 ;if (!pskb_may_pull (skb, srcs_offset))return -EINVAL ;
@@ -1942,7 +1950,7 @@ err_out:static void mld_resend_report (struct inet6_dev *idev) { -if (MLD_V1_SEEN (idev)) { +if (mld_in_v1_mode (idev)) {struct ifmcaddr6 *mcaddr;read_lock_bh (&idev->lock);for (mcaddr = idev->mc_list; mcaddr; mcaddr = mcaddr->next) {
@@ -2006,7 +2014,7 @@ static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,else pmc->mca_sources = psf->sf_next;if (psf->sf_oldin && !(pmc->mca_flags &MAF_NOREPORT ) && - !MLD_V1_SEEN (idev)) { + !mld_in_v1_mode (idev)) { psf->sf_crcount = idev->mc_qrv; psf->sf_next = pmc->mca_tomb; pmc->mca_tomb = psf;
@@ -2306,7 +2314,7 @@ static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,static void igmp6_leave_group (struct ifmcaddr6 *ma) { -if (MLD_V1_SEEN (ma->idev)) { +if (mld_in_v1_mode (ma->idev)) {if (ma->mca_flags &MAF_LAST_REPORTER )igmp6_send (&ma->mca_addr, ma->idev->dev,ICMPV6_MGM_REDUCTION );
@@ -2340,7 +2348,7 @@ static void mld_ifc_timer_expire(unsigned long data)static void mld_ifc_event (struct inet6_dev *idev) { -if (MLD_V1_SEEN (idev)) +if (mld_in_v1_mode (idev))return ; idev->mc_ifc_count = idev->mc_qrv;mld_ifc_start_timer (idev,1 );
@@ -2351,7 +2359,7 @@ static void igmp6_timer_handler(unsigned long data) {struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data; -if (MLD_V1_SEEN (ma->idev)) +if (mld_in_v1_mode (ma->idev))igmp6_send (&ma->mca_addr, ma->idev->dev,ICMPV6_MGM_REPORT );else mld_send_report (ma->idev, ma);
Signature · 1 line
1.7.11.7
PATCH v2 3/8 net: ipv6: mld: get rid of MLDV2_MRC and simplify calculation
In reply to Daniel BorkmannGet rid of MLDV2_MRC and use our new macros for mantisse and exponent to calculate Maximum Response Delay out of the Maximum Response Code.
---
This will give a merge conflict in net/bridge/br_multicast.c with net tree. You can resolve it by simply taking this version as we already do msecs_to_jiffies() here.
include/net/mld.h | 28 +++++++++++++++++++--------- net/bridge/br_multicast.c | 3 ++- net/ipv6/mcast.c | 18 ++---------------- 3 files changed, 23 insertions(+), 26 deletions(-)
include/net/mld.h +19 -9
@@ -63,15 +63,6 @@ struct mld2_query {#define mld2q_mrc mld2q_hdr.icmp6_maxdelay#define mld2q_resv1 mld2q_hdr.icmp6_dataun.un_data16[1] -/* Max Response Code, TODO: transform this to use the below */ -#define MLDV2_MASK (value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value)) -#define MLDV2_EXP (thresh, nbmant, nbexp, value) \ - ((value) < (thresh) ? (value) : \ - ((MLDV2_MASK(value, nbmant) | (1<<(nbmant))) << \ - (MLDV2_MASK((value) >> (nbmant), nbexp) + (nbexp)))) - -#define MLDV2_MRC (value) MLDV2_EXP(0x8000, 12, 3, value) -/* RFC3810, 5.1.3. Maximum Response Code: * * If Maximum Response Code >= 32768, Maximum Response Code represents a
@@ -97,4 +88,23 @@ struct mld2_query {#define MLDV2_QQIC_EXP (value) (((value) >> 4) & 0x07)#define MLDV2_QQIC_MAN (value) ((value) & 0x0f) +static inline unsigned long mldv2_mrc (const struct mld2_query *mlh2) +{ +/* RFC3810, 5.1.3. Maximum Response Code */ +unsigned long ret, mc_mrc =ntohs (mlh2->mld2q_mrc); + +if (mc_mrc <32768 ) { + ret = mc_mrc; + }else { +unsigned long mc_man, mc_exp; + + mc_exp =MLDV2_MRC_EXP (mc_mrc); + mc_man =MLDV2_MRC_MAN (mc_mrc); + + ret = (mc_man |0x1000 ) << (mc_exp +3 ); + } + +return ret; +} +#endif
net/bridge/br_multicast.c +2 -1
@@ -1203,7 +1203,8 @@ static int br_ip6_multicast_query(struct net_bridge *br, mld2q = (struct mld2_query *)icmp6_hdr (skb);if (!mld2q->mld2q_nsrcs) group = &mld2q->mld2q_mca; - max_delay = mld2q->mld2q_mrc ?MLDV2_MRC (ntohs (mld2q->mld2q_mrc)) :1 ; + + max_delay =max (msecs_to_jiffies (mldv2_mrc (mld2q)),1UL ); } br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr),
net/ipv6/mcast.c +2 -16
@@ -1195,20 +1195,7 @@ static void mld_update_qri(struct inet6_dev *idev,* - 5.1.3. Maximum Response Code * - 9.3. Query Response Interval */ -unsigned long mc_qri, mc_mrc =ntohs (mlh2->mld2q_mrc); - -if (mc_mrc <32768 ) { - mc_qri = mc_mrc; - }else { -unsigned long mc_man, mc_exp; - - mc_exp =MLDV2_MRC_EXP (mc_mrc); - mc_man =MLDV2_MRC_MAN (mc_mrc); - - mc_qri = (mc_man |0x1000 ) << (mc_exp +3 ); - } - - idev->mc_qri =msecs_to_jiffies (mc_qri); + idev->mc_qri =msecs_to_jiffies (mldv2_mrc (mlh2)); }/* called with rcu_read_lock() */
@@ -1277,8 +1264,7 @@ int igmp6_event_query(struct sk_buff *skb) mlh2 = (struct mld2_query *)skb_transport_header (skb); - max_delay =max (msecs_to_jiffies (MLDV2_MRC (ntohs (mlh2->mld2q_mrc))),1UL ); - + max_delay =max (msecs_to_jiffies (mldv2_mrc (mlh2)),1UL ); idev->mc_maxdelay = max_delay;mld_update_qrv (idev, mlh2);
Signature · 1 line
1.7.11.7
PATCH v2 4/8 net: ipv6: mld: implement RFC3810 MLDv2 mode only
In reply to Daniel BorkmannRFC3810, 10. Security Considerations says under subsection 10.1. Query Message:
A forged Version 1 Query message will put MLDv2 listeners on that link in MLDv1 Host Compatibility Mode. This scenario can be avoided by providing MLDv2 hosts with a configuration option to ignore Version 1 messages completely.
Hence, implement a MLDv2-only mode that will ignore MLDv1 traffic:
echo 2 > /proc/sys/net/ipv6/conf/ethX/force_mld_version or echo 2 > /proc/sys/net/ipv6/conf/all/force_mld_version
Note that <all> device has a higher precedence as it was previously also the case in the macro MLD_V1_SEEN() that would "short-circuit" if condition on <all> case.
--- net/ipv6/mcast.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
net/ipv6/mcast.c +30 -4
@@ -1112,11 +1112,34 @@ static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs,return true; } +static int mld_force_mld_version (const struct inet6_dev *idev) +{ +/* Normally, both are 0 here. If enforcement to a particular is +* being used, individual device enforcement will have a lower +* precedence over 'all' device (.../conf/all/force_mld_version). +*/ + +if (dev_net (idev->dev)->ipv6.devconf_all->force_mld_version !=0 ) +return dev_net (idev->dev)->ipv6.devconf_all->force_mld_version; +else +return idev->cnf.force_mld_version; +} + +static bool mld_in_v2_mode_only (const struct inet6_dev *idev) +{ +return mld_force_mld_version (idev) ==2 ; +} + +static bool mld_in_v1_mode_only (const struct inet6_dev *idev) +{ +return mld_force_mld_version (idev) ==1 ; +} +static bool mld_in_v1_mode (const struct inet6_dev *idev) { -if (dev_net (idev->dev)->ipv6.devconf_all->force_mld_version ==1 ) -return true; -if (idev->cnf.force_mld_version ==1 ) +if (mld_in_v2_mode_only (idev)) +return false; +if (mld_in_v1_mode_only (idev))return true;if (idev->mc_v1_seen &&time_before (jiffies, idev->mc_v1_seen))return true;
@@ -1223,7 +1246,6 @@ int igmp6_event_query(struct sk_buff *skb)return -EINVAL ; idev =__in6_dev_get (skb->dev); -if (idev ==NULL )return 0 ;
@@ -1236,6 +1258,10 @@ int igmp6_event_query(struct sk_buff *skb)return -EINVAL ;if (len ==MLD_V1_QUERY_LEN ) { +/* Ignore v1 queries */ +if (mld_in_v2_mode_only (idev)) +return 0 ; +/* MLDv1 router present */ max_delay =msecs_to_jiffies (ntohs (mld->mld_maxdelay));
Signature · 1 line
1.7.11.7
Re: [PATCH net-next v2 4/8] net: ipv6: mld: implement RFC3810 MLDv2 mode only
Quoted 13 lines · Daniel Borkmann
RFC3810, 10. Security Considerations says under subsection 10.1. Query Message:
A forged Version 1 Query message will put MLDv2 listeners on that link in MLDv1 Host Compatibility Mode. This scenario can be avoided by providing MLDv2 hosts with a configuration option to ignore Version 1 messages completely.
Hence, implement a MLDv2-only mode that will ignore MLDv1 traffic:
echo 2 >
/proc/sys/net/ipv6/conf/ethX/force_mld_versionor echo 2 >/proc/sys/net/ipv6/conf/all/force_mld_version
Quoted 6 lines
Note that <all> device has a higher precedence as it was previously also the case in the macro
MLD_V1_SEEN()that would "short-circuit" if condition on <all> case.Signed-off-by Daniel Borkmann <[email protected]>Cc Hannes Frederic Sowa <[email protected]>
Even better...
Thanks!
PATCH v2 5/8 net: ipv6: mld: similarly to MLDv2 have min max_delay of 1
In reply to Daniel BorkmannSimilarly as we do in MLDv2 queries, set a forged MLDv1 query with 0 ms mld_maxdelay to minimum timer shot time of 1 jiffies. This is eventually done in igmp6_group_queried() anyway, so we can simplify a check there.
--- net/ipv6/mcast.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/ipv6/mcast.c +7 -7
@@ -1040,12 +1040,9 @@ static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime) delay = ma->mca_timer.expires - jiffies; } -if (delay >= resptime) { -if (resptime) - delay =net_random () % resptime; -else - delay =1 ; - } +if (delay >= resptime) + delay =net_random () % resptime; + ma->mca_timer.expires = jiffies + delay;if (!mod_timer (&ma->mca_timer, jiffies + delay))atomic_inc (&ma->mca_refcnt);
@@ -1258,12 +1255,15 @@ int igmp6_event_query(struct sk_buff *skb)return -EINVAL ;if (len ==MLD_V1_QUERY_LEN ) { +unsigned long mldv1_md; +/* Ignore v1 queries */ if (mld_in_v2_mode_only (idev))return 0 ;/* MLDv1 router present */ - max_delay =msecs_to_jiffies (ntohs (mld->mld_maxdelay)); + mldv1_md =ntohs (mld->mld_maxdelay); + max_delay =max (msecs_to_jiffies (mldv1_md),1UL );mld_set_v1_mode (idev);
Signature · 1 line
1.7.11.7
PATCH v2 6/8 net: ipv6: mld: refactor query processing into v1/v2 functions
In reply to Daniel BorkmannMake igmp6_event_query() a bit easier to read by refactoring code parts into mld_process_v1() and mld_process_v2().
--- net/ipv6/mcast.c | 89 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 33 deletions(-)
net/ipv6/mcast.c +56 -33
@@ -1218,6 +1218,55 @@ static void mld_update_qri(struct inet6_dev *idev, idev->mc_qri =msecs_to_jiffies (mldv2_mrc (mlh2)); } +static int mld_process_v1 (struct inet6_dev *idev,struct mld_msg *mld, +unsigned long *max_delay) +{ +unsigned long mldv1_md; + +/* Ignore v1 queries */ +if (mld_in_v2_mode_only (idev)) +return -EINVAL ; + +/* MLDv1 router present */ + mldv1_md =ntohs (mld->mld_maxdelay); + *max_delay =max (msecs_to_jiffies (mldv1_md),1UL ); + +mld_set_v1_mode (idev); + +/* cancel MLDv2 report timer */ + idev->mc_gq_running =0 ; +if (del_timer (&idev->mc_gq_timer)) +__in6_dev_put (idev); + +/* cancel the interface change timer */ + idev->mc_ifc_count =0 ; +if (del_timer (&idev->mc_ifc_timer)) +__in6_dev_put (idev); + +/* clear deleted report items */ +mld_clear_delrec (idev); + +return 0 ; +} + +static int mld_process_v2 (struct inet6_dev *idev,struct mld2_query *mld, +unsigned long *max_delay) +{ +/* hosts need to stay in MLDv1 mode, discard MLDv2 queries */ +if (mld_in_v1_mode (idev)) +return -EINVAL ; + + *max_delay =max (msecs_to_jiffies (mldv2_mrc (mld)),1UL ); + +mld_update_qrv (idev, mld); +mld_update_qi (idev, mld); +mld_update_qri (idev, mld); + + idev->mc_maxdelay = *max_delay; + +return 0 ; +} +/* called with rcu_read_lock() */ int igmp6_event_query (struct sk_buff *skb) {
@@ -1229,7 +1278,7 @@ int igmp6_event_query(struct sk_buff *skb)struct mld_msg *mld;int group_type;int mark =0 ; -int len; +int len, err;if (!pskb_may_pull (skb,sizeof (struct in6_addr )))return -EINVAL ;
@@ -1255,47 +1304,21 @@ int igmp6_event_query(struct sk_buff *skb)return -EINVAL ;if (len ==MLD_V1_QUERY_LEN ) { -unsigned long mldv1_md; - -/* Ignore v1 queries */ -if (mld_in_v2_mode_only (idev)) -return 0 ; - -/* MLDv1 router present */ - mldv1_md =ntohs (mld->mld_maxdelay); - max_delay =max (msecs_to_jiffies (mldv1_md),1UL ); - -mld_set_v1_mode (idev); - -/* cancel MLDv2 report timer */ - idev->mc_gq_running =0 ; -if (del_timer (&idev->mc_gq_timer)) -__in6_dev_put (idev); - -/* cancel the interface change timer */ - idev->mc_ifc_count =0 ; -if (del_timer (&idev->mc_ifc_timer)) -__in6_dev_put (idev); -/* clear deleted report items */ -mld_clear_delrec (idev); + err =mld_process_v1 (idev, mld, &max_delay); +if (err <0 ) +return err; }else if (len >=MLD_V2_QUERY_LEN_MIN ) {int srcs_offset =sizeof (struct mld2_query ) -sizeof (struct icmp6hdr ); -/* hosts need to stay in MLDv1 mode, discard MLDv2 queries */ -if (mld_in_v1_mode (idev)) -return 0 ;if (!pskb_may_pull (skb, srcs_offset))return -EINVAL ; mlh2 = (struct mld2_query *)skb_transport_header (skb); - max_delay =max (msecs_to_jiffies (mldv2_mrc (mlh2)),1UL ); - idev->mc_maxdelay = max_delay; - -mld_update_qrv (idev, mlh2); -mld_update_qi (idev, mlh2); -mld_update_qri (idev, mlh2); + err =mld_process_v2 (idev, mlh2, &max_delay); +if (err <0 ) +return err;if (group_type ==IPV6_ADDR_ANY ) {/* general query */ if (mlh2->mld2q_nsrcs)
Signature · 1 line
1.7.11.7
PATCH v2 7/8 net: ipv6: mld: introduce mld_{gq,ifc,dad}_stop_timer functions
In reply to Daniel BorkmannWe already have mld_{gq,ifc,dad}_start_timer() functions, so introduce mld_{gq,ifc,dad}_stop_timer() functions to reduce code size and make it more readable.
--- net/ipv6/mcast.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
net/ipv6/mcast.c +25 -16
@@ -1006,6 +1006,13 @@ static void mld_gq_start_timer(struct inet6_dev *idev)in6_dev_hold (idev); } +static void mld_gq_stop_timer (struct inet6_dev *idev) +{ + idev->mc_gq_running =0 ; +if (del_timer (&idev->mc_gq_timer)) +__in6_dev_put (idev); +} +static void mld_ifc_start_timer (struct inet6_dev *idev,unsigned long delay) {unsigned long tv =net_random () % delay;
@@ -1014,6 +1021,13 @@ static void mld_ifc_start_timer(struct inet6_dev *idev, unsigned long delay)in6_dev_hold (idev); } +static void mld_ifc_stop_timer (struct inet6_dev *idev) +{ + idev->mc_ifc_count =0 ; +if (del_timer (&idev->mc_ifc_timer)) +__in6_dev_put (idev); +} +static void mld_dad_start_timer (struct inet6_dev *idev,unsigned long delay) {unsigned long tv =net_random () % delay;
@@ -1022,6 +1036,12 @@ static void mld_dad_start_timer(struct inet6_dev *idev, unsigned long delay)in6_dev_hold (idev); } +static void mld_dad_stop_timer (struct inet6_dev *idev) +{ +if (del_timer (&idev->mc_dad_timer)) +__in6_dev_put (idev); +} +/* * IGMP handling (alias multicast ICMPv6 messages) */
@@ -1234,15 +1254,9 @@ static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld,mld_set_v1_mode (idev);/* cancel MLDv2 report timer */ - idev->mc_gq_running =0 ; -if (del_timer (&idev->mc_gq_timer)) -__in6_dev_put (idev); - +mld_gq_stop_timer (idev);/* cancel the interface change timer */ - idev->mc_ifc_count =0 ; -if (del_timer (&idev->mc_ifc_timer)) -__in6_dev_put (idev); - +mld_ifc_stop_timer (idev);/* clear deleted report items */ mld_clear_delrec (idev);
@@ -2434,14 +2448,9 @@ void ipv6_mc_down(struct inet6_dev *idev)/* Withdraw multicast list */ read_lock_bh (&idev->lock); - idev->mc_ifc_count =0 ; -if (del_timer (&idev->mc_ifc_timer)) -__in6_dev_put (idev); - idev->mc_gq_running =0 ; -if (del_timer (&idev->mc_gq_timer)) -__in6_dev_put (idev); -if (del_timer (&idev->mc_dad_timer)) -__in6_dev_put (idev); +mld_ifc_stop_timer (idev); +mld_gq_stop_timer (idev); +mld_dad_stop_timer (idev);for (i = idev->mc_list; i; i=i->next)igmp6_group_dropped (i);
Signature · 1 line
1.7.11.7
PATCH v2 8/8 net: ipv6: mld: document force_mld_version in ip-sysctl.txt
In reply to Daniel BorkmannDocument force_mld_version parameter in ip-sysctl.txt.
--- Documentation/networking/ip-sysctl.txt | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/networking/ip-sysctl.txt +5 -0
@@ -1358,6 +1358,11 @@ mldv2_unsolicited_report_interval - INTEGER MLDv2 report retransmit will take place. Default: 1000 (1 second) +force_mld_version - INTEGER + 0 - (default) No enforcement of a MLD version, MLDv1 fallback allowed + 1 - Enforce to use MLD version 1 + 2 - Enforce to use MLD version 2 + suppress_frag_ndisc - INTEGER Control RFC 6980 (Security Implications of IPv6 Fragmentation with IPv6 Neighbor Discovery) behavior:
Signature · 1 line
1.7.11.7
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Wed, 4 Sep 2013 00:19:36 +0200
Quoted 7 lines
This set contains the non-RFC version of the previous submission entitled "[RFC PATCH net-next 0/7] IPv6 MLD updates". Most importantly it contains a fix for MLDv1/v2 switchback timeout where hosts currently are switching back from v1 compat mode to normal v2 too early (i.e. switchback time was <= 30secs instead of >= 260secs on default), and the set also contains a patch that allows for v2-only mode as per RFC recommendation. The rest is related to cleanups that make the code more readable resp. maintainable.
Series applied, thanks in particular for the 'net' merge conflict resolution as that helps me a lot.