https://source.android.com/docs/security/bulletin/2023-05-01 CVE-2023-21102 CVE-2023-21106 CVE-2023-0266 * tag 'ASB-2023-05-05_4.19-stable' of https://android.googlesource.com/kernel/common: Linux 4.19.282 ASN.1: Fix check for strdup() success iio: adc: at91-sama5d2_adc: fix an error code in at91_adc_allocate_trigger() counter: 104-quad-8: Fix race condition between FLAG and CNTR reads sctp: Call inet6_destroy_sock() via sk->sk_destruct(). dccp: Call inet6_destroy_sock() via sk->sk_destruct(). inet6: Remove inet6_destroy_sock() in sk->sk_prot->destroy(). tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct(). udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM). ext4: fix use-after-free in ext4_xattr_set_entry ext4: remove duplicate definition of ext4_xattr_ibody_inline_set() Revert "ext4: fix use-after-free in ext4_xattr_set_entry" x86/purgatory: Don't generate debug info for purgatory.ro memstick: fix memory leak if card device is never registered nilfs2: initialize unused bytes in segment summary blocks xen/netback: use same error messages for same errors s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling net: dsa: b53: mmap: add phy ops scsi: core: Improve scsi_vpd_inquiry() checks scsi: megaraid_sas: Fix fw_crash_buffer_show() selftests: sigaltstack: fix -Wuninitialized Input: i8042 - add quirk for Fujitsu Lifebook A574/H f2fs: Fix f2fs_truncate_partial_nodes ftrace event e1000e: Disable TSO on i219-LM card to increase speed mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next() i40e: fix i40e_setup_misc_vector() error handling i40e: fix accessing vsi->active_filters without holding lock virtio_net: bugfix overflow inside xdp_linearize_page() net: sched: sch_qfq: prevent slab-out-of-bounds in qfq_activate_agg ARM: dts: rockchip: fix a typo error for rk3288 spdif node Linux 4.19.281 arm64: KVM: Fix system register enumeration KVM: arm64: Filter out invalid core register IDs in KVM_GET_REG_LIST KVM: arm64: Factor out core register ID enumeration KVM: nVMX: add missing consistency checks for CR0 and CR4 coresight-etm4: Fix for() loop drvdata->nr_addr_cmp range bug watchdog: sbsa_wdog: Make sure the timeout programming is within the limits cgroup/cpuset: Wake up cpuset_attach_wq tasks in cpuset_cancel_attach() ubi: Fix deadlock caused by recursively holding work_sem mtd: ubi: wl: Fix a couple of kernel-doc issues ubi: Fix failure attaching when vid_hdr offset equals to (sub)page size x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot scsi: ses: Handle enclosure with just a primary component gracefully verify_pefile: relax wrapper length check efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L i2c: imx-lpi2c: clean rx/tx buffers upon new message power: supply: cros_usbpd: reclassify "default case!" as debug udp6: fix potential access to stale information net: macb: fix a memory corruption in extended buffer descriptor mode sctp: fix a potential overflow in sctp_ifwdtsn_skip qlcnic: check pci_reset_function result niu: Fix missing unwind goto in niu_alloc_channels() 9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition mtdblock: tolerate corrected bit-flips Bluetooth: Fix race condition in hidp_session_thread Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp} ALSA: hda/sigmatel: fix S/PDIF out on Intel D*45* motherboards ALSA: i2c/cs8427: fix iec958 mixer control deactivation ALSA: hda/sigmatel: add pin overrides for Intel DP45SG motherboard ALSA: emu10k1: fix capture interrupt handler unlinking Revert "pinctrl: amd: Disable and mask interrupts on resume" mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() ring-buffer: Fix race while reader and writer are on the same page ftrace: Mark get_lock_parent_ip() __always_inline perf/core: Fix the same task check in perf_event_set_output ALSA: hda/realtek: Add quirk for Clevo X370SNW nilfs2: fix sysfs interface lifetime nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread() tty: serial: sh-sci: Fix Rx on RZ/G2L SCI tty: serial: sh-sci: Fix transmit end interrupt handler iio: dac: cio-dac: Fix max DAC write value check for 12-bit USB: serial: option: add Quectel RM500U-CN modem USB: serial: option: add Telit FE990 compositions USB: serial: cp210x: add Silicon Labs IFS-USB-DATACABLE IDs gpio: davinci: Add irq chip flag to skip set wake ipv6: Fix an uninit variable access bug in __ip6_make_skb() sctp: check send stream number after wait_for_sndbuf net: don't let netpoll invoke NAPI if in xmit context icmp: guard against too small mtu wifi: mac80211: fix invalid drv_sta_pre_rcu_remove calls for non-uploaded sta pwm: cros-ec: Explicitly set .polarity in .get_state() NFSv4: Fix hangs when recovering open state after a server reboot NFSv4: Check the return value of update_open_stateid() NFSv4: Convert struct nfs4_state to use refcount_t pinctrl: amd: Disable and mask interrupts on resume pinctrl: amd: disable and mask interrupts on probe pinctrl: amd: Use irqchip template pinctrl: Added IRQF_SHARED flag for amd-pinctrl driver Revert "dm thin: fix deadlock when swapping to thin device" Linux 4.19.280 cgroup: Add missing cpus_read_lock() to cgroup_attach_task_all() cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock cgroup/cpuset: Change cpuset_rwsem and hotplug lock order net: sched: cbq: dont intepret cls results when asked to drop gfs2: Always check inode size of inline inodes firmware: arm_scmi: Fix device node validation for mailbox transport ext4: fix kernel BUG in 'ext4_write_inline_data_end()' usb: host: ohci-pxa27x: Fix and & vs | typo s390/uaccess: add missing earlyclobber annotations to __clear_user() drm/etnaviv: fix reference leak when mmaping imported buffer ALSA: usb-audio: Fix regression on detection of Roland VS-100 ALSA: hda/conexant: Partial revert of a quirk for Lenovo pinctrl: at91-pio4: fix domain name assignment xen/netback: don't do grant copy across page boundary cifs: fix DFS traversal oops without CONFIG_CIFS_DFS_UPCALL cifs: prevent infinite recursion in CIFSGetDFSRefer() Input: focaltech - use explicitly signed char type Input: alps - fix compatibility with -funsigned-char net: mvneta: make tx buffer array agnostic net: dsa: mv88e6xxx: Enable IGMP snooping on user ports only i40e: fix registers dump after run ethtool adapter self test can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write scsi: megaraid_sas: Fix crash after a double completion ca8210: Fix unsigned mac_len comparison with zero in ca8210_skb_tx() fbdev: au1200fb: Fix potential divide by zero fbdev: lxfb: Fix potential divide by zero fbdev: intelfb: Fix potential divide by zero fbdev: nvidia: Fix potential divide by zero sched_getaffinity: don't assume 'cpumask_size()' is fully initialized fbdev: tgafb: Fix potential divide by zero ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() ALSA: asihpi: check pao in control_message() md: avoid signed overflow in slot_store() bus: imx-weim: fix branch condition evaluates to a garbage value ocfs2: fix data corruption after failed write tun: avoid double free in tun_free_netdev sched/fair: Sanitize vruntime of entity being migrated sched/fair: sanitize vruntime of entity being placed dm crypt: add cond_resched() to dmcrypt_write() dm stats: check for and propagate alloc_percpu failure i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer() nilfs2: fix kernel-infoleak in nilfs_ioctl_wrap_copy() usb: chipidea: core: fix possible concurrent when switch role usb: chipdea: core: fix return -EINVAL if request role is the same with current role dm thin: fix deadlock when swapping to thin device igb: revert rtnl_lock() that causes deadlock usb: gadget: u_audio: don't let userspace block driver unbind scsi: core: Add BLIST_SKIP_VPD_PAGES for SKhynix H28U74301AMR cifs: empty interface list when server doesn't support query interfaces sh: sanitize the flags on sigreturn net: usb: qmi_wwan: add Telit 0x1080 composition net: usb: cdc_mbim: avoid altsetting toggling for Telit FE990 scsi: ufs: core: Add soft dependency on governor_simpleondemand scsi: target: iscsi: Fix an error message in iscsi_check_key() m68k: Only force 030 bus error if PC not in exception table ca8210: fix mac_len negative array access riscv: Bump COMMAND_LINE_SIZE value to 1024 thunderbolt: Use const qualifier for `ring_interrupt_index` uas: Add US_FL_NO_REPORT_OPCODES for JMicron JMS583Gen 2 hwmon (it87): Fix voltage scaling for chips with 10.9mV ADCs Bluetooth: btsdio: fix use after free bug in btsdio_remove due to unfinished work Bluetooth: btqcomsmd: Fix command timeout after setting BD address net: mdio: thunder: Add missing fwnode_handle_put() hvc/xen: prevent concurrent accesses to the shared ring net/sonic: use dma_mapping_error() for error check erspan: do not use skb_mac_header() in ndo_start_xmit() atm: idt77252: fix kmemleak when rmmod idt77252 net/mlx5: Read the TC mapping of all priorities on ETS query bpf: Adjust insufficient default bpf_jit_limit net/ps3_gelic_net: Use dma_mapping_error net/ps3_gelic_net: Fix RX sk_buff length net: qcom/emac: Fix use after free bug in emac_remove due to race condition xirc2ps_cs: Fix use after free bug in xirc2ps_detach qed/qed_sriov: guard against NULL derefs from qed_iov_get_vf_info net: usb: smsc95xx: Limit packet length to skb->len scsi: scsi_dh_alua: Fix memleak for 'qdata' in alua_activate() i2c: imx-lpi2c: check only for enabled interrupt flags igbvf: Regard vf reset nack as success intel/igbvf: free irq on the error path in igbvf_request_msix() iavf: fix inverted Rx hash condition leading to disabled hash iavf: diet and reformat intel-ethernet: rename i40evf to iavf i40evf: Change a VF mac without reloading the VF driver power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Conflicts: kernel/cgroup/cpuset.c Change-Id: Ic09017614f20bff94eb0b913bb7fb5b9656dc272
488 lines
14 KiB
C
488 lines
14 KiB
C
/*
|
|
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
|
* operating system. INET is implemented using the BSD Socket
|
|
* interface as the means of communication with the user level.
|
|
*
|
|
* Definitions for the UDP module.
|
|
*
|
|
* Version: @(#)udp.h 1.0.2 05/07/93
|
|
*
|
|
* Authors: Ross Biro
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
*
|
|
* Fixes:
|
|
* Alan Cox : Turned on udp checksums. I don't want to
|
|
* chase 'memory corruption' bugs that aren't!
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
#ifndef _UDP_H
|
|
#define _UDP_H
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/bug.h>
|
|
#include <net/inet_sock.h>
|
|
#include <net/sock.h>
|
|
#include <net/snmp.h>
|
|
#include <net/ip.h>
|
|
#include <linux/ipv6.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/poll.h>
|
|
|
|
/**
|
|
* struct udp_skb_cb - UDP(-Lite) private variables
|
|
*
|
|
* @header: private variables used by IPv4/IPv6
|
|
* @cscov: checksum coverage length (UDP-Lite only)
|
|
* @partial_cov: if set indicates partial csum coverage
|
|
*/
|
|
struct udp_skb_cb {
|
|
union {
|
|
struct inet_skb_parm h4;
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
struct inet6_skb_parm h6;
|
|
#endif
|
|
} header;
|
|
__u16 cscov;
|
|
__u8 partial_cov;
|
|
};
|
|
#define UDP_SKB_CB(__skb) ((struct udp_skb_cb *)((__skb)->cb))
|
|
|
|
/**
|
|
* struct udp_hslot - UDP hash slot
|
|
*
|
|
* @head: head of list of sockets
|
|
* @count: number of sockets in 'head' list
|
|
* @lock: spinlock protecting changes to head/count
|
|
*/
|
|
struct udp_hslot {
|
|
struct hlist_head head;
|
|
int count;
|
|
spinlock_t lock;
|
|
} __attribute__((aligned(2 * sizeof(long))));
|
|
|
|
/**
|
|
* 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)
|
|
* @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 *hash2;
|
|
unsigned int mask;
|
|
unsigned int log;
|
|
};
|
|
extern struct udp_table udp_table;
|
|
void udp_table_init(struct udp_table *, const char *);
|
|
static inline struct udp_hslot *udp_hashslot(struct udp_table *table,
|
|
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];
|
|
}
|
|
|
|
extern struct proto udp_prot;
|
|
|
|
extern atomic_long_t udp_memory_allocated;
|
|
|
|
/* sysctl variables for udp */
|
|
extern long sysctl_udp_mem[3];
|
|
extern int sysctl_udp_rmem_min;
|
|
extern int sysctl_udp_wmem_min;
|
|
|
|
struct sk_buff;
|
|
|
|
/*
|
|
* Generic checksumming routines for UDP(-Lite) v4 and v6
|
|
*/
|
|
static inline __sum16 __udp_lib_checksum_complete(struct sk_buff *skb)
|
|
{
|
|
return (UDP_SKB_CB(skb)->cscov == skb->len ?
|
|
__skb_checksum_complete(skb) :
|
|
__skb_checksum_complete_head(skb, UDP_SKB_CB(skb)->cscov));
|
|
}
|
|
|
|
static inline int udp_lib_checksum_complete(struct sk_buff *skb)
|
|
{
|
|
return !skb_csum_unnecessary(skb) &&
|
|
__udp_lib_checksum_complete(skb);
|
|
}
|
|
|
|
/**
|
|
* udp_csum_outgoing - compute UDPv4/v6 checksum over fragments
|
|
* @sk: socket we are writing to
|
|
* @skb: sk_buff containing the filled-in UDP header
|
|
* (checksum field must be zeroed out)
|
|
*/
|
|
static inline __wsum udp_csum_outgoing(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
__wsum csum = csum_partial(skb_transport_header(skb),
|
|
sizeof(struct udphdr), 0);
|
|
skb_queue_walk(&sk->sk_write_queue, skb) {
|
|
csum = csum_add(csum, skb->csum);
|
|
}
|
|
return csum;
|
|
}
|
|
|
|
static inline __wsum udp_csum(struct sk_buff *skb)
|
|
{
|
|
__wsum csum = csum_partial(skb_transport_header(skb),
|
|
sizeof(struct udphdr), skb->csum);
|
|
|
|
for (skb = skb_shinfo(skb)->frag_list; skb; skb = skb->next) {
|
|
csum = csum_add(csum, skb->csum);
|
|
}
|
|
return csum;
|
|
}
|
|
|
|
static inline __sum16 udp_v4_check(int len, __be32 saddr,
|
|
__be32 daddr, __wsum base)
|
|
{
|
|
return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
|
|
}
|
|
|
|
void udp_set_csum(bool nocheck, struct sk_buff *skb,
|
|
__be32 saddr, __be32 daddr, int len);
|
|
|
|
static inline void udp_csum_pull_header(struct sk_buff *skb)
|
|
{
|
|
if (!skb->csum_valid && skb->ip_summed == CHECKSUM_NONE)
|
|
skb->csum = csum_partial(skb->data, sizeof(struct udphdr),
|
|
skb->csum);
|
|
skb_pull_rcsum(skb, sizeof(struct udphdr));
|
|
UDP_SKB_CB(skb)->cscov -= sizeof(struct udphdr);
|
|
}
|
|
|
|
typedef struct sock *(*udp_lookup_t)(struct sk_buff *skb, __be16 sport,
|
|
__be16 dport);
|
|
|
|
struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb,
|
|
struct udphdr *uh, udp_lookup_t lookup);
|
|
int udp_gro_complete(struct sk_buff *skb, int nhoff, udp_lookup_t lookup);
|
|
|
|
struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
|
|
netdev_features_t features);
|
|
|
|
static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb)
|
|
{
|
|
struct udphdr *uh;
|
|
unsigned int hlen, off;
|
|
|
|
off = skb_gro_offset(skb);
|
|
hlen = off + sizeof(*uh);
|
|
uh = skb_gro_header_fast(skb, off);
|
|
if (skb_gro_header_hard(skb, hlen))
|
|
uh = skb_gro_header_slow(skb, hlen, off);
|
|
|
|
return uh;
|
|
}
|
|
|
|
/* hash routines shared between UDPv4/6 and UDP-Litev4/6 */
|
|
static inline int udp_lib_hash(struct sock *sk)
|
|
{
|
|
BUG();
|
|
return 0;
|
|
}
|
|
|
|
void udp_lib_unhash(struct sock *sk);
|
|
void udp_lib_rehash(struct sock *sk, u16 new_hash);
|
|
|
|
static inline void udp_lib_close(struct sock *sk, long timeout)
|
|
{
|
|
sk_common_release(sk);
|
|
}
|
|
|
|
int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
|
unsigned int hash2_nulladdr);
|
|
|
|
u32 udp_flow_hashrnd(void);
|
|
|
|
static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
|
|
int min, int max, bool use_eth)
|
|
{
|
|
u32 hash;
|
|
|
|
if (min >= max) {
|
|
/* Use default range */
|
|
inet_get_local_port_range(net, &min, &max);
|
|
}
|
|
|
|
hash = skb_get_hash(skb);
|
|
if (unlikely(!hash)) {
|
|
if (use_eth) {
|
|
/* Can't find a normal hash, caller has indicated an
|
|
* Ethernet packet so use that to compute a hash.
|
|
*/
|
|
hash = jhash(skb->data, 2 * ETH_ALEN,
|
|
(__force u32) skb->protocol);
|
|
} else {
|
|
/* Can't derive any sort of hash for the packet, set
|
|
* to some consistent random value.
|
|
*/
|
|
hash = udp_flow_hashrnd();
|
|
}
|
|
}
|
|
|
|
/* Since this is being sent on the wire obfuscate hash a bit
|
|
* to minimize possbility that any useful information to an
|
|
* attacker is leaked. Only upper 16 bits are relevant in the
|
|
* computation for 16 bit port value.
|
|
*/
|
|
hash ^= hash << 16;
|
|
|
|
return htons((((u64) hash * (max - min)) >> 32) + min);
|
|
}
|
|
|
|
static inline int udp_rqueue_get(struct sock *sk)
|
|
{
|
|
return sk_rmem_alloc_get(sk) - READ_ONCE(udp_sk(sk)->forward_deficit);
|
|
}
|
|
|
|
/* net/ipv4/udp.c */
|
|
void udp_destruct_common(struct sock *sk);
|
|
void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len);
|
|
int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb);
|
|
void udp_skb_destructor(struct sock *sk, struct sk_buff *skb);
|
|
struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
|
|
int noblock, int *peeked, int *off, int *err);
|
|
static inline struct sk_buff *skb_recv_udp(struct sock *sk, unsigned int flags,
|
|
int noblock, int *err)
|
|
{
|
|
int peeked, off = 0;
|
|
|
|
return __skb_recv_udp(sk, flags, noblock, &peeked, &off, err);
|
|
}
|
|
|
|
int udp_v4_early_demux(struct sk_buff *skb);
|
|
bool udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst);
|
|
int udp_get_port(struct sock *sk, unsigned short snum,
|
|
int (*saddr_cmp)(const struct sock *,
|
|
const struct sock *));
|
|
void udp_err(struct sk_buff *, u32);
|
|
int udp_abort(struct sock *sk, int err);
|
|
int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
|
|
int udp_push_pending_frames(struct sock *sk);
|
|
void udp_flush_pending_frames(struct sock *sk);
|
|
int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size);
|
|
void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst);
|
|
int udp_rcv(struct sk_buff *skb);
|
|
int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
|
|
int udp_init_sock(struct sock *sk);
|
|
int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
|
|
int __udp_disconnect(struct sock *sk, int flags);
|
|
int udp_disconnect(struct sock *sk, int flags);
|
|
__poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait);
|
|
struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb,
|
|
netdev_features_t features,
|
|
bool is_ipv6);
|
|
int udp_lib_getsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, int __user *optlen);
|
|
int udp_lib_setsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, unsigned int optlen,
|
|
int (*push_pending_frames)(struct sock *));
|
|
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
|
|
__be32 daddr, __be16 dport, int dif);
|
|
struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
|
|
__be32 daddr, __be16 dport, int dif, int sdif,
|
|
struct udp_table *tbl, struct sk_buff *skb);
|
|
struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
|
|
__be16 sport, __be16 dport);
|
|
struct sock *udp6_lib_lookup(struct net *net,
|
|
const struct in6_addr *saddr, __be16 sport,
|
|
const struct in6_addr *daddr, __be16 dport,
|
|
int dif);
|
|
struct sock *__udp6_lib_lookup(struct net *net,
|
|
const struct in6_addr *saddr, __be16 sport,
|
|
const struct in6_addr *daddr, __be16 dport,
|
|
int dif, int sdif, struct udp_table *tbl,
|
|
struct sk_buff *skb);
|
|
struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
|
|
__be16 sport, __be16 dport);
|
|
|
|
/* UDP uses skb->dev_scratch to cache as much information as possible and avoid
|
|
* possibly multiple cache miss on dequeue()
|
|
*/
|
|
struct udp_dev_scratch {
|
|
/* skb->truesize and the stateless bit are embedded in a single field;
|
|
* do not use a bitfield since the compiler emits better/smaller code
|
|
* this way
|
|
*/
|
|
u32 _tsize_state;
|
|
|
|
#if BITS_PER_LONG == 64
|
|
/* len and the bit needed to compute skb_csum_unnecessary
|
|
* will be on cold cache lines at recvmsg time.
|
|
* skb->len can be stored on 16 bits since the udp header has been
|
|
* already validated and pulled.
|
|
*/
|
|
u16 len;
|
|
bool is_linear;
|
|
bool csum_unnecessary;
|
|
#endif
|
|
};
|
|
|
|
static inline struct udp_dev_scratch *udp_skb_scratch(struct sk_buff *skb)
|
|
{
|
|
return (struct udp_dev_scratch *)&skb->dev_scratch;
|
|
}
|
|
|
|
#if BITS_PER_LONG == 64
|
|
static inline unsigned int udp_skb_len(struct sk_buff *skb)
|
|
{
|
|
return udp_skb_scratch(skb)->len;
|
|
}
|
|
|
|
static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
|
|
{
|
|
return udp_skb_scratch(skb)->csum_unnecessary;
|
|
}
|
|
|
|
static inline bool udp_skb_is_linear(struct sk_buff *skb)
|
|
{
|
|
return udp_skb_scratch(skb)->is_linear;
|
|
}
|
|
|
|
#else
|
|
static inline unsigned int udp_skb_len(struct sk_buff *skb)
|
|
{
|
|
return skb->len;
|
|
}
|
|
|
|
static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
|
|
{
|
|
return skb_csum_unnecessary(skb);
|
|
}
|
|
|
|
static inline bool udp_skb_is_linear(struct sk_buff *skb)
|
|
{
|
|
return !skb_is_nonlinear(skb);
|
|
}
|
|
#endif
|
|
|
|
static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
|
|
struct iov_iter *to)
|
|
{
|
|
int n;
|
|
|
|
n = copy_to_iter(skb->data + off, len, to);
|
|
if (n == len)
|
|
return 0;
|
|
|
|
iov_iter_revert(to, n);
|
|
return -EFAULT;
|
|
}
|
|
|
|
/*
|
|
* SNMP statistics for UDP and UDP-Lite
|
|
*/
|
|
#define UDP_INC_STATS(net, field, is_udplite) do { \
|
|
if (is_udplite) SNMP_INC_STATS((net)->mib.udplite_statistics, field); \
|
|
else SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0)
|
|
#define __UDP_INC_STATS(net, field, is_udplite) do { \
|
|
if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_statistics, field); \
|
|
else __SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0)
|
|
|
|
#define __UDP6_INC_STATS(net, field, is_udplite) do { \
|
|
if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_stats_in6, field);\
|
|
else __SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \
|
|
} while(0)
|
|
#define UDP6_INC_STATS(net, field, __lite) do { \
|
|
if (__lite) SNMP_INC_STATS((net)->mib.udplite_stats_in6, field); \
|
|
else SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \
|
|
} while(0)
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
#define __UDPX_MIB(sk, ipv4) \
|
|
({ \
|
|
ipv4 ? (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \
|
|
sock_net(sk)->mib.udp_statistics) : \
|
|
(IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_stats_in6 : \
|
|
sock_net(sk)->mib.udp_stats_in6); \
|
|
})
|
|
#else
|
|
#define __UDPX_MIB(sk, ipv4) \
|
|
({ \
|
|
IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \
|
|
sock_net(sk)->mib.udp_statistics; \
|
|
})
|
|
#endif
|
|
|
|
#define __UDPX_INC_STATS(sk, field) \
|
|
__SNMP_INC_STATS(__UDPX_MIB(sk, (sk)->sk_family == AF_INET), field)
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
struct udp_seq_afinfo {
|
|
sa_family_t family;
|
|
struct udp_table *udp_table;
|
|
};
|
|
|
|
struct udp_iter_state {
|
|
struct seq_net_private p;
|
|
int bucket;
|
|
};
|
|
|
|
void *udp_seq_start(struct seq_file *seq, loff_t *pos);
|
|
void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos);
|
|
void udp_seq_stop(struct seq_file *seq, void *v);
|
|
|
|
extern const struct seq_operations udp_seq_ops;
|
|
extern const struct seq_operations udp6_seq_ops;
|
|
|
|
int udp4_proc_init(void);
|
|
void udp4_proc_exit(void);
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
int udpv4_offload_init(void);
|
|
|
|
void udp_init(void);
|
|
|
|
void udp_encap_enable(void);
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
void udpv6_encap_enable(void);
|
|
#endif
|
|
|
|
static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
|
|
struct sk_buff *skb, bool ipv4)
|
|
{
|
|
netdev_features_t features = NETIF_F_SG;
|
|
struct sk_buff *segs;
|
|
|
|
/* Avoid csum recalculation by skb_segment unless userspace explicitly
|
|
* asks for the final checksum values
|
|
*/
|
|
if (!inet_get_convert_csum(sk))
|
|
features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
|
|
|
|
/* the GSO CB lays after the UDP one, no need to save and restore any
|
|
* CB fragment
|
|
*/
|
|
segs = __skb_gso_segment(skb, features, false);
|
|
if (unlikely(IS_ERR_OR_NULL(segs))) {
|
|
int segs_nr = skb_shinfo(skb)->gso_segs;
|
|
|
|
atomic_add(segs_nr, &sk->sk_drops);
|
|
SNMP_ADD_STATS(__UDPX_MIB(sk, ipv4), UDP_MIB_INERRORS, segs_nr);
|
|
kfree_skb(skb);
|
|
return NULL;
|
|
}
|
|
|
|
consume_skb(skb);
|
|
return segs;
|
|
}
|
|
|
|
#endif /* _UDP_H */
|