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

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