2.2.0-final
[davej-history.git] / include / net / sock.h
blobc03168f4b61da1593b788fa9508746fa9b3e46de
1 /*
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>
15 * Fixes:
16 * Alan Cox : Volatiles in skbuff pointers. See
17 * skbuff comments. May be overdone,
18 * better to prove they can be removed
19 * than the reverse.
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.
33 #ifndef _SOCK_H
34 #define _SOCK_H
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 */
45 #endif
47 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
48 #include <linux/icmp.h>
49 #endif
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)
56 #include <net/x25.h>
57 #endif
58 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
59 #include <net/ax25.h>
60 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
61 #include <net/netrom.h>
62 #endif
63 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
64 #include <net/rose.h>
65 #endif
66 #endif
68 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
69 #if defined(CONFIG_SPX) || defined(CONFIG_SPX_MODULE)
70 #include <net/spx.h>
71 #else
72 #include <net/ipx.h>
73 #endif /* CONFIG_SPX */
74 #endif /* CONFIG_IPX */
76 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
77 #include <linux/atalk.h>
78 #endif
80 #if defined(CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
81 #include <net/dn.h>
82 #endif
84 #ifdef CONFIG_FILTER
85 #include <linux/filter.h>
86 #endif
88 #include <asm/atomic.h>
90 #define MIN_WRITE_SPACE 2048
92 /* The AF_UNIX specific socket options */
93 struct unix_opt {
94 int family;
95 char * name;
96 int locks;
97 struct unix_address *addr;
98 struct dentry * dentry;
99 struct semaphore readsem;
100 struct sock * other;
101 struct sock ** list;
102 int marksweep;
103 #define MARKED 1
104 int inflight;
107 #ifdef CONFIG_NETLINK
108 struct netlink_callback;
110 struct netlink_opt {
111 pid_t pid;
112 unsigned groups;
113 pid_t dst_pid;
114 unsigned dst_groups;
115 int (*handler)(int unit, struct sk_buff *skb);
116 atomic_t locks;
117 struct netlink_callback *cb;
119 #endif
121 /* Once the IPX ncpd patches are in these are going into protinfo. */
122 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
123 struct ipx_opt {
124 ipx_address dest_addr;
125 ipx_interface *intrfc;
126 unsigned short port;
127 #ifdef CONFIG_IPX_INTERN
128 unsigned char node[IPX_NODE_LEN];
129 #endif
130 unsigned short type;
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;
137 #endif
139 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
140 struct ipv6_pinfo {
141 struct in6_addr saddr;
142 struct in6_addr rcv_saddr;
143 struct in6_addr daddr;
144 struct in6_addr *daddr_cache;
146 __u32 flow_lbl;
147 __u32 frag_size;
148 int hop_limit;
149 int mcast_hops;
150 int mcast_oif;
151 __u8 priority;
153 /* pktoption flags */
154 union {
155 struct {
156 __u8 srcrt:2,
157 rxinfo:1,
158 rxhlim:1,
159 hopopts:1,
160 dstopts:1,
161 authhdr:1,
162 unused:1;
163 } bits;
164 __u8 all;
165 } rxopt;
167 /* sockopt flags */
168 __u8 mc_loop:1,
169 recverr:1,
170 pmtudisc:2;
172 struct ipv6_mc_socklist *ipv6_mc_list;
173 __u32 dst_cookie;
175 struct ipv6_txoptions *opt;
176 struct sk_buff *pktoptions;
179 struct raw6_opt {
180 __u32 checksum; /* perform checksum */
181 __u32 offset; /* checksum offset */
183 struct icmp6_filter filter;
186 #endif /* IPV6 */
188 #if defined(CONFIG_INET) || defined(CONFIG_INET_MODULE)
189 struct raw_opt {
190 struct icmp_filter filter;
192 #endif
194 /* This defines a selective acknowledgement block. */
195 struct tcp_sack_block {
196 __u32 start_seq;
197 __u32 end_seq;
200 struct tcp_opt {
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
207 __u32 pred_flags;
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 */
227 __u32 max_window;
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 */
233 __u8 retransmits;
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 */
251 __u8 delayed_acks;
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
265 * fast retransmit
268 __u32 rcv_wnd; /* Current receiver window */
269 __u32 rcv_wup; /* rcv_nxt on last window update sent */
270 __u32 write_seq;
271 __u32 copied_seq;
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 */
292 __u32 syn_seq;
293 __u32 fin_seq;
294 __u32 urg_seq;
295 __u32 urg_data;
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:
318 * struct sock {
319 * sockmem [mem, proto, callbacks]
321 * union or struct {
322 * ax25;
323 * } ll_pinfo;
325 * union {
326 * ipv4;
327 * ipv6;
328 * ipx;
329 * netrom;
330 * rose;
331 * x25;
332 * } net_pinfo;
334 * union {
335 * tcp;
336 * udp;
337 * spx;
338 * netrom;
339 * } tp_pinfo;
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)
348 #else
349 #define SOCK_DEBUG(sk, msg...) do { } while (0)
350 #endif
352 struct sock {
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. */
369 struct sock *next;
370 struct sock **pprev;
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 */
393 struct sock *prev;
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
398 volatile char dead,
399 done,
400 urginline,
401 keepopen,
402 linger,
403 destroy,
404 no_check,
405 broadcast,
406 bsdism;
407 unsigned char debug;
408 int proc;
409 unsigned long lingertime;
411 int hashent;
412 struct sock *pair;
414 /* Error and backlog packet queues, rarely used. */
415 struct sk_buff_head back_log,
416 error_queue;
418 struct proto *prot;
420 unsigned short shutdown;
422 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
423 union {
424 struct ipv6_pinfo af_inet6;
425 } net_pinfo;
426 #endif
428 union {
429 struct tcp_opt af_tcp;
430 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
431 struct raw_opt tp_raw4;
432 #endif
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 */
440 } tp_pinfo;
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
445 'timed out' */
446 unsigned short ack_backlog;
447 unsigned short max_ack_backlog;
448 __u32 priority;
449 unsigned short type;
450 unsigned char localroute; /* Route locally only */
451 unsigned char protocol;
452 struct ucred peercred;
454 #ifdef CONFIG_FILTER
455 /* Socket Filtering Instructions */
456 int filter;
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.
463 union {
464 void *destruct_hook;
465 struct unix_opt af_unix;
466 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
467 struct atalk_sock af_at;
468 #endif
469 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
470 struct ipx_opt af_ipx;
471 #endif
472 #if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
473 struct dn_scp dn;
474 #endif
475 #if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
476 struct packet_opt *af_packet;
477 #endif
478 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
479 x25_cb *x25;
480 #endif
481 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
482 ax25_cb *ax25;
483 #endif
484 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
485 nr_cb *nr;
486 #endif
487 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
488 rose_cb *rose;
489 #endif
490 #ifdef CONFIG_NETLINK
491 struct netlink_opt af_netlink;
492 #endif
493 #if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)
494 struct econet_opt *af_econet;
495 #endif
496 } protinfo;
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 */
506 __u8 ip_recverr;
507 __u8 ip_pmtudisc;
508 int ip_mc_index; /* Multicast device index */
509 __u32 ip_mc_addr;
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;
517 /* Identd */
518 struct socket *socket;
520 /* RPC layer private data */
521 void *user_data;
523 /* Callbacks */
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
538 struct proto {
539 /* These must be first. */
540 struct sock *sklist_next;
541 struct sock *sklist_prev;
543 void (*close)(struct sock *sk,
544 long timeout);
545 int (*connect)(struct sock *sk,
546 struct sockaddr *uaddr,
547 int addr_len);
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,
558 unsigned long arg);
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,
566 int *option);
567 int (*sendmsg)(struct sock *sk, struct msghdr *msg,
568 int len);
569 int (*recvmsg)(struct sock *sk, struct msghdr *msg,
570 int len, int noblock, int flags,
571 int *addr_len);
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;
587 char name[32];
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 */
594 #define TIME_CLOSE 4
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
611 * nothing changes.
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)
621 SOCKHASH_LOCK();
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;
628 p->sklist_next = 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;
635 SOCKHASH_UNLOCK();
638 static __inline__ void del_from_prot_sklist(struct sock *sk)
640 SOCKHASH_LOCK();
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;
645 sk->prot->inuse--;
647 SOCKHASH_UNLOCK();
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)
664 #if 0
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)) {
668 __label__ here;
669 printk("double lock on socket at %p\n", &&here);
670 here:
672 #endif
673 atomic_inc(&sk->sock_readers);
674 synchronize_bh();
677 static inline void release_sock(struct sock *sk)
679 barrier();
680 if (atomic_dec_and_test(&sk->sock_readers))
681 __release_sock(sk);
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)
692 if (a > b)
693 a = b;
694 return a;
697 static __inline__ int max(unsigned int a, unsigned int b)
699 if (a < b)
700 a = b;
701 return a;
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,
710 int priority);
711 extern struct sk_buff *sock_rmalloc(struct sock *sk,
712 unsigned long size, int force,
713 int priority);
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,
721 int optlen);
723 extern int sock_getsockopt(struct socket *sock, int level,
724 int op, char *optval,
725 int *optlen);
726 extern struct sk_buff *sock_alloc_send_skb(struct sock *sk,
727 unsigned long size,
728 unsigned long fallback,
729 int noblock,
730 int *errcode);
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 *,
741 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 *,
747 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,
755 unsigned long);
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,
759 char *, int *);
760 extern int sock_no_setsockopt(struct socket *, int, int,
761 char *, 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);
787 #ifdef CONFIG_FILTER
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)
795 int pkt_len;
797 pkt_len = sk_run_filter(skb->data, skb->len, filter, flen);
798 if(!pkt_len)
799 return 1; /* Toss Packet */
800 else
801 skb_trim(skb, pkt_len);
803 return 0;
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)
818 skb->sk = 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)
825 skb->sk = 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)
837 return -ENOMEM;
839 #ifdef CONFIG_FILTER
840 if (sk->filter)
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);
849 if (!sk->dead)
850 sk->data_ready(sk,skb->len);
851 return 0;
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)
860 return -ENOMEM;
861 skb_set_owner_r(skb, sk);
862 skb_queue_tail(&sk->error_queue,skb);
863 if (!sk->dead)
864 sk->data_ready(sk,skb->len);
865 return 0;
869 * Recover an error report and clear atomically
872 extern __inline__ int sock_error(struct sock *sk)
874 int err=xchg(&sk->err,0);
875 return -err;
878 extern __inline__ unsigned long sock_wspace(struct sock *sk)
880 int amt = 0;
882 if (!(sk->shutdown & SEND_SHUTDOWN)) {
883 amt = sk->sndbuf - atomic_read(&sk->wmem_alloc);
884 if (amt < 0)
885 amt = 0;
887 return amt;
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
914 #if 1
915 #define NETDEBUG(x) do { } while (0)
916 #else
917 #define NETDEBUG(x) do { x; } while (0)
918 #endif
920 #endif /* _SOCK_H */