mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-14 01:08:46 +02:00
Bind implementation (#779)
This PR adds supports for the WireGuard userspace implementation using Bind interface from wireguard-go. The newly introduced ICEBind struct implements Bind with UDPMux-based structs from pion/ice to handle hole punching using ICE. The core implementation was taken from StdBind of wireguard-go. The result is a single WireGuard port that is used for host and server reflexive candidates. Relay candidates are still handled separately and will be integrated in the following PRs. ICEBind checks the incoming packets for being STUN or WireGuard ones and routes them to UDPMux (to handle hole punching) or to WireGuard respectively.
This commit is contained in:
68
client/internal/stdnet/discover_mobile_test.go
Normal file
68
client/internal/stdnet/discover_mobile_test.go
Normal file
@ -0,0 +1,68 @@
|
||||
package stdnet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_parseInterfacesString(t *testing.T) {
|
||||
testData := []struct {
|
||||
name string
|
||||
index int
|
||||
mtu int
|
||||
up bool
|
||||
broadcast bool
|
||||
loopBack bool
|
||||
pointToPoint bool
|
||||
multicast bool
|
||||
addr string
|
||||
}{
|
||||
{"wlan0", 30, 1500, true, true, false, false, true, "10.1.10.131/24"},
|
||||
{"rmnet0", 30, 1500, true, true, false, false, true, "192.168.0.56/24"},
|
||||
{"rmnet_data1", 30, 1500, true, true, false, false, true, "fec0::118c:faf7:8d97:3cb2/64"},
|
||||
}
|
||||
|
||||
var exampleString string
|
||||
for _, d := range testData {
|
||||
exampleString = fmt.Sprintf("%s\n%s %d %d %t %t %t %t %t | %s", exampleString,
|
||||
d.name,
|
||||
d.index,
|
||||
d.mtu,
|
||||
d.up,
|
||||
d.broadcast,
|
||||
d.loopBack,
|
||||
d.pointToPoint,
|
||||
d.multicast,
|
||||
d.addr)
|
||||
}
|
||||
|
||||
d := mobileIFaceDiscover{}
|
||||
nets := d.parseInterfacesString(exampleString)
|
||||
if len(nets) == 0 {
|
||||
t.Fatalf("failed to parse interfaces")
|
||||
}
|
||||
|
||||
for i, net := range nets {
|
||||
if net.MTU != testData[i].mtu {
|
||||
t.Errorf("invalid mtu: %d, expected: %d", net.MTU, testData[0].mtu)
|
||||
|
||||
}
|
||||
|
||||
if net.Interface.Name != testData[i].name {
|
||||
t.Errorf("invalid interface name: %s, expected: %s", net.Interface.Name, testData[i].name)
|
||||
}
|
||||
|
||||
addr, err := net.Addrs()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(addr) == 0 {
|
||||
t.Errorf("invalid address parsing")
|
||||
}
|
||||
|
||||
if addr[0].String() != testData[i].addr {
|
||||
t.Errorf("invalid address: %s, expected: %s", addr[0].String(), testData[i].addr)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user