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 "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                                  unsigned long size);
 218   void                  (*rfree)(struct sock *sk, struct sk_buff *skb,
 219                                  unsigned long size);
 220   unsigned long         (*rspace)(struct sock *sk);
 221   unsigned long         (*wspace)(struct sock *sk);
 222   void                  (*close)(struct sock *sk, int timeout);
 223   int                   (*read)(struct sock *sk, unsigned char *to,
 224                                 int len, int nonblock, unsigned flags);
 225   int                   (*write)(struct sock *sk, unsigned char *to,
 226                                  int len, int nonblock, unsigned flags);
 227   int                   (*sendto)(struct sock *sk,
 228                                   unsigned char *from, int len, int noblock,
 229                                   unsigned flags, struct sockaddr_in *usin,
 230                                   int addr_len);
 231   int                   (*recvfrom)(struct sock *sk,
 232                                     unsigned char *from, int len, int noblock,
 233                                     unsigned flags, struct sockaddr_in *usin,
 234                                     int *addr_len);
 235   int                   (*build_header)(struct sk_buff *skb,
 236                                         unsigned long saddr,
 237                                         unsigned long daddr,
 238                                         struct device **dev, int type,
 239                                         struct options *opt, int len, int tos, int ttl);
 240   int                   (*connect)(struct sock *sk,
 241                                   struct sockaddr_in *usin, int addr_len);
 242   struct sock *         (*accept) (struct sock *sk, int flags);
 243   void                  (*queue_xmit)(struct sock *sk,
 244                                       struct device *dev, struct sk_buff *skb,
 245                                       int free);
 246   void                  (*retransmit)(struct sock *sk, int all);
 247   void                  (*write_wakeup)(struct sock *sk);
 248   void                  (*read_wakeup)(struct sock *sk);
 249   int                   (*rcv)(struct sk_buff *buff, struct device *dev,
 250                                struct options *opt, unsigned long daddr,
 251                                unsigned short len, unsigned long saddr,
 252                                int redo, struct inet_protocol *protocol);
 253   int                   (*select)(struct sock *sk, int which,
 254                                   select_table *wait);
 255   int                   (*ioctl)(struct sock *sk, int cmd,
 256                                  unsigned long arg);
 257   int                   (*init)(struct sock *sk);
 258   void                  (*shutdown)(struct sock *sk, int how);
 259   int                   (*setsockopt)(struct sock *sk, int level, int optname,
 260                                  char *optval, int optlen);
 261   int                   (*getsockopt)(struct sock *sk, int level, int optname,
 262                                 char *optval, int *option);      
 263   unsigned short        max_header;
 264   unsigned long         retransmits;
 265   char                  name[32];
 266   int                   inuse, highestinuse;
 267 #ifndef PACKET_C                /* Hack to save 1K for packet sockets */ 
 268   struct sock *         sock_array[SOCK_ARRAY_SIZE];
 269 #endif PACKET_C  
 270 };
 271 
 272 #define TIME_WRITE      1
 273 #define TIME_CLOSE      2
 274 #define TIME_KEEPOPEN   3
 275 #define TIME_DESTROY    4
 276 #define TIME_DONE       5       /* used to absorb those last few packets */
 277 #define TIME_PROBE0     6
 278 #define SOCK_DESTROY_TIME 1000  /* about 10 seconds                     */
 279 
 280 #define PROT_SOCK       1024    /* Sockets 0-1023 can't be bound too unless you are superuser */
 281 
 282 #define SHUTDOWN_MASK   3
 283 #define RCV_SHUTDOWN    1
 284 #define SEND_SHUTDOWN   2
 285 
 286 
 287 extern void                     destroy_sock(struct sock *sk);
 288 extern unsigned short           get_new_socknum(struct proto *, unsigned short);
 289 extern void                     put_sock(unsigned short, struct sock *); 
 290 extern void                     release_sock(struct sock *sk);
 291 extern struct sock              *get_sock(struct proto *, unsigned short,
 292                                           unsigned long, unsigned short,
 293                                           unsigned long);
 294 extern struct sock              *get_sock_mcast(struct sock *, unsigned short,
 295                                           unsigned long, unsigned short,
 296                                           unsigned long);
 297 extern struct sock              *get_sock_raw(struct sock *, unsigned short,
 298                                           unsigned long, unsigned long);
 299 
 300 extern struct sk_buff           *sock_wmalloc(struct sock *sk,
 301                                               unsigned long size, int force,
 302                                               int priority);
 303 extern struct sk_buff           *sock_rmalloc(struct sock *sk,
 304                                               unsigned long size, int force,
 305                                               int priority);
 306 extern void                     sock_wfree(struct sock *sk, struct sk_buff *skb,
 307                                            unsigned long size);
 308 extern void                     sock_rfree(struct sock *sk, struct sk_buff *skb,
 309                                            unsigned long size);
 310 extern unsigned long            sock_rspace(struct sock *sk);
 311 extern unsigned long            sock_wspace(struct sock *sk);
 312 
 313 extern int                      sock_setsockopt(struct sock *sk,int level,int op,char *optval,int optlen);
 314 
 315 extern int                      sock_getsockopt(struct sock *sk,int level,int op,char *optval,int *optlen);
 316 extern struct sk_buff           *sock_alloc_send_skb(struct sock *skb, unsigned long size, int noblock, int *errcode);
 317 
 318 /*
 319  *      Queue a received datagram if it will fit. Stream and sequenced protocols
 320  *      can't normally use this as they need to fit buffers in and play with them.
 321  *
 322  *      Inlined as its very short and called for pretty much every packet ever
 323  *      received.
 324  */
 325 
 326 extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 327 {
 328         unsigned long flags;
 329         if(sk->rmem_alloc + skb->mem_len >= sk->rcvbuf)
 330                 return -ENOMEM;
 331         save_flags(flags);
 332         cli();
 333         sk->rmem_alloc+=skb->mem_len;
 334         skb->sk=sk;
 335         restore_flags(flags);
 336         skb_queue_tail(&sk->receive_queue,skb);
 337         if(!sk->dead)
 338                 sk->data_ready(sk,skb->len);
 339         return 0;
 340 }
 341 
 342 /* declarations from timer.c */
 343 extern struct sock *timer_base;
 344 
 345 void delete_timer (struct sock *);
 346 void reset_timer (struct sock *, int, unsigned long);
 347 void net_timer (unsigned long);
 348 
 349 
 350 /* Enable debug/info messages */
 351 
 352 #define NETDEBUG(x)             x
 353 
 354 #endif  /* _SOCK_H */

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