Add WG_EXTENSION_HOOKS so internal behavior can be customized easier
This commit is contained in:
parent
23b4e819ad
commit
59650dcd55
2 changed files with 9 additions and 2 deletions
|
@ -354,7 +354,6 @@ void WireguardProcessor::HandleUdpPacket(Packet *packet, bool overload) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// On incoming packet to the tun interface.
|
// On incoming packet to the tun interface.
|
||||||
WireguardProcessor::PacketResult WireguardProcessor::HandleTunPacket2(Packet *packet) {
|
WireguardProcessor::PacketResult WireguardProcessor::HandleTunPacket2(Packet *packet) {
|
||||||
uint8 *data = packet->data;
|
uint8 *data = packet->data;
|
||||||
|
@ -369,7 +368,7 @@ WireguardProcessor::PacketResult WireguardProcessor::HandleTunPacket2(Packet *pa
|
||||||
|
|
||||||
ip_version = *data >> 4;
|
ip_version = *data >> 4;
|
||||||
if (ip_version == 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_);
|
WG_ACQUIRE_RWLOCK_SHARED(dev_.ip_to_peer_map_lock_);
|
||||||
peer = (WgPeer*)dev_.ip_to_peer_map().LookupV4(ip);
|
peer = (WgPeer*)dev_.ip_to_peer_map().LookupV4(ip);
|
||||||
WG_RELEASE_RWLOCK_SHARED(dev_.ip_to_peer_map_lock_);
|
WG_RELEASE_RWLOCK_SHARED(dev_.ip_to_peer_map_lock_);
|
||||||
|
|
|
@ -771,3 +771,11 @@ bool WgKeypairDecryptPayload(uint8 *dst, const size_t src_len,
|
||||||
const uint8 *ad, const size_t ad_len,
|
const uint8 *ad, const size_t ad_len,
|
||||||
const uint64 nonce, WgKeypair *keypair);
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue