Main Page | Class List | File List | Class Members | File Members

net.h File Reference

#include <linux/config.h>
#include <linux/socket.h>
#include <linux/wait.h>

Go to the source code of this file.

Classes

struct  socket
struct  proto_ops
struct  net_proto_family
struct  net_proto

Defines

#define NPROTO   32
#define SYS_SOCKET   1
#define SYS_BIND   2
#define SYS_CONNECT   3
#define SYS_LISTEN   4
#define SYS_ACCEPT   5
#define SYS_GETSOCKNAME   6
#define SYS_GETPEERNAME   7
#define SYS_SOCKETPAIR   8
#define SYS_SEND   9
#define SYS_RECV   10
#define SYS_SENDTO   11
#define SYS_RECVFROM   12
#define SYS_SHUTDOWN   13
#define SYS_SETSOCKOPT   14
#define SYS_GETSOCKOPT   15
#define SYS_SENDMSG   16
#define SYS_RECVMSG   17
#define __SO_ACCEPTCON   (1<<16)
#define SOCK_ASYNC_NOSPACE   0
#define SOCK_ASYNC_WAITDATA   1
#define SOCK_NOSPACE   2
#define SOCK_INODE(S)   ((S)->inode)
#define SOCKOPS_WRAPPED(name)   name
#define SOCKOPS_WRAP(name, fam)

Enumerations

enum  socket_state {
  SS_FREE = 0, SS_UNCONNECTED, SS_CONNECTING, SS_CONNECTED,
  SS_DISCONNECTING
}

Functions

int sock_wake_async (struct socket *sk, int how, int band)
int sock_register (struct net_proto_family *fam)
int sock_unregister (int family)
socketsock_alloc (void)
int sock_create (int family, int type, int proto, struct socket **)
void sock_release (struct socket *)
int sock_sendmsg (struct socket *, struct msghdr *m, int len)
int sock_recvmsg (struct socket *, struct msghdr *m, int len, int flags)
int sock_readv_writev (int type, struct inode *inode, struct file *file, const struct iovec *iov, long count, long size)
socketsockfd_lookup (int fd, int *err)
int sock_map_fd (struct socket *sock)
int net_ratelimit (void)
unsigned long net_random (void)
void net_srandom (unsigned long)


Define Documentation

#define __SO_ACCEPTCON   (1<<16)
 

Definition at line 57 of file net.h.

#define NPROTO   32
 

Definition at line 27 of file net.h.

Referenced by dev_ifconf(), netfilter_init(), register_gifconf(), rtnetlink_dump_all(), rtnetlink_rcv_msg(), sock_create(), sock_init(), sock_register(), and sock_unregister().

#define SOCK_ASYNC_NOSPACE   0
 

Definition at line 61 of file net.h.

Referenced by datagram_poll(), do_tcp_sendpages(), sock_alloc_send_pskb(), sock_wait_for_wmem(), sock_wake_async(), tcp_poll(), tcp_sendmsg(), and wait_for_tcp_memory().

#define SOCK_ASYNC_WAITDATA   1
 

Definition at line 62 of file net.h.

Referenced by sock_wake_async(), and tcp_data_wait().

#define SOCK_INODE  )     ((S)->inode)
 

Definition at line 81 of file net.h.

#define SOCK_NOSPACE   2
 

Definition at line 63 of file net.h.

Referenced by do_tcp_sendpages(), sock_alloc_send_pskb(), sock_wait_for_wmem(), tcp_check_space(), tcp_cwnd_application_limited(), tcp_poll(), tcp_sendmsg(), tcp_write_space(), and wait_for_tcp_memory().

#define SOCKOPS_WRAP name,
fam   ) 
 

Definition at line 151 of file net.h.

#define SOCKOPS_WRAPPED name   )     name
 

Definition at line 150 of file net.h.

#define SYS_ACCEPT   5
 

Definition at line 34 of file net.h.

Referenced by sys_socketcall().

#define SYS_BIND   2
 

Definition at line 31 of file net.h.

Referenced by sys_socketcall().

#define SYS_CONNECT   3
 

Definition at line 32 of file net.h.

Referenced by sys_socketcall().

#define SYS_GETPEERNAME   7
 

Definition at line 36 of file net.h.

Referenced by sys_socketcall().

#define SYS_GETSOCKNAME   6
 

Definition at line 35 of file net.h.

Referenced by sys_socketcall().

#define SYS_GETSOCKOPT   15
 

Definition at line 44 of file net.h.

Referenced by sys_socketcall().

#define SYS_LISTEN   4
 

Definition at line 33 of file net.h.

Referenced by sys_socketcall().

#define SYS_RECV   10
 

Definition at line 39 of file net.h.

Referenced by sys_socketcall().

#define SYS_RECVFROM   12
 

Definition at line 41 of file net.h.

Referenced by sys_socketcall().

#define SYS_RECVMSG   17
 

Definition at line 46 of file net.h.

Referenced by sys_socketcall().

#define SYS_SEND   9
 

Definition at line 38 of file net.h.

Referenced by sys_socketcall().

#define SYS_SENDMSG   16
 

Definition at line 45 of file net.h.

Referenced by sys_socketcall().

#define SYS_SENDTO   11
 

Definition at line 40 of file net.h.

Referenced by sys_socketcall().

#define SYS_SETSOCKOPT   14
 

Definition at line 43 of file net.h.

Referenced by sys_socketcall().

#define SYS_SHUTDOWN   13
 

Definition at line 42 of file net.h.

Referenced by sys_socketcall().

#define SYS_SOCKET   1
 

Definition at line 30 of file net.h.

Referenced by sys_socketcall().

#define SYS_SOCKETPAIR   8
 

Definition at line 37 of file net.h.

Referenced by sys_socketcall().


Enumeration Type Documentation

enum socket_state
 

Enumeration values:
SS_FREE 
SS_UNCONNECTED 
SS_CONNECTING 
SS_CONNECTED 
SS_DISCONNECTING 
Definition at line 49 of file net.h.
00049 { 00050 SS_FREE = 0, /* not allocated */ 00051 SS_UNCONNECTED, /* unconnected to any socket */ 00052 SS_CONNECTING, /* in process of connecting */ 00053 SS_CONNECTED, /* connected to socket */ 00054 SS_DISCONNECTING /* in process of disconnecting */ 00055 } socket_state;


Function Documentation

unsigned long net_random void   ) 
 

Definition at line 26 of file core/utils.c.

References net_rand_seed.

Referenced by get_sample_stats(), inet_initpeers(), ip_rt_init(), ip_vs_random_dropentry(), mod_cur_headers(), neigh_rand_reach_time(), net_srandom(), pneigh_enqueue(), and wait_for_tcp_memory().

00027 { 00028 net_rand_seed=net_rand_seed*69069L+1; 00029 return net_rand_seed^jiffies; 00030 }

int net_ratelimit void   ) 
 

Definition at line 47 of file core/utils.c.

References net_msg_burst, and net_msg_cost.

Referenced by __ipq_enqueue_entry(), arpt_error(), asn1_octets_decode(), asn1_oid_decode(), check_for_demasq(), dev_queue_xmit(), dev_queue_xmit_nit(), help(), icmp_address(), icmp_address_reply(), icmp_rcv(), icmp_unreach(), init_conntrack(), inject(), ip_conntrack_expect_related(), ip_conntrack_local(), ip_finish_output2(), ip_forward_options(), ip_frag_create(), ip_frag_reasm(), ip_fw_check(), ip_fw_domatch(), ip_nat_mangle_tcp_packet(), ip_nat_mangle_udp_packet(), ip_rcv_finish(), ip_route_input_slow(), ip_rt_redirect(), ip_rt_send_redirect(), ipmr_cache_report(), ipt_error(), ipt_local_hook(), ipt_local_out_hook(), ipt_tcpmss_target(), masquerade_target(), nat_help(), nf_queue(), rt_garbage_collect(), rt_intern_hash(), snmp_object_decode(), snmp_parse_mangle(), tcp_close(), tcp_out_of_resources(), tcp_parse_options(), tcp_recvmsg(), tcp_retransmit_skb(), tcp_retransmit_timer(), tcp_time_wait(), tcp_v4_checksum_init(), tcp_v4_conn_request(), udp_checksum_init(), and udp_rcv().

