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