1/* 2 * NET An implementation of the SOCKET network access protocol. 3 * This is the master header file for the Linux NET layer, 4 * or, in plain English: the networking handling part of the 5 * kernel. 6 * 7 * Version: @(#)net.h 1.0.3 05/25/93 8 * 9 * Authors: Orest Zborowski, <obz@Kodak.COM> 10 * Ross Biro, <bir7@leland.Stanford.Edu> 11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 16 * 2 of the License, or (at your option) any later version. 17 */ 18#ifndef _LINUX_NET_H 19#define _LINUX_NET_H 20 21#include <linux/config.h> 22#include <linux/socket.h> 23#include <linux/wait.h> 24 25struct poll_table_struct; 26 27#define NPROTO 32 /* should be enough for now.. */ 28 29 30#define SYS_SOCKET 1 /* sys_socket(2) */ 31#define SYS_BIND 2 /* sys_bind(2) */ 32#define SYS_CONNECT 3 /* sys_connect(2) */ 33#define SYS_LISTEN 4 /* sys_listen(2) */ 34#define SYS_ACCEPT 5 /* sys_accept(2) */ 35#define SYS_GETSOCKNAME 6 /* sys_getsockname(2) */ 36#define SYS_GETPEERNAME 7 /* sys_getpeername(2) */ 37#define SYS_SOCKETPAIR 8 /* sys_socketpair(2) */ 38#define SYS_SEND 9 /* sys_send(2) */ 39#define SYS_RECV 10 /* sys_recv(2) */ 40#define SYS_SENDTO 11 /* sys_sendto(2) */ 41#define SYS_RECVFROM 12 /* sys_recvfrom(2) */ 42#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */ 43#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */ 44#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */ 45#define SYS_SENDMSG 16 /* sys_sendmsg(2) */ 46#define SYS_RECVMSG 17 /* sys_recvmsg(2) */ 47 48 49typedef enum { 50 SS_FREE = 0, /* not allocated */ 51 SS_UNCONNECTED, /* unconnected to any socket */ 52 SS_CONNECTING, /* in process of connecting */ 53 SS_CONNECTED, /* connected to socket */ 54 SS_DISCONNECTING /* in process of disconnecting */ 55} socket_state; 56 57#define __SO_ACCEPTCON (1<<16) /* performed a listen */ 58 59#ifdef __KERNEL__ 60 61#define SOCK_ASYNC_NOSPACE 0 62#define SOCK_ASYNC_WAITDATA 1 63#define SOCK_NOSPACE 2 64 65struct socket 66{ 67 socket_state state; 68 69 unsigned long flags; 70 struct proto_ops *ops; 71 struct inode *inode; 72 struct fasync_struct *fasync_list; /* Asynchronous wake up list */ 73 struct file *file; /* File back pointer for gc */ 74 struct sock *sk; 75 wait_queue_head_t wait; 76 77 short type; 78 unsigned char passcred; 79}; 80 81#define SOCK_INODE(S) ((S)->inode) 82 83struct scm_cookie; 84struct vm_area_struct; 85struct page; 86 87struct proto_ops { 88 int family; 89 90 int (*release) (struct socket *sock); 91 int (*bind) (struct socket *sock, struct sockaddr *umyaddr, 92 int sockaddr_len); 93 int (*connect) (struct socket *sock, struct sockaddr *uservaddr, 94 int sockaddr_len, int flags); 95 int (*socketpair) (struct socket *sock1, struct socket *sock2); 96 int (*accept) (struct socket *sock, struct socket *newsock, 97 int flags); 98 int (*getname) (struct socket *sock, struct sockaddr *uaddr, 99 int *usockaddr_len, int peer); 100 unsigned int (*poll) (struct file *file, struct socket *sock, struct poll_table_struct *wait); 101 int (*ioctl) (struct socket *sock, unsigned int cmd, 102 unsigned long arg); 103 int (*listen) (struct socket *sock, int len); 104 int (*shutdown) (struct socket *sock, int flags); 105 int (*setsockopt) (struct socket *sock, int level, int optname, 106 char *optval, int optlen); 107 int (*getsockopt) (struct socket *sock, int level, int optname, 108 char *optval, int *optlen); 109 int (*sendmsg) (struct socket *sock, struct msghdr *m, int total_len, struct scm_cookie *scm); 110 int (*recvmsg) (struct socket *sock, struct msghdr *m, int total_len, int flags, struct scm_cookie *scm); 111 int (*mmap) (struct file *file, struct socket *sock, struct vm_area_struct * vma); 112 ssize_t (*sendpage) (struct socket *sock, struct page *page, int offset, size_t size, int flags); 113}; 114 115struct net_proto_family 116{ 117 int family; 118 int (*create)(struct socket *sock, int protocol); 119 /* These are counters for the number of different methods of 120 each we support */ 121 short authentication; 122 short encryption; 123 short encrypt_net; 124}; 125 126struct net_proto 127{ 128 const char *name; /* Protocol name */ 129 void (*init_func)(struct net_proto *); /* Bootstrap */ 130}; 131 132extern int sock_wake_async(struct socket *sk, int how, int band); 133extern int sock_register(struct net_proto_family *fam); 134extern int sock_unregister(int family); 135extern struct socket *sock_alloc(void); 136extern int sock_create(int family, int type, int proto, struct socket **); 137extern void sock_release(struct socket *); 138extern int sock_sendmsg(struct socket *, struct msghdr *m, int len); 139extern int sock_recvmsg(struct socket *, struct msghdr *m, int len, int flags); 140extern int sock_readv_writev(int type, struct inode * inode, struct file * file, 141 const struct iovec * iov, long count, long size); 142 143extern int net_ratelimit(void); 144extern unsigned long net_random(void); 145extern void net_srandom(unsigned long); 146 147#ifndef CONFIG_SMP 148#define SOCKOPS_WRAPPED(name) name 149#define SOCKOPS_WRAP(name, fam) 150#else 151 152#define SOCKOPS_WRAPPED(name) __unlocked_##name 153 154#define SOCKCALL_WRAP(name, call, parms, args) \ 155static int __lock_##name##_##call parms \ 156{ \ 157 int ret; \ 158 lock_kernel(); \ 159 ret = __unlocked_##name##_ops.call args ;\ 160 unlock_kernel(); \ 161 return ret; \ 162} 163 164#define SOCKCALL_UWRAP(name, call, parms, args) \ 165static unsigned int __lock_##name##_##call parms \ 166{ \ 167 int ret; \ 168 lock_kernel(); \ 169 ret = __unlocked_##name##_ops.call args ;\ 170 unlock_kernel(); \ 171 return ret; \ 172} 173 174 175#define SOCKOPS_WRAP(name, fam) \ 176SOCKCALL_WRAP(name, release, (struct socket *sock), (sock)) \ 177SOCKCALL_WRAP(name, bind, (struct socket *sock, struct sockaddr *uaddr, int addr_len), \ 178 (sock, uaddr, addr_len)) \ 179SOCKCALL_WRAP(name, connect, (struct socket *sock, struct sockaddr * uaddr, \ 180 int addr_len, int flags), \ 181 (sock, uaddr, addr_len, flags)) \ 182SOCKCALL_WRAP(name, socketpair, (struct socket *sock1, struct socket *sock2), \ 183 (sock1, sock2)) \ 184SOCKCALL_WRAP(name, accept, (struct socket *sock, struct socket *newsock, \ 185 int flags), (sock, newsock, flags)) \ 186SOCKCALL_WRAP(name, getname, (struct socket *sock, struct sockaddr *uaddr, \ 187 int *addr_len, int peer), (sock, uaddr, addr_len, peer)) \ 188SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_table_struct *wait), \ 189 (file, sock, wait)) \ 190SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \ 191 unsigned long arg), (sock, cmd, arg)) \ 192SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \ 193SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \ 194SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \ 195 char *optval, int optlen), (sock, level, optname, optval, optlen)) \ 196SOCKCALL_WRAP(name, getsockopt, (struct socket *sock, int level, int optname, \ 197 char *optval, int *optlen), (sock, level, optname, optval, optlen)) \ 198SOCKCALL_WRAP(name, sendmsg, (struct socket *sock, struct msghdr *m, int len, struct scm_cookie *scm), \ 199 (sock, m, len, scm)) \ 200SOCKCALL_WRAP(name, recvmsg, (struct socket *sock, struct msghdr *m, int len, int flags, struct scm_cookie *scm), \ 201 (sock, m, len, flags, scm)) \ 202SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \ 203 (file, sock, vma)) \ 204 \ 205static struct proto_ops name##_ops = { \ 206 family: fam, \ 207 \ 208 release: __lock_##name##_release, \ 209 bind: __lock_##name##_bind, \ 210 connect: __lock_##name##_connect, \ 211 socketpair: __lock_##name##_socketpair, \ 212 accept: __lock_##name##_accept, \ 213 getname: __lock_##name##_getname, \ 214 poll: __lock_##name##_poll, \ 215 ioctl: __lock_##name##_ioctl, \ 216 listen: __lock_##name##_listen, \ 217 shutdown: __lock_##name##_shutdown, \ 218 setsockopt: __lock_##name##_setsockopt, \ 219 getsockopt: __lock_##name##_getsockopt, \ 220 sendmsg: __lock_##name##_sendmsg, \ 221 recvmsg: __lock_##name##_recvmsg, \ 222 mmap: __lock_##name##_mmap, \ 223}; 224#endif 225 226 227#endif /* __KERNEL__ */ 228#endif /* _LINUX_NET_H */ 229