handshake_ix.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. package nebula
  2. import (
  3. "time"
  4. "github.com/flynn/noise"
  5. "github.com/slackhq/nebula/header"
  6. "github.com/slackhq/nebula/iputil"
  7. "github.com/slackhq/nebula/udp"
  8. )
  9. // NOISE IX Handshakes
  10. // This function constructs a handshake packet, but does not actually send it
  11. // Sending is done by the handshake manager
  12. func ixHandshakeStage0(f *Interface, hostinfo *HostInfo) bool {
  13. err := f.handshakeManager.allocateIndex(hostinfo)
  14. if err != nil {
  15. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).
  16. WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to generate index")
  17. return false
  18. }
  19. certState := f.pki.GetCertState()
  20. ci := NewConnectionState(f.l, f.cipher, certState, true, noise.HandshakeIX, []byte{}, 0)
  21. hostinfo.ConnectionState = ci
  22. hsProto := &NebulaHandshakeDetails{
  23. InitiatorIndex: hostinfo.localIndexId,
  24. Time: uint64(time.Now().UnixNano()),
  25. Cert: certState.RawCertificateNoKey,
  26. }
  27. hsBytes := []byte{}
  28. hs := &NebulaHandshake{
  29. Details: hsProto,
  30. }
  31. hsBytes, err = hs.Marshal()
  32. if err != nil {
  33. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).
  34. WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to marshal handshake message")
  35. return false
  36. }
  37. h := header.Encode(make([]byte, header.Len), header.Version, header.Handshake, header.HandshakeIXPSK0, 0, 1)
  38. ci.messageCounter.Add(1)
  39. msg, _, _, err := ci.H.WriteMessage(h, hsBytes)
  40. if err != nil {
  41. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).
  42. WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to call noise.WriteMessage")
  43. return false
  44. }
  45. // We are sending handshake packet 1, so we don't expect to receive
  46. // handshake packet 1 from the responder
  47. ci.window.Update(f.l, 1)
  48. hostinfo.HandshakePacket[0] = msg
  49. hostinfo.HandshakeReady = true
  50. hostinfo.handshakeStart = time.Now()
  51. return true
  52. }
  53. func ixHandshakeStage1(f *Interface, addr *udp.Addr, via *ViaSender, packet []byte, h *header.H) {
  54. certState := f.pki.GetCertState()
  55. ci := NewConnectionState(f.l, f.cipher, certState, false, noise.HandshakeIX, []byte{}, 0)
  56. // Mark packet 1 as seen so it doesn't show up as missed
  57. ci.window.Update(f.l, 1)
  58. msg, _, _, err := ci.H.ReadMessage(nil, packet[header.Len:])
  59. if err != nil {
  60. f.l.WithError(err).WithField("udpAddr", addr).
  61. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Failed to call noise.ReadMessage")
  62. return
  63. }
  64. hs := &NebulaHandshake{}
  65. err = hs.Unmarshal(msg)
  66. /*
  67. l.Debugln("GOT INDEX: ", hs.Details.InitiatorIndex)
  68. */
  69. if err != nil || hs.Details == nil {
  70. f.l.WithError(err).WithField("udpAddr", addr).
  71. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Failed unmarshal handshake message")
  72. return
  73. }
  74. remoteCert, err := RecombineCertAndValidate(ci.H, hs.Details.Cert, f.pki.GetCAPool())
  75. if err != nil {
  76. f.l.WithError(err).WithField("udpAddr", addr).
  77. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).WithField("cert", remoteCert).
  78. Info("Invalid certificate from host")
  79. return
  80. }
  81. vpnIp := iputil.Ip2VpnIp(remoteCert.Details.Ips[0].IP)
  82. certName := remoteCert.Details.Name
  83. fingerprint, _ := remoteCert.Sha256Sum()
  84. issuer := remoteCert.Details.Issuer
  85. if vpnIp == f.myVpnIp {
  86. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  87. WithField("certName", certName).
  88. WithField("fingerprint", fingerprint).
  89. WithField("issuer", issuer).
  90. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Refusing to handshake with myself")
  91. return
  92. }
  93. if addr != nil {
  94. if !f.lightHouse.GetRemoteAllowList().Allow(vpnIp, addr.IP) {
  95. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
  96. return
  97. }
  98. }
  99. myIndex, err := generateIndex(f.l)
  100. if err != nil {
  101. f.l.WithError(err).WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  102. WithField("certName", certName).
  103. WithField("fingerprint", fingerprint).
  104. WithField("issuer", issuer).
  105. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Failed to generate index")
  106. return
  107. }
  108. hostinfo := &HostInfo{
  109. ConnectionState: ci,
  110. localIndexId: myIndex,
  111. remoteIndexId: hs.Details.InitiatorIndex,
  112. vpnIp: vpnIp,
  113. HandshakePacket: make(map[uint8][]byte, 0),
  114. lastHandshakeTime: hs.Details.Time,
  115. relayState: RelayState{
  116. relays: map[iputil.VpnIp]struct{}{},
  117. relayForByIp: map[iputil.VpnIp]*Relay{},
  118. relayForByIdx: map[uint32]*Relay{},
  119. },
  120. }
  121. hostinfo.Lock()
  122. defer hostinfo.Unlock()
  123. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  124. WithField("certName", certName).
  125. WithField("fingerprint", fingerprint).
  126. WithField("issuer", issuer).
  127. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  128. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).
  129. Info("Handshake message received")
  130. hs.Details.ResponderIndex = myIndex
  131. hs.Details.Cert = certState.RawCertificateNoKey
  132. // Update the time in case their clock is way off from ours
  133. hs.Details.Time = uint64(time.Now().UnixNano())
  134. hsBytes, err := hs.Marshal()
  135. if err != nil {
  136. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  137. WithField("certName", certName).
  138. WithField("fingerprint", fingerprint).
  139. WithField("issuer", issuer).
  140. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Failed to marshal handshake message")
  141. return
  142. }
  143. nh := header.Encode(make([]byte, header.Len), header.Version, header.Handshake, header.HandshakeIXPSK0, hs.Details.InitiatorIndex, 2)
  144. msg, dKey, eKey, err := ci.H.WriteMessage(nh, hsBytes)
  145. if err != nil {
  146. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  147. WithField("certName", certName).
  148. WithField("fingerprint", fingerprint).
  149. WithField("issuer", issuer).
  150. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Failed to call noise.WriteMessage")
  151. return
  152. } else if dKey == nil || eKey == nil {
  153. f.l.WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  154. WithField("certName", certName).
  155. WithField("fingerprint", fingerprint).
  156. WithField("issuer", issuer).
  157. WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).Error("Noise did not arrive at a key")
  158. return
  159. }
  160. hostinfo.HandshakePacket[0] = make([]byte, len(packet[header.Len:]))
  161. copy(hostinfo.HandshakePacket[0], packet[header.Len:])
  162. // Regardless of whether you are the sender or receiver, you should arrive here
  163. // and complete standing up the connection.
  164. hostinfo.HandshakePacket[2] = make([]byte, len(msg))
  165. copy(hostinfo.HandshakePacket[2], msg)
  166. // We are sending handshake packet 2, so we don't expect to receive
  167. // handshake packet 2 from the initiator.
  168. ci.window.Update(f.l, 2)
  169. ci.peerCert = remoteCert
  170. ci.dKey = NewNebulaCipherState(dKey)
  171. ci.eKey = NewNebulaCipherState(eKey)
  172. hostinfo.remotes = f.lightHouse.QueryCache(vpnIp)
  173. hostinfo.SetRemote(addr)
  174. hostinfo.CreateRemoteCIDR(remoteCert)
  175. existing, err := f.handshakeManager.CheckAndComplete(hostinfo, 0, f)
  176. if err != nil {
  177. switch err {
  178. case ErrAlreadySeen:
  179. // Update remote if preferred (Note we have to switch to locking
  180. // the existing hostinfo, and then switch back so the defer Unlock
  181. // higher in this function still works)
  182. hostinfo.Unlock()
  183. existing.Lock()
  184. // Update remote if preferred
  185. if existing.SetRemoteIfPreferred(f.hostMap, addr) {
  186. // Send a test packet to ensure the other side has also switched to
  187. // the preferred remote
  188. f.SendMessageToVpnIp(header.Test, header.TestRequest, vpnIp, []byte(""), make([]byte, 12, 12), make([]byte, mtu))
  189. }
  190. existing.Unlock()
  191. hostinfo.Lock()
  192. msg = existing.HandshakePacket[2]
  193. f.messageMetrics.Tx(header.Handshake, header.MessageSubType(msg[1]), 1)
  194. if addr != nil {
  195. err := f.outside.WriteTo(msg, addr)
  196. if err != nil {
  197. f.l.WithField("vpnIp", existing.vpnIp).WithField("udpAddr", addr).
  198. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).WithField("cached", true).
  199. WithError(err).Error("Failed to send handshake message")
  200. } else {
  201. f.l.WithField("vpnIp", existing.vpnIp).WithField("udpAddr", addr).
  202. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).WithField("cached", true).
  203. Info("Handshake message sent")
  204. }
  205. return
  206. } else {
  207. if via == nil {
  208. f.l.Error("Handshake send failed: both addr and via are nil.")
  209. return
  210. }
  211. hostinfo.relayState.InsertRelayTo(via.relayHI.vpnIp)
  212. f.SendVia(via.relayHI, via.relay, msg, make([]byte, 12), make([]byte, mtu), false)
  213. f.l.WithField("vpnIp", existing.vpnIp).WithField("relay", via.relayHI.vpnIp).
  214. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).WithField("cached", true).
  215. Info("Handshake message sent")
  216. return
  217. }
  218. case ErrExistingHostInfo:
  219. // This means there was an existing tunnel and this handshake was older than the one we are currently based on
  220. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  221. WithField("certName", certName).
  222. WithField("oldHandshakeTime", existing.lastHandshakeTime).
  223. WithField("newHandshakeTime", hostinfo.lastHandshakeTime).
  224. WithField("fingerprint", fingerprint).
  225. WithField("issuer", issuer).
  226. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  227. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).
  228. Info("Handshake too old")
  229. // Send a test packet to trigger an authenticated tunnel test, this should suss out any lingering tunnel issues
  230. f.SendMessageToVpnIp(header.Test, header.TestRequest, vpnIp, []byte(""), make([]byte, 12, 12), make([]byte, mtu))
  231. return
  232. case ErrLocalIndexCollision:
  233. // This means we failed to insert because of collision on localIndexId. Just let the next handshake packet retry
  234. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  235. WithField("certName", certName).
  236. WithField("fingerprint", fingerprint).
  237. WithField("issuer", issuer).
  238. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  239. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).
  240. WithField("localIndex", hostinfo.localIndexId).WithField("collision", existing.vpnIp).
  241. Error("Failed to add HostInfo due to localIndex collision")
  242. return
  243. default:
  244. // Shouldn't happen, but just in case someone adds a new error type to CheckAndComplete
  245. // And we forget to update it here
  246. f.l.WithError(err).WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  247. WithField("certName", certName).
  248. WithField("fingerprint", fingerprint).
  249. WithField("issuer", issuer).
  250. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  251. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).
  252. Error("Failed to add HostInfo to HostMap")
  253. return
  254. }
  255. }
  256. // Do the send
  257. f.messageMetrics.Tx(header.Handshake, header.MessageSubType(msg[1]), 1)
  258. if addr != nil {
  259. err = f.outside.WriteTo(msg, addr)
  260. if err != nil {
  261. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  262. WithField("certName", certName).
  263. WithField("fingerprint", fingerprint).
  264. WithField("issuer", issuer).
  265. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  266. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  267. WithError(err).Error("Failed to send handshake")
  268. } else {
  269. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  270. WithField("certName", certName).
  271. WithField("fingerprint", fingerprint).
  272. WithField("issuer", issuer).
  273. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  274. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  275. WithField("sentCachedPackets", len(hostinfo.packetStore)).
  276. Info("Handshake message sent")
  277. }
  278. } else {
  279. if via == nil {
  280. f.l.Error("Handshake send failed: both addr and via are nil.")
  281. return
  282. }
  283. hostinfo.relayState.InsertRelayTo(via.relayHI.vpnIp)
  284. f.SendVia(via.relayHI, via.relay, msg, make([]byte, 12), make([]byte, mtu), false)
  285. f.l.WithField("vpnIp", vpnIp).WithField("relay", via.relayHI.vpnIp).
  286. WithField("certName", certName).
  287. WithField("fingerprint", fingerprint).
  288. WithField("issuer", issuer).
  289. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  290. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  291. WithField("sentCachedPackets", len(hostinfo.packetStore)).
  292. Info("Handshake message sent")
  293. }
  294. f.connectionManager.AddTrafficWatch(hostinfo.localIndexId)
  295. hostinfo.handshakeComplete(f.l, f.cachedPacketMetrics)
  296. return
  297. }
  298. func ixHandshakeStage2(f *Interface, addr *udp.Addr, via *ViaSender, hostinfo *HostInfo, packet []byte, h *header.H) bool {
  299. if hostinfo == nil {
  300. // Nothing here to tear down, got a bogus stage 2 packet
  301. return true
  302. }
  303. hostinfo.Lock()
  304. defer hostinfo.Unlock()
  305. if addr != nil {
  306. if !f.lightHouse.GetRemoteAllowList().Allow(hostinfo.vpnIp, addr.IP) {
  307. f.l.WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
  308. return false
  309. }
  310. }
  311. ci := hostinfo.ConnectionState
  312. if ci.ready {
  313. f.l.WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  314. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).WithField("header", h).
  315. Info("Handshake is already complete")
  316. // Update remote if preferred
  317. if hostinfo.SetRemoteIfPreferred(f.hostMap, addr) {
  318. // Send a test packet to ensure the other side has also switched to
  319. // the preferred remote
  320. f.SendMessageToVpnIp(header.Test, header.TestRequest, hostinfo.vpnIp, []byte(""), make([]byte, 12, 12), make([]byte, mtu))
  321. }
  322. // We already have a complete tunnel, there is nothing that can be done by processing further stage 1 packets
  323. return false
  324. }
  325. msg, eKey, dKey, err := ci.H.ReadMessage(nil, packet[header.Len:])
  326. if err != nil {
  327. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  328. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).WithField("header", h).
  329. Error("Failed to call noise.ReadMessage")
  330. // We don't want to tear down the connection on a bad ReadMessage because it could be an attacker trying
  331. // to DOS us. Every other error condition after should to allow a possible good handshake to complete in the
  332. // near future
  333. return false
  334. } else if dKey == nil || eKey == nil {
  335. f.l.WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  336. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  337. Error("Noise did not arrive at a key")
  338. // This should be impossible in IX but just in case, if we get here then there is no chance to recover
  339. // the handshake state machine. Tear it down
  340. return true
  341. }
  342. hs := &NebulaHandshake{}
  343. err = hs.Unmarshal(msg)
  344. if err != nil || hs.Details == nil {
  345. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  346. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).Error("Failed unmarshal handshake message")
  347. // The handshake state machine is complete, if things break now there is no chance to recover. Tear down and start again
  348. return true
  349. }
  350. remoteCert, err := RecombineCertAndValidate(ci.H, hs.Details.Cert, f.pki.GetCAPool())
  351. if err != nil {
  352. f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
  353. WithField("cert", remoteCert).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  354. Error("Invalid certificate from host")
  355. // The handshake state machine is complete, if things break now there is no chance to recover. Tear down and start again
  356. return true
  357. }
  358. vpnIp := iputil.Ip2VpnIp(remoteCert.Details.Ips[0].IP)
  359. certName := remoteCert.Details.Name
  360. fingerprint, _ := remoteCert.Sha256Sum()
  361. issuer := remoteCert.Details.Issuer
  362. // Ensure the right host responded
  363. if vpnIp != hostinfo.vpnIp {
  364. f.l.WithField("intendedVpnIp", hostinfo.vpnIp).WithField("haveVpnIp", vpnIp).
  365. WithField("udpAddr", addr).WithField("certName", certName).
  366. WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  367. Info("Incorrect host responded to handshake")
  368. // Release our old handshake from pending, it should not continue
  369. f.handshakeManager.DeleteHostInfo(hostinfo)
  370. // Create a new hostinfo/handshake for the intended vpn ip
  371. f.handshakeManager.StartHandshake(hostinfo.vpnIp, func(newHostInfo *HostInfo) {
  372. //TODO: this doesnt know if its being added or is being used for caching a packet
  373. // Block the current used address
  374. newHostInfo.remotes = hostinfo.remotes
  375. newHostInfo.remotes.BlockRemote(addr)
  376. // Get the correct remote list for the host we did handshake with
  377. hostinfo.remotes = f.lightHouse.QueryCache(vpnIp)
  378. f.l.WithField("blockedUdpAddrs", newHostInfo.remotes.CopyBlockedRemotes()).WithField("vpnIp", vpnIp).
  379. WithField("remotes", newHostInfo.remotes.CopyAddrs(f.hostMap.preferredRanges)).
  380. Info("Blocked addresses for handshakes")
  381. // Swap the packet store to benefit the original intended recipient
  382. newHostInfo.packetStore = hostinfo.packetStore
  383. hostinfo.packetStore = []*cachedPacket{}
  384. // Finally, put the correct vpn ip in the host info, tell them to close the tunnel, and return true to tear down
  385. hostinfo.vpnIp = vpnIp
  386. f.sendCloseTunnel(hostinfo)
  387. })
  388. return true
  389. }
  390. // Mark packet 2 as seen so it doesn't show up as missed
  391. ci.window.Update(f.l, 2)
  392. duration := time.Since(hostinfo.handshakeStart).Nanoseconds()
  393. f.l.WithField("vpnIp", vpnIp).WithField("udpAddr", addr).
  394. WithField("certName", certName).
  395. WithField("fingerprint", fingerprint).
  396. WithField("issuer", issuer).
  397. WithField("initiatorIndex", hs.Details.InitiatorIndex).WithField("responderIndex", hs.Details.ResponderIndex).
  398. WithField("remoteIndex", h.RemoteIndex).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
  399. WithField("durationNs", duration).
  400. WithField("sentCachedPackets", len(hostinfo.packetStore)).
  401. Info("Handshake message received")
  402. hostinfo.remoteIndexId = hs.Details.ResponderIndex
  403. hostinfo.lastHandshakeTime = hs.Details.Time
  404. // Store their cert and our symmetric keys
  405. ci.peerCert = remoteCert
  406. ci.dKey = NewNebulaCipherState(dKey)
  407. ci.eKey = NewNebulaCipherState(eKey)
  408. // Make sure the current udpAddr being used is set for responding
  409. if addr != nil {
  410. hostinfo.SetRemote(addr)
  411. } else {
  412. hostinfo.relayState.InsertRelayTo(via.relayHI.vpnIp)
  413. }
  414. // Build up the radix for the firewall if we have subnets in the cert
  415. hostinfo.CreateRemoteCIDR(remoteCert)
  416. // Complete our handshake and update metrics, this will replace any existing tunnels for this vpnIp
  417. f.handshakeManager.Complete(hostinfo, f)
  418. f.connectionManager.AddTrafficWatch(hostinfo.localIndexId)
  419. hostinfo.handshakeComplete(f.l, f.cachedPacketMetrics)
  420. f.metricHandshakes.Update(duration)
  421. return false
  422. }