00048 { 00049 static spinlock_t ratelimit_lock = SPIN_LOCK_UNLOCKED; 00050 static unsigned long toks = 10*5*HZ; 00051 static unsigned long last_msg; 00052 static int missed; 00053 unsigned long flags; 00054 unsigned long now = jiffies; 00055 00056 spin_lock_irqsave(&ratelimit_lock, flags); 00057 toks += now - last_msg; 00058 last_msg = now; 00059 if (toks > net_msg_burst) 00060 toks = net_msg_burst; 00061 if (toks >= net_msg_cost) { 00062 int lost = missed; 00063 missed = 0; 00064 toks -= net_msg_cost; 00065 spin_unlock_irqrestore(&ratelimit_lock, flags); 00066 if (lost) 00067 printk(KERN_WARNING "NET: %d messages suppressed.\n", lost); 00068 return 1; 00069 } 00070 missed++; 00071 spin_unlock_irqrestore(&ratelimit_lock, flags); 00072 return 0; 00073 }

void net_srandom unsigned  long  ) 
 

Definition at line 32 of file core/utils.c.

References net_rand_seed, and net_random().

Referenced by inet_insert_ifa().

00033 { 00034 net_rand_seed ^= entropy; 00035 net_random(); 00036 }

struct socket* sock_alloc void   ) 
 

Definition at line 434 of file socket.c.

References sock_mnt, socki_lookup(), and SS_UNCONNECTED.

Referenced by sock_create(), and sys_accept().

00435 { 00436 struct inode * inode; 00437 struct socket * sock; 00438 00439 inode = new_inode(sock_mnt->mnt_sb); 00440 if (!inode) 00441 return NULL; 00442 00443 inode->i_dev = NODEV; 00444 sock = socki_lookup(inode); 00445 00446 inode->i_mode = S_IFSOCK|S_IRWXUGO; 00447 inode->i_sock = 1; 00448 inode->i_uid = current->fsuid; 00449 inode->i_gid = current->fsgid; 00450 00451 sock->inode = inode; 00452 init_waitqueue_head(&sock->wait); 00453 sock->fasync_list = NULL; 00454 sock->state = SS_UNCONNECTED; 00455 sock->flags = 0; 00456 sock->ops = NULL; 00457 sock->sk = NULL; 00458 sock->file = NULL; 00459 00460 sockets_in_use[smp_processor_id()].counter++; 00461 return sock; 00462 }

int sock_create int  family,
int  type,
int  proto,
struct socket ** 
 

Definition at line 824 of file socket.c.

References net_proto_family::create, net_families, net_family_read_lock, net_family_read_unlock, NPROTO, sock_alloc(), and sock_release().

Referenced by make_receive_sock(), make_send_sock(), sys_socket(), and sys_socketpair().

