http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / include / linux / net.h
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/wait.h>
23 #include <linux/stringify.h>
24
25 struct poll_table_struct;
26 struct inode;
27
28 #define NPROTO          32              /* should be enough for now..   */
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 typedef enum {
49         SS_FREE = 0,                    /* not allocated                */
50         SS_UNCONNECTED,                 /* unconnected to any socket    */
51         SS_CONNECTING,                  /* in process of connecting     */
52         SS_CONNECTED,                   /* connected to socket          */
53         SS_DISCONNECTING                /* in process of disconnecting  */
54 } socket_state;
55
56 #define __SO_ACCEPTCON  (1 << 16)       /* performed a listen           */
57
58 #ifdef __KERNEL__
59
60 #define SOCK_ASYNC_NOSPACE      0
61 #define SOCK_ASYNC_WAITDATA     1
62 #define SOCK_NOSPACE            2
63
64 /**
65  *  struct socket - general BSD socket
66  *  @state - socket state (%SS_CONNECTED, etc)
67  *  @flags - socket flags (%SOCK_ASYNC_NOSPACE, etc)
68  *  @ops - protocol specific socket operations
69  *  @fasync_list - Asynchronous wake up list
70  *  @file - File back pointer for gc
71  *  @sk - internal networking protocol agnostic socket representation
72  *  @wait - wait queue for several uses
73  *  @type - socket type (%SOCK_STREAM, etc)
74  *  @passcred - credentials (used only in Unix Sockets (aka PF_LOCAL))
75  */
76 struct socket {
77         socket_state            state;
78         unsigned long           flags;
79         struct proto_ops        *ops;
80         struct fasync_struct    *fasync_list;
81         struct file             *file;
82         struct sock             *sk;
83         wait_queue_head_t       wait;
84         short                   type;
85         unsigned char           passcred;
86 };
87
88 struct vm_area_struct;
89 struct page;
90 struct kiocb;
91 struct sockaddr;
92 struct msghdr;
93 struct module;
94
95 struct proto_ops {
96         int             family;
97         struct module   *owner;
98         int             (*release)   (struct socket *sock);
99         int             (*bind)      (struct socket *sock,
100                                       struct sockaddr *myaddr,
101                                       int sockaddr_len);
102         int             (*connect)   (struct socket *sock,
103                                       struct sockaddr *vaddr,
104                                       int sockaddr_len, int flags);
105         int             (*socketpair)(struct socket *sock1,
106                                       struct socket *sock2);
107         int             (*accept)    (struct socket *sock,
108                                       struct socket *newsock, int flags);
109         int             (*getname)   (struct socket *sock,
110                                       struct sockaddr *addr,
111                                       int *sockaddr_len, int peer);
112         unsigned int    (*poll)      (struct file *file, struct socket *sock,
113                                       struct poll_table_struct *wait);
114         int             (*ioctl)     (struct socket *sock, unsigned int cmd,
115                                       unsigned long arg);
116         int             (*listen)    (struct socket *sock, int len);
117         int             (*shutdown)  (struct socket *sock, int flags);
118         int             (*setsockopt)(struct socket *sock, int level,
119                                       int optname, char __user *optval, int optlen);
120         int             (*getsockopt)(struct socket *sock, int level,
121                                       int optname, char __user *optval, int __user *optlen);
122         int             (*sendmsg)   (struct kiocb *iocb, struct socket *sock,
123                                       struct msghdr *m, size_t total_len);
124         int             (*recvmsg)   (struct kiocb *iocb, struct socket *sock,
125                                       struct msghdr *m, size_t total_len,
126                                       int flags);
127         int             (*mmap)      (struct file *file, struct socket *sock,
128                                       struct vm_area_struct * vma);
129         ssize_t         (*sendpage)  (struct socket *sock, struct page *page,
130                                       int offset, size_t size, int flags);
131 };
132
133 struct net_proto_family {
134         int             family;
135         int             (*create)(struct socket *sock, int protocol);
136         /* These are counters for the number of different methods of
137            each we support */
138         short           authentication;
139         short           encryption;
140         short           encrypt_net;
141         struct module   *owner;
142 };
143
144 struct iovec;
145 struct kvec;
146
147 extern int           sock_wake_async(struct socket *sk, int how, int band);
148 extern int           sock_register(struct net_proto_family *fam);
149 extern int           sock_unregister(int family);
150 extern struct socket *sock_alloc(void);
151 extern int           sock_create(int family, int type, int proto,
152                                  struct socket **res);
153 extern int           sock_create_kern(int family, int type, int proto,
154                                       struct socket **res);
155 extern int           sock_create_lite(int family, int type, int proto,
156                                       struct socket **res); 
157 extern void          sock_release(struct socket *sock);
158 extern int           sock_sendmsg(struct socket *sock, struct msghdr *msg,
159                                   size_t len);
160 extern int           sock_recvmsg(struct socket *sock, struct msghdr *msg,
161                                   size_t size, int flags);
162 extern int           sock_readv_writev(int type, struct inode *inode,
163                                        struct file *file,
164                                        const struct iovec *iov, long count,
165                                        size_t size);
166 extern int           sock_map_fd(struct socket *sock);
167 extern struct socket *sockfd_lookup(int fd, int *err);
168 #define              sockfd_put(sock) fput(sock->file)
169 extern int           net_ratelimit(void);
170 extern unsigned long net_random(void);
171 extern void          net_srandom(unsigned long);
172
173 extern int           kernel_sendmsg(struct socket *sock, struct msghdr *msg,
174                                     struct kvec *vec, size_t num, size_t len);
175 extern int           kernel_recvmsg(struct socket *sock, struct msghdr *msg,
176                                     struct kvec *vec, size_t num,
177                                     size_t len, int flags);
178
179 #ifndef CONFIG_SMP
180 #define SOCKOPS_WRAPPED(name) name
181 #define SOCKOPS_WRAP(name, fam)
182 #else
183
184 #define SOCKOPS_WRAPPED(name) __unlocked_##name
185
186 #define SOCKCALL_WRAP(name, call, parms, args)          \
187 static int __lock_##name##_##call  parms                \
188 {                                                       \
189         int ret;                                        \
190         lock_kernel();                                  \
191         ret = __unlocked_##name##_ops.call  args ;\
192         unlock_kernel();                                \
193         return ret;                                     \
194 }
195
196 #define SOCKCALL_UWRAP(name, call, parms, args)         \
197 static unsigned int __lock_##name##_##call  parms       \
198 {                                                       \
199         int ret;                                        \
200         lock_kernel();                                  \
201         ret = __unlocked_##name##_ops.call  args ;\
202         unlock_kernel();                                \
203         return ret;                                     \
204 }
205
206
207 #define SOCKOPS_WRAP(name, fam)                                 \
208 SOCKCALL_WRAP(name, release, (struct socket *sock), (sock))     \
209 SOCKCALL_WRAP(name, bind, (struct socket *sock, struct sockaddr *uaddr, int addr_len), \
210               (sock, uaddr, addr_len))                          \
211 SOCKCALL_WRAP(name, connect, (struct socket *sock, struct sockaddr * uaddr, \
212                               int addr_len, int flags),         \
213               (sock, uaddr, addr_len, flags))                   \
214 SOCKCALL_WRAP(name, socketpair, (struct socket *sock1, struct socket *sock2), \
215               (sock1, sock2))                                   \
216 SOCKCALL_WRAP(name, accept, (struct socket *sock, struct socket *newsock, \
217                          int flags), (sock, newsock, flags)) \
218 SOCKCALL_WRAP(name, getname, (struct socket *sock, struct sockaddr *uaddr, \
219                          int *addr_len, int peer), (sock, uaddr, addr_len, peer)) \
220 SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_table_struct *wait), \
221               (file, sock, wait)) \
222 SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \
223                          unsigned long arg), (sock, cmd, arg)) \
224 SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \
225 SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \
226 SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \
227                          char __user *optval, int optlen), (sock, level, optname, optval, optlen)) \
228 SOCKCALL_WRAP(name, getsockopt, (struct socket *sock, int level, int optname, \
229                          char __user *optval, int __user *optlen), (sock, level, optname, optval, optlen)) \
230 SOCKCALL_WRAP(name, sendmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t len), \
231               (iocb, sock, m, len)) \
232 SOCKCALL_WRAP(name, recvmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t len, int flags), \
233               (iocb, sock, m, len, flags)) \
234 SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \
235               (file, sock, vma)) \
236               \
237 static struct proto_ops name##_ops = {                  \
238         .family         = fam,                          \
239         .owner          = THIS_MODULE,                  \
240         .release        = __lock_##name##_release,      \
241         .bind           = __lock_##name##_bind,         \
242         .connect        = __lock_##name##_connect,      \
243         .socketpair     = __lock_##name##_socketpair,   \
244         .accept         = __lock_##name##_accept,       \
245         .getname        = __lock_##name##_getname,      \
246         .poll           = __lock_##name##_poll,         \
247         .ioctl          = __lock_##name##_ioctl,        \
248         .listen         = __lock_##name##_listen,       \
249         .shutdown       = __lock_##name##_shutdown,     \
250         .setsockopt     = __lock_##name##_setsockopt,   \
251         .getsockopt     = __lock_##name##_getsockopt,   \
252         .sendmsg        = __lock_##name##_sendmsg,      \
253         .recvmsg        = __lock_##name##_recvmsg,      \
254         .mmap           = __lock_##name##_mmap,         \
255 };
256 #endif
257
258 #define MODULE_ALIAS_NETPROTO(proto) \
259         MODULE_ALIAS("net-pf-" __stringify(proto))
260
261 #endif /* __KERNEL__ */
262 #endif  /* _LINUX_NET_H */