3
0

outside.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. package nebula
  2. import (
  3. "encoding/binary"
  4. "errors"
  5. "fmt"
  6. "net/netip"
  7. "time"
  8. "github.com/google/gopacket/layers"
  9. "golang.org/x/net/ipv6"
  10. "github.com/sirupsen/logrus"
  11. "github.com/slackhq/nebula/firewall"
  12. "github.com/slackhq/nebula/header"
  13. "golang.org/x/net/ipv4"
  14. )
  15. const (
  16. minFwPacketLen = 4
  17. )
  18. func (f *Interface) readOutsidePackets(ip netip.AddrPort, via *ViaSender, out []byte, packet []byte, h *header.H, fwPacket *firewall.Packet, lhf *LightHouseHandler, nb []byte, q int, localCache firewall.ConntrackCache) {
  19. err := h.Parse(packet)
  20. if err != nil {
  21. // TODO: best if we return this and let caller log
  22. // TODO: Might be better to send the literal []byte("holepunch") packet and ignore that?
  23. // Hole punch packets are 0 or 1 byte big, so lets ignore printing those errors
  24. if len(packet) > 1 {
  25. f.l.WithField("packet", packet).Infof("Error while parsing inbound packet from %s: %s", ip, err)
  26. }
  27. return
  28. }
  29. //l.Error("in packet ", header, packet[HeaderLen:])
  30. if ip.IsValid() {
  31. _, found := f.myVpnNetworksTable.Lookup(ip.Addr())
  32. if found {
  33. if f.l.Level >= logrus.DebugLevel {
  34. f.l.WithField("udpAddr", ip).Debug("Refusing to process double encrypted packet")
  35. }
  36. return
  37. }
  38. }
  39. var hostinfo *HostInfo
  40. // verify if we've seen this index before, otherwise respond to the handshake initiation
  41. if h.Type == header.Message && h.Subtype == header.MessageRelay {
  42. hostinfo = f.hostMap.QueryRelayIndex(h.RemoteIndex)
  43. } else {
  44. hostinfo = f.hostMap.QueryIndex(h.RemoteIndex)
  45. }
  46. var ci *ConnectionState
  47. if hostinfo != nil {
  48. ci = hostinfo.ConnectionState
  49. }
  50. switch h.Type {
  51. case header.Message:
  52. // TODO handleEncrypted sends directly to addr on error. Handle this in the tunneling case.
  53. if !f.handleEncrypted(ci, ip, h) {
  54. return
  55. }
  56. switch h.Subtype {
  57. case header.MessageNone:
  58. if !f.decryptToTun(hostinfo, h.MessageCounter, out, packet, fwPacket, nb, q, localCache) {
  59. return
  60. }
  61. case header.MessageRelay:
  62. // The entire body is sent as AD, not encrypted.
  63. // The packet consists of a 16-byte parsed Nebula header, Associated Data-protected payload, and a trailing 16-byte AEAD signature value.
  64. // The packet is guaranteed to be at least 16 bytes at this point, b/c it got past the h.Parse() call above. If it's
  65. // otherwise malformed (meaning, there is no trailing 16 byte AEAD value), then this will result in at worst a 0-length slice
  66. // which will gracefully fail in the DecryptDanger call.
  67. signedPayload := packet[:len(packet)-hostinfo.ConnectionState.dKey.Overhead()]
  68. signatureValue := packet[len(packet)-hostinfo.ConnectionState.dKey.Overhead():]
  69. out, err = hostinfo.ConnectionState.dKey.DecryptDanger(out, signedPayload, signatureValue, h.MessageCounter, nb)
  70. if err != nil {
  71. return
  72. }
  73. // Successfully validated the thing. Get rid of the Relay header.
  74. signedPayload = signedPayload[header.Len:]
  75. // Pull the Roaming parts up here, and return in all call paths.
  76. f.handleHostRoaming(hostinfo, ip)
  77. // Track usage of both the HostInfo and the Relay for the received & authenticated packet
  78. f.connectionManager.In(hostinfo.localIndexId)
  79. f.connectionManager.RelayUsed(h.RemoteIndex)
  80. relay, ok := hostinfo.relayState.QueryRelayForByIdx(h.RemoteIndex)
  81. if !ok {
  82. // The only way this happens is if hostmap has an index to the correct HostInfo, but the HostInfo is missing
  83. // its internal mapping. This should never happen.
  84. hostinfo.logger(f.l).WithFields(logrus.Fields{"vpnAddrs": hostinfo.vpnAddrs, "remoteIndex": h.RemoteIndex}).Error("HostInfo missing remote relay index")
  85. return
  86. }
  87. switch relay.Type {
  88. case TerminalType:
  89. // If I am the target of this relay, process the unwrapped packet
  90. // From this recursive point, all these variables are 'burned'. We shouldn't rely on them again.
  91. f.readOutsidePackets(netip.AddrPort{}, &ViaSender{relayHI: hostinfo, remoteIdx: relay.RemoteIndex, relay: relay}, out[:0], signedPayload, h, fwPacket, lhf, nb, q, localCache)
  92. return
  93. case ForwardingType:
  94. // Find the target HostInfo relay object
  95. targetHI, targetRelay, err := f.hostMap.QueryVpnAddrsRelayFor(hostinfo.vpnAddrs, relay.PeerAddr)
  96. if err != nil {
  97. hostinfo.logger(f.l).WithField("relayTo", relay.PeerAddr).WithError(err).WithField("hostinfo.vpnAddrs", hostinfo.vpnAddrs).Info("Failed to find target host info by ip")
  98. return
  99. }
  100. // If that relay is Established, forward the payload through it
  101. if targetRelay.State == Established {
  102. switch targetRelay.Type {
  103. case ForwardingType:
  104. // Forward this packet through the relay tunnel
  105. // Find the target HostInfo
  106. f.SendVia(targetHI, targetRelay, signedPayload, nb, out, false)
  107. return
  108. case TerminalType:
  109. hostinfo.logger(f.l).Error("Unexpected Relay Type of Terminal")
  110. }
  111. } else {
  112. hostinfo.logger(f.l).WithFields(logrus.Fields{"relayTo": relay.PeerAddr, "relayFrom": hostinfo.vpnAddrs[0], "targetRelayState": targetRelay.State}).Info("Unexpected target relay state")
  113. return
  114. }
  115. }
  116. }
  117. case header.LightHouse:
  118. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  119. if !f.handleEncrypted(ci, ip, h) {
  120. return
  121. }
  122. d, err := f.decrypt(hostinfo, h.MessageCounter, out, packet, h, nb)
  123. if err != nil {
  124. hostinfo.logger(f.l).WithError(err).WithField("udpAddr", ip).
  125. WithField("packet", packet).
  126. Error("Failed to decrypt lighthouse packet")
  127. //TODO: maybe after build 64 is out? 06/14/2018 - NB
  128. //f.sendRecvError(net.Addr(addr), header.RemoteIndex)
  129. return
  130. }
  131. lhf.HandleRequest(ip, hostinfo.vpnAddrs, d, f)
  132. // Fallthrough to the bottom to record incoming traffic
  133. case header.Test:
  134. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  135. if !f.handleEncrypted(ci, ip, h) {
  136. return
  137. }
  138. d, err := f.decrypt(hostinfo, h.MessageCounter, out, packet, h, nb)
  139. if err != nil {
  140. hostinfo.logger(f.l).WithError(err).WithField("udpAddr", ip).
  141. WithField("packet", packet).
  142. Error("Failed to decrypt test packet")
  143. //TODO: maybe after build 64 is out? 06/14/2018 - NB
  144. //f.sendRecvError(net.Addr(addr), header.RemoteIndex)
  145. return
  146. }
  147. if h.Subtype == header.TestRequest {
  148. // This testRequest might be from TryPromoteBest, so we should roam
  149. // to the new IP address before responding
  150. f.handleHostRoaming(hostinfo, ip)
  151. f.send(header.Test, header.TestReply, ci, hostinfo, d, nb, out)
  152. }
  153. // Fallthrough to the bottom to record incoming traffic
  154. // Non encrypted messages below here, they should not fall through to avoid tracking incoming traffic since they
  155. // are unauthenticated
  156. case header.Handshake:
  157. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  158. f.handshakeManager.HandleIncoming(ip, via, packet, h)
  159. return
  160. case header.RecvError:
  161. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  162. f.handleRecvError(ip, h)
  163. return
  164. case header.CloseTunnel:
  165. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  166. if !f.handleEncrypted(ci, ip, h) {
  167. return
  168. }
  169. hostinfo.logger(f.l).WithField("udpAddr", ip).
  170. Info("Close tunnel received, tearing down.")
  171. f.closeTunnel(hostinfo)
  172. return
  173. case header.Control:
  174. if !f.handleEncrypted(ci, ip, h) {
  175. return
  176. }
  177. d, err := f.decrypt(hostinfo, h.MessageCounter, out, packet, h, nb)
  178. if err != nil {
  179. hostinfo.logger(f.l).WithError(err).WithField("udpAddr", ip).
  180. WithField("packet", packet).
  181. Error("Failed to decrypt Control packet")
  182. return
  183. }
  184. f.relayManager.HandleControlMsg(hostinfo, d, f)
  185. default:
  186. f.messageMetrics.Rx(h.Type, h.Subtype, 1)
  187. hostinfo.logger(f.l).Debugf("Unexpected packet received from %s", ip)
  188. return
  189. }
  190. f.handleHostRoaming(hostinfo, ip)
  191. f.connectionManager.In(hostinfo.localIndexId)
  192. }
  193. // closeTunnel closes a tunnel locally, it does not send a closeTunnel packet to the remote
  194. func (f *Interface) closeTunnel(hostInfo *HostInfo) {
  195. final := f.hostMap.DeleteHostInfo(hostInfo)
  196. if final {
  197. // We no longer have any tunnels with this vpn addr, clear learned lighthouse state to lower memory usage
  198. f.lightHouse.DeleteVpnAddrs(hostInfo.vpnAddrs)
  199. }
  200. }
  201. // sendCloseTunnel is a helper function to send a proper close tunnel packet to a remote
  202. func (f *Interface) sendCloseTunnel(h *HostInfo) {
  203. f.send(header.CloseTunnel, 0, h.ConnectionState, h, []byte{}, make([]byte, 12, 12), make([]byte, mtu))
  204. }
  205. func (f *Interface) handleHostRoaming(hostinfo *HostInfo, vpnAddr netip.AddrPort) {
  206. if vpnAddr.IsValid() && hostinfo.remote != vpnAddr {
  207. //TODO: this is weird now that we can have multiple vpn addrs
  208. if !f.lightHouse.GetRemoteAllowList().Allow(hostinfo.vpnAddrs[0], vpnAddr.Addr()) {
  209. hostinfo.logger(f.l).WithField("newAddr", vpnAddr).Debug("lighthouse.remote_allow_list denied roaming")
  210. return
  211. }
  212. if !hostinfo.lastRoam.IsZero() && vpnAddr == hostinfo.lastRoamRemote && time.Since(hostinfo.lastRoam) < RoamingSuppressSeconds*time.Second {
  213. if f.l.Level >= logrus.DebugLevel {
  214. hostinfo.logger(f.l).WithField("udpAddr", hostinfo.remote).WithField("newAddr", vpnAddr).
  215. Debugf("Suppressing roam back to previous remote for %d seconds", RoamingSuppressSeconds)
  216. }
  217. return
  218. }
  219. hostinfo.logger(f.l).WithField("udpAddr", hostinfo.remote).WithField("newAddr", vpnAddr).
  220. Info("Host roamed to new udp ip/port.")
  221. hostinfo.lastRoam = time.Now()
  222. hostinfo.lastRoamRemote = hostinfo.remote
  223. hostinfo.SetRemote(vpnAddr)
  224. }
  225. }
  226. func (f *Interface) handleEncrypted(ci *ConnectionState, addr netip.AddrPort, h *header.H) bool {
  227. // If connectionstate exists and the replay protector allows, process packet
  228. // Else, send recv errors for 300 seconds after a restart to allow fast reconnection.
  229. if ci == nil || !ci.window.Check(f.l, h.MessageCounter) {
  230. if addr.IsValid() {
  231. f.maybeSendRecvError(addr, h.RemoteIndex)
  232. return false
  233. } else {
  234. return false
  235. }
  236. }
  237. return true
  238. }
  239. // newPacket validates and parses the interesting bits for the firewall out of the ip and sub protocol headers
  240. func newPacket(data []byte, incoming bool, fp *firewall.Packet) error {
  241. if len(data) < 1 {
  242. return errors.New("packet too short")
  243. }
  244. version := int((data[0] >> 4) & 0x0f)
  245. switch version {
  246. case ipv4.Version:
  247. return parseV4(data, incoming, fp)
  248. case ipv6.Version:
  249. return parseV6(data, incoming, fp)
  250. }
  251. return fmt.Errorf("packet is an unknown ip version: %v", version)
  252. }
  253. func parseV6(data []byte, incoming bool, fp *firewall.Packet) error {
  254. dataLen := len(data)
  255. if dataLen < ipv6.HeaderLen {
  256. return fmt.Errorf("ipv6 packet is less than %v bytes", ipv4.HeaderLen)
  257. }
  258. if incoming {
  259. fp.RemoteAddr, _ = netip.AddrFromSlice(data[8:24])
  260. fp.LocalAddr, _ = netip.AddrFromSlice(data[24:40])
  261. } else {
  262. fp.LocalAddr, _ = netip.AddrFromSlice(data[8:24])
  263. fp.RemoteAddr, _ = netip.AddrFromSlice(data[24:40])
  264. }
  265. //TODO: whats a reasonable number of extension headers to attempt to parse?
  266. //https://www.ietf.org/archive/id/draft-ietf-6man-eh-limits-00.html
  267. protoAt := 6
  268. offset := 40
  269. for i := 0; i < 24; i++ {
  270. if dataLen < offset {
  271. break
  272. }
  273. proto := layers.IPProtocol(data[protoAt])
  274. //fmt.Println(proto, protoAt)
  275. switch proto {
  276. case layers.IPProtocolICMPv6:
  277. //TODO: we need a new protocol in config language "icmpv6"
  278. fp.Protocol = uint8(proto)
  279. fp.RemotePort = 0
  280. fp.LocalPort = 0
  281. fp.Fragment = false
  282. return nil
  283. case layers.IPProtocolTCP:
  284. if dataLen < offset+4 {
  285. return fmt.Errorf("ipv6 packet was too small")
  286. }
  287. fp.Protocol = uint8(proto)
  288. if incoming {
  289. fp.RemotePort = binary.BigEndian.Uint16(data[offset : offset+2])
  290. fp.LocalPort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
  291. } else {
  292. fp.LocalPort = binary.BigEndian.Uint16(data[offset : offset+2])
  293. fp.RemotePort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
  294. }
  295. fp.Fragment = false
  296. return nil
  297. case layers.IPProtocolUDP:
  298. if dataLen < offset+4 {
  299. return fmt.Errorf("ipv6 packet was too small")
  300. }
  301. fp.Protocol = uint8(proto)
  302. if incoming {
  303. fp.RemotePort = binary.BigEndian.Uint16(data[offset : offset+2])
  304. fp.LocalPort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
  305. } else {
  306. fp.LocalPort = binary.BigEndian.Uint16(data[offset : offset+2])
  307. fp.RemotePort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
  308. }
  309. fp.Fragment = false
  310. return nil
  311. case layers.IPProtocolIPv6Fragment:
  312. //TODO: can we determine the protocol?
  313. fp.RemotePort = 0
  314. fp.LocalPort = 0
  315. fp.Fragment = true
  316. return nil
  317. default:
  318. if dataLen < offset+1 {
  319. break
  320. }
  321. next := int(data[offset+1]) * 8
  322. if next == 0 {
  323. // each extension is at least 8 bytes
  324. next = 8
  325. }
  326. protoAt = offset
  327. offset = offset + next
  328. }
  329. }
  330. return fmt.Errorf("could not find payload in ipv6 packet")
  331. }
  332. func parseV4(data []byte, incoming bool, fp *firewall.Packet) error {
  333. // Do we at least have an ipv4 header worth of data?
  334. if len(data) < ipv4.HeaderLen {
  335. return fmt.Errorf("ipv4 packet is less than %v bytes", ipv4.HeaderLen)
  336. }
  337. // Adjust our start position based on the advertised ip header length
  338. ihl := int(data[0]&0x0f) << 2
  339. // Well formed ip header length?
  340. if ihl < ipv4.HeaderLen {
  341. return fmt.Errorf("ipv4 packet had an invalid header length: %v", ihl)
  342. }
  343. // Check if this is the second or further fragment of a fragmented packet.
  344. flagsfrags := binary.BigEndian.Uint16(data[6:8])
  345. fp.Fragment = (flagsfrags & 0x1FFF) != 0
  346. // Firewall handles protocol checks
  347. fp.Protocol = data[9]
  348. // Accounting for a variable header length, do we have enough data for our src/dst tuples?
  349. minLen := ihl
  350. if !fp.Fragment && fp.Protocol != firewall.ProtoICMP {
  351. minLen += minFwPacketLen
  352. }
  353. if len(data) < minLen {
  354. return fmt.Errorf("ipv4 packet is less than %v bytes, ip header len: %v", minLen, ihl)
  355. }
  356. // Firewall packets are locally oriented
  357. if incoming {
  358. fp.RemoteAddr, _ = netip.AddrFromSlice(data[12:16])
  359. fp.LocalAddr, _ = netip.AddrFromSlice(data[16:20])
  360. if fp.Fragment || fp.Protocol == firewall.ProtoICMP {
  361. fp.RemotePort = 0
  362. fp.LocalPort = 0
  363. } else {
  364. fp.RemotePort = binary.BigEndian.Uint16(data[ihl : ihl+2])
  365. fp.LocalPort = binary.BigEndian.Uint16(data[ihl+2 : ihl+4])
  366. }
  367. } else {
  368. fp.LocalAddr, _ = netip.AddrFromSlice(data[12:16])
  369. fp.RemoteAddr, _ = netip.AddrFromSlice(data[16:20])
  370. if fp.Fragment || fp.Protocol == firewall.ProtoICMP {
  371. fp.RemotePort = 0
  372. fp.LocalPort = 0
  373. } else {
  374. fp.LocalPort = binary.BigEndian.Uint16(data[ihl : ihl+2])
  375. fp.RemotePort = binary.BigEndian.Uint16(data[ihl+2 : ihl+4])
  376. }
  377. }
  378. return nil
  379. }
  380. func (f *Interface) decrypt(hostinfo *HostInfo, mc uint64, out []byte, packet []byte, h *header.H, nb []byte) ([]byte, error) {
  381. var err error
  382. out, err = hostinfo.ConnectionState.dKey.DecryptDanger(out, packet[:header.Len], packet[header.Len:], mc, nb)
  383. if err != nil {
  384. return nil, err
  385. }
  386. if !hostinfo.ConnectionState.window.Update(f.l, mc) {
  387. hostinfo.logger(f.l).WithField("header", h).
  388. Debugln("dropping out of window packet")
  389. return nil, errors.New("out of window packet")
  390. }
  391. return out, nil
  392. }
  393. func (f *Interface) decryptToTun(hostinfo *HostInfo, messageCounter uint64, out []byte, packet []byte, fwPacket *firewall.Packet, nb []byte, q int, localCache firewall.ConntrackCache) bool {
  394. var err error
  395. out, err = hostinfo.ConnectionState.dKey.DecryptDanger(out, packet[:header.Len], packet[header.Len:], messageCounter, nb)
  396. if err != nil {
  397. hostinfo.logger(f.l).WithError(err).Error("Failed to decrypt packet")
  398. //TODO: maybe after build 64 is out? 06/14/2018 - NB
  399. //f.sendRecvError(hostinfo.remote, header.RemoteIndex)
  400. return false
  401. }
  402. err = newPacket(out, true, fwPacket)
  403. if err != nil {
  404. hostinfo.logger(f.l).WithError(err).WithField("packet", out).
  405. Warnf("Error while validating inbound packet")
  406. return false
  407. }
  408. if !hostinfo.ConnectionState.window.Update(f.l, messageCounter) {
  409. hostinfo.logger(f.l).WithField("fwPacket", fwPacket).
  410. Debugln("dropping out of window packet")
  411. return false
  412. }
  413. dropReason := f.firewall.Drop(*fwPacket, true, hostinfo, f.pki.GetCAPool(), localCache)
  414. if dropReason != nil {
  415. // NOTE: We give `packet` as the `out` here since we already decrypted from it and we don't need it anymore
  416. // This gives us a buffer to build the reject packet in
  417. f.rejectOutside(out, hostinfo.ConnectionState, hostinfo, nb, packet, q)
  418. if f.l.Level >= logrus.DebugLevel {
  419. hostinfo.logger(f.l).WithField("fwPacket", fwPacket).
  420. WithField("reason", dropReason).
  421. Debugln("dropping inbound packet")
  422. }
  423. return false
  424. }
  425. f.connectionManager.In(hostinfo.localIndexId)
  426. _, err = f.readers[q].Write(out)
  427. if err != nil {
  428. f.l.WithError(err).Error("Failed to write to tun")
  429. }
  430. return true
  431. }
  432. func (f *Interface) maybeSendRecvError(endpoint netip.AddrPort, index uint32) {
  433. if f.sendRecvErrorConfig.ShouldSendRecvError(endpoint) {
  434. f.sendRecvError(endpoint, index)
  435. }
  436. }
  437. func (f *Interface) sendRecvError(endpoint netip.AddrPort, index uint32) {
  438. f.messageMetrics.Tx(header.RecvError, 0, 1)
  439. //TODO: this should be a signed message so we can trust that we should drop the index
  440. b := header.Encode(make([]byte, header.Len), header.Version, header.RecvError, 0, index, 0)
  441. f.outside.WriteTo(b, endpoint)
  442. if f.l.Level >= logrus.DebugLevel {
  443. f.l.WithField("index", index).
  444. WithField("udpAddr", endpoint).
  445. Debug("Recv error sent")
  446. }
  447. }
  448. func (f *Interface) handleRecvError(addr netip.AddrPort, h *header.H) {
  449. if f.l.Level >= logrus.DebugLevel {
  450. f.l.WithField("index", h.RemoteIndex).
  451. WithField("udpAddr", addr).
  452. Debug("Recv error received")
  453. }
  454. hostinfo := f.hostMap.QueryReverseIndex(h.RemoteIndex)
  455. if hostinfo == nil {
  456. f.l.WithField("remoteIndex", h.RemoteIndex).Debugln("Did not find remote index in main hostmap")
  457. return
  458. }
  459. if !hostinfo.RecvErrorExceeded() {
  460. return
  461. }
  462. if hostinfo.remote.IsValid() && hostinfo.remote != addr {
  463. f.l.Infoln("Someone spoofing recv_errors? ", addr, hostinfo.remote)
  464. return
  465. }
  466. f.closeTunnel(hostinfo)
  467. // We also delete it from pending hostmap to allow for fast reconnect.
  468. f.handshakeManager.DeleteHostInfo(hostinfo)
  469. }
  470. /*
  471. func (f *Interface) sendMeta(ci *ConnectionState, endpoint *net.UDPAddr, meta *NebulaMeta) {
  472. if ci.eKey != nil {
  473. //TODO: log error?
  474. return
  475. }
  476. msg, err := proto.Marshal(meta)
  477. if err != nil {
  478. l.Debugln("failed to encode header")
  479. }
  480. c := ci.messageCounter
  481. b := HeaderEncode(nil, Version, uint8(metadata), 0, hostinfo.remoteIndexId, c)
  482. ci.messageCounter++
  483. msg := ci.eKey.EncryptDanger(b, nil, msg, c)
  484. //msg := ci.eKey.EncryptDanger(b, nil, []byte(fmt.Sprintf("%d", counter)), c)
  485. f.outside.WriteTo(msg, endpoint)
  486. }
  487. */