net/ceph/decode.c

Source file repositories/reference/linux-study-clean/net/ceph/decode.c

File Facts

System
Linux kernel
Corpus path
net/ceph/decode.c
Extension
.c
Size
4744 bytes
Lines
194
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

if (tmp_addr.type == my_type) {
			if (found) {
				pr_err("another match of type %d in addrvec\n",
				       le32_to_cpu(my_type));
				return -EINVAL;
			}

			memcpy(addr, &tmp_addr, sizeof(*addr));
			found = true;
		}
	}

	if (found)
		return 0;

	if (!addr_cnt)
		return 0;  /* normal -- e.g. unused OSD id/slot */

	if (addr_cnt == 1 && !memchr_inv(&tmp_addr, 0, sizeof(tmp_addr)))
		return 0;  /* weird but effectively the same as !addr_cnt */

	pr_err("no match of type %d in addrvec\n", le32_to_cpu(my_type));
	return -ENOENT;

e_inval:
	return -EINVAL;
}
EXPORT_SYMBOL(ceph_decode_entity_addrvec);

static int get_sockaddr_encoding_len(sa_family_t family)
{
	union {
		struct sockaddr sa;
		struct sockaddr_in sin;
		struct sockaddr_in6 sin6;
	} u;

	switch (family) {
	case AF_INET:
		return sizeof(u.sin);
	case AF_INET6:
		return sizeof(u.sin6);
	default:
		return sizeof(u);
	}
}

int ceph_entity_addr_encoding_len(const struct ceph_entity_addr *addr)
{
	sa_family_t family = get_unaligned(&addr->in_addr.ss_family);
	int addr_len = get_sockaddr_encoding_len(family);

	return 1 + CEPH_ENCODING_START_BLK_LEN + 4 + 4 + 4 + addr_len;
}

void ceph_encode_entity_addr(void **p, const struct ceph_entity_addr *addr)
{
	sa_family_t family = get_unaligned(&addr->in_addr.ss_family);
	int addr_len = get_sockaddr_encoding_len(family);

	ceph_encode_8(p, 1);  /* marker */
	ceph_start_encoding(p, 1, 1, sizeof(addr->type) +
				     sizeof(addr->nonce) +
				     sizeof(u32) + addr_len);
	ceph_encode_copy(p, &addr->type, sizeof(addr->type));
	ceph_encode_copy(p, &addr->nonce, sizeof(addr->nonce));

	ceph_encode_32(p, addr_len);
	ceph_encode_16(p, family);
	ceph_encode_copy(p, addr->in_addr.__data, addr_len - sizeof(family));
}

Annotation

Implementation Notes