Changes in 5.15.58 pinctrl: stm32: fix optional IRQ support to gpios riscv: add as-options for modules with assembly compontents mlxsw: spectrum_router: Fix IPv4 nexthop gateway indication lockdown: Fix kexec lockdown bypass with ima policy drm/ttm: fix locking in vmap/vunmap TTM GEM helpers bus: mhi: host: pci_generic: add Telit FN980 v1 hardware revision bus: mhi: host: pci_generic: add Telit FN990 Revert "selftest/vm: verify remap destination address in mremap_test" Revert "selftest/vm: verify mmap addr in mremap_test" PCI: hv: Fix multi-MSI to allow more than one MSI vector PCI: hv: Fix hv_arch_irq_unmask() for multi-MSI PCI: hv: Reuse existing IRTE allocation in compose_msi_msg() PCI: hv: Fix interrupt mapping for multi-MSI serial: mvebu-uart: correctly report configured baudrate value batman-adv: Use netif_rx_any_context() any. Revert "mt76: mt7921: Fix the error handling path of mt7921_pci_probe()" Revert "mt76: mt7921e: fix possible probe failure after reboot" mt76: mt7921: use physical addr to unify register access mt76: mt7921e: fix possible probe failure after reboot mt76: mt7921: Fix the error handling path of mt7921_pci_probe() xfs: fix maxlevels comparisons in the btree staging code xfs: fold perag loop iteration logic into helper function xfs: rename the next_agno perag iteration variable xfs: terminate perag iteration reliably on agcount xfs: fix perag reference leak on iteration race with growfs xfs: prevent a WARN_ONCE() in xfs_ioc_attr_list() r8152: fix a WOL issue ip: Fix data-races around sysctl_ip_default_ttl. xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup() power/reset: arm-versatile: Fix refcount leak in versatile_reboot_probe RDMA/irdma: Do not advertise 1GB page size for x722 RDMA/irdma: Fix sleep from invalid context BUG pinctrl: ralink: rename MT7628(an) functions to MT76X8 pinctrl: ralink: rename pinctrl-rt2880 to pinctrl-ralink pinctrl: ralink: Check for null return of devm_kcalloc perf/core: Fix data race between perf_event_set_output() and perf_mmap_close() ipv4/tcp: do not use per netns ctl sockets net: tun: split run_ebpf_filter() and pskb_trim() into different "if statement" mm/pagealloc: sysctl: change watermark_scale_factor max limit to 30% sysctl: move some boundary constants from sysctl.c to sysctl_vals tcp: Fix data-races around sysctl_tcp_ecn. drm/amd/display: Support for DMUB HPD interrupt handling drm/amd/display: Add option to defer works of hpd_rx_irq drm/amd/display: Fork thread to offload work of hpd_rx_irq drm/amdgpu/display: add quirk handling for stutter mode drm/amd/display: Ignore First MST Sideband Message Return Error scsi: megaraid: Clear READ queue map's nr_queues scsi: ufs: core: Drop loglevel of WriteBoost message nvme: check for duplicate identifiers earlier nvme: fix block device naming collision e1000e: Enable GPT clock before sending message to CSME Revert "e1000e: Fix possible HW unit hang after an s0ix exit" igc: Reinstate IGC_REMOVED logic and implement it properly ip: Fix data-races around sysctl_ip_no_pmtu_disc. ip: Fix data-races around sysctl_ip_fwd_use_pmtu. ip: Fix data-races around sysctl_ip_fwd_update_priority. ip: Fix data-races around sysctl_ip_nonlocal_bind. ip: Fix a data-race around sysctl_ip_autobind_reuse. ip: Fix a data-race around sysctl_fwmark_reflect. tcp/dccp: Fix a data-race around sysctl_tcp_fwmark_accept. tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() tcp: Fix data-races around sysctl_tcp_l3mdev_accept. tcp: Fix data-races around sysctl_tcp_mtu_probing. tcp: Fix data-races around sysctl_tcp_base_mss. tcp: Fix data-races around sysctl_tcp_min_snd_mss. tcp: Fix a data-race around sysctl_tcp_mtu_probe_floor. tcp: Fix a data-race around sysctl_tcp_probe_threshold. tcp: Fix a data-race around sysctl_tcp_probe_interval. net: stmmac: fix pm runtime issue in stmmac_dvr_remove() net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow mtd: rawnand: gpmi: validate controller clock rate mtd: rawnand: gpmi: Set WAIT_FOR_READY timeout based on program/erase times net: dsa: microchip: ksz_common: Fix refcount leak bug net: skb: introduce kfree_skb_reason() net: skb: use kfree_skb_reason() in tcp_v4_rcv() net: skb: use kfree_skb_reason() in __udp4_lib_rcv() net: socket: rename SKB_DROP_REASON_SOCKET_FILTER net: skb_drop_reason: add document for drop reasons net: netfilter: use kfree_drop_reason() for NF_DROP net: ipv4: use kfree_skb_reason() in ip_rcv_core() net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core() i2c: mlxcpld: Fix register setting for 400KHz frequency i2c: cadence: Change large transfer count reset logic to be unconditional perf tests: Fix Convert perf time to TSC test for hybrid net: stmmac: fix dma queue left shift overflow issue net/tls: Fix race in TLS device down flow igmp: Fix data-races around sysctl_igmp_llm_reports. igmp: Fix a data-race around sysctl_igmp_max_memberships. igmp: Fix data-races around sysctl_igmp_max_msf. tcp: Fix data-races around keepalive sysctl knobs. tcp: Fix data-races around sysctl_tcp_syn(ack)?_retries. tcp: Fix data-races around sysctl_tcp_syncookies. tcp: Fix data-races around sysctl_tcp_migrate_req. tcp: Fix data-races around sysctl_tcp_reordering. tcp: Fix data-races around some timeout sysctl knobs. tcp: Fix a data-race around sysctl_tcp_notsent_lowat. tcp: Fix a data-race around sysctl_tcp_tw_reuse. tcp: Fix data-races around sysctl_max_syn_backlog. tcp: Fix data-races around sysctl_tcp_fastopen. tcp: Fix data-races around sysctl_tcp_fastopen_blackhole_timeout. iavf: Fix handling of dummy receive descriptors pinctrl: armada-37xx: Use temporary variable for struct device pinctrl: armada-37xx: Make use of the devm_platform_ioremap_resource() pinctrl: armada-37xx: Convert to use dev_err_probe() pinctrl: armada-37xx: use raw spinlocks for regmap to avoid invalid wait context i40e: Fix erroneous adapter reinitialization during recovery process ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero net: stmmac: remove redunctant disable xPCS EEE call gpio: pca953x: only use single read/write for No AI mode gpio: pca953x: use the correct range when do regmap sync gpio: pca953x: use the correct register address when regcache sync during init be2net: Fix buffer overflow in be_get_module_eeprom net: dsa: sja1105: silent spi_device_id warnings net: dsa: vitesse-vsc73xx: silent spi_device_id warnings drm/imx/dcss: Add missing of_node_put() in fail path ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh. ipv4: Fix data-races around sysctl_fib_multipath_hash_policy. ipv4: Fix data-races around sysctl_fib_multipath_hash_fields. ip: Fix data-races around sysctl_ip_prot_sock. udp: Fix a data-race around sysctl_udp_l3mdev_accept. tcp: Fix data-races around sysctl knobs related to SYN option. tcp: Fix a data-race around sysctl_tcp_early_retrans. tcp: Fix data-races around sysctl_tcp_recovery. tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts. tcp: Fix data-races around sysctl_tcp_slow_start_after_idle. tcp: Fix a data-race around sysctl_tcp_retrans_collapse. tcp: Fix a data-race around sysctl_tcp_stdurg. tcp: Fix a data-race around sysctl_tcp_rfc1337. tcp: Fix a data-race around sysctl_tcp_abort_on_overflow. tcp: Fix data-races around sysctl_tcp_max_reordering. gpio: gpio-xilinx: Fix integer overflow KVM: selftests: Fix target thread to be migrated in rseq_test spi: bcm2835: bcm2835_spi_handle_err(): fix NULL pointer deref for non DMA transfers KVM: Don't null dereference ops->destroy mm/mempolicy: fix uninit-value in mpol_rebind_policy() bpf: Make sure mac_header was set before using it sched/deadline: Fix BUG_ON condition for deboosted tasks x86/bugs: Warn when "ibrs" mitigation is selected on Enhanced IBRS parts dlm: fix pending remove if msg allocation fails x86/uaccess: Implement macros for CMPXCHG on user addresses x86/extable: Tidy up redundant handler functions x86/extable: Get rid of redundant macros x86/mce: Deduplicate exception handling x86/extable: Rework the exception table mechanics x86/extable: Provide EX_TYPE_DEFAULT_MCE_SAFE and EX_TYPE_FAULT_MCE_SAFE bitfield.h: Fix "type of reg too small for mask" test x86/entry_32: Remove .fixup usage x86/extable: Extend extable functionality x86/msr: Remove .fixup usage x86/futex: Remove .fixup usage KVM: x86: Use __try_cmpxchg_user() to emulate atomic accesses xhci: dbc: refactor xhci_dbc_init() xhci: dbc: create and remove dbc structure in dbgtty driver. xhci: dbc: Rename xhci_dbc_init and xhci_dbc_exit xhci: Set HCD flag to defer primary roothub registration mt76: fix use-after-free by removing a non-RCU wcid pointer iwlwifi: fw: uefi: add missing include guards crypto: qat - set to zero DH parameters before free crypto: qat - use pre-allocated buffers in datapath crypto: qat - refactor submission logic crypto: qat - add backlog mechanism crypto: qat - fix memory leak in RSA crypto: qat - remove dma_free_coherent() for RSA crypto: qat - remove dma_free_coherent() for DH crypto: qat - add param check for RSA crypto: qat - add param check for DH crypto: qat - re-enable registration of algorithms exfat: fix referencing wrong parent directory information after renaming tracing: Have event format check not flag %p* on __get_dynamic_array() tracing: Place trace_pid_list logic into abstract functions tracing: Fix return value of trace_pid_write() um: virtio_uml: Allow probing from devicetree um: virtio_uml: Fix broken device handling in time-travel Bluetooth: Add bt_skb_sendmsg helper Bluetooth: Add bt_skb_sendmmsg helper Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg Bluetooth: Fix passing NULL to PTR_ERR Bluetooth: SCO: Fix sco_send_frame returning skb->len Bluetooth: Fix bt_skb_sendmmsg not allocating partial chunks exfat: use updated exfat_chain directly during renaming drm/amd/display: Reset DMCUB before HW init drm/amd/display: Optimize bandwidth on following fast update drm/amd/display: Fix surface optimization regression on Carrizo x86/amd: Use IBPB for firmware calls x86/alternative: Report missing return thunk details watchqueue: make sure to serialize 'wqueue->defunct' properly tty: drivers/tty/, stop using tty_schedule_flip() tty: the rest, stop using tty_schedule_flip() tty: drop tty_schedule_flip() tty: extract tty_flip_buffer_commit() from tty_flip_buffer_push() tty: use new tty_insert_flip_string_and_push_buffer() in pty_write() net: usb: ax88179_178a needs FLAG_SEND_ZLP watch-queue: remove spurious double semicolon drm/amd/display: Don't lock connection_mutex for DMUB HPD drm/amd/display: invalid parameter check in dmub_hpd_callback x86/extable: Prefer local labels in .set directives KVM: x86: fix typo in __try_cmpxchg_user causing non-atomicness x86: drop bogus "cc" clobber from __try_cmpxchg_user_asm() drm/amdgpu: Off by one in dm_dmub_outbox1_low_irq() x86/entry_32: Fix segment exceptions drm/amd/display: Fix wrong format specifier in amdgpu_dm.c Linux 5.15.58 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I6655a937b4226d3011278d13df84b25e5ab4b9ef
802 lines
22 KiB
C
802 lines
22 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* 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 IP module.
|
|
*
|
|
* Version: @(#)ip.h 1.0.2 05/07/93
|
|
*
|
|
* Authors: Ross Biro
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
* Alan Cox, <gw4pts@gw4pts.ampr.org>
|
|
*
|
|
* Changes:
|
|
* Mike McLagan : Routing by source
|
|
*/
|
|
#ifndef _IP_H
|
|
#define _IP_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/in.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/jhash.h>
|
|
#include <linux/sockptr.h>
|
|
|
|
#include <net/inet_sock.h>
|
|
#include <net/route.h>
|
|
#include <net/snmp.h>
|
|
#include <net/flow.h>
|
|
#include <net/flow_dissector.h>
|
|
#include <net/netns/hash.h>
|
|
#include <net/lwtunnel.h>
|
|
|
|
#define IPV4_MAX_PMTU 65535U /* RFC 2675, Section 5.1 */
|
|
#define IPV4_MIN_MTU 68 /* RFC 791 */
|
|
|
|
extern unsigned int sysctl_fib_sync_mem;
|
|
extern unsigned int sysctl_fib_sync_mem_min;
|
|
extern unsigned int sysctl_fib_sync_mem_max;
|
|
|
|
struct sock;
|
|
|
|
struct inet_skb_parm {
|
|
int iif;
|
|
struct ip_options opt; /* Compiled IP options */
|
|
u16 flags;
|
|
|
|
#define IPSKB_FORWARDED BIT(0)
|
|
#define IPSKB_XFRM_TUNNEL_SIZE BIT(1)
|
|
#define IPSKB_XFRM_TRANSFORMED BIT(2)
|
|
#define IPSKB_FRAG_COMPLETE BIT(3)
|
|
#define IPSKB_REROUTED BIT(4)
|
|
#define IPSKB_DOREDIRECT BIT(5)
|
|
#define IPSKB_FRAG_PMTU BIT(6)
|
|
#define IPSKB_L3SLAVE BIT(7)
|
|
#define IPSKB_NOPOLICY BIT(8)
|
|
|
|
u16 frag_max_size;
|
|
};
|
|
|
|
static inline bool ipv4_l3mdev_skb(u16 flags)
|
|
{
|
|
return !!(flags & IPSKB_L3SLAVE);
|
|
}
|
|
|
|
static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
|
|
{
|
|
return ip_hdr(skb)->ihl * 4;
|
|
}
|
|
|
|
struct ipcm_cookie {
|
|
struct sockcm_cookie sockc;
|
|
__be32 addr;
|
|
int oif;
|
|
struct ip_options_rcu *opt;
|
|
__u8 ttl;
|
|
__s16 tos;
|
|
char priority;
|
|
__u16 gso_size;
|
|
};
|
|
|
|
static inline void ipcm_init(struct ipcm_cookie *ipcm)
|
|
{
|
|
*ipcm = (struct ipcm_cookie) { .tos = -1 };
|
|
}
|
|
|
|
static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
|
|
const struct inet_sock *inet)
|
|
{
|
|
ipcm_init(ipcm);
|
|
|
|
ipcm->sockc.mark = inet->sk.sk_mark;
|
|
ipcm->sockc.tsflags = inet->sk.sk_tsflags;
|
|
ipcm->oif = inet->sk.sk_bound_dev_if;
|
|
ipcm->addr = inet->inet_saddr;
|
|
}
|
|
|
|
#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))
|
|
#define PKTINFO_SKB_CB(skb) ((struct in_pktinfo *)((skb)->cb))
|
|
|
|
/* return enslaved device index if relevant */
|
|
static inline int inet_sdif(const struct sk_buff *skb)
|
|
{
|
|
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
|
|
if (skb && ipv4_l3mdev_skb(IPCB(skb)->flags))
|
|
return IPCB(skb)->iif;
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
/* Special input handler for packets caught by router alert option.
|
|
They are selected only by protocol field, and then processed likely
|
|
local ones; but only if someone wants them! Otherwise, router
|
|
not running rsvpd will kill RSVP.
|
|
|
|
It is user level problem, what it will make with them.
|
|
I have no idea, how it will masquearde or NAT them (it is joke, joke :-)),
|
|
but receiver should be enough clever f.e. to forward mtrace requests,
|
|
sent to multicast group to reach destination designated router.
|
|
*/
|
|
|
|
struct ip_ra_chain {
|
|
struct ip_ra_chain __rcu *next;
|
|
struct sock *sk;
|
|
union {
|
|
void (*destructor)(struct sock *);
|
|
struct sock *saved_sk;
|
|
};
|
|
struct rcu_head rcu;
|
|
};
|
|
|
|
/* IP flags. */
|
|
#define IP_CE 0x8000 /* Flag: "Congestion" */
|
|
#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
|
|
#define IP_MF 0x2000 /* Flag: "More Fragments" */
|
|
#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
|
|
|
|
#define IP_FRAG_TIME (30 * HZ) /* fragment lifetime */
|
|
|
|
struct msghdr;
|
|
struct net_device;
|
|
struct packet_type;
|
|
struct rtable;
|
|
struct sockaddr;
|
|
|
|
int igmp_mc_init(void);
|
|
|
|
/*
|
|
* Functions provided by ip.c
|
|
*/
|
|
|
|
int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
|
|
__be32 saddr, __be32 daddr,
|
|
struct ip_options_rcu *opt, u8 tos);
|
|
int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
|
|
struct net_device *orig_dev);
|
|
void ip_list_rcv(struct list_head *head, struct packet_type *pt,
|
|
struct net_device *orig_dev);
|
|
int ip_local_deliver(struct sk_buff *skb);
|
|
void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int proto);
|
|
int ip_mr_input(struct sk_buff *skb);
|
|
int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb);
|
|
int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb);
|
|
int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
|
|
int (*output)(struct net *, struct sock *, struct sk_buff *));
|
|
|
|
struct ip_fraglist_iter {
|
|
struct sk_buff *frag;
|
|
struct iphdr *iph;
|
|
int offset;
|
|
unsigned int hlen;
|
|
};
|
|
|
|
void ip_fraglist_init(struct sk_buff *skb, struct iphdr *iph,
|
|
unsigned int hlen, struct ip_fraglist_iter *iter);
|
|
void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter);
|
|
|
|
static inline struct sk_buff *ip_fraglist_next(struct ip_fraglist_iter *iter)
|
|
{
|
|
struct sk_buff *skb = iter->frag;
|
|
|
|
iter->frag = skb->next;
|
|
skb_mark_not_on_list(skb);
|
|
|
|
return skb;
|
|
}
|
|
|
|
struct ip_frag_state {
|
|
bool DF;
|
|
unsigned int hlen;
|
|
unsigned int ll_rs;
|
|
unsigned int mtu;
|
|
unsigned int left;
|
|
int offset;
|
|
int ptr;
|
|
__be16 not_last_frag;
|
|
};
|
|
|
|
void ip_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int ll_rs,
|
|
unsigned int mtu, bool DF, struct ip_frag_state *state);
|
|
struct sk_buff *ip_frag_next(struct sk_buff *skb,
|
|
struct ip_frag_state *state);
|
|
|
|
void ip_send_check(struct iphdr *ip);
|
|
int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
|
|
int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
|
|
|
|
int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
|
|
__u8 tos);
|
|
void ip_init(void);
|
|
int ip_append_data(struct sock *sk, struct flowi4 *fl4,
|
|
int getfrag(void *from, char *to, int offset, int len,
|
|
int odd, struct sk_buff *skb),
|
|
void *from, int len, int protolen,
|
|
struct ipcm_cookie *ipc,
|
|
struct rtable **rt,
|
|
unsigned int flags);
|
|
int ip_generic_getfrag(void *from, char *to, int offset, int len, int odd,
|
|
struct sk_buff *skb);
|
|
ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page,
|
|
int offset, size_t size, int flags);
|
|
struct sk_buff *__ip_make_skb(struct sock *sk, struct flowi4 *fl4,
|
|
struct sk_buff_head *queue,
|
|
struct inet_cork *cork);
|
|
int ip_send_skb(struct net *net, struct sk_buff *skb);
|
|
int ip_push_pending_frames(struct sock *sk, struct flowi4 *fl4);
|
|
void ip_flush_pending_frames(struct sock *sk);
|
|
struct sk_buff *ip_make_skb(struct sock *sk, struct flowi4 *fl4,
|
|
int getfrag(void *from, char *to, int offset,
|
|
int len, int odd, struct sk_buff *skb),
|
|
void *from, int length, int transhdrlen,
|
|
struct ipcm_cookie *ipc, struct rtable **rtp,
|
|
struct inet_cork *cork, unsigned int flags);
|
|
|
|
int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
|
|
|
|
static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4)
|
|
{
|
|
return __ip_make_skb(sk, fl4, &sk->sk_write_queue, &inet_sk(sk)->cork.base);
|
|
}
|
|
|
|
static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
|
|
{
|
|
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos);
|
|
}
|
|
|
|
static inline __u8 get_rtconn_flags(struct ipcm_cookie* ipc, struct sock* sk)
|
|
{
|
|
return (ipc->tos != -1) ? RT_CONN_FLAGS_TOS(sk, ipc->tos) : RT_CONN_FLAGS(sk);
|
|
}
|
|
|
|
/* datagram.c */
|
|
int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
|
|
int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
|
|
|
|
void ip4_datagram_release_cb(struct sock *sk);
|
|
|
|
struct ip_reply_arg {
|
|
struct kvec iov[1];
|
|
int flags;
|
|
__wsum csum;
|
|
int csumoffset; /* u16 offset of csum in iov[0].iov_base */
|
|
/* -1 if not needed */
|
|
int bound_dev_if;
|
|
u8 tos;
|
|
kuid_t uid;
|
|
};
|
|
|
|
#define IP_REPLY_ARG_NOSRCCHECK 1
|
|
|
|
static inline __u8 ip_reply_arg_flowi_flags(const struct ip_reply_arg *arg)
|
|
{
|
|
return (arg->flags & IP_REPLY_ARG_NOSRCCHECK) ? FLOWI_FLAG_ANYSRC : 0;
|
|
}
|
|
|
|
void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,
|
|
const struct ip_options *sopt,
|
|
__be32 daddr, __be32 saddr,
|
|
const struct ip_reply_arg *arg,
|
|
unsigned int len, u64 transmit_time);
|
|
|
|
#define IP_INC_STATS(net, field) SNMP_INC_STATS64((net)->mib.ip_statistics, field)
|
|
#define __IP_INC_STATS(net, field) __SNMP_INC_STATS64((net)->mib.ip_statistics, field)
|
|
#define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val)
|
|
#define __IP_ADD_STATS(net, field, val) __SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val)
|
|
#define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS64((net)->mib.ip_statistics, field, val)
|
|
#define __IP_UPD_PO_STATS(net, field, val) __SNMP_UPD_PO_STATS64((net)->mib.ip_statistics, field, val)
|
|
#define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field)
|
|
#define __NET_INC_STATS(net, field) __SNMP_INC_STATS((net)->mib.net_statistics, field)
|
|
#define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
|
|
#define __NET_ADD_STATS(net, field, adnd) __SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
|
|
|
|
u64 snmp_get_cpu_field(void __percpu *mib, int cpu, int offct);
|
|
unsigned long snmp_fold_field(void __percpu *mib, int offt);
|
|
#if BITS_PER_LONG==32
|
|
u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offct,
|
|
size_t syncp_offset);
|
|
u64 snmp_fold_field64(void __percpu *mib, int offt, size_t sync_off);
|
|
#else
|
|
static inline u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offct,
|
|
size_t syncp_offset)
|
|
{
|
|
return snmp_get_cpu_field(mib, cpu, offct);
|
|
|
|
}
|
|
|
|
static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_off)
|
|
{
|
|
return snmp_fold_field(mib, offt);
|
|
}
|
|
#endif
|
|
|
|
#define snmp_get_cpu_field64_batch(buff64, stats_list, mib_statistic, offset) \
|
|
{ \
|
|
int i, c; \
|
|
for_each_possible_cpu(c) { \
|
|
for (i = 0; stats_list[i].name; i++) \
|
|
buff64[i] += snmp_get_cpu_field64( \
|
|
mib_statistic, \
|
|
c, stats_list[i].entry, \
|
|
offset); \
|
|
} \
|
|
}
|
|
|
|
#define snmp_get_cpu_field_batch(buff, stats_list, mib_statistic) \
|
|
{ \
|
|
int i, c; \
|
|
for_each_possible_cpu(c) { \
|
|
for (i = 0; stats_list[i].name; i++) \
|
|
buff[i] += snmp_get_cpu_field( \
|
|
mib_statistic, \
|
|
c, stats_list[i].entry); \
|
|
} \
|
|
}
|
|
|
|
void inet_get_local_port_range(struct net *net, int *low, int *high);
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
|
|
{
|
|
if (!net->ipv4.sysctl_local_reserved_ports)
|
|
return false;
|
|
return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
|
|
}
|
|
|
|
static inline bool inet_is_local_unbindable_port(struct net *net, unsigned short port)
|
|
{
|
|
if (!net->ipv4.sysctl_local_unbindable_ports)
|
|
return false;
|
|
return test_bit(port, net->ipv4.sysctl_local_unbindable_ports);
|
|
}
|
|
|
|
static inline bool sysctl_dev_name_is_allowed(const char *name)
|
|
{
|
|
return strcmp(name, "default") != 0 && strcmp(name, "all") != 0;
|
|
}
|
|
|
|
static inline bool inet_port_requires_bind_service(struct net *net, unsigned short port)
|
|
{
|
|
return port < READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
|
|
}
|
|
|
|
#else
|
|
static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool inet_is_local_unbindable_port(struct net *net, unsigned short port)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool inet_port_requires_bind_service(struct net *net, unsigned short port)
|
|
{
|
|
return port < PROT_SOCK;
|
|
}
|
|
#endif
|
|
|
|
__be32 inet_current_timestamp(void);
|
|
|
|
/* From inetpeer.c */
|
|
extern int inet_peer_threshold;
|
|
extern int inet_peer_minttl;
|
|
extern int inet_peer_maxttl;
|
|
|
|
void ipfrag_init(void);
|
|
|
|
void ip_static_sysctl_init(void);
|
|
|
|
#define IP4_REPLY_MARK(net, mark) \
|
|
(READ_ONCE((net)->ipv4.sysctl_fwmark_reflect) ? (mark) : 0)
|
|
|
|
static inline bool ip_is_fragment(const struct iphdr *iph)
|
|
{
|
|
return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
|
|
}
|
|
|
|
#ifdef CONFIG_INET
|
|
#include <net/dst.h>
|
|
|
|
/* The function in 2.2 was invalid, producing wrong result for
|
|
* check=0xFEFF. It was noticed by Arthur Skawina _year_ ago. --ANK(000625) */
|
|
static inline
|
|
int ip_decrease_ttl(struct iphdr *iph)
|
|
{
|
|
u32 check = (__force u32)iph->check;
|
|
check += (__force u32)htons(0x0100);
|
|
iph->check = (__force __sum16)(check + (check>=0xFFFF));
|
|
return --iph->ttl;
|
|
}
|
|
|
|
static inline int ip_mtu_locked(const struct dst_entry *dst)
|
|
{
|
|
const struct rtable *rt = (const struct rtable *)dst;
|
|
|
|
return rt->rt_mtu_locked || dst_metric_locked(dst, RTAX_MTU);
|
|
}
|
|
|
|
static inline
|
|
int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
|
|
{
|
|
u8 pmtudisc = READ_ONCE(inet_sk(sk)->pmtudisc);
|
|
|
|
return pmtudisc == IP_PMTUDISC_DO ||
|
|
(pmtudisc == IP_PMTUDISC_WANT &&
|
|
!ip_mtu_locked(dst));
|
|
}
|
|
|
|
static inline bool ip_sk_accept_pmtu(const struct sock *sk)
|
|
{
|
|
return inet_sk(sk)->pmtudisc != IP_PMTUDISC_INTERFACE &&
|
|
inet_sk(sk)->pmtudisc != IP_PMTUDISC_OMIT;
|
|
}
|
|
|
|
static inline bool ip_sk_use_pmtu(const struct sock *sk)
|
|
{
|
|
return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
|
|
}
|
|
|
|
static inline bool ip_sk_ignore_df(const struct sock *sk)
|
|
{
|
|
return inet_sk(sk)->pmtudisc < IP_PMTUDISC_DO ||
|
|
inet_sk(sk)->pmtudisc == IP_PMTUDISC_OMIT;
|
|
}
|
|
|
|
static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
|
|
bool forwarding)
|
|
{
|
|
const struct rtable *rt = container_of(dst, struct rtable, dst);
|
|
struct net *net = dev_net(dst->dev);
|
|
unsigned int mtu;
|
|
|
|
if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) ||
|
|
ip_mtu_locked(dst) ||
|
|
!forwarding) {
|
|
mtu = rt->rt_pmtu;
|
|
if (mtu && time_before(jiffies, rt->dst.expires))
|
|
goto out;
|
|
}
|
|
|
|
/* 'forwarding = true' case should always honour route mtu */
|
|
mtu = dst_metric_raw(dst, RTAX_MTU);
|
|
if (mtu)
|
|
goto out;
|
|
|
|
mtu = READ_ONCE(dst->dev->mtu);
|
|
|
|
if (unlikely(ip_mtu_locked(dst))) {
|
|
if (rt->rt_uses_gateway && mtu > 576)
|
|
mtu = 576;
|
|
}
|
|
|
|
out:
|
|
mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
|
|
|
|
return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
|
|
}
|
|
|
|
static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
|
|
const struct sk_buff *skb)
|
|
{
|
|
unsigned int mtu;
|
|
|
|
if (!sk || !sk_fullsock(sk) || ip_sk_use_pmtu(sk)) {
|
|
bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED;
|
|
|
|
return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding);
|
|
}
|
|
|
|
mtu = min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU);
|
|
return mtu - lwtunnel_headroom(skb_dst(skb)->lwtstate, mtu);
|
|
}
|
|
|
|
struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
|
|
int fc_mx_len,
|
|
struct netlink_ext_ack *extack);
|
|
static inline void ip_fib_metrics_put(struct dst_metrics *fib_metrics)
|
|
{
|
|
if (fib_metrics != &dst_default_metrics &&
|
|
refcount_dec_and_test(&fib_metrics->refcnt))
|
|
kfree(fib_metrics);
|
|
}
|
|
|
|
/* ipv4 and ipv6 both use refcounted metrics if it is not the default */
|
|
static inline
|
|
void ip_dst_init_metrics(struct dst_entry *dst, struct dst_metrics *fib_metrics)
|
|
{
|
|
dst_init_metrics(dst, fib_metrics->metrics, true);
|
|
|
|
if (fib_metrics != &dst_default_metrics) {
|
|
dst->_metrics |= DST_METRICS_REFCOUNTED;
|
|
refcount_inc(&fib_metrics->refcnt);
|
|
}
|
|
}
|
|
|
|
static inline
|
|
void ip_dst_metrics_put(struct dst_entry *dst)
|
|
{
|
|
struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
|
|
|
|
if (p != &dst_default_metrics && refcount_dec_and_test(&p->refcnt))
|
|
kfree(p);
|
|
}
|
|
|
|
u32 ip_idents_reserve(u32 hash, int segs);
|
|
void __ip_select_ident(struct net *net, struct iphdr *iph, int segs);
|
|
|
|
static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb,
|
|
struct sock *sk, int segs)
|
|
{
|
|
struct iphdr *iph = ip_hdr(skb);
|
|
|
|
/* We had many attacks based on IPID, use the private
|
|
* generator as much as we can.
|
|
*/
|
|
if (sk && inet_sk(sk)->inet_daddr) {
|
|
iph->id = htons(inet_sk(sk)->inet_id);
|
|
inet_sk(sk)->inet_id += segs;
|
|
return;
|
|
}
|
|
if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) {
|
|
iph->id = 0;
|
|
} else {
|
|
/* Unfortunately we need the big hammer to get a suitable IPID */
|
|
__ip_select_ident(net, iph, segs);
|
|
}
|
|
}
|
|
|
|
static inline void ip_select_ident(struct net *net, struct sk_buff *skb,
|
|
struct sock *sk)
|
|
{
|
|
ip_select_ident_segs(net, skb, sk, 1);
|
|
}
|
|
|
|
static inline __wsum inet_compute_pseudo(struct sk_buff *skb, int proto)
|
|
{
|
|
return csum_tcpudp_nofold(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
|
|
skb->len, proto, 0);
|
|
}
|
|
|
|
/* copy IPv4 saddr & daddr to flow_keys, possibly using 64bit load/store
|
|
* Equivalent to : flow->v4addrs.src = iph->saddr;
|
|
* flow->v4addrs.dst = iph->daddr;
|
|
*/
|
|
static inline void iph_to_flow_copy_v4addrs(struct flow_keys *flow,
|
|
const struct iphdr *iph)
|
|
{
|
|
BUILD_BUG_ON(offsetof(typeof(flow->addrs), v4addrs.dst) !=
|
|
offsetof(typeof(flow->addrs), v4addrs.src) +
|
|
sizeof(flow->addrs.v4addrs.src));
|
|
memcpy(&flow->addrs.v4addrs, &iph->saddr, sizeof(flow->addrs.v4addrs));
|
|
flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
|
|
}
|
|
|
|
static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto)
|
|
{
|
|
const struct iphdr *iph = skb_gro_network_header(skb);
|
|
|
|
return csum_tcpudp_nofold(iph->saddr, iph->daddr,
|
|
skb_gro_len(skb), proto, 0);
|
|
}
|
|
|
|
/*
|
|
* Map a multicast IP onto multicast MAC for type ethernet.
|
|
*/
|
|
|
|
static inline void ip_eth_mc_map(__be32 naddr, char *buf)
|
|
{
|
|
__u32 addr=ntohl(naddr);
|
|
buf[0]=0x01;
|
|
buf[1]=0x00;
|
|
buf[2]=0x5e;
|
|
buf[5]=addr&0xFF;
|
|
addr>>=8;
|
|
buf[4]=addr&0xFF;
|
|
addr>>=8;
|
|
buf[3]=addr&0x7F;
|
|
}
|
|
|
|
/*
|
|
* Map a multicast IP onto multicast MAC for type IP-over-InfiniBand.
|
|
* Leave P_Key as 0 to be filled in by driver.
|
|
*/
|
|
|
|
static inline void ip_ib_mc_map(__be32 naddr, const unsigned char *broadcast, char *buf)
|
|
{
|
|
__u32 addr;
|
|
unsigned char scope = broadcast[5] & 0xF;
|
|
|
|
buf[0] = 0; /* Reserved */
|
|
buf[1] = 0xff; /* Multicast QPN */
|
|
buf[2] = 0xff;
|
|
buf[3] = 0xff;
|
|
addr = ntohl(naddr);
|
|
buf[4] = 0xff;
|
|
buf[5] = 0x10 | scope; /* scope from broadcast address */
|
|
buf[6] = 0x40; /* IPv4 signature */
|
|
buf[7] = 0x1b;
|
|
buf[8] = broadcast[8]; /* P_Key */
|
|
buf[9] = broadcast[9];
|
|
buf[10] = 0;
|
|
buf[11] = 0;
|
|
buf[12] = 0;
|
|
buf[13] = 0;
|
|
buf[14] = 0;
|
|
buf[15] = 0;
|
|
buf[19] = addr & 0xff;
|
|
addr >>= 8;
|
|
buf[18] = addr & 0xff;
|
|
addr >>= 8;
|
|
buf[17] = addr & 0xff;
|
|
addr >>= 8;
|
|
buf[16] = addr & 0x0f;
|
|
}
|
|
|
|
static inline void ip_ipgre_mc_map(__be32 naddr, const unsigned char *broadcast, char *buf)
|
|
{
|
|
if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0)
|
|
memcpy(buf, broadcast, 4);
|
|
else
|
|
memcpy(buf, &naddr, sizeof(naddr));
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
#include <linux/ipv6.h>
|
|
#endif
|
|
|
|
static __inline__ void inet_reset_saddr(struct sock *sk)
|
|
{
|
|
inet_sk(sk)->inet_rcv_saddr = inet_sk(sk)->inet_saddr = 0;
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
if (sk->sk_family == PF_INET6) {
|
|
struct ipv6_pinfo *np = inet6_sk(sk);
|
|
|
|
memset(&np->saddr, 0, sizeof(np->saddr));
|
|
memset(&sk->sk_v6_rcv_saddr, 0, sizeof(sk->sk_v6_rcv_saddr));
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#endif
|
|
|
|
static inline unsigned int ipv4_addr_hash(__be32 ip)
|
|
{
|
|
return (__force unsigned int) ip;
|
|
}
|
|
|
|
static inline u32 ipv4_portaddr_hash(const struct net *net,
|
|
__be32 saddr,
|
|
unsigned int port)
|
|
{
|
|
return jhash_1word((__force u32)saddr, net_hash_mix(net)) ^ port;
|
|
}
|
|
|
|
bool ip_call_ra_chain(struct sk_buff *skb);
|
|
|
|
/*
|
|
* Functions provided by ip_fragment.c
|
|
*/
|
|
|
|
enum ip_defrag_users {
|
|
IP_DEFRAG_LOCAL_DELIVER,
|
|
IP_DEFRAG_CALL_RA_CHAIN,
|
|
IP_DEFRAG_CONNTRACK_IN,
|
|
__IP_DEFRAG_CONNTRACK_IN_END = IP_DEFRAG_CONNTRACK_IN + USHRT_MAX,
|
|
IP_DEFRAG_CONNTRACK_OUT,
|
|
__IP_DEFRAG_CONNTRACK_OUT_END = IP_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
|
|
IP_DEFRAG_CONNTRACK_BRIDGE_IN,
|
|
__IP_DEFRAG_CONNTRACK_BRIDGE_IN = IP_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
|
|
IP_DEFRAG_VS_IN,
|
|
IP_DEFRAG_VS_OUT,
|
|
IP_DEFRAG_VS_FWD,
|
|
IP_DEFRAG_AF_PACKET,
|
|
IP_DEFRAG_MACVLAN,
|
|
};
|
|
|
|
/* Return true if the value of 'user' is between 'lower_bond'
|
|
* and 'upper_bond' inclusively.
|
|
*/
|
|
static inline bool ip_defrag_user_in_between(u32 user,
|
|
enum ip_defrag_users lower_bond,
|
|
enum ip_defrag_users upper_bond)
|
|
{
|
|
return user >= lower_bond && user <= upper_bond;
|
|
}
|
|
|
|
int ip_defrag(struct net *net, struct sk_buff *skb, u32 user);
|
|
#ifdef CONFIG_INET
|
|
struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user);
|
|
#else
|
|
static inline struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
|
|
{
|
|
return skb;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Functions provided by ip_forward.c
|
|
*/
|
|
|
|
int ip_forward(struct sk_buff *skb);
|
|
|
|
/*
|
|
* Functions provided by ip_options.c
|
|
*/
|
|
|
|
void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
|
|
__be32 daddr, struct rtable *rt, int is_frag);
|
|
|
|
int __ip_options_echo(struct net *net, struct ip_options *dopt,
|
|
struct sk_buff *skb, const struct ip_options *sopt);
|
|
static inline int ip_options_echo(struct net *net, struct ip_options *dopt,
|
|
struct sk_buff *skb)
|
|
{
|
|
return __ip_options_echo(net, dopt, skb, &IPCB(skb)->opt);
|
|
}
|
|
|
|
void ip_options_fragment(struct sk_buff *skb);
|
|
int __ip_options_compile(struct net *net, struct ip_options *opt,
|
|
struct sk_buff *skb, __be32 *info);
|
|
int ip_options_compile(struct net *net, struct ip_options *opt,
|
|
struct sk_buff *skb);
|
|
int ip_options_get(struct net *net, struct ip_options_rcu **optp,
|
|
sockptr_t data, int optlen);
|
|
void ip_options_undo(struct ip_options *opt);
|
|
void ip_forward_options(struct sk_buff *skb);
|
|
int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev);
|
|
|
|
/*
|
|
* Functions provided by ip_sockglue.c
|
|
*/
|
|
|
|
void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb);
|
|
void ip_cmsg_recv_offset(struct msghdr *msg, struct sock *sk,
|
|
struct sk_buff *skb, int tlen, int offset);
|
|
int ip_cmsg_send(struct sock *sk, struct msghdr *msg,
|
|
struct ipcm_cookie *ipc, bool allow_ipv6);
|
|
int ip_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
|
|
unsigned int optlen);
|
|
int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval,
|
|
int __user *optlen);
|
|
int ip_ra_control(struct sock *sk, unsigned char on,
|
|
void (*destructor)(struct sock *));
|
|
|
|
int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len);
|
|
void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
|
|
u32 info, u8 *payload);
|
|
void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 dport,
|
|
u32 info);
|
|
|
|
static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
|
|
{
|
|
ip_cmsg_recv_offset(msg, skb->sk, skb, 0, 0);
|
|
}
|
|
|
|
bool icmp_global_allow(void);
|
|
extern int sysctl_icmp_msgs_per_sec;
|
|
extern int sysctl_icmp_msgs_burst;
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
int ip_misc_proc_init(void);
|
|
#endif
|
|
|
|
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
|
|
struct netlink_ext_ack *extack);
|
|
|
|
static inline bool inetdev_valid_mtu(unsigned int mtu)
|
|
{
|
|
return likely(mtu >= IPV4_MIN_MTU);
|
|
}
|
|
|
|
void ip_sock_set_freebind(struct sock *sk);
|
|
int ip_sock_set_mtu_discover(struct sock *sk, int val);
|
|
void ip_sock_set_pktinfo(struct sock *sk);
|
|
void ip_sock_set_recverr(struct sock *sk);
|
|
void ip_sock_set_tos(struct sock *sk, int val);
|
|
|
|
#endif /* _IP_H */
|