2
0

handshake.go 915 B

12345678910111213141516171819202122232425262728293031
  1. package nebula
  2. const (
  3. handshakeIXPSK0 = 0
  4. handshakeXXPSK0 = 1
  5. )
  6. func HandleIncomingHandshake(f *Interface, addr *udpAddr, packet []byte, h *Header, hostinfo *HostInfo) {
  7. newHostinfo, _ := f.handshakeManager.QueryIndex(h.RemoteIndex)
  8. //TODO: For stage 1 we won't have hostinfo yet but stage 2 and above would require it, this check may be helpful in those cases
  9. //if err != nil {
  10. // l.WithError(err).WithField("udpAddr", addr).Error("Error while finding host info for handshake message")
  11. // return
  12. //}
  13. tearDown := false
  14. switch h.Subtype {
  15. case handshakeIXPSK0:
  16. switch h.MessageCounter {
  17. case 1:
  18. tearDown = ixHandshakeStage1(f, addr, newHostinfo, packet, h)
  19. case 2:
  20. tearDown = ixHandshakeStage2(f, addr, newHostinfo, packet, h)
  21. }
  22. }
  23. if tearDown && newHostinfo != nil {
  24. f.handshakeManager.DeleteIndex(newHostinfo.localIndexId)
  25. f.handshakeManager.DeleteVpnIP(newHostinfo.hostId)
  26. }
  27. }