From: Jeff Layton Date: Mon, 3 Jun 2019 14:55:37 +0000 (-0400) Subject: msg: fix addr2 encoding for sockaddrs X-Git-Tag: v15.1.0~2516^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F28379%2Fhead;p=ceph.git msg: fix addr2 encoding for sockaddrs Currently, the sockaddr sa_family field is being sent across the wire without any sort of endianness conversion. Redefine the new-style entity_addr_t encoding to encode the sa_family field as little-endian. This will allow LE machines in the field to keep limping along, but note that BE machines may break until they are all fixed. To do this, use the code that was initially written for BSD/Apple machines to encode the different fields separately. Fixes: http://tracker.ceph.com/issues/40114 Signed-off-by: Jeff Layton --- diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 7557c51a82f9..6ce1b3a0b2f8 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -489,16 +489,16 @@ struct entity_addr_t { } encode(nonce, bl); __u32 elen = get_sockaddr_len(); +#if (__FreeBSD__) || defined(__APPLE__) + elen -= sizeof(u.sa.sa_len); +#endif encode(elen, bl); if (elen) { -#if (__FreeBSD__) || defined(__APPLE__) - __le16 ss_family = u.sa.sa_family; + uint16_t ss_family = u.sa.sa_family; + encode(ss_family, bl); - bl.append(u.sa.sa_data, - elen - sizeof(u.sa.sa_len) - sizeof(u.sa.sa_family)); -#else - bl.append((char*)get_sockaddr(), elen); -#endif + elen -= sizeof(u.sa.sa_family); + bl.append(u.sa.sa_data, elen); } ENCODE_FINISH(bl); } @@ -520,7 +520,8 @@ struct entity_addr_t { if (elen) { #if defined(__FreeBSD__) || defined(__APPLE__) u.sa.sa_len = 0; - __le16 ss_family; +#endif + uint16_t ss_family; if (elen < sizeof(ss_family)) { throw buffer::malformed_input("elen smaller than family len"); } @@ -531,17 +532,6 @@ struct entity_addr_t { throw buffer::malformed_input("elen exceeds sockaddr len"); } bl.copy(elen, u.sa.sa_data); -#else - if (elen < sizeof(u.sa.sa_family)) { - throw ceph::buffer::malformed_input("elen smaller than family len"); - } - bl.copy(sizeof(u.sa.sa_family), (char*)&u.sa.sa_family); - if (elen > get_sockaddr_len()) { - throw ceph::buffer::malformed_input("elen exceeds sockaddr len"); - } - elen -= sizeof(u.sa.sa_family); - bl.copy(elen, u.sa.sa_data); -#endif } DECODE_FINISH(bl); }