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 25 struct 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 49 typedef 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 65 struct 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 83 struct scm_cookie; 84 struct vm_area_struct; 85 struct page; 86 87 struct 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 115 struct 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 126 struct net_proto 127 { 128 const char *name; /* Protocol name */ 129 void (*init_func)(struct net_proto *); /* Bootstrap */ 130 }; 131 132 extern int sock_wake_async(struct socket *sk, int how, int band); 133 extern int sock_register(struct net_proto_family *fam); 134 extern int sock_unregister(int family); 135 extern struct socket *sock_alloc(void); 136 extern int sock_create(int family, int type, int proto, struct socket **); 137 extern void sock_release(struct socket *); 138 extern int sock_sendmsg(struct socket *, struct msghdr *m, int len); 139 extern int sock_recvmsg(struct socket *, struct msghdr *m, int len, int flags); 140 extern int sock_readv_writev(int type, struct inode * inode, struct file * file, 141 const struct iovec * iov, long count, long size); 142 extern struct socket *sockfd_lookup(int fd, int *err); 143 144 extern int sock_map_fd(struct socket *sock); 145 extern int net_ratelimit(void); 146 extern unsigned long net_random(void); 147 extern void net_srandom(unsigned long); 148 149 #ifndef CONFIG_SMP 150 #define SOCKOPS_WRAPPED(name) name 151 #define SOCKOPS_WRAP(name, fam) 152 #else 153 154 #define SOCKOPS_WRAPPED(name) __unlocked_##name 155 156 #define SOCKCALL_WRAP(name, call, parms, args) \ 157 static int __lock_##name##_##call parms \ 158 { \ 159 int ret; \ 160 lock_kernel(); \ 161 ret = __unlocked_##name##_ops.call args ;\ 162 unlock_kernel(); \ 163 return ret; \ 164 } 165 166 #define SOCKCALL_UWRAP(name, call, parms, args) \ 167 static unsigned int __lock_##name##_##call parms \ 168 { \ 169 int ret; \ 170 lock_kernel(); \ 171 ret = __unlocked_##name##_ops.call args ;\ 172 unlock_kernel(); \ 173 return ret; \ 174 } 175 176 177 #define SOCKOPS_WRAP(name, fam) \ 178 SOCKCALL_WRAP(name, release, (struct socket *sock), (sock)) \ 179 SOCKCALL_WRAP(name, bind, (struct socket *sock, struct sockaddr *uaddr, int addr_len), \ 180 (sock, uaddr, addr_len)) \ 181 SOCKCALL_WRAP(name, connect, (struct socket *sock, struct sockaddr * uaddr, \ 182 int addr_len, int flags), \ 183 (sock, uaddr, addr_len, flags)) \ 184 SOCKCALL_WRAP(name, socketpair, (struct socket *sock1, struct socket *sock2), \ 185 (sock1, sock2)) \ 186 SOCKCALL_WRAP(name, accept, (struct socket *sock, struct socket *newsock, \ 187 int flags), (sock, newsock, flags)) \ 188 SOCKCALL_WRAP(name, getname, (struct socket *sock, struct sockaddr *uaddr, \ 189 int *addr_len, int peer), (sock, uaddr, addr_len, peer)) \ 190 SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_table_struct *wait), \ 191 (file, sock, wait)) \ 192 SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \ 193 unsigned long arg), (sock, cmd, arg)) \ 194 SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \ 195 SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \ 196 SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \ 197 char *optval, int optlen), (sock, level, optname, optval, optlen)) \ 198 SOCKCALL_WRAP(name, getsockopt, (struct socket *sock, int level, int optname, \ 199 char *optval, int *optlen), (sock, level, optname, optval, optlen)) \ 200 SOCKCALL_WRAP(name, sendmsg, (struct socket *sock, struct msghdr *m, int len, struct scm_cookie *scm), \ 201 (sock, m, len, scm)) \ 202 SOCKCALL_WRAP(name, recvmsg, (struct socket *sock, struct msghdr *m, int len, int flags, struct scm_cookie *scm), \ 203 (sock, m, len, flags, scm)) \ 204 SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \ 205 (file, sock, vma)) \ 206 \ 207 static struct proto_ops name##_ops = { \ 208 family: fam, \ 209 \ 210 release: __lock_##name##_release, \ 211 bind: __lock_##name##_bind, \ 212 connect: __lock_##name##_connect, \ 213 socketpair: __lock_##name##_socketpair, \ 214 accept: __lock_##name##_accept, \ 215 getname: __lock_##name##_getname, \ 216 poll: __lock_##name##_poll, \ 217 ioctl: __lock_##name##_ioctl, \ 218 listen: __lock_##name##_listen, \ 219 shutdown: __lock_##name##_shutdown, \ 220 setsockopt: __lock_##name##_setsockopt, \ 221 getsockopt: __lock_##name##_getsockopt, \ 222 sendmsg: __lock_##name##_sendmsg, \ 223 recvmsg: __lock_##name##_recvmsg, \ 224 mmap: __lock_##name##_mmap, \ 225 }; 226 #endif 227 228 229 #endif /* __KERNEL__ */ 230 #endif /* _LINUX_NET_H */ 231