diff --git a/wireguard.cpp b/wireguard.cpp index 8b087bb..f15de27 100644 --- a/wireguard.cpp +++ b/wireguard.cpp @@ -354,7 +354,6 @@ void WireguardProcessor::HandleUdpPacket(Packet *packet, bool overload) { } } - // On incoming packet to the tun interface. WireguardProcessor::PacketResult WireguardProcessor::HandleTunPacket2(Packet *packet) { uint8 *data = packet->data; @@ -369,7 +368,7 @@ WireguardProcessor::PacketResult WireguardProcessor::HandleTunPacket2(Packet *pa ip_version = *data >> 4; if (ip_version == 4) { - uint32 ip = ReadBE32(data + 16); + uint32 ip = WG_EXTENSION_HOOKS::GetIpv4Target(packet, data); WG_ACQUIRE_RWLOCK_SHARED(dev_.ip_to_peer_map_lock_); peer = (WgPeer*)dev_.ip_to_peer_map().LookupV4(ip); WG_RELEASE_RWLOCK_SHARED(dev_.ip_to_peer_map_lock_); diff --git a/wireguard_proto.h b/wireguard_proto.h index f447cde..5003d40 100644 --- a/wireguard_proto.h +++ b/wireguard_proto.h @@ -771,3 +771,11 @@ bool WgKeypairDecryptPayload(uint8 *dst, const size_t src_len, const uint8 *ad, const size_t ad_len, const uint64 nonce, WgKeypair *keypair); +struct WgExtensionHooksDefault { + static uint32 GetIpv4Target(Packet *packet, uint8 *data) { return ReadBE32(data + 16); } +}; + +#ifndef WG_EXTENSION_HOOKS +#define WG_EXTENSION_HOOKS WgExtensionHooksDefault +#endif // WG_EXTENSION_HOOKS +