decode.c (a5cbd5fc22d5043a8a76e15d75d031fe24d1f69c) decode.c (cd1a677cad994021b19665ed476aea63f5d54f31)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/ceph/ceph_debug.h>
3
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/ceph/ceph_debug.h>
3
4#include <linux/inet.h>
5
4#include <linux/ceph/decode.h>
5
6static int
7ceph_decode_entity_addr_versioned(void **p, void *end,
8 struct ceph_entity_addr *addr)
9{
10 int ret;
11 u8 struct_v;

--- 121 unchanged lines hidden (view full) ---

133 }
134
135 return 0;
136
137e_inval:
138 return -EINVAL;
139}
140EXPORT_SYMBOL(ceph_decode_entity_addrvec);
6#include <linux/ceph/decode.h>
7
8static int
9ceph_decode_entity_addr_versioned(void **p, void *end,
10 struct ceph_entity_addr *addr)
11{
12 int ret;
13 u8 struct_v;

--- 121 unchanged lines hidden (view full) ---

135 }
136
137 return 0;
138
139e_inval:
140 return -EINVAL;
141}
142EXPORT_SYMBOL(ceph_decode_entity_addrvec);
143
144static int get_sockaddr_encoding_len(sa_family_t family)
145{
146 union {
147 struct sockaddr sa;
148 struct sockaddr_in sin;
149 struct sockaddr_in6 sin6;
150 } u;
151
152 switch (family) {
153 case AF_INET:
154 return sizeof(u.sin);
155 case AF_INET6:
156 return sizeof(u.sin6);
157 default:
158 return sizeof(u);
159 }
160}
161
162int ceph_entity_addr_encoding_len(const struct ceph_entity_addr *addr)
163{
164 sa_family_t family = get_unaligned(&addr->in_addr.ss_family);
165 int addr_len = get_sockaddr_encoding_len(family);
166
167 return 1 + CEPH_ENCODING_START_BLK_LEN + 4 + 4 + 4 + addr_len;
168}
169
170void ceph_encode_entity_addr(void **p, const struct ceph_entity_addr *addr)
171{
172 sa_family_t family = get_unaligned(&addr->in_addr.ss_family);
173 int addr_len = get_sockaddr_encoding_len(family);
174
175 ceph_encode_8(p, 1); /* marker */
176 ceph_start_encoding(p, 1, 1, sizeof(addr->type) +
177 sizeof(addr->nonce) +
178 sizeof(u32) + addr_len);
179 ceph_encode_copy(p, &addr->type, sizeof(addr->type));
180 ceph_encode_copy(p, &addr->nonce, sizeof(addr->nonce));
181
182 ceph_encode_32(p, addr_len);
183 ceph_encode_16(p, family);
184 ceph_encode_copy(p, addr->in_addr.__data, addr_len - sizeof(family));
185}