net: better support of blackholes
Subsystems (3)
cover net: better support of blackholes
First patch is adding a new drop_reason, for packets that are dropped by route blackhole.
Second patch changes ipv6 to no longer report
local errors for blackhole users.
Eric Dumazet (2):
net: dropreason: add SKB_DROP_REASON_BLACKHOLE
ipv6: fix blackhole routes
include/net/dropreason-core.h | 5 +++++ net/core/dst.c | 2 +- net/ipv6/route.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.48.1.502.g6dc24dfdaf-goog
PATCH 1/2 net: dropreason: add SKB_DROP_REASON_BLACKHOLE
Use this new drop reason from dst_discard_out().
--- include/net/dropreason-core.h | 5 +++++ net/core/dst.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
include/net/dropreason-core.h +5 -0
@@ -117,6 +117,7 @@ FN(ARP_PVLAN_DISABLE) \ FN(MAC_IEEE_MAC_CONTROL) \ FN(BRIDGE_INGRESS_STP_STATE) \ + FN(BLACKHOLE) \ FNe(MAX)/**
@@ -554,6 +555,10 @@ enum skb_drop_reason {* ingress bridge port does not allow frames to be forwarded. */ SKB_DROP_REASON_BRIDGE_INGRESS_STP_STATE , +/** +* @SKB_DROP_REASON_BLACKHOLE: blackhole route. +*/ + SKB_DROP_REASON_BLACKHOLE,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
net/core/dst.c +1 -1
@@ -29,7 +29,7 @@int dst_discard_out (struct net *net,struct sock *sk,struct sk_buff *skb) { -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_BLACKHOLE );return 0 ; }EXPORT_SYMBOL (dst_discard_out);
Signature · 1 line
2.48.1.502.g6dc24dfdaf-goog
Re: [PATCH net-next 1/2] net: dropreason: add SKB_DROP_REASON_BLACKHOLE
Quoted 8 lines · Eric Dumazet
Use this new drop reason from
dst_discard_out().Signed-off-by Eric Dumazet <[email protected]>--- include/net/dropreason-core.h | 5 +++++ net/core/dst.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
PATCH 2/2 ipv6: fix blackhole routes
In reply to Eric DumazetFor some reason, linux does not really act as a blackhole for local processes:
ip route add blackhole 100::/64 # RFC 6666
ip route get 100::
RTNETLINK answers: Invalid argument
ping6 -c2 100::
ping6: connect: Invalid argument
ip route del 100::/64
After this patch, a local process no longer has an immediate error, the blackhole is simply eating the packets as intended.
Also the "route get" command does not fail anymore.
ip route add blackhole 100::/64
ip route get 100::
blackhole 100:: dev lo src ::1 metric 1024 pref medium ping6 -c2 100::
PING 100:: (100::) 56 data bytes
--- 100:: ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1019ms
ip route del 100::/64
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,
Signature · 1 line
2.48.1.502.g6dc24dfdaf-goog
David Ahern
maintainerRe: [PATCH net-next 2/2] ipv6: fix blackhole routes
net/ipv6/route.c static const int fib6_prop[RTN_MAX + 1] = { · line 1054
Quoted 13 lines · Eric Dumazet
net/ipv6/route.c +1
-1@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,
EINVAL goes back to ef2c7d7b59708 in 2012, so this is a change in user visible behavior. Also this will make ipv6 deviate from ipv4:
[RTN_BLACKHOLE] = {
.error = -EINVAL,
.scope = RT_SCOPE_UNIVERSE,
},
Re: [PATCH net-next 2/2] ipv6: fix blackhole routes
Quoted 19 lines · David Ahern
net/ipv6/route.c static const int fib6_prop[RTN_MAX + 1] = { · line 1054
Quoted 13 lines · Eric Dumazet
net/ipv6/route.c +1
-1@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,EINVAL goes back to
ef2c7d7b59708in 2012, so this is a change in user visible behavior. Also this will make ipv6 deviate from ipv4:
Quoted 4 lines
[
RTN_BLACKHOLE] = {
.error =-EINVAL,
.scope =RT_SCOPE_UNIVERSE,
},
Should we create a new RTN_SINK (or different name), for both IPv4 and IPv6 ?
Re: [PATCH net-next 2/2] ipv6: fix blackhole routes
Quoted 20 lines · Eric Dumazet
Quoted 19 lines · David Ahern
net/ipv6/route.c static const int fib6_prop[RTN_MAX + 1] = { · line 1054
Quoted 13 lines · Eric Dumazet
net/ipv6/route.c +1
-1@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,EINVAL goes back to
ef2c7d7b59708in 2012, so this is a change in user visible behavior. Also this will make ipv6 deviate from ipv4:
Quoted 6 lines
Quoted 4 lines
[
RTN_BLACKHOLE] = {
.error =-EINVAL,
.scope =RT_SCOPE_UNIVERSE,
},Should we create a new
RTN_SINK(or different name), for both IPv4 and IPv6 ?
Sorry for sidelining, but depending on how this discussion goes, tools/testing/selftests/net/fib_nexthops.sh test might need to be adjusted (currently fails presumably because of -EINVAL change):
https://netdev-3.bots.linux.dev/vmksft-net/results/990081/2-fib-nexthops-sh/stdout
---
pw-bot: cr
David Ahern
maintainerRe: [PATCH net-next 2/2] ipv6: fix blackhole routes
Quoted 26 lines · Stanislav Fomichev
Quoted 25 lines · Eric Dumazet
Quoted 23 lines · David Ahern
net/ipv6/route.c static const int fib6_prop[RTN_MAX + 1] = { · line 1054
Quoted 13 lines · Eric Dumazet
net/ipv6/route.c +1
-1@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,EINVAL goes back to
ef2c7d7b59708in 2012, so this is a change in user visible behavior. Also this will make ipv6 deviate from ipv4:[
RTN_BLACKHOLE] = {
.error =-EINVAL,
.scope =RT_SCOPE_UNIVERSE,
},
Quoted 8 lines
Quoted 1 line
Should we create a new
RTN_SINK(or different name), for both IPv4 and IPv6 ?Sorry for sidelining, but depending on how this discussion goes,
tools/testing/selftests/net/fib_nexthops.shtest might need to be adjusted (currently fails presumably because of-EINVALchange):https://netdev-3.bots.linux.dev/vmksft-net/results/990081/2-fib-nexthops-sh/stdout
yep, I verified that yesterday - there are blackhole selftests. At this point SINK or whatever the name would have to be a new API, including how the route is installed if no local failure is really desired.
Re: [PATCH net-next 2/2] ipv6: fix blackhole routes
In reply to David AhernLe 12/02/2025 à 19:00, David Ahern a écrit :
Quoted 18 lines · Eric Dumazet
net/ipv6/route.c static const int fib6_prop[RTN_MAX + 1] = { · line 1054
Quoted 13 lines
net/ipv6/route.c +1
-1@@ -1048,7 +1048,7 @@ static const int fib6_prop[RTN_MAX + 1] = { [RTN_BROADCAST] = 0, [RTN_ANYCAST] = 0, [RTN_MULTICAST] = 0, - [RTN_BLACKHOLE] = -EINVAL, + [RTN_BLACKHOLE] = 0, [RTN_UNREACHABLE] = -EHOSTUNREACH, [RTN_PROHIBIT] = -EACCES, [RTN_THROW] = -EAGAIN,EINVAL goes back to
ef2c7d7b59708in 2012, so this is a change in user visible behavior. Also this will make ipv6 deviate from ipv4:
Quoted 4 lines
[
RTN_BLACKHOLE] = {
.error =-EINVAL,
.scope =RT_SCOPE_UNIVERSE,
},
Yes, if I remember well, to be consistent I mimicked what existed in IPv4. I never found a good answer to why 'EINVAL' :)
Nicolas
Simon Horman
reviewerRe: [PATCH net-next 2/2] ipv6: fix blackhole routes
In reply to Eric DumazetQuoted 15 lines · Eric Dumazet
For some reason, linux does not really act as a blackhole for local processes:
ip route add blackhole 100::/64 # RFC 6666
ip route get 100::
RTNETLINK answers: Invalid argument
ping6 -c2 100::
ping6: connect: Invalid argument
ip route del 100::/64After this patch, a local process no longer has an immediate error, the blackhole is simply eating the packets as intended.
Also the "route get" command does not fail anymore.
Quoted 8 lines
ip route add blackhole 100::/64
ip route get 100::
blackhole 100:: dev lo src ::1 metric 1024 pref medium ping6 -c2 100::
PING 100:: (100::) 56 data bytes--- 100:: ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1019ms
Hi Eric,
Sorry to nit-pick on something that is nothing to do with the change itself. But could you reformat the above somehow as git will cut off the commit message at the ("^---") above. Which amongst other things means the patch will end up without a Signed-off-by line in git.
Quoted 5 lines
ip route del 100::/64
Reported-by Paul Ripke <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
...