]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/msg_type: entity_addr_t: fix legacy decode 25934/head
authorSage Weil <sage@redhat.com>
Wed, 16 Jan 2019 13:13:14 +0000 (07:13 -0600)
committerSage Weil <sage@redhat.com>
Wed, 16 Jan 2019 14:30:44 +0000 (08:30 -0600)
If we decode a zeroed sockaddr, we should end up with a TYPE_NONE
entity_addr_t, not v1::/0.

This was obscured by unit test TestAddrvecEncodeAddrDecode3, which
took an addrvec with all v2 addrs, decoded to an addr variable that
previously had v1:1.2.3.4:/0, and asserted the result was not v1::/0.
The test passed before because the set_sockaddr() failed on AF_UNSPEC
and the addr kept v1:1.2.3.4, but with the previous commit it failed
because it equaled v1::/0.  In reality, addr should get - (addr TYPE_NONE).

The TestEmptyAddrvecEncodeAddrDecode test case is similarly adjusted.

Signed-off-by: Sage Weil <sage@redhat.com>
src/msg/msg_types.h
src/test/test_addrs.cc

index 828b635b196cbdf76280764717f643fb35fa0836..cc5dc12dc113bfc5b88c32746a769831b144865d 100644 (file)
@@ -440,11 +440,15 @@ struct entity_addr_t {
     __u16 rest;
     decode(marker, bl);
     decode(rest, bl);
-    type = TYPE_LEGACY;
     decode(nonce, bl);
     sockaddr_storage ss;
     decode(ss, bl);
     set_sockaddr((sockaddr*)&ss);
+    if (get_family() == AF_UNSPEC) {
+      type = TYPE_NONE;
+    } else {
+      type = TYPE_LEGACY;
+    }
   }
 
   // Right now, these only deal with sockaddr_storage that have only family and content.
index 155f8eb4bf1d8a89a986926c22656069329805c7..b8795963e89acebc08375f78139b4d6ee448354b 100644 (file)
@@ -131,7 +131,7 @@ TEST(Msgr, TestEmptyAddrvecEncodeAddrDecode)
   addrvec.encode(bl, 0);
   auto bli = bl.cbegin();
   addr.decode(bli);
-  ASSERT_EQ(addr, entity_addr_t(1, 0));
+  ASSERT_EQ(addr, entity_addr_t());
 }
 
 const char *addrvec_checks[][4] = {
@@ -237,9 +237,11 @@ TEST(Msgr, TestAddrvecEncodeAddrDecode3)
   auto bli = bl.cbegin();
 
   addr.decode(bli);
+  //cout << addrvec << " (legacy " << addrvec.legacy_addr()
+  //<< ") -> " << addr << std::endl;
 
   ASSERT_NE(addr, addrvec.v[0]); // it's not the first addr(which is non-legacy)
-  ASSERT_NE(addr, entity_addr_t(1, 0)); // it's not a blank addr either
+  ASSERT_EQ(addr, entity_addr_t()); // it's not a blank addr either
 }
 
 const char *addrvec_parse_checks[][3] = {