]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: fix addr2 encoding for sockaddrs 28379/head
authorJeff Layton <jlayton@redhat.com>
Mon, 3 Jun 2019 14:55:37 +0000 (10:55 -0400)
committerJeff Layton <jlayton@redhat.com>
Wed, 5 Jun 2019 13:31:02 +0000 (09:31 -0400)
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 <jlayton@redhat.com>
src/msg/msg_types.h

index 7557c51a82f97cdfa0b059feb5b6530795f024f4..6ce1b3a0b2f8c57a0c2d1e94782474a8c9b5d820 100644 (file)
@@ -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);
   }