]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3546] hw_type in HWAddr class is now 16 bits long.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 2 Oct 2014 13:49:16 +0000 (15:49 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 2 Oct 2014 13:49:16 +0000 (15:49 +0200)
src/lib/dhcp/hwaddr.cc
src/lib/dhcp/hwaddr.h
src/lib/dhcp/tests/hwaddr_unittest.cc

index 5f130804b5339baf0784a6d29f883fc298165c9b..82bfd1d3f29f8c4978a5651505505d1ecc6fa33c 100644 (file)
@@ -31,14 +31,14 @@ HWAddr::HWAddr()
     :htype_(HTYPE_ETHER) {
 }
 
-HWAddr::HWAddr(const uint8_t* hwaddr, size_t len, uint8_t htype)
+HWAddr::HWAddr(const uint8_t* hwaddr, size_t len, uint16_t htype)
     :hwaddr_(hwaddr, hwaddr + len), htype_(htype) {
     if (len > MAX_HWADDR_LEN) {
         isc_throw(InvalidParameter, "hwaddr length exceeds MAX_HWADDR_LEN");
     }
 }
 
-HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype)
+HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint16_t htype)
     :hwaddr_(hwaddr), htype_(htype) {
     if (hwaddr.size() > MAX_HWADDR_LEN) {
         isc_throw(InvalidParameter,
@@ -49,7 +49,7 @@ HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype)
 std::string HWAddr::toText(bool include_htype) const {
     std::stringstream tmp;
     if (include_htype) {
-        tmp << "hwtype=" << static_cast<int>(htype_) << " ";
+        tmp << "hwtype=" << static_cast<unsigned int>(htype_) << " ";
     }
     tmp << std::hex;
     bool delim = false;
@@ -65,7 +65,7 @@ std::string HWAddr::toText(bool include_htype) const {
 }
 
 HWAddr
-HWAddr::fromText(const std::string& text, const uint8_t htype) {
+HWAddr::fromText(const std::string& text, const uint16_t htype) {
     /// @todo optimize stream operations here.
     std::vector<std::string> split_text;
     boost::split(split_text, text, boost::is_any_of(":"),
index 3b4d62687cc262ce5f7aacc7e8e3ec5e228c1390..a2fa5ec1e638a69ad0869900f315e221525b3eb1 100644 (file)
@@ -41,18 +41,22 @@ public:
     /// @param hwaddr pointer to hardware address
     /// @param len length of the address pointed by hwaddr
     /// @param htype hardware type
-    HWAddr(const uint8_t* hwaddr, size_t len, uint8_t htype);
+    HWAddr(const uint8_t* hwaddr, size_t len, uint16_t htype);
 
     /// @brief constructor, based on C++ vector<uint8_t>
     /// @param hwaddr const reference to hardware address
     /// @param htype hardware type
-    HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype);
+    HWAddr(const std::vector<uint8_t>& hwaddr, uint16_t htype);
 
     // Vector that keeps the actual hardware address
     std::vector<uint8_t> hwaddr_;
 
-    // Hardware type
-    uint8_t htype_;
+    /// Hardware type
+    ///
+    /// @note It used to be uint8_t as used in DHCPv4. However, since we're
+    /// expanding MAC addresses support to DHCPv6 that uses hw_type as
+    /// 16 bits, we need to be able to store that wider format.
+    uint16_t htype_;
 
     /// @brief Returns textual representation of a hardware address
     /// (e.g. 00:01:02:03:04:05)
@@ -83,7 +87,7 @@ public:
     ///
     /// @return Instance of the HW address created from text.
     static HWAddr fromText(const std::string& text,
-                           const uint8_t htype = HTYPE_ETHER);
+                           const uint16_t htype = HTYPE_ETHER);
 
     /// @brief Compares two hardware addresses for equality
     bool operator==(const HWAddr& other) const;
index 7a904d36e5028c4e04cf256aa7764b4930681f11..184965c7cfcefa397dd7311f7dead0cf5a1515c1 100644 (file)
@@ -163,4 +163,16 @@ TEST(HWAddrTest, fromText) {
 
 }
 
+// Checks that 16 bits values can be stored in HWaddr
+TEST(HWAddrTest, 16bits) {
+
+    uint8_t data[] = {0, 1, 2, 3, 4, 5};
+    uint16_t htype = 257;
+    HWAddrPtr hw(new HWAddr(data, sizeof(data), htype));
+
+    EXPECT_EQ("hwtype=257 00:01:02:03:04:05", hw->toText());
+
+
+}
+
 } // end of anonymous namespace