00825 { 00826 int i; 00827 struct socket *sock; 00828 00829 /* 00830 * Check protocol is in range 00831 */ 00832 if (family < 0 || family >= NPROTO) 00833 return -EAFNOSUPPORT; 00834 if (type < 0 || type >= SOCK_MAX) 00835 return -EINVAL; 00836 00837 /* Compatibility. 00838 00839 This uglymoron is moved from INET layer to here to avoid 00840 deadlock in module load. 00841 */ 00842 if (family == PF_INET && type == SOCK_PACKET) { 00843 static int warned; 00844 if (!warned) { 00845 warned = 1; 00846 printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", current->comm); 00847 } 00848 family = PF_PACKET; 00849 } 00850 00851 #if defined(CONFIG_KMOD) && defined(CONFIG_NET) 00852 /* Attempt to load a protocol module if the find failed. 00853 * 00854 * 12/09/1996 Marcin: But! this makes REALLY only sense, if the user 00855 * requested real, full-featured networking support upon configuration. 00856 * Otherwise module support will break! 00857 */ 00858 if (net_families[family]==NULL) 00859 { 00860 char module_name[30]; 00861 sprintf(module_name,"net-pf-%d",family); 00862 request_module(module_name); 00863 } 00864 #endif 00865 00866 net_family_read_lock(); 00867 if (net_families[family] == NULL) { 00868 i = -EAFNOSUPPORT; 00869 goto out; 00870 } 00871 00872 /* 00873 * Allocate the socket and allow the family to set things up. if 00874 * the protocol is 0, the family is instructed to select an appropriate 00875 * default. 00876 */ 00877 00878 if (!(sock = sock_alloc())) 00879 { 00880 printk(KERN_WARNING "socket: no more sockets\n"); 00881 i = -ENFILE; /* Not exactly a match, but its the 00882 closest posix thing */ 00883 goto out; 00884 } 00885 00886 sock->type = type; 00887 00888 if ((i = net_families[family]->create(sock, protocol)) < 0) 00889 { 00890 sock_release(sock); 00891 goto out; 00892 } 00893 00894 *res = sock; 00895 00896 out: 00897 net_family_read_unlock(); 00898 return i; 00899 }

int sock_map_fd struct socket sock  ) 
 

Definition at line 328 of file socket.c.

References socket::file, socket::inode, sock_mnt, socket_file_ops, and sockfs_dentry_operations.

Referenced by sys_accept(), sys_socket(), and sys_socketpair().

00329 { 00330 int fd; 00331 struct qstr this; 00332 char name[32]; 00333 00334 /* 00335 * Find a file descriptor suitable for return to the user. 00336 */ 00337 00338 fd = get_unused_fd(); 00339 if (fd >= 0) { 00340 struct file *file = get_empty_filp(); 00341 00342 if (!file) { 00343 put_unused_fd(fd); 00344 fd = -ENFILE; 00345 goto out; 00346 } 00347 00348 sprintf(name, "[%lu]", sock->inode->i_ino); 00349 this.name = name; 00350 this.len = strlen(name); 00351 this.hash = sock->inode->i_ino; 00352 00353 file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this); 00354 if (!file->f_dentry) { 00355 put_filp(file); 00356 put_unused_fd(fd); 00357 fd = -ENOMEM; 00358 goto out; 00359 } 00360 file->f_dentry->d_op = &sockfs_dentry_operations; 00361 d_add(file->f_dentry, sock->inode); 00362 file->f_vfsmnt = mntget(sock_mnt); 00363 00364 sock->file = file; 00365 file->f_op = sock->inode->i_fop = &socket_file_ops; 00366 file->f_mode = 3; 00367 file->f_flags = O_RDWR; 00368 file->f_pos = 0; 00369 fd_install(fd, file); 00370 } 00371 00372 out: 00373 return fd; 00374 }

int sock_readv_writev int  type,
struct inode *  inode,
struct file *  file,
const struct iovec *  iov,
long  count,
long  size
 

Definition at line 613 of file socket.c.

References sock_recvmsg(), sock_sendmsg(), and socki_lookup().

Referenced by sock_readv(), and sock_writev().

00615 { 00616 struct msghdr msg; 00617 struct socket *sock; 00618 00619 sock = socki_lookup(inode); 00620 00621 msg.msg_name = NULL; 00622 msg.msg_namelen = 0; 00623 msg.msg_control = NULL; 00624 msg.msg_controllen = 0; 00625 msg.msg_iov = (struct iovec *) iov; 00626 msg.msg_iovlen = count; 00627 msg.msg_flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0; 00628 00629 /* read() does a VERIFY_WRITE */ 00630 if (type == VERIFY_WRITE) 00631 return sock_recvmsg(sock, &msg, size, msg.msg_flags); 00632 00633 if (sock->type == SOCK_SEQPACKET) 00634 msg.msg_flags |= MSG_EOR; 00635 00636 return sock_sendmsg(sock, &msg, size); 00637 }

int sock_recvmsg struct socket ,
struct msghdr *  m,
int  len,
int  flags
 

Definition at line 513 of file socket.c.

References socket::ops, proto_ops::recvmsg, and scm_recv().

Referenced by ip_vs_receive(), sock_read(), sock_readv_writev(), sys_recvfrom(), and sys_recvmsg().

00514 { 00515 struct scm_cookie scm; 00516 00517 memset(&scm, 0, sizeof(scm)); 00518 00519 size = sock->ops->recvmsg(sock, msg, size, flags, &scm); 00520 if (size >= 0) 00521 scm_recv(sock, msg, &scm, flags); 00522 00523 return size; 00524 }

int sock_register struct net_proto_family fam  ) 
 

Definition at line 1620 of file socket.c.

References net_proto_family::family, net_families, net_family_write_lock, net_family_write_unlock, and NPROTO.

Referenced by inet_init().

