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

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