dont create cached routes from ARP requests
Subsystems (3)
RFC PATCH 1/1 dont create cached routes from ARP requests
Do we really have to cache routes based on ARP requests? Are there any other reasons than expecting new connections?
Attached is a patch to skip caching for ARP requests not related to local IP addresses or ARP proxy.
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.
Cheers
Ulrich
---
[PATCH] dont create cached routes from ARP requests
except for local destination or enabled ARP proxy. Otherwise Neighbour table can overflow on broken network setups.
--- include/linux/in_route.h | 1 + net/ipv4/route.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletions(-)
include/linux/in_route.h +1 -0
@@ -18,6 +18,7 @@#define RTCF_MASQ 0x00400000/* unused */ #define RTCF_SNAT 0x00800000/* unused */ #define RTCF_DOREDIRECT 0x01000000 +#define RTCF_NOCACHE 0x02000000#define RTCF_DIRECTSRC 0x04000000#define RTCF_DNAT 0x08000000#define RTCF_BROADCAST 0x10000000
net/ipv4/route.c +4 -1
@@ -1090,7 +1090,7 @@ restart: candp =NULL ; now = jiffies; -if (!rt_caching (dev_net (rt->dst.dev))) { +if (rt->rt_flags &RTCF_NOCACHE || !rt_caching (dev_net (rt->dst.dev))) {/* * If we're not caching, just tell the caller we * were successful and don't touch the route. The
@@ -2001,6 +2001,9 @@ static int __mkroute_input(struct sk_buff *skb, err = -EINVAL ; goto cleanup; } +if (!(out_dev->dev->flags &IFF_LOOPBACK ) && + !IN_DEV_PROXY_ARP (in_dev) && !IN_DEV_PROXY_ARP_PVLAN (in_dev)) + flags |=RTCF_NOCACHE ; }
Signature · 1 line
1.7.0.4
David Miller
maintainerFrom: Ulrich Weber <[email protected]>
Date: Wed, 22 Sep 2010 18:22:09 +0200
Quoted 6 lines
Do we really have to cache routes based on ARP requests? Are there any other reasons than expecting new connections?
Attached is a patch to skip caching for ARP requests not related to local IP addresses or ARP proxy.
Quoted 6 lines
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.
If you get neighbour table overflows, something is holding a reference to the routing cache entry and/or the neighbour entries those routing cache entries are attached to.
If these really are transient entries, they should be trivially garbage collected and not cause any problems at all.
Quoted 10 lines · David Miller
From: Ulrich Weber <[email protected]>
Date: Wed, 22 Sep 2010 18:22:09 +0200Quoted 6 lines
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.
Quoted 6 lines
If you get neighbour table overflows, something is holding a reference to the routing cache entry and/or the neighbour entries those routing cache entries are attached to.
If these really are transient entries, they should be trivially garbage collected and not cause any problems at all.
rt_garbage_collect is not called within rt_intern_hash, because the call is done within softirq context.
Forcing the call of rt_garbage_collect didn't help either, there are no routes freed afterwards...
Cheers
Ulrich
Quoted 15 lines · Ulrich Weber
Quoted 14 lines · David Miller
From: Ulrich Weber <[email protected]>
Date: Wed, 22 Sep 2010 18:22:09 +0200Quoted 6 lines
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.If you get neighbour table overflows, something is holding a reference to the routing cache entry and/or the neighbour entries those routing cache entries are attached to.
Quoted 8 lines
Quoted 2 lines
If these really are transient entries, they should be trivially garbage collected and not cause any problems at all.
rt_garbage_collectis not called withinrt_intern_hash, because the call is done within softirq context.Forcing the call of
rt_garbage_collectdidn't help either, there are no routes freed afterwards...
Please give us more information.
grep . /proc/sys/net/ipv4/route/*
rtstat -c10 -i1
Thanks
David Miller
maintainerFrom: Ulrich Weber <[email protected]>
Date: Thu, 23 Sep 2010 16:47:08 +0200
Quoted 2 lines
Forcing the call of
rt_garbage_collectdidn't help either, there are no routes freed afterwards...
Then you need to find out why :-)
Hi Eric,
please find the output in the attached text file.
Neighbor garbage collection wont't work because all neighbor records are bound to cached routes.
Forced route garbaged collections returns without freeing any routes, probably because the route threshold is quite high with 65536 compared to the small neighbor threshold of 1024, resulting in a fixed amount of 1024 cached routes...
Instead of running the garbage collection we could flush the route cache completely if the neighbor cache overflows.
But why do we have to cache that routes in first place ? See the previous patch which skips caching for that kind of routes.
Cheers
Ulrich
/proc/sys/net/ipv4/route/error_burst:1250/proc/sys/net/ipv4/route/error_cost:250/proc/sys/net/ipv4/route/gc_elasticity:8/proc/sys/net/ipv4/route/gc_interval:60/proc/sys/net/ipv4/route/gc_min_interval:0/proc/sys/net/ipv4/route/gc_min_interval_ms:500/proc/sys/net/ipv4/route/gc_thresh:65536/proc/sys/net/ipv4/route/gc_timeout:300/proc/sys/net/ipv4/route/max_size:1048576/proc/sys/net/ipv4/route/min_adv_mss:256/proc/sys/net/ipv4/route/min_pmtu:552/proc/sys/net/ipv4/route/mtu_expires:600/proc/sys/net/ipv4/route/redirect_load:5/proc/sys/net/ipv4/route/redirect_number:9/proc/sys/net/ipv4/route/redirect_silence:5120
/proc/sys/net/ipv4/neigh/default/gc_interval:30/proc/sys/net/ipv4/neigh/default/gc_stale_time:60/proc/sys/net/ipv4/neigh/default/gc_thresh1:128/proc/sys/net/ipv4/neigh/default/gc_thresh2:512/proc/sys/net/ipv4/neigh/default/gc_thresh3:1024
net-next:
rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|
entries| in_hit|in_slow_|in_slow_|in_no_ro| in_brd|in_marti|in_marti| out_hit|out_slow|out_slow|gc_total|gc_ignor|gc_goal_|gc_dst_o|in_hlist|out_hlis|
| | tot| mc| ute| | an_dst| an_src| | _tot| _mc| | ed| miss| verflow| _search|t_search|
10| 255| 2| 1| 0| 0| 0| 0| 128| 17| 2| 0| 0| 0| 0| 15| 3|
199| 1| 189| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
433| 190| 234| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
433| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0|
433| 235| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
533| 119| 100| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0|
533| 219| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
533| 219| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
551| 406| 18| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
551| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
551| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
973| 1| 422| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 9| 0|
973| 423| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
973| 423| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 357| 68| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 413| 11| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 413| 11| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 124| 300| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 124| 300| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|
1030| 125| 300| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 2| 0|next-next with forced rt_garbage_collect
rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|
entries| in_hit|in_slow_|in_slow_|in_no_ro| in_brd|in_marti|in_marti| out_hit|out_slow|out_slow|gc_total|gc_ignor|gc_goal_|gc_dst_o|in_hlist|out_hlis|
| | tot| mc| ute| | an_dst| an_src| | _tot| _mc| | ed| miss| verflow| _search|t_search|
8| 43| 2| 0| 0| 0| 0| 0| 129| 20| 3| 0| 0| 0| 0| 1| 1|
138| 1| 130| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
431| 131| 293| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
431| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
431| 294| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
531| 120| 100| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
531| 220| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
531| 220| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0|
550| 405| 19| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
550| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
550| 424| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 3| 0|
972| 1| 422| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0|
972| 423| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0|
972| 423| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0|
1029| 358| 66| 0| 0| 0| 0| 0| 0| 0| 0| 9| 0| 0| 0| 1| 0|
1029| 415| 9| 0| 0| 0| 0| 0| 0| 0| 0| 9| 0| 0| 0| 1| 0|
1029| 415| 9| 0| 0| 0| 0| 0| 0| 0| 0| 9| 0| 0| 0| 1| 0|
1029| 122| 302| 0| 0| 0| 0| 0| 0| 0| 0| 302| 0| 0| 0| 2| 0|
1029| 122| 302| 0| 0| 0| 0| 0| 0| 0| 0| 302| 0| 0| 0| 2| 0|
1029| 122| 302| 0| 0| 0| 0| 0| 0| 0| 0| 302| 0| 0| 0| 2| 0|Quoted 12 lines · Ulrich Weber
Hi Eric,
please find the output in the attached text file.
Neighbor garbage collection wont't work because all neighbor records are bound to cached routes.
Forced route garbaged collections returns without freeing any routes, probably because the route threshold is quite high with 65536 compared to the small neighbor threshold of 1024, resulting in a fixed amount of 1024 cached routes...
Quoted 4 lines
Instead of running the garbage collection we could flush the route cache completely if the neighbor cache overflows.
But why do we have to cache that routes in first place ? See the previous patch which skips caching for that kind of routes.
What are the packets you receive ? A flood of ARP answers ?
a "tcpdump -X" of a few packets would help to understand.
Quoted 5 lines · Eric Dumazet
What are the packets you receive ? A flood of ARP answers ?
a "tcpdump -X" of a few packets would help to understand.
Also please report
grep . find /proc/sys -name arp_accept
Yes, as I wrote before my Cable ISP is flooding me with ARP requests from 10.0.0.0/8, which get a route via the primary PPP link.
I know thats not a common setup but why do that
kind of routes have to be cached ? :)
steps to reproduce:
server:
ip route add 1.0.0.0/8 dev dummy0
client:
ip route add 1.0.0.0/8 dev eth0
nmap --min-rate 500 -sP 1.0.0.0/8
Quoted 24 lines · Eric Dumazet
Quoted 12 lines · Ulrich Weber
Hi Eric,
please find the output in the attached text file.
Neighbor garbage collection wont't work because all neighbor records are bound to cached routes.
Forced route garbaged collections returns without freeing any routes, probably because the route threshold is quite high with 65536 compared to the small neighbor threshold of 1024, resulting in a fixed amount of 1024 cached routes...
Quoted 4 lines
Instead of running the garbage collection we could flush the route cache completely if the neighbor cache overflows.
But why do we have to cache that routes in first place ? See the previous patch which skips caching for that kind of routes.What are the packets you receive ? A flood of ARP answers ?
a "tcpdump -X" of a few packets would help to understand.
Signature · 3 lines
Ulrich Weber | [email protected] | Software Engineer Astaro GmbH & Co. KG | www.astaro.com | Phone +49-721-25516-0 | Fax –200 An der RaumFabrik 33a | 76227 Karlsruhe | Germany
/proc/sys/net/ipv4/conf/all/arp_accept:0/proc/sys/net/ipv4/conf/default/arp_accept:0/proc/sys/net/ipv4/conf/lo/arp_accept:0/proc/sys/net/ipv4/conf/eth0/arp_accept:0/proc/sys/net/ipv4/conf/dummy0/arp_accept:0
Quoted 15 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
What are the packets you receive ? A flood of ARP answers ?
a "tcpdump -X" of a few packets would help to understand.
Also please report
grep .
find /proc/sys -name arp_accept
Signature · 3 lines
Ulrich Weber | [email protected] | Software Engineer Astaro GmbH & Co. KG | www.astaro.com | Phone +49-721-25516-0 | Fax –200 An der RaumFabrik 33a | 76227 Karlsruhe | Germany
Quoted 8 lines · Ulrich Weber
Yes, as I wrote before my Cable ISP is flooding me with ARP requests from 10.0.0.0/8, which get a route via the primary PPP link.
I know thats not a common setup but why do that kind of routes have to be cached ? :)
Quoted 8 lines
steps to reproduce:
server:
ip route add 1.0.0.0/8 dev dummy0client:
ip route add 1.0.0.0/8 dev eth0
nmap --min-rate 500 -sP 1.0.0.0/8
Great, you use nmap and fill 'client' neighbour cache.
Now, back to the _real_ problem, please ?
<quote>
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.
</quote>
You receive an ARP request on device eth1,
this creates a route on eth0 ?
Could you send your routing/address setup ?
ip addr
ip ro
Quoted 11 lines · Eric Dumazet
Quoted 8 lines · Ulrich Weber
steps to reproduce:
server:
ip route add 1.0.0.0/8 dev dummy0client:
ip route add 1.0.0.0/8 dev eth0
nmap --min-rate 500 -sP 1.0.0.0/8Great, you use nmap and fill 'client' neighbour cache.
Nope, I fills the 'server' neighbor cache too
due cached routes in arp_process():
if (arp->ar_op == htons(ARPOP_REQUEST) &&
ip_route_input_noref(skb, tip, sip, 0, dev) == 0)Quoted 13 lines
Now, back to the _real_ problem, please ?
<quote>
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.</quote>
Quoted 8 lines
You receive an ARP request on device eth1,
this creates a route on eth0 ?Could you send your routing/address setup ?
ip addr
ip ro
ARP request flood comes in via eth2.
Have to correct myself: With configuration below only route cache increases but no "Neighbour table overflow".
By adding "ip route add 10.0.0.0/8 dev eth0" the Neighbor table overflow will occur.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
inet 78.43.x.x/22 brd 78.43.35.255 scope global eth2
12: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc hfsc
state UNKNOWN qlen 3
inet 95.114.x.x peer 213.20.56.129/32 scope global ppp0default via 213.20.56.129 dev ppp0
78.43.32.0/22 dev eth2 proto kernel scope link src 78.43.x.x 127.0.0.0/8 dev lo scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.1 213.20.56.129 dev ppp0 proto kernel scope link src 95.114.x.x
Signature · 3 lines
Ulrich Weber | [email protected] | Software Engineer Astaro GmbH & Co. KG | www.astaro.com | Phone +49-721-25516-0 | Fax –200 An der RaumFabrik 33a | 76227 Karlsruhe | Germany
Quoted 11 lines · Ulrich Weber
Quoted 10 lines · Eric Dumazet
Quoted 8 lines · Ulrich Weber
steps to reproduce:
server:
ip route add 1.0.0.0/8 dev dummy0client:
ip route add 1.0.0.0/8 dev eth0
nmap --min-rate 500 -sP 1.0.0.0/8
Quoted 6 lines
Quoted 1 line
Great, you use nmap and fill 'client' neighbour cache.
Nope, I fills the 'server' neighbor cache too
due cached routes inarp_process():if (arp->ar_op == htons(ARPOP_REQUEST) && ip_route_input_noref(skb, tip, sip, 0, dev) == 0)
It fills the "server neighbor cache" because you specifically said it has 2^24 ip addresses.
If using a normal route to gateway on eth0, it only fills route cache, with a max of 65536 slots on your config, not 1024. When max is reached, garbage collection takes place.
Quoted 23 lines
Quoted 14 lines
Now, back to the _real_ problem, please ?
<quote>
Background: At home I have two Internet connections, DSL and Cable. DSL is the primary uplink while Cable is the secondary. My Cable ISP is flooding me with ARP request from 10.0.0.0/8, which creates routes via the primary uplink.
There are thousands of cached routes and after some time I get "Neighbour table overflow" messages.</quote>
Quoted 8 lines
You receive an ARP request on device eth1,
this creates a route on eth0 ?Could you send your routing/address setup ?
ip addr
ip ro
Quoted 8 lines
ARP request flood comes in via eth2.
Have to correct myself: With configuration below only route cache increases but no "Neighbour table overflow".
By adding "ip route add 10.0.0.0/8 dev eth0" the Neighbor table overflow will occur.
Because you want instead "ip route add 10.0.0.0/8 via gateway" Or else you are vulnerable to an attack, as you discovered.
Here it works perfectly.
rtstat -c20 -i1|cut -c1-60
rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cache|rt_cac
entries| in_hit|in_slow_|in_slow_|in_no_ro| in_brd|in_mar
| | tot| mc| ute| | an_d 1984| 2| 1| 0| 0| 0|
1984| 2| 0| 0| 0| 0|
1984| 2| 0| 0| 0| 0|
1985| 4| 2| 0| 0| 0|
1988| 0| 4| 0| 0| 0|
2020| 1| 33| 0| 0| 0|
2042| 1| 23| 0| 0| 0|
2104| 0| 63| 0| 0| 0|
2117| 0| 14| 0| 0| 0|
2141| 0| 26| 0| 0| 0|
2159| 1| 19| 0| 0| 0|
2175| 0| 17| 0| 0| 0|
2221| 0| 48| 0| 0| 0|
2241| 0| 20| 0| 0| 0|
2256| 0| 17| 0| 0| 0|
2269| 3| 15| 0| 0| 0|
2286| 0| 17| 0| 0| 0|
2295| 1| 10| 0| 0| 0|
2326| 1| 33| 0| 0| 0| Quoted 14 lines
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 78.43.x.x/22 brd 78.43.35.255 scope global eth2 12: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc hfsc state UNKNOWN qlen 3 inet 95.114.x.x peer 213.20.56.129/32 scope global ppp0
Quoted 7 lines
default via 213.20.56.129 dev ppp0
78.43.32.0/22 dev eth2 proto kernel scope link src 78.43.x.x 127.0.0.0/8 dev lo scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.1 213.20.56.129 dev ppp0 proto kernel scope link src 95.114.x.x
Thanks
Hi Eric,
thanks for the correction! Searched through the log files and discovered that the initial "Neighbor overflow" message was caused by an IPv6 ping scan from the Internet.
rt_garbage_collect() is called from dst_alloc and rt_intern_hash. In any case no routes will be freed if the total entries are smaller than ipv4.route.gc_thresh.
neigh.default.gc_thresh is static while ipv4.route.gc_thresh is based on system memory. Wouldn't it make sense to set neigh.default.gc_thresh based on system memory too?
Cheers
Ulrich
Signature · 3 lines
Ulrich Weber | [email protected] | Software Engineer Astaro GmbH & Co. KG | www.astaro.com | Phone +49-721-25516-0 | Fax –200 An der RaumFabrik 33a | 76227 Karlsruhe | Germany