linux/net/ipv4/af_inet.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.
 *
 *		PF_INET protocol family socket handler.
 *
 * Authors:	Ross Biro
 *		Fred N. van Kempen, <[email protected]>
 *		Florian La Roche, <[email protected]>
 *		Alan Cox, <[email protected]>
 *
 * Changes (see also sock.c)
 *
 *		piggy,
 *		Karl Knutson	:	Socket protocol table
 *		A.N.Kuznetsov	:	Socket death error in accept().
 *		John Richardson :	Fix non blocking error in connect()
 *					so sockets that fail to connect
 *					don't return -EINPROGRESS.
 *		Alan Cox	:	Asynchronous I/O support
 *		Alan Cox	:	Keep correct socket pointer on sock
 *					structures
 *					when accept() ed
 *		Alan Cox	:	Semantics of SO_LINGER aren't state
 *					moved to close when you look carefully.
 *					With this fixed and the accept bug fixed
 *					some RPC stuff seems happier.
 *		Niibe Yutaka	:	4.4BSD style write async I/O
 *		Alan Cox,
 *		Tony Gale 	:	Fixed reuse semantics.
 *		Alan Cox	:	bind() shouldn't abort existing but dead
 *					sockets. Stops FTP netin:.. I hope.
 *		Alan Cox	:	bind() works correctly for RAW sockets.
 *					Note that FreeBSD at least was broken
 *					in this respect so be careful with
 *					compatibility tests...
 *		Alan Cox	:	routing cache support
 *		Alan Cox	:	memzero the socket structure for
 *					compactness.
 *		Matt Day	:	nonblock connect error handler
 *		Alan Cox	:	Allow large numbers of pending sockets
 *					(eg for big web sites), but only if
 *					specifically application requested.
 *		Alan Cox	:	New buffering throughout IP. Used
 *					dumbly.
 *		Alan Cox	:	New buffering now used smartly.
 *		Alan Cox	:	BSD rather than common sense
 *					interpretation of listen.
 *		Germano Caronni	:	Assorted small races.
 *		Alan Cox	:	sendmsg/recvmsg basic support.
 *		Alan Cox	:	Only sendmsg/recvmsg now supported.
 *		Alan Cox	:	Locked down bind (see security list).
 *		Alan Cox	:	Loosened bind a little.
 *		Mike McLagan	:	ADD/DEL DLCI Ioctls
 *	Willy Konynenberg	:	Transparent proxying support.
 *		David S. Miller	:	New socket lookup architecture.
 *					Some other random speedups.
 *		Cyrus Durgin	:	Cleaned up file for kmod hacks.
 *		Andi Kleen	:	Fix inet_stream_connect TCP race.
 */

#define pr_fmt(fmt)

#include <linux/err.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/capability.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/netfilter_ipv4.h>
#include <linux/random.h>
#include <linux/slab.h>

#include <linux/uaccess.h>

#include <linux/inet.h>
#include <linux/igmp.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <net/checksum.h>
#include <net/ip.h>
#include <net/protocol.h>
#include <net/arp.h>
#include <net/route.h>
#include <net/ip_fib.h>
#include <net/inet_connection_sock.h>
#include <net/gro.h>
#include <net/gso.h>
#include <net/tcp.h>
#include <net/udp.h>
#include <net/udplite.h>
#include <net/ping.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <net/raw.h>
#include <net/icmp.h>
#include <net/inet_common.h>
#include <net/ip_tunnels.h>
#include <net/xfrm.h>
#include <net/net_namespace.h>
#include <net/secure_seq.h>
#ifdef CONFIG_IP_MROUTE
#include <linux/mroute.h>
#endif
#include <net/l3mdev.h>
#include <net/compat.h>
#include <net/rps.h>

#include <trace/events/sock.h>

/* The inetsw table contains everything that inet_create needs to
 * build a new socket.
 */
static struct list_head inetsw[SOCK_MAX];
static DEFINE_SPINLOCK(inetsw_lock);

/* New destruction routine */

void inet_sock_destruct(struct sock *sk)
{}
EXPORT_SYMBOL();

/*
 *	The routines beyond this point handle the behaviour of an AF_INET
 *	socket object. Mostly it punts to the subprotocols of IP to do
 *	the work.
 */

/*
 *	Automatically bind an unbound socket.
 */

static int inet_autobind(struct sock *sk)
{}

int __inet_listen_sk(struct sock *sk, int backlog)
{}

/*
 *	Move a socket into listening state.
 */
int inet_listen(struct socket *sock, int backlog)
{}
EXPORT_SYMBOL();

/*
 *	Create an inet socket.
 */

static int inet_create(struct net *net, struct socket *sock, int protocol,
		       int kern)
{}


/*
 *	The peer socket should always be NULL (or else). When we call this
 *	function we are destroying the object and from then on nobody
 *	should refer to it.
 */
int inet_release(struct socket *sock)
{}
EXPORT_SYMBOL();

int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{}

int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{}
EXPORT_SYMBOL();

int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
		u32 flags)
{}

int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
		       int addr_len, int flags)
{}
EXPORT_SYMBOL();

static long inet_wait_for_connect(struct sock *sk, long timeo, int writebias)
{}

/*
 *	Connect to a remote host. There is regrettably still a little
 *	TCP 'magic' in here.
 */
int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
			  int addr_len, int flags, int is_sendmsg)
{}
EXPORT_SYMBOL();

int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
			int addr_len, int flags)
{}
EXPORT_SYMBOL();

void __inet_accept(struct socket *sock, struct socket *newsock, struct sock *newsk)
{}

/*
 *	Accept a pending connection. The TCP layer now gives BSD semantics.
 */

