|
@@ -306,13 +306,16 @@ func TestLighthouse_reload(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func newLHHostRequest(fromAddr netip.AddrPort, myVpnIp, queryVpnIp netip.Addr, lhh *LightHouseHandler) testLhReply {
|
|
|
- //TODO: IPV6-WORK
|
|
|
- bip := queryVpnIp.As4()
|
|
|
req := &NebulaMeta{
|
|
|
- Type: NebulaMeta_HostQuery,
|
|
|
- Details: &NebulaMetaDetails{
|
|
|
- OldVpnAddr: binary.BigEndian.Uint32(bip[:]),
|
|
|
- },
|
|
|
+ Type: NebulaMeta_HostQuery,
|
|
|
+ Details: &NebulaMetaDetails{},
|
|
|
+ }
|
|
|
+
|
|
|
+ if queryVpnIp.Is4() {
|
|
|
+ bip := queryVpnIp.As4()
|
|
|
+ req.Details.OldVpnAddr = binary.BigEndian.Uint32(bip[:])
|
|
|
+ } else {
|
|
|
+ req.Details.VpnAddr = netAddrToProtoAddr(queryVpnIp)
|
|
|
}
|
|
|
|
|
|
b, err := req.Marshal()
|
|
@@ -329,18 +332,24 @@ func newLHHostRequest(fromAddr netip.AddrPort, myVpnIp, queryVpnIp netip.Addr, l
|
|
|
}
|
|
|
|
|
|
func newLHHostUpdate(fromAddr netip.AddrPort, vpnIp netip.Addr, addrs []netip.AddrPort, lhh *LightHouseHandler) {
|
|
|
- //TODO: IPV6-WORK
|
|
|
- bip := vpnIp.As4()
|
|
|
req := &NebulaMeta{
|
|
|
- Type: NebulaMeta_HostUpdateNotification,
|
|
|
- Details: &NebulaMetaDetails{
|
|
|
- OldVpnAddr: binary.BigEndian.Uint32(bip[:]),
|
|
|
- V4AddrPorts: make([]*V4AddrPort, len(addrs)),
|
|
|
- },
|
|
|
+ Type: NebulaMeta_HostUpdateNotification,
|
|
|
+ Details: &NebulaMetaDetails{},
|
|
|
}
|
|
|
|
|
|
- for k, v := range addrs {
|
|
|
- req.Details.V4AddrPorts[k] = netAddrToProtoV4AddrPort(v.Addr(), v.Port())
|
|
|
+ if vpnIp.Is4() {
|
|
|
+ bip := vpnIp.As4()
|
|
|
+ req.Details.OldVpnAddr = binary.BigEndian.Uint32(bip[:])
|
|
|
+ } else {
|
|
|
+ req.Details.VpnAddr = netAddrToProtoAddr(vpnIp)
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range addrs {
|
|
|
+ if v.Addr().Is4() {
|
|
|
+ req.Details.V4AddrPorts = append(req.Details.V4AddrPorts, netAddrToProtoV4AddrPort(v.Addr(), v.Port()))
|
|
|
+ } else {
|
|
|
+ req.Details.V6AddrPorts = append(req.Details.V6AddrPorts, netAddrToProtoV6AddrPort(v.Addr(), v.Port()))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
b, err := req.Marshal()
|
|
@@ -352,72 +361,6 @@ func newLHHostUpdate(fromAddr netip.AddrPort, vpnIp netip.Addr, addrs []netip.Ad
|
|
|
lhh.HandleRequest(fromAddr, []netip.Addr{vpnIp}, b, w)
|
|
|
}
|
|
|
|
|
|
-//TODO: this is a RemoteList test
|
|
|
-//func Test_lhRemoteAllowList(t *testing.T) {
|
|
|
-// l := NewLogger()
|
|
|
-// c := NewConfig(l)
|
|
|
-// c.Settings["remoteallowlist"] = map[interface{}]interface{}{
|
|
|
-// "10.20.0.0/12": false,
|
|
|
-// }
|
|
|
-// allowList, err := c.GetAllowList("remoteallowlist", false)
|
|
|
-// assert.Nil(t, err)
|
|
|
-//
|
|
|
-// lh1 := "10.128.0.2"
|
|
|
-// lh1IP := net.ParseIP(lh1)
|
|
|
-//
|
|
|
-// udpServer, _ := NewListener(l, "0.0.0.0", 0, true)
|
|
|
-//
|
|
|
-// lh := NewLightHouse(l, true, &net.IPNet{IP: net.IP{0, 0, 0, 1}, Mask: net.IPMask{255, 255, 255, 0}}, []uint32{ip2int(lh1IP)}, 10, 10003, udpServer, false, 1, false)
|
|
|
-// lh.SetRemoteAllowList(allowList)
|
|
|
-//
|
|
|
-// // A disallowed ip should not enter the cache but we should end up with an empty entry in the addrMap
|
|
|
-// remote1IP := net.ParseIP("10.20.0.3")
|
|
|
-// remotes := lh.unlockedGetRemoteList(ip2int(remote1IP))
|
|
|
-// remotes.unlockedPrependV4(ip2int(remote1IP), NewIp4AndPort(remote1IP, 4242))
|
|
|
-// assert.NotNil(t, lh.addrMap[ip2int(remote1IP)])
|
|
|
-// assert.Empty(t, lh.addrMap[ip2int(remote1IP)].CopyAddrs([]*net.IPNet{}))
|
|
|
-//
|
|
|
-// // Make sure a good ip enters the cache and addrMap
|
|
|
-// remote2IP := net.ParseIP("10.128.0.3")
|
|
|
-// remote2UDPAddr := NewUDPAddr(remote2IP, uint16(4242))
|
|
|
-// lh.addRemoteV4(ip2int(remote2IP), ip2int(remote2IP), NewIp4AndPort(remote2UDPAddr.IP, uint32(remote2UDPAddr.Port)), false, false)
|
|
|
-// assertUdpAddrInArray(t, lh.addrMap[ip2int(remote2IP)].CopyAddrs([]*net.IPNet{}), remote2UDPAddr)
|
|
|
-//
|
|
|
-// // Another good ip gets into the cache, ordering is inverted
|
|
|
-// remote3IP := net.ParseIP("10.128.0.4")
|
|
|
-// remote3UDPAddr := NewUDPAddr(remote3IP, uint16(4243))
|
|
|
-// lh.addRemoteV4(ip2int(remote2IP), ip2int(remote2IP), NewIp4AndPort(remote3UDPAddr.IP, uint32(remote3UDPAddr.Port)), false, false)
|
|
|
-// assertUdpAddrInArray(t, lh.addrMap[ip2int(remote2IP)].CopyAddrs([]*net.IPNet{}), remote2UDPAddr, remote3UDPAddr)
|
|
|
-//
|
|
|
-// // If we exceed the length limit we should only have the most recent addresses
|
|
|
-// addedAddrs := []*udpAddr{}
|
|
|
-// for i := 0; i < 11; i++ {
|
|
|
-// remoteUDPAddr := NewUDPAddr(net.IP{10, 128, 0, 4}, uint16(4243+i))
|
|
|
-// lh.addRemoteV4(ip2int(remote2IP), ip2int(remote2IP), NewIp4AndPort(remoteUDPAddr.IP, uint32(remoteUDPAddr.Port)), false, false)
|
|
|
-// // The first entry here is a duplicate, don't add it to the assert list
|
|
|
-// if i != 0 {
|
|
|
-// addedAddrs = append(addedAddrs, remoteUDPAddr)
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // We should only have the last 10 of what we tried to add
|
|
|
-// assert.True(t, len(addedAddrs) >= 10, "We should have tried to add at least 10 addresses")
|
|
|
-// assertUdpAddrInArray(
|
|
|
-// t,
|
|
|
-// lh.addrMap[ip2int(remote2IP)].CopyAddrs([]*net.IPNet{}),
|
|
|
-// addedAddrs[0],
|
|
|
-// addedAddrs[1],
|
|
|
-// addedAddrs[2],
|
|
|
-// addedAddrs[3],
|
|
|
-// addedAddrs[4],
|
|
|
-// addedAddrs[5],
|
|
|
-// addedAddrs[6],
|
|
|
-// addedAddrs[7],
|
|
|
-// addedAddrs[8],
|
|
|
-// addedAddrs[9],
|
|
|
-// )
|
|
|
-//}
|
|
|
-
|
|
|
type testLhReply struct {
|
|
|
nebType header.MessageType
|
|
|
nebSubType header.MessageSubType
|
|
@@ -485,7 +428,6 @@ func assertIp4InArray(t *testing.T, have []*V4AddrPort, want ...netip.AddrPort)
|
|
|
}
|
|
|
|
|
|
for k, w := range want {
|
|
|
- //TODO: IPV6-WORK
|
|
|
h := protoV4AddrPortToNetAddrPort(have[k])
|
|
|
if !(h == w) {
|
|
|
assert.Fail(t, fmt.Sprintf("Response did not contain: %v at %v, found %v", w, k, h))
|