Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * INET		An implementation of the TCP/IP protocol suite for the LINUX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *		operating system.  INET is implemented using the  BSD Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *		interface as the means of communication with the user level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *		Definitions for the UDP module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Version:	@(#)udp.h	1.0.2	05/07/93
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Authors:	Ross Biro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *		Alan Cox	: Turned on udp checksums. I don't want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *				  chase 'memory corruption' bugs that aren't!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #ifndef _UDP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define _UDP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/inet_sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/indirect_call_wrapper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *	struct udp_skb_cb  -  UDP(-Lite) private variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *	@header:      private variables used by IPv4/IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *	@cscov:       checksum coverage length (UDP-Lite only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *	@partial_cov: if set indicates partial csum coverage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct udp_skb_cb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		struct inet_skb_parm	h4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		struct inet6_skb_parm	h6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	} header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__u16		cscov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	__u8		partial_cov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define UDP_SKB_CB(__skb)	((struct udp_skb_cb *)((__skb)->cb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *	struct udp_hslot - UDP hash slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *	@head:	head of list of sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *	@count:	number of sockets in 'head' list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *	@lock:	spinlock protecting changes to head/count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct udp_hslot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct hlist_head	head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int			count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	spinlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) } __attribute__((aligned(2 * sizeof(long))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *	struct udp_table - UDP table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *	@hash:	hash table, sockets are hashed on (local port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *	@hash2:	hash table, sockets are hashed on (local port, local address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *	@mask:	number of slots in hash tables, minus 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *	@log:	log2(number of slots in hash table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct udp_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct udp_hslot	*hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct udp_hslot	*hash2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned int		mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	unsigned int		log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) extern struct udp_table udp_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) void udp_table_init(struct udp_table *, const char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static inline struct udp_hslot *udp_hashslot(struct udp_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 					     struct net *net, unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return &table->hash[udp_hashfn(net, num, table->mask)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * For secondary hash, net_hash_mix() is performed before calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * udp_hashslot2(), this explains difference with udp_hashslot()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static inline struct udp_hslot *udp_hashslot2(struct udp_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 					      unsigned int hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return &table->hash2[hash & table->mask];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) extern struct proto udp_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) extern atomic_long_t udp_memory_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /* sysctl variables for udp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) extern long sysctl_udp_mem[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) extern int sysctl_udp_rmem_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) extern int sysctl_udp_wmem_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct sk_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *	Generic checksumming routines for UDP(-Lite) v4 and v6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static inline __sum16 __udp_lib_checksum_complete(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return (UDP_SKB_CB(skb)->cscov == skb->len ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		__skb_checksum_complete(skb) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		__skb_checksum_complete_head(skb, UDP_SKB_CB(skb)->cscov));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline int udp_lib_checksum_complete(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return !skb_csum_unnecessary(skb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		__udp_lib_checksum_complete(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * 	udp_csum_outgoing  -  compute UDPv4/v6 checksum over fragments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * 	@sk: 	socket we are writing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * 	@skb: 	sk_buff containing the filled-in UDP header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * 	        (checksum field must be zeroed out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline __wsum udp_csum_outgoing(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	__wsum csum = csum_partial(skb_transport_header(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				   sizeof(struct udphdr), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	skb_queue_walk(&sk->sk_write_queue, skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		csum = csum_add(csum, skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline __wsum udp_csum(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	__wsum csum = csum_partial(skb_transport_header(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				   sizeof(struct udphdr), skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	for (skb = skb_shinfo(skb)->frag_list; skb; skb = skb->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		csum = csum_add(csum, skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static inline __sum16 udp_v4_check(int len, __be32 saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				   __be32 daddr, __wsum base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) void udp_set_csum(bool nocheck, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		  __be32 saddr, __be32 daddr, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static inline void udp_csum_pull_header(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (!skb->csum_valid && skb->ip_summed == CHECKSUM_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		skb->csum = csum_partial(skb->data, sizeof(struct udphdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					 skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	skb_pull_rcsum(skb, sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	UDP_SKB_CB(skb)->cscov -= sizeof(struct udphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) typedef struct sock *(*udp_lookup_t)(struct sk_buff *skb, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				     __be16 dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp4_gro_receive(struct list_head *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 							   struct sk_buff *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) INDIRECT_CALLABLE_DECLARE(int udp4_gro_complete(struct sk_buff *, int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp6_gro_receive(struct list_head *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 							   struct sk_buff *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) INDIRECT_CALLABLE_DECLARE(int udp6_gro_complete(struct sk_buff *, int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				struct udphdr *uh, struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int udp_gro_complete(struct sk_buff *skb, int nhoff, udp_lookup_t lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				  netdev_features_t features, bool is_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned int hlen, off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	off  = skb_gro_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	hlen = off + sizeof(*uh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	uh   = skb_gro_header_fast(skb, off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (skb_gro_header_hard(skb, hlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		uh = skb_gro_header_slow(skb, hlen, off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* hash routines shared between UDPv4/6 and UDP-Litev4/6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static inline int udp_lib_hash(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void udp_lib_unhash(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void udp_lib_rehash(struct sock *sk, u16 new_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline void udp_lib_close(struct sock *sk, long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int udp_lib_get_port(struct sock *sk, unsigned short snum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		     unsigned int hash2_nulladdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u32 udp_flow_hashrnd(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				       int min, int max, bool use_eth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (min >= max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		/* Use default range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		inet_get_local_port_range(net, &min, &max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	hash = skb_get_hash(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (unlikely(!hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (use_eth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			/* Can't find a normal hash, caller has indicated an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			 * Ethernet packet so use that to compute a hash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			hash = jhash(skb->data, 2 * ETH_ALEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				     (__force u32) skb->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			/* Can't derive any sort of hash for the packet, set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 * to some consistent random value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			hash = udp_flow_hashrnd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* Since this is being sent on the wire obfuscate hash a bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * to minimize possbility that any useful information to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * attacker is leaked. Only upper 16 bits are relevant in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * computation for 16 bit port value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	hash ^= hash << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return htons((((u64) hash * (max - min)) >> 32) + min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static inline int udp_rqueue_get(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return sk_rmem_alloc_get(sk) - READ_ONCE(udp_sk(sk)->forward_deficit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline bool udp_sk_bound_dev_eq(struct net *net, int bound_dev_if,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				       int dif, int sdif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return inet_bound_dev_eq(!!net->ipv4.sysctl_udp_l3mdev_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				 bound_dev_if, dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* net/ipv4/udp.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void udp_destruct_sock(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) void udp_skb_destructor(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			       int noblock, int *off, int *err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static inline struct sk_buff *skb_recv_udp(struct sock *sk, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 					   int noblock, int *err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	int off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return __skb_recv_udp(sk, flags, noblock, &off, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int udp_v4_early_demux(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) bool udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int udp_get_port(struct sock *sk, unsigned short snum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		 int (*saddr_cmp)(const struct sock *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				  const struct sock *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int udp_err(struct sk_buff *, u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int udp_abort(struct sock *sk, int err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int udp_push_pending_frames(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void udp_flush_pending_frames(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int udp_rcv(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int udp_init_sock(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int __udp_disconnect(struct sock *sk, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int udp_disconnect(struct sock *sk, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 				       netdev_features_t features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				       bool is_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int udp_lib_getsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		       char __user *optval, int __user *optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int udp_lib_setsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		       sockptr_t optval, unsigned int optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		       int (*push_pending_frames)(struct sock *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			     __be32 daddr, __be16 dport, int dif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			       __be32 daddr, __be16 dport, int dif, int sdif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			       struct udp_table *tbl, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				 __be16 sport, __be16 dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct sock *udp6_lib_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			     const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			     const struct in6_addr *daddr, __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			     int dif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct sock *__udp6_lib_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			       const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			       const struct in6_addr *daddr, __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			       int dif, int sdif, struct udp_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			       struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				 __be16 sport, __be16 dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* UDP uses skb->dev_scratch to cache as much information as possible and avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * possibly multiple cache miss on dequeue()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct udp_dev_scratch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/* skb->truesize and the stateless bit are embedded in a single field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 * do not use a bitfield since the compiler emits better/smaller code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * this way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	u32 _tsize_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/* len and the bit needed to compute skb_csum_unnecessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 * will be on cold cache lines at recvmsg time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 * skb->len can be stored on 16 bits since the udp header has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * already validated and pulled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	bool is_linear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	bool csum_unnecessary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static inline struct udp_dev_scratch *udp_skb_scratch(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return (struct udp_dev_scratch *)&skb->dev_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static inline unsigned int udp_skb_len(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	return udp_skb_scratch(skb)->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return udp_skb_scratch(skb)->csum_unnecessary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static inline bool udp_skb_is_linear(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return udp_skb_scratch(skb)->is_linear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static inline unsigned int udp_skb_len(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return skb_csum_unnecessary(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static inline bool udp_skb_is_linear(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	return !skb_is_nonlinear(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				  struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	n = copy_to_iter(skb->data + off, len, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (n == len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	iov_iter_revert(to, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * 	SNMP statistics for UDP and UDP-Lite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #define UDP_INC_STATS(net, field, is_udplite)		      do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (is_udplite) SNMP_INC_STATS((net)->mib.udplite_statistics, field);       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	else		SNMP_INC_STATS((net)->mib.udp_statistics, field);  }  while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #define __UDP_INC_STATS(net, field, is_udplite) 	      do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_statistics, field);         \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	else		__SNMP_INC_STATS((net)->mib.udp_statistics, field);    }  while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) #define __UDP6_INC_STATS(net, field, is_udplite)	    do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_stats_in6, field);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	else		__SNMP_INC_STATS((net)->mib.udp_stats_in6, field);  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #define UDP6_INC_STATS(net, field, __lite)		    do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (__lite) SNMP_INC_STATS((net)->mib.udplite_stats_in6, field);  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	else	    SNMP_INC_STATS((net)->mib.udp_stats_in6, field);      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #define __UDPX_MIB(sk, ipv4)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	ipv4 ? (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics :	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				 sock_net(sk)->mib.udp_statistics) :	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		(IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_stats_in6 :	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				 sock_net(sk)->mib.udp_stats_in6);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #define __UDPX_MIB(sk, ipv4)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics :		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			 sock_net(sk)->mib.udp_statistics;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #define __UDPX_INC_STATS(sk, field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	__SNMP_INC_STATS(__UDPX_MIB(sk, (sk)->sk_family == AF_INET), field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct udp_seq_afinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	sa_family_t			family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	struct udp_table		*udp_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct udp_iter_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	struct seq_net_private  p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	int			bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	struct udp_seq_afinfo	*bpf_seq_afinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) void *udp_seq_start(struct seq_file *seq, loff_t *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) void udp_seq_stop(struct seq_file *seq, void *v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) extern const struct seq_operations udp_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) extern const struct seq_operations udp6_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) int udp4_proc_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) void udp4_proc_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int udpv4_offload_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) void udp_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) DECLARE_STATIC_KEY_FALSE(udp_encap_needed_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) void udp_encap_enable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) void udp_encap_disable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) DECLARE_STATIC_KEY_FALSE(udpv6_encap_needed_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) void udpv6_encap_enable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 					      struct sk_buff *skb, bool ipv4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	netdev_features_t features = NETIF_F_SG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	struct sk_buff *segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	/* Avoid csum recalculation by skb_segment unless userspace explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	 * asks for the final checksum values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (!inet_get_convert_csum(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	/* UDP segmentation expects packets of type CHECKSUM_PARTIAL or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	 * CHECKSUM_NONE in __udp_gso_segment. UDP GRO indeed builds partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	 * packets in udp_gro_complete_segment. As does UDP GSO, verified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 * udp_send_skb. But when those packets are looped in dev_loopback_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 * their ip_summed CHECKSUM_NONE is changed to CHECKSUM_UNNECESSARY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 * Reset in this specific case, where PARTIAL is both correct and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	 * required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (skb->pkt_type == PACKET_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		skb->ip_summed = CHECKSUM_PARTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* the GSO CB lays after the UDP one, no need to save and restore any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	 * CB fragment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	segs = __skb_gso_segment(skb, features, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (IS_ERR_OR_NULL(segs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		int segs_nr = skb_shinfo(skb)->gso_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		atomic_add(segs_nr, &sk->sk_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		SNMP_ADD_STATS(__UDPX_MIB(sk, ipv4), UDP_MIB_INERRORS, segs_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) #ifdef CONFIG_BPF_STREAM_PARSER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct sk_psock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct proto *udp_bpf_get_proto(struct sock *sk, struct sk_psock *psock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #endif /* BPF_STREAM_PARSER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #endif	/* _UDP_H */