From 88824a97508d2593cde7370c7b663ed9cd7517b4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 16 Jan 2019 07:13:14 -0600 Subject: [PATCH] msg/msg_type: entity_addr_t: fix legacy decode 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 --- src/msg/msg_types.h | 6 +++++- src/test/test_addrs.cc | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 828b635b196..cc5dc12dc11 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -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. diff --git a/src/test/test_addrs.cc b/src/test/test_addrs.cc index 155f8eb4bf1..b8795963e89 100644 --- a/src/test/test_addrs.cc +++ b/src/test/test_addrs.cc @@ -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] = { -- 2.39.5