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
  2. sock_error

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

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