Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
422 | giacomo | 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, int total_len); |
||
124 | int (*recvmsg) (struct kiocb *iocb, struct socket *sock, |
||
125 | struct msghdr *m, int 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 | |||
146 | extern int sock_wake_async(struct socket *sk, int how, int band); |
||
147 | extern int sock_register(struct net_proto_family *fam); |
||
148 | extern int sock_unregister(int family); |
||
149 | extern struct socket *sock_alloc(void); |
||
150 | extern int sock_create(int family, int type, int proto, |
||
151 | struct socket **res); |
||
152 | extern void sock_release(struct socket *sock); |
||
153 | extern int sock_sendmsg(struct socket *sock, struct msghdr *msg, |
||
154 | int len); |
||
155 | extern int sock_recvmsg(struct socket *sock, struct msghdr *msg, |
||
156 | int size, int flags); |
||
157 | extern int sock_readv_writev(int type, struct inode *inode, |
||
158 | struct file *file, |
||
159 | const struct iovec *iov, long count, |
||
160 | long size); |
||
161 | extern int sock_map_fd(struct socket *sock); |
||
162 | extern struct socket *sockfd_lookup(int fd, int *err); |
||
163 | #define sockfd_put(sock) fput(sock->file) |
||
164 | extern int net_ratelimit(void); |
||
165 | extern unsigned long net_random(void); |
||
166 | extern void net_srandom(unsigned long); |
||
167 | |||
168 | #ifndef CONFIG_SMP |
||
169 | #define SOCKOPS_WRAPPED(name) name |
||
170 | #define SOCKOPS_WRAP(name, fam) |
||
171 | #else |
||
172 | |||
173 | #define SOCKOPS_WRAPPED(name) __unlocked_##name |
||
174 | |||
175 | #define SOCKCALL_WRAP(name, call, parms, args) \ |
||
176 | static int __lock_##name##_##call parms \ |
||
177 | { \ |
||
178 | int ret; \ |
||
179 | lock_kernel(); \ |
||
180 | ret = __unlocked_##name##_ops.call args ;\ |
||
181 | unlock_kernel(); \ |
||
182 | return ret; \ |
||
183 | } |
||
184 | |||
185 | #define SOCKCALL_UWRAP(name, call, parms, args) \ |
||
186 | static unsigned int __lock_##name##_##call parms \ |
||
187 | { \ |
||
188 | int ret; \ |
||
189 | lock_kernel(); \ |
||
190 | ret = __unlocked_##name##_ops.call args ;\ |
||
191 | unlock_kernel(); \ |
||
192 | return ret; \ |
||
193 | } |
||
194 | |||
195 | |||
196 | #define SOCKOPS_WRAP(name, fam) \ |
||
197 | SOCKCALL_WRAP(name, release, (struct socket *sock), (sock)) \ |
||
198 | SOCKCALL_WRAP(name, bind, (struct socket *sock, struct sockaddr *uaddr, int addr_len), \ |
||
199 | (sock, uaddr, addr_len)) \ |
||
200 | SOCKCALL_WRAP(name, connect, (struct socket *sock, struct sockaddr * uaddr, \ |
||
201 | int addr_len, int flags), \ |
||
202 | (sock, uaddr, addr_len, flags)) \ |
||
203 | SOCKCALL_WRAP(name, socketpair, (struct socket *sock1, struct socket *sock2), \ |
||
204 | (sock1, sock2)) \ |
||
205 | SOCKCALL_WRAP(name, accept, (struct socket *sock, struct socket *newsock, \ |
||
206 | int flags), (sock, newsock, flags)) \ |
||
207 | SOCKCALL_WRAP(name, getname, (struct socket *sock, struct sockaddr *uaddr, \ |
||
208 | int *addr_len, int peer), (sock, uaddr, addr_len, peer)) \ |
||
209 | SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_table_struct *wait), \ |
||
210 | (file, sock, wait)) \ |
||
211 | SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \ |
||
212 | unsigned long arg), (sock, cmd, arg)) \ |
||
213 | SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \ |
||
214 | SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \ |
||
215 | SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \ |
||
216 | char *optval, int optlen), (sock, level, optname, optval, optlen)) \ |
||
217 | SOCKCALL_WRAP(name, getsockopt, (struct socket *sock, int level, int optname, \ |
||
218 | char *optval, int *optlen), (sock, level, optname, optval, optlen)) \ |
||
219 | SOCKCALL_WRAP(name, sendmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, int len), \ |
||
220 | (iocb, sock, m, len)) \ |
||
221 | SOCKCALL_WRAP(name, recvmsg, (struct kiocb *iocb, struct socket *sock, struct msghdr *m, int len, int flags), \ |
||
222 | (iocb, sock, m, len, flags)) \ |
||
223 | SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \ |
||
224 | (file, sock, vma)) \ |
||
225 | \ |
||
226 | static struct proto_ops name##_ops = { \ |
||
227 | .family = fam, \ |
||
228 | .owner = THIS_MODULE, \ |
||
229 | .release = __lock_##name##_release, \ |
||
230 | .bind = __lock_##name##_bind, \ |
||
231 | .connect = __lock_##name##_connect, \ |
||
232 | .socketpair = __lock_##name##_socketpair, \ |
||
233 | .accept = __lock_##name##_accept, \ |
||
234 | .getname = __lock_##name##_getname, \ |
||
235 | .poll = __lock_##name##_poll, \ |
||
236 | .ioctl = __lock_##name##_ioctl, \ |
||
237 | .listen = __lock_##name##_listen, \ |
||
238 | .shutdown = __lock_##name##_shutdown, \ |
||
239 | .setsockopt = __lock_##name##_setsockopt, \ |
||
240 | .getsockopt = __lock_##name##_getsockopt, \ |
||
241 | .sendmsg = __lock_##name##_sendmsg, \ |
||
242 | .recvmsg = __lock_##name##_recvmsg, \ |
||
243 | .mmap = __lock_##name##_mmap, \ |
||
244 | }; |
||
245 | #endif |
||
246 | |||
247 | #define MODULE_ALIAS_NETPROTO(proto) \ |
||
248 | MODULE_ALIAS("net-pf-" __stringify(proto)) |
||
249 | |||
250 | #endif /* __KERNEL__ */ |
||
251 | #endif /* _LINUX_NET_H */ |