net/ipv6/udp.c

Source file repositories/reference/linux-study-clean/net/ipv6/udp.c

File Facts

System
Linux kernel
Corpus path
net/ipv6/udp.c
Extension
.c
Size
50783 bytes
Lines
1952
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 (score > badness) {
			result = sk;
			badness = score;
		}
	}

	return result;
}

/* called with rcu_read_lock() */
static struct sock *udp6_lib_lookup2(const struct net *net,
		const struct in6_addr *saddr, __be16 sport,
		const struct in6_addr *daddr, unsigned int hnum,
		int dif, int sdif, struct udp_hslot *hslot2,
		struct sk_buff *skb)
{
	struct sock *sk, *result;
	int score, badness;
	bool need_rescore;

	result = NULL;
	badness = -1;
	udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
		need_rescore = false;
rescore:
		score = compute_score(need_rescore ? result : sk, net, saddr,
				      sport, daddr, hnum, dif, sdif);
		if (score > badness) {
			badness = score;

			if (need_rescore)
				continue;

			if (sk->sk_state == TCP_ESTABLISHED) {
				result = sk;
				continue;
			}

			result = inet6_lookup_reuseport(net, sk, skb, sizeof(struct udphdr),
							saddr, sport, daddr, hnum, udp6_ehashfn);
			if (!result) {
				result = sk;
				continue;
			}

			/* Fall back to scoring if group has connections */
			if (!reuseport_has_conns(sk))
				return result;

			/* Reuseport logic returned an error, keep original score. */
			if (IS_ERR(result))
				continue;

			/* compute_score is too long of a function to be
			 * inlined twice here, and calling it uninlined
			 * here yields measurable overhead for some
			 * workloads. Work around it by jumping
			 * backwards to rescore 'result'.
			 */
			need_rescore = true;
			goto rescore;
		}
	}
	return result;
}

#if IS_ENABLED(CONFIG_BASE_SMALL)
static struct sock *udp6_lib_lookup4(const struct net *net,
				     const struct in6_addr *saddr, __be16 sport,
				     const struct in6_addr *daddr,
				     unsigned int hnum, int dif, int sdif,
				     struct udp_table *udptable)
{
	return NULL;
}

static void udp6_hash4(struct sock *sk)
{
}
#else /* !CONFIG_BASE_SMALL */
static struct sock *udp6_lib_lookup4(const struct net *net,
				     const struct in6_addr *saddr, __be16 sport,
				     const struct in6_addr *daddr,
				     unsigned int hnum, int dif, int sdif,
				     struct udp_table *udptable)
{
	const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
	const struct hlist_nulls_node *node;
	struct udp_hslot *hslot4;
	unsigned int hash4, slot;

Annotation

Implementation Notes