Skip to contentSkip to conversation

net: better support of blackholes

PATCH In review Eric Dumazet 5 participants 10 messages Feb 12, 2025 – Feb 18, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 32a34dfe8cc58fb1afda8922a52249080f1183b5..de42577f16dd199790cea9ac07b326864f2103e3 100644
@@ -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
index 9552a90d4772dce49b5fe94d2f1d8da6979d9908..0cbbad4d7c07fa397f66a2d252a636f90dafddee 100644
@@ -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
maintainer Reviewed-by on v1 1/2
#2 lore raw

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().

---
 include/net/dropreason-core.h | 5 +++++
 net/core/dst.c                | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
#3 lore raw

PATCH 2/2 ipv6: fix blackhole routes

In reply to 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::/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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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
maintainer
#4 lore raw

Re: [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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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,
},

#5 lore raw

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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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:

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 ?

#6 lore raw

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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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:

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

maintainer
#7 lore raw

Re: [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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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,
},

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.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

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.

#8 lore raw

Re: [PATCH net-next 2/2] ipv6: fix blackhole routes

In reply to David Ahern

Le 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
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
@@ -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:

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

reviewer
#9 lore raw

Re: [PATCH net-next 2/2] ipv6: fix blackhole routes

In reply to Eric Dumazet
Quoted 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::/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.

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

...