IPv6 MLD updates
Subsystems (5)
cover IPv6 MLD updates
If there are no further objections, I'll send out the non-RFC version on Monday after some more testing. That's just a heads up. This set includes my improved fix from yesterday as well besides other things.
Thanks!
Daniel Borkmann (7):
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: restrict min/max of sysctl force_mld_version
net: ipv6: mld: similarly to MLDv2 have min max_delay of 1
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/addrconf.c | 7 +- net/ipv6/mcast.c | 159 +++++++++++++++++++++++++++------ 6 files changed, 195 insertions(+), 39 deletions(-)
Signature · 1 line
1.7.11.7
RFC PATCH 1/7 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
On the other hand, 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 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.
Hence, introduce 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.
--- include/net/if_inet6.h | 9 ++++- include/net/mld.h | 27 ++++++++++++- net/ipv6/mcast.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 135 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 +102 -6
147 lines not on this page · raw message
Signature · 1 line
1.7.11.7
RFC PATCH 2/7 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 | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
net/ipv6/mcast.c +20 -12
@@ -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:
@@ -1934,7 +1942,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) {
@@ -1998,7 +2006,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;
@@ -2298,7 +2306,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 );
@@ -2332,7 +2340,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 );
@@ -2343,7 +2351,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
RFC PATCH 3/7 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.
--- 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() */
@@ -1269,8 +1256,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
RFC PATCH 4/7 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
--- net/ipv6/mcast.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
net/ipv6/mcast.c +17 -2
@@ -1112,9 +1112,21 @@ static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs,return true; } +static bool mld_in_v2_mode_only (const struct inet6_dev *idev) +{ +return dev_net (idev->dev)->ipv6.devconf_all->force_mld_version ==2 ; +} + +static bool mld_in_v1_mode_only (const struct inet6_dev *idev) +{ +return dev_net (idev->dev)->ipv6.devconf_all->force_mld_version ==1 ; +} +static bool mld_in_v1_mode (const struct inet6_dev *idev) { -if (dev_net (idev->dev)->ipv6.devconf_all->force_mld_version ==1 ) +if (mld_in_v2_mode_only (idev)) +return false; +if (mld_in_v1_mode_only (idev))return true;if (idev->cnf.force_mld_version ==1 )return true;
@@ -1223,7 +1235,6 @@ int igmp6_event_query(struct sk_buff *skb)return -EINVAL ; idev =__in6_dev_get (skb->dev); -if (idev ==NULL )return 0 ;
@@ -1236,6 +1247,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
RFC PATCH 5/7 net: ipv6: mld: restrict min/max of sysctl force_mld_version
In reply to Daniel BorkmannRestrict minimum and maximum values that are allowed to be set by the administrator for force_mld_version into sysctl:
0 - No enforcement of any MLD version
1 - Enforce to use MLD version 1
2 - Enforce to use MLD version 2
--- net/ipv6/addrconf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv6/addrconf.c +6 -1
@@ -106,6 +106,9 @@#define INFINITY_LIFE_TIME 0xFFFFFFFF +static int zero =0 ; +static int two =2 ; +static inline u32 cstamp_delta (unsigned long cstamp) {return (cstamp -INITIAL_JIFFIES ) *100UL /HZ ;
@@ -4842,7 +4845,9 @@ static struct addrconf_sysctl_table .data = &ipv6_devconf.force_mld_version, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &two, }, { .procname = "mldv1_unsolicited_report_interval",
Signature · 1 line
1.7.11.7
RFC PATCH 6/7 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);
@@ -1247,12 +1244,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
RFC PATCH 7/7 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: Fri, 30 Aug 2013 18:58:21 +0200
Quoted 7 lines
If there are no further objections, I'll send out the non-RFC version on Monday after some more testing. That's just a heads up. This set includes my improved fix from yesterday as well besides other things.
Thanks!
From a coding style and general correctness perspective these changes
look fine to me.
I'll let IPV6 MLD experts comment on the semantic part.