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
32
33#ifndef _SOCK_H
34#define _SOCK_H
35
36#include <linux/config.h>
37#include <linux/timer.h>
38#include <linux/cache.h>
39#include <linux/in.h>
40
41#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
42#include <linux/in6.h>
43#include <linux/ipv6.h>
44#include <linux/icmpv6.h>
45#include <net/if_inet6.h>
46#endif
47
48#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
49#include <linux/icmp.h>
50#endif
51#include <linux/tcp.h>
52#if defined(CONFIG_IP_SCTP) || defined (CONFIG_IP_SCTP_MODULE)
53#include <net/sctp/structs.h>
54#endif
55
56#include <linux/netdevice.h>
57#include <linux/skbuff.h>
58#include <net/protocol.h>
59#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
60#include <net/x25.h>
61#endif
62#if defined(CONFIG_WAN_ROUTER) || defined(CONFIG_WAN_ROUTER_MODULE)
63#include <linux/if_wanpipe.h>
64#endif
65
66#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
67#include <net/ax25.h>
68#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
69#include <net/netrom.h>
70#endif
71#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
72#include <net/rose.h>
73#endif
74#endif
75
76#if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)
77#include <linux/if_pppox.h>
78#include <linux/ppp_channel.h>
79#endif
80
81#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
82#if defined(CONFIG_SPX) || defined(CONFIG_SPX_MODULE)
83#include <net/spx.h>
84#else
85#include <net/ipx.h>
86#endif
87#endif
88
89#if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
90#include <linux/atalk.h>
91#endif
92
93#if defined(CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
94#include <net/dn.h>
95#endif
96
97#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
98#include <net/irda/irda.h>
99#endif
100
101#if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)
102struct atm_vcc;
103#endif
104
105#ifdef CONFIG_FILTER
106#include <linux/filter.h>
107#endif
108
109#include <asm/atomic.h>
110#include <net/dst.h>
111
112
113
114struct unix_opt {
115 struct unix_address *addr;
116 struct dentry * dentry;
117 struct vfsmount * mnt;
118 struct semaphore readsem;
119 struct sock * other;
120 struct sock ** list;
121 struct sock * gc_tree;
122 atomic_t inflight;
123 rwlock_t lock;
124 wait_queue_head_t peer_wait;
125};
126
127
128
129#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
130struct ipx_opt {
131 ipx_address dest_addr;
132 ipx_interface *intrfc;
133 unsigned short port;
134#ifdef CONFIG_IPX_INTERN
135 unsigned char node[IPX_NODE_LEN];
136#endif
137 unsigned short type;
138
139
140
141
142 unsigned short ipx_ncp_conn;
143};
144#endif
145
146#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
147struct ipv6_pinfo {
148 struct in6_addr saddr;
149 struct in6_addr rcv_saddr;
150 struct in6_addr daddr;
151 struct in6_addr *daddr_cache;
152
153 __u32 flow_label;
154 __u32 frag_size;
155 int hop_limit;
156 int mcast_hops;
157 int mcast_oif;
158
159
160 union {
161 struct {
162 __u8 srcrt:2,
163 rxinfo:1,
164 rxhlim:1,
165 hopopts:1,
166 dstopts:1,
167 authhdr:1,
168 rxflow:1;
169 } bits;
170 __u8 all;
171 } rxopt;
172
173
174 __u8 mc_loop:1,
175 recverr:1,
176 sndflow:1,
177 pmtudisc:2,
178 ipv6only:1;
179
180 struct ipv6_mc_socklist *ipv6_mc_list;
181 struct ipv6_ac_socklist *ipv6_ac_list;
182 struct ipv6_fl_socklist *ipv6_fl_list;
183 __u32 dst_cookie;
184
185 struct ipv6_txoptions *opt;
186 struct sk_buff *pktoptions;
187};
188
189struct raw6_opt {
190 __u32 checksum;
191 __u32 offset;
192
193 struct icmp6_filter filter;
194};
195
196#define __ipv6_only_sock(sk) ((sk)->net_pinfo.af_inet6.ipv6only)
197#define ipv6_only_sock(sk) ((sk)->family == PF_INET6 && \
198 (sk)->net_pinfo.af_inet6.ipv6only)
199#else
200#define __ipv6_only_sock(sk) 0
201#define ipv6_only_sock(sk) 0
202#endif
203
204#if defined(CONFIG_INET) || defined(CONFIG_INET_MODULE)
205struct raw_opt {
206 struct icmp_filter filter;
207};
208#endif
209
210#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
211struct inet_opt
212{
213 int ttl;
214 int tos;
215 unsigned cmsg_flags;
216 struct ip_options *opt;
217 unsigned char hdrincl;
218 __u8 mc_ttl;
219 __u8 mc_loop;
220 unsigned recverr : 1,
221 freebind : 1;
222 __u16 id;
223 __u8 pmtudisc;
224 int mc_index;
225 __u32 mc_addr;
226 struct ip_mc_socklist *mc_list;
227};
228#endif
229
230#if defined(CONFIG_PPPOE) || defined (CONFIG_PPPOE_MODULE)
231struct pppoe_opt
232{
233 struct net_device *dev;
234 struct pppoe_addr pa;
235 struct sockaddr_pppox relay;
236
237};
238
239struct pppox_opt
240{
241 struct ppp_channel chan;
242 struct sock *sk;
243 struct pppox_opt *next;
244 union {
245 struct pppoe_opt pppoe;
246 } proto;
247};
248#define pppoe_dev proto.pppoe.dev
249#define pppoe_pa proto.pppoe.pa
250#define pppoe_relay proto.pppoe.relay
251#endif
252
253
254struct tcp_sack_block {
255 __u32 start_seq;
256 __u32 end_seq;
257};
258
259struct tcp_opt {
260 int tcp_header_len;
261
262
263
264
265
266 __u32 pred_flags;
267
268
269
270
271
272
273 __u32 rcv_nxt;
274 __u32 snd_nxt;
275
276 __u32 snd_una;
277 __u32 snd_sml;
278 __u32 rcv_tstamp;
279 __u32 lsndtime;
280
281
282 struct {
283 __u8 pending;
284 __u8 quick;
285 __u8 pingpong;
286 __u8 blocked;
287 __u32 ato;
288 unsigned long timeout;
289 __u32 lrcvtime;
290 __u16 last_seg_size;
291 __u16 rcv_mss;
292 } ack;
293
294
295 struct {
296 struct sk_buff_head prequeue;
297 struct task_struct *task;
298 struct iovec *iov;
299 int memory;
300 int len;
301 } ucopy;
302
303 __u32 snd_wl1;
304 __u32 snd_wnd;
305 __u32 max_window;
306 __u32 pmtu_cookie;
307 __u16 mss_cache;
308 __u16 mss_clamp;
309 __u16 ext_header_len;
310 __u8 ca_state;
311 __u8 retransmits;
312
313 __u8 reordering;
314 __u8 queue_shrunk;
315 __u8 defer_accept;
316
317
318 __u8 backoff;
319 __u32 srtt;
320 __u32 mdev;
321 __u32 mdev_max;
322 __u32 rttvar;
323 __u32 rtt_seq;
324 __u32 rto;
325
326 __u32 packets_out;
327 __u32 left_out;
328 __u32 retrans_out;
329
330
331
332
333
334 __u32 snd_ssthresh;
335 __u32 snd_cwnd;
336 __u16 snd_cwnd_cnt;
337 __u16 snd_cwnd_clamp;
338 __u32 snd_cwnd_used;
339 __u32 snd_cwnd_stamp;
340
341
342 unsigned long timeout;
343 struct timer_list retransmit_timer;
344 struct timer_list delack_timer;
345
346 struct sk_buff_head out_of_order_queue;
347
348 struct tcp_func *af_specific;
349 struct sk_buff *send_head;
350 struct page *sndmsg_page;
351 u32 sndmsg_off;
352
353 __u32 rcv_wnd;
354 __u32 rcv_wup;
355 __u32 write_seq;
356 __u32 pushed_seq;
357 __u32 copied_seq;
358
359
360
361 char tstamp_ok,
362 wscale_ok,
363 sack_ok;
364 char saw_tstamp;
365 __u8 snd_wscale;
366 __u8 rcv_wscale;
367 __u8 nonagle;
368 __u8 keepalive_probes;
369
370
371 __u32 rcv_tsval;
372 __u32 rcv_tsecr;
373 __u32 ts_recent;
374 long ts_recent_stamp;
375
376
377 __u16 user_mss;
378 __u8 dsack;
379 __u8 eff_sacks;
380 struct tcp_sack_block duplicate_sack[1];
381 struct tcp_sack_block selective_acks[4];
382
383 __u32 window_clamp;
384 __u32 rcv_ssthresh;
385 __u8 probes_out;
386 __u8 num_sacks;
387 __u16 advmss;
388
389 __u8 syn_retries;
390 __u8 ecn_flags;
391 __u16 prior_ssthresh;
392 __u32 lost_out;
393 __u32 sacked_out;
394 __u32 fackets_out;
395 __u32 high_seq;
396
397 __u32 retrans_stamp;
398
399
400 __u32 undo_marker;
401 int undo_retrans;
402 __u32 urg_seq;
403 __u16 urg_data;
404 __u8 pending;
405 __u8 urg_mode;
406 __u32 snd_up;
407
408
409
410
411
412
413
414
415
416
417
418 rwlock_t syn_wait_lock;
419 struct tcp_listen_opt *listen_opt;
420
421
422 struct open_request *accept_queue;
423 struct open_request *accept_queue_tail;
424
425 int write_pending;
426
427 unsigned int keepalive_time;
428 unsigned int keepalive_intvl;
429 int linger2;
430
431 int frto_counter;
432 __u32 frto_highmark;
433
434 unsigned long last_synq_overflow;
435
436
437 struct {
438 __u32 rtt;
439 __u32 seq;
440 __u32 time;
441 } rcv_rtt_est;
442
443
444 struct {
445 int space;
446 __u32 seq;
447 __u32 time;
448 } rcvq_space;
449
450
451 struct {
452 __u32 bw_ns_est;
453 __u32 bw_est;
454 __u32 rtt_win_sx;
455 __u32 bk;
456 __u32 snd_una;
457 __u32 cumul_ack;
458 __u32 accounted;
459 __u32 rtt;
460 __u32 rtt_min;
461 } westwood;
462
463
464 struct {
465 __u32 beg_snd_nxt;
466 __u32 beg_snd_una;
467 __u32 beg_snd_cwnd;
468 __u8 do_vegas;
469 __u8 doing_vegas_now;
470 __u16 cntRTT;
471 __u32 minRTT;
472 __u32 baseRTT;
473 } vegas;
474
475
476 struct {
477 __u32 cnt;
478 __u32 last_max_cwnd;
479 __u32 last_cwnd;
480 __u32 last_stamp;
481 } bictcp;
482};
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527#define SOCK_DEBUGGING
528#ifdef SOCK_DEBUGGING
529#define SOCK_DEBUG(sk, msg...) do { if((sk) && ((sk)->debug)) printk(KERN_DEBUG msg); } while (0)
530#else
531#define SOCK_DEBUG(sk, msg...) do { } while (0)
532#endif
533
534
535
536
537
538typedef struct {
539 spinlock_t slock;
540 unsigned int users;
541 wait_queue_head_t wq;
542} socket_lock_t;
543
544#define sock_lock_init(__sk) \
545do { spin_lock_init(&((__sk)->lock.slock)); \
546 (__sk)->lock.users = 0; \
547 init_waitqueue_head(&((__sk)->lock.wq)); \
548} while(0)
549
550struct sock {
551
552 __u32 daddr;
553 __u32 rcv_saddr;
554 __u16 dport;
555 unsigned short num;
556 int bound_dev_if;
557
558
559 struct sock *next;
560 struct sock **pprev;
561 struct sock *bind_next;
562 struct sock **bind_pprev;
563
564 volatile unsigned char state,
565 zapped;
566 __u16 sport;
567
568 unsigned short family;
569 unsigned char reuse;
570 unsigned char shutdown;
571 atomic_t refcnt;
572
573 socket_lock_t lock;
574 int rcvbuf;
575
576 wait_queue_head_t *sleep;
577 struct dst_entry *dst_cache;
578 rwlock_t dst_lock;
579 atomic_t rmem_alloc;
580 struct sk_buff_head receive_queue;
581 atomic_t wmem_alloc;
582 struct sk_buff_head write_queue;
583 atomic_t omem_alloc;
584 int wmem_queued;
585 int forward_alloc;
586 __u32 saddr;
587 unsigned int allocation;
588 int sndbuf;
589 struct sock *prev;
590
591
592
593
594 volatile char dead,
595 done,
596 urginline,
597 keepopen,
598 linger,
599 destroy,
600 no_check,
601 broadcast,
602 bsdism;
603 unsigned char debug;
604 unsigned char rcvtstamp;
605 unsigned char use_write_queue;
606 unsigned char userlocks;
607
608 int route_caps;
609 int proc;
610 unsigned long lingertime;
611
612 int hashent;
613 struct sock *pair;
614
615
616
617
618
619 struct {
620 struct sk_buff *head;
621 struct sk_buff *tail;
622 } backlog;
623
624 rwlock_t callback_lock;
625
626
627 struct sk_buff_head error_queue;
628
629 struct proto *prot;
630
631#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
632 union {
633 struct ipv6_pinfo af_inet6;
634 } net_pinfo;
635#endif
636
637 union {
638 struct tcp_opt af_tcp;
639#if defined(CONFIG_IP_SCTP) || defined (CONFIG_IP_SCTP_MODULE)
640 struct sctp_opt af_sctp;
641#endif
642#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
643 struct raw_opt tp_raw4;
644#endif
645#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
646 struct raw6_opt tp_raw;
647#endif
648#if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)
649 struct spx_opt af_spx;
650#endif
651
652 } tp_pinfo;
653
654 int err, err_soft;
655
656
657
658 unsigned short ack_backlog;
659 unsigned short max_ack_backlog;
660 __u32 priority;
661 unsigned short type;
662 unsigned char localroute;
663 unsigned char protocol;
664 struct ucred peercred;
665 int rcvlowat;
666 long rcvtimeo;
667 long sndtimeo;
668
669#ifdef CONFIG_FILTER
670
671 struct sk_filter *filter;
672#endif
673
674
675
676
677 union {
678 void *destruct_hook;
679 struct unix_opt af_unix;
680#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
681 struct inet_opt af_inet;
682#endif
683#if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
684 struct atalk_sock af_at;
685#endif
686#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
687 struct ipx_opt af_ipx;
688#endif
689#if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
690 struct dn_scp dn;
691#endif
692#if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
693 struct packet_opt *af_packet;
694#endif
695#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
696 x25_cb *x25;
697#endif
698#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
699 ax25_cb *ax25;
700#endif
701#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
702 nr_cb *nr;
703#endif
704#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
705 rose_cb *rose;
706#endif
707#if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)
708 struct pppox_opt *pppox;
709#endif
710 struct netlink_opt *af_netlink;
711#if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)
712 struct econet_opt *af_econet;
713#endif
714#if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)
715 struct atm_vcc *af_atm;
716#endif
717#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
718 struct irda_sock *irda;
719#endif
720#if defined(CONFIG_WAN_ROUTER) || defined(CONFIG_WAN_ROUTER_MODULE)
721 struct wanpipe_opt *af_wanpipe;
722#endif
723 } protinfo;
724
725
726
727 struct timer_list timer;
728 struct timeval stamp;
729
730
731 struct socket *socket;
732
733
734 void *user_data;
735
736
737 void (*state_change)(struct sock *sk);
738 void (*data_ready)(struct sock *sk,int bytes);
739 void (*write_space)(struct sock *sk);
740 void (*error_report)(struct sock *sk);
741
742 int (*backlog_rcv) (struct sock *sk,
743 struct sk_buff *skb);
744 void (*destruct)(struct sock *sk);
745};
746
747
748#define sk_add_backlog(__sk, __skb) \
749do { if((__sk)->backlog.tail == NULL) { \
750 (__sk)->backlog.head = \
751 (__sk)->backlog.tail = (__skb); \
752 } else { \
753 ((__sk)->backlog.tail)->next = (__skb); \
754 (__sk)->backlog.tail = (__skb); \
755 } \
756 (__skb)->next = NULL; \
757} while(0)
758
759
760
761
762
763struct proto {
764 void (*close)(struct sock *sk,
765 long timeout);
766 int (*connect)(struct sock *sk,
767 struct sockaddr *uaddr,
768 int addr_len);
769 int (*disconnect)(struct sock *sk, int flags);
770
771 struct sock * (*accept) (struct sock *sk, int flags, int *err);
772
773 int (*ioctl)(struct sock *sk, int cmd,
774 unsigned long arg);
775 int (*init)(struct sock *sk);
776 int (*destroy)(struct sock *sk);
777 void (*shutdown)(struct sock *sk, int how);
778 int (*setsockopt)(struct sock *sk, int level,
779 int optname, char *optval, int optlen);
780 int (*getsockopt)(struct sock *sk, int level,
781 int optname, char *optval,
782 int *option);
783 int (*sendmsg)(struct sock *sk, struct msghdr *msg,
784 int len);
785 int (*recvmsg)(struct sock *sk, struct msghdr *msg,
786 int len, int noblock, int flags,
787 int *addr_len);
788 int (*bind)(struct sock *sk,
789 struct sockaddr *uaddr, int addr_len);
790
791 int (*backlog_rcv) (struct sock *sk,
792 struct sk_buff *skb);
793
794
795 void (*hash)(struct sock *sk);
796 void (*unhash)(struct sock *sk);
797 int (*get_port)(struct sock *sk, unsigned short snum);
798
799 char name[32];
800
801 struct {
802 int inuse;
803 u8 __pad[SMP_CACHE_BYTES - sizeof(int)];
804 } stats[NR_CPUS];
805};
806
807
808static __inline__ void sock_prot_inc_use(struct proto *prot)
809{
810 prot->stats[smp_processor_id()].inuse++;
811}
812
813static __inline__ void sock_prot_dec_use(struct proto *prot)
814{
815 prot->stats[smp_processor_id()].inuse--;
816}
817
818
819#define SOCK_DESTROY_TIME (10*HZ)
820
821
822#define PROT_SOCK 1024
823
824#define SHUTDOWN_MASK 3
825#define RCV_SHUTDOWN 1
826#define SEND_SHUTDOWN 2
827
828#define SOCK_SNDBUF_LOCK 1
829#define SOCK_RCVBUF_LOCK 2
830#define SOCK_BINDADDR_LOCK 4
831#define SOCK_BINDPORT_LOCK 8
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847extern void __lock_sock(struct sock *sk);
848extern void __release_sock(struct sock *sk);
849#define lock_sock(__sk) \
850do { spin_lock_bh(&((__sk)->lock.slock)); \
851 if ((__sk)->lock.users != 0) \
852 __lock_sock(__sk); \
853 (__sk)->lock.users = 1; \
854 spin_unlock_bh(&((__sk)->lock.slock)); \
855} while(0)
856
857#define release_sock(__sk) \
858do { spin_lock_bh(&((__sk)->lock.slock)); \
859 if ((__sk)->backlog.tail != NULL) \
860 __release_sock(__sk); \
861 (__sk)->lock.users = 0; \
862 if (waitqueue_active(&((__sk)->lock.wq))) wake_up(&((__sk)->lock.wq)); \
863 spin_unlock_bh(&((__sk)->lock.slock)); \
864} while(0)
865
866
867#define bh_lock_sock(__sk) spin_lock(&((__sk)->lock.slock))
868#define bh_unlock_sock(__sk) spin_unlock(&((__sk)->lock.slock))
869
870extern struct sock * sk_alloc(int family, int priority, int zero_it);
871extern void sk_free(struct sock *sk);
872
873extern struct sk_buff *sock_wmalloc(struct sock *sk,
874 unsigned long size, int force,
875 int priority);
876extern struct sk_buff *sock_rmalloc(struct sock *sk,
877 unsigned long size, int force,
878 int priority);
879extern void sock_wfree(struct sk_buff *skb);
880extern void sock_rfree(struct sk_buff *skb);
881
882extern int sock_setsockopt(struct socket *sock, int level,
883 int op, char *optval,
884 int optlen);
885
886extern int sock_getsockopt(struct socket *sock, int level,
887 int op, char *optval,
888 int *optlen);
889extern struct sk_buff *sock_alloc_send_skb(struct sock *sk,
890 unsigned long size,
891 int noblock,
892 int *errcode);
893extern struct sk_buff *sock_alloc_send_pskb(struct sock *sk,
894 unsigned long header_len,
895 unsigned long data_len,
896 int noblock,
897 int *errcode);
898extern void *sock_kmalloc(struct sock *sk, int size, int priority);
899extern void sock_kfree_s(struct sock *sk, void *mem, int size);
900
901
902
903
904
905extern int sock_no_release(struct socket *);
906extern int sock_no_bind(struct socket *,
907 struct sockaddr *, int);
908extern int sock_no_connect(struct socket *,
909 struct sockaddr *, int, int);
910extern int sock_no_socketpair(struct socket *,
911 struct socket *);
912extern int sock_no_accept(struct socket *,
913 struct socket *, int);
914extern int sock_no_getname(struct socket *,
915 struct sockaddr *, int *, int);
916extern unsigned int sock_no_poll(struct file *, struct socket *,
917 struct poll_table_struct *);
918extern int sock_no_ioctl(struct socket *, unsigned int,
919 unsigned long);
920extern int sock_no_listen(struct socket *, int);
921extern int sock_no_shutdown(struct socket *, int);
922extern int sock_no_getsockopt(struct socket *, int , int,
923 char *, int *);
924extern int sock_no_setsockopt(struct socket *, int, int,
925 char *, int);
926extern int sock_no_fcntl(struct socket *,
927 unsigned int, unsigned long);
928extern int sock_no_sendmsg(struct socket *,
929 struct msghdr *, int,
930 struct scm_cookie *);
931extern int sock_no_recvmsg(struct socket *,
932 struct msghdr *, int, int,
933 struct scm_cookie *);
934extern int sock_no_mmap(struct file *file,
935 struct socket *sock,
936 struct vm_area_struct *vma);
937extern ssize_t sock_no_sendpage(struct socket *sock,
938 struct page *page,
939 int offset, size_t size,
940 int flags);
941
942
943
944
945
946extern void sock_def_destruct(struct sock *);
947
948
949extern void sock_init_data(struct socket *sock, struct sock *sk);
950
951extern void sklist_remove_socket(struct sock **list, struct sock *sk);
952extern void sklist_insert_socket(struct sock **list, struct sock *sk);
953extern void sklist_destroy_socket(struct sock **list, struct sock *sk);
954
955#ifdef CONFIG_FILTER
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970static inline int sk_filter(struct sock *sk, struct sk_buff *skb, int needlock)
971{
972 int err = 0;
973
974 if (sk->filter) {
975 struct sk_filter *filter;
976
977 if (needlock)
978 bh_lock_sock(sk);
979
980 filter = sk->filter;
981 if (filter) {
982 int pkt_len = sk_run_filter(skb, filter->insns,
983 filter->len);
984 if (!pkt_len)
985 err = -EPERM;
986 else
987 skb_trim(skb, pkt_len);
988 }
989
990 if (needlock)
991 bh_unlock_sock(sk);
992 }
993 return err;
994}
995
996
997
998
999
1000
1001
1002
1003
1004static inline void sk_filter_release(struct sock *sk, struct sk_filter *fp)
1005{
1006 unsigned int size = sk_filter_len(fp);
1007
1008 atomic_sub(size, &sk->omem_alloc);
1009
1010 if (atomic_dec_and_test(&fp->refcnt))
1011 kfree(fp);
1012}
1013
1014static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
1015{
1016 atomic_inc(&fp->refcnt);
1017 atomic_add(sk_filter_len(fp), &sk->omem_alloc);
1018}
1019
1020#else
1021
1022static inline int sk_filter(struct sock *sk, struct sk_buff *skb, int needlock)
1023{
1024 return 0;
1025}
1026
1027#endif
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060static inline void sock_hold(struct sock *sk)
1061{
1062 atomic_inc(&sk->refcnt);
1063}
1064
1065
1066
1067
1068static inline void __sock_put(struct sock *sk)
1069{
1070 atomic_dec(&sk->refcnt);
1071}
1072
1073
1074static inline void sock_put(struct sock *sk)
1075{
1076 if (atomic_dec_and_test(&sk->refcnt))
1077 sk_free(sk);
1078}
1079
1080
1081
1082
1083
1084
1085
1086
1087static inline void sock_orphan(struct sock *sk)
1088{
1089 write_lock_bh(&sk->callback_lock);
1090 sk->dead = 1;
1091 sk->socket = NULL;
1092 sk->sleep = NULL;
1093 write_unlock_bh(&sk->callback_lock);
1094}
1095
1096static inline void sock_graft(struct sock *sk, struct socket *parent)
1097{
1098 write_lock_bh(&sk->callback_lock);
1099 sk->sleep = &parent->wait;
1100 parent->sk = sk;
1101 sk->socket = parent;
1102 write_unlock_bh(&sk->callback_lock);
1103}
1104
1105static inline int sock_i_uid(struct sock *sk)
1106{
1107 int uid;
1108
1109 read_lock(&sk->callback_lock);
1110 uid = sk->socket ? sk->socket->inode->i_uid : 0;
1111 read_unlock(&sk->callback_lock);
1112 return uid;
1113}
1114
1115static inline unsigned long sock_i_ino(struct sock *sk)
1116{
1117 unsigned long ino;
1118
1119 read_lock(&sk->callback_lock);
1120 ino = sk->socket ? sk->socket->inode->i_ino : 0;
1121 read_unlock(&sk->callback_lock);
1122 return ino;
1123}
1124
1125static inline struct dst_entry *
1126__sk_dst_get(struct sock *sk)
1127{
1128 return sk->dst_cache;
1129}
1130
1131static inline struct dst_entry *
1132sk_dst_get(struct sock *sk)
1133{
1134 struct dst_entry *dst;
1135
1136 read_lock(&sk->dst_lock);
1137 dst = sk->dst_cache;
1138 if (dst)
1139 dst_hold(dst);
1140 read_unlock(&sk->dst_lock);
1141 return dst;
1142}
1143
1144static inline void
1145__sk_dst_set(struct sock *sk, struct dst_entry *dst)
1146{
1147 struct dst_entry *old_dst;
1148
1149 old_dst = sk->dst_cache;
1150 sk->dst_cache = dst;
1151 dst_release(old_dst);
1152}
1153
1154static inline void
1155sk_dst_set(struct sock *sk, struct dst_entry *dst)
1156{
1157 write_lock(&sk->dst_lock);
1158 __sk_dst_set(sk, dst);
1159 write_unlock(&sk->dst_lock);
1160}
1161
1162static inline void
1163__sk_dst_reset(struct sock *sk)
1164{
1165 struct dst_entry *old_dst;
1166
1167 old_dst = sk->dst_cache;
1168 sk->dst_cache = NULL;
1169 dst_release(old_dst);
1170}
1171
1172static inline void
1173sk_dst_reset(struct sock *sk)
1174{
1175 write_lock(&sk->dst_lock);
1176 __sk_dst_reset(sk);
1177 write_unlock(&sk->dst_lock);
1178}
1179
1180static inline struct dst_entry *
1181__sk_dst_check(struct sock *sk, u32 cookie)
1182{
1183 struct dst_entry *dst = sk->dst_cache;
1184
1185 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
1186 sk->dst_cache = NULL;
1187 return NULL;
1188 }
1189
1190 return dst;
1191}
1192
1193static inline struct dst_entry *
1194sk_dst_check(struct sock *sk, u32 cookie)
1195{
1196 struct dst_entry *dst = sk_dst_get(sk);
1197
1198 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
1199 sk_dst_reset(sk);
1200 return NULL;
1201 }
1202
1203 return dst;
1204}
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
1217{
1218 sock_hold(sk);
1219 skb->sk = sk;
1220 skb->destructor = sock_wfree;
1221 atomic_add(skb->truesize, &sk->wmem_alloc);
1222}
1223
1224static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
1225{
1226 skb->sk = sk;
1227 skb->destructor = sock_rfree;
1228 atomic_add(skb->truesize, &sk->rmem_alloc);
1229}
1230
1231static inline int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
1232{
1233 int err = 0;
1234 int skb_len;
1235
1236
1237
1238
1239 if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf) {
1240 err = -ENOMEM;
1241 goto out;
1242 }
1243
1244
1245
1246
1247
1248 err = sk_filter(sk, skb, 1);
1249 if (err)
1250 goto out;
1251
1252 skb->dev = NULL;
1253 skb_set_owner_r(skb, sk);
1254
1255
1256
1257
1258
1259
1260 skb_len = skb->len;
1261
1262 skb_queue_tail(&sk->receive_queue, skb);
1263 if (!sk->dead)
1264 sk->data_ready(sk,skb_len);
1265out:
1266 return err;
1267}
1268
1269static inline int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
1270{
1271
1272
1273
1274 if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf)
1275 return -ENOMEM;
1276 skb_set_owner_r(skb, sk);
1277 skb_queue_tail(&sk->error_queue,skb);
1278 if (!sk->dead)
1279 sk->data_ready(sk,skb->len);
1280 return 0;
1281}
1282
1283
1284
1285
1286
1287static inline int sock_error(struct sock *sk)
1288{
1289 int err=xchg(&sk->err,0);
1290 return -err;
1291}
1292
1293static inline unsigned long sock_wspace(struct sock *sk)
1294{
1295 int amt = 0;
1296
1297 if (!(sk->shutdown & SEND_SHUTDOWN)) {
1298 amt = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1299 if (amt < 0)
1300 amt = 0;
1301 }
1302 return amt;
1303}
1304
1305static inline void sk_wake_async(struct sock *sk, int how, int band)
1306{
1307 if (sk->socket && sk->socket->fasync_list)
1308 sock_wake_async(sk->socket, how, band);
1309}
1310
1311#define SOCK_MIN_SNDBUF 2048
1312#define SOCK_MIN_RCVBUF 256
1313
1314
1315
1316
1317static inline int sock_writeable(struct sock *sk)
1318{
1319 return atomic_read(&sk->wmem_alloc) < (sk->sndbuf / 2);
1320}
1321
1322static inline int gfp_any(void)
1323{
1324 return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
1325}
1326
1327static inline long sock_rcvtimeo(struct sock *sk, int noblock)
1328{
1329 return noblock ? 0 : sk->rcvtimeo;
1330}
1331
1332static inline long sock_sndtimeo(struct sock *sk, int noblock)
1333{
1334 return noblock ? 0 : sk->sndtimeo;
1335}
1336
1337static inline int sock_rcvlowat(struct sock *sk, int waitall, int len)
1338{
1339 return (waitall ? len : min_t(int, sk->rcvlowat, len)) ? : 1;
1340}
1341
1342
1343
1344
1345static inline int sock_intr_errno(long timeo)
1346{
1347 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR;
1348}
1349
1350static __inline__ void
1351sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
1352{
1353 if (sk->rcvtstamp)
1354 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP, sizeof(skb->stamp), &skb->stamp);
1355 else
1356 sk->stamp = skb->stamp;
1357}
1358
1359
1360
1361
1362
1363#if 0
1364#define NETDEBUG(x) do { } while (0)
1365#else
1366#define NETDEBUG(x) do { x; } while (0)
1367#endif
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379#define SOCK_SLEEP_PRE(sk) { struct task_struct *tsk = current; \
1380 DECLARE_WAITQUEUE(wait, tsk); \
1381 tsk->state = TASK_INTERRUPTIBLE; \
1382 add_wait_queue((sk)->sleep, &wait); \
1383 release_sock(sk);
1384
1385#define SOCK_SLEEP_POST(sk) tsk->state = TASK_RUNNING; \
1386 remove_wait_queue((sk)->sleep, &wait); \
1387 lock_sock(sk); \
1388 }
1389
1390extern __u32 sysctl_wmem_max;
1391extern __u32 sysctl_rmem_max;
1392
1393#endif
1394