Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more interfaces to ignore #351

Merged
merged 4 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func createNewConfig(managementURL, adminURL, configPath, preSharedKey string) (
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)
if err != nil {
Expand Down
29 changes: 15 additions & 14 deletions client/internal/peer/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/netbirdio/netbird/iface"
"golang.zx2c4.com/wireguard/wgctrl"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -84,27 +85,27 @@ func NewConn(config ConnConfig) (*Conn, error) {
}, 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 {
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]
if ok {
return false
return func(iFace string) bool {
for _, s := range blackList {
if strings.HasPrefix(iFace, s) {
return false
}
}
// look for unlisted Wireguard interfaces
// look for unlisted WireGuard interfaces
wg, err := wgctrl.New()
if err != nil {
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)
return err != nil
Expand Down
13 changes: 13 additions & 0 deletions client/internal/peer/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package peer
import (
"github.com/magiconair/properties/assert"
"github.com/netbirdio/netbird/client/internal/proxy"
"github.com/netbirdio/netbird/iface"
"github.com/pion/ice/v2"
"sync"
"testing"
Expand All @@ -18,6 +19,18 @@ var connConf = ConnConfig{
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) {
conn, err := NewConn(connConf)
if err != nil {
Expand Down