lkml.org 
[lkml]   [2022]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/2] ipv4: Namespaceify route/error_cost knob
Date
From: xu xin <xu.xin16@zte.com.cn>

Different netns has different requirement on the setting of error_cost
sysctl which is used to limit the max frequency of sending
ICMP_DEST_UNREACH packet together with error_burst.

Enable error_cost to be configured per network namespace.

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
include/net/netns/ipv4.h | 1 +
net/ipv4/route.c | 20 ++++++++++----------
2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index c7320ef356d9..319395bbad3c 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -85,6 +85,7 @@ struct netns_ipv4 {
u32 ip_rt_min_pmtu;
int ip_rt_mtu_expires;
int ip_rt_min_advmss;
+ int ip_rt_error_cost;

struct local_ports ip_local_ports;

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 795cbe1de912..0598393e03ac 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -118,7 +118,6 @@ static int ip_rt_max_size;
static int ip_rt_redirect_number __read_mostly = 9;
static int ip_rt_redirect_load __read_mostly = HZ / 50;
static int ip_rt_redirect_silence __read_mostly = ((HZ / 50) << (9 + 1));
-static int ip_rt_error_cost __read_mostly = HZ;
static int ip_rt_error_burst __read_mostly = 5 * HZ;

static int ip_rt_gc_timeout __read_mostly = RT_GC_TIMEOUT;
@@ -1005,8 +1004,8 @@ static int ip_error(struct sk_buff *skb)
if (peer->rate_tokens > ip_rt_error_burst)
peer->rate_tokens = ip_rt_error_burst;
peer->rate_last = now;
- if (peer->rate_tokens >= ip_rt_error_cost)
- peer->rate_tokens -= ip_rt_error_cost;
+ if (peer->rate_tokens >= net->ipv4.ip_rt_error_cost)
+ peer->rate_tokens -= net->ipv4.ip_rt_error_cost;
else
send = false;
inet_putpeer(peer);
@@ -3535,13 +3534,6 @@ static struct ctl_table ipv4_route_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec,
},
- {
- .procname = "error_cost",
- .data = &ip_rt_error_cost,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = proc_dointvec,
- },
{
.procname = "error_burst",
.data = &ip_rt_error_burst,
@@ -3590,6 +3582,13 @@ static struct ctl_table ipv4_route_netns_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec,
},
+ {
+ .procname = "error_cost",
+ .data = &init_net.ipv4.ip_rt_error_cost,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
{ },
};

@@ -3653,6 +3652,7 @@ static __net_init int netns_ip_rt_init(struct net *net)
net->ipv4.ip_rt_min_pmtu = DEFAULT_MIN_PMTU;
net->ipv4.ip_rt_mtu_expires = DEFAULT_MTU_EXPIRES;
net->ipv4.ip_rt_min_advmss = DEFAULT_MIN_ADVMSS;
+ net->ipv4.ip_rt_error_cost = HZ;
return 0;
}

--
2.25.1
\
 
 \ /
  Last update: 2022-08-16 09:02    [W:0.227 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site