diff --git a/README.md b/README.md index f53e5e3..c12cdb3 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Robert Eperjesi](https://github.com/epes) * [Sebastian Waisbrot](https://github.com/seppo0010) * [Zizheng Tai](https://github.com/ZizhengTai) +* [Aaron France](https://github.com/AeroNotix) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/gather_vnet_test.go b/gather_vnet_test.go index 8fc24e3..3f1fea6 100644 --- a/gather_vnet_test.go +++ b/gather_vnet_test.go @@ -343,3 +343,63 @@ func TestVNetGatherWithNAT1To1(t *testing.T) { assert.Equal(t, "1.2.3.4", candiSrflx.Address(), "should match") }) } + +func TestVNetGatherWithInterfaceFilter(t *testing.T) { + loggerFactory := logging.NewDefaultLoggerFactory() + r, err := vnet.NewRouter(&vnet.RouterConfig{ + CIDR: "1.2.3.0/24", + LoggerFactory: loggerFactory, + }) + if err != nil { + t.Fatalf("Failed to create a router: %s", err) + } + + nw := vnet.NewNet(&vnet.NetConfig{}) + if nw == nil { + t.Fatalf("Failed to create a Net: %s", err) + } + + if err = r.AddNet(nw); err != nil { + t.Fatalf("Failed to add a Net to the router: %s", err) + } + + t.Run("InterfaceFilter should exclude the interface", func(t *testing.T) { + a, err := NewAgent(&AgentConfig{ + Net: nw, + InterfaceFilter: func(interfaceName string) bool { + assert.Equal(t, "eth0", interfaceName) + return false + }, + }) + if err != nil { + t.Fatalf("Failed to create agent: %s", err) + } + + localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4}) + if err != nil { + t.Fatal(err) + } else if len(localIPs) != 0 { + t.Fatal("InterfaceFilter should have excluded everything") + } + }) + + t.Run("InterfaceFilter should not exclude the interface", func(t *testing.T) { + a, err := NewAgent(&AgentConfig{ + Net: nw, + InterfaceFilter: func(interfaceName string) bool { + assert.Equal(t, "eth0", interfaceName) + return true + }, + }) + if err != nil { + t.Fatalf("Failed to create agent: %s", err) + } + + localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4}) + if err != nil { + t.Fatal(err) + } else if len(localIPs) == 0 { + t.Fatal("InterfaceFilter should not have excluded anything") + } + }) +}