handler.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package nebula
  2. func (f *Interface) handleMessagePacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  3. if !f.handleEncrypted(ci, addr, header) {
  4. return
  5. }
  6. f.decryptToTun(hostInfo, header.MessageCounter, out, packet, fwPacket, nb)
  7. f.handleHostRoaming(hostInfo, addr)
  8. f.connectionManager.In(hostInfo.hostId)
  9. }
  10. func (f *Interface) handleLighthousePacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  11. f.messageMetrics.Rx(header.Type, header.Subtype, 1)
  12. if !f.handleEncrypted(ci, addr, header) {
  13. return
  14. }
  15. d, err := f.decrypt(hostInfo, header.MessageCounter, out, packet, header, nb)
  16. if err != nil {
  17. hostInfo.logger().WithError(err).WithField("udpAddr", addr).
  18. WithField("packet", packet).
  19. Error("Failed to decrypt lighthouse packet")
  20. //TODO: maybe after build 64 is out? 06/14/2018 - NB
  21. //f.sendRecvError(net.Addr(addr), header.RemoteIndex)
  22. return
  23. }
  24. f.lightHouse.HandleRequest(addr, hostInfo.hostId, d, hostInfo.GetCert(), f)
  25. f.handleHostRoaming(hostInfo, addr)
  26. f.connectionManager.In(hostInfo.hostId)
  27. }
  28. func (f *Interface) handleTestPacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  29. f.messageMetrics.Rx(header.Type, header.Subtype, 1)
  30. if !f.handleEncrypted(ci, addr, header) {
  31. return
  32. }
  33. d, err := f.decrypt(hostInfo, header.MessageCounter, out, packet, header, nb)
  34. if err != nil {
  35. hostInfo.logger().WithError(err).WithField("udpAddr", addr).
  36. WithField("packet", packet).
  37. Error("Failed to decrypt test packet")
  38. //TODO: maybe after build 64 is out? 06/14/2018 - NB
  39. //f.sendRecvError(net.Addr(addr), header.RemoteIndex)
  40. return
  41. }
  42. if header.Subtype == testRequest {
  43. // This testRequest might be from TryPromoteBest, so we should roam
  44. // to the new IP address before responding
  45. f.handleHostRoaming(hostInfo, addr)
  46. f.send(test, testReply, ci, hostInfo, hostInfo.remote, d, nb, out)
  47. }
  48. f.handleHostRoaming(hostInfo, addr)
  49. f.connectionManager.In(hostInfo.hostId)
  50. }
  51. func (f *Interface) handleHandshakePacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  52. f.messageMetrics.Rx(header.Type, header.Subtype, 1)
  53. HandleIncomingHandshake(f, addr, packet, header, hostInfo)
  54. }
  55. func (f *Interface) handleRecvErrorPacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  56. f.messageMetrics.Rx(header.Type, header.Subtype, 1)
  57. // TODO: Remove this with recv_error deprecation
  58. f.handleRecvError(addr, header)
  59. }
  60. func (f *Interface) handleCloseTunnelPacket(hostInfo *HostInfo, ci *ConnectionState, addr *udpAddr, header *Header, out []byte, packet []byte, fwPacket *FirewallPacket, nb []byte) {
  61. f.messageMetrics.Rx(header.Type, header.Subtype, 1)
  62. if !f.handleEncrypted(ci, addr, header) {
  63. return
  64. }
  65. hostInfo.logger().WithField("udpAddr", addr).
  66. Info("Close tunnel received, tearing down.")
  67. f.closeTunnel(hostInfo)
  68. }