BACKPORT: ipv6 addrconf: implement RFC7559 router solicitation backoff
This implements: https://tools.ietf.org/html/rfc7559 Backoff is performed according to RFC3315 section 14: https://tools.ietf.org/html/rfc3315#section-14 We allow setting /proc/sys/net/ipv6/conf/*/router_solicitations to a negative value meaning an unlimited number of retransmits, and we make this the new default (inline with the RFC). We also add a new setting: /proc/sys/net/ipv6/conf/*/router_solicitation_max_interval defaulting to 1 hour (per RFC recommendation). Signed-off-by: Maciej Żenczykowski <maze@google.com> Acked-by: Erik Kline <ek@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit bd11f0741fa5a2c296629898ad07759dd12b35bb in DaveM's net-next/master, should make Linus' tree in 4.9-rc1) Change-Id: Ia32cdc5c61481893ef8040734e014bf2229fc39e Git-commit: ce2d59ac01f3b8d29441d29449653fb25bb83f2a Git-repo: https://android.googlesource.com/kernel/common.git [resolved trivial merge conflicts] Signed-off-by: Srinivasarao P <spathi@codeaurora.org>
This commit is contained in:
parent
ee8d8d6381
commit
454fd4e57c
|
@ -17,6 +17,7 @@ struct ipv6_devconf {
|
|||
__s32 dad_transmits;
|
||||
__s32 rtr_solicits;
|
||||
__s32 rtr_solicit_interval;
|
||||
__s32 rtr_solicit_max_interval;
|
||||
__s32 rtr_solicit_delay;
|
||||
__s32 force_mld_version;
|
||||
#ifdef CONFIG_IPV6_PRIVACY
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef _ADDRCONF_H
|
||||
#define _ADDRCONF_H
|
||||
|
||||
#define MAX_RTR_SOLICITATIONS 3
|
||||
#define MAX_RTR_SOLICITATIONS -1 /* unlimited */
|
||||
#define RTR_SOLICITATION_INTERVAL (4*HZ)
|
||||
#define RTR_SOLICITATION_MAX_INTERVAL (3600*HZ) /* 1 hour */
|
||||
|
||||
#define MIN_VALID_LIFETIME (2*3600) /* 2 hours */
|
||||
|
||||
|
|
|
@ -199,6 +199,7 @@ struct inet6_dev {
|
|||
struct ipv6_devstat stats;
|
||||
|
||||
struct timer_list rs_timer;
|
||||
__s32 rs_interval; /* in jiffies */
|
||||
__u8 rs_probes;
|
||||
|
||||
unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
|
||||
|
|
|
@ -162,7 +162,12 @@ enum {
|
|||
DEVCONF_NDISC_NOTIFY,
|
||||
DEVCONF_ACCEPT_RA_PREFIX_ROUTE,
|
||||
DEVCONF_ACCEPT_RA_RT_TABLE,
|
||||
DEVCONF_MLDV1_UNSOLICITED_REPORT_INTERVAL,
|
||||
DEVCONF_MLDV2_UNSOLICITED_REPORT_INTERVAL,
|
||||
DEVCONF_SUPPRESS_FRAG_NDISC,
|
||||
DEVCONF_ACCEPT_RA_FROM_LOCAL,
|
||||
DEVCONF_ACCEPT_RA_MTU,
|
||||
DEVCONF_STABLE_SECRET,
|
||||
DEVCONF_USE_OIF_ADDRS_ONLY,
|
||||
DEVCONF_USE_OPTIMISTIC,
|
||||
DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT,
|
||||
|
|
|
@ -113,6 +113,27 @@ static inline u32 cstamp_delta(unsigned long cstamp)
|
|||
return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
|
||||
}
|
||||
|
||||
static inline s32 rfc3315_s14_backoff_init(s32 irt)
|
||||
{
|
||||
/* multiply 'initial retransmission time' by 0.9 .. 1.1 */
|
||||
u64 tmp = (900000 + prandom_u32() % 200001) * (u64)irt;
|
||||
do_div(tmp, 1000000);
|
||||
return (s32)tmp;
|
||||
}
|
||||
|
||||
static inline s32 rfc3315_s14_backoff_update(s32 rt, s32 mrt)
|
||||
{
|
||||
/* multiply 'retransmission timeout' by 1.9 .. 2.1 */
|
||||
u64 tmp = (1900000 + prandom_u32() % 200001) * (u64)rt;
|
||||
do_div(tmp, 1000000);
|
||||
if ((s32)tmp > mrt) {
|
||||
/* multiply 'maximum retransmission time' by 0.9 .. 1.1 */
|
||||
tmp = (900000 + prandom_u32() % 200001) * (u64)mrt;
|
||||
do_div(tmp, 1000000);
|
||||
}
|
||||
return (s32)tmp;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SYSCTL
|
||||
static void addrconf_sysctl_register(struct inet6_dev *idev);
|
||||
static void addrconf_sysctl_unregister(struct inet6_dev *idev);
|
||||
|
@ -184,6 +205,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
|
|||
.dad_transmits = 1,
|
||||
.rtr_solicits = MAX_RTR_SOLICITATIONS,
|
||||
.rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
|
||||
.rtr_solicit_max_interval = RTR_SOLICITATION_MAX_INTERVAL,
|
||||
.rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
|
||||
#ifdef CONFIG_IPV6_PRIVACY
|
||||
.use_tempaddr = 0,
|
||||
|
@ -223,6 +245,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
|
|||
.dad_transmits = 1,
|
||||
.rtr_solicits = MAX_RTR_SOLICITATIONS,
|
||||
.rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
|
||||
.rtr_solicit_max_interval = RTR_SOLICITATION_MAX_INTERVAL,
|
||||
.rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
|
||||
#ifdef CONFIG_IPV6_PRIVACY
|
||||
.use_tempaddr = 0,
|
||||
|
@ -3281,7 +3304,7 @@ static void addrconf_rs_timer(unsigned long data)
|
|||
if (idev->if_flags & IF_RA_RCVD)
|
||||
goto out;
|
||||
|
||||
if (idev->rs_probes++ < idev->cnf.rtr_solicits) {
|
||||
if (idev->rs_probes++ < idev->cnf.rtr_solicits || idev->cnf.rtr_solicits < 0) {
|
||||
write_unlock(&idev->lock);
|
||||
if (!ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE))
|
||||
ndisc_send_rs(dev, &lladdr,
|
||||
|
@ -3290,11 +3313,13 @@ static void addrconf_rs_timer(unsigned long data)
|
|||
goto put;
|
||||
|
||||
write_lock(&idev->lock);
|
||||
idev->rs_interval = rfc3315_s14_backoff_update(
|
||||
idev->rs_interval, idev->cnf.rtr_solicit_max_interval);
|
||||
/* The wait after the last probe can be shorter */
|
||||
addrconf_mod_rs_timer(idev, (idev->rs_probes ==
|
||||
idev->cnf.rtr_solicits) ?
|
||||
idev->cnf.rtr_solicit_delay :
|
||||
idev->cnf.rtr_solicit_interval);
|
||||
idev->rs_interval);
|
||||
} else {
|
||||
/*
|
||||
* Note: we do not support deprecated "all on-link"
|
||||
|
@ -3496,7 +3521,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
|
|||
*/
|
||||
|
||||
if (ipv6_accept_ra(ifp->idev) &&
|
||||
ifp->idev->cnf.rtr_solicits > 0 &&
|
||||
ifp->idev->cnf.rtr_solicits != 0 &&
|
||||
(dev->flags&IFF_LOOPBACK) == 0 &&
|
||||
(ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
|
||||
/*
|
||||
|
@ -3512,10 +3537,11 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
|
|||
|
||||
write_lock_bh(&ifp->idev->lock);
|
||||
spin_lock(&ifp->lock);
|
||||
ifp->idev->rs_interval = rfc3315_s14_backoff_init(
|
||||
ifp->idev->cnf.rtr_solicit_interval);
|
||||
ifp->idev->rs_probes = 1;
|
||||
ifp->idev->if_flags |= IF_RS_SENT;
|
||||
addrconf_mod_rs_timer(ifp->idev,
|
||||
ifp->idev->cnf.rtr_solicit_interval);
|
||||
addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval);
|
||||
spin_unlock(&ifp->lock);
|
||||
write_unlock_bh(&ifp->idev->lock);
|
||||
}
|
||||
|
@ -4363,6 +4389,8 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
|
|||
array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits;
|
||||
array[DEVCONF_RTR_SOLICIT_INTERVAL] =
|
||||
jiffies_to_msecs(cnf->rtr_solicit_interval);
|
||||
array[DEVCONF_RTR_SOLICIT_MAX_INTERVAL] =
|
||||
jiffies_to_msecs(cnf->rtr_solicit_max_interval);
|
||||
array[DEVCONF_RTR_SOLICIT_DELAY] =
|
||||
jiffies_to_msecs(cnf->rtr_solicit_delay);
|
||||
array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version;
|
||||
|
@ -4548,7 +4576,7 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
|
|||
return -EINVAL;
|
||||
if (!ipv6_accept_ra(idev))
|
||||
return -EINVAL;
|
||||
if (idev->cnf.rtr_solicits <= 0)
|
||||
if (idev->cnf.rtr_solicits == 0)
|
||||
return -EINVAL;
|
||||
|
||||
write_lock_bh(&idev->lock);
|
||||
|
@ -5019,6 +5047,13 @@ static struct addrconf_sysctl_table
|
|||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_jiffies,
|
||||
},
|
||||
{
|
||||
.procname = "router_solicitation_max_interval",
|
||||
.data = &ipv6_devconf.rtr_solicit_max_interval,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_jiffies,
|
||||
},
|
||||
{
|
||||
.procname = "router_solicitation_delay",
|
||||
.data = &ipv6_devconf.rtr_solicit_delay,
|
||||
|
|
Loading…
Reference in New Issue