Skip to content

Commit

Permalink
Refactor function and variable names for WireGuard
Browse files Browse the repository at this point in the history
Signed-off-by: Dongjun Na <kmu5544616@gmail.com>
  • Loading branch information
nadongjun committed Sep 21, 2024
1 parent be9d664 commit 6ef3cf5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Packet++/header/ProtocolType.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace pcpp
/*
* Wireguard protocol
*/
const ProtocolType WIREGUARD = 56;
const ProtocolType Wireguard = 56;

/**
* An enum representing OSI model layers
Expand Down
6 changes: 3 additions & 3 deletions Packet++/header/WireGuardLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace pcpp
* @param packet Pointer to the packet this layer belongs to
*/
WireGuardLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: Layer(data, dataLen, prevLayer, packet, WIREGUARD)
: Layer(data, dataLen, prevLayer, packet, Wireguard)
{}

/**
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace pcpp
* @param dataLen Length of the data
* @return True if the data starts with a valid WireGuard message type, false otherwise
*/
static inline bool isWireGuard(const uint8_t* data, size_t dataLen);
static inline bool isDataValid(const uint8_t* data, size_t dataLen);

/**
* No operation required for parsing the next layer since WireGuard does not have a next layer.
Expand Down Expand Up @@ -240,7 +240,7 @@ namespace pcpp
* @param dataLen Length of the data
* @return True if the data starts with a valid WireGuard message type, false otherwise
*/
bool WireGuardLayer::isWireGuard(const uint8_t* data, size_t dataLen)
bool WireGuardLayer::isDataValid(const uint8_t* data, size_t dataLen)
{
if (dataLen < sizeof(wg_common_header))
return false;
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/UdpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace pcpp
else if ((WakeOnLanLayer::isWakeOnLanPort(portDst) && WakeOnLanLayer::isDataValid(udpData, udpDataLen)))
m_NextLayer = new WakeOnLanLayer(udpData, udpDataLen, this, m_Packet);
else if ((WireGuardLayer::isWireguardPorts(portDst, portSrc) &&
WireGuardLayer::isWireGuard(udpData, udpDataLen)))
WireGuardLayer::isDataValid(udpData, udpDataLen)))
m_NextLayer = new WireGuardLayer(udpData, udpDataLen, this, m_Packet);
else
m_NextLayer = new PayloadLayer(udpData, udpDataLen, this, m_Packet);
Expand Down
6 changes: 3 additions & 3 deletions Tests/Packet++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ PTF_TEST_CASE(LdapParsingTest);
PTF_TEST_CASE(LdapCreationTest);

// Implemented in WireGuardTests.cpp
PTF_TEST_CASE(WGHandshakeInitParsingTest);
PTF_TEST_CASE(WGHandshakeRespParsingTest);
PTF_TEST_CASE(WGTransportDataParsingTest);
PTF_TEST_CASE(WireGuardHandshakeInitParsingTest);
PTF_TEST_CASE(WireGuardHandshakeRespParsingTest);
PTF_TEST_CASE(WireGuardTransportDataParsingTest);
12 changes: 6 additions & 6 deletions Tests/Packet++Test/Tests/WireGuardTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "SystemUtils.h"
#include <cstring>

PTF_TEST_CASE(WGHandshakeInitParsingTest)
PTF_TEST_CASE(WireGuardHandshakeInitParsingTest)
{
timeval time;
gettimeofday(&time, nullptr);

READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/WireGuardHandshakeInitiation.dat");

pcpp::Packet wgPacket(&rawPacket1);
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::WIREGUARD));
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::Wireguard));
pcpp::WireGuardLayer* wgLayer = wgPacket.getLayerOfType<pcpp::WireGuardLayer>();
PTF_ASSERT_NOT_NULL(wgLayer);
PTF_ASSERT_TRUE(wgLayer->getHeaderLen() == sizeof(pcpp::wg_handshake_initiation));
Expand Down Expand Up @@ -50,15 +50,15 @@ PTF_TEST_CASE(WGHandshakeInitParsingTest)
PTF_ASSERT_TRUE(std::memcmp(handshakeInit->mac2, expectedMac2, sizeof(expectedMac2)) == 0);
}

PTF_TEST_CASE(WGHandshakeRespParsingTest)
PTF_TEST_CASE(WireGuardHandshakeRespParsingTest)
{
timeval time;
gettimeofday(&time, nullptr);

READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/WireGuardHandshakeResponse.dat");

pcpp::Packet wgPacket(&rawPacket1);
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::WIREGUARD));
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::Wireguard));
pcpp::WireGuardLayer* wgLayer = wgPacket.getLayerOfType<pcpp::WireGuardLayer>();
PTF_ASSERT_NOT_NULL(wgLayer);

Expand Down Expand Up @@ -86,15 +86,15 @@ PTF_TEST_CASE(WGHandshakeRespParsingTest)
PTF_ASSERT_TRUE(std::memcmp(handshakeResponse->mac2, expectedMac2, sizeof(expectedMac2)) == 0);
}

PTF_TEST_CASE(WGTransportDataParsingTest)
PTF_TEST_CASE(WireGuardTransportDataParsingTest)
{
timeval time;
gettimeofday(&time, nullptr);

READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/WireGuardTransportData.dat");

pcpp::Packet wgPacket(&rawPacket1);
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::WIREGUARD));
PTF_ASSERT_TRUE(wgPacket.isPacketOfType(pcpp::Wireguard));
pcpp::WireGuardLayer* wgLayer = wgPacket.getLayerOfType<pcpp::WireGuardLayer>();
PTF_ASSERT_NOT_NULL(wgLayer);
PTF_ASSERT_TRUE(wgLayer->getHeaderLen() >= sizeof(pcpp::wg_transport_data));
Expand Down
6 changes: 3 additions & 3 deletions Tests/Packet++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ int main(int argc, char* argv[])
PTF_RUN_TEST(LdapParsingTest, "ldap");
PTF_RUN_TEST(LdapCreationTest, "ldap");

PTF_RUN_TEST(WGHandshakeInitParsingTest, "wg");
PTF_RUN_TEST(WGHandshakeRespParsingTest, "wg");
PTF_RUN_TEST(WGTransportDataParsingTest, "wg");
PTF_RUN_TEST(WireGuardHandshakeInitParsingTest, "wg");
PTF_RUN_TEST(WireGuardHandshakeRespParsingTest, "wg");
PTF_RUN_TEST(WireGuardTransportDataParsingTest, "wg");

PTF_END_RUNNING_TESTS;
}

0 comments on commit 6ef3cf5

Please sign in to comment.