|
@@ -172,6 +172,7 @@ func ixHandshakeStage1(f *Interface, addr netip.AddrPort, via *ViaSender, packet
|
|
|
}
|
|
|
|
|
|
var vpnAddrs []netip.Addr
|
|
|
+ var filteredNetworks []netip.Prefix
|
|
|
certName := remoteCert.Certificate.Name()
|
|
|
fingerprint := remoteCert.Fingerprint
|
|
|
issuer := remoteCert.Certificate.Issuer()
|
|
@@ -189,15 +190,32 @@ func ixHandshakeStage1(f *Interface, addr netip.AddrPort, via *ViaSender, packet
|
|
|
}
|
|
|
|
|
|
if addr.IsValid() {
|
|
|
+ // addr can be invalid when the tunnel is being relayed.
|
|
|
+ // We only want to apply the remote allow list for direct tunnels here
|
|
|
if !f.lightHouse.GetRemoteAllowList().Allow(vpnAddr, addr.Addr()) {
|
|
|
f.l.WithField("vpnAddr", vpnAddr).WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // vpnAddrs outside our vpn networks are of no use to us, filter them out
|
|
|
+ if _, ok := f.myVpnNetworksTable.Lookup(vpnAddr); !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ filteredNetworks = append(filteredNetworks, network)
|
|
|
vpnAddrs = append(vpnAddrs, vpnAddr)
|
|
|
}
|
|
|
|
|
|
+ if len(vpnAddrs) == 0 {
|
|
|
+ f.l.WithError(err).WithField("udpAddr", addr).
|
|
|
+ WithField("certName", certName).
|
|
|
+ WithField("fingerprint", fingerprint).
|
|
|
+ WithField("issuer", issuer).
|
|
|
+ WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("No usable vpn addresses from host, refusing handshake")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
myIndex, err := generateIndex(f.l)
|
|
|
if err != nil {
|
|
|
f.l.WithError(err).WithField("vpnAddrs", vpnAddrs).WithField("udpAddr", addr).
|
|
@@ -294,7 +312,7 @@ func ixHandshakeStage1(f *Interface, addr netip.AddrPort, via *ViaSender, packet
|
|
|
|
|
|
hostinfo.remotes = f.lightHouse.QueryCache(vpnAddrs)
|
|
|
hostinfo.SetRemote(addr)
|
|
|
- hostinfo.buildNetworks(remoteCert.Certificate)
|
|
|
+ hostinfo.buildNetworks(filteredNetworks, remoteCert.Certificate.UnsafeNetworks())
|
|
|
|
|
|
existing, err := f.handshakeManager.CheckAndComplete(hostinfo, 0, f)
|
|
|
if err != nil {
|
|
@@ -431,7 +449,7 @@ func ixHandshakeStage2(f *Interface, addr netip.AddrPort, via *ViaSender, hh *Ha
|
|
|
|
|
|
hostinfo := hh.hostinfo
|
|
|
if addr.IsValid() {
|
|
|
- //TODO: this is kind of nonsense now
|
|
|
+ // The vpnAddr we know about is the one we tried to handshake with, use it to apply the remote allow list.
|
|
|
if !f.lightHouse.GetRemoteAllowList().Allow(hostinfo.vpnAddrs[0], addr.Addr()) {
|
|
|
f.l.WithField("vpnIp", hostinfo.vpnAddrs).WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
|
|
|
return false
|
|
@@ -492,7 +510,7 @@ func ixHandshakeStage2(f *Interface, addr netip.AddrPort, via *ViaSender, hh *Ha
|
|
|
e = e.WithField("cert", remoteCert)
|
|
|
}
|
|
|
|
|
|
- e.Info("Invalid vpn ip from host")
|
|
|
+ e.Info("Empty networks from host")
|
|
|
return true
|
|
|
}
|
|
|
|
|
@@ -516,9 +534,26 @@ func ixHandshakeStage2(f *Interface, addr netip.AddrPort, via *ViaSender, hh *Ha
|
|
|
hostinfo.relayState.InsertRelayTo(via.relayHI.vpnAddrs[0])
|
|
|
}
|
|
|
|
|
|
- vpnAddrs := make([]netip.Addr, len(vpnNetworks))
|
|
|
- for i, n := range vpnNetworks {
|
|
|
- vpnAddrs[i] = n.Addr()
|
|
|
+ var vpnAddrs []netip.Addr
|
|
|
+ var filteredNetworks []netip.Prefix
|
|
|
+ for _, network := range vpnNetworks {
|
|
|
+ // vpnAddrs outside our vpn networks are of no use to us, filter them out
|
|
|
+ vpnAddr := network.Addr()
|
|
|
+ if _, ok := f.myVpnNetworksTable.Lookup(vpnAddr); !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ filteredNetworks = append(filteredNetworks, network)
|
|
|
+ vpnAddrs = append(vpnAddrs, vpnAddr)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(vpnAddrs) == 0 {
|
|
|
+ f.l.WithError(err).WithField("udpAddr", addr).
|
|
|
+ WithField("certName", certName).
|
|
|
+ WithField("fingerprint", fingerprint).
|
|
|
+ WithField("issuer", issuer).
|
|
|
+ WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).Error("No usable vpn addresses from host, refusing handshake")
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
// Ensure the right host responded
|
|
@@ -558,7 +593,7 @@ func ixHandshakeStage2(f *Interface, addr netip.AddrPort, via *ViaSender, hh *Ha
|
|
|
ci.window.Update(f.l, 2)
|
|
|
|
|
|
duration := time.Since(hh.startTime).Nanoseconds()
|
|
|
- f.l.WithField("vpnNetworks", vpnNetworks).WithField("udpAddr", addr).
|
|
|
+ f.l.WithField("vpnAddrs", vpnAddrs).WithField("udpAddr", addr).
|
|
|
WithField("certName", certName).
|
|
|
WithField("fingerprint", fingerprint).
|
|
|
WithField("issuer", issuer).
|
|
@@ -569,9 +604,10 @@ func ixHandshakeStage2(f *Interface, addr netip.AddrPort, via *ViaSender, hh *Ha
|
|
|
Info("Handshake message received")
|
|
|
|
|
|
// Build up the radix for the firewall if we have subnets in the cert
|
|
|
- hostinfo.buildNetworks(remoteCert.Certificate)
|
|
|
+ hostinfo.vpnAddrs = vpnAddrs
|
|
|
+ hostinfo.buildNetworks(filteredNetworks, remoteCert.Certificate.UnsafeNetworks())
|
|
|
|
|
|
- // Complete our handshake and update metrics, this will replace any existing tunnels for this vpnIp
|
|
|
+ // Complete our handshake and update metrics, this will replace any existing tunnels for the vpnAddrs here
|
|
|
f.handshakeManager.Complete(hostinfo, f)
|
|
|
f.connectionManager.AddTrafficWatch(hostinfo.localIndexId)
|
|
|
|