int inet_accept(struct socket *sock, struct socket *newsock,
		struct proto_accept_arg *arg)
{}
EXPORT_SYMBOL();

/*
 *	This does both peername and sockname.
 */
int inet_getname(struct socket *sock, struct sockaddr *uaddr,
		 int peer)
{}
EXPORT_SYMBOL();

int inet_send_prepare(struct sock *sk)
{}
EXPORT_SYMBOL_GPL();

int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
{}
EXPORT_SYMBOL();

void inet_splice_eof(struct socket *sock)
{}
EXPORT_SYMBOL_GPL();

INDIRECT_CALLABLE_DECLARE();
int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
		 int flags)
{}
EXPORT_SYMBOL();

int inet_shutdown(struct socket *sock, int how)
{}
EXPORT_SYMBOL();

/*
 *	ioctl() calls you can issue on an INET socket. Most of these are
 *	device configuration and stuff and very rarely used. Some ioctls
 *	pass on to the socket itself.
 *
 *	NOTE: I like the idea of a module for the config stuff. ie ifconfig
 *	loads the devconfigure module does its configuring and unloads it.
 *	There's a good 20K of config code hanging around the kernel.
 */

int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
{}
EXPORT_SYMBOL();

#ifdef CONFIG_COMPAT
static int inet_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
		struct compat_rtentry __user *ur)
{}

static int inet_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
{}
#endif /* CONFIG_COMPAT */

const struct proto_ops inet_stream_ops =;
EXPORT_SYMBOL();

const struct proto_ops inet_dgram_ops =;
EXPORT_SYMBOL();

/*
 * For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
 * udp_poll
 */
static const struct proto_ops inet_sockraw_ops =;

static const struct net_proto_family inet_family_ops =;

/* Upon startup we insert all the elements in inetsw_array[] into
 * the linked list inetsw.
 */
static struct inet_protosw inetsw_array[] =;

#define INETSW_ARRAY_LEN

void inet_register_protosw(struct inet_protosw *p)
{}
EXPORT_SYMBOL();

void inet_unregister_protosw(struct inet_protosw *p)
{}
EXPORT_SYMBOL();

static int inet_sk_reselect_saddr(struct sock *sk)
{}

int inet_sk_rebuild_header(struct sock *sk)
{}
EXPORT_SYMBOL();

void inet_sk_set_state(struct sock *sk, int state)
{}
EXPORT_SYMBOL();

void inet_sk_state_store(struct sock *sk, int newstate)
{}

struct sk_buff *inet_gso_segment(struct sk_buff *skb,
				 netdev_features_t features)
{}

static struct sk_buff *ipip_gso_segment(struct sk_buff *skb,
					netdev_features_t features)
{}

struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)
{}

static struct sk_buff *ipip_gro_receive(struct list_head *head,
					struct sk_buff *skb)
{}

#define SECONDS_PER_DAY

/* inet_current_timestamp - Return IP network timestamp
 *
 * Return milliseconds since midnight in network byte order.
 */
__be32 inet_current_timestamp(void)
{}
EXPORT_SYMBOL();

int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
{}
EXPORT_SYMBOL();

int inet_gro_complete(struct sk_buff *skb, int nhoff)
{}

static int ipip_gro_complete(struct sk_buff *skb, int nhoff)
{}

int inet_ctl_sock_create(struct sock **sk, unsigned short family,
			 unsigned short type, unsigned char protocol,
			 struct net *net)
{}
EXPORT_SYMBOL_GPL();

unsigned long snmp_fold_field(void __percpu *mib, int offt)
{}
EXPORT_SYMBOL_GPL();

#if BITS_PER_LONG==32

u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offt,
			 size_t syncp_offset)
{
	void *bhptr;
	struct u64_stats_sync *syncp;
	u64 v;
	unsigned int start;

	bhptr = per_cpu_ptr(mib, cpu);
	syncp = (struct u64_stats_sync *)(bhptr + syncp_offset);
	do {
		start = u64_stats_fetch_begin(syncp);
		v = *(((u64 *)bhptr) + offt);
	} while (u64_stats_fetch_retry(syncp, start));

	return v;
}
EXPORT_SYMBOL_GPL(snmp_get_cpu_field64);

u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_offset)
{
	u64 res = 0;
	int cpu;

	for_each_possible_cpu(cpu) {
		res += snmp_get_cpu_field64(mib, cpu, offt, syncp_offset);
	}
	return res;
}
EXPORT_SYMBOL_GPL(snmp_fold_field64);
#endif

#ifdef CONFIG_IP_MULTICAST
static const struct net_protocol igmp_protocol =;
#endif

static const struct net_protocol icmp_protocol =;

static __net_init int ipv4_mib_init_net(struct net *net)
{}

static __net_exit void ipv4_mib_exit_net(struct net *net)
{}

static __net_initdata struct pernet_operations ipv4_mib_ops =;

static int __init init_ipv4_mibs(void)
{}

static __net_init int inet_init_net(struct net *net)
{}

static __net_initdata struct pernet_operations af_inet_ops =;

static int __init init_inet_pernet_ops(void)
{}

static int ipv4_proc_init(void);

/*
 *	IP protocol layer initialiser
 */


static const struct net_offload ipip_offload =;

static int __init ipip_offload_init(void)
{}

static int __init ipv4_offload_init(void)
{}

fs_initcall(ipv4_offload_init);

static struct packet_type ip_packet_type __read_mostly =;

static int __init inet_init(void)
{}

fs_initcall(inet_init);

/* ------------------------------------------------------------------------ */

#ifdef CONFIG_PROC_FS
static int __init ipv4_proc_init(void)
{}

#else /* CONFIG_PROC_FS */
static int __init ipv4_proc_init(void)
{
	return 0;
}
#endif /* CONFIG_PROC_FS */