Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
net.h File Reference
#include <linux/stringify.h>
#include <linux/random.h>
#include <linux/wait.h>
#include <linux/fcntl.h>
#include <linux/kmemcheck.h>
#include <linux/rcupdate.h>
#include <uapi/linux/net.h>

Go to the source code of this file.

Data Structures

struct  socket_wq
 
struct  socket
 
struct  proto_ops
 
struct  net_proto_family
 

Macros

#define SOCK_ASYNC_NOSPACE   0
 
#define SOCK_ASYNC_WAITDATA   1
 
#define SOCK_NOSPACE   2
 
#define SOCK_PASSCRED   3
 
#define SOCK_PASSSEC   4
 
#define SOCK_EXTERNALLY_ALLOCATED   5
 
#define SOCK_MAX   (SOCK_PACKET + 1)
 
#define SOCK_TYPE_MASK   0xf
 
#define SOCK_CLOEXEC   O_CLOEXEC
 
#define SOCK_NONBLOCK   O_NONBLOCK
 
#define DECLARE_SOCKADDR(type, dst, src)   type dst = ({ __sockaddr_check_size(sizeof(*dst)); (type) src; })
 
#define sockfd_put(sock)   fput(sock->file)
 
#define net_ratelimited_function(function,...)
 
#define net_emerg_ratelimited(fmt,...)   net_ratelimited_function(pr_emerg, fmt, ##__VA_ARGS__)
 
#define net_alert_ratelimited(fmt,...)   net_ratelimited_function(pr_alert, fmt, ##__VA_ARGS__)
 
#define net_crit_ratelimited(fmt,...)   net_ratelimited_function(pr_crit, fmt, ##__VA_ARGS__)
 
#define net_err_ratelimited(fmt,...)   net_ratelimited_function(pr_err, fmt, ##__VA_ARGS__)
 
#define net_notice_ratelimited(fmt,...)   net_ratelimited_function(pr_notice, fmt, ##__VA_ARGS__)
 
#define net_warn_ratelimited(fmt,...)   net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
 
#define net_info_ratelimited(fmt,...)   net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
 
#define net_dbg_ratelimited(fmt,...)   net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
 
#define net_random()   random32()
 
#define net_srandom(seed)   srandom32((__force u32)seed)
 
#define MODULE_ALIAS_NETPROTO(proto)   MODULE_ALIAS("net-pf-" __stringify(proto))
 
#define MODULE_ALIAS_NET_PF_PROTO(pf, proto)   MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto))
 
#define MODULE_ALIAS_NET_PF_PROTO_TYPE(pf, proto, type)
 
#define MODULE_ALIAS_NET_PF_PROTO_NAME(pf, proto, name)
 

Enumerations

enum  sock_type {
  SOCK_DGRAM = 1, SOCK_STREAM = 2, SOCK_RAW = 3, SOCK_RDM = 4,
  SOCK_SEQPACKET = 5, SOCK_DCCP = 6, SOCK_PACKET = 10, SOCK_STREAM = 1,
  SOCK_DGRAM = 2, SOCK_RAW = 3, SOCK_RDM = 4, SOCK_SEQPACKET = 5,
  SOCK_DCCP = 6, SOCK_PACKET = 10
}
 
enum  sock_shutdown_cmd { SHUT_RD = 0, SHUT_WR = 1, SHUT_RDWR = 2 }
 
enum  { SOCK_WAKE_IO, SOCK_WAKE_WAITD, SOCK_WAKE_SPACE, SOCK_WAKE_URG }
 

Functions

int sock_wake_async (struct socket *sk, int how, int band)
 
int sock_register (const struct net_proto_family *fam)
 
void sock_unregister (int family)
 
int __sock_create (struct net *net, int family, int type, int proto, struct socket **res, int kern)
 
int sock_create (int family, int type, int proto, struct socket **res)
 
int sock_create_kern (int family, int type, int proto, struct socket **res)
 
int sock_create_lite (int family, int type, int proto, struct socket **res)
 
void sock_release (struct socket *sock)
 
int sock_sendmsg (struct socket *sock, struct msghdr *msg, size_t len)
 
int sock_recvmsg (struct socket *sock, struct msghdr *msg, size_t size, int flags)
 
struct filesock_alloc_file (struct socket *sock, int flags, const char *dname)
 
struct socketsockfd_lookup (int fd, int *err)
 
struct socketsock_from_file (struct file *file, int *err)
 
int net_ratelimit (void)
 
int kernel_sendmsg (struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t len)
 
int kernel_recvmsg (struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t len, int flags)
 
int kernel_bind (struct socket *sock, struct sockaddr *addr, int addrlen)
 
int kernel_listen (struct socket *sock, int backlog)
 
int kernel_accept (struct socket *sock, struct socket **newsock, int flags)
 
int kernel_connect (struct socket *sock, struct sockaddr *addr, int addrlen, int flags)
 
int kernel_getsockname (struct socket *sock, struct sockaddr *addr, int *addrlen)
 
int kernel_getpeername (struct socket *sock, struct sockaddr *addr, int *addrlen)
 
int kernel_getsockopt (struct socket *sock, int level, int optname, char *optval, int *optlen)
 
