(n *NebulaMeta, fromVpnAddrs []netip.Addr, addr netip.AddrPort, w EncWriter)
| 1056 | } |
| 1057 | |
| 1058 | func (lhh *LightHouseHandler) handleHostQuery(n *NebulaMeta, fromVpnAddrs []netip.Addr, addr netip.AddrPort, w EncWriter) { |
| 1059 | // Exit if we don't answer queries |
| 1060 | if !lhh.lh.amLighthouse { |
| 1061 | if lhh.l.Level >= logrus.DebugLevel { |
| 1062 | lhh.l.Debugln("I don't answer queries, but received from: ", addr) |
| 1063 | } |
| 1064 | return |
| 1065 | } |
| 1066 | |
| 1067 | queryVpnAddr, useVersion, err := n.Details.GetVpnAddrAndVersion() |
| 1068 | if err != nil { |
| 1069 | if lhh.l.Level >= logrus.DebugLevel { |
| 1070 | lhh.l.WithField("from", fromVpnAddrs).WithField("details", n.Details). |
| 1071 | Debugln("Dropping malformed HostQuery") |
| 1072 | } |
| 1073 | return |
| 1074 | } |
| 1075 | if useVersion == cert.Version1 && queryVpnAddr.Is6() { |
| 1076 | // this case really shouldn't be possible to represent, but reject it anyway. |
| 1077 | if lhh.l.Level >= logrus.DebugLevel { |
| 1078 | lhh.l.WithField("vpnAddrs", fromVpnAddrs).WithField("queryVpnAddr", queryVpnAddr). |
| 1079 | Debugln("invalid vpn addr for v1 handleHostQuery") |
| 1080 | } |
| 1081 | return |
| 1082 | } |
| 1083 | |
| 1084 | found, ln, err := lhh.lh.queryAndPrepMessage(queryVpnAddr, func(c *cache) (int, error) { |
| 1085 | n = lhh.resetMeta() |
| 1086 | n.Type = NebulaMeta_HostQueryReply |
| 1087 | if useVersion == cert.Version1 { |
| 1088 | b := queryVpnAddr.As4() |
| 1089 | n.Details.OldVpnAddr = binary.BigEndian.Uint32(b[:]) |
| 1090 | } else { |
| 1091 | n.Details.VpnAddr = netAddrToProtoAddr(queryVpnAddr) |
| 1092 | } |
| 1093 | |
| 1094 | lhh.coalesceAnswers(useVersion, c, n) |
| 1095 | |
| 1096 | return n.MarshalTo(lhh.pb) |
| 1097 | }) |
| 1098 | |
| 1099 | if !found { |
| 1100 | return |
| 1101 | } |
| 1102 | |
| 1103 | if err != nil { |
| 1104 | lhh.l.WithError(err).WithField("vpnAddrs", fromVpnAddrs).Error("Failed to marshal lighthouse host query reply") |
| 1105 | return |
| 1106 | } |
| 1107 | |
| 1108 | lhh.lh.metricTx(NebulaMeta_HostQueryReply, 1) |
| 1109 | w.SendMessageToVpnAddr(header.LightHouse, 0, fromVpnAddrs[0], lhh.pb[:ln], lhh.nb, lhh.out[:0]) |
| 1110 | |
| 1111 | lhh.sendHostPunchNotification(n, fromVpnAddrs, queryVpnAddr, w) |
| 1112 | } |
| 1113 | |
| 1114 | // sendHostPunchNotification signals the other side to punch some zero byte udp packets |
| 1115 | func (lhh *LightHouseHandler) sendHostPunchNotification(n *NebulaMeta, fromVpnAddrs []netip.Addr, punchNotifDest netip.Addr, w EncWriter) { |
no test coverage detected