1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/ceph/decode.h>
6 ceph_decode_entity_addr_versioned(void **p
, void *end
,
7 struct ceph_entity_addr
*addr
)
11 u32 struct_len
, addr_len
;
14 ret
= ceph_start_decoding(p
, end
, 1, "entity_addr_t", &struct_v
,
20 struct_end
= *p
+ struct_len
;
22 ceph_decode_copy_safe(p
, end
, &addr
->type
, sizeof(addr
->type
), bad
);
24 ceph_decode_copy_safe(p
, end
, &addr
->nonce
, sizeof(addr
->nonce
), bad
);
26 ceph_decode_32_safe(p
, end
, addr_len
, bad
);
27 if (addr_len
> sizeof(addr
->in_addr
))
30 memset(&addr
->in_addr
, 0, sizeof(addr
->in_addr
));
32 ceph_decode_copy_safe(p
, end
, &addr
->in_addr
, addr_len
, bad
);
34 addr
->in_addr
.ss_family
=
35 le16_to_cpu((__force __le16
)addr
->in_addr
.ss_family
);
38 /* Advance past anything the client doesn't yet understand */
46 ceph_decode_entity_addr_legacy(void **p
, void *end
,
47 struct ceph_entity_addr
*addr
)
51 /* Skip rest of type field */
52 ceph_decode_skip_n(p
, end
, 3, bad
);
55 * Clients that don't support ADDR2 always send TYPE_NONE, change it
56 * to TYPE_LEGACY for forward compatibility.
58 addr
->type
= CEPH_ENTITY_ADDR_TYPE_LEGACY
;
59 ceph_decode_copy_safe(p
, end
, &addr
->nonce
, sizeof(addr
->nonce
), bad
);
60 memset(&addr
->in_addr
, 0, sizeof(addr
->in_addr
));
61 ceph_decode_copy_safe(p
, end
, &addr
->in_addr
,
62 sizeof(addr
->in_addr
), bad
);
63 addr
->in_addr
.ss_family
=
64 be16_to_cpu((__force __be16
)addr
->in_addr
.ss_family
);
71 ceph_decode_entity_addr(void **p
, void *end
, struct ceph_entity_addr
*addr
)
75 ceph_decode_8_safe(p
, end
, marker
, bad
);
77 return ceph_decode_entity_addr_versioned(p
, end
, addr
);
79 return ceph_decode_entity_addr_legacy(p
, end
, addr
);
83 EXPORT_SYMBOL(ceph_decode_entity_addr
);