Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
socket.c File Reference
#include <linux/mm.h>
#include <linux/socket.h>
#include <linux/file.h>
#include <linux/net.h>
#include <linux/interrupt.h>
#include <linux/thread_info.h>
#include <linux/rcupdate.h>
#include <linux/netdevice.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/mutex.h>
#include <linux/wanrouter.h>
#include <linux/if_bridge.h>
#include <linux/if_frad.h>
#include <linux/if_vlan.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/cache.h>
#include <linux/module.h>
#include <linux/highmem.h>
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/compat.h>
#include <linux/kmod.h>
#include <linux/audit.h>
#include <linux/wireless.h>
#include <linux/nsproxy.h>
#include <linux/magic.h>
#include <linux/slab.h>
#include <linux/xattr.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <net/compat.h>
#include <net/wext.h>
#include <net/cls_cgroup.h>
#include <net/sock.h>
#include <linux/netfilter.h>
#include <linux/if_tun.h>
#include <linux/ipv6_route.h>
#include <linux/route.h>
#include <linux/sockios.h>
#include <linux/atalk.h>

Go to the source code of this file.

Data Structures

struct  used_address
 

Macros

#define XATTR_SOCKPROTONAME_SUFFIX   "sockprotoname"
 
#define XATTR_NAME_SOCKPROTONAME   (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
 
#define XATTR_NAME_SOCKPROTONAME_LEN   (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
 
#define COMPAT_MSG(msg, member)   ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)
 
#define COMPAT_NAMELEN(msg)   COMPAT_MSG(msg, msg_namelen)
 
#define COMPAT_FLAGS(msg)   COMPAT_MSG(msg, msg_flags)
 

Functions

int move_addr_to_kernel (void __user *uaddr, int ulen, struct sockaddr_storage *kaddr)
 
struct filesock_alloc_file (struct socket *sock, int flags, const char *dname)
 
 EXPORT_SYMBOL (sock_alloc_file)
 
struct socketsock_from_file (struct file *file, int *err)
 
 EXPORT_SYMBOL (sock_from_file)
 
struct socketsockfd_lookup (int fd, int *err)
 
 EXPORT_SYMBOL (sockfd_lookup)
 
void sock_release (struct socket *sock)
 
 EXPORT_SYMBOL (sock_release)
 
int sock_tx_timestamp (struct sock *sk, __u8 *tx_flags)
 
 EXPORT_SYMBOL (sock_tx_timestamp)
 
int sock_sendmsg (struct socket *sock, struct msghdr *msg, size_t size)
 
 EXPORT_SYMBOL (sock_sendmsg)
 
int kernel_sendmsg (struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t size)
 
 EXPORT_SYMBOL (kernel_sendmsg)
 
