Skip to content

Commit 55126f9

Browse files
authored
[client] Use native windows sock opts to avoid routing loops (#4314)
- Move `util/grpc` and `util/net` to `client` so `internal` packages can be accessed - Add methods to return the next best interface after the NetBird interface. - Use `IP_UNICAST_IF` sock opt to force the outgoing interface for the NetBird `net.Dialer` and `net.ListenerConfig` to avoid routing loops. The interface is picked by the new route lookup method. - Some refactoring to avoid import cycles - Old behavior is available through `NB_USE_LEGACY_ROUTING=true` env var
1 parent 9057768 commit 55126f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1180
-606
lines changed

client/android/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/netbirdio/netbird/client/internal/stdnet"
2020
"github.com/netbirdio/netbird/client/system"
2121
"github.com/netbirdio/netbird/formatter"
22-
"github.com/netbirdio/netbird/util/net"
22+
"github.com/netbirdio/netbird/client/net"
2323
)
2424

2525
// ConnectionListener export internal Listener for mobile

client/cmd/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var downCmd = &cobra.Command{
2727
return err
2828
}
2929

30-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*7)
30+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
3131
defer cancel()
3232

3333
conn, err := DialClientGRPCServer(ctx, daemonAddr)

client/firewall/iptables/acl_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
firewall "github.com/netbirdio/netbird/client/firewall/manager"
1414
"github.com/netbirdio/netbird/client/internal/statemanager"
15-
nbnet "github.com/netbirdio/netbird/util/net"
15+
nbnet "github.com/netbirdio/netbird/client/net"
1616
)
1717

1818
const (

client/firewall/iptables/router_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/netbirdio/netbird/client/internal/routemanager/ipfwdstate"
2020
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
2121
"github.com/netbirdio/netbird/client/internal/statemanager"
22-
nbnet "github.com/netbirdio/netbird/util/net"
22+
nbnet "github.com/netbirdio/netbird/client/net"
2323
)
2424

2525
// constants needed to manage and create iptable rules

client/firewall/iptables/router_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
firewall "github.com/netbirdio/netbird/client/firewall/manager"
1616
"github.com/netbirdio/netbird/client/firewall/test"
17-
nbnet "github.com/netbirdio/netbird/util/net"
17+
nbnet "github.com/netbirdio/netbird/client/net"
1818
)
1919

2020
func isIptablesSupported() bool {

client/firewall/nftables/acl_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"golang.org/x/sys/unix"
1717

1818
firewall "github.com/netbirdio/netbird/client/firewall/manager"
19-
nbnet "github.com/netbirdio/netbird/util/net"
19+
nbnet "github.com/netbirdio/netbird/client/net"
2020
)
2121

2222
const (

client/firewall/nftables/router_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
nbid "github.com/netbirdio/netbird/client/internal/acl/id"
2323
"github.com/netbirdio/netbird/client/internal/routemanager/ipfwdstate"
2424
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
25-
nbnet "github.com/netbirdio/netbird/util/net"
25+
nbnet "github.com/netbirdio/netbird/client/net"
2626
)
2727

2828
const (

util/grpc/dialer.go renamed to client/grpc/dialer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
"google.golang.org/grpc/credentials/insecure"
2121
"google.golang.org/grpc/keepalive"
2222

23+
nbnet "github.com/netbirdio/netbird/client/net"
24+
2325
"github.com/netbirdio/netbird/util/embeddedroots"
24-
nbnet "github.com/netbirdio/netbird/util/net"
2526
)
2627

2728
func WithCustomDialer() grpc.DialOption {

client/iface/bind/control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package bind
33
import (
44
wireguard "golang.zx2c4.com/wireguard/conn"
55

6-
nbnet "github.com/netbirdio/netbird/util/net"
6+
nbnet "github.com/netbirdio/netbird/client/net"
77
)
88

99
// TODO: This is most likely obsolete since the control fns should be called by the wrapped udpconn (ice_bind.go)

client/iface/bind/ice_bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
"github.com/netbirdio/netbird/client/iface/udpmux"
1919
"github.com/netbirdio/netbird/client/iface/wgaddr"
20-
nbnet "github.com/netbirdio/netbird/util/net"
20+
nbnet "github.com/netbirdio/netbird/client/net"
2121
)
2222

2323
type RecvMessage struct {

0 commit comments

Comments
 (0)