int kernel_setsockopt (struct socket *sock, int level, int optname, char *optval, unsigned int optlen)
 
int kernel_sendpage (struct socket *sock, struct page *page, int offset, size_t size, int flags)
 
int kernel_sock_ioctl (struct socket *sock, int cmd, unsigned long arg)
 
int kernel_sock_shutdown (struct socket *sock, enum sock_shutdown_cmd how)
 

Variables

struct socket_wq ____cacheline_aligned_in_smp
 

Macro Definition Documentation

#define DECLARE_SOCKADDR (   type,
  dst,
  src 
)    type dst = ({ __sockaddr_check_size(sizeof(*dst)); (type) src; })

Definition at line 178 of file net.h.

#define MODULE_ALIAS_NET_PF_PROTO (   pf,
  proto 
)    MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto))

Definition at line 276 of file net.h.

#define MODULE_ALIAS_NET_PF_PROTO_NAME (   pf,
  proto,
  name 
)
Value:
MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto) \

Definition at line 283 of file net.h.

#define MODULE_ALIAS_NET_PF_PROTO_TYPE (   pf,
  proto,
  type 
)
Value:
MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto) \
"-type-" __stringify(type))

Definition at line 279 of file net.h.

#define MODULE_ALIAS_NETPROTO (   proto)    MODULE_ALIAS("net-pf-" __stringify(proto))

Definition at line 273 of file net.h.

#define net_alert_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_alert, fmt, ##__VA_ARGS__)

Definition at line 228 of file net.h.

#define net_crit_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_crit, fmt, ##__VA_ARGS__)

Definition at line 230 of file net.h.

#define net_dbg_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)

Definition at line 240 of file net.h.

#define net_emerg_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_emerg, fmt, ##__VA_ARGS__)

Definition at line 226 of file net.h.

#define net_err_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_err, fmt, ##__VA_ARGS__)

Definition at line 232 of file net.h.

#define net_info_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)

Definition at line 238 of file net.h.

#define net_notice_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_notice, fmt, ##__VA_ARGS__)

Definition at line 234 of file net.h.

#define net_random ( )    random32()

Definition at line 243 of file net.h.

#define net_ratelimited_function (   function,
  ... 
)
Value:
do { \
if (net_ratelimit()) \
function(__VA_ARGS__); \
} while (0)

Definition at line 220 of file net.h.

#define net_srandom (   seed)    srandom32((__force u32)seed)

Definition at line 244 of file net.h.

#define net_warn_ratelimited (   fmt,
  ... 
)    net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)

Definition at line 236 of file net.h.

#define SOCK_ASYNC_NOSPACE   0

Definition at line 35 of file net.h.

#define SOCK_ASYNC_WAITDATA   1

Definition at line 36 of file net.h.

#define SOCK_CLOEXEC   O_CLOEXEC

Definition at line 74 of file net.h.

#define SOCK_EXTERNALLY_ALLOCATED   5

Definition at line 40 of file net.h.

#define SOCK_MAX   (SOCK_PACKET + 1)

Definition at line 68 of file net.h.

#define SOCK_NONBLOCK   O_NONBLOCK

Definition at line 76 of file net.h.

#define SOCK_NOSPACE   2

Definition at line 37 of file net.h.

#define SOCK_PASSCRED   3

Definition at line 38 of file net.h.

#define SOCK_PASSSEC   4

Definition at line 39 of file net.h.

#define SOCK_TYPE_MASK   0xf

Definition at line 71 of file net.h.

#define sockfd_put (   sock)    fput(sock->file)

Definition at line 217 of file net.h.

Enumeration Type Documentation

anonymous enum
Enumerator:
SOCK_WAKE_IO 
SOCK_WAKE_WAITD 
SOCK_WAKE_SPACE 
SOCK_WAKE_URG 

Definition at line 191 of file net.h.

Enumerator:
SHUT_RD 
SHUT_WR 
SHUT_RDWR 

Definition at line 81 of file net.h.

enum sock_type

enum sock_type - Socket types : stream (connection) socket : datagram (conn.less) socket : raw socket : reliably-delivered message : sequential packet socket : Datagram Congestion Control Protocol socket : linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level.

When adding some new socket type please grep ARCH_HAS_SOCKET_TYPE include/asm-* /socket.h, at least MIPS overrides this enum for binary compat reasons.

Enumerator:
SOCK_DGRAM 
SOCK_STREAM 
SOCK_RAW 
SOCK_RDM 
SOCK_SEQPACKET 
SOCK_DCCP 
SOCK_PACKET 
SOCK_STREAM 
SOCK_DGRAM 
SOCK_RAW 
SOCK_RDM 
SOCK_SEQPACKET 
SOCK_DCCP 
SOCK_PACKET 

Definition at line 58 of file net.h.

Function Documentation

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

Definition at line 1265 of file socket.c.

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  len 
)

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 net_ratelimit ( void  )

Definition at line 42 of file utils.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  proto,
struct socket **  res 
)

Definition at line 1378 of file socket.c.

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

Definition at line 1384 of file socket.c.

int sock_create_lite ( int  family,
int  type,
int  proto,
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  len 
)

Definition at line 641 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 sk,
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.

Variable Documentation

struct socket_wq ____cacheline_aligned_in_smp