mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
* refs/heads/tmp-f960b38: Linux 4.14.159 of: unittest: fix memory leak in attach_node_and_children raid5: need to set STRIPE_HANDLE for batch head gpiolib: acpi: Add Terra Pad 1061 to the run_edge_events_on_boot_blacklist kernel/module.c: wakeup processes in module_wq on module unload gfs2: fix glock reference problem in gfs2_trans_remove_revoke net/mlx5e: Fix SFF 8472 eeprom length sunrpc: fix crash when cache_head become valid before update workqueue: Fix missing kfree(rescuer) in destroy_workqueue() blk-mq: make sure that line break can be printed mfd: rk808: Fix RK818 ID template ext4: fix a bug in ext4_wait_for_tail_page_commit mm/shmem.c: cast the type of unmap_start to u64 firmware: qcom: scm: Ensure 'a0' status code is treated as signed ext4: work around deleting a file with i_nlink == 0 safely powerpc: Fix vDSO clock_getres() powerpc: Avoid clang warnings around setjmp and longjmp ath10k: fix fw crash by moving chip reset after napi disabled media: vimc: fix component match compare mlxsw: spectrum_router: Refresh nexthop neighbour when it becomes dead power: supply: cpcap-battery: Fix signed counter sample register x86/MCE/AMD: Carve out the MC4_MISC thresholding quirk x86/MCE/AMD: Turn off MC4_MISC thresholding on all family 0x15 models e100: Fix passing zero to 'PTR_ERR' warning in e100_load_ucode_wait drbd: Change drbd_request_detach_interruptible's return type to int scsi: lpfc: Correct code setting non existent bits in sli4 ABORT WQE scsi: lpfc: Cap NPIV vports to 256 omap: pdata-quirks: remove openpandora quirks for mmc3 and wl1251 phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role" iio: adis16480: Add debugfs_reg_access entry xhci: make sure interrupts are restored to correct state xhci: Fix memory leak in xhci_add_in_port() scsi: qla2xxx: Fix message indicating vectors used by driver scsi: qla2xxx: Always check the qla2x00_wait_for_hba_online() return value scsi: qla2xxx: Fix qla24xx_process_bidir_cmd() scsi: qla2xxx: Fix session lookup in qlt_abort_work() scsi: qla2xxx: Fix DMA unmap leak scsi: zfcp: trace channel log even for FCP command responses block: fix single range discard merge reiserfs: fix extended attributes on the root directory ext4: Fix credit estimate for final inode freeing quota: fix livelock in dquot_writeback_dquots ext2: check err when partial != NULL quota: Check that quota is not dirty before release video/hdmi: Fix AVI bar unpack powerpc/xive: Skip ioremap() of ESB pages for LSI interrupts powerpc: Allow flush_icache_range to work across ranges >4GB powerpc/xive: Prevent page fault issues in the machine crash handler powerpc: Allow 64bit VDSO __kernel_sync_dicache to work across ranges >4GB ppdev: fix PPGETTIME/PPSETTIME ioctls ARM: dts: omap3-tao3530: Fix incorrect MMC card detection GPIO polarity mmc: host: omap_hsmmc: add code for special init of wl1251 to get rid of pandora_wl1251_init_card pinctrl: samsung: Fix device node refcount leaks in S3C64xx wakeup controller init pinctrl: samsung: Fix device node refcount leaks in init code pinctrl: samsung: Fix device node refcount leaks in S3C24xx wakeup controller init pinctrl: samsung: Add of_node_put() before return in error path ACPI: PM: Avoid attaching ACPI PM domain to certain devices ACPI: bus: Fix NULL pointer check in acpi_bus_get_private_data() ACPI: OSL: only free map once in osl.c cpufreq: powernv: fix stack bloat and hard limit on number of CPUs PM / devfreq: Lock devfreq in trans_stat_show intel_th: pci: Add Tiger Lake CPU support intel_th: pci: Add Ice Lake CPU support intel_th: Fix a double put_device() in error path cpuidle: Do not unset the driver if it is there already media: cec.h: CEC_OP_REC_FLAG_ values were swapped media: radio: wl1273: fix interrupt masking on release media: bdisp: fix memleak on release s390/mm: properly clear _PAGE_NOEXEC bit when it is not supported ar5523: check NULL before memcpy() in ar5523_cmd() cgroup: pids: use atomic64_t for pids->limit blk-mq: avoid sysfs buffer overflow with too many CPU cores ASoC: Jack: Fix NULL pointer dereference in snd_soc_jack_report workqueue: Fix pwq ref leak in rescuer_thread() workqueue: Fix spurious sanity check failures in destroy_workqueue() dm zoned: reduce overhead of backing device checks hwrng: omap - Fix RNG wait loop timeout watchdog: aspeed: Fix clock behaviour for ast2600 md/raid0: Fix an error message in raid0_make_request() ALSA: hda - Fix pending unsol events at shutdown ovl: relax WARN_ON() on rename to self lib: raid6: fix awk build warnings rtlwifi: rtl8192de: Fix missing enable interrupt flag rtlwifi: rtl8192de: Fix missing callback that tests for hw release of buffer rtlwifi: rtl8192de: Fix missing code to retrieve RX buffer address btrfs: record all roots for rename exchange on a subvol Btrfs: send, skip backreference walking for extents with many references btrfs: Remove btrfs_bio::flags member Btrfs: fix negative subv_writers counter and data space leak after buffered write btrfs: use refcount_inc_not_zero in kill_all_nodes btrfs: check page->mapping when loading free space cache usb: dwc3: ep0: Clear started flag on completion virtio-balloon: fix managed page counts when migrating pages between zones mtd: spear_smi: Fix Write Burst mode tpm: add check after commands attribs tab allocation usb: mon: Fix a deadlock in usbmon between mmap and read usb: core: urb: fix URB structure initialization function USB: adutux: fix interface sanity check USB: serial: io_edgeport: fix epic endpoint lookup USB: idmouse: fix interface sanity checks USB: atm: ueagle-atm: add missing endpoint check iio: humidity: hdc100x: fix IIO_HUMIDITYRELATIVE channel reporting ARM: dts: pandora-common: define wl1251 as child node of mmc3 xhci: handle some XHCI_TRUST_TX_LENGTH quirks cases as default behaviour. xhci: Increase STS_HALT timeout in xhci_suspend() usb: xhci: only set D3hot for pci device staging: gigaset: add endpoint-type sanity check staging: gigaset: fix illegal free on probe errors staging: gigaset: fix general protection fault on probe staging: rtl8712: fix interface sanity check staging: rtl8188eu: fix interface sanity check usb: Allow USB device to be warm reset in suspended state USB: documentation: flags on usb-storage versus UAS USB: uas: heed CAPACITY_HEURISTICS USB: uas: honor flag to avoid CAPACITY16 media: venus: remove invalid compat_ioctl32 handler scsi: qla2xxx: Fix driver unload hang usb: gadget: pch_udc: fix use after free usb: gadget: configfs: Fix missing spin_lock_init() appletalk: Set error code if register_snap_client failed appletalk: Fix potential NULL pointer dereference in unregister_snap_client KVM: x86: fix out-of-bounds write in KVM_GET_EMULATED_CPUID (CVE-2019-19332) ASoC: rsnd: fixup MIX kctrl registration binder: Handle start==NULL in binder_update_page_range() thermal: Fix deadlock in thermal thermal_zone_device_check iomap: Fix pipe page leakage during splicing RDMA/qib: Validate ->show()/store() callbacks before calling them spi: atmel: Fix CS high support crypto: user - fix memory leak in crypto_report crypto: ecdh - fix big endian bug in ECC library crypto: ccp - fix uninitialized list head crypto: af_alg - cast ki_complete ternary op to int crypto: crypto4xx - fix double-free in crypto4xx_destroy_sdr KVM: x86: fix presentation of TSX feature in ARCH_CAPABILITIES KVM: x86: do not modify masked bits of shared MSRs KVM: arm/arm64: vgic: Don't rely on the wrong pending table drm/i810: Prevent underflow in ioctl jbd2: Fix possible overflow in jbd2_log_space_left() kernfs: fix ino wrap-around detection can: slcan: Fix use-after-free Read in slcan_open tty: vt: keyboard: reject invalid keycodes CIFS: Fix SMB2 oplock break processing CIFS: Fix NULL-pointer dereference in smb2_push_mandatory_locks x86/PCI: Avoid AMD FCH XHCI USB PME# from D0 defect Input: Fix memory leak in psxpad_spi_probe coresight: etm4x: Fix input validation for sysfs. Input: goodix - add upside-down quirk for Teclast X89 tablet Input: synaptics-rmi4 - don't increment rmiaddr for SMBus transfers Input: synaptics-rmi4 - re-enable IRQs in f34v7_do_reflash Input: synaptics - switch another X1 Carbon 6 to RMI/SMbus ALSA: hda - Add mute led support for HP ProBook 645 G4 ALSA: pcm: oss: Avoid potential buffer overflows ALSA: hda/realtek - Dell headphone has noise on unmute for ALC236 fuse: verify attributes fuse: verify nlink sched/fair: Scale bandwidth quota and period without losing quota/period ratio precision tcp: exit if nothing to retransmit on RTO timeout net: aquantia: fix RSS table and key sizes media: vimc: fix start stream when link is disabled ARM: dts: sunxi: Fix PMU compatible strings usb: mtu3: fix dbginfo in qmu_tx_zlp_error_handler mlx4: Use snprintf instead of complicated strcpy IB/hfi1: Close VNIC sdma_progress sleep window IB/hfi1: Ignore LNI errors before DC8051 transitions to Polling state mlxsw: spectrum_router: Relax GRE decap matching check firmware: qcom: scm: fix compilation error when disabled media: stkwebcam: Bugfix for wrong return values tty: Don't block on IO when ldisc change is pending nfsd: Return EPERM, not EACCES, in some SETATTR cases MIPS: OCTEON: cvmx_pko_mem_debug8: use oldest forward compatible definition clk: renesas: r8a77995: Correct parent clock of DU powerpc/math-emu: Update macros from GCC pstore/ram: Avoid NULL deref in ftrace merging failure path net/mlx4_core: Fix return codes of unsupported operations dlm: fix invalid cluster name warning ARM: dts: realview: Fix some more duplicate regulator nodes clk: sunxi-ng: h3/h5: Fix CSI_MCLK parent ARM: dts: pxa: clean up USB controller nodes mtd: fix mtd_oobavail() incoherent returned value kbuild: fix single target build for external module modpost: skip ELF local symbols during section mismatch check tcp: fix SNMP TCP timeout under-estimation tcp: fix SNMP under-estimation on failed retransmission tcp: fix off-by-one bug on aborting window-probing socket ARM: dts: realview-pbx: Fix duplicate regulator nodes ARM: dts: mmp2: fix the gpio interrupt cell number net/x25: fix null_x25_address handling net/x25: fix called/calling length calculation in x25_parse_address_block arm64: dts: meson-gxl-khadas-vim: fix GPIO lines names arm64: dts: meson-gxbb-odroidc2: fix GPIO lines names arm64: dts: meson-gxbb-nanopi-k2: fix GPIO lines names arm64: dts: meson-gxl-libretech-cc: fix GPIO lines names ARM: OMAP1/2: fix SoC name printing ASoC: au8540: use 64-bit arithmetic instead of 32-bit nfsd: fix a warning in __cld_pipe_upcall() ARM: debug: enable UART1 for socfpga Cyclone5 dlm: NULL check before kmem_cache_destroy is not needed ARM: dts: sun8i: v3s: Change pinctrl nodes to avoid warning ARM: dts: sun5i: a10s: Fix HDMI output DTC warning ASoC: rsnd: tidyup registering method for rsnd_kctrl_new() lockd: fix decoding of TEST results i2c: imx: don't print error message on probe defer serial: imx: fix error handling in console_setup altera-stapl: check for a null key before strcasecmp'ing it dma-mapping: fix return type of dma_set_max_seg_size() sparc: Correct ctx->saw_frame_pointer logic. f2fs: fix to allow node segment for GC by ioctl path ARM: dts: rockchip: Assign the proper GPIO clocks for rv1108 ARM: dts: rockchip: Fix the PMU interrupt number for rv1108 f2fs: change segment to section in f2fs_ioc_gc_range f2fs: fix count of seg_freed to make sec_freed correct ACPI: fix acpi_find_child_device() invocation in acpi_preset_companion() usb: dwc3: don't log probe deferrals; but do log other error codes usb: dwc3: debugfs: Properly print/set link state for HS dmaengine: dw-dmac: implement dma protection control setting dmaengine: coh901318: Remove unused variable dmaengine: coh901318: Fix a double-lock bug media: cec: report Vendor ID after initialization media: pulse8-cec: return 0 when invalidating the logical address ARM: dts: exynos: Use Samsung SoC specific compatible for DWC2 module rtc: dt-binding: abx80x: fix resistance scale rtc: max8997: Fix the returned value in case of error in 'max8997_rtc_read_alarm()' math-emu/soft-fp.h: (_FP_ROUND_ZERO) cast 0 to void to fix warning net/smc: use after free fix in smc_wr_tx_put_slot() MIPS: OCTEON: octeon-platform: fix typing iomap: sub-block dio needs to zeroout beyond EOF net-next/hinic:fix a bug in set mac address regulator: Fix return value of _set_load() stub clk: rockchip: fix ID of 8ch clock of I2S1 for rk3328 clk: rockchip: fix I2S1 clock gate register for rk3328 mm/vmstat.c: fix NUMA statistics updates Staging: iio: adt7316: Fix i2c data reading, set the data field pinctrl: qcom: ssbi-gpio: fix gpio-hog related boot issues crypto: bcm - fix normal/non key hash algorithm failure crypto: ecc - check for invalid values in the key verification test scsi: zfcp: drop default switch case which might paper over missing case net: dsa: mv88e6xxx: Work around mv886e6161 SERDES missing MII_PHYSID2 MIPS: SiByte: Enable ZONE_DMA32 for LittleSur dlm: fix missing idr_destroy for recover_idr ARM: dts: rockchip: Fix rk3288-rock2 vcc_flash name clk: rockchip: fix rk3188 sclk_mac_lbtest parameter ordering clk: rockchip: fix rk3188 sclk_smc gate data i40e: don't restart nway if autoneg not supported rtc: s3c-rtc: Avoid using broken ALMYEAR register net: ethernet: ti: cpts: correct debug for expired txq skb extcon: max8997: Fix lack of path setting in USB device mode dlm: fix possible call to kfree() for non-initialized pointer clk: sunxi-ng: a64: Fix gate bit of DSI DPHY net/mlx5: Release resource on error flow ARM: 8813/1: Make aligned 2-byte getuser()/putuser() atomic on ARMv6+ iwlwifi: mvm: Send non offchannel traffic via AP sta iwlwifi: mvm: synchronize TID queue removal cxgb4vf: fix memleak in mac_hlist initialization serial: core: Allow processing sysrq at port unlock time i2c: core: fix use after free in of_i2c_notify net: ep93xx_eth: fix mismatch of request_mem_region in remove rsxx: add missed destroy_workqueue calls in remove ALSA: pcm: Fix stream lock usage in snd_pcm_period_elapsed() sched/core: Avoid spurious lock dependencies Input: cyttsp4_core - fix use after free bug xfrm: release device reference for invalid state NFC: nxp-nci: Fix NULL pointer dereference after I2C communication error audit_get_nd(): don't unlock parent too early exportfs_decode_fh(): negative pinned may become positive without the parent locked iwlwifi: pcie: don't consider IV len in A-MSDU RDMA/hns: Correct the value of HNS_ROCE_HEM_CHUNK_LEN autofs: fix a leak in autofs_expire_indirect() serial: ifx6x60: add missed pm_runtime_disable serial: serial_core: Perform NULL checks for break_ctl ops serial: pl011: Fix DMA ->flush_buffer() tty: serial: msm_serial: Fix flow control tty: serial: fsl_lpuart: use the sg count from dma_map_sg usb: gadget: u_serial: add missing port entry locking arm64: tegra: Fix 'active-low' warning for Jetson TX1 regulator rsi: release skb if rsi_prepare_beacon fails ANDROID: staging: android: ion: Fix build when CONFIG_ION_SYSTEM_HEAP=n ANDROID: staging: android: ion: Expose total heap and pool sizes via sysfs UPSTREAM: include/linux/slab.h: fix sparse warning in kmalloc_type() UPSTREAM: mm, slab: shorten kmalloc cache names for large sizes UPSTREAM: mm, proc: add KReclaimable to /proc/meminfo BACKPORT: mm: rename and change semantics of nr_indirectly_reclaimable_bytes UPSTREAM: dcache: allocate external names from reclaimable kmalloc caches BACKPORT: mm, slab/slub: introduce kmalloc-reclaimable caches UPSTREAM: mm, slab: combine kmalloc_caches and kmalloc_dma_caches ANDROID: kbuild: disable SCS by default in allmodconfig ANDROID: arm64: cuttlefish_defconfig: enable LTO, CFI, and SCS BACKPORT: FROMLIST: arm64: implement Shadow Call Stack FROMLIST: arm64: disable SCS for hypervisor code BACKPORT: FROMLIST: arm64: vdso: disable Shadow Call Stack FROMLIST: arm64: preserve x18 when CPU is suspended FROMLIST: arm64: reserve x18 from general allocation with SCS FROMLIST: arm64: disable function graph tracing with SCS FROMLIST: scs: add support for stack usage debugging FROMLIST: scs: add accounting FROMLIST: add support for Clang's Shadow Call Stack (SCS) FROMLIST: arm64: kernel: avoid x18 in __cpu_soft_restart FROMLIST: arm64: kvm: stop treating register x18 as caller save FROMLIST: arm64/lib: copy_page: avoid x18 register in assembler code FROMLIST: arm64: mm: avoid x18 in idmap_kpti_install_ng_mappings ANDROID: use non-canonical CFI jump tables ANDROID: arm64: add __nocfi to __apply_alternatives ANDROID: arm64: add __pa_function ANDROID: arm64: allow ThinLTO to be selected ANDROID: soc/tegra: disable ARCH_TEGRA_210_SOC with LTO FROMLIST: arm64: fix alternatives with LLVM's integrated assembler ANDROID: irqchip/gic-v3: rename gic_of_init to work around a ThinLTO+CFI bug ANDROID: kbuild: limit LTO inlining ANDROID: kbuild: merge module sections with LTO ANDROID: init: ensure initcall ordering with LTO Revert "ANDROID: HACK: init: ensure initcall ordering with LTO" ANDROID: add support for ThinLTO ANDROID: Switch to LLD ANDROID: clang: update to 10.0.1 ANDROID: arm64: add atomic_ll_sc.o to obj-y if using lld ANDROID: enable ARM64_ERRATUM_843419 by default with LTO_CLANG ANDROID: kbuild: allow lld to be used with CONFIG_LTO_CLANG ANDROID: Makefile: set -Qunused-arguments sooner BACKPORT: FROMLIST: Makefile: lld: tell clang to use lld BACKPORT: FROMLIST: Makefile: lld: set -O2 linker flag when linking with LLD ANDROID: scripts/Kbuild: add ld-name support for ld.lld UPSTREAM: bpf: permit multiple bpf attachments for a single perf event UPSTREAM: bpf: use the same condition in perf event set/free bpf handler UPSTREAM: bpf: multi program support for cgroup+bpf BACKPORT: serdev: make synchronous write return bytes written UPSTREAM: gnss: serial: fix synchronous write timeout UPSTREAM: gnss: fix potential error pointer dereference BACKPORT: gnss: add receiver type support UPSTREAM: dt-bindings: add generic gnss binding UPSTREAM: gnss: add generic serial driver ANDROID: cuttlefish_defconfig: Enable CONFIG_SERIAL_DEV_BUS ANDROID: cuttlefish_defconfig: Enable CONFIG_GNSS BACKPORT: gnss: add GNSS receiver subsystem UPSTREAM: arm64: Validate tagged addresses in access_ok() called from kernel threads BACKPORT: ARM: 8905/1: Emit __gnu_mcount_nc when using Clang 10.0.0 or newer fs/lock: skip lock owner pid translation in case we are in init_pid_ns f2fs: stop GC when the victim becomes fully valid f2fs: expose main_blkaddr in sysfs f2fs: choose hardlimit when softlimit is larger than hardlimit in f2fs_statfs_project() f2fs: Fix deadlock in f2fs_gc() context during atomic files handling f2fs: show f2fs instance in printk_ratelimited f2fs: fix potential overflow f2fs: fix to update dir's i_pino during cross_rename f2fs: support aligned pinned file f2fs: avoid kernel panic on corruption test f2fs: fix wrong description in document f2fs: cache global IPU bio f2fs: fix to avoid memory leakage in f2fs_listxattr f2fs: check total_segments from devices in raw_super f2fs: update multi-dev metadata in resize_fs f2fs: mark recovery flag correctly in read_raw_super_block() f2fs: fix to update time in lazytime mode vfs: don't allow writes to swap files mm: set S_SWAPFILE on blockdev swap devices Conflicts: drivers/Makefile drivers/staging/android/ion/ion.c drivers/staging/android/ion/ion.h drivers/staging/android/ion/ion_page_pool.c drivers/usb/dwc3/core.c drivers/usb/dwc3/debugfs.c drivers/usb/dwc3/ep0.c fs/f2fs/data.c include/linux/mmzone.h mm/vmstat.c Discarded below patches, as usb patches not applicable and block patch causing stability issues: usb: dwc3: ep0: Clear started flag on completion usb: dwc3: don't log probe deferrals; but do log other error codes block: fix single range discard merge Fixed build errors in below files: drivers/gpu/msm/kgsl_pool.c drivers/staging/android/ion/ion_page_pool.c kernel/taskstats.c Fixed bootup issue in: arch/arm64/mm/proc.s Change-Id: I0a16824c251c14c63af78f9cfd9ede5e82c427fc Signed-off-by: Srinivasarao P <spathi@codeaurora.org> Signed-off-by: Blagovest Kolenichev <bkolenichev@codeaurora.org>
759 lines
22 KiB
C
759 lines
22 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.
|
|
*
|
|
* Implementation of the Transmission Control Protocol(TCP).
|
|
*
|
|
* Authors: Ross Biro
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
* Mark Evans, <evansmp@uhura.aston.ac.uk>
|
|
* Corey Minyard <wf-rch!minyard@relay.EU.net>
|
|
* Florian La Roche, <flla@stud.uni-sb.de>
|
|
* Charles Hedrick, <hedrick@klinzhai.rutgers.edu>
|
|
* Linus Torvalds, <torvalds@cs.helsinki.fi>
|
|
* Alan Cox, <gw4pts@gw4pts.ampr.org>
|
|
* Matthew Dillon, <dillon@apollo.west.oic.com>
|
|
* Arnt Gulbrandsen, <agulbra@nvg.unit.no>
|
|
* Jorge Cwik, <jorge@laser.satlink.net>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/gfp.h>
|
|
#include <net/tcp.h>
|
|
|
|
int sysctl_tcp_thin_linear_timeouts __read_mostly;
|
|
|
|
static void set_tcp_default(void)
|
|
{
|
|
sysctl_tcp_delack_seg = TCP_DELACK_SEG;
|
|
}
|
|
|
|
/*sysctl handler for tcp_ack realted master control */
|
|
int tcp_proc_delayed_ack_control(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *length,
|
|
loff_t *ppos)
|
|
{
|
|
int ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
|
|
|
|
/* The ret value will be 0 if the input validation is successful
|
|
* and the values are written to sysctl table. If not, the stack
|
|
* will continue to work with currently configured values
|
|
*/
|
|
return ret;
|
|
}
|
|
|
|
/*sysctl handler for tcp_ack realted master control */
|
|
int tcp_use_userconfig_sysctl_handler(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *length,
|
|
loff_t *ppos)
|
|
{
|
|
int ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
|
|
|
|
if (write && ret == 0) {
|
|
if (!sysctl_tcp_use_userconfig)
|
|
set_tcp_default();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* tcp_write_err() - close socket and save error info
|
|
* @sk: The socket the error has appeared on.
|
|
*
|
|
* Returns: Nothing (void)
|
|
*/
|
|
static void tcp_write_err(struct sock *sk)
|
|
{
|
|
sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
|
|
sk->sk_error_report(sk);
|
|
|
|
tcp_write_queue_purge(sk);
|
|
tcp_done(sk);
|
|
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT);
|
|
}
|
|
|
|
/**
|
|
* tcp_out_of_resources() - Close socket if out of resources
|
|
* @sk: pointer to current socket
|
|
* @do_reset: send a last packet with reset flag
|
|
*
|
|
* Do not allow orphaned sockets to eat all our resources.
|
|
* This is direct violation of TCP specs, but it is required
|
|
* to prevent DoS attacks. It is called when a retransmission timeout
|
|
* or zero probe timeout occurs on orphaned socket.
|
|
*
|
|
* Also close if our net namespace is exiting; in that case there is no
|
|
* hope of ever communicating again since all netns interfaces are already
|
|
* down (or about to be down), and we need to release our dst references,
|
|
* which have been moved to the netns loopback interface, so the namespace
|
|
* can finish exiting. This condition is only possible if we are a kernel
|
|
* socket, as those do not hold references to the namespace.
|
|
*
|
|
* Criteria is still not confirmed experimentally and may change.
|
|
* We kill the socket, if:
|
|
* 1. If number of orphaned sockets exceeds an administratively configured
|
|
* limit.
|
|
* 2. If we have strong memory pressure.
|
|
* 3. If our net namespace is exiting.
|
|
*/
|
|
static int tcp_out_of_resources(struct sock *sk, bool do_reset)
|
|
{
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
int shift = 0;
|
|
|
|
/* If peer does not open window for long time, or did not transmit
|
|
* anything for long time, penalize it. */
|
|
if ((s32)(tcp_jiffies32 - tp->lsndtime) > 2*TCP_RTO_MAX || !do_reset)
|
|
shift++;
|
|
|
|
/* If some dubious ICMP arrived, penalize even more. */
|
|
if (sk->sk_err_soft)
|
|
shift++;
|
|
|
|
if (tcp_check_oom(sk, shift)) {
|
|
/* Catch exceptional cases, when connection requires reset.
|
|
* 1. Last segment was sent recently. */
|
|
if ((s32)(tcp_jiffies32 - tp->lsndtime) <= TCP_TIMEWAIT_LEN ||
|
|
/* 2. Window is closed. */
|
|
(!tp->snd_wnd && !tp->packets_out))
|
|
do_reset = true;
|
|
if (do_reset)
|
|
tcp_send_active_reset(sk, GFP_ATOMIC);
|
|
tcp_done(sk);
|
|
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
|
|
return 1;
|
|
}
|
|
|
|
if (!check_net(sock_net(sk))) {
|
|
/* Not possible to send reset; just close */
|
|
tcp_done(sk);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* tcp_orphan_retries() - Returns maximal number of retries on an orphaned socket
|
|
* @sk: Pointer to the current socket.
|
|
* @alive: bool, socket alive state
|
|
*/
|
|
static int tcp_orphan_retries(struct sock *sk, bool alive)
|
|
{
|
|
int retries = sock_net(sk)->ipv4.sysctl_tcp_orphan_retries; /* May be zero. */
|
|
|
|
/* We know from an ICMP that something is wrong. */
|
|
if (sk->sk_err_soft && !alive)
|
|
retries = 0;
|
|
|
|
/* However, if socket sent something recently, select some safe
|
|
* number of retries. 8 corresponds to >100 seconds with minimal
|
|
* RTO of 200msec. */
|
|
if (retries == 0 && alive)
|
|
retries = 8;
|
|
return retries;
|
|
}
|
|
|
|
static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
|
|
{
|
|
struct net *net = sock_net(sk);
|
|
|
|
/* Black hole detection */
|
|
if (net->ipv4.sysctl_tcp_mtu_probing) {
|
|
if (!icsk->icsk_mtup.enabled) {
|
|
icsk->icsk_mtup.enabled = 1;
|
|
icsk->icsk_mtup.probe_timestamp = tcp_jiffies32;
|
|
tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
|
|
} else {
|
|
struct net *net = sock_net(sk);
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
int mss;
|
|
|
|
mss = tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1;
|
|
mss = min(net->ipv4.sysctl_tcp_base_mss, mss);
|
|
mss = max(mss, 68 - tp->tcp_header_len);
|
|
mss = max(mss, net->ipv4.sysctl_tcp_min_snd_mss);
|
|
icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss);
|
|
tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* retransmits_timed_out() - returns true if this connection has timed out
|
|
* @sk: The current socket
|
|
* @boundary: max number of retransmissions
|
|
* @timeout: A custom timeout value.
|
|
* If set to 0 the default timeout is calculated and used.
|
|
* Using TCP_RTO_MIN and the number of unsuccessful retransmits.
|
|
*
|
|
* The default "timeout" value this function can calculate and use
|
|
* is equivalent to the timeout of a TCP Connection
|
|
* after "boundary" unsuccessful, exponentially backed-off
|
|
* retransmissions with an initial RTO of TCP_RTO_MIN.
|
|
*/
|
|
static bool retransmits_timed_out(struct sock *sk,
|
|
unsigned int boundary,
|
|
unsigned int timeout)
|
|
{
|
|
const unsigned int rto_base = TCP_RTO_MIN;
|
|
unsigned int linear_backoff_thresh, start_ts;
|
|
|
|
if (!inet_csk(sk)->icsk_retransmits)
|
|
return false;
|
|
|
|
start_ts = tcp_sk(sk)->retrans_stamp;
|
|
if (unlikely(!start_ts))
|
|
start_ts = tcp_skb_timestamp(tcp_write_queue_head(sk));
|
|
|
|
if (likely(timeout == 0)) {
|
|
linear_backoff_thresh = ilog2(TCP_RTO_MAX/rto_base);
|
|
|
|
if (boundary <= linear_backoff_thresh)
|
|
timeout = ((2 << boundary) - 1) * rto_base;
|
|
else
|
|
timeout = ((2 << linear_backoff_thresh) - 1) * rto_base +
|
|
(boundary - linear_backoff_thresh) * TCP_RTO_MAX;
|
|
}
|
|
return (tcp_time_stamp(tcp_sk(sk)) - start_ts) >= jiffies_to_msecs(timeout);
|
|
}
|
|
|
|
/* A write timeout has occurred. Process the after effects. */
|
|
static int tcp_write_timeout(struct sock *sk)
|
|
{
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
struct net *net = sock_net(sk);
|
|
bool expired, do_reset;
|
|
int retry_until;
|
|
|
|
if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
|
|
if (icsk->icsk_retransmits) {
|
|
dst_negative_advice(sk);
|
|
if (tp->syn_fastopen || tp->syn_data)
|
|
tcp_fastopen_cache_set(sk, 0, NULL, true, 0);
|
|
if (tp->syn_data && icsk->icsk_retransmits == 1)
|
|
NET_INC_STATS(sock_net(sk),
|
|
LINUX_MIB_TCPFASTOPENACTIVEFAIL);
|
|
} else if (!tp->syn_data && !tp->syn_fastopen) {
|
|
sk_rethink_txhash(sk);
|
|
}
|
|
retry_until = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries;
|
|
expired = icsk->icsk_retransmits >= retry_until;
|
|
} else {
|
|
if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1, 0)) {
|
|
/* Some middle-boxes may black-hole Fast Open _after_
|
|
* the handshake. Therefore we conservatively disable
|
|
* Fast Open on this path on recurring timeouts after
|
|
* successful Fast Open.
|
|
*/
|
|
if (tp->syn_data_acked) {
|
|
tcp_fastopen_cache_set(sk, 0, NULL, true, 0);
|
|
if (icsk->icsk_retransmits == net->ipv4.sysctl_tcp_retries1)
|
|
NET_INC_STATS(sock_net(sk),
|
|
LINUX_MIB_TCPFASTOPENACTIVEFAIL);
|
|
}
|
|
/* Black hole detection */
|
|
tcp_mtu_probing(icsk, sk);
|
|
|
|
dst_negative_advice(sk);
|
|
} else {
|
|
sk_rethink_txhash(sk);
|
|
}
|
|
|
|
retry_until = net->ipv4.sysctl_tcp_retries2;
|
|
if (sock_flag(sk, SOCK_DEAD)) {
|
|
const bool alive = icsk->icsk_rto < TCP_RTO_MAX;
|
|
|
|
retry_until = tcp_orphan_retries(sk, alive);
|
|
do_reset = alive ||
|
|
!retransmits_timed_out(sk, retry_until, 0);
|
|
|
|
if (tcp_out_of_resources(sk, do_reset))
|
|
return 1;
|
|
}
|
|
expired = retransmits_timed_out(sk, retry_until,
|
|
icsk->icsk_user_timeout);
|
|
}
|
|
if (expired) {
|
|
/* Has it gone just too far? */
|
|
tcp_write_err(sk);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Called with BH disabled */
|
|
void tcp_delack_timer_handler(struct sock *sk)
|
|
{
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
sk_mem_reclaim_partial(sk);
|
|
|
|
if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
|
|
!(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
|
|
goto out;
|
|
|
|
if (time_after(icsk->icsk_ack.timeout, jiffies)) {
|
|
sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
|
|
goto out;
|
|
}
|
|
icsk->icsk_ack.pending &= ~ICSK_ACK_TIMER;
|
|
|
|
if (inet_csk_ack_scheduled(sk)) {
|
|
if (!icsk->icsk_ack.pingpong) {
|
|
/* Delayed ACK missed: inflate ATO. */
|
|
icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1, icsk->icsk_rto);
|
|
} else {
|
|
/* Delayed ACK missed: leave pingpong mode and
|
|
* deflate ATO.
|
|
*/
|
|
icsk->icsk_ack.pingpong = 0;
|
|
icsk->icsk_ack.ato = TCP_ATO_MIN;
|
|
}
|
|
tcp_mstamp_refresh(tcp_sk(sk));
|
|
tcp_send_ack(sk);
|
|
__NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKS);
|
|
}
|
|
|
|
out:
|
|
if (tcp_under_memory_pressure(sk))
|
|
sk_mem_reclaim(sk);
|
|
}
|
|
|
|
|
|
/**
|
|
* tcp_delack_timer() - The TCP delayed ACK timeout handler
|
|
* @data: Pointer to the current socket. (gets casted to struct sock *)
|
|
*
|
|
* This function gets (indirectly) called when the kernel timer for a TCP packet
|
|
* of this socket expires. Calls tcp_delack_timer_handler() to do the actual work.
|
|
*
|
|
* Returns: Nothing (void)
|
|
*/
|
|
static void tcp_delack_timer(unsigned long data)
|
|
{
|
|
struct sock *sk = (struct sock *)data;
|
|
|
|
bh_lock_sock(sk);
|
|
if (!sock_owned_by_user(sk)) {
|
|
tcp_delack_timer_handler(sk);
|
|
} else {
|
|
inet_csk(sk)->icsk_ack.blocked = 1;
|
|
__NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED);
|
|
/* deleguate our work to tcp_release_cb() */
|
|
if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags))
|
|
sock_hold(sk);
|
|
}
|
|
bh_unlock_sock(sk);
|
|
sock_put(sk);
|
|
}
|
|
|
|
static void tcp_probe_timer(struct sock *sk)
|
|
{
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
int max_probes;
|
|
u32 start_ts;
|
|
|
|
if (tp->packets_out || !tcp_send_head(sk)) {
|
|
icsk->icsk_probes_out = 0;
|
|
return;
|
|
}
|
|
|
|
/* RFC 1122 4.2.2.17 requires the sender to stay open indefinitely as
|
|
* long as the receiver continues to respond probes. We support this by
|
|
* default and reset icsk_probes_out with incoming ACKs. But if the
|
|
* socket is orphaned or the user specifies TCP_USER_TIMEOUT, we
|
|
* kill the socket when the retry count and the time exceeds the
|
|
* corresponding system limit. We also implement similar policy when
|
|
* we use RTO to probe window in tcp_retransmit_timer().
|
|
*/
|
|
start_ts = tcp_skb_timestamp(tcp_send_head(sk));
|
|
if (!start_ts)
|
|
tcp_send_head(sk)->skb_mstamp = tp->tcp_mstamp;
|
|
else if (icsk->icsk_user_timeout &&
|
|
(s32)(tcp_time_stamp(tp) - start_ts) >
|
|
jiffies_to_msecs(icsk->icsk_user_timeout))
|
|
goto abort;
|
|
|
|
max_probes = sock_net(sk)->ipv4.sysctl_tcp_retries2;
|
|
if (sock_flag(sk, SOCK_DEAD)) {
|
|
const bool alive = inet_csk_rto_backoff(icsk, TCP_RTO_MAX) < TCP_RTO_MAX;
|
|
|
|
max_probes = tcp_orphan_retries(sk, alive);
|
|
if (!alive && icsk->icsk_backoff >= max_probes)
|
|
goto abort;
|
|
if (tcp_out_of_resources(sk, true))
|
|
return;
|
|
}
|
|
|
|
if (icsk->icsk_probes_out >= max_probes) {
|
|
abort: tcp_write_err(sk);
|
|
} else {
|
|
/* Only send another probe if we didn't close things up. */
|
|
tcp_send_probe0(sk);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Timer for Fast Open socket to retransmit SYNACK. Note that the
|
|
* sk here is the child socket, not the parent (listener) socket.
|
|
*/
|
|
static void tcp_fastopen_synack_timer(struct sock *sk)
|
|
{
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
int max_retries = icsk->icsk_syn_retries ? :
|
|
sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */
|
|
struct request_sock *req;
|
|
|
|
req = tcp_sk(sk)->fastopen_rsk;
|
|
req->rsk_ops->syn_ack_timeout(req);
|
|
|
|
if (req->num_timeout >= max_retries) {
|
|
tcp_write_err(sk);
|
|
return;
|
|
}
|
|
/* XXX (TFO) - Unlike regular SYN-ACK retransmit, we ignore error
|
|
* returned from rtx_syn_ack() to make it more persistent like
|
|
* regular retransmit because if the child socket has been accepted
|
|
* it's not good to give up too easily.
|
|
*/
|
|
inet_rtx_syn_ack(sk, req);
|
|
req->num_timeout++;
|
|
icsk->icsk_retransmits++;
|
|
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
|
TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
|
|
}
|
|
|
|
|
|
/**
|
|
* tcp_retransmit_timer() - The TCP retransmit timeout handler
|
|
* @sk: Pointer to the current socket.
|
|
*
|
|
* This function gets called when the kernel timer for a TCP packet
|
|
* of this socket expires.
|
|
*
|
|
* It handles retransmission, timer adjustment and other necesarry measures.
|
|
*
|
|
* Returns: Nothing (void)
|
|
*/
|
|
void tcp_retransmit_timer(struct sock *sk)
|
|
{
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
struct net *net = sock_net(sk);
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
struct sk_buff *skb;
|
|
|
|
if (tp->fastopen_rsk) {
|
|
WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV &&
|
|
sk->sk_state != TCP_FIN_WAIT1);
|
|
tcp_fastopen_synack_timer(sk);
|
|
/* Before we receive ACK to our SYN-ACK don't retransmit
|
|
* anything else (e.g., data or FIN segments).
|
|
*/
|
|
return;
|
|
}
|
|
|
|
if (!tp->packets_out)
|
|
return;
|
|
|
|
skb = tcp_rtx_queue_head(sk);
|
|
if (WARN_ON_ONCE(!skb))
|
|
return;
|
|
|
|
tp->tlp_high_seq = 0;
|
|
|
|
if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) &&
|
|
!((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) {
|
|
/* Receiver dastardly shrinks window. Our retransmits
|
|
* become zero probes, but we should not timeout this
|
|
* connection. If the socket is an orphan, time it out,
|
|
* we cannot allow such beasts to hang infinitely.
|
|
*/
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
if (sk->sk_family == AF_INET) {
|
|
net_dbg_ratelimited("Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
|
|
&inet->inet_daddr,
|
|
ntohs(inet->inet_dport),
|
|
inet->inet_num,
|
|
tp->snd_una, tp->snd_nxt);
|
|
}
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
else if (sk->sk_family == AF_INET6) {
|
|
net_dbg_ratelimited("Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
|
|
&sk->sk_v6_daddr,
|
|
ntohs(inet->inet_dport),
|
|
inet->inet_num,
|
|
tp->snd_una, tp->snd_nxt);
|
|
}
|
|
#endif
|
|
if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) {
|
|
tcp_write_err(sk);
|
|
goto out;
|
|
}
|
|
tcp_enter_loss(sk);
|
|
tcp_retransmit_skb(sk, skb, 1);
|
|
__sk_dst_reset(sk);
|
|
goto out_reset_timer;
|
|
}
|
|
|
|
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTS);
|
|
if (tcp_write_timeout(sk))
|
|
goto out;
|
|
|
|
if (icsk->icsk_retransmits == 0) {
|
|
int mib_idx = 0;
|
|
|
|
if (icsk->icsk_ca_state == TCP_CA_Recovery) {
|
|
if (tcp_is_sack(tp))
|
|
mib_idx = LINUX_MIB_TCPSACKRECOVERYFAIL;
|
|
else
|
|
mib_idx = LINUX_MIB_TCPRENORECOVERYFAIL;
|
|
} else if (icsk->icsk_ca_state == TCP_CA_Loss) {
|
|
mib_idx = LINUX_MIB_TCPLOSSFAILURES;
|
|
} else if ((icsk->icsk_ca_state == TCP_CA_Disorder) ||
|
|
tp->sacked_out) {
|
|
if (tcp_is_sack(tp))
|
|
mib_idx = LINUX_MIB_TCPSACKFAILURES;
|
|
else
|
|
mib_idx = LINUX_MIB_TCPRENOFAILURES;
|
|
}
|
|
if (mib_idx)
|
|
__NET_INC_STATS(sock_net(sk), mib_idx);
|
|
}
|
|
|
|
tcp_enter_loss(sk);
|
|
|
|
if (tcp_retransmit_skb(sk, tcp_write_queue_head(sk), 1) > 0) {
|
|
/* Retransmission failed because of local congestion,
|
|
* do not backoff.
|
|
*/
|
|
if (!icsk->icsk_retransmits)
|
|
icsk->icsk_retransmits = 1;
|
|
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
|
min(icsk->icsk_rto, TCP_RESOURCE_PROBE_INTERVAL),
|
|
TCP_RTO_MAX);
|
|
goto out;
|
|
}
|
|
|
|
/* Increase the timeout each time we retransmit. Note that
|
|
* we do not increase the rtt estimate. rto is initialized
|
|
* from rtt, but increases here. Jacobson (SIGCOMM 88) suggests
|
|
* that doubling rto each time is the least we can get away with.
|
|
* In KA9Q, Karn uses this for the first few times, and then
|
|
* goes to quadratic. netBSD doubles, but only goes up to *64,
|
|
* and clamps at 1 to 64 sec afterwards. Note that 120 sec is
|
|
* defined in the protocol as the maximum possible RTT. I guess
|
|
* we'll have to use something other than TCP to talk to the
|
|
* University of Mars.
|
|
*
|
|
* PAWS allows us longer timeouts and large windows, so once
|
|
* implemented ftp to mars will work nicely. We will have to fix
|
|
* the 120 second clamps though!
|
|
*/
|
|
icsk->icsk_backoff++;
|
|
icsk->icsk_retransmits++;
|
|
|
|
out_reset_timer:
|
|
/* If stream is thin, use linear timeouts. Since 'icsk_backoff' is
|
|
* used to reset timer, set to 0. Recalculate 'icsk_rto' as this
|
|
* might be increased if the stream oscillates between thin and thick,
|
|
* thus the old value might already be too high compared to the value
|
|
* set by 'tcp_set_rto' in tcp_input.c which resets the rto without
|
|
* backoff. Limit to TCP_THIN_LINEAR_RETRIES before initiating
|
|
* exponential backoff behaviour to avoid continue hammering
|
|
* linear-timeout retransmissions into a black hole
|
|
*/
|
|
if (sk->sk_state == TCP_ESTABLISHED &&
|
|
(tp->thin_lto || sysctl_tcp_thin_linear_timeouts) &&
|
|
tcp_stream_is_thin(tp) &&
|
|
icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) {
|
|
icsk->icsk_backoff = 0;
|
|
icsk->icsk_rto = min(__tcp_set_rto(tp), TCP_RTO_MAX);
|
|
} else {
|
|
/* Use normal (exponential) backoff */
|
|
icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
|
|
}
|
|
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX);
|
|
if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0))
|
|
__sk_dst_reset(sk);
|
|
|
|
out:;
|
|
}
|
|
|
|
/* Called with bottom-half processing disabled.
|
|
Called by tcp_write_timer() */
|
|
void tcp_write_timer_handler(struct sock *sk)
|
|
{
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
int event;
|
|
|
|
if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
|
|
!icsk->icsk_pending)
|
|
goto out;
|
|
|
|
if (time_after(icsk->icsk_timeout, jiffies)) {
|
|
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
|
|
goto out;
|
|
}
|
|
|
|
tcp_mstamp_refresh(tcp_sk(sk));
|
|
event = icsk->icsk_pending;
|
|
|
|
switch (event) {
|
|
case ICSK_TIME_REO_TIMEOUT:
|
|
tcp_rack_reo_timeout(sk);
|
|
break;
|
|
case ICSK_TIME_LOSS_PROBE:
|
|
tcp_send_loss_probe(sk);
|
|
break;
|
|
case ICSK_TIME_RETRANS:
|
|
icsk->icsk_pending = 0;
|
|
tcp_retransmit_timer(sk);
|
|
break;
|
|
case ICSK_TIME_PROBE0:
|
|
icsk->icsk_pending = 0;
|
|
tcp_probe_timer(sk);
|
|
break;
|
|
}
|
|
|
|
out:
|
|
sk_mem_reclaim(sk);
|
|
}
|
|
|
|
static void tcp_write_timer(unsigned long data)
|
|
{
|
|
struct sock *sk = (struct sock *)data;
|
|
|
|
bh_lock_sock(sk);
|
|
if (!sock_owned_by_user(sk)) {
|
|
tcp_write_timer_handler(sk);
|
|
} else {
|
|
/* delegate our work to tcp_release_cb() */
|
|
if (!test_and_set_bit(TCP_WRITE_TIMER_DEFERRED, &sk->sk_tsq_flags))
|
|
sock_hold(sk);
|
|
}
|
|
bh_unlock_sock(sk);
|
|
sock_put(sk);
|
|
}
|
|
|
|
void tcp_syn_ack_timeout(const struct request_sock *req)
|
|
{
|
|
struct net *net = read_pnet(&inet_rsk(req)->ireq_net);
|
|
|
|
__NET_INC_STATS(net, LINUX_MIB_TCPTIMEOUTS);
|
|
}
|
|
EXPORT_SYMBOL(tcp_syn_ack_timeout);
|
|
|
|
void tcp_set_keepalive(struct sock *sk, int val)
|
|
{
|
|
if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
|
|
return;
|
|
|
|
if (val && !sock_flag(sk, SOCK_KEEPOPEN))
|
|
inet_csk_reset_keepalive_timer(sk, keepalive_time_when(tcp_sk(sk)));
|
|
else if (!val)
|
|
inet_csk_delete_keepalive_timer(sk);
|
|
}
|
|
EXPORT_SYMBOL_GPL(tcp_set_keepalive);
|
|
|
|
|
|
static void tcp_keepalive_timer (unsigned long data)
|
|
{
|
|
struct sock *sk = (struct sock *) data;
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
struct tcp_sock *tp = tcp_sk(sk);
|
|
u32 elapsed;
|
|
|
|
/* Only process if socket is not in use. */
|
|
bh_lock_sock(sk);
|
|
if (sock_owned_by_user(sk)) {
|
|
/* Try again later. */
|
|
inet_csk_reset_keepalive_timer (sk, HZ/20);
|
|
goto out;
|
|
}
|
|
|
|
if (sk->sk_state == TCP_LISTEN) {
|
|
pr_err("Hmm... keepalive on a LISTEN ???\n");
|
|
goto out;
|
|
}
|
|
|
|
tcp_mstamp_refresh(tp);
|
|
if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) {
|
|
if (tp->linger2 >= 0) {
|
|
const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN;
|
|
|
|
if (tmo > 0) {
|
|
tcp_time_wait(sk, TCP_FIN_WAIT2, tmo);
|
|
goto out;
|
|
}
|
|
}
|
|
tcp_send_active_reset(sk, GFP_ATOMIC);
|
|
goto death;
|
|
}
|
|
|
|
if (!sock_flag(sk, SOCK_KEEPOPEN) ||
|
|
((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)))
|
|
goto out;
|
|
|
|
elapsed = keepalive_time_when(tp);
|
|
|
|
/* It is alive without keepalive 8) */
|
|
if (tp->packets_out || tcp_send_head(sk))
|
|
goto resched;
|
|
|
|
elapsed = keepalive_time_elapsed(tp);
|
|
|
|
if (elapsed >= keepalive_time_when(tp)) {
|
|
/* If the TCP_USER_TIMEOUT option is enabled, use that
|
|
* to determine when to timeout instead.
|
|
*/
|
|
if ((icsk->icsk_user_timeout != 0 &&
|
|
elapsed >= icsk->icsk_user_timeout &&
|
|
icsk->icsk_probes_out > 0) ||
|
|
(icsk->icsk_user_timeout == 0 &&
|
|
icsk->icsk_probes_out >= keepalive_probes(tp))) {
|
|
tcp_send_active_reset(sk, GFP_ATOMIC);
|
|
tcp_write_err(sk);
|
|
goto out;
|
|
}
|
|
if (tcp_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) {
|
|
icsk->icsk_probes_out++;
|
|
elapsed = keepalive_intvl_when(tp);
|
|
} else {
|
|
/* If keepalive was lost due to local congestion,
|
|
* try harder.
|
|
*/
|
|
elapsed = TCP_RESOURCE_PROBE_INTERVAL;
|
|
}
|
|
} else {
|
|
/* It is tp->rcv_tstamp + keepalive_time_when(tp) */
|
|
elapsed = keepalive_time_when(tp) - elapsed;
|
|
}
|
|
|
|
sk_mem_reclaim(sk);
|
|
|
|
resched:
|
|
inet_csk_reset_keepalive_timer (sk, elapsed);
|
|
goto out;
|
|
|
|
death:
|
|
tcp_done(sk);
|
|
|
|
out:
|
|
bh_unlock_sock(sk);
|
|
sock_put(sk);
|
|
}
|
|
|
|
void tcp_init_xmit_timers(struct sock *sk)
|
|
{
|
|
inet_csk_init_xmit_timers(sk, &tcp_write_timer, &tcp_delack_timer,
|
|
&tcp_keepalive_timer);
|
|
hrtimer_init(&tcp_sk(sk)->pacing_timer, CLOCK_MONOTONIC,
|
|
HRTIMER_MODE_ABS_PINNED);
|
|
tcp_sk(sk)->pacing_timer.function = tcp_pace_kick;
|
|
}
|