include/net/tcx.h

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

File Facts

System
Linux kernel
Corpus path
include/net/tcx.h
Extension
.h
Size
4485 bytes
Lines
207
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 tcx_entry {
	struct mini_Qdisc __rcu *miniq;
	struct bpf_mprog_bundle bundle;
	u32 miniq_active;
	struct rcu_head rcu;
};

struct tcx_link {
	struct bpf_link link;
	struct net_device *dev;
};

static inline void tcx_set_ingress(struct sk_buff *skb, bool ingress)
{
#ifdef CONFIG_NET_XGRESS
	skb->tc_at_ingress = ingress;
#endif
}

#ifdef CONFIG_NET_XGRESS
static inline struct tcx_entry *tcx_entry(struct bpf_mprog_entry *entry)
{
	struct bpf_mprog_bundle *bundle = entry->parent;

	return container_of(bundle, struct tcx_entry, bundle);
}

static inline struct tcx_link *tcx_link(const struct bpf_link *link)
{
	return container_of(link, struct tcx_link, link);
}

void tcx_inc(void);
void tcx_dec(void);

static inline void tcx_entry_sync(void)
{
	/* bpf_mprog_entry got a/b swapped, therefore ensure that
	 * there are no inflight users on the old one anymore.
	 */
	synchronize_rcu();
}

static inline void
tcx_entry_update(struct net_device *dev, struct bpf_mprog_entry *entry,
		 bool ingress)
{
	ASSERT_RTNL();
	if (ingress)
		rcu_assign_pointer(dev->tcx_ingress, entry);
	else
		rcu_assign_pointer(dev->tcx_egress, entry);
}

static inline struct bpf_mprog_entry *
tcx_entry_fetch(struct net_device *dev, bool ingress)
{
	ASSERT_RTNL();
	if (ingress)
		return rcu_dereference_rtnl(dev->tcx_ingress);
	else
		return rcu_dereference_rtnl(dev->tcx_egress);
}

static inline struct bpf_mprog_entry *tcx_entry_create_noprof(void)
{
	struct tcx_entry *tcx = kzalloc_noprof(sizeof(*tcx), GFP_KERNEL);

	if (tcx) {
		bpf_mprog_bundle_init(&tcx->bundle);
		return &tcx->bundle.a;
	}
	return NULL;
}
#define tcx_entry_create(...)	alloc_hooks(tcx_entry_create_noprof(__VA_ARGS__))

static inline void tcx_entry_free(struct bpf_mprog_entry *entry)
{
	kfree_rcu(tcx_entry(entry), rcu);
}

static inline struct bpf_mprog_entry *
tcx_entry_fetch_or_create(struct net_device *dev, bool ingress, bool *created)
{
	struct bpf_mprog_entry *entry = tcx_entry_fetch(dev, ingress);

	*created = false;
	if (!entry) {
		entry = tcx_entry_create();
		if (!entry)

Annotation

Implementation Notes