mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-10 18:58:27 +02:00
feat: add interface black list to avoid undesired interfaces
This commit is contained in:
parent
47933bcbfa
commit
a773ec8150
@ -17,6 +17,7 @@ type Config struct {
|
|||||||
SignalAddr string
|
SignalAddr string
|
||||||
WgAddr string
|
WgAddr string
|
||||||
WgIface string
|
WgIface string
|
||||||
|
IFaceBlackList []string
|
||||||
}
|
}
|
||||||
|
|
||||||
//Write writes configPath to a file
|
//Write writes configPath to a file
|
||||||
|
@ -38,7 +38,11 @@ var (
|
|||||||
//todo proper close handling
|
//todo proper close handling
|
||||||
defer func() { signalClient.Close() }()
|
defer func() { signalClient.Close() }()
|
||||||
|
|
||||||
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr)
|
iFaceBlackList := make(map[string]struct{})
|
||||||
|
for i := 0; i < len(config.IFaceBlackList); i += 2 {
|
||||||
|
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
|
||||||
|
}
|
||||||
|
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)
|
||||||
|
|
||||||
err = engine.Start(myKey, config.Peers)
|
err = engine.Start(myKey, config.Peers)
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ type ConnConfig struct {
|
|||||||
RemoteWgKey wgtypes.Key
|
RemoteWgKey wgtypes.Key
|
||||||
|
|
||||||
StunTurnURLS []*ice.URL
|
StunTurnURLS []*ice.URL
|
||||||
|
|
||||||
|
iFaceBlackList map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type IceCredentials struct {
|
type IceCredentials struct {
|
||||||
@ -88,6 +90,13 @@ func (conn *Connection) Open(timeout time.Duration) error {
|
|||||||
a, err := ice.NewAgent(&ice.AgentConfig{
|
a, err := ice.NewAgent(&ice.AgentConfig{
|
||||||
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
|
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
|
||||||
Urls: conn.Config.StunTurnURLS,
|
Urls: conn.Config.StunTurnURLS,
|
||||||
|
InterfaceFilter: func(s string) bool {
|
||||||
|
if conn.Config.iFaceBlackList == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
_, ok := conn.Config.iFaceBlackList[s]
|
||||||
|
return !ok
|
||||||
|
},
|
||||||
})
|
})
|
||||||
conn.agent = a
|
conn.agent = a
|
||||||
|
|
||||||
@ -280,7 +289,7 @@ func (conn *Connection) listenOnConnectionStateChanges() error {
|
|||||||
log.Errorf("failed selecting active ICE candidate pair %s", err)
|
log.Errorf("failed selecting active ICE candidate pair %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("closed to peer %s via selected candidate pair %s", conn.Config.RemoteWgKey.String(), pair)
|
log.Infof("will connect to peer %s via a selected connnection candidate pair %s", conn.Config.RemoteWgKey.String(), pair)
|
||||||
} else if state == ice.ConnectionStateDisconnected || state == ice.ConnectionStateFailed {
|
} else if state == ice.ConnectionStateDisconnected || state == ice.ConnectionStateFailed {
|
||||||
// todo do we really wanna have a connection restart within connection itself? Think of moving it outside
|
// todo do we really wanna have a connection restart within connection itself? Think of moving it outside
|
||||||
err := conn.Close()
|
err := conn.Close()
|
||||||
|
@ -23,6 +23,8 @@ type Engine struct {
|
|||||||
wgIface string
|
wgIface string
|
||||||
// Wireguard local address
|
// Wireguard local address
|
||||||
wgIp string
|
wgIp string
|
||||||
|
|
||||||
|
iFaceBlackList map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
@ -30,13 +32,15 @@ type Peer struct {
|
|||||||
WgAllowedIps string
|
WgAllowedIps string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgAddr string) *Engine {
|
func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgAddr string,
|
||||||
|
iFaceBlackList map[string]struct{}) *Engine {
|
||||||
return &Engine{
|
return &Engine{
|
||||||
stunsTurns: stunsTurns,
|
stunsTurns: stunsTurns,
|
||||||
signal: signal,
|
signal: signal,
|
||||||
wgIface: wgIface,
|
wgIface: wgIface,
|
||||||
wgIp: wgAddr,
|
wgIp: wgAddr,
|
||||||
conns: map[string]*Connection{},
|
conns: map[string]*Connection{},
|
||||||
|
iFaceBlackList: iFaceBlackList,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +112,7 @@ func (e *Engine) openPeerConnection(wgPort int, myKey wgtypes.Key, peer Peer) (*
|
|||||||
WgKey: myKey,
|
WgKey: myKey,
|
||||||
RemoteWgKey: remoteKey,
|
RemoteWgKey: remoteKey,
|
||||||
StunTurnURLS: e.stunsTurns,
|
StunTurnURLS: e.stunsTurns,
|
||||||
|
iFaceBlackList: e.iFaceBlackList,
|
||||||
}
|
}
|
||||||
|
|
||||||
signalOffer := func(uFrag string, pwd string) error {
|
signalOffer := func(uFrag string, pwd string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user