handshake.go 871 B

12345678910111213141516171819202122232425262728293031
  1. package nebula
  2. import (
  3. "github.com/slackhq/nebula/header"
  4. "github.com/slackhq/nebula/udp"
  5. )
  6. func HandleIncomingHandshake(f *Interface, addr *udp.Addr, via interface{}, packet []byte, h *header.H, hostinfo *HostInfo) {
  7. // First remote allow list check before we know the vpnIp
  8. if addr != nil {
  9. if !f.lightHouse.GetRemoteAllowList().AllowUnknownVpnIp(addr.IP) {
  10. f.l.WithField("udpAddr", addr).Debug("lighthouse.remote_allow_list denied incoming handshake")
  11. return
  12. }
  13. }
  14. switch h.Subtype {
  15. case header.HandshakeIXPSK0:
  16. switch h.MessageCounter {
  17. case 1:
  18. ixHandshakeStage1(f, addr, via, packet, h)
  19. case 2:
  20. newHostinfo, _ := f.handshakeManager.QueryIndex(h.RemoteIndex)
  21. tearDown := ixHandshakeStage2(f, addr, via, newHostinfo, packet, h)
  22. if tearDown && newHostinfo != nil {
  23. f.handshakeManager.DeleteHostInfo(newHostinfo)
  24. }
  25. }
  26. }
  27. }