Skip to content

msg: put Linux's AF_INET6 on the wire on FreeBSD and macOS too - #72446

Open
dvanders wants to merge 6 commits into
ceph:mainfrom
dvanders:wip-addr-af-inet6
Open

dvanders wants to merge 6 commits into
ceph:mainfrom
dvanders:wip-addr-af-inet6

Conversation

@dvanders

@dvanders dvanders commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #71445, now merged.

  • test/test_addrs: the two tests from my msg: fix entity_addr_t wire encoding on BSD and macOS #71445 review. They pin the msgr2 AF_INET encoding byte for byte, and check that entity_addr_t and entity_addrvec_t reject an elen one byte too long.
  • msg: AF_INET6 on the wire: the wire format uses Linux's AF_INET6 (10), but only Windows mapped to it. FreeBSD (28) and macOS (30) sent their own value, which Linux peers don't recognise. Now every platform maps it; on Linux this is a no-op. Two new tests pin the IPv6 encoding.
  • msg: entity_addrvec_t's msgr2 decode (from @tchaikov's review): entity_addrvec_t::decode() had its own copy of the msgr2 address decode, which kept the wire family as is. It now calls the same decode_after_marker() as entity_addr_t::decode(), and a new test decodes an IPv6 address through it.

On macOS the new tests fail without the fixes and pass with them. @wjwithagen confirmed unittest_addrs passes on FreeBSD.

Fixes: https://tracker.ceph.com/issues/81504

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

🤖 Generated with Claude Code

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#71445 has landed, so the branch could be rebased to drop a2c3329.since

Comment thread src/test/test_addrs.cc Resolved
Comment thread src/msg/msg_types.h Resolved
@wjwithagen

Copy link
Copy Markdown
Member

On macOS the new tests fail without the fix and pass with it. @wjwithagen, could you run unittest_addrs on FreeBSD?

[~/Ceph.ggate/build] [email protected]> ctest -R 'addr|msgr|ipaddr' --output-on-failure
Test project /home/wjw/Ceph.ggate/build
    Start 25: unittest_addrs
1/2 Test #25: unittest_addrs ...................   Passed    0.23 sec
    Start 61: unittest_ipaddr
2/2 Test #61: unittest_ipaddr ..................   Passed    0.36 sec

100% tests passed, 0 tests failed out of 2

For me/FreeBSD oke....

Check that an AF_INET entity_addr_t encodes to the same bytes as on
Linux, and that entity_addr_t and entity_addrvec_t both reject an
address one byte longer than a sockaddr_in.  Both pass on Linux before
and after the fix.  On macOS, each half of the decode test fails without
the matching decode fix in msg_types.h and msg_types.cc.

Assisted-by: Claude-Code-v2.1.287:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
entity_addr_t and the legacy sockaddr_storage encoding carry the address
family as a number, and every reader assumes Linux's values.  AF_INET is 2
everywhere, but AF_INET6 is 10 on Linux, 23 on Windows, 28 on FreeBSD and
30 on macOS.  encode() and decode() mapped it to and from AF_INET6_LINUX
only on Windows, so an IPv6 address from a FreeBSD or macOS daemon reaches
a Linux peer with a family the peer does not recognise, and the reverse.

Define AF_INET6_LINUX everywhere and map in both the msgr2 and the legacy
encoding.  On Linux the mapping is a no-op.  A FreeBSD or macOS daemon
still decodes the native value an older daemon of the same OS sends.

Fixes: https://tracker.ceph.com/issues/81504
Assisted-by: Claude-Code-v2.1.287:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
entity_addrvec_t::decode() decodes a single msgr2 address (marker 1)
with its own copy of entity_addr_t::decode(), and that copy stores the
wire family as is. An IPv6 address decoded that way keeps AF_INET6_LINUX
(10) on FreeBSD, macOS and Windows, where AF_INET6 is 28, 30 and 23.

Split the msgr2 part of entity_addr_t::decode() into
decode_after_marker(), alongside decode_legacy_addr_after_marker(), and
call it from entity_addrvec_t::decode() instead of the copy.

Add a test that decodes an encoded msgr2 IPv6 address as an
entity_addrvec_t. Move the comment for the oversized-address test back
to that test.

Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders

Copy link
Copy Markdown
Contributor Author

Rebased on main as suggested, so a2c3329 (merged with #71445) no longer shows here. The other three commits are unchanged.

Comment thread src/msg/msg_types.h Resolved
Comment thread src/msg/msg_types.h
}
/// the msgr2 encoding, once decode() or entity_addrvec_t::decode() has
/// read marker 1
void decode_after_marker(ceph::buffer::list::const_iterator& bl) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity_addr_t::decode() never clears the union. so we probably need to have something like

void decode(ceph::buffer::list::const_iterator& bl) {
  // the encoding only carries the bytes of this particular address, so
  // clear the union: a reused entity_addr_t would otherwise keep stale
  // bytes from a previously decoded longer address
  memset(&u, 0, sizeof(u));
  ...
}

the ctor already does this. please note, the bug only manifests when decode() is called on an entity_addr_t that already holds a value. the reason why it has not surfaced yet is that the overwhelmingly dominant decode idiom in ceph is decoding into freshly constructed objects. but better safe than sorry..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and it's easy to show: an IPv4 address decoded over an IPv6 one compares unequal to the same address decoded into a new object. Fixed in e61096f. I put the memset in decode_after_marker() and decode_legacy_addr_after_marker() rather than in decode(), so that entity_addrvec_t::decode(), which calls those two directly, is covered as well. Tests for both are in c72ea3a; on macOS they fail without the fixes and pass with them. Not run on Linux or FreeBSD yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going on the test list for FreeBSD as well.

entity_addr_t's conversions to and from ceph_entity_addr put the
address family in network byte order with htons() and ntohs().
sa_family_t is a single byte on the BSDs and macOS, so the swapped
value is truncated to 0 and the family is lost. FreeBSD was already
excluded by name; macOS was not.

Swap only where the family is two bytes wide, which covers both.

Suggested-by: Kefu Chai <[email protected]>
Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2
Signed-off-by: Dan van der Ster <[email protected]>
decode() only writes the bytes that the encoding carries. When the
entity_addr_t already holds an address, the rest of the sockaddr union
keeps its old bytes: an IPv4 address decoded over an IPv6 one compares
unequal to the same address decoded into a new object, and a blank
address leaves the old one in place. Most callers decode into a new
object, so this has not shown up.

Clear the union in both decode paths, as the constructors do.

Suggested-by: Kefu Chai <[email protected]>
Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2
Signed-off-by: Dan van der Ster <[email protected]>
TestAddrDecodeIntoUsedAddr decodes an IPv4 and then a blank address
into an entity_addr_t that held an IPv6 address, in both encodings, and
expects the same value as from a new object. It fails without the
previous commit.

TestAddrCephEntityAddrRoundTrip converts to ceph_entity_addr and back.
On macOS it fails without the byte-swap fix: the family comes back
as 0.

Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2
Signed-off-by: Dan van der Ster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants