Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 575880f2 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Greg Kroah-Hartman
Browse files

net: ipv4: use a dedicated counter for icmp_v4 redirect packets



[ Upstream commit c09551c6ff7fe16a79a42133bcecba5fc2fc3291 ]

According to the algorithm described in the comment block at the
beginning of ip_rt_send_redirect, the host should try to send
'ip_rt_redirect_number' ICMP redirect packets with an exponential
backoff and then stop sending them at all assuming that the destination
ignores redirects.
If the device has previously sent some ICMP error packets that are
rate-limited (e.g TTL expired) and continues to receive traffic,
the redirect packets will never be transmitted. This happens since
peer->rate_tokens will be typically greater than 'ip_rt_redirect_number'
and so it will never be reset even if the redirect silence timeout
(ip_rt_redirect_silence) has elapsed without receiving any packet
requiring redirects.

Fix it by using a dedicated counter for the number of ICMP redirect
packets that has been sent by the host

I have not been able to identify a given commit that introduced the
issue since ip_rt_send_redirect implements the same rate-limiting
algorithm from commit 1da177e4 ("Linux-2.6.12-rc2")

Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2a3c6898
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ struct inet_peer {


	u32			metrics[RTAX_MAX];
	u32			metrics[RTAX_MAX];
	u32			rate_tokens;	/* rate limiting for ICMP */
	u32			rate_tokens;	/* rate limiting for ICMP */
	u32			n_redirects;
	unsigned long		rate_last;
	unsigned long		rate_last;
	union {
	union {
		struct list_head	gc_list;
		struct list_head	gc_list;
+1 −0
Original line number Original line Diff line number Diff line
@@ -448,6 +448,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base,
		atomic_set(&p->rid, 0);
		atomic_set(&p->rid, 0);
		p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
		p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
		p->rate_tokens = 0;
		p->rate_tokens = 0;
		p->n_redirects = 0;
		/* 60*HZ is arbitrary, but chosen enough high so that the first
		/* 60*HZ is arbitrary, but chosen enough high so that the first
		 * calculation of tokens is at its maximum.
		 * calculation of tokens is at its maximum.
		 */
		 */
+5 −2
Original line number Original line Diff line number Diff line
@@ -882,13 +882,15 @@ void ip_rt_send_redirect(struct sk_buff *skb)
	/* No redirected packets during ip_rt_redirect_silence;
	/* No redirected packets during ip_rt_redirect_silence;
	 * reset the algorithm.
	 * reset the algorithm.
	 */
	 */
	if (time_after(jiffies, peer->rate_last + ip_rt_redirect_silence))
	if (time_after(jiffies, peer->rate_last + ip_rt_redirect_silence)) {
		peer->rate_tokens = 0;
		peer->rate_tokens = 0;
		peer->n_redirects = 0;
	}


	/* Too many ignored redirects; do not send anything
	/* Too many ignored redirects; do not send anything
	 * set dst.rate_last to the last seen redirected packet.
	 * set dst.rate_last to the last seen redirected packet.
	 */
	 */
	if (peer->rate_tokens >= ip_rt_redirect_number) {
	if (peer->n_redirects >= ip_rt_redirect_number) {
		peer->rate_last = jiffies;
		peer->rate_last = jiffies;
		goto out_put_peer;
		goto out_put_peer;
	}
	}
@@ -905,6 +907,7 @@ void ip_rt_send_redirect(struct sk_buff *skb)
		icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
		icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
		peer->rate_last = jiffies;
		peer->rate_last = jiffies;
		++peer->rate_tokens;
		++peer->rate_tokens;
		++peer->n_redirects;
#ifdef CONFIG_IP_ROUTE_VERBOSE
#ifdef CONFIG_IP_ROUTE_VERBOSE
		if (log_martians &&
		if (log_martians &&
		    peer->rate_tokens == ip_rt_redirect_number)
		    peer->rate_tokens == ip_rt_redirect_number)