include/net/udp.h

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

File Facts

System
Linux kernel
Corpus path
include/net/udp.h
Extension
.h
Size
18561 bytes
Lines
657
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 udp_skb_cb {
	union {
		struct inet_skb_parm	h4;
#if IS_ENABLED(CONFIG_IPV6)
		struct inet6_skb_parm	h6;
#endif
	} header;
};
#define UDP_SKB_CB(__skb)	((struct udp_skb_cb *)((__skb)->cb))

/**
 *	struct udp_hslot - UDP hash slot used by udp_table.hash/hash4
 *
 *	@head:	head of list of sockets
 *	@nulls_head:	head of list of sockets, only used by hash4
 *	@count:	number of sockets in 'head' list
 *	@lock:	spinlock protecting changes to head/count
 */
struct udp_hslot {
	union {
		struct hlist_head	head;
		/* hash4 uses hlist_nulls to avoid moving wrongly onto another
		 * hlist, because rehash() can happen with lookup().
		 */
		struct hlist_nulls_head	nulls_head;
	};
	int			count;
	spinlock_t		lock;
} __aligned(2 * sizeof(long));

/**
 *	struct udp_hslot_main - UDP hash slot used by udp_table.hash2
 *
 *	@hslot:	basic hash slot
 *	@hash4_cnt: number of sockets in hslot4 of the same
 *		    (local port, local address)
 */
struct udp_hslot_main {
	struct udp_hslot	hslot; /* must be the first member */
#if !IS_ENABLED(CONFIG_BASE_SMALL)
	u32			hash4_cnt;
#endif
} __aligned(2 * sizeof(long));
#define UDP_HSLOT_MAIN(__hslot) ((struct udp_hslot_main *)(__hslot))

/**
 *	struct udp_table - UDP table
 *
 *	@hash:	hash table, sockets are hashed on (local port)
 *	@hash2:	hash table, sockets are hashed on (local port, local address)
 *	@hash4:	hash table, connected sockets are hashed on
 *		(local port, local address, remote port, remote address)
 *	@mask:	number of slots in hash tables, minus 1
 *	@log:	log2(number of slots in hash table)
 */
struct udp_table {
	struct udp_hslot	*hash;
	struct udp_hslot_main	*hash2;
#if !IS_ENABLED(CONFIG_BASE_SMALL)
	struct udp_hslot	*hash4;
#endif
	unsigned int		mask;
	unsigned int		log;
};
extern struct udp_table udp_table;

static inline struct udp_hslot *udp_hashslot(struct udp_table *table,
					     const struct net *net,
					     unsigned int num)
{
	return &table->hash[udp_hashfn(net, num, table->mask)];
}

/*
 * For secondary hash, net_hash_mix() is performed before calling
 * udp_hashslot2(), this explains difference with udp_hashslot()
 */
static inline struct udp_hslot *udp_hashslot2(struct udp_table *table,
					      unsigned int hash)
{
	return &table->hash2[hash & table->mask].hslot;
}

#if IS_ENABLED(CONFIG_BASE_SMALL)
static inline void udp_table_hash4_init(struct udp_table *table)
{
}

static inline struct udp_hslot *udp_hashslot4(struct udp_table *table,
					      unsigned int hash)

Annotation

Implementation Notes