01621 { 01622 int err; 01623 01624 if (ops->family >= NPROTO) { 01625 printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, NPROTO); 01626 return -ENOBUFS; 01627 } 01628 net_family_write_lock(); 01629 err = -EEXIST; 01630 if (net_families[ops->family] == NULL) { 01631 net_families[ops->family]=ops; 01632 err = 0; 01633 } 01634 net_family_write_unlock(); 01635 return err; 01636 }

void sock_release struct socket  ) 
 

Definition at line 484 of file socket.c.

References socket::fasync_list, socket::file, socket::inode, socket::ops, and proto_ops::release.

Referenced by fini(), init(), init_or_cleanup(), ipfw_init_or_cleanup(), make_receive_sock(), make_send_sock(), sock_close(), sock_create(), sync_backup_loop(), sync_master_loop(), sys_accept(), sys_socket(), and sys_socketpair().

00485 { 00486 if (sock->ops) 00487 sock->ops->release(sock); 00488 00489 if (sock->fasync_list) 00490 printk(KERN_ERR "sock_release: fasync list not empty!\n"); 00491 00492 sockets_in_use[smp_processor_id()].counter--; 00493 if (!sock->file) { 00494 iput(sock->inode); 00495 return; 00496 } 00497 sock->file=NULL; 00498 }

int sock_sendmsg struct socket ,
struct msghdr *  m,
int  len
 

Definition at line 500 of file socket.c.

References socket::ops, scm_destroy(), scm_send(), and proto_ops::sendmsg.

Referenced by ip_vs_send_async(), sock_no_sendpage(), sock_readv_writev(), sock_write(), sys_sendmsg(), and sys_sendto().

00501 { 00502 int err; 00503 struct scm_cookie scm; 00504 00505 err = scm_send(sock, msg, &scm); 00506 if (err >= 0) { 00507 err = sock->ops->sendmsg(sock, msg, size, &scm); 00508 scm_destroy(&scm); 00509 } 00510 return err; 00511 }

int sock_unregister int  family  ) 
 

Definition at line 1644 of file socket.c.

References net_families, net_family_write_lock, net_family_write_unlock, and NPROTO.

01645 { 01646 if (family < 0 || family >= NPROTO) 01647 return -1; 01648 01649 net_family_write_lock(); 01650 net_families[family]=NULL; 01651 net_family_write_unlock(); 01652 return 0; 01653 }

int sock_wake_async struct socket sk,
int  how,
int  band
 

Definition at line 798 of file socket.c.

References socket::fasync_list, socket::flags, SOCK_ASYNC_NOSPACE, and SOCK_ASYNC_WAITDATA.

Referenced by sk_wake_async(), and tcp_write_space().

00799 { 00800 if (!sock || !sock->fasync_list) 00801 return -1; 00802 switch (how) 00803 { 00804 case 1: 00805 00806 if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags)) 00807 break; 00808 goto call_kill; 00809 case 2: 00810 if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags)) 00811 break; 00812 /* fall through */ 00813 case 0: 00814 call_kill: 00815 __kill_fasync(sock->fasync_list, SIGIO, band); 00816 break; 00817 case 3: 00818 __kill_fasync(sock->fasync_list, SIGURG, band); 00819 } 00820 return 0; 00821 }

struct socket* sockfd_lookup int  fd,
int *  err
 

Definition at line 394 of file socket.c.

References socki_lookup().

Referenced by sys_accept(), sys_bind(), sys_connect(), sys_getpeername(), sys_getsockname(), sys_getsockopt(), sys_listen(), sys_recvfrom(), sys_recvmsg(), sys_sendmsg(), sys_sendto(), sys_setsockopt(), and sys_shutdown().

00395 { 00396 struct file *file; 00397 struct inode *inode; 00398 struct socket *sock; 00399 00400 if (!(file = fget(fd))) 00401 { 00402 *err = -EBADF; 00403 return NULL; 00404 } 00405 00406 inode = file->f_dentry->d_inode; 00407 if (!inode->i_sock || !(sock = socki_lookup(inode))) 00408 { 00409 *err = -ENOTSOCK; 00410 fput(file); 00411 return NULL; 00412 } 00413 00414 if (sock->file != file) { 00415 printk(KERN_ERR "socki_lookup: socket file changed!\n"); 00416 sock->file = file; 00417 } 00418 return sock; 00419 }


Generated on Wed Dec 1 21:25:38 2004 for Linux 2.4.23 Networking by doxygen 1.3.8