Commit 97ba667a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3546] Renamed MAC_SOURCE_* consts to HWADDR_SOURCE_*

parent 2bc92b76
......@@ -125,11 +125,11 @@ Pkt::setHWAddrMember(const uint8_t htype, const uint8_t,
HWAddrPtr
Pkt::getMAC(uint32_t hw_addr_src) {
HWAddrPtr mac;
if (hw_addr_src & MAC_SOURCE_RAW) {
if (hw_addr_src & HWADDR_SOURCE_RAW) {
mac = getRemoteHWAddr();
if (mac) {
return (mac);
} else if (hw_addr_src == MAC_SOURCE_RAW) {
} else if (hw_addr_src == HWADDR_SOURCE_RAW) {
// If we're interested only in RAW sockets as source of that info,
// there's no point in trying other options.
return (HWAddrPtr());
......
......@@ -39,9 +39,10 @@ namespace dhcp {
class Pkt {
public:
/// @defgroup mac_sources Specifies where a given MAC address was obtained.
/// @defgroup hw_sources Specifies where a given MAC/hardware address was
/// obtained.
///
/// @brief The list covers all possible MAC sources.
/// @brief The list covers all possible MAC/hw address sources.
///
/// @note The uncommented ones are currently supported. When you implement
/// a new method, please uncomment appropriate line here.
......@@ -49,38 +50,38 @@ public:
/// @{
/// Not really a type, only used in getMAC() calls.
static const uint32_t MAC_SOURCE_ANY = 0xffff;
static const uint32_t HWADDR_SOURCE_ANY = 0xffff;
/// Obtained first hand from raw socket (100% reliable).
static const uint32_t MAC_SOURCE_RAW = 0x0001;
static const uint32_t HWADDR_SOURCE_RAW = 0x0001;
/// Extracted from DUID-LL or DUID-LLT (not 100% reliable as the client
/// can send fake DUID).
//static const uint32_t MAC_SOURCE_DUID = 0x0002;
//static const uint32_t HWADDR_SOURCE_DUID = 0x0002;
/// Extracted from IPv6 link-local address. Not 100% reliable, as the
/// client can use different IID other than EUI-64, e.g. Windows supports
/// RFC4941 and uses random values instead of EUI-64.
//static const uint32_t MAC_SOURCE_IPV6_LINK_LOCAL = 0x0004;
//static const uint32_t HWADDR_SOURCE_IPV6_LINK_LOCAL = 0x0004;
/// Get it from RFC6939 option. (A relay agent can insert client link layer
/// address option). Note that a skilled attacker can fake that by sending
/// his request relayed, so the legitimate relay will think it's a second
/// relay.
//static const uint32_t MAC_SOURCE_CLIENT_ADDR_RELAY_OPTION = 0x0008;
//static const uint32_t HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION = 0x0008;
/// A relay can insert remote-id. In some deployments it contains a MAC
/// address (RFC4649).
//static const uint32_t MAC_SOURCE_REMOTE_ID = 0x0010;
//static const uint32_t HWADDR_SOURCE_REMOTE_ID = 0x0010;
/// A relay can insert a subscriber-id option. In some deployments it
/// contains a MAC address (RFC4580).
//static const uint32_t MAC_SOURCE_SUBSCRIBER_ID = 0x0020;
//static const uint32_t HWADDR_SOURCE_SUBSCRIBER_ID = 0x0020;
/// A CMTS (acting as DHCP relay agent) that supports DOCSIS standard
/// can insert DOCSIS options that contain client's MAC address.
/// Client in this context would be a cable modem.
//static const uint32_t MAC_SOURCE_DOCSIS_OPTIONS = 0x0040;
//static const uint32_t HWADDR_SOURCE_DOCSIS_OPTIONS = 0x0040;
/// @}
......@@ -469,7 +470,7 @@ public:
/// to keep the name of getMAC().
///
/// hw_addr_src takes a combination of bit values specified in
/// MAC_SOURCE_* constants.
/// HWADDR_SOURCE_* constants.
///
/// @param hw_addr_src a bitmask that specifies hardware address source
HWAddrPtr getMAC(uint32_t hw_addr_src);
......
......@@ -874,8 +874,8 @@ TEST_F(Pkt6Test, getMAC) {
Pkt6 pkt(DHCPV6_ADVERTISE, 1234);
// DHCPv6 packet by default doens't have MAC address specified.
EXPECT_FALSE(pkt.getMAC(Pkt::MAC_SOURCE_ANY));
EXPECT_FALSE(pkt.getMAC(Pkt::MAC_SOURCE_RAW));
EXPECT_FALSE(pkt.getMAC(Pkt::HWADDR_SOURCE_ANY));
EXPECT_FALSE(pkt.getMAC(Pkt::HWADDR_SOURCE_RAW));
// Let's invent a MAC
const uint8_t hw[] = { 2, 4, 6, 8, 10, 12 }; // MAC
......@@ -886,12 +886,12 @@ TEST_F(Pkt6Test, getMAC) {
pkt.setRemoteHWAddr(dummy_hwaddr);
// Now we should be able to get something
ASSERT_TRUE(pkt.getMAC(Pkt::MAC_SOURCE_ANY));
ASSERT_TRUE(pkt.getMAC(Pkt::MAC_SOURCE_RAW));
ASSERT_TRUE(pkt.getMAC(Pkt::HWADDR_SOURCE_ANY));
ASSERT_TRUE(pkt.getMAC(Pkt::HWADDR_SOURCE_RAW));
// Check that the returned MAC is indeed the expected one
ASSERT_TRUE(*dummy_hwaddr == *pkt.getMAC(Pkt::MAC_SOURCE_ANY));
ASSERT_TRUE(*dummy_hwaddr == *pkt.getMAC(Pkt::MAC_SOURCE_RAW));
ASSERT_TRUE(*dummy_hwaddr == *pkt.getMAC(Pkt::HWADDR_SOURCE_ANY));
ASSERT_TRUE(*dummy_hwaddr == *pkt.getMAC(Pkt::HWADDR_SOURCE_RAW));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment