This source file includes following definitions.
- lock_sock
- release_sock
- sock_queue_rcv_skb
- sock_error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #ifndef _SOCK_H
32 #define _SOCK_H
33
34 #include <linux/timer.h>
35 #include <linux/ip.h>
36 #include <linux/in.h>
37 #include <linux/tcp.h>
38 #include <linux/config.h>
39
40 #include <linux/netdevice.h>
41 #include <linux/skbuff.h>
42 #include <net/protocol.h>
43 #ifdef CONFIG_AX25
44 #include <net/ax25.h>
45 #ifdef CONFIG_NETROM
46 #include <net/netrom.h>
47 #endif
48 #endif
49
50 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
51 #include <net/ipx.h>
52 #endif
53
54 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
55 #include <linux/atalk.h>
56 #endif
57
58 #include <linux/igmp.h>
59
60 #include <asm/atomic.h>
61
62
63 #define SOCK_ARRAY_SIZE 256
64
65
66
67
68
69
70 struct unix_opt
71 {
72 int family;
73 char * name;
74 int locks;
75 struct inode * inode;
76 struct semaphore readsem;
77 struct sock * other;
78 int marksweep;
79 #define MARKED 1
80 int inflight;
81 };
82
83
84
85
86
87 struct inet_packet_opt
88 {
89 struct notifier_block notifier;
90 struct device *bound_dev;
91 unsigned long dev_stamp;
92 struct packet_type *prot_hook;
93 char device_name[15];
94 };
95
96
97
98
99
100 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
101 struct ipx_opt
102 {
103 ipx_address dest_addr;
104 ipx_interface *intrfc;
105 unsigned short port;
106 #ifdef CONFIG_IPX_INTERN
107 unsigned char node[IPX_NODE_LEN];
108 #endif
109 unsigned short type;
110
111
112
113
114 struct ncp_server *ncp_server;
115
116 };
117 #endif
118
119 #ifdef CONFIG_NUTCP
120 struct tcp_opt
121 {
122
123
124
125
126
127 __u32 rcv_nxt;
128 __u32 rcv_up;
129 __u32 rcv_wnd;
130 __u32 snd_nxt;
131 __u32 snd_una;
132 __u32 snd_up;
133 __u32 snd_wl1;
134 __u32 snd_wl2;
135
136
137
138 __u32 snd_cwnd;
139 __u32 snd_ssthresh;
140
141
142
143 struct timer_list delack_timer;
144 struct timer_list idle_timer;
145 struct timer_list completion_timer;
146 struct timer_list probe_timer;
147 struct timer_list retransmit_timer;
148 };
149 #endif
150
151
152
153
154
155
156 struct sock
157 {
158 struct options *opt;
159 atomic_t wmem_alloc;
160 atomic_t rmem_alloc;
161 unsigned long allocation;
162 __u32 write_seq;
163 __u32 sent_seq;
164 __u32 acked_seq;
165 __u32 copied_seq;
166 __u32 rcv_ack_seq;
167 __u32 window_seq;
168 __u32 fin_seq;
169 __u32 urg_seq;
170 __u32 urg_data;
171 int users;
172
173
174
175
176 volatile char dead,
177 urginline,
178 intr,
179 blog,
180 done,
181 reuse,
182 keepopen,
183 linger,
184 delay_acks,
185 destroy,
186 ack_timed,
187 no_check,
188 zapped,
189 broadcast,
190 nonagle,
191 bsdism;
192 unsigned long lingertime;
193 int proc;
194 struct sock *next;
195 struct sock *prev;
196 struct sock *pair;
197 struct sk_buff * volatile send_head;
198 struct sk_buff * volatile send_tail;
199 struct sk_buff_head back_log;
200 struct sk_buff *partial;
201 struct timer_list partial_timer;
202 long retransmits;
203 struct sk_buff_head write_queue,
204 receive_queue;
205 struct proto *prot;
206 struct wait_queue **sleep;
207 __u32 daddr;
208 __u32 saddr;
209 __u32 rcv_saddr;
210 unsigned short max_unacked;
211 unsigned short window;
212 __u32 lastwin_seq;
213 volatile unsigned long ato;
214 volatile unsigned long lrcvtime;
215 unsigned short bytes_rcv;
216
217
218
219 unsigned short mtu;
220 volatile unsigned short mss;
221 volatile unsigned short user_mss;
222 volatile unsigned short max_window;
223 unsigned long window_clamp;
224 unsigned short num;
225 volatile unsigned short cong_window;
226 volatile unsigned short cong_count;
227 volatile unsigned short ssthresh;
228 volatile unsigned short packets_out;
229 volatile unsigned short shutdown;
230 volatile unsigned long rtt;
231 volatile unsigned long mdev;
232 volatile unsigned long rto;
233
234
235
236
237
238
239 volatile unsigned short backoff;
240 volatile int err, err_soft;
241
242
243
244 unsigned char protocol;
245 volatile unsigned char state;
246 unsigned char ack_backlog;
247 unsigned char max_ack_backlog;
248 unsigned char priority;
249 unsigned char debug;
250 unsigned short rcvbuf;
251 unsigned short sndbuf;
252 unsigned short type;
253 unsigned char localroute;
254 #ifdef CONFIG_AX25
255 ax25_cb *ax25;
256 #ifdef CONFIG_NETROM
257 nr_cb *nr;
258 #endif
259 #endif
260
261
262
263
264
265
266 union
267 {
268 struct unix_opt af_unix;
269 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
270 struct atalk_sock af_at;
271 #endif
272 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
273 struct ipx_opt af_ipx;
274 #endif
275 #ifdef CONFIG_INET
276 struct inet_packet_opt af_packet;
277 #ifdef CONFIG_NUTCP
278 struct tcp_opt af_tcp;
279 #endif
280 #endif
281 } protinfo;
282
283
284
285
286 int ip_ttl;
287 int ip_tos;
288 struct tcphdr dummy_th;
289 struct timer_list keepalive_timer;
290 struct timer_list retransmit_timer;
291 struct timer_list ack_timer;
292 int ip_xmit_timeout;
293 struct rtable *ip_route_cache;
294 unsigned char ip_hdrincl;
295 #ifdef CONFIG_IP_MULTICAST
296 int ip_mc_ttl;
297 int ip_mc_loop;
298 char ip_mc_name[MAX_ADDR_LEN];
299 struct ip_mc_socklist *ip_mc_list;
300 #endif
301
302
303
304
305
306 int timeout;
307 struct timer_list timer;
308
309
310 struct timeval stamp;
311
312
313
314
315
316 struct socket *socket;
317
318
319
320
321
322 void (*state_change)(struct sock *sk);
323 void (*data_ready)(struct sock *sk,int bytes);
324 void (*write_space)(struct sock *sk);
325 void (*error_report)(struct sock *sk);
326
327 };
328
329
330
331
332
333 struct proto
334 {
335 void (*close)(struct sock *sk, unsigned long timeout);
336 int (*build_header)(struct sk_buff *skb,
337 __u32 saddr,
338 __u32 daddr,
339 struct device **dev, int type,
340 struct options *opt, int len,
341 int tos, int ttl, struct rtable ** rp);
342 int (*connect)(struct sock *sk,
343 struct sockaddr_in *usin, int addr_len);
344 struct sock * (*accept) (struct sock *sk, int flags);
345 void (*queue_xmit)(struct sock *sk,
346 struct device *dev, struct sk_buff *skb,
347 int free);
348 void (*retransmit)(struct sock *sk, int all);
349 void (*write_wakeup)(struct sock *sk);
350 void (*read_wakeup)(struct sock *sk);
351 int (*rcv)(struct sk_buff *buff, struct device *dev,
352 struct options *opt, __u32 daddr,
353 unsigned short len, __u32 saddr,
354 int redo, struct inet_protocol *protocol);
355 int (*select)(struct sock *sk, int which,
356 select_table *wait);
357 int (*ioctl)(struct sock *sk, int cmd,
358 unsigned long arg);
359 int (*init)(struct sock *sk);
360 void (*shutdown)(struct sock *sk, int how);
361 int (*setsockopt)(struct sock *sk, int level, int optname,
362 char *optval, int optlen);
363 int (*getsockopt)(struct sock *sk, int level, int optname,
364 char *optval, int *option);
365 int (*sendmsg)(struct sock *sk, struct msghdr *msg, int len,
366 int noblock, int flags);
367 int (*recvmsg)(struct sock *sk, struct msghdr *msg, int len,
368 int noblock, int flags, int *addr_len);
369 int (*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len);
370 unsigned short max_header;
371 unsigned long retransmits;
372 char name[32];
373 int inuse, highestinuse;
374 struct sock * sock_array[SOCK_ARRAY_SIZE];
375 };
376
377 #define TIME_WRITE 1
378 #define TIME_CLOSE 2
379 #define TIME_KEEPOPEN 3
380 #define TIME_DESTROY 4
381 #define TIME_DONE 5
382 #define TIME_PROBE0 6
383
384
385
386
387
388 #define SOCK_DESTROY_TIME (10*HZ)
389
390
391
392
393
394 #define PROT_SOCK 1024
395
396 #define SHUTDOWN_MASK 3
397 #define RCV_SHUTDOWN 1
398 #define SEND_SHUTDOWN 2
399
400
401
402
403
404
405
406
407
408
409
410 extern void __release_sock(struct sock *sk);
411
412 static inline void lock_sock(struct sock *sk)
413 {
414 #if 1
415
416
417 if (sk->users) {
418 __label__ here;
419 printk("double lock on socket at %p\n", &&here);
420 here:
421 }
422 #endif
423 sk->users++;
424 barrier();
425 }
426
427 static inline void release_sock(struct sock *sk)
428 {
429 barrier();
430 #if 1
431
432 if (sk->users == 0) {
433 __label__ here;
434 sk->users = 1;
435 printk("trying to unlock unlocked socket at %p\n", &&here);
436 here:
437 }
438 #endif
439 if (!--sk->users)
440 __release_sock(sk);
441 }
442
443
444 extern void destroy_sock(struct sock *sk);
445 extern unsigned short get_new_socknum(struct proto *,
446 unsigned short);
447 extern void put_sock(unsigned short, struct sock *);
448 extern struct sock *get_sock(struct proto *, unsigned short,
449 unsigned long, unsigned short,
450 unsigned long);
451 extern struct sock *get_sock_mcast(struct sock *, unsigned short,
452 unsigned long, unsigned short,
453 unsigned long);
454 extern struct sock *get_sock_raw(struct sock *, unsigned short,
455 unsigned long, unsigned long);
456
457 extern struct sk_buff *sock_wmalloc(struct sock *sk,
458 unsigned long size, int force,
459 int priority);
460 extern struct sk_buff *sock_rmalloc(struct sock *sk,
461 unsigned long size, int force,
462 int priority);
463 extern void sock_wfree(struct sock *sk,
464 struct sk_buff *skb);
465 extern void sock_rfree(struct sock *sk,
466 struct sk_buff *skb);
467 extern unsigned long sock_rspace(struct sock *sk);
468 extern unsigned long sock_wspace(struct sock *sk);
469
470 extern int sock_setsockopt(struct sock *sk, int level,
471 int op, char *optval,
472 int optlen);
473
474 extern int sock_getsockopt(struct sock *sk, int level,
475 int op, char *optval,
476 int *optlen);
477 extern struct sk_buff *sock_alloc_send_skb(struct sock *skb,
478 unsigned long size,
479 unsigned long fallback,
480 int noblock,
481 int *errcode);
482
483
484
485
486
487
488
489
490
491
492 extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
493 {
494 if (sk->rmem_alloc + skb->truesize >= sk->rcvbuf)
495 return -ENOMEM;
496 atomic_add(skb->truesize, &sk->rmem_alloc);
497 skb->sk=sk;
498 skb_queue_tail(&sk->receive_queue,skb);
499 if(!sk->dead)
500 sk->data_ready(sk,skb->len);
501 return 0;
502 }
503
504
505
506
507
508 extern __inline__ int sock_error(struct sock *sk)
509 {
510 int err=xchg(&sk->err,0);
511 return -err;
512 }
513
514
515
516
517
518 extern struct sock *timer_base;
519
520 extern void delete_timer (struct sock *);
521 extern void reset_timer (struct sock *, int, unsigned long);
522 extern void net_timer (unsigned long);
523
524
525
526
527
528
529 #define NETDEBUG(x) x
530
531 #endif