netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
10.86k stars 491 forks source link

network route not working for subnetwork even if it should have to work #840

Closed lfarkas closed 10 months ago

lfarkas commented 1 year ago

The network routes is a very nice feature in netbird, but one of my current topology it's not working. I've 2 network, let it be office and home:

I've one client (actually more but let's make it more simple) in each network and i'd like route through these client from each network to the other. This normally works (eg with openvpn) and it's works even with netbird, BUT do not work if i set both routes in https://app.netbird.io/routes and try to advertise them through netbird.

The reason is simple from the log:

2023-05-08T12:50:55+02:00 INFO client/internal/peer/conn.go:348: connected to peer gsrpCbJwc8lkmNV783rxIHpyj+zZIhy/rFj5HsfVuBY= [laddr <-> raddr] [192.168.209.150:51820 <-> 192.168.209.1:38584]
2023-05-08T12:50:55+02:00 INFO client/internal/routemanager/client.go:111: new chosen route is chccqaat2r9s73b1k4q0 with peer gsrpCbJwc8lkmNV783rxIHpyj+zZIhy/rFj5HsfVuBY= with score 11
2023-05-08T12:50:55+02:00 WARN client/internal/routemanager/systemops_nonandroid.go:27: skipping adding a new route for network 192.168.253.0/24 because it already exists and is pointing to the non default gateway: 192.168.209.150

it seems that netbird see something similar route in the local routing table and skip this, which is a bug. in linux (any any other os) the routing decision is working in a way that always try to choose the smallest network which contains the given destination. so in this case there can be 2 orverlapping route in the routing table the os always choose the smallest one eg. with this routing table:

192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 enp2s0
192.168.253.0     100.76.24.179   255.255.255.0     UG    0      0        0 wt0

the host 192.168.253.2 should have to route through wt0.

The strange thing is that the opposite works in the other side of the network. ie. routeing from home to office has this routing table:

0.0.0.0         192.168.253.1   0.0.0.0         UG    100    0        0 enp6s0
100.76.0.0      0.0.0.0         255.255.0.0     U     0      0        0 wt0
192.168.0.0     100.76.24.179   255.255.0.0     UG    0      0        0 wt0
192.168.253.0   0.0.0.0         255.255.255.0   U     100    0        0 enp6s0

and in the log:

2023-05-08T12:50:55+02:00 INFO client/internal/peer/conn.go:348: connected to peer hCDjKQBW9TBwsZigTRXxvVzpAYE+ZqDHBol4sOSUMl0= [laddr <-> raddr] [192.168.253.9:51820 <-> 185.199.30.141:2563]
2023-05-08T12:50:55+02:00 INFO client/internal/routemanager/client.go:111: new chosen route is cgva4m2t2r9s73c4r8tg with peer hCDjKQBW9TBwsZigTRXxvVzpAYE+ZqDHBol4sOSUMl0= with score 11

so when the remote is overlapping BUT larger then the routing rule is added.

mlsmaycon commented 1 year ago

The PR #945 fixes it and it will be available in the next release.

lfarkas commented 1 year ago

i already reconfigure all of our networks so i can't test it now. but let's assume working if not i'll write a new issue.

lfarkas commented 11 months ago

this is not working again in the latest release netbird-0.24.2-1.x86_64. i'm just now connected to a wifi network where the local ip address is:

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.185  netmask 255.255.255.0  broadcast 192.168.0.255

ad the same time one of my network which should have to be routed is: 192.168.0.0/16 so the peer's route should have to be added, but in the log i can see this:

2023-10-28T11:17:58+02:00 WARN client/internal/routemanager/client.go:119: the network 192.168.0.0/16 has not been assigned a routing peer as no peers from the list [FfiyZKMquYILabBxOquw/jXEuTjhBq6tUvBEPdV3ckY= hCDjKQBW9TBwsZigTRXxvVzpAYE+ZqDHBol4sOSUMl0=] are currently connected

imho it's the same bug as earlier so it seems still not solved.

mlsmaycon commented 11 months ago

Hello @lfarkas can you run the client with debug logs?

You can do that by running the following commands:

sudo netbird service stop
sudo netbird up -F -l debug | tee /tmp/netbird.debug.log

After running for 60s you can share the logs for us to check them.

lfarkas commented 11 months ago

netbird.log

lfarkas commented 11 months ago

do you need any further info?

mlsmaycon commented 11 months ago

Hello, @lfarkas the issue happened because the default gateway of your local network is 192.168.0.1, which is part of the 192.168.0.0/16 network. See the log event below:

2023-10-30T18:46:59+01:00 WARN client/internal/routemanager/systemops_nonandroid.go:24: skipping adding a new route for network 192.168.0.0/16 because it overlaps with the default gateway: 192.168.0.1

This shouldn't happen as the local network is smaller. We will update the logic to prevent this case. Thanks for the logs.

lfarkas commented 10 months ago

work in 24.3