mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-26 22:39:07 +01:00
Merge branch 'main' into feature/header-auth-on-proxy
This commit is contained in:
@@ -45,8 +45,8 @@ func daemonServerOptions(network string) []grpc.ServerOption {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := ipcauth.NewTransportCredentials()
|
creds := ipcauth.NewTransportCredentials() //nolint:staticcheck
|
||||||
if creds == nil {
|
if creds == nil { //nolint:staticcheck // nil only on platforms without a peer-identity primitive
|
||||||
log.Warnf("daemon IPC has no peer-identity primitive on %s: privileged operations will be denied", runtime.GOOS)
|
log.Warnf("daemon IPC has no peer-identity primitive on %s: privileged operations will be denied", runtime.GOOS)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ func listenOnAddress(addr string) (*socketListener, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if network == "npipe" {
|
if network == "npipe" {
|
||||||
listener, path, err := listenNamedPipe(address)
|
listener, path, err := listenNamedPipe(address) //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on non-Windows builds
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &socketListener{Listener: listener, network: network, address: path}, nil
|
return &socketListener{Listener: listener, network: network, address: path}, nil
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ func NewProxyBind(bind Bind, mtu uint16) *ProxyBind {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTurnConn adds a new connection to the bind.
|
// AddRelayedConn adds a new connection to the bind.
|
||||||
// endpoint is the NetBird address of the remote peer. The SetEndpoint return with the address what will be used in the
|
// endpoint is the NetBird address of the remote peer. The SetEndpoint return with the address what will be used in the
|
||||||
// WireGuard configuration.
|
// WireGuard configuration.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - ctx: Context is used for proxyToLocal to avoid unnecessary error messages
|
// - ctx: Context is used for proxyToLocal to avoid unnecessary error messages
|
||||||
// - nbAddr: The NetBird UDP address of the remote peer, it required to generate fake address
|
// - nbAddr: The NetBird UDP address of the remote peer, it required to generate fake address
|
||||||
// - remoteConn: The established TURN connection to the remote peer
|
// - remoteConn: The established relayed connection to the remote peer
|
||||||
func (p *ProxyBind) AddTurnConn(ctx context.Context, nbAddr *net.UDPAddr, remoteConn net.Conn) error {
|
func (p *ProxyBind) AddRelayedConn(ctx context.Context, nbAddr *net.UDPAddr, remoteConn net.Conn) error {
|
||||||
fakeNetIP, err := fakeAddress(nbAddr)
|
fakeNetIP, err := fakeAddress(nbAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ type WGEBPFProxy struct {
|
|||||||
proxyPort int
|
proxyPort int
|
||||||
mtu uint16
|
mtu uint16
|
||||||
|
|
||||||
ebpfManager ebpfMgr.Manager
|
ebpfManager ebpfMgr.Manager
|
||||||
turnConnStore map[uint16]net.Conn
|
relayedConnStore map[uint16]net.Conn
|
||||||
turnConnMutex sync.Mutex
|
relayedConnMutex sync.Mutex
|
||||||
|
|
||||||
lastUsedPort uint16
|
lastUsedPort uint16
|
||||||
rawConnIPv4 net.PacketConn
|
rawConnIPv4 net.PacketConn
|
||||||
@@ -50,7 +50,7 @@ func NewWGEBPFProxy(wgPort int, mtu uint16) *WGEBPFProxy {
|
|||||||
localWGListenPort: wgPort,
|
localWGListenPort: wgPort,
|
||||||
mtu: mtu,
|
mtu: mtu,
|
||||||
ebpfManager: ebpf.GetEbpfManagerInstance(),
|
ebpfManager: ebpf.GetEbpfManagerInstance(),
|
||||||
turnConnStore: make(map[uint16]net.Conn),
|
relayedConnStore: make(map[uint16]net.Conn),
|
||||||
}
|
}
|
||||||
return wgProxy
|
return wgProxy
|
||||||
}
|
}
|
||||||
@@ -110,14 +110,14 @@ func (p *WGEBPFProxy) Listen() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTurnConn add new turn connection for the proxy
|
// AddRelayedConn add new relayed connection for the proxy
|
||||||
func (p *WGEBPFProxy) AddTurnConn(turnConn net.Conn) (*net.UDPAddr, error) {
|
func (p *WGEBPFProxy) AddRelayedConn(relayedConn net.Conn) (*net.UDPAddr, error) {
|
||||||
wgEndpointPort, err := p.storeTurnConn(turnConn)
|
wgEndpointPort, err := p.storeRelayedConn(relayedConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("turn conn added to wg proxy store: %s, endpoint port: :%d", turnConn.RemoteAddr(), wgEndpointPort)
|
log.Infof("relayed conn added to wg proxy store: %s, endpoint port: :%d", relayedConn.RemoteAddr(), wgEndpointPort)
|
||||||
|
|
||||||
wgEndpoint := &net.UDPAddr{
|
wgEndpoint := &net.UDPAddr{
|
||||||
IP: net.ParseIP(loopbackAddr),
|
IP: net.ParseIP(loopbackAddr),
|
||||||
@@ -186,48 +186,48 @@ func (p *WGEBPFProxy) readAndForwardPacket(buf []byte) error {
|
|||||||
return fmt.Errorf("failed to read UDP packet from WG: %w", err)
|
return fmt.Errorf("failed to read UDP packet from WG: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.turnConnMutex.Lock()
|
p.relayedConnMutex.Lock()
|
||||||
conn, ok := p.turnConnStore[uint16(addr.Port)]
|
conn, ok := p.relayedConnStore[uint16(addr.Port)]
|
||||||
p.turnConnMutex.Unlock()
|
p.relayedConnMutex.Unlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
if p.ctx.Err() == nil {
|
if p.ctx.Err() == nil {
|
||||||
log.Debugf("turn conn not found by port because conn already has been closed: %d", addr.Port)
|
log.Debugf("relayed conn not found by port because conn already has been closed: %d", addr.Port)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := conn.Write(buf[:n]); err != nil {
|
if _, err := conn.Write(buf[:n]); err != nil {
|
||||||
return fmt.Errorf("failed to forward local WG packet (%d) to remote turn conn: %w", addr.Port, err)
|
return fmt.Errorf("forward local WG packet (%d) to remote relayed conn: %w", addr.Port, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WGEBPFProxy) storeTurnConn(turnConn net.Conn) (uint16, error) {
|
func (p *WGEBPFProxy) storeRelayedConn(relayedConn net.Conn) (uint16, error) {
|
||||||
p.turnConnMutex.Lock()
|
p.relayedConnMutex.Lock()
|
||||||
defer p.turnConnMutex.Unlock()
|
defer p.relayedConnMutex.Unlock()
|
||||||
|
|
||||||
np, err := p.nextFreePort()
|
np, err := p.nextFreePort()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return np, err
|
return np, err
|
||||||
}
|
}
|
||||||
p.turnConnStore[np] = turnConn
|
p.relayedConnStore[np] = relayedConn
|
||||||
return np, nil
|
return np, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WGEBPFProxy) removeTurnConn(turnConnID uint16) {
|
func (p *WGEBPFProxy) removeRelayedConn(relayedConnID uint16) {
|
||||||
p.turnConnMutex.Lock()
|
p.relayedConnMutex.Lock()
|
||||||
defer p.turnConnMutex.Unlock()
|
defer p.relayedConnMutex.Unlock()
|
||||||
|
|
||||||
_, ok := p.turnConnStore[turnConnID]
|
_, ok := p.relayedConnStore[relayedConnID]
|
||||||
if ok {
|
if ok {
|
||||||
log.Debugf("remove turn conn from store by port: %d", turnConnID)
|
log.Debugf("remove relayed conn from store by port: %d", relayedConnID)
|
||||||
}
|
}
|
||||||
delete(p.turnConnStore, turnConnID)
|
delete(p.relayedConnStore, relayedConnID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WGEBPFProxy) nextFreePort() (uint16, error) {
|
func (p *WGEBPFProxy) nextFreePort() (uint16, error) {
|
||||||
if len(p.turnConnStore) == 65535 {
|
if len(p.relayedConnStore) == 65535 {
|
||||||
return 0, fmt.Errorf("reached maximum turn connection numbers")
|
return 0, fmt.Errorf("reached maximum relayed connection numbers")
|
||||||
}
|
}
|
||||||
generatePort:
|
generatePort:
|
||||||
if p.lastUsedPort == 65535 {
|
if p.lastUsedPort == 65535 {
|
||||||
@@ -236,7 +236,7 @@ generatePort:
|
|||||||
p.lastUsedPort++
|
p.lastUsedPort++
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := p.turnConnStore[p.lastUsedPort]; ok {
|
if _, ok := p.relayedConnStore[p.lastUsedPort]; ok {
|
||||||
goto generatePort
|
goto generatePort
|
||||||
}
|
}
|
||||||
return p.lastUsedPort, nil
|
return p.lastUsedPort, nil
|
||||||
|
|||||||
@@ -9,32 +9,32 @@ import (
|
|||||||
func TestWGEBPFProxy_connStore(t *testing.T) {
|
func TestWGEBPFProxy_connStore(t *testing.T) {
|
||||||
wgProxy := NewWGEBPFProxy(1, 1280)
|
wgProxy := NewWGEBPFProxy(1, 1280)
|
||||||
|
|
||||||
p, _ := wgProxy.storeTurnConn(nil)
|
p, _ := wgProxy.storeRelayedConn(nil)
|
||||||
if p != 1 {
|
if p != 1 {
|
||||||
t.Errorf("invalid initial port: %d", wgProxy.lastUsedPort)
|
t.Errorf("invalid initial port: %d", wgProxy.lastUsedPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfConns := 10
|
numOfConns := 10
|
||||||
for i := 0; i < numOfConns; i++ {
|
for i := 0; i < numOfConns; i++ {
|
||||||
p, _ = wgProxy.storeTurnConn(nil)
|
p, _ = wgProxy.storeRelayedConn(nil)
|
||||||
}
|
}
|
||||||
if p != uint16(numOfConns)+1 {
|
if p != uint16(numOfConns)+1 {
|
||||||
t.Errorf("invalid last used port: %d, expected: %d", p, numOfConns+1)
|
t.Errorf("invalid last used port: %d, expected: %d", p, numOfConns+1)
|
||||||
}
|
}
|
||||||
if len(wgProxy.turnConnStore) != numOfConns+1 {
|
if len(wgProxy.relayedConnStore) != numOfConns+1 {
|
||||||
t.Errorf("invalid store size: %d, expected: %d", len(wgProxy.turnConnStore), numOfConns+1)
|
t.Errorf("invalid store size: %d, expected: %d", len(wgProxy.relayedConnStore), numOfConns+1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWGEBPFProxy_portCalculation_overflow(t *testing.T) {
|
func TestWGEBPFProxy_portCalculation_overflow(t *testing.T) {
|
||||||
wgProxy := NewWGEBPFProxy(1, 1280)
|
wgProxy := NewWGEBPFProxy(1, 1280)
|
||||||
|
|
||||||
_, _ = wgProxy.storeTurnConn(nil)
|
_, _ = wgProxy.storeRelayedConn(nil)
|
||||||
wgProxy.lastUsedPort = 65535
|
wgProxy.lastUsedPort = 65535
|
||||||
p, _ := wgProxy.storeTurnConn(nil)
|
p, _ := wgProxy.storeRelayedConn(nil)
|
||||||
|
|
||||||
if len(wgProxy.turnConnStore) != 2 {
|
if len(wgProxy.relayedConnStore) != 2 {
|
||||||
t.Errorf("invalid store size: %d, expected: %d", len(wgProxy.turnConnStore), 2)
|
t.Errorf("invalid store size: %d, expected: %d", len(wgProxy.relayedConnStore), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p != 2 {
|
if p != 2 {
|
||||||
@@ -46,11 +46,11 @@ func TestWGEBPFProxy_portCalculation_maxConn(t *testing.T) {
|
|||||||
wgProxy := NewWGEBPFProxy(1, 1280)
|
wgProxy := NewWGEBPFProxy(1, 1280)
|
||||||
|
|
||||||
for i := 0; i < 65535; i++ {
|
for i := 0; i < 65535; i++ {
|
||||||
_, _ = wgProxy.storeTurnConn(nil)
|
_, _ = wgProxy.storeRelayedConn(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := wgProxy.storeTurnConn(nil)
|
_, err := wgProxy.storeRelayedConn(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("invalid turn conn store calculation")
|
t.Errorf("invalid relayed conn store calculation")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ func NewProxyWrapper(proxy *WGEBPFProxy) *ProxyWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyWrapper) AddTurnConn(ctx context.Context, _ *net.UDPAddr, remoteConn net.Conn) error {
|
func (p *ProxyWrapper) AddRelayedConn(ctx context.Context, _ *net.UDPAddr, remoteConn net.Conn) error {
|
||||||
addr, err := p.wgeBPFProxy.AddTurnConn(remoteConn)
|
addr, err := p.wgeBPFProxy.AddRelayedConn(remoteConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("add turn conn: %w", err)
|
return fmt.Errorf("add relayed conn: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers, err := NewPacketHeaders(p.wgeBPFProxy.localWGListenPort, addr)
|
headers, err := NewPacketHeaders(p.wgeBPFProxy.localWGListenPort, addr)
|
||||||
@@ -252,7 +252,7 @@ func (p *ProxyWrapper) CloseConn() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyWrapper) proxyToLocal(ctx context.Context) {
|
func (p *ProxyWrapper) proxyToLocal(ctx context.Context) {
|
||||||
defer p.wgeBPFProxy.removeTurnConn(uint16(p.wgRelayedEndpointAddr.Port))
|
defer p.wgeBPFProxy.removeRelayedConn(uint16(p.wgRelayedEndpointAddr.Port))
|
||||||
|
|
||||||
buf := make([]byte, p.wgeBPFProxy.mtu+bufsize.WGBufferOverhead)
|
buf := make([]byte, p.wgeBPFProxy.mtu+bufsize.WGBufferOverhead)
|
||||||
for {
|
for {
|
||||||
@@ -273,7 +273,7 @@ func (p *ProxyWrapper) proxyToLocal(ctx context.Context) {
|
|||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Errorf("failed to write out turn pkg to local conn: %v", err)
|
log.Errorf("failed to write out relayed pkg to local conn: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ func (p *ProxyWrapper) readFromRemote(ctx context.Context, buf []byte) (int, err
|
|||||||
}
|
}
|
||||||
p.closeListener.Notify()
|
p.closeListener.Notify()
|
||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
log.Errorf("failed to read from turn conn (endpoint: :%d): %s", p.wgRelayedEndpointAddr.Port, err)
|
log.Errorf("failed to read from relayed conn (endpoint: :%d): %s", p.wgRelayedEndpointAddr.Port, err)
|
||||||
}
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
// Proxy is a transfer layer between the relayed connection and the WireGuard
|
// Proxy is a transfer layer between the relayed connection and the WireGuard
|
||||||
type Proxy interface {
|
type Proxy interface {
|
||||||
AddTurnConn(ctx context.Context, endpoint *net.UDPAddr, remoteConn net.Conn) error
|
AddRelayedConn(ctx context.Context, endpoint *net.UDPAddr, remoteConn net.Conn) error
|
||||||
EndpointAddr() *net.UDPAddr // EndpointAddr returns the address of the WireGuard peer endpoint
|
EndpointAddr() *net.UDPAddr // EndpointAddr returns the address of the WireGuard peer endpoint
|
||||||
Work() // Work start or resume the proxy
|
Work() // Work start or resume the proxy
|
||||||
Pause() // Pause to forward the packages from remote connection to WireGuard. The opposite way still works.
|
Pause() // Pause to forward the packages from remote connection to WireGuard. The opposite way still works.
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func TestProxyCloseByRemoteConn(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
addr, _ := net.ResolveUDPAddr("udp", "100.108.135.221:51892")
|
addr, _ := net.ResolveUDPAddr("udp", "100.108.135.221:51892")
|
||||||
relayedConn := newMockConn()
|
relayedConn := newMockConn()
|
||||||
err := tt.proxy.AddTurnConn(ctx, addr, relayedConn)
|
err := tt.proxy.AddRelayedConn(ctx, addr, relayedConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error: %v", err)
|
t.Errorf("error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ func redirectTraffic(t *testing.T, proxy Proxy, wgPort int, endPointAddr *net.UD
|
|||||||
_ = relayedServer.Close()
|
_ = relayedServer.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := proxy.AddTurnConn(context.Background(), endPointAddr, relayedConn); err != nil {
|
if err := proxy.AddRelayedConn(context.Background(), endPointAddr, relayedConn); err != nil {
|
||||||
t.Errorf("error: %v", err)
|
t.Errorf("error: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ func testRedirectAs(t *testing.T, proxy Proxy, wgPort int, nbAddr, p2pEndpoint *
|
|||||||
}
|
}
|
||||||
defer relayConn.Close()
|
defer relayConn.Close()
|
||||||
|
|
||||||
// Add TURN connection to proxy
|
// Add relayed connection to proxy
|
||||||
if err := proxy.AddTurnConn(ctx, nbAddr, relayConn); err != nil {
|
if err := proxy.AddRelayedConn(ctx, nbAddr, relayConn); err != nil {
|
||||||
t.Fatalf("failed to add TURN connection: %v", err)
|
t.Fatalf("failed to add relayed connection: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := proxy.CloseConn(); err != nil {
|
if err := proxy.CloseConn(); err != nil {
|
||||||
@@ -304,8 +304,8 @@ func TestRedirectAs_Multiple_Switches(t *testing.T) {
|
|||||||
Port: 38746,
|
Port: 38746,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := proxy.AddTurnConn(ctx, nbAddr, relayConn); err != nil {
|
if err := proxy.AddRelayedConn(ctx, nbAddr, relayConn); err != nil {
|
||||||
t.Fatalf("failed to add TURN connection: %v", err)
|
t.Fatalf("failed to add relayed connection: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := proxy.CloseConn(); err != nil {
|
if err := proxy.CloseConn(); err != nil {
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ func NewWGUDPProxy(wgPort int, mtu uint16) *WGUDPProxy {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTurnConn
|
// AddRelayedConn dials the local WireGuard port and stores the relayed connection.
|
||||||
// The provided Context must be non-nil. If the context expires before
|
// The provided Context must be non-nil. If the context expires before
|
||||||
// the connection is complete, an error is returned. Once successfully
|
// the connection is complete, an error is returned. Once successfully
|
||||||
// connected, any expiration of the context will not affect the
|
// connected, any expiration of the context will not affect the
|
||||||
// connection.
|
// connection.
|
||||||
func (p *WGUDPProxy) AddTurnConn(ctx context.Context, _ *net.UDPAddr, remoteConn net.Conn) error {
|
func (p *WGUDPProxy) AddRelayedConn(ctx context.Context, _ *net.UDPAddr, remoteConn net.Conn) error {
|
||||||
dialer := net.Dialer{}
|
dialer := net.Dialer{}
|
||||||
localConn, err := dialer.DialContext(ctx, "udp", fmt.Sprintf(":%d", p.localWGListenPort))
|
localConn, err := dialer.DialContext(ctx, "udp", fmt.Sprintf(":%d", p.localWGListenPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -116,11 +116,11 @@ func (d *DefaultManager) ApplyFiltering(networkMap *mgmProto.NetworkMap, dnsRout
|
|||||||
// firewall state, so an identical hash means an identical resulting ruleset.
|
// firewall state, so an identical hash means an identical resulting ruleset.
|
||||||
func (d *DefaultManager) firewallConfigHash(networkMap *mgmProto.NetworkMap, dnsRouteFeatureFlag bool) (uint64, error) {
|
func (d *DefaultManager) firewallConfigHash(networkMap *mgmProto.NetworkMap, dnsRouteFeatureFlag bool) (uint64, error) {
|
||||||
return hashstructure.Hash(struct {
|
return hashstructure.Hash(struct {
|
||||||
PeerRules []*mgmProto.FirewallRule
|
PeerRules []*mgmProto.FirewallRule
|
||||||
PeerRulesIsEmpty bool
|
PeerRulesIsEmpty bool
|
||||||
RouteRules []*mgmProto.RouteFirewallRule
|
RouteRules []*mgmProto.RouteFirewallRule
|
||||||
RouteRulesIsEmpty bool
|
RouteRulesIsEmpty bool
|
||||||
DNSRouteFeatureFlag bool
|
DNSRouteFeatureFlag bool
|
||||||
}{
|
}{
|
||||||
PeerRules: networkMap.GetFirewallRules(),
|
PeerRules: networkMap.GetFirewallRules(),
|
||||||
PeerRulesIsEmpty: networkMap.GetFirewallRulesIsEmpty(),
|
PeerRulesIsEmpty: networkMap.GetFirewallRulesIsEmpty(),
|
||||||
@@ -144,13 +144,13 @@ func (d *DefaultManager) applyPeerACLs(networkMap *mgmProto.NetworkMap) {
|
|||||||
log.Warn("this peer is connected to a NetBird Management service with an older version. Allowing all traffic from connected peers")
|
log.Warn("this peer is connected to a NetBird Management service with an older version. Allowing all traffic from connected peers")
|
||||||
rules = append(rules,
|
rules = append(rules,
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "0.0.0.0",
|
PeerIP: "0.0.0.0", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_ALL,
|
Protocol: mgmProto.RuleProtocol_ALL,
|
||||||
},
|
},
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "0.0.0.0",
|
PeerIP: "0.0.0.0", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_OUT,
|
Direction: mgmProto.RuleDirection_OUT,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_ALL,
|
Protocol: mgmProto.RuleProtocol_ALL,
|
||||||
@@ -407,7 +407,6 @@ func (d *DefaultManager) getRuleGroupingSelector(rule *mgmProto.FirewallRule) st
|
|||||||
return fmt.Sprintf("%v:%v:%v:%s:%v", strconv.Itoa(int(rule.Direction)), rule.Action, rule.Protocol, rule.Port, rule.PortInfo)
|
return fmt.Sprintf("%v:%v:%v:%s:%v", strconv.Itoa(int(rule.Direction)), rule.Action, rule.Protocol, rule.Port, rule.PortInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// extractRuleIP extracts the peer IP from a firewall rule.
|
// extractRuleIP extracts the peer IP from a firewall rule.
|
||||||
// If sourcePrefixes is populated (new management), decode the first entry and use its address.
|
// If sourcePrefixes is populated (new management), decode the first entry and use its address.
|
||||||
// Otherwise fall back to the deprecated PeerIP string field (old management).
|
// Otherwise fall back to the deprecated PeerIP string field (old management).
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.uber.org/mock/gomock"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/mock/gomock"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/firewall"
|
"github.com/netbirdio/netbird/client/firewall"
|
||||||
"github.com/netbirdio/netbird/client/iface"
|
"github.com/netbirdio/netbird/client/iface"
|
||||||
@@ -87,7 +87,7 @@ func TestDefaultManager(t *testing.T) {
|
|||||||
networkMap.FirewallRules = append(
|
networkMap.FirewallRules = append(
|
||||||
networkMap.FirewallRules,
|
networkMap.FirewallRules,
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "10.93.0.3",
|
PeerIP: "10.93.0.3", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_DROP,
|
Action: mgmProto.RuleAction_DROP,
|
||||||
Protocol: mgmProto.RuleProtocol_ICMP,
|
Protocol: mgmProto.RuleProtocol_ICMP,
|
||||||
@@ -556,12 +556,12 @@ func TestApplyFilteringSkipsUnchangedConfig(t *testing.T) {
|
|||||||
|
|
||||||
func buildNetworkMap(peerRules, routeRules int) *mgmProto.NetworkMap {
|
func buildNetworkMap(peerRules, routeRules int) *mgmProto.NetworkMap {
|
||||||
nm := &mgmProto.NetworkMap{
|
nm := &mgmProto.NetworkMap{
|
||||||
FirewallRulesIsEmpty: peerRules == 0,
|
FirewallRulesIsEmpty: peerRules == 0,
|
||||||
RoutesFirewallRulesIsEmpty: routeRules == 0,
|
RoutesFirewallRulesIsEmpty: routeRules == 0,
|
||||||
}
|
}
|
||||||
for i := range peerRules {
|
for i := range peerRules {
|
||||||
nm.FirewallRules = append(nm.FirewallRules, &mgmProto.FirewallRule{
|
nm.FirewallRules = append(nm.FirewallRules, &mgmProto.FirewallRule{
|
||||||
PeerIP: fmt.Sprintf("10.%d.%d.%d", i>>16&0xff, i>>8&0xff, i&0xff),
|
PeerIP: fmt.Sprintf("10.%d.%d.%d", i>>16&0xff, i>>8&0xff, i&0xff), //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_TCP,
|
Protocol: mgmProto.RuleProtocol_TCP,
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ func (r *registryConfigurator) flushDNSCache() {
|
|||||||
|
|
||||||
ret, _, err := dnsFlushResolverCacheFn.Call()
|
ret, _, err := dnsFlushResolverCacheFn.Call()
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
if err != nil && !errors.Is(err, syscall.Errno(0)) {
|
if !errors.Is(err, syscall.Errno(0)) {
|
||||||
log.Errorf("DnsFlushResolverCache failed: %v", err)
|
log.Errorf("DnsFlushResolverCache failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -627,7 +627,7 @@ func refreshGroupPolicy() error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
if err != nil && !errors.Is(err, syscall.Errno(0)) {
|
if !errors.Is(err, syscall.Errno(0)) {
|
||||||
return fmt.Errorf("RefreshPolicyEx failed: %w", err)
|
return fmt.Errorf("RefreshPolicyEx failed: %w", err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("RefreshPolicyEx failed")
|
return fmt.Errorf("RefreshPolicyEx failed")
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (m *Manager) Start(fwdEntries []*ForwarderEntry) error {
|
|||||||
m.dnsForwarder = NewDNSForwarder(listenAddress, dnsTTL, m.firewall, m.statusRecorder, m.wgIface)
|
m.dnsForwarder = NewDNSForwarder(listenAddress, dnsTTL, m.firewall, m.statusRecorder, m.wgIface)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := m.dnsForwarder.Listen(fwdEntries); err != nil {
|
if err := m.dnsForwarder.Listen(fwdEntries); err != nil { //nolint:staticcheck
|
||||||
// todo handle close error if it is exists
|
// todo handle close error if it is exists
|
||||||
log.Errorf("failed to start DNS forwarder, err: %v", err)
|
log.Errorf("failed to start DNS forwarder, err: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2572,7 +2572,7 @@ func (e *Engine) SetCapture(pc device.PacketCapture) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afc := capture.NewAFPacketCapture(intf.Name(), sess)
|
afc := capture.NewAFPacketCapture(intf.Name(), sess)
|
||||||
if err := afc.Start(); err != nil {
|
if err := afc.Start(); err != nil { //nolint:staticcheck // always errors on non-Linux builds
|
||||||
return fmt.Errorf("start AF_PACKET capture on %s: %w", intf.Name(), err)
|
return fmt.Errorf("start AF_PACKET capture on %s: %w", intf.Name(), err)
|
||||||
}
|
}
|
||||||
e.afpacketCapture = afc
|
e.afpacketCapture = afc
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ func (conn *Conn) onICEConnectionIsReady(priority conntype.ConnPriority, iceConn
|
|||||||
conn.dumpState.NewLocalProxy()
|
conn.dumpState.NewLocalProxy()
|
||||||
wgProxy, err = conn.newProxy(iceConnInfo.RemoteConn)
|
wgProxy, err = conn.newProxy(iceConnInfo.RemoteConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Log.Errorf("failed to add turn net.Conn to local proxy: %v", err)
|
conn.Log.Errorf("failed to add relayed net.Conn to local proxy: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ep = wgProxy.EndpointAddr()
|
ep = wgProxy.EndpointAddr()
|
||||||
@@ -883,9 +883,8 @@ func (conn *Conn) newProxy(remoteConn net.Conn) (wgproxy.Proxy, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wgProxy := conn.config.WgConfig.WgInterface.GetProxy()
|
wgProxy := conn.config.WgConfig.WgInterface.GetProxy()
|
||||||
if err := wgProxy.AddTurnConn(conn.ctx, udpAddr, remoteConn); err != nil {
|
if err := wgProxy.AddRelayedConn(conn.ctx, udpAddr, remoteConn); err != nil {
|
||||||
conn.Log.Errorf("failed to add turn net.Conn to local proxy: %v", err)
|
return nil, fmt.Errorf("add relayed conn to proxy: %w", err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
return wgProxy, nil
|
return wgProxy, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,8 +255,8 @@ func (w *WorkerICE) connect(ctx context.Context, agent *icemaker.ThreadSafeAgent
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.log.Debugf("turn agent dial")
|
w.log.Debugf("agent dial")
|
||||||
remoteConn, err := w.turnAgentDial(ctx, agent, remoteOfferAnswer)
|
remoteConn, err := w.agentDial(ctx, agent, remoteOfferAnswer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.log.Debugf("failed to dial the remote peer: %s", err)
|
w.log.Debugf("failed to dial the remote peer: %s", err)
|
||||||
w.closeAgent(agent, w.agentDialerCancel)
|
w.closeAgent(agent, w.agentDialerCancel)
|
||||||
@@ -517,8 +517,8 @@ func (w *WorkerICE) onConnectionStateChange(agent *icemaker.ThreadSafeAgent, dia
|
|||||||
w.logSuccessfulPaths(agent)
|
w.logSuccessfulPaths(agent)
|
||||||
return
|
return
|
||||||
case ice.ConnectionStateFailed, ice.ConnectionStateDisconnected, ice.ConnectionStateClosed:
|
case ice.ConnectionStateFailed, ice.ConnectionStateDisconnected, ice.ConnectionStateClosed:
|
||||||
// ice.ConnectionStateClosed happens when we recreate the agent. For the P2P to TURN switch important to
|
// ice.ConnectionStateClosed happens when we recreate the agent. The P2P to relay switch requires
|
||||||
// notify the conn.onICEStateDisconnected changes to update the current used priority
|
// notifying conn.onICEStateDisconnected so it can update the currently used priority.
|
||||||
|
|
||||||
sessionChanged := w.closeAgent(agent, dialerCancel)
|
sessionChanged := w.closeAgent(agent, dialerCancel)
|
||||||
|
|
||||||
@@ -532,7 +532,7 @@ func (w *WorkerICE) onConnectionStateChange(agent *icemaker.ThreadSafeAgent, dia
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkerICE) turnAgentDial(ctx context.Context, agent *icemaker.ThreadSafeAgent, remoteOfferAnswer *OfferAnswer) (*ice.Conn, error) {
|
func (w *WorkerICE) agentDial(ctx context.Context, agent *icemaker.ThreadSafeAgent, remoteOfferAnswer *OfferAnswer) (*ice.Conn, error) {
|
||||||
if isController(w.config) {
|
if isController(w.config) {
|
||||||
return agent.Dial(ctx, remoteOfferAnswer.IceCredentials.UFrag, remoteOfferAnswer.IceCredentials.Pwd)
|
return agent.Dial(ctx, remoteOfferAnswer.IceCredentials.UFrag, remoteOfferAnswer.IceCredentials.Pwd)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ type Service struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Service, error) {
|
func New() (*Service, error) {
|
||||||
d, err := NewDetector()
|
d, err := NewDetector() //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on platforms without a sleep detector
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ func (m *Manager) install(ctx context.Context, pendingVersion *v.Version) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
inst := installer.New()
|
inst := installer.New()
|
||||||
if err := inst.RunInstallation(ctx, pendingVersion.String()); err != nil {
|
if err := inst.RunInstallation(ctx, pendingVersion.String()); err != nil { //nolint:staticcheck // always errors on platforms without an installer
|
||||||
log.Errorf("error triggering update: %v", err)
|
log.Errorf("error triggering update: %v", err)
|
||||||
m.statusRecorder.PublishEvent(
|
m.statusRecorder.PublishEvent(
|
||||||
cProto.SystemEvent_ERROR,
|
cProto.SystemEvent_ERROR,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -69,7 +70,7 @@ func setStdHandle(f *os.File) error {
|
|||||||
handle := f.Fd()
|
handle := f.Fd()
|
||||||
r0, _, e1 := setStdHandleFn.Call(stdErrorHandle, handle)
|
r0, _, e1 := setStdHandleFn.Call(stdErrorHandle, handle)
|
||||||
if r0 == 0 {
|
if r0 == 0 {
|
||||||
if e1 != nil {
|
if !errors.Is(e1, syscall.Errno(0)) {
|
||||||
return e1
|
return e1
|
||||||
}
|
}
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ func (s *Server) createCommand(logger *log.Entry, privilegeResult PrivilegeCheck
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try su first for system integration (PAM/audit) when privileged
|
// Try su first for system integration (PAM/audit) when privileged
|
||||||
cmd, err := s.createSuCommand(logger, session, localUser, hasPty)
|
cmd, err := s.createSuCommand(logger, session, localUser, hasPty) //nolint:staticcheck
|
||||||
if err != nil || privilegeResult.UsedFallback {
|
if err != nil || privilegeResult.UsedFallback { //nolint:staticcheck // always errors on platforms without su
|
||||||
logger.Debugf("su command failed, falling back to executor: %v", err)
|
logger.Debugf("su command failed, falling back to executor: %v", err)
|
||||||
cmd, cleanup, err := s.createExecutorCommand(logger, session, localUser, hasPty)
|
cmd, cleanup, err := s.createExecutorCommand(logger, session, localUser, hasPty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -146,11 +146,14 @@ func (c *GRPCClient) Receive(ctx context.Context, interval time.Duration, msgHan
|
|||||||
|
|
||||||
streamStart := time.Now()
|
streamStart := time.Now()
|
||||||
|
|
||||||
if err := c.receive(stream, msgHandler); err != nil {
|
// receive always returns a non-nil error once the stream breaks;
|
||||||
|
// handleRetryableError decides between reconnecting and exiting
|
||||||
|
// permanently on local context cancellation
|
||||||
|
err = c.receive(stream, msgHandler)
|
||||||
|
if !isContextDone(err) {
|
||||||
log.Errorf("receive failed: %v", err)
|
log.Errorf("receive failed: %v", err)
|
||||||
return c.handleRetryableError(err, streamStart, backOff)
|
|
||||||
}
|
}
|
||||||
return nil
|
return c.handleRetryableError(err, streamStart, backOff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := backoff.Retry(operation, backOff); err != nil {
|
if err := backoff.Retry(operation, backOff); err != nil {
|
||||||
|
|||||||
@@ -1024,7 +1024,7 @@ func (c *Controller) OnPeersDeleted(ctx context.Context, accountID string, peerI
|
|||||||
FirewallRules: []*proto.FirewallRule{},
|
FirewallRules: []*proto.FirewallRule{},
|
||||||
FirewallRulesIsEmpty: true,
|
FirewallRulesIsEmpty: true,
|
||||||
DNSConfig: &proto.DNSConfig{
|
DNSConfig: &proto.DNSConfig{
|
||||||
ForwarderPort: dnsFwdPort,
|
ForwarderPort: dnsFwdPort, //nolint:staticcheck
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ func buildJWTConfig(config *nbconfig.HttpServerConfig, deviceFlowConfig *nbconfi
|
|||||||
|
|
||||||
return &proto.JWTConfig{
|
return &proto.JWTConfig{
|
||||||
Issuer: issuer,
|
Issuer: issuer,
|
||||||
Audience: audience,
|
Audience: audience, //nolint:staticcheck
|
||||||
Audiences: audiences,
|
Audiences: audiences,
|
||||||
KeysLocation: keysLocation,
|
KeysLocation: keysLocation,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1140,7 +1140,7 @@ func (s *Server) GetDeviceAuthorizationFlow(ctx context.Context, req *proto.Encr
|
|||||||
Provider: proto.DeviceAuthorizationFlowProvider(provider),
|
Provider: proto.DeviceAuthorizationFlowProvider(provider),
|
||||||
ProviderConfig: &proto.ProviderConfig{
|
ProviderConfig: &proto.ProviderConfig{
|
||||||
ClientID: s.config.DeviceAuthorizationFlow.ProviderConfig.ClientID,
|
ClientID: s.config.DeviceAuthorizationFlow.ProviderConfig.ClientID,
|
||||||
ClientSecret: s.config.DeviceAuthorizationFlow.ProviderConfig.ClientSecret,
|
ClientSecret: s.config.DeviceAuthorizationFlow.ProviderConfig.ClientSecret, //nolint:staticcheck
|
||||||
Domain: s.config.DeviceAuthorizationFlow.ProviderConfig.Domain,
|
Domain: s.config.DeviceAuthorizationFlow.ProviderConfig.Domain,
|
||||||
Audience: s.config.DeviceAuthorizationFlow.ProviderConfig.Audience,
|
Audience: s.config.DeviceAuthorizationFlow.ProviderConfig.Audience,
|
||||||
DeviceAuthEndpoint: s.config.DeviceAuthorizationFlow.ProviderConfig.DeviceAuthEndpoint,
|
DeviceAuthEndpoint: s.config.DeviceAuthorizationFlow.ProviderConfig.DeviceAuthEndpoint,
|
||||||
@@ -1211,7 +1211,7 @@ func (s *Server) GetPKCEAuthorizationFlow(ctx context.Context, req *proto.Encryp
|
|||||||
ProviderConfig: &proto.ProviderConfig{
|
ProviderConfig: &proto.ProviderConfig{
|
||||||
Audience: s.config.PKCEAuthorizationFlow.ProviderConfig.Audience,
|
Audience: s.config.PKCEAuthorizationFlow.ProviderConfig.Audience,
|
||||||
ClientID: s.config.PKCEAuthorizationFlow.ProviderConfig.ClientID,
|
ClientID: s.config.PKCEAuthorizationFlow.ProviderConfig.ClientID,
|
||||||
ClientSecret: s.config.PKCEAuthorizationFlow.ProviderConfig.ClientSecret,
|
ClientSecret: s.config.PKCEAuthorizationFlow.ProviderConfig.ClientSecret, //nolint:staticcheck
|
||||||
TokenEndpoint: s.config.PKCEAuthorizationFlow.ProviderConfig.TokenEndpoint,
|
TokenEndpoint: s.config.PKCEAuthorizationFlow.ProviderConfig.TokenEndpoint,
|
||||||
AuthorizationEndpoint: s.config.PKCEAuthorizationFlow.ProviderConfig.AuthorizationEndpoint,
|
AuthorizationEndpoint: s.config.PKCEAuthorizationFlow.ProviderConfig.AuthorizationEndpoint,
|
||||||
Scope: s.config.PKCEAuthorizationFlow.ProviderConfig.Scope,
|
Scope: s.config.PKCEAuthorizationFlow.ProviderConfig.Scope,
|
||||||
|
|||||||
@@ -591,7 +591,7 @@ func Test_GetPKCEAuthorizationFlow(t *testing.T) {
|
|||||||
expectedFlowInfo := &mgmtProto.PKCEAuthorizationFlow{
|
expectedFlowInfo := &mgmtProto.PKCEAuthorizationFlow{
|
||||||
ProviderConfig: &mgmtProto.ProviderConfig{
|
ProviderConfig: &mgmtProto.ProviderConfig{
|
||||||
ClientID: "client",
|
ClientID: "client",
|
||||||
ClientSecret: "secret",
|
ClientSecret: "secret", //nolint:staticcheck
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ func ToProtocolDNSConfig(update nbdns.Config, cache DNSConfigCache, forwardPort
|
|||||||
ServiceEnable: update.ServiceEnable,
|
ServiceEnable: update.ServiceEnable,
|
||||||
CustomZones: make([]*proto.CustomZone, 0, len(update.CustomZones)),
|
CustomZones: make([]*proto.CustomZone, 0, len(update.CustomZones)),
|
||||||
NameServerGroups: make([]*proto.NameServerGroup, 0, len(update.NameServerGroups)),
|
NameServerGroups: make([]*proto.NameServerGroup, 0, len(update.NameServerGroups)),
|
||||||
ForwarderPort: forwardPort,
|
ForwarderPort: forwardPort, //nolint:staticcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, zone := range update.CustomZones {
|
for _, zone := range update.CustomZones {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
port := 51820
|
port := 51820
|
||||||
rawSock, err := sharedsock.Listen(port, sharedsock.NewIncomingSTUNFilter(), iface.DefaultMTU)
|
rawSock, err := sharedsock.Listen(port, sharedsock.NewIncomingSTUNFilter(), iface.DefaultMTU) //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on non-Linux builds
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -26,7 +26,7 @@ func WriteBytesWithRestrictedPermission(ctx context.Context, file string, bs []b
|
|||||||
return fmt.Errorf("enforce permission: %w", err)
|
return fmt.Errorf("enforce permission: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeBytes(ctx, file, err, configDir, configFileName, bs)
|
return writeBytes(ctx, file, configDir, configFileName, bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJsonWithRestrictedPermission writes JSON config object to a file. Enforces permission on the parent directory
|
// WriteJsonWithRestrictedPermission writes JSON config object to a file. Enforces permission on the parent directory
|
||||||
@@ -106,10 +106,10 @@ func writeJson(ctx context.Context, file string, obj interface{}, configDir stri
|
|||||||
return fmt.Errorf("marshal: %w", err)
|
return fmt.Errorf("marshal: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeBytes(ctx, file, err, configDir, configFileName, bs)
|
return writeBytes(ctx, file, configDir, configFileName, bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBytes(ctx context.Context, file string, err error, configDir string, configFileName string, bs []byte) error {
|
func writeBytes(ctx context.Context, file string, configDir string, configFileName string, bs []byte) error {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return fmt.Errorf("write bytes start: %w", ctx.Err())
|
return fmt.Errorf("write bytes start: %w", ctx.Err())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user