void __sock_recv_timestamp (struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
 
 EXPORT_SYMBOL_GPL (__sock_recv_timestamp)
 
void __sock_recv_wifi_status (struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
 
 EXPORT_SYMBOL_GPL (__sock_recv_wifi_status)
 
void __sock_recv_ts_and_drops (struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
 
 EXPORT_SYMBOL_GPL (__sock_recv_ts_and_drops)
 
int sock_recvmsg (struct socket *sock, struct msghdr *msg, size_t size, int flags)
 
 EXPORT_SYMBOL (sock_recvmsg)
 
int kernel_recvmsg (struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t size, int flags)
 
 EXPORT_SYMBOL (kernel_recvmsg)
 
void brioctl_set (int(*hook)(struct net *, unsigned int, void __user *))
 
 EXPORT_SYMBOL (brioctl_set)
 
void vlan_ioctl_set (int(*hook)(struct net *, void __user *))
 
 EXPORT_SYMBOL (vlan_ioctl_set)
 
void dlci_ioctl_set (int(*hook)(unsigned int, void __user *))
 
 EXPORT_SYMBOL (dlci_ioctl_set)
 
int sock_create_lite (int family, int type, int protocol, struct socket **res)
 
 EXPORT_SYMBOL (sock_create_lite)
 
int sock_wake_async (struct socket *sock, int how, int band)
 
 EXPORT_SYMBOL (sock_wake_async)
 
int __sock_create (struct net *net, int family, int type, int protocol, struct socket **res, int kern)
 
 EXPORT_SYMBOL (__sock_create)
 
int sock_create (int family, int type, int protocol, struct socket **res)
 
 EXPORT_SYMBOL (sock_create)
 
int sock_create_kern (int family, int type, int protocol, struct socket **res)
 
 EXPORT_SYMBOL (sock_create_kern)
 
 SYSCALL_DEFINE3 (socket, int, family, int, type, int, protocol)
 
 SYSCALL_DEFINE4 (socketpair, int, family, int, type, int, protocol, int __user *, usockvec)
 
 SYSCALL_DEFINE3 (bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
 
 SYSCALL_DEFINE2 (listen, int, fd, int, backlog)
 
 SYSCALL_DEFINE4 (accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, int __user *, upeer_addrlen, int, flags)
 
 SYSCALL_DEFINE3 (accept, int, fd, struct sockaddr __user *, upeer_sockaddr, int __user *, upeer_addrlen)
 
 SYSCALL_DEFINE3 (connect, int, fd, struct sockaddr __user *, uservaddr, int, addrlen)
 
 SYSCALL_DEFINE3 (getsockname, int, fd, struct sockaddr __user *, usockaddr, int __user *, usockaddr_len)
 
 SYSCALL_DEFINE3 (getpeername, int, fd, struct sockaddr __user *, usockaddr, int __user *, usockaddr_len)
 
 SYSCALL_DEFINE6 (sendto, int, fd, void __user *, buff, size_t, len, unsigned int, flags, struct sockaddr __user *, addr, int, addr_len)
 
 SYSCALL_DEFINE4 (send, int, fd, void __user *, buff, size_t, len, unsigned int, flags)
 
 SYSCALL_DEFINE6 (recvfrom, int, fd, void __user *, ubuf, size_t, size, unsigned int, flags, struct sockaddr __user *, addr, int __user *, addr_len)
 
asmlinkage long sys_recv (int fd, void __user *ubuf, size_t size, unsigned int flags)
 
 SYSCALL_DEFINE5 (setsockopt, int, fd, int, level, int, optname, char __user *, optval, int, optlen)
 
 SYSCALL_DEFINE5 (getsockopt, int, fd, int, level, int, optname, char __user *, optval, int __user *, optlen)
 
 SYSCALL_DEFINE2 (shutdown, int, fd, int, how)
 
 SYSCALL_DEFINE3 (sendmsg, int, fd, struct msghdr __user *, msg, unsigned int, flags)
 
int __sys_sendmmsg (int fd, struct mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags)
 
 SYSCALL_DEFINE4 (sendmmsg, int, fd, struct mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags)
 
 SYSCALL_DEFINE3 (recvmsg, int, fd, struct msghdr __user *, msg, unsigned int, flags)
 
int __sys_recvmmsg (int fd, struct mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags, struct timespec *timeout)
 
 SYSCALL_DEFINE5 (recvmmsg, int, fd, struct mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, struct timespec __user *, timeout)
 
int sock_register (const struct net_proto_family *ops)
 
 EXPORT_SYMBOL (sock_register)
 
void sock_unregister (int family)
 
 EXPORT_SYMBOL (sock_unregister)
 
 core_initcall (sock_init)
 
int kernel_bind (struct socket *sock, struct sockaddr *addr, int addrlen)
 
 EXPORT_SYMBOL (kernel_bind)
 
int kernel_listen (struct socket *sock, int backlog)
 
 EXPORT_SYMBOL (kernel_listen)
 
int kernel_accept (struct socket *sock, struct socket **newsock, int flags)
 
 EXPORT_SYMBOL (kernel_accept)
 
int kernel_connect (struct socket *sock, struct sockaddr *addr, int addrlen, int flags)
 
 EXPORT_SYMBOL (kernel_connect)
 
int kernel_getsockname (struct socket *sock, struct sockaddr *addr, int *addrlen)
 
 EXPORT_SYMBOL (kernel_getsockname)
 
int kernel_getpeername (struct socket *sock, struct sockaddr *addr, int *addrlen)
 
 EXPORT_SYMBOL (kernel_getpeername)
 
int kernel_getsockopt (struct socket *sock, int level, int optname, char *optval, int *optlen)
 
 EXPORT_SYMBOL (kernel_getsockopt)
 
int kernel_setsockopt (struct socket *sock, int level, int optname, char *optval, unsigned int optlen)
 
 EXPORT_SYMBOL (kernel_setsockopt)
 
int kernel_sendpage (struct socket *sock, struct page *page, int offset, size_t size, int flags)
 
 EXPORT_SYMBOL (kernel_sendpage)
 
int kernel_sock_ioctl (struct socket *sock, int cmd, unsigned long arg)
 
 EXPORT_SYMBOL (kernel_sock_ioctl)
 
int kernel_sock_shutdown (struct socket *sock, enum sock_shutdown_cmd how)
 
 EXPORT_SYMBOL (kernel_sock_shutdown)
 

Variables

struct file_operations bad_sock_fops
 

Macro Definition Documentation

#define COMPAT_FLAGS (   msg)    COMPAT_MSG(msg, msg_flags)

Definition at line 1982 of file socket.c.

#define COMPAT_MSG (   msg,
  member 
)    ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)

Definition at line 1980 of file socket.c.

#define COMPAT_NAMELEN (   msg)    COMPAT_MSG(msg, msg_namelen)

Definition at line 1981 of file socket.c.

#define XATTR_NAME_SOCKPROTONAME   (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)

Definition at line 463 of file socket.c.

#define XATTR_NAME_SOCKPROTONAME_LEN   (sizeof(XATTR_NAME_SOCKPROTONAME)-1)

Definition at line 464 of file socket.c.

#define XATTR_SOCKPROTONAME_SUFFIX   "sockprotoname"

Definition at line 462 of file socket.c.

Function Documentation

int __sock_create ( struct net net,
int  family,
int  type,
int  protocol,
struct socket **  res,
int  kern 
)

Definition at line 1265 of file socket.c.

void __sock_recv_timestamp ( struct msghdr msg,
struct sock sk,
struct sk_buff skb 
)

Definition at line 702 of file socket.c.

void __sock_recv_ts_and_drops ( struct msghdr msg,
struct sock sk,
struct sk_buff skb 
)

Definition at line 774 of file socket.c.

void __sock_recv_wifi_status ( struct msghdr msg,
struct sock sk,
struct sk_buff skb 
)

Definition at line 750 of file socket.c.

int __sys_recvmmsg ( int  fd,
struct mmsghdr __user mmsg,
unsigned int  vlen,
unsigned int  flags,
struct timespec timeout 
)

Definition at line 2298 of file socket.c.

int __sys_sendmmsg ( int  fd,
struct mmsghdr __user mmsg,
unsigned int  vlen,
unsigned int  flags 
)

Definition at line 2124 of file socket.c.

void brioctl_set ( int(*)(struct net *, unsigned int, void __user *)  hook)

Definition at line 1006 of file socket.c.

core_initcall ( sock_init  )
void dlci_ioctl_set ( int(*)(unsigned int, void __user *)  hook)

Definition at line 1028 of file socket.c.

EXPORT_SYMBOL ( sock_alloc_file  )
EXPORT_SYMBOL ( sock_from_file  )
EXPORT_SYMBOL ( sockfd_lookup  )
EXPORT_SYMBOL ( sock_release  )
EXPORT_SYMBOL ( sock_tx_timestamp  )
EXPORT_SYMBOL ( sock_sendmsg  )
EXPORT_SYMBOL ( kernel_sendmsg  )
EXPORT_SYMBOL ( sock_recvmsg  )
EXPORT_SYMBOL ( kernel_recvmsg  )
EXPORT_SYMBOL ( brioctl_set  )
EXPORT_SYMBOL ( vlan_ioctl_set  )
EXPORT_SYMBOL ( dlci_ioctl_set  )
EXPORT_SYMBOL ( sock_create_lite  )
EXPORT_SYMBOL ( sock_wake_async  )
EXPORT_SYMBOL ( __sock_create  )
EXPORT_SYMBOL ( sock_create  )
EXPORT_SYMBOL ( sock_create_kern  )
EXPORT_SYMBOL ( sock_register  )
EXPORT_SYMBOL ( sock_unregister  )
EXPORT_SYMBOL ( kernel_bind  )
EXPORT_SYMBOL ( kernel_listen  )
EXPORT_SYMBOL ( kernel_accept  )
EXPORT_SYMBOL ( kernel_connect  )
EXPORT_SYMBOL ( kernel_getsockname  )
EXPORT_SYMBOL ( kernel_getpeername  )
EXPORT_SYMBOL ( kernel_getsockopt  )
EXPORT_SYMBOL ( kernel_setsockopt  )
EXPORT_SYMBOL ( kernel_sendpage  )
EXPORT_SYMBOL ( kernel_sock_ioctl  )
EXPORT_SYMBOL ( kernel_sock_shutdown  )
EXPORT_SYMBOL_GPL ( __sock_recv_timestamp  )
EXPORT_SYMBOL_GPL ( __sock_recv_wifi_status  )
EXPORT_SYMBOL_GPL ( __sock_recv_ts_and_drops  )
int kernel_accept ( struct socket sock,
struct socket **  newsock,
int  flags 
)

Definition at line 3349 of file socket.c.

int kernel_bind ( struct socket sock,
struct sockaddr addr,
int  addrlen 
)

Definition at line 3337 of file socket.c.

int kernel_connect ( struct socket sock,
struct sockaddr addr,
int  addrlen,
int  flags 
)

Definition at line 3374 of file socket.c.

int kernel_getpeername ( struct socket sock,
struct sockaddr addr,
int addrlen 
)

Definition at line 3388 of file socket.c.

int kernel_getsockname ( struct socket sock,
struct sockaddr addr,
int addrlen 
)

Definition at line 3381 of file socket.c.

int kernel_getsockopt ( struct socket sock,
int  level,
int  optname,
char optval,
int optlen 
)

Definition at line 3395 of file socket.c.

int kernel_listen ( struct socket sock,
int  backlog 
)

Definition at line 3343 of file socket.c.

int kernel_recvmsg ( struct socket sock,
struct msghdr msg,
struct kvec vec,
size_t  num,
size_t  size,
int  flags 
)

kernel_recvmsg - Receive a message from a socket (kernel space) : The socket to receive the message from : Received message : Input s/g array for message data : Size of input s/g array : Number of bytes to read : Message flags (MSG_DONTWAIT, etc...)

On return the msg structure contains the scatter/gather array passed in the vec argument. The array is modified so that it consists of the unfilled portion of the original array.

The returned value is the total number of bytes received, or an error.

Definition at line 852 of file socket.c.

int kernel_sendmsg ( struct socket sock,
struct msghdr msg,
struct kvec vec,
size_t  num,
size_t  size 
)

Definition at line 670 of file socket.c.

int kernel_sendpage ( struct socket sock,
struct page page,
int  offset,
size_t  size,
int  flags 
)

Definition at line 3437 of file socket.c.

int kernel_setsockopt ( struct socket sock,
int  level,
int  optname,
char optval,
unsigned int  optlen 
)

Definition at line 3417 of file socket.c.

int kernel_sock_ioctl ( struct socket sock,
int  cmd,
unsigned long  arg 
)

Definition at line 3449 of file socket.c.

int kernel_sock_shutdown ( struct socket sock,
enum sock_shutdown_cmd  how 
)

Definition at line 3462 of file socket.c.

int move_addr_to_kernel ( void __user uaddr,
int  ulen,
struct sockaddr_storage kaddr 
)

move_addr_to_kernel - copy a socket address into kernel space : Address in user space : Address in kernel space : Length in user space

The address is copied into kernel space. If the provided address is too long an error code of -EINVAL is returned. If the copy gives invalid addresses -EFAULT is returned. On a success 0 is returned.

Definition at line 185 of file socket.c.

struct file* sock_alloc_file ( struct socket sock,
int  flags,
const char dname 
)
read

Definition at line 350 of file socket.c.

int sock_create ( int  family,
int  type,
int  protocol,
struct socket **  res 
)

Definition at line 1378 of file socket.c.

int sock_create_kern ( int  family,
int  type,
int  protocol,
struct socket **  res 
)

Definition at line 1384 of file socket.c.

int sock_create_lite ( int  family,
int  type,
int  protocol,
struct socket **  res 
)

Definition at line 1133 of file socket.c.

struct socket* sock_from_file ( struct file file,
int err 
)
read

Definition at line 405 of file socket.c.

int sock_recvmsg ( struct socket sock,
struct msghdr msg,
size_t  size,
int  flags 
)

Definition at line 806 of file socket.c.

int sock_register ( const struct net_proto_family ops)

sock_register - add a socket protocol handler : description of protocol

This function is called by a protocol handler that wants to advertise its address family, and have it linked into the socket interface. The value ops->family coresponds to the socket system call protocol family.

Definition at line 2557 of file socket.c.

void sock_release ( struct socket sock)

sock_release - close a socket : socket to close

The socket is released from the protocol stack if it has a release callback, and the inode is then released if the socket is bound to an inode not a file.

Definition at line 580 of file socket.c.

int sock_sendmsg ( struct socket sock,
struct msghdr msg,
size_t  size 
)

Definition at line 641 of file socket.c.

int sock_tx_timestamp ( struct sock sk,
__u8 tx_flags 
)

sock_tx_timestamp - checks whether the outgoing packet is to be time stamped : socket sending this packet : filled with instructions for time stamping

Currently only depends on SOCK_TIMESTAMPING* flags. Returns error code if parameters are invalid.

Definition at line 605 of file socket.c.

void sock_unregister ( int  family)

sock_unregister - remove a protocol handler : protocol family to remove

This function is called by a protocol handler that wants to remove its address family, and have it unlinked from the new socket creation.

If protocol handler is a module, then it can use module reference counts to protect against new references. If protocol handler is not a module then it needs to provide its own protection in the ops->create routine.

Definition at line 2595 of file socket.c.

int sock_wake_async ( struct socket sock,
int  how,
int  band 
)

Definition at line 1232 of file socket.c.

struct socket* sockfd_lookup ( int  fd,
int err 
)
read

sockfd_lookup - Go from a file number to its socket slot : file handle : pointer to an error code return

The file handle passed in is locked and the socket it is bound too is returned. If an error occurs the err pointer is overwritten with a negative errno code and NULL is returned. The function checks for both invalid handles and passing a handle which is not a socket.

On a success the socket object pointer is returned.

Definition at line 428 of file socket.c.

asmlinkage long sys_recv ( int  fd,
void __user ubuf,
size_t  size,
unsigned int  flags 
)

Definition at line 1887 of file socket.c.

SYSCALL_DEFINE2 ( listen  ,
int  ,
fd  ,
int  ,
backlog   
)

Definition at line 1556 of file socket.c.

SYSCALL_DEFINE2 ( shutdown  ,
int  ,
fd  ,
int  ,
how   
)

Definition at line 1962 of file socket.c.

SYSCALL_DEFINE3 ( socket  ,
int  ,
family  ,
int  ,
type  ,
int  ,
protocol   
)

Definition at line 1390 of file socket.c.

SYSCALL_DEFINE3 ( bind  ,
int  ,
fd  ,
struct sockaddr __user ,
umyaddr  ,
int  ,
addrlen   
)

Definition at line 1527 of file socket.c.

SYSCALL_DEFINE3 ( accept  ,
int  ,
fd  ,
struct sockaddr __user ,
upeer_sockaddr  ,
int __user ,
upeer_addrlen   
)

Definition at line 1670 of file socket.c.

SYSCALL_DEFINE3 ( connect  ,
int  ,
fd  ,
struct sockaddr __user ,
uservaddr  ,
int  ,
addrlen   
)

Definition at line 1688 of file socket.c.

SYSCALL_DEFINE3 ( getsockname  ,
int  ,
fd  ,
struct sockaddr __user ,
usockaddr  ,
int __user ,
usockaddr_len   
)

Definition at line 1720 of file socket.c.

SYSCALL_DEFINE3 ( getpeername  ,
int  ,
fd  ,
struct sockaddr __user ,
usockaddr  ,
int __user ,
usockaddr_len   
)

Definition at line 1751 of file socket.c.

SYSCALL_DEFINE3 ( sendmsg  ,
int  ,
fd  ,
struct msghdr __user ,
msg  ,
unsigned  int,
flags   
)

Definition at line 2104 of file socket.c.

SYSCALL_DEFINE3 ( recvmsg  ,
int  ,
fd  ,
struct msghdr __user ,
msg  ,
unsigned  int,
flags   
)

Definition at line 2277 of file socket.c.

SYSCALL_DEFINE4 ( socketpair  ,
int  ,
family  ,
int  ,
type  ,
int  ,
protocol  ,
int __user ,
usockvec   
)

Definition at line 1431 of file socket.c.

SYSCALL_DEFINE4 ( accept4  ,
int  ,
fd  ,
struct sockaddr __user ,
upeer_sockaddr  ,
int __user ,
upeer_addrlen  ,
int  ,
flags   
)

Definition at line 1589 of file socket.c.

SYSCALL_DEFINE4 ( send  ,
int  ,
fd  ,
void __user ,
buff  ,
size_t  ,
len  ,
unsigned  int,
flags   
)

Definition at line 1830 of file socket.c.

SYSCALL_DEFINE4 ( sendmmsg  ,
int  ,
fd  ,
struct mmsghdr __user ,
mmsg  ,
unsigned  int,
vlen  ,
unsigned  int,
flags   
)

Definition at line 2179 of file socket.c.

SYSCALL_DEFINE5 ( setsockopt  ,
int  ,
fd  ,
int  ,
level  ,
int  ,
optname  ,
char __user ,
optval  ,
int  ,
optlen   
)

Definition at line 1898 of file socket.c.

SYSCALL_DEFINE5 ( getsockopt  ,
int  ,
fd  ,
int  ,
level  ,
int  ,
optname  ,
char __user ,
optval  ,
int __user ,
optlen   
)

Definition at line 1932 of file socket.c.

SYSCALL_DEFINE5 ( recvmmsg  ,
int  ,
fd  ,
struct mmsghdr __user ,
mmsg  ,
unsigned  int,
vlen  ,
unsigned  int,
flags  ,
struct timespec __user ,
timeout   
)

Definition at line 2401 of file socket.c.

SYSCALL_DEFINE6 ( sendto  ,
int  ,
fd  ,
void __user ,
buff  ,
size_t  ,
len  ,
unsigned  int,
flags  ,
struct sockaddr __user ,
addr  ,
int  ,
addr_len   
)

Definition at line 1783 of file socket.c.

SYSCALL_DEFINE6 ( recvfrom  ,
int  ,
fd  ,
void __user ,
ubuf  ,
size_t  ,
size  ,
unsigned  int,
flags  ,
struct sockaddr __user ,
addr  ,
int __user ,
addr_len   
)

Definition at line 1842 of file socket.c.

void vlan_ioctl_set ( int(*)(struct net *, void __user *)  hook)

Definition at line 1017 of file socket.c.

Variable Documentation

struct file_operations bad_sock_fops
Initial value:
= {
.owner = THIS_MODULE,
.open = sock_no_open,
.llseek = noop_llseek,
}

Definition at line 565 of file socket.c.