Add more interfaces to ignore (#351)

This commit is contained in:
Misha Bragin 2022-06-04 20:15:41 +02:00 committed by GitHub
parent e6e9f0322f
commit fa0399d975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 15 deletions

View File

@ -58,7 +58,8 @@ func createNewConfig(managementURL, adminURL, configPath, preSharedKey string) (
config.PreSharedKey = preSharedKey config.PreSharedKey = preSharedKey
} }
config.IFaceBlackList = []string{iface.WgInterfaceDefault, "tun0"} config.IFaceBlackList = []string{iface.WgInterfaceDefault, "tun0", "zt", "ZeroTier", "utun", "wg", "ts",
"Tailscale", "tailscale"}
err := util.WriteJson(configPath, config) err := util.WriteJson(configPath, config)
if err != nil { if err != nil {

View File

@ -5,6 +5,7 @@ import (
"github.com/netbirdio/netbird/iface" "github.com/netbirdio/netbird/iface"
"golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl"
"net" "net"
"strings"
"sync" "sync"
"time" "time"
@ -84,27 +85,27 @@ func NewConn(config ConnConfig) (*Conn, error) {
}, nil }, nil
} }
// interfaceFilter is a function passed to ICE Agent to filter out blacklisted interfaces // interfaceFilter is a function passed to ICE Agent to filter out not allowed interfaces
// to avoid building tunnel over them
func interfaceFilter(blackList []string) func(string) bool { func interfaceFilter(blackList []string) func(string) bool {
var blackListMap map[string]struct{}
if blackList != nil {
blackListMap = make(map[string]struct{})
for _, s := range blackList {
blackListMap[s] = struct{}{}
}
}
return func(iFace string) bool {
_, ok := blackListMap[iFace] return func(iFace string) bool {
if ok { for _, s := range blackList {
return false if strings.HasPrefix(iFace, s) {
return false
}
} }
// look for unlisted Wireguard interfaces // look for unlisted WireGuard interfaces
wg, err := wgctrl.New() wg, err := wgctrl.New()
if err != nil { if err != nil {
log.Debugf("trying to create a wgctrl client failed with: %v", err) log.Debugf("trying to create a wgctrl client failed with: %v", err)
} }
defer wg.Close() defer func() {
err := wg.Close()
if err != nil {
return
}
}()
_, err = wg.Device(iFace) _, err = wg.Device(iFace)
return err != nil return err != nil

View File

@ -3,6 +3,7 @@ package peer
import ( import (
"github.com/magiconair/properties/assert" "github.com/magiconair/properties/assert"
"github.com/netbirdio/netbird/client/internal/proxy" "github.com/netbirdio/netbird/client/internal/proxy"
"github.com/netbirdio/netbird/iface"
"github.com/pion/ice/v2" "github.com/pion/ice/v2"
"sync" "sync"
"testing" "testing"
@ -18,6 +19,18 @@ var connConf = ConnConfig{
ProxyConfig: proxy.Config{}, ProxyConfig: proxy.Config{},
} }
func TestNewConn_interfaceFilter(t *testing.T) {
ignore := []string{iface.WgInterfaceDefault, "tun0", "zt", "ZeroTier", "utun", "wg", "ts",
"Tailscale", "tailscale"}
filter := interfaceFilter(ignore)
for _, s := range ignore {
assert.Equal(t, filter(s), false)
}
}
func TestConn_GetKey(t *testing.T) { func TestConn_GetKey(t *testing.T) {
conn, err := NewConn(connConf) conn, err := NewConn(connConf)
if err != nil { if err != nil {