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