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 unsigned short rcv_ack_cnt;
168 __u32 window_seq;
169 __u32 fin_seq;
170 __u32 urg_seq;
171 __u32 urg_data;
172 int users;
173
174
175
176
177 volatile char dead,
178 urginline,
179 intr,
180 blog,
181 done,
182 reuse,
183 keepopen,
184 linger,
185 delay_acks,
186 destroy,
187 ack_timed,
188 no_check,
189 zapped,
190 broadcast,
191 nonagle,
192 bsdism;
193 unsigned long lingertime;
194 int proc;
195 struct sock *next;
196 struct sock *prev;
197 struct sock *pair;
198 struct sk_buff * volatile send_head;
199 struct sk_buff * volatile send_tail;
200 struct sk_buff_head back_log;
201 struct sk_buff *partial;
202 struct timer_list partial_timer;
203 long retransmits;
204 struct sk_buff_head write_queue,
205 receive_queue;
206 struct proto *prot;
207 struct wait_queue **sleep;
208 __u32 daddr;
209 __u32 saddr;
210 __u32 rcv_saddr;
211 unsigned short max_unacked;
212 unsigned short window;
213 __u32 lastwin_seq;
214 volatile unsigned long ato;
215 volatile unsigned long lrcvtime;
216 unsigned short bytes_rcv;
217
218
219
220 unsigned short mtu;
221 volatile unsigned short mss;
222 volatile unsigned short user_mss;
223 volatile unsigned short max_window;
224 unsigned long window_clamp;
225 unsigned short num;
226 volatile unsigned short cong_window;
227 volatile unsigned short cong_count;
228 volatile unsigned short ssthresh;
229 volatile unsigned short packets_out;
230 volatile unsigned short shutdown;
231 volatile unsigned long rtt;
232 volatile unsigned long mdev;
233 volatile unsigned long rto;
234
235
236
237
238
239
240 volatile unsigned short backoff;
241 int err, err_soft;
242
243
244
245 unsigned char protocol;
246 volatile unsigned char state;
247 unsigned char ack_backlog;
248 unsigned char max_ack_backlog;
249 unsigned char priority;
250 unsigned char debug;
251 unsigned short rcvbuf;
252 unsigned short sndbuf;
253 unsigned short type;
254 unsigned char localroute;
255 #ifdef CONFIG_AX25
256 ax25_cb *ax25;
257 #ifdef CONFIG_NETROM
258 nr_cb *nr;
259 #endif
260 #endif
261
262
263
264
265
266
267 union
268 {
269 struct unix_opt af_unix;
270 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
271 struct atalk_sock af_at;
272 #endif
273 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
274 struct ipx_opt af_ipx;
275 #endif
276 #ifdef CONFIG_INET
277 struct inet_packet_opt af_packet;
278 #ifdef CONFIG_NUTCP
279 struct tcp_opt af_tcp;
280 #endif
281 #endif
282 } protinfo;
283
284
285
286
287 int ip_ttl;
288 int ip_tos;
289 struct tcphdr dummy_th;
290 struct timer_list keepalive_timer;
291 struct timer_list retransmit_timer;
292 struct timer_list delack_timer;
293 int ip_xmit_timeout;
294 struct rtable *ip_route_cache;
295 unsigned char ip_hdrincl;
296 #ifdef CONFIG_IP_MULTICAST
297 int ip_mc_ttl;
298 int ip_mc_loop;
299 char ip_mc_name[MAX_ADDR_LEN];
300 struct ip_mc_socklist *ip_mc_list;
301 #endif
302
303
304
305
306
307 int timeout;
308 struct timer_list timer;
309
310
311 struct timeval stamp;
312
313
314
315
316
317 struct socket *socket;
318
319
320
321
322
323 void (*state_change)(struct sock *sk);
324 void (*data_ready)(struct sock *sk,int bytes);
325 void (*write_space)(struct sock *sk);
326 void (*error_report)(struct sock *sk);
327
328 };
329
330
331
332
333
334 struct proto
335 {
336 void (*close)(struct sock *sk, unsigned long timeout);
337 int (*build_header)(struct sk_buff *skb,
338 __u32 saddr,
339 __u32 daddr,
340 struct device **dev, int type,
341 struct options *opt, int len,
342 int tos, int ttl, struct rtable ** rp);
343 int (*connect)(struct sock *sk,
344 struct sockaddr_in *usin, int addr_len);
345 struct sock * (*accept) (struct sock *sk, int flags);
346 void (*queue_xmit)(struct sock *sk,
347 struct device *dev, struct sk_buff *skb,
348 int free);
349 void (*retransmit)(struct sock *sk, int all);
350 void (*write_wakeup)(struct sock *sk);
351 void (*read_wakeup)(struct sock *sk);
352 int (*rcv)(struct sk_buff *buff, struct device *dev,
353 struct options *opt, __u32 daddr,
354 unsigned short len, __u32 saddr,
355 int redo, struct inet_protocol *protocol);
356 int (*select)(struct sock *sk, int which,
357 select_table *wait);
358 int (*ioctl)(struct sock *sk, int cmd,
359 unsigned long arg);
360 int (*init)(struct sock *sk);
361 void (*shutdown)(struct sock *sk, int how);
362 int (*setsockopt)(struct sock *sk, int level, int optname,
363 char *optval, int optlen);
364 int (*getsockopt)(struct sock *sk, int level, int optname,
365 char *optval, int *option);
366 int (*sendmsg)(struct sock *sk, struct msghdr *msg, int len,
367 int noblock, int flags);
368 int (*recvmsg)(struct sock *sk, struct msghdr *msg, int len,
369 int noblock, int flags, int *addr_len);
370 int (*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len);
371 unsigned short max_header;
372 unsigned long retransmits;
373 char name[32];
374 int inuse, highestinuse;
375 struct sock * sock_array[SOCK_ARRAY_SIZE];
376 };
377
378 #define TIME_WRITE 1
379 #define TIME_CLOSE 2
380 #define TIME_KEEPOPEN 3
381 #define TIME_DESTROY 4
382 #define TIME_DONE 5
383 #define TIME_PROBE0 6
384
385
386
387
388
389 #define SOCK_DESTROY_TIME (10*HZ)
390
391
392
393
394
395 #define PROT_SOCK 1024
396
397 #define SHUTDOWN_MASK 3
398 #define RCV_SHUTDOWN 1
399 #define SEND_SHUTDOWN 2
400
401
402
403
404
405
406
407
408
409
410
411 extern void __release_sock(struct sock *sk);
412
413 static inline void lock_sock(struct sock *sk)
414 {
415 #if 1
416
417
418 if (sk->users) {
419 __label__ here;
420 printk("double lock on socket at %p\n", &&here);
421 here:
422 }
423 #endif
424 sk->users++;
425 barrier();
426 }
427
428 static inline void release_sock(struct sock *sk)
429 {
430 barrier();
431 #if 1
432
433 if (sk->users == 0) {
434 __label__ here;
435 sk->users = 1;
436 printk("trying to unlock unlocked socket at %p\n", &&here);
437 here:
438 }
439 #endif
440 if (!--sk->users)
441 __release_sock(sk);
442 }
443
444
445 extern struct sock * sk_alloc(int priority);
446 extern void sk_free(struct sock *sk);
447 extern void destroy_sock(struct sock *sk);
448 extern unsigned short get_new_socknum(struct proto *,
449 unsigned short);
450 extern void put_sock(unsigned short, struct sock *);
451 extern struct sock *get_sock(struct proto *, unsigned short,
452 unsigned long, unsigned short,
453 unsigned long);
454 extern struct sock *get_sock_mcast(struct sock *, unsigned short,
455 unsigned long, unsigned short,
456 unsigned long);
457 extern struct sock *get_sock_raw(struct sock *, unsigned short,
458 unsigned long, unsigned long);
459
460 extern struct sk_buff *sock_wmalloc(struct sock *sk,
461 unsigned long size, int force,
462 int priority);
463 extern struct sk_buff *sock_rmalloc(struct sock *sk,
464 unsigned long size, int force,
465 int priority);
466 extern void sock_wfree(struct sock *sk,
467 struct sk_buff *skb);
468 extern void sock_rfree(struct sock *sk,
469 struct sk_buff *skb);
470 extern unsigned long sock_rspace(struct sock *sk);
471 extern unsigned long sock_wspace(struct sock *sk);
472
473 extern int sock_setsockopt(struct sock *sk, int level,
474 int op, char *optval,
475 int optlen);
476
477 extern int sock_getsockopt(struct sock *sk, int level,
478 int op, char *optval,
479 int *optlen);
480 extern struct sk_buff *sock_alloc_send_skb(struct sock *skb,
481 unsigned long size,
482 unsigned long fallback,
483 int noblock,
484 int *errcode);
485
486
487
488
489
490
491
492
493
494
495 extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
496 {
497 if (sk->rmem_alloc + skb->truesize >= sk->rcvbuf)
498 return -ENOMEM;
499 atomic_add(skb->truesize, &sk->rmem_alloc);
500 skb->sk=sk;
501 __skb_queue_tail(&sk->receive_queue,skb);
502 if (!sk->dead)
503 sk->data_ready(sk,skb->len);
504 return 0;
505 }
506
507
508
509
510
511 extern __inline__ int sock_error(struct sock *sk)
512 {
513 int err=xchg(&sk->err,0);
514 return -err;
515 }
516
517
518
519
520
521 extern struct sock *timer_base;
522
523 extern void delete_timer (struct sock *);
524 extern void reset_timer (struct sock *, int, unsigned long);
525 extern void net_timer (unsigned long);
526
527
528
529
530
531
532 #define NETDEBUG(x) x
533
534 #endif