include/net/mctp.h

Source file repositories/reference/linux-study-clean/include/net/mctp.h

File Facts

System
Linux kernel
Corpus path
include/net/mctp.h
Extension
.h
Size
9743 bytes
Lines
361
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source 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

struct mctp_hdr {
	u8	ver;
	u8	dest;
	u8	src;
	u8	flags_seq_tag;
};

#define MCTP_VER_MIN	1
#define MCTP_VER_MAX	1

/* Definitions for ver field */
#define MCTP_HDR_VER_MASK	GENMASK(3, 0)

/* Definitions for flags_seq_tag field */
#define MCTP_HDR_FLAG_SOM	BIT(7)
#define MCTP_HDR_FLAG_EOM	BIT(6)
#define MCTP_HDR_FLAG_TO	BIT(3)
#define MCTP_HDR_FLAGS		GENMASK(5, 3)
#define MCTP_HDR_SEQ_SHIFT	4
#define MCTP_HDR_SEQ_MASK	GENMASK(1, 0)
#define MCTP_HDR_TAG_SHIFT	0
#define MCTP_HDR_TAG_MASK	GENMASK(2, 0)

#define MCTP_INITIAL_DEFAULT_NET	1

static inline bool mctp_address_unicast(mctp_eid_t eid)
{
	return eid >= 8 && eid < 255;
}

static inline bool mctp_address_broadcast(mctp_eid_t eid)
{
	return eid == 255;
}

static inline bool mctp_address_null(mctp_eid_t eid)
{
	return eid == 0;
}

static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid)
{
	return match == eid || match == MCTP_ADDR_ANY;
}

static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
{
	return (struct mctp_hdr *)skb_network_header(skb);
}

/* socket implementation */
struct mctp_sock {
	struct sock	sk;

	/* bind() params */
	unsigned int	bind_net;
	mctp_eid_t	bind_local_addr;
	mctp_eid_t	bind_peer_addr;
	unsigned int	bind_peer_net;
	bool		bind_peer_set;
	__u8		bind_type;

	/* sendmsg()/recvmsg() uses struct sockaddr_mctp_ext */
	bool		addr_ext;

	/* list of mctp_sk_key, for incoming tag lookup. updates protected
	 * by sk->net->keys_lock
	 */
	struct hlist_head keys;

	/* mechanism for expiring allocated keys; will release an allocated
	 * tag, and any netdev state for a request/response pairing
	 */
	struct timer_list key_expiry;
};

/* Key for matching incoming packets to sockets or reassembly contexts.
 * Packets are matched on (peer EID, local EID, tag).
 *
 * Lifetime / locking requirements:
 *
 *  - individual key data (ie, the struct itself) is protected by key->lock;
 *    changes must be made with that lock held.
 *
 *  - the lookup fields: peer_addr, local_addr and tag are set before the
 *    key is added to lookup lists, and never updated.
 *
 *  - A ref to the key must be held (throuh key->refs) if a pointer to the
 *    key is to be accessed after key->lock is released.
 *

Annotation

Implementation Notes