root/include/net/sock.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. sock_queue_rcv_skb

   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.
   5  *
   6  *              Definitions for the AF_INET socket handler.
   7  *
   8  * Version:     @(#)sock.h      1.0.4   05/13/93
   9  *
  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>
  14  *
  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  *
  25  *              This program is free software; you can redistribute it and/or
  26  *              modify it under the terms of the GNU General Public License
  27  *              as published by the Free Software Foundation; either version
  28  *              2 of the License, or (at your option) any later version.
  29  */
  30 #ifndef _SOCK_H
  31 #define _SOCK_H
  32 
  33 #include <linux/timer.h>
  34 #include <linux/ip.h>           /* struct options */
  35 #include <linux/in.h>           /* struct sockaddr_in */
  36 #include <linux/tcp.h>          /* struct tcphdr */
  37 #include <linux/config.h>
  38 
  39 #include <linux/skbuff.h>       /* struct sk_buff */
  40 #include "protocol.h"           /* struct inet_protocol */
  41 #ifdef CONFIG_AX25
  42 #include "ax25.h"
  43 #ifdef CONFIG_NETROM
  44 #include "netrom.h"
  45 #endif
  46 #endif
  47 #ifdef CONFIG_IPX
  48 #include "ipx.h"
  49 #endif
  50 #ifdef CONFIG_ATALK
  51 #include <linux/atalk.h>
  52 #endif
  53 
  54 #include <linux/igmp.h>
  55 
  56 #define SOCK_ARRAY_SIZE 256             /* Think big (also on some systems a byte is faster */
  57 
  58 
  59 /*
  60  * This structure really needs to be cleaned up.
  61  * Most of it is for TCP, and not used by any of
  62  * the other protocols.
  63  */
  64 struct sock {
  65   struct options                *opt;
  66   volatile unsigned long        wmem_alloc;
  67   volatile unsigned long        rmem_alloc;
  68   __u32                         write_seq;
  69   __u32                         sent_seq;
  70   __u32                         acked_seq;
  71   __u32                         copied_seq;
  72   __u32                         rcv_ack_seq;
  73   __u32                         window_seq;
  74   __u32                         fin_seq;
  75   __u32                         urg_seq;
  76   __u32                         urg_data;
  77 
  78   /*
  79    * Not all are volatile, but some are, so we
  80    * might as well say they all are.
  81    */
  82   volatile char                 inuse,
  83                                 dead,
  84                                 urginline,
  85                                 intr,
  86                                 blog,
  87                                 done,
  88                                 reuse,
  89                                 keepopen,
  90                                 linger,
  91                                 delay_acks,
  92                                 destroy,
  93                                 ack_timed,
  94                                 no_check,
  95                                 zapped, /* In ax25 & ipx means not linked */
  96                                 broadcast,
  97                                 nonagle;
  98   unsigned long                 lingertime;
  99   int                           proc;
 100   struct sock                   *next;
 101   struct sock                   *prev; /* Doubly linked chain.. */
 102   struct sock                   *pair;
 103   struct sk_buff                * volatile send_head;
 104   struct sk_buff                * volatile send_tail;
 105   struct sk_buff_head           back_log;
 106   struct sk_buff                *partial;
 107   struct timer_list             partial_timer;
 108   long                          retransmits;
 109   struct sk_buff_head           write_queue,
 110                                 receive_queue;
 111   struct proto                  *prot;
 112   struct wait_queue             **sleep;
 113   unsigned long                 daddr;
 114   unsigned long                 saddr;
 115   unsigned short                max_unacked;
 116   unsigned short                window;
 117   unsigned short                bytes_rcv;
 118 /* mss is min(mtu, max_window) */
 119   unsigned short                mtu;       /* mss negotiated in the syn's */
 120   volatile unsigned short       mss;       /* current eff. mss - can change */
 121   volatile unsigned short       user_mss;  /* mss requested by user in ioctl */
 122   volatile unsigned short       max_window;
 123   unsigned long                 window_clamp;
 124   unsigned short                num;
 125   volatile unsigned short       cong_window;
 126   volatile unsigned short       cong_count;
 127   volatile unsigned short       ssthresh;
 128   volatile unsigned short       packets_out;
 129   volatile unsigned short       shutdown;
 130   volatile unsigned long        rtt;
 131   volatile unsigned long        mdev;
 132   volatile unsigned long        rto;
 133 /* currently backoff isn't used, but I'm maintaining it in case
 134  * we want to go back to a backoff formula that needs it
 135  */
 136   volatile unsigned short       backoff;
 137   volatile short                err;
 138   unsigned char                 protocol;
 139   volatile unsigned char        state;
 140   volatile unsigned char        ack_backlog;
 141   unsigned char                 max_ack_backlog;
 142   unsigned char                 priority;
 143   unsigned char                 debug;
 144   unsigned short                rcvbuf;
 145   unsigned short                sndbuf;
 146   unsigned short                type;
 147   unsigned char                 localroute;     /* Route locally only */
 148 #ifdef CONFIG_IPX
 149   ipx_address                   ipx_dest_addr;
 150   ipx_interface                 *ipx_intrfc;
 151   unsigned short                ipx_port;
 152   unsigned short                ipx_type;
 153 #endif
 154 #ifdef CONFIG_AX25
 155   ax25_cb                       *ax25;
 156 #ifdef CONFIG_NETROM
 157   nr_cb                         *nr;
 158 #endif
 159 #endif
 160 #ifdef CONFIG_ATALK
 161   struct atalk_sock             at;
 162 #endif
 163 
 164 /* IP 'private area' or will be eventually */
 165   int                           ip_ttl;                 /* TTL setting                          */
 166   int                           ip_tos;                 /* TOS                                  */
 167   struct tcphdr                 dummy_th;
 168   struct timer_list             keepalive_timer;        /* TCP keepalive hack                   */
 169   struct timer_list             retransmit_timer;       /* TCP retransmit timer                 */
 170   struct timer_list             ack_timer;              /* TCP delayed ack timer                */
 171   int                           ip_xmit_timeout;        /* Why the timeout is running           */
 172   struct rtable                 *ip_route_cache;        /* Cached output route                  */
 173   unsigned long                 ip_route_stamp;         /* Route cache stamp                    */
 174   unsigned long                 ip_route_daddr;         /* Target address                       */
 175   unsigned long                 ip_route_saddr;         /* Source address                       */
 176   int                           ip_route_local;         /* State of locality flag               */
 177   unsigned long                 ip_hcache_stamp;        /* Header cache stamp                   */
 178   unsigned long                 *ip_hcache_ver;         /* Pointer to version of cache          */
 179   char                          ip_hcache_data[16];     /* Cached header                        */
 180   int                           ip_hcache_state;        /* Have we a cached header              */
 181   unsigned char                 ip_option_len;          /* Length of IP options                 */
 182   unsigned char                 ip_option_flen;         /* Second fragment option length        */
 183   unsigned char                 ip_opt_next_strict;     /* Next hop is strict route             */
 184   unsigned long                 ip_opt_next_hop;        /* Next hop if forced                   */
 185   unsigned char                 *ip_opt_ptr[2];         /* IP option pointers                   */
 186 #ifdef CONFIG_IP_MULTICAST  
 187   int                           ip_mc_ttl;                      /* Multicasting TTL             */
 188   int                           ip_mc_loop;                     /* Loopback                     */
 189   char                          ip_mc_name[MAX_ADDR_LEN];       /* Multicast device name        */
 190   struct ip_mc_socklist         *ip_mc_list;                    /* Group array                  */
 191 #endif  
 192 
 193   /* This part is used for the timeout functions (timer.c). */
 194   int                           timeout;        /* What are we waiting for? */
 195   struct timer_list             timer;          /* This is the TIME_WAIT/receive timer when we are doing IP */
 196   struct timeval                stamp;
 197 
 198   /* identd */
 199   struct socket                 *socket;
 200   
 201   /* Callbacks */
 202   void                          (*state_change)(struct sock *sk);
 203   void                          (*data_ready)(struct sock *sk,int bytes);
 204   void                          (*write_space)(struct sock *sk);
 205   void                          (*error_report)(struct sock *sk);
 206   
 207 };
 208 
 209 struct proto {
 210   struct sk_buff *      (*wmalloc)(struct sock *sk,
 211                                     unsigned long size, int force,
 212                                     int priority);
 213   struct sk_buff *      (*rmalloc)(struct sock *sk,
 214                                     unsigned long size, int force,
 215                                     int priority);
 216   void                  (*wfree)(struct sock *sk, struct sk_buff *skb);
 217   void                  (*rfree)(struct sock *sk, struct sk_buff *skb);
 218   unsigned long         (*rspace)(struct sock *sk);
 219   unsigned long         (*wspace)(struct sock *sk);
 220   void                  (*close)(struct sock *sk, int timeout);
 221   int                   (*read)(struct sock *sk, unsigned char *to,
 222                                 int len, int nonblock, unsigned flags);
 223   int                   (*write)(struct sock *sk, unsigned char *to,
 224                                  int len, int nonblock, unsigned flags);
 225   int                   (*sendto)(struct sock *sk,
 226                                   unsigned char *from, int len, int noblock,
 227                                   unsigned flags, struct sockaddr_in *usin,
 228                                   int addr_len);
 229   int                   (*recvfrom)(struct sock *sk,
 230                                     unsigned char *from, int len, int noblock,
 231                                     unsigned flags, struct sockaddr_in *usin,
 232                                     int *addr_len);
 233   int                   (*build_header)(struct sk_buff *skb,
 234                                         unsigned long saddr,
 235                                         unsigned long daddr,
 236                                         struct device **dev, int type,
 237                                         struct options *opt, int len, int tos, int ttl);
 238   int                   (*connect)(struct sock *sk,
 239                                   struct sockaddr_in *usin, int addr_len);
 240   struct sock *         (*accept) (struct sock *sk, int flags);
 241   void                  (*queue_xmit)(struct sock *sk,
 242                                       struct device *dev, struct sk_buff *skb,
 243                                       int free);
 244   void                  (*retransmit)(struct sock *sk, int all);
 245   void                  (*write_wakeup)(struct sock *sk);
 246   void                  (*read_wakeup)(struct sock *sk);
 247   int                   (*rcv)(struct sk_buff *buff, struct device *dev,
 248                                struct options *opt, unsigned long daddr,
 249                                unsigned short len, unsigned long saddr,
 250                                int redo, struct inet_protocol *protocol);
 251   int                   (*select)(struct sock *sk, int which,
 252                                   select_table *wait);
 253   int                   (*ioctl)(struct sock *sk, int cmd,
 254                                  unsigned long arg);
 255   int                   (*init)(struct sock *sk);
 256   void                  (*shutdown)(struct sock *sk, int how);
 257   int                   (*setsockopt)(struct sock *sk, int level, int optname,
 258                                  char *optval, int optlen);
 259   int                   (*getsockopt)(struct sock *sk, int level, int optname,
 260                                 char *optval, int *option);      
 261   unsigned short        max_header;
 262   unsigned long         retransmits;
 263   char                  name[32];
 264   int                   inuse, highestinuse;
 265 #ifndef PACKET_C                /* Hack to save 1K for packet sockets */ 
 266   struct sock *         sock_array[SOCK_ARRAY_SIZE];
 267 #endif PACKET_C  
 268 };
 269 
 270 #define TIME_WRITE      1
 271 #define TIME_CLOSE      2
 272 #define TIME_KEEPOPEN   3
 273 #define TIME_DESTROY    4
 274 #define TIME_DONE       5       /* used to absorb those last few packets */
 275 #define TIME_PROBE0     6
 276 #define SOCK_DESTROY_TIME 1000  /* about 10 seconds                     */
 277 
 278 #define PROT_SOCK       1024    /* Sockets 0-1023 can't be bound too unless you are superuser */
 279 
 280 #define SHUTDOWN_MASK   3
 281 #define RCV_SHUTDOWN    1
 282 #define SEND_SHUTDOWN   2
 283 
 284 
 285 extern void                     destroy_sock(struct sock *sk);
 286 extern unsigned short           get_new_socknum(struct proto *, unsigned short);
 287 extern void                     put_sock(unsigned short, struct sock *); 
 288 extern void                     release_sock(struct sock *sk);
 289 extern struct sock              *get_sock(struct proto *, unsigned short,
 290                                           unsigned long, unsigned short,
 291                                           unsigned long);
 292 extern struct sock              *get_sock_mcast(struct sock *, unsigned short,
 293                                           unsigned long, unsigned short,
 294                                           unsigned long);
 295 extern struct sock              *get_sock_raw(struct sock *, unsigned short,
 296                                           unsigned long, unsigned long);
 297 
 298 extern struct sk_buff           *sock_wmalloc(struct sock *sk,
 299                                               unsigned long size, int force,
 300                                               int priority);
 301 extern struct sk_buff           *sock_rmalloc(struct sock *sk,
 302                                               unsigned long size, int force,
 303                                               int priority);
 304 extern void                     sock_wfree(struct sock *sk, struct sk_buff *skb);
 305 extern void                     sock_rfree(struct sock *sk, struct sk_buff *skb);
 306 extern unsigned long            sock_rspace(struct sock *sk);
 307 extern unsigned long            sock_wspace(struct sock *sk);
 308 
 309 extern int                      sock_setsockopt(struct sock *sk,int level,int op,char *optval,int optlen);
 310 
 311 extern int                      sock_getsockopt(struct sock *sk,int level,int op,char *optval,int *optlen);
 312 extern struct sk_buff           *sock_alloc_send_skb(struct sock *skb, unsigned long size, int noblock, int *errcode);
 313 
 314 /*
 315  *      Queue a received datagram if it will fit. Stream and sequenced protocols
 316  *      can't normally use this as they need to fit buffers in and play with them.
 317  *
 318  *      Inlined as its very short and called for pretty much every packet ever
 319  *      received.
 320  */
 321 
 322 extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 323 {
 324         unsigned long flags;
 325         if(sk->rmem_alloc + skb->truesize >= sk->rcvbuf)
 326                 return -ENOMEM;
 327         save_flags(flags);
 328         cli();
 329         sk->rmem_alloc+=skb->truesize;
 330         skb->sk=sk;
 331         restore_flags(flags);
 332         skb_queue_tail(&sk->receive_queue,skb);
 333         if(!sk->dead)
 334                 sk->data_ready(sk,skb->len);
 335         return 0;
 336 }
 337 
 338 /* declarations from timer.c */
 339 extern struct sock *timer_base;
 340 
 341 void delete_timer (struct sock *);
 342 void reset_timer (struct sock *, int, unsigned long);
 343 void net_timer (unsigned long);
 344 
 345 
 346 /* Enable debug/info messages */
 347 
 348 #define NETDEBUG(x)             x
 349 
 350 #endif  /* _SOCK_H */

/* [previous][next][first][last][top][bottom][index][help] */