handshake.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. if !f.lightHouse.remoteAllowList.Allow(udp2ipInt(addr)) {
  14. l.WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
  15. return
  16. }
  17. tearDown := false
  18. switch h.Subtype {
  19. case handshakeIXPSK0:
  20. switch h.MessageCounter {
  21. case 1:
  22. tearDown = ixHandshakeStage1(f, addr, newHostinfo, packet, h)
  23. case 2:
  24. tearDown = ixHandshakeStage2(f, addr, newHostinfo, packet, h)
  25. }
  26. }
  27. if tearDown && newHostinfo != nil {
  28. f.handshakeManager.DeleteIndex(newHostinfo.localIndexId)
  29. f.handshakeManager.DeleteVpnIP(newHostinfo.hostId)
  30. }
  31. }