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