x86: initial changes to unify traps_32.c and traps_64.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / net.h
blob71f7dd55928580065f3581898a1657d9cea2b944
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.
7 * Version: @(#)net.h 1.0.3 05/25/93
9 * Authors: Orest Zborowski, <obz@Kodak.COM>
10 * Ross Biro
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
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.
18 #ifndef _LINUX_NET_H
19 #define _LINUX_NET_H
21 #include <linux/wait.h>
22 #include <linux/socket.h>
23 #include <asm/socket.h>
25 struct poll_table_struct;
26 struct pipe_inode_info;
27 struct inode;
28 struct net;
30 #define NPROTO AF_MAX
32 #define SYS_SOCKET 1 /* sys_socket(2) */
33 #define SYS_BIND 2 /* sys_bind(2) */
34 #define SYS_CONNECT 3 /* sys_connect(2) */
35 #define SYS_LISTEN 4 /* sys_listen(2) */
36 #define SYS_ACCEPT 5 /* sys_accept(2) */
37 #define SYS_GETSOCKNAME 6 /* sys_getsockname(2) */
38 #define SYS_GETPEERNAME 7 /* sys_getpeername(2) */
39 #define SYS_SOCKETPAIR 8 /* sys_socketpair(2) */
40 #define SYS_SEND 9 /* sys_send(2) */
41 #define SYS_RECV 10 /* sys_recv(2) */
42 #define SYS_SENDTO 11 /* sys_sendto(2) */
43 #define SYS_RECVFROM 12 /* sys_recvfrom(2) */
44 #define SYS_SHUTDOWN 13 /* sys_shutdown(2) */
45 #define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */
46 #define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */
47 #define SYS_SENDMSG 16 /* sys_sendmsg(2) */
48 #define SYS_RECVMSG 17 /* sys_recvmsg(2) */
50 typedef enum {
51 SS_FREE = 0, /* not allocated */
52 SS_UNCONNECTED, /* unconnected to any socket */
53 SS_CONNECTING, /* in process of connecting */
54 SS_CONNECTED, /* connected to socket */
55 SS_DISCONNECTING /* in process of disconnecting */
56 } socket_state;
58 #define __SO_ACCEPTCON (1 << 16) /* performed a listen */
60 #ifdef __KERNEL__
61 #include <linux/stringify.h>
62 #include <linux/random.h>
64 #define SOCK_ASYNC_NOSPACE 0
65 #define SOCK_ASYNC_WAITDATA 1
66 #define SOCK_NOSPACE 2
67 #define SOCK_PASSCRED 3
68 #define SOCK_PASSSEC 4
70 #ifndef ARCH_HAS_SOCKET_TYPES
71 /**
72 * enum sock_type - Socket types
73 * @SOCK_STREAM: stream (connection) socket
74 * @SOCK_DGRAM: datagram (conn.less) socket
75 * @SOCK_RAW: raw socket
76 * @SOCK_RDM: reliably-delivered message
77 * @SOCK_SEQPACKET: sequential packet socket
78 * @SOCK_DCCP: Datagram Congestion Control Protocol socket
79 * @SOCK_PACKET: linux specific way of getting packets at the dev level.
80 * For writing rarp and other similar things on the user level.
82 * When adding some new socket type please
83 * grep ARCH_HAS_SOCKET_TYPE include/asm-* /socket.h, at least MIPS
84 * overrides this enum for binary compat reasons.
86 enum sock_type {
87 SOCK_STREAM = 1,
88 SOCK_DGRAM = 2,
89 SOCK_RAW = 3,
90 SOCK_RDM = 4,
91 SOCK_SEQPACKET = 5,
92 SOCK_DCCP = 6,
93 SOCK_PACKET = 10,
96 #define SOCK_MAX (SOCK_PACKET + 1)
98 #endif /* ARCH_HAS_SOCKET_TYPES */
100 enum sock_shutdown_cmd {
101 SHUT_RD = 0,
102 SHUT_WR = 1,
103 SHUT_RDWR = 2,
107 * struct socket - general BSD socket
108 * @state: socket state (%SS_CONNECTED, etc)
109 * @flags: socket flags (%SOCK_ASYNC_NOSPACE, etc)
110 * @ops: protocol specific socket operations
111 * @fasync_list: Asynchronous wake up list
112 * @file: File back pointer for gc
113 * @sk: internal networking protocol agnostic socket representation
114 * @wait: wait queue for several uses
115 * @type: socket type (%SOCK_STREAM, etc)
117 struct socket {
118 socket_state state;
119 unsigned long flags;
120 const struct proto_ops *ops;
121 struct fasync_struct *fasync_list;
122 struct file *file;
123 struct sock *sk;
124 wait_queue_head_t wait;
125 short type;
128 struct vm_area_struct;
129 struct page;
130 struct kiocb;
131 struct sockaddr;
132 struct msghdr;
133 struct module;
135 struct proto_ops {
136 int family;
137 struct module *owner;
138 int (*release) (struct socket *sock);
139 int (*bind) (struct socket *sock,
140 struct sockaddr *myaddr,
141 int sockaddr_len);
142 int (*connect) (struct socket *sock,
143 struct sockaddr *vaddr,
144 int sockaddr_len, int flags);
145 int (*socketpair)(struct socket *sock1,
146 struct socket *sock2);
147 int (*accept) (struct socket *sock,
148 struct socket *newsock, int flags);
149 int (*getname) (struct socket *sock,
150 struct sockaddr *addr,
151 int *sockaddr_len, int peer);
152 unsigned int (*poll) (struct file *file, struct socket *sock,
153 struct poll_table_struct *wait);
154 int (*ioctl) (struct socket *sock, unsigned int cmd,
155 unsigned long arg);
156 int (*compat_ioctl) (struct socket *sock, unsigned int cmd,
157 unsigned long arg);
158 int (*listen) (struct socket *sock, int len);
159 int (*shutdown) (struct socket *sock, int flags);
160 int (*setsockopt)(struct socket *sock, int level,
161 int optname, char __user *optval, int optlen);
162 int (*getsockopt)(struct socket *sock, int level,
163 int optname, char __user *optval, int __user *optlen);
164 int (*compat_setsockopt)(struct socket *sock, int level,
165 int optname, char __user *optval, int optlen);
166 int (*compat_getsockopt)(struct socket *sock, int level,
167 int optname, char __user *optval, int __user *optlen);
168 int (*sendmsg) (struct kiocb *iocb, struct socket *sock,
169 struct msghdr *m, size_t total_len);
170 int (*recvmsg) (struct kiocb *iocb, struct socket *sock,
171 struct msghdr *m, size_t total_len,
172 int flags);
173 int (*mmap) (struct file *file, struct socket *sock,
174 struct vm_area_struct * vma);
175 ssize_t (*sendpage) (struct socket *sock, struct page *page,
176 int offset, size_t size, int flags);
177 ssize_t (*splice_read)(struct socket *sock, loff_t *ppos,
178 struct pipe_inode_info *pipe, size_t len, unsigned int flags);
181 struct net_proto_family {
182 int family;
183 int (*create)(struct net *net, struct socket *sock, int protocol);
184 struct module *owner;
187 struct iovec;
188 struct kvec;
190 enum {
191 SOCK_WAKE_IO,
192 SOCK_WAKE_WAITD,
193 SOCK_WAKE_SPACE,
194 SOCK_WAKE_URG,
197 extern int sock_wake_async(struct socket *sk, int how, int band);
198 extern int sock_register(const struct net_proto_family *fam);
199 extern void sock_unregister(int family);
200 extern int sock_create(int family, int type, int proto,
201 struct socket **res);
202 extern int sock_create_kern(int family, int type, int proto,
203 struct socket **res);
204 extern int sock_create_lite(int family, int type, int proto,
205 struct socket **res);
206 extern void sock_release(struct socket *sock);
207 extern int sock_sendmsg(struct socket *sock, struct msghdr *msg,
208 size_t len);
209 extern int sock_recvmsg(struct socket *sock, struct msghdr *msg,
210 size_t size, int flags);
211 extern int sock_map_fd(struct socket *sock);
212 extern struct socket *sockfd_lookup(int fd, int *err);
213 #define sockfd_put(sock) fput(sock->file)
214 extern int net_ratelimit(void);
216 #define net_random() random32()
217 #define net_srandom(seed) srandom32((__force u32)seed)
219 extern int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
220 struct kvec *vec, size_t num, size_t len);
221 extern int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
222 struct kvec *vec, size_t num,
223 size_t len, int flags);
225 extern int kernel_bind(struct socket *sock, struct sockaddr *addr,
226 int addrlen);
227 extern int kernel_listen(struct socket *sock, int backlog);
228 extern int kernel_accept(struct socket *sock, struct socket **newsock,
229 int flags);
230 extern int kernel_connect(struct socket *sock, struct sockaddr *addr,
231 int addrlen, int flags);
232 extern int kernel_getsockname(struct socket *sock, struct sockaddr *addr,
233 int *addrlen);
234 extern int kernel_getpeername(struct socket *sock, struct sockaddr *addr,
235 int *addrlen);
236 extern int kernel_getsockopt(struct socket *sock, int level, int optname,
237 char *optval, int *optlen);
238 extern int kernel_setsockopt(struct socket *sock, int level, int optname,
239 char *optval, int optlen);
240 extern int kernel_sendpage(struct socket *sock, struct page *page, int offset,
241 size_t size, int flags);
242 extern int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg);
243 extern int kernel_sock_shutdown(struct socket *sock,
244 enum sock_shutdown_cmd how);
246 #ifndef CONFIG_SMP
247 #define SOCKOPS_WRAPPED(name) name
248 #define SOCKOPS_WRAP(name, fam)
249 #else
251 #define SOCKOPS_WRAPPED(name) __unlocked_##name
253 #define SOCKCALL_WRAP(name, call, parms, args) \
254 static int __lock_##name##_##call parms \
256 int ret; \
257 lock_kernel(); \
258 ret = __unlocked_##name##_ops.call args ;\
259 unlock_kernel(); \
260 return ret; \
263 #define SOCKCALL_UWRAP(name, call, parms, args) \
264 static unsigned int __lock_##name##_##call parms \
266 int ret; \
267 lock_kernel(); \
268 ret = __unlocked_##name##_ops.call args ;\
269 unlock_kernel(); \
270 return ret; \
274 #define SOCKOPS_WRAP(name, fam) \
275 SOCKCALL_WRAP(name, release, (struct socket *sock), (sock)) \
276 SOCKCALL_WRAP(name, bind, (struct socket *sock, struct sockaddr *uaddr, int addr_len), \
277 (sock, uaddr, addr_len)) \
278 SOCKCALL_WRAP(name, connect, (struct socket *sock, struct sockaddr * uaddr, \
279 int addr_len, int flags), \
280 (sock, uaddr, addr_len, flags)) \
281 SOCKCALL_WRAP(name, socketpair, (struct socket *sock1, struct socket *sock2), \
282 (sock1, sock2)) \
283 SOCKCALL_WRAP(name, accept, (struct socket *sock, struct socket *newsock, \
284 int flags), (sock, newsock, flags)) \
285 SOCKCALL_WRAP(name, getname, (struct socket *sock, struct sockaddr *uaddr, \
286 int *addr_len, int peer), (sock, uaddr, addr_len, peer)) \
287 SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_table_struct *wait), \
288 (file, sock, wait)) \
289 SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \
290 unsigned long arg), (sock, cmd, arg)) \
291 SOCKCALL_WRAP(name, compat_ioctl, (struct socket *sock, unsigned int cmd, \
292 unsigned long arg), (sock, cmd, arg)) \
293 SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \
294 SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \
295 SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \
296 char __user *optval, int optlen), (sock, level, optname, optval, optlen)) \
297 SOCKCALL_WRAP(name, getsockopt, (struct socket *sock, int level, int optname, \
298 char __user *optval, int __user *optlen), (sock, level, optname, optval, optlen)) \
299 SOCKCALL_WRAP(name, sendmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t len), \
300 (iocb, sock, m, len)) \
301 SOCKCALL_WRAP(name, recvmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t len, int flags), \
302 (iocb, sock, m, len, flags)) \
303 SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \
304 (file, sock, vma)) \
306 static const struct proto_ops name##_ops = { \
307 .family = fam, \
308 .owner = THIS_MODULE, \
309 .release = __lock_##name##_release, \
310 .bind = __lock_##name##_bind, \
311 .connect = __lock_##name##_connect, \
312 .socketpair = __lock_##name##_socketpair, \
313 .accept = __lock_##name##_accept, \
314 .getname = __lock_##name##_getname, \
315 .poll = __lock_##name##_poll, \
316 .ioctl = __lock_##name##_ioctl, \
317 .compat_ioctl = __lock_##name##_compat_ioctl, \
318 .listen = __lock_##name##_listen, \
319 .shutdown = __lock_##name##_shutdown, \
320 .setsockopt = __lock_##name##_setsockopt, \
321 .getsockopt = __lock_##name##_getsockopt, \
322 .sendmsg = __lock_##name##_sendmsg, \
323 .recvmsg = __lock_##name##_recvmsg, \
324 .mmap = __lock_##name##_mmap, \
327 #endif
329 #define MODULE_ALIAS_NETPROTO(proto) \
330 MODULE_ALIAS("net-pf-" __stringify(proto))
332 #define MODULE_ALIAS_NET_PF_PROTO(pf, proto) \
333 MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto))
335 #define MODULE_ALIAS_NET_PF_PROTO_TYPE(pf, proto, type) \
336 MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto) \
337 "-type-" __stringify(type))
339 #ifdef CONFIG_SYSCTL
340 #include <linux/sysctl.h>
341 extern int net_msg_cost;
342 extern int net_msg_burst;
343 #endif
345 #endif /* __KERNEL__ */
346 #endif /* _LINUX_NET_H */