include/net/erspan.h

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

File Facts

System
Linux kernel
Corpus path
include/net/erspan.h
Extension
.h
Size
9251 bytes
Lines
322
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 erspan_base_hdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
	__u8	vlan_upper:4,
		ver:4;
	__u8	vlan:8;
	__u8	session_id_upper:2,
		t:1,
		en:2,
		cos:3;
	__u8	session_id:8;
#elif defined(__BIG_ENDIAN_BITFIELD)
	__u8	ver: 4,
		vlan_upper:4;
	__u8	vlan:8;
	__u8	cos:3,
		en:2,
		t:1,
		session_id_upper:2;
	__u8	session_id:8;
#else
#error "Please fix <asm/byteorder.h>"
#endif
};

static inline void set_session_id(struct erspan_base_hdr *ershdr, u16 id)
{
	ershdr->session_id = id & 0xff;
	ershdr->session_id_upper = (id >> 8) & 0x3;
}

static inline u16 get_session_id(const struct erspan_base_hdr *ershdr)
{
	return (ershdr->session_id_upper << 8) + ershdr->session_id;
}

static inline void set_vlan(struct erspan_base_hdr *ershdr, u16 vlan)
{
	ershdr->vlan = vlan & 0xff;
	ershdr->vlan_upper = (vlan >> 8) & 0xf;
}

static inline u16 get_vlan(const struct erspan_base_hdr *ershdr)
{
	return (ershdr->vlan_upper << 8) + ershdr->vlan;
}

static inline void set_hwid(struct erspan_md2 *md2, u8 hwid)
{
	md2->hwid = hwid & 0xf;
	md2->hwid_upper = (hwid >> 4) & 0x3;
}

static inline u8 get_hwid(const struct erspan_md2 *md2)
{
	return (md2->hwid_upper << 4) + md2->hwid;
}

static inline int erspan_hdr_len(int version)
{
	if (version == 0)
		return 0;

	return sizeof(struct erspan_base_hdr) +
	       (version == 1 ? ERSPAN_V1_MDSIZE : ERSPAN_V2_MDSIZE);
}

static inline u8 tos_to_cos(u8 tos)
{
	u8 dscp, cos;

	dscp = tos >> 2;
	cos = dscp >> 3;
	return cos;
}

static inline void erspan_build_header(struct sk_buff *skb,
				u32 id, u32 index,
				bool truncate, bool is_ipv4)
{
	struct ethhdr *eth = (struct ethhdr *)skb->data;
	enum erspan_encap_type enc_type;
	struct erspan_base_hdr *ershdr;
	struct qtag_prefix {
		__be16 eth_type;
		__be16 tci;
	} *qp;
	u16 vlan_tci = 0;
	u8 tos;
	__be32 *idx;

Annotation

Implementation Notes