ipv4: Don't pre-seed hoplimit metric.
Subsystems (6)
David Miller
maintainerPATCH 3/3 ipv4: Don't pre-seed hoplimit metric.
Always go through a new ip4_dst_hoplimit() helper, just like ipv6.
This allowed several simplifications:
1) The interim dst_metric_hoplimit() can go as it's no longer userd.
2) The sysctl_ip_default_ttl entry no longer needs to use ipv4_doint_and_flush, since the sysctl is not cached in routing cache metrics any longer.
3) ipv4_doint_and_flush no longer needs to be exported and therefore can be marked static.
When ipv4_doint_and_flush_strategy was removed some time ago, the external declaration in ip.h was mistakenly left around so kill that off too.
We have to move the sysctl_ip_default_ttl declaration into ipv4's route cache definition header net/route.h, because currently net/ip.h (where the declaration lives now) has a back dependency on net/route.h
--- drivers/net/pptp.c | 2 +- include/net/dst.h | 6 ------ include/net/ip.h | 10 ---------- include/net/route.h | 11 +++++++++++ net/ipv4/devinet.c | 6 +++--- net/ipv4/ip_gre.c | 2 +- net/ipv4/ip_output.c | 3 ++- net/ipv4/netfilter/ipt_REJECT.c | 2 +- net/ipv4/route.c | 2 -- net/ipv4/sysctl_net_ipv4.c | 2 +- net/ipv4/xfrm4_mode_tunnel.c | 2 +- 11 files changed, 21 insertions(+), 27 deletions(-)
drivers/net/pptp.c +1 -1
@@ -277,7 +277,7 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb) iph->tos =0 ; iph->daddr = rt->rt_dst; iph->saddr = rt->rt_src; - iph->ttl =dst_metric_hoplimit (&rt->dst); + iph->ttl =ip4_dst_hoplimit (&rt->dst); iph->tot_len =htons (skb->len);skb_dst_drop (skb);
include/net/dst.h +0 -6
@@ -116,12 +116,6 @@ dst_metric(const struct dst_entry *dst, const int metric)return dst_metric_raw (dst, metric); } -static inline u32 -dst_metric_hoplimit (const struct dst_entry *dst) -{ -return dst_metric_raw (dst,RTAX_HOPLIMIT ); -} -static inline void dst_metric_set (struct dst_entry *dst,int metric,u32 val) { dst->_metrics[metric-1 ] = val;
include/net/ip.h +0 -10
@@ -201,7 +201,6 @@ static inline int inet_is_reserved_local_port(int port)return test_bit (port, sysctl_local_reserved_ports); } -extern int sysctl_ip_default_ttl;extern int sysctl_ip_nonlocal_bind;extern struct ctl_path net_core_path[];
@@ -428,15 +427,6 @@ extern void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,extern void ip_local_error (struct sock *sk,int err,__be32 daddr,__be16 dport,u32 info); -/* sysctl helpers - any sysctl which holds a value that ends up being -* fed into the routing cache should use these handlers. -*/ -int ipv4_doint_and_flush (ctl_table *ctl,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos); -int ipv4_doint_and_flush_strategy (ctl_table *table, -void __user *oldval,size_t __user *oldlenp, -void __user *newval,size_t newlen);#ifdef CONFIG_PROC_FS extern int ip_misc_proc_init (void );#endif
include/net/route.h +11 -0
@@ -231,4 +231,15 @@ static inline int inet_iif(const struct sk_buff *skb) return skb_rtable(skb)->rt_iif; } +extern int sysctl_ip_default_ttl; + +static inline int ip4_dst_hoplimit (const struct dst_entry *dst) +{ +int hoplimit =dst_metric_raw (dst,RTAX_HOPLIMIT ); + +if (hoplimit ==0 ) + hoplimit = sysctl_ip_default_ttl; +return hoplimit; +} +#endif /* _ROUTE_H */
net/ipv4/devinet.c +3 -3
@@ -1430,9 +1430,9 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,return ret; } -int ipv4_doint_and_flush (ctl_table *ctl,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos) +static int ipv4_doint_and_flush (ctl_table *ctl,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos) {int *valp = ctl->data;int val = *valp;
net/ipv4/ip_gre.c +1 -1
@@ -890,7 +890,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev iph->ttl = ((struct ipv6hdr *)old_iph)->hop_limit;#endif else - iph->ttl = dst_metric_hoplimit(&rt->dst); + iph->ttl = ip4_dst_hoplimit(&rt->dst); } ((__be16 *)(iph +1 ))[0 ] = tunnel->parms.o_flags;
net/ipv4/ip_output.c +2 -1
@@ -82,6 +82,7 @@#include <linux/tcp.h> int sysctl_ip_default_ttl__read_mostly =IPDEFTTL ; +EXPORT_SYMBOL (sysctl_ip_default_ttl);/* Generate a checksum for an outgoing IP datagram. */ __inline__void ip_send_check (struct iphdr *iph)
@@ -130,7 +131,7 @@ static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)int ttl = inet->uc_ttl;if (ttl <0 ) - ttl =dst_metric_hoplimit (dst); + ttl =ip4_dst_hoplimit (dst);return ttl; }
net/ipv4/netfilter/ipt_REJECT.c +1 -1
@@ -116,7 +116,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)if (ip_route_me_harder (nskb, addr_type)) goto free_nskb; - niph->ttl =dst_metric_hoplimit (skb_dst (nskb)); + niph->ttl =ip4_dst_hoplimit (skb_dst (nskb));/* "Never happens" */ if (nskb->len >dst_mtu (skb_dst (nskb)))
net/ipv4/route.c +0 -2
@@ -1821,8 +1821,6 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag) }else dst_metric_set (dst,RTAX_MTU , dst->dev->mtu); -if (dst_metric_raw (dst,RTAX_HOPLIMIT ) ==0 ) -dst_metric_set (dst,RTAX_HOPLIMIT , sysctl_ip_default_ttl);if (dst_mtu (dst) >IP_MAX_MTU )dst_metric_set (dst,RTAX_MTU ,IP_MAX_MTU );if (dst_metric (dst,RTAX_ADVMSS ) ==0 )
net/ipv4/sysctl_net_ipv4.c +1 -1
@@ -155,7 +155,7 @@ static struct ctl_table ipv4_table[] = { .data = &sysctl_ip_default_ttl, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = ipv4_doint_and_flush, + .proc_handler = proc_dointvec, .extra2 = &init_net, }, {
net/ipv4/xfrm4_mode_tunnel.c +1 -1
@@ -56,7 +56,7 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) 0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));ip_select_ident (top_iph, dst->child,NULL ); - top_iph->ttl =dst_metric_hoplimit (dst->child); + top_iph->ttl =ip4_dst_hoplimit (dst->child); top_iph->saddr = x->props.saddr.a4; top_iph->daddr = x->id.daddr.a4;
Signature · 1 line
1.7.3.2
PATCH 1/1 net: add limits to ip_default_ttl
Quoted 29 lines · David Miller
Always go through a new
ip4_dst_hoplimit()helper, just like ipv6.This allowed several simplifications:
1) The interim
dst_metric_hoplimit()can go as it's no longer userd.2) The
sysctl_ip_default_ttlentry no longer needs to useipv4_doint_and_flush, since the sysctl is not cached in routing cache metrics any longer.3)
ipv4_doint_and_flushno longer needs to be exported and therefore can be marked static.When
ipv4_doint_and_flush_strategywas removed some time ago, the external declaration inip.hwas mistakenly left around so kill that off too.We have to move the
sysctl_ip_default_ttldeclaration into ipv4's route cache definition headernet/route.h, because currentlynet/ip.h(where the declaration lives now) has a back dependency onnet/route.hSigned-off-by David S. Miller <[email protected]>---
net/ipv4/sysctl_net_ipv4.c static struct ctl_table ipv4_table[] = { · line 160
Quoted 7 lines
net/ipv4/sysctl_net_ipv4.c +1
-1@@ -155,7 +155,7 @@ static struct ctl_table ipv4_table[] = { .data = &sysctl_ip_default_ttl, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = ipv4_doint_and_flush, + .proc_handler = proc_dointvec, .extra2 = &init_net, },
Please find following patch then, because extra2 is not anymore used.
BTW, I cant find where extra2 was set to actual struct net pointer in net-2.6 kernel. I suspect a write on /proc/sys/net/ipv4/ip_default_ttl was flushing routes of initial net only, not current one ?
I can see this extra2 param properly handled in __devinet_sysctl_register() for /proc/net/ipv4/conf parameters, not for ip_default_ttl.
For net-next-2.6, we could remove the line, or we could add sensible limits ;)
[PATCH net-next-2.6] net: add limits to ip_default_ttl
ip_default_ttl should be between 1 and 255
--- net/ipv4/sysctl_net_ipv4.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/sysctl_net_ipv4.c +5 -2
@@ -28,6 +28,8 @@ static int ip_local_port_range_min[] = { 1, 1 };static int ip_local_port_range_max[] = {65535 ,65535 };static int tcp_adv_win_scale_min =-31 ;static int tcp_adv_win_scale_max =31 ; +static int ip_ttl_min =1 ; +static int ip_ttl_max =255 ;/* Update system visible IP port range */ static void set_local_port_range (int range[2 ])
@@ -155,8 +157,9 @@ static struct ctl_table ipv4_table[] = { .data = &sysctl_ip_default_ttl, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, - .extra2 = &init_net, + .proc_handler = proc_dointvec_minmax, + .extra1 = &ip_ttl_min, + .extra2 = &ip_ttl_max, }, { .procname = "ip_no_pmtu_disc",
Re: [PATCH net-next-2.6] net: add limits to ip_default_ttl
From: Eric Dumazet <[email protected]>
Date: Mon, 13 Dec 2010 21:08:32 +0100
Quoted 2 lines · David Miller
Quoted 1 line
Always go through a new
ip4_dst_hoplimit()helper, just like ipv6.
...
Quoted 1 line
Please find following patch then, because extra2 is not anymore used.
Ok.
Quoted 3 lines
BTW, I cant find where extra2 was set to actual struct net pointer in net-2.6 kernel. I suspect a write on
/proc/sys/net/ipv4/ip_default_ttlwas flushing routes of initial net only, not current one ?
It appears that way.
Quoted 5 lines
[PATCH net-next-2.6] net: add limits to
ip_default_ttl
ip_default_ttlshould be between 1 and 255Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.
Re: [PATCH net-next-2.6] net: add limits to ip_default_ttl
Quoted 1 line · David Miller
Applied, thanks Eric.
I forgot the Documentation changes as well, sorry :(
[PATCH] net: change ip_default_ttl documentation
--- Documentation/networking/ip-sysctl.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.txt +3 -1
@@ -11,7 +11,9 @@ ip_forward - BOOLEAN for routers) ip_default_ttl - INTEGER - default 64 + Default value of TTL field (Time To Live) for outgoing (but not + forwarded) IP packets. Should be between 1 and 255 inclusive. + Default: 64 (as recommended by RFC1700) ip_no_pmtu_disc - BOOLEAN Disable Path MTU Discovery.
David Miller
maintainerRe: [PATCH net-next-2.6] net: add limits to ip_default_ttl
From: Eric Dumazet <[email protected]>
Date: Mon, 13 Dec 2010 21:43:09 +0100
Quoted 10 lines · David Miller
Quoted 2 lines
Applied, thanks Eric.
I forgot the Documentation changes as well, sorry :(
[PATCH] net: change
ip_default_ttldocumentationSigned-off-by Eric Dumazet <[email protected]>
Also applied, thanks.