diff mbox series

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

Message ID 20250212164323.2183023-3-edumazet@google.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: better support of blackholes | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff fail author Signed-off-by missing
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-02-13--00-00 (tests: 889)

Commit Message

Eric Dumazet Feb. 12, 2025, 4:43 p.m. UTC
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

Reported-by: Paul Ripke <stix@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern Feb. 12, 2025, 6 p.m. UTC | #1
On 2/12/25 9:43 AM, Eric Dumazet wrote:
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -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,
        },
Eric Dumazet Feb. 12, 2025, 6:38 p.m. UTC | #2
On Wed, Feb 12, 2025 at 7:00 PM David Ahern <dsahern@kernel.org> wrote:
>
> On 2/12/25 9:43 AM, Eric Dumazet wrote:
> > diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> > index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
> > --- a/net/ipv6/route.c
> > +++ b/net/ipv6/route.c
> > @@ -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,
>         },

Should we create a new RTN_SINK (or different name), for both IPv4 and IPv6 ?
Stanislav Fomichev Feb. 13, 2025, 2:30 a.m. UTC | #3
On 02/12, Eric Dumazet wrote:
> On Wed, Feb 12, 2025 at 7:00 PM David Ahern <dsahern@kernel.org> wrote:
> >
> > On 2/12/25 9:43 AM, Eric Dumazet wrote:
> > > diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> > > index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
> > > --- a/net/ipv6/route.c
> > > +++ b/net/ipv6/route.c
> > > @@ -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,
> >         },
> 
> 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 Feb. 13, 2025, 3:49 p.m. UTC | #4
On 2/12/25 7:30 PM, Stanislav Fomichev wrote:
> On 02/12, Eric Dumazet wrote:
>> On Wed, Feb 12, 2025 at 7:00 PM David Ahern <dsahern@kernel.org> wrote:
>>>
>>> On 2/12/25 9:43 AM, Eric Dumazet wrote:
>>>> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
>>>> index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
>>>> --- a/net/ipv6/route.c
>>>> +++ b/net/ipv6/route.c
>>>> @@ -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,
>>>         },
>>
>> 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.
Simon Horman Feb. 16, 2025, 9:50 a.m. UTC | #5
On Wed, Feb 12, 2025 at 04:43:23PM +0000, Eric Dumazet wrote:
> 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

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.

> 
> ip route del 100::/64
> 
> Reported-by: Paul Ripke <stix@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

...
Nicolas Dichtel Feb. 18, 2025, 8:43 a.m. UTC | #6
Le 12/02/2025 à 19:00, David Ahern a écrit :
> On 2/12/25 9:43 AM, Eric Dumazet wrote:
>> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
>> index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
>> --- a/net/ipv6/route.c
>> +++ b/net/ipv6/route.c
>> @@ -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,
>         },
Yes, if I remember well, to be consistent I mimicked what existed in IPv4. I
never found a good answer to why 'EINVAL' :)

Nicolas
diff mbox series

Patch

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 78362822b9070df138a0724dc76003b63026f9e2..335cdbfe621e2fc4a71badf4ff834870638d5e13 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -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,