2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * Definitions for the AF_INET socket handler.
8 * Version: @(#)sock.h 1.0.4 05/13/93
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Florian La Roche <flla@stud.uni-sb.de>
16 * Alan Cox : Volatiles in skbuff pointers. See
17 * skbuff comments. May be overdone,
18 * better to prove they can be removed
20 * Alan Cox : Added a zapped field for tcp to note
21 * a socket is reset and must stay shut up
22 * Alan Cox : New fields for options
23 * Pauline Middelink : identd support
24 * Alan Cox : Eliminate low level recv/recvfrom
25 * David S. Miller : New socket lookup architecture.
26 * Steve Whitehouse: Default routines for sock_ops
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License
30 * as published by the Free Software Foundation; either version
31 * 2 of the License, or (at your option) any later version.
36 #include <linux/config.h>
37 #include <linux/timer.h>
38 #include <linux/in.h> /* struct sockaddr_in */
40 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
41 #include <linux/in6.h> /* struct sockaddr_in6 */
42 #include <linux/ipv6.h> /* dest_cache, inet6_options */
43 #include <linux/icmpv6.h>
44 #include <net/if_inet6.h> /* struct ipv6_mc_socklist */
47 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
48 #include <linux/icmp.h>
50 #include <linux/tcp.h> /* struct tcphdr */
52 #include <linux/netdevice.h>
53 #include <linux/skbuff.h> /* struct sk_buff */
54 #include <net/protocol.h> /* struct inet_protocol */
55 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
58 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
60 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
61 #include <net/netrom.h>
63 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
68 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
69 #if defined(CONFIG_SPX) || defined(CONFIG_SPX_MODULE)
73 #endif /* CONFIG_SPX */
74 #endif /* CONFIG_IPX */
76 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
77 #include <linux/atalk.h>
80 #if defined(CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
85 #include <linux/filter.h>
88 #include <asm/atomic.h>
90 #define MIN_WRITE_SPACE 2048
92 /* The AF_UNIX specific socket options */
97 struct unix_address
*addr
;
98 struct dentry
* dentry
;
99 struct semaphore readsem
;
107 #ifdef CONFIG_NETLINK
108 struct netlink_callback
;
115 int (*handler
)(int unit
, struct sk_buff
*skb
);
117 struct netlink_callback
*cb
;
121 /* Once the IPX ncpd patches are in these are going into protinfo. */
122 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
124 ipx_address dest_addr
;
125 ipx_interface
*intrfc
;
127 #ifdef CONFIG_IPX_INTERN
128 unsigned char node
[IPX_NODE_LEN
];
132 * To handle special ncp connection-handling sockets for mars_nwe,
133 * the connection number must be stored in the socket.
135 unsigned short ipx_ncp_conn
;
139 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
141 struct in6_addr saddr
;
142 struct in6_addr rcv_saddr
;
143 struct in6_addr daddr
;
144 struct in6_addr
*daddr_cache
;
153 /* pktoption flags */
172 struct ipv6_mc_socklist
*ipv6_mc_list
;
175 struct ipv6_txoptions
*opt
;
176 struct sk_buff
*pktoptions
;
180 __u32 checksum
; /* perform checksum */
181 __u32 offset
; /* checksum offset */
183 struct icmp6_filter filter
;
188 #if defined(CONFIG_INET) || defined(CONFIG_INET_MODULE)
190 struct icmp_filter filter
;
194 /* This defines a selective acknowledgement block. */
195 struct tcp_sack_block
{
201 int tcp_header_len
; /* Bytes of tcp header to send */
204 * Header prediction flags
205 * 0x5?10 << 16 + snd_wnd in net byte order
210 * RFC793 variables by their proper names. This means you can
211 * read the code and the spec side by side (and laugh ...)
212 * See RFC793 and RFC1122. The RFC writes these in capitals.
214 __u32 rcv_nxt
; /* What we want to receive next */
215 __u32 snd_nxt
; /* Next sequence we send */
217 __u32 snd_una
; /* First byte we want an ack for */
218 __u32 rcv_tstamp
; /* timestamp of last received packet */
219 __u32 lrcvtime
; /* timestamp of last received data packet*/
220 __u32 srtt
; /* smothed round trip time << 3 */
222 __u32 ato
; /* delayed ack timeout */
223 __u32 snd_wl1
; /* Sequence for window update */
225 __u32 snd_wl2
; /* Ack sequence for update */
226 __u32 snd_wnd
; /* The window we expect to receive */
228 __u32 pmtu_cookie
; /* Last pmtu seen by socket */
229 __u16 mss_cache
; /* Cached effective mss, not including SACKS */
230 __u16 mss_clamp
; /* Maximal mss, negotiated at connection setup */
231 __u16 ext_header_len
; /* Dave, do you allow mw to use this hole? 8) --ANK */
232 __u8 pending
; /* pending events */
234 __u32 last_ack_sent
; /* last ack we sent */
236 __u32 backoff
; /* backoff */
237 __u32 mdev
; /* medium deviation */
238 __u32 snd_cwnd
; /* Sending congestion window */
239 __u32 rto
; /* retransmit timeout */
241 __u32 packets_out
; /* Packets which are "in flight" */
242 __u32 fackets_out
; /* Non-retrans SACK'd packets */
243 __u32 retrans_out
; /* Fast-retransmitted packets out */
244 __u32 high_seq
; /* snd_nxt at onset of congestion */
246 * Slow start and congestion control (see also Nagle, and Karn & Partridge)
248 __u32 snd_ssthresh
; /* Slow start size threshold */
249 __u16 snd_cwnd_cnt
; /* Linear increase counter */
250 __u8 dup_acks
; /* Consequetive duplicate acks seen from other end */
252 __u16 user_mss
; /* mss requested by user in ioctl */
254 /* Two commonly used timers in both sender and receiver paths. */
255 struct timer_list retransmit_timer
; /* Resend (no ack) */
256 struct timer_list delack_timer
; /* Ack delay */
258 struct sk_buff_head out_of_order_queue
; /* Out of order segments go here */
260 struct tcp_func
*af_specific
; /* Operations which are AF_INET{4,6} specific */
261 struct sk_buff
*send_head
; /* Front of stuff to transmit */
262 struct sk_buff
*retrans_head
; /* retrans head can be
263 * different to the head of
264 * write queue if we are doing
268 __u32 rcv_wnd
; /* Current receiver window */
269 __u32 rcv_wup
; /* rcv_nxt on last window update sent */
273 * Options received (usually on last packet, some only on SYN packets).
275 char tstamp_ok
, /* TIMESTAMP seen on SYN packet */
276 wscale_ok
, /* Wscale seen on SYN packet */
277 sack_ok
; /* SACK seen on SYN packet */
278 char saw_tstamp
; /* Saw TIMESTAMP on last packet */
279 __u8 snd_wscale
; /* Window scaling received from sender */
280 __u8 rcv_wscale
; /* Window scaling to send to receiver */
281 __u8 rexmt_done
; /* Retransmitted up to send head? */
282 __u32 rcv_tsval
; /* Time stamp value */
283 __u32 rcv_tsecr
; /* Time stamp echo reply */
284 __u32 ts_recent
; /* Time stamp to echo next */
285 __u32 ts_recent_stamp
;/* Time we stored ts_recent (for aging) */
286 int num_sacks
; /* Number of SACK blocks */
287 struct tcp_sack_block selective_acks
[4]; /* The SACKS themselves*/
289 struct timer_list probe_timer
; /* Probes */
290 __u32 window_clamp
; /* XXX Document this... -DaveM */
291 __u32 probes_out
; /* unanswered 0 window probes */
297 __u32 last_seg_size
; /* Size of last incoming segment */
298 __u32 rcv_mss
; /* MSS used for delayed ACK decisions */
300 struct open_request
*syn_wait_queue
;
301 struct open_request
**syn_wait_last
;
303 int syn_backlog
; /* Backlog of received SYNs */
308 * This structure really needs to be cleaned up.
309 * Most of it is for TCP, and not used by any of
310 * the other protocols.
314 * The idea is to start moving to a newer struct gradualy
316 * IMHO the newer struct should have the following format:
319 * sockmem [mem, proto, callbacks]
344 /* Define this to get the sk->debug debugging facility. */
345 #define SOCK_DEBUGGING
346 #ifdef SOCK_DEBUGGING
347 #define SOCK_DEBUG(sk, msg...) do { if((sk) && ((sk)->debug)) printk(KERN_DEBUG ## msg); } while (0)
349 #define SOCK_DEBUG(sk, msg...) do { } while (0)
353 /* This must be first. */
354 struct sock
*sklist_next
;
355 struct sock
*sklist_prev
;
357 /* Local port binding hash linkage. */
358 struct sock
*bind_next
;
359 struct sock
**bind_pprev
;
361 /* Socket demultiplex comparisons on incoming packets. */
362 __u32 daddr
; /* Foreign IPv4 addr */
363 __u32 rcv_saddr
; /* Bound local IPv4 addr */
364 __u16 dport
; /* Destination port */
365 unsigned short num
; /* Local port */
366 int bound_dev_if
; /* Bound device index if != 0 */
368 /* Main hash linkage for various protocol lookup tables. */
372 volatile unsigned char state
, /* Connection state */
373 zapped
; /* In ax25 & ipx means not linked */
374 __u16 sport
; /* Source port */
376 unsigned short family
; /* Address family */
377 unsigned char reuse
, /* SO_REUSEADDR setting */
378 nonagle
; /* Disable Nagle algorithm? */
380 atomic_t sock_readers
; /* User count */
381 int rcvbuf
; /* Size of receive buffer in bytes */
383 struct wait_queue
**sleep
; /* Sock wait queue */
384 struct dst_entry
*dst_cache
; /* Destination cache */
385 atomic_t rmem_alloc
; /* Receive queue bytes committed */
386 struct sk_buff_head receive_queue
; /* Incoming packets */
387 atomic_t wmem_alloc
; /* Transmit queue bytes committed */
388 struct sk_buff_head write_queue
; /* Packet sending queue */
389 atomic_t omem_alloc
; /* "o" is "option" or "other" */
390 __u32 saddr
; /* Sending source */
391 unsigned int allocation
; /* Allocation mode */
392 int sndbuf
; /* Size of send buffer in bytes */
395 /* Not all are volatile, but some are, so we might as well say they all are.
396 * XXX Make this a flag word -DaveM
409 unsigned long lingertime
;
414 /* Error and backlog packet queues, rarely used. */
415 struct sk_buff_head back_log
,
420 unsigned short shutdown
;
422 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
424 struct ipv6_pinfo af_inet6
;
429 struct tcp_opt af_tcp
;
430 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
431 struct raw_opt tp_raw4
;
433 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
434 struct raw6_opt tp_raw
;
435 #endif /* CONFIG_IPV6 */
436 #if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)
437 struct spx_opt af_spx
;
438 #endif /* CONFIG_SPX */
442 int err
, err_soft
; /* Soft holds errors that don't
443 cause failure but are the cause
444 of a persistent failure not just
446 unsigned short ack_backlog
;
447 unsigned short max_ack_backlog
;
450 unsigned char localroute
; /* Route locally only */
451 unsigned char protocol
;
452 struct ucred peercred
;
455 /* Socket Filtering Instructions */
457 struct sock_filter
*filter_data
;
458 #endif /* CONFIG_FILTER */
460 /* This is where all the private (optional) areas that don't
461 * overlap will eventually live.
465 struct unix_opt af_unix
;
466 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
467 struct atalk_sock af_at
;
469 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
470 struct ipx_opt af_ipx
;
472 #if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
475 #if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
476 struct packet_opt
*af_packet
;
478 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
481 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
484 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
487 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
490 #ifdef CONFIG_NETLINK
491 struct netlink_opt af_netlink
;
493 #if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)
494 struct econet_opt
*af_econet
;
498 /* IP 'private area' or will be eventually. */
499 int ip_ttl
; /* TTL setting */
500 int ip_tos
; /* TOS */
501 unsigned ip_cmsg_flags
;
502 struct ip_options
*opt
;
503 unsigned char ip_hdrincl
; /* Include headers ? */
504 __u8 ip_mc_ttl
; /* Multicasting TTL */
505 __u8 ip_mc_loop
; /* Loopback */
508 int ip_mc_index
; /* Multicast device index */
510 struct ip_mc_socklist
*ip_mc_list
; /* Group array */
512 /* This part is used for the timeout functions (timer.c). */
513 int timeout
; /* What are we waiting for? */
514 struct timer_list timer
; /* This is the sock cleanup timer. */
515 struct timeval stamp
;
518 struct socket
*socket
;
520 /* RPC layer private data */
524 void (*state_change
)(struct sock
*sk
);
525 void (*data_ready
)(struct sock
*sk
,int bytes
);
526 void (*write_space
)(struct sock
*sk
);
527 void (*error_report
)(struct sock
*sk
);
529 int (*backlog_rcv
) (struct sock
*sk
,
530 struct sk_buff
*skb
);
531 void (*destruct
)(struct sock
*sk
);
534 /* IP protocol blocks we attach to sockets.
535 * socket layer -> transport layer interface
536 * transport -> network interface is defined by struct inet_proto
539 /* These must be first. */
540 struct sock
*sklist_next
;
541 struct sock
*sklist_prev
;
543 void (*close
)(struct sock
*sk
,
545 int (*connect
)(struct sock
*sk
,
546 struct sockaddr
*uaddr
,
549 struct sock
* (*accept
) (struct sock
*sk
, int flags
);
550 void (*retransmit
)(struct sock
*sk
, int all
);
551 void (*write_wakeup
)(struct sock
*sk
);
552 void (*read_wakeup
)(struct sock
*sk
);
554 unsigned int (*poll
)(struct file
* file
, struct socket
*sock
,
555 struct poll_table_struct
*wait
);
557 int (*ioctl
)(struct sock
*sk
, int cmd
,
559 int (*init
)(struct sock
*sk
);
560 int (*destroy
)(struct sock
*sk
);
561 void (*shutdown
)(struct sock
*sk
, int how
);
562 int (*setsockopt
)(struct sock
*sk
, int level
,
563 int optname
, char *optval
, int optlen
);
564 int (*getsockopt
)(struct sock
*sk
, int level
,
565 int optname
, char *optval
,
567 int (*sendmsg
)(struct sock
*sk
, struct msghdr
*msg
,
569 int (*recvmsg
)(struct sock
*sk
, struct msghdr
*msg
,
570 int len
, int noblock
, int flags
,
572 int (*bind
)(struct sock
*sk
,
573 struct sockaddr
*uaddr
, int addr_len
);
575 int (*backlog_rcv
) (struct sock
*sk
,
576 struct sk_buff
*skb
);
578 /* Keeping track of sk's, looking them up, and port selection methods. */
579 void (*hash
)(struct sock
*sk
);
580 void (*unhash
)(struct sock
*sk
);
581 void (*rehash
)(struct sock
*sk
);
582 unsigned short (*good_socknum
)(void);
583 int (*verify_bind
)(struct sock
*sk
, unsigned short snum
);
585 unsigned short max_header
;
586 unsigned long retransmits
;
588 int inuse
, highestinuse
;
591 #define TIME_WRITE 1 /* Not yet used */
592 #define TIME_RETRANS 2 /* Retransmit timer */
593 #define TIME_DACK 3 /* Delayed ack timer */
595 #define TIME_KEEPOPEN 5
596 #define TIME_DESTROY 6
597 #define TIME_DONE 7 /* Used to absorb those last few packets */
598 #define TIME_PROBE0 8
600 /* About 10 seconds */
601 #define SOCK_DESTROY_TIME (10*HZ)
603 /* Sockets 0-1023 can't be bound to unless you are superuser */
604 #define PROT_SOCK 1024
606 #define SHUTDOWN_MASK 3
607 #define RCV_SHUTDOWN 1
608 #define SEND_SHUTDOWN 2
610 /* Per-protocol hash table implementations use this to make sure
613 #define SOCKHASH_LOCK() start_bh_atomic()
614 #define SOCKHASH_UNLOCK() end_bh_atomic()
616 /* Some things in the kernel just want to get at a protocols
617 * entire socket list commensurate, thus...
619 static __inline__
void add_to_prot_sklist(struct sock
*sk
)
622 if(!sk
->sklist_next
) {
623 struct proto
*p
= sk
->prot
;
625 sk
->sklist_prev
= (struct sock
*) p
;
626 sk
->sklist_next
= p
->sklist_next
;
627 p
->sklist_next
->sklist_prev
= sk
;
630 /* Charge the protocol. */
631 sk
->prot
->inuse
+= 1;
632 if(sk
->prot
->highestinuse
< sk
->prot
->inuse
)
633 sk
->prot
->highestinuse
= sk
->prot
->inuse
;
638 static __inline__
void del_from_prot_sklist(struct sock
*sk
)
641 if(sk
->sklist_next
) {
642 sk
->sklist_next
->sklist_prev
= sk
->sklist_prev
;
643 sk
->sklist_prev
->sklist_next
= sk
->sklist_next
;
644 sk
->sklist_next
= NULL
;
651 * Used by processes to "lock" a socket state, so that
652 * interrupts and bottom half handlers won't change it
653 * from under us. It essentially blocks any incoming
654 * packets, so that we won't get any new data or any
655 * packets that change the state of the socket.
657 * Note the 'barrier()' calls: gcc may not move a lock
658 * "downwards" or a unlock "upwards" when optimizing.
660 extern void __release_sock(struct sock
*sk
);
662 static inline void lock_sock(struct sock
*sk
)
665 /* debugging code: the test isn't even 100% correct, but it can catch bugs */
666 /* Note that a double lock is ok in theory - it's just _usually_ a bug */
667 if (atomic_read(&sk
->sock_readers
)) {
669 printk("double lock on socket at %p\n", &&here
);
673 atomic_inc(&sk
->sock_readers
);
677 static inline void release_sock(struct sock
*sk
)
680 if (atomic_dec_and_test(&sk
->sock_readers
))
685 * This might not be the most appropriate place for this two
686 * but since they are used by a lot of the net related code
687 * at least they get declared on a include that is common to all
690 static __inline__
int min(unsigned int a
, unsigned int b
)
697 static __inline__
int max(unsigned int a
, unsigned int b
)
704 extern struct sock
* sk_alloc(int family
, int priority
, int zero_it
);
705 extern void sk_free(struct sock
*sk
);
706 extern void destroy_sock(struct sock
*sk
);
708 extern struct sk_buff
*sock_wmalloc(struct sock
*sk
,
709 unsigned long size
, int force
,
711 extern struct sk_buff
*sock_rmalloc(struct sock
*sk
,
712 unsigned long size
, int force
,
714 extern void sock_wfree(struct sk_buff
*skb
);
715 extern void sock_rfree(struct sk_buff
*skb
);
716 extern unsigned long sock_rspace(struct sock
*sk
);
717 extern unsigned long sock_wspace(struct sock
*sk
);
719 extern int sock_setsockopt(struct socket
*sock
, int level
,
720 int op
, char *optval
,
723 extern int sock_getsockopt(struct socket
*sock
, int level
,
724 int op
, char *optval
,
726 extern struct sk_buff
*sock_alloc_send_skb(struct sock
*sk
,
728 unsigned long fallback
,
731 extern void *sock_kmalloc(struct sock
*sk
, int size
, int priority
);
732 extern void sock_kfree_s(struct sock
*sk
, void *mem
, int size
);
736 * Functions to fill in entries in struct proto_ops when a protocol
737 * does not implement a particular function.
739 extern int sock_no_dup(struct socket
*, struct socket
*);
740 extern int sock_no_release(struct socket
*,
742 extern int sock_no_bind(struct socket
*,
743 struct sockaddr
*, int);
744 extern int sock_no_connect(struct socket
*,
745 struct sockaddr
*, int, int);
746 extern int sock_no_socketpair(struct socket
*,
748 extern int sock_no_accept(struct socket
*,
749 struct socket
*, int);
750 extern int sock_no_getname(struct socket
*,
751 struct sockaddr
*, int *, int);
752 extern unsigned int sock_no_poll(struct file
*, struct socket
*,
753 struct poll_table_struct
*);
754 extern int sock_no_ioctl(struct socket
*, unsigned int,
756 extern int sock_no_listen(struct socket
*, int);
757 extern int sock_no_shutdown(struct socket
*, int);
758 extern int sock_no_getsockopt(struct socket
*, int , int,
760 extern int sock_no_setsockopt(struct socket
*, int, int,
762 extern int sock_no_fcntl(struct socket
*,
763 unsigned int, unsigned long);
764 extern int sock_no_sendmsg(struct socket
*,
765 struct msghdr
*, int,
766 struct scm_cookie
*);
767 extern int sock_no_recvmsg(struct socket
*,
768 struct msghdr
*, int,
769 struct scm_cookie
*);
772 * Default socket callbacks and setup code
775 extern void sock_def_callback1(struct sock
*);
776 extern void sock_def_callback2(struct sock
*, int);
777 extern void sock_def_callback3(struct sock
*);
778 extern void sock_def_destruct(struct sock
*);
780 /* Initialise core socket variables */
781 extern void sock_init_data(struct socket
*sock
, struct sock
*sk
);
783 extern void sklist_remove_socket(struct sock
**list
, struct sock
*sk
);
784 extern void sklist_insert_socket(struct sock
**list
, struct sock
*sk
);
785 extern void sklist_destroy_socket(struct sock
**list
, struct sock
*sk
);
789 * Run the filter code and then cut skb->data to correct size returned by
790 * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller
791 * than pkt_len we keep whole skb->data.
793 extern __inline__
int sk_filter(struct sk_buff
*skb
, struct sock_filter
*filter
, int flen
)
797 pkt_len
= sk_run_filter(skb
->data
, skb
->len
, filter
, flen
);
799 return 1; /* Toss Packet */
801 skb_trim(skb
, pkt_len
);
805 #endif /* CONFIG_FILTER */
808 * Queue a received datagram if it will fit. Stream and sequenced
809 * protocols can't normally use this as they need to fit buffers in
810 * and play with them.
812 * Inlined as it's very short and called for pretty much every
813 * packet ever received.
816 extern __inline__
void skb_set_owner_w(struct sk_buff
*skb
, struct sock
*sk
)
819 skb
->destructor
= sock_wfree
;
820 atomic_add(skb
->truesize
, &sk
->wmem_alloc
);
823 extern __inline__
void skb_set_owner_r(struct sk_buff
*skb
, struct sock
*sk
)
826 skb
->destructor
= sock_rfree
;
827 atomic_add(skb
->truesize
, &sk
->rmem_alloc
);
831 extern __inline__
int sock_queue_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
833 /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
834 number of warnings when compiling with -W --ANK
836 if (atomic_read(&sk
->rmem_alloc
) + skb
->truesize
>= (unsigned)sk
->rcvbuf
)
842 if (sk_filter(skb
, sk
->filter_data
, sk
->filter
))
843 return -EPERM
; /* Toss packet */
845 #endif /* CONFIG_FILTER */
847 skb_set_owner_r(skb
, sk
);
848 skb_queue_tail(&sk
->receive_queue
, skb
);
850 sk
->data_ready(sk
,skb
->len
);
854 extern __inline__
int sock_queue_err_skb(struct sock
*sk
, struct sk_buff
*skb
)
856 /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
857 number of warnings when compiling with -W --ANK
859 if (atomic_read(&sk
->rmem_alloc
) + skb
->truesize
>= (unsigned)sk
->rcvbuf
)
861 skb_set_owner_r(skb
, sk
);
862 skb_queue_tail(&sk
->error_queue
,skb
);
864 sk
->data_ready(sk
,skb
->len
);
869 * Recover an error report and clear atomically
872 extern __inline__
int sock_error(struct sock
*sk
)
874 int err
=xchg(&sk
->err
,0);
878 extern __inline__
unsigned long sock_wspace(struct sock
*sk
)
882 if (!(sk
->shutdown
& SEND_SHUTDOWN
)) {
883 amt
= sk
->sndbuf
- atomic_read(&sk
->wmem_alloc
);
891 * Default write policy as shown to user space via poll/select/SIGIO
892 * Kernel internally doesn't use the MIN_WRITE_SPACE threshold.
894 extern __inline__
int sock_writeable(struct sock
*sk
)
896 return sock_wspace(sk
) >= MIN_WRITE_SPACE
;
900 * Declarations from timer.c
903 extern struct sock
*timer_base
;
905 extern void net_delete_timer (struct sock
*);
906 extern void net_reset_timer (struct sock
*, int, unsigned long);
907 extern void net_timer (unsigned long);
911 * Enable debug/info messages
915 #define NETDEBUG(x) do { } while (0)
917 #define NETDEBUG(x) do { x; } while (0)