root/include/net/sock.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. lock_sock
  2. release_sock
  3. sock_queue_rcv_skb
  4. 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/netdevice.h>
  41 #include <linux/skbuff.h>       /* struct sk_buff */
  42 #include <net/protocol.h>               /* struct inet_protocol */
  43 #ifdef CONFIG_AX25
  44 #include <net/ax25.h>
  45 #ifdef CONFIG_NETROM
  46 #include <net/netrom.h>
  47 #endif
  48 #endif
  49 
  50 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
  51 #include <net/ipx.h>
  52 #endif
  53 
  54 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
  55 #include <linux/atalk.h>
  56 #endif
  57 
  58 #include <linux/igmp.h>
  59 
  60 #include <asm/atomic.h>
  61 
  62 /* Think big (also on some systems a byte is faster) */
  63 #define SOCK_ARRAY_SIZE 256
  64 
  65 
  66 /*
  67  *      The AF_UNIX specific socket options
  68  */
  69  
  70 struct unix_opt
  71 {
  72         int                     family;
  73         char *                  name;
  74         int                     locks;
  75         struct inode *          inode;
  76         struct semaphore        readsem;
  77         struct sock *           other;
  78         int                     marksweep;
  79 #define MARKED                  1
  80         int                     inflight;
  81 };
  82 
  83 /*
  84  *      IP packet socket options
  85  */
  86 
  87 struct inet_packet_opt
  88 {
  89         struct notifier_block   notifier;               /* Used when bound */
  90         struct device           *bound_dev;
  91         unsigned long           dev_stamp;
  92         struct packet_type      *prot_hook;
  93         char                    device_name[15];
  94 };
  95 
  96 /*
  97  *      Once the IPX ncpd patches are in these are going into protinfo
  98  */
  99 
 100 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
 101 struct ipx_opt
 102 {
 103         ipx_address             dest_addr;
 104         ipx_interface           *intrfc;
 105         unsigned short          port;
 106 #ifdef CONFIG_IPX_INTERN
 107         unsigned char           node[IPX_NODE_LEN];
 108 #endif
 109         unsigned short          type;
 110 /* 
 111  * To handle asynchronous messages from the NetWare server, we have to
 112  * know the connection this socket belongs to. 
 113  */
 114         struct ncp_server       *ncp_server;
 115         
 116 };
 117 #endif
 118 
 119 #ifdef CONFIG_NUTCP
 120 struct tcp_opt
 121 {
 122 /*
 123  *      RFC793 variables by their proper names. This means you can
 124  *      read the code and the spec side by side (and laugh ...)
 125  *      See RFC793 and RFC1122. The RFC writes these in capitals.
 126  */
 127         __u32   rcv_nxt;        /* What we want to receive next         */
 128         __u32   rcv_up;         /* The urgent point (may not be valid)  */
 129         __u32   rcv_wnd;        /* Current receiver window              */
 130         __u32   snd_nxt;        /* Next sequence we send                */
 131         __u32   snd_una;        /* First byte we want an ack for        */
 132         __u32   snd_up;         /* Outgoing urgent pointer              */
 133         __u32   snd_wl1;        /* Sequence for window update           */
 134         __u32   snd_wl2;        /* Ack sequence for update              */
 135 /*
 136  *      Slow start and congestion control (see also Nagle, and Karn & Partridge)
 137  */
 138         __u32   snd_cwnd;       /* Sending congestion window            */
 139         __u32   snd_ssthresh;   /* Slow start size threshold            */
 140 /*
 141  *      Timers used by the TCP protocol layer
 142  */
 143         struct timer_list       delack_timer;           /* Ack delay    */
 144         struct timer_list       idle_timer;             /* Idle watch   */
 145         struct timer_list       completion_timer;       /* Up/Down timer */
 146         struct timer_list       probe_timer;            /* Probes       */
 147         struct timer_list       retransmit_timer;       /* Resend (no ack) */
 148 };
 149 #endif
 150         
 151 /*
 152  * This structure really needs to be cleaned up.
 153  * Most of it is for TCP, and not used by any of
 154  * the other protocols.
 155  */
 156 struct sock 
 157 {
 158         struct options          *opt;
 159         atomic_t                wmem_alloc;
 160         atomic_t                rmem_alloc;
 161         unsigned long           allocation;             /* Allocation mode */
 162         __u32                   write_seq;
 163         __u32                   sent_seq;
 164         __u32                   acked_seq;
 165         __u32                   copied_seq;
 166         __u32                   rcv_ack_seq;
 167         unsigned short          rcv_ack_cnt;            /* count of same ack */
 168         __u32                   window_seq;
 169         __u32                   fin_seq;
 170         __u32                   urg_seq;
 171         __u32                   urg_data;
 172         int                     users;                  /* user count */
 173   /*
 174    *    Not all are volatile, but some are, so we
 175    *    might as well say they all are.
 176    */
 177         volatile char           dead,
 178                                 urginline,
 179                                 intr,
 180                                 blog,
 181                                 done,
 182                                 reuse,
 183                                 keepopen,
 184                                 linger,
 185                                 delay_acks,
 186                                 destroy,
 187                                 ack_timed,
 188                                 no_check,
 189                                 zapped, /* In ax25 & ipx means not linked */
 190                                 broadcast,
 191                                 nonagle,
 192                                 bsdism;
 193         unsigned long           lingertime;
 194         int                     proc;
 195         struct sock             *next;
 196         struct sock             *prev; /* Doubly linked chain.. */
 197         struct sock             *pair;
 198         struct sk_buff          * volatile send_head;
 199         struct sk_buff          * volatile send_tail;
 200         struct sk_buff_head     back_log;
 201         struct sk_buff          *partial;
 202         struct timer_list       partial_timer;
 203         long                    retransmits;
 204         struct sk_buff_head     write_queue,
 205                                 receive_queue;
 206         struct proto            *prot;
 207         struct wait_queue       **sleep;
 208         __u32                   daddr;
 209         __u32                   saddr;          /* Sending source */
 210         __u32                   rcv_saddr;      /* Bound address */
 211         unsigned short          max_unacked;
 212         unsigned short          window;
 213         __u32                   lastwin_seq;    /* sequence number when we last updated the window we offer */
 214         volatile unsigned long  ato;            /* ack timeout */
 215         volatile unsigned long  lrcvtime;       /* jiffies at last rcv */
 216         unsigned short          bytes_rcv;
 217 /*
 218  *      mss is min(mtu, max_window) 
 219  */
 220         unsigned short          mtu;       /* mss negotiated in the syn's */
 221         volatile unsigned short mss;       /* current eff. mss - can change */
 222         volatile unsigned short user_mss;  /* mss requested by user in ioctl */
 223         volatile unsigned short max_window;
 224         unsigned long           window_clamp;
 225         unsigned short          num;
 226         volatile unsigned short cong_window;
 227         volatile unsigned short cong_count;
 228         volatile unsigned short ssthresh;
 229         volatile unsigned short packets_out;
 230         volatile unsigned short shutdown;
 231         volatile unsigned long  rtt;
 232         volatile unsigned long  mdev;
 233         volatile unsigned long  rto;
 234 
 235 /*
 236  *      currently backoff isn't used, but I'm maintaining it in case
 237  *      we want to go back to a backoff formula that needs it
 238  */
 239  
 240         volatile unsigned short backoff;
 241         int                     err, err_soft;  /* Soft holds errors that don't
 242                                                    cause failure but are the cause
 243                                                    of a persistent failure not just
 244                                                    'timed out' */
 245         unsigned char           protocol;
 246         volatile unsigned char  state;
 247         unsigned char           ack_backlog;
 248         unsigned char           max_ack_backlog;
 249         unsigned char           priority;
 250         unsigned char           debug;
 251         unsigned short          rcvbuf;
 252         unsigned short          sndbuf;
 253         unsigned short          type;
 254         unsigned char           localroute;     /* Route locally only */
 255 #ifdef CONFIG_AX25
 256         ax25_cb                 *ax25;
 257 #ifdef CONFIG_NETROM
 258         nr_cb                   *nr;
 259 #endif
 260 #endif
 261   
 262 /*
 263  *      This is where all the private (optional) areas that don't
 264  *      overlap will eventually live. 
 265  */
 266 
 267         union
 268         {
 269                 struct unix_opt af_unix;
 270 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
 271                 struct atalk_sock       af_at;
 272 #endif
 273 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
 274                 struct ipx_opt          af_ipx;
 275 #endif
 276 #ifdef CONFIG_INET
 277                 struct inet_packet_opt  af_packet;
 278 #ifdef CONFIG_NUTCP             
 279                 struct tcp_opt          af_tcp;
 280 #endif          
 281 #endif
 282         } protinfo;             
 283 
 284 /* 
 285  *      IP 'private area' or will be eventually 
 286  */
 287         int                     ip_ttl;                 /* TTL setting */
 288         int                     ip_tos;                 /* TOS */
 289         struct tcphdr           dummy_th;
 290         struct timer_list       keepalive_timer;        /* TCP keepalive hack */
 291         struct timer_list       retransmit_timer;       /* TCP retransmit timer */
 292         struct timer_list       delack_timer;           /* TCP delayed ack timer */
 293         int                     ip_xmit_timeout;        /* Why the timeout is running */
 294         struct rtable           *ip_route_cache;        /* Cached output route */
 295         unsigned char           ip_hdrincl;             /* Include headers ? */
 296 #ifdef CONFIG_IP_MULTICAST  
 297         int                     ip_mc_ttl;              /* Multicasting TTL */
 298         int                     ip_mc_loop;             /* Loopback */
 299         char                    ip_mc_name[MAX_ADDR_LEN];/* Multicast device name */
 300         struct ip_mc_socklist   *ip_mc_list;            /* Group array */
 301 #endif  
 302 
 303 /*
 304  *      This part is used for the timeout functions (timer.c). 
 305  */
 306  
 307         int                     timeout;        /* What are we waiting for? */
 308         struct timer_list       timer;          /* This is the TIME_WAIT/receive timer
 309                                          * when we are doing IP
 310                                          */
 311         struct timeval          stamp;
 312 
 313  /*
 314   *     Identd 
 315   */
 316   
 317         struct socket           *socket;
 318   
 319   /*
 320    *    Callbacks 
 321    */
 322    
 323         void                    (*state_change)(struct sock *sk);
 324         void                    (*data_ready)(struct sock *sk,int bytes);
 325         void                    (*write_space)(struct sock *sk);
 326         void                    (*error_report)(struct sock *sk);
 327   
 328 };
 329 
 330 /*
 331  *      IP protocol blocks we attach to sockets.
 332  */
 333  
 334 struct proto 
 335 {
 336         void                    (*close)(struct sock *sk, unsigned long timeout);
 337         int                     (*build_header)(struct sk_buff *skb,
 338                                         __u32 saddr,
 339                                         __u32 daddr,
 340                                         struct device **dev, int type,
 341                                         struct options *opt, int len,
 342                                         int tos, int ttl, struct rtable ** rp);
 343         int                     (*connect)(struct sock *sk,
 344                                         struct sockaddr_in *usin, int addr_len);
 345         struct sock *           (*accept) (struct sock *sk, int flags);
 346         void                    (*queue_xmit)(struct sock *sk,
 347                                         struct device *dev, struct sk_buff *skb,
 348                                         int free);
 349         void                    (*retransmit)(struct sock *sk, int all);
 350         void                    (*write_wakeup)(struct sock *sk);
 351         void                    (*read_wakeup)(struct sock *sk);
 352         int                     (*rcv)(struct sk_buff *buff, struct device *dev,
 353                                         struct options *opt, __u32 daddr,
 354                                         unsigned short len, __u32 saddr,
 355                                         int redo, struct inet_protocol *protocol);
 356         int                     (*select)(struct sock *sk, int which,
 357                                         select_table *wait);
 358         int                     (*ioctl)(struct sock *sk, int cmd,
 359                                         unsigned long arg);
 360         int                     (*init)(struct sock *sk);
 361         void                    (*shutdown)(struct sock *sk, int how);
 362         int                     (*setsockopt)(struct sock *sk, int level, int optname,
 363                                         char *optval, int optlen);
 364         int                     (*getsockopt)(struct sock *sk, int level, int optname,
 365                                         char *optval, int *option);      
 366         int                     (*sendmsg)(struct sock *sk, struct msghdr *msg, int len,
 367                                         int noblock, int flags);
 368         int                     (*recvmsg)(struct sock *sk, struct msghdr *msg, int len,
 369                                         int noblock, int flags, int *addr_len);
 370         int                     (*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len);
 371         unsigned short          max_header;
 372         unsigned long           retransmits;
 373         char                    name[32];
 374         int                     inuse, highestinuse;
 375         struct sock *           sock_array[SOCK_ARRAY_SIZE];
 376 };
 377 
 378 #define TIME_WRITE      1
 379 #define TIME_CLOSE      2
 380 #define TIME_KEEPOPEN   3
 381 #define TIME_DESTROY    4
 382 #define TIME_DONE       5       /* Used to absorb those last few packets */
 383 #define TIME_PROBE0     6
 384 
 385 /*
 386  *      About 10 seconds 
 387  */
 388 
 389 #define SOCK_DESTROY_TIME (10*HZ)
 390 
 391 /*
 392  *      Sockets 0-1023 can't be bound too unless you are superuser 
 393  */
 394  
 395 #define PROT_SOCK       1024
 396 
 397 #define SHUTDOWN_MASK   3
 398 #define RCV_SHUTDOWN    1
 399 #define SEND_SHUTDOWN   2
 400 
 401 /*
 402  * Used by processes to "lock" a socket state, so that
 403  * interrupts and bottom half handlers won't change it
 404  * from under us. It essentially blocks any incoming
 405  * packets, so that we won't get any new data or any
 406  * packets that change the state of the socket.
 407  *
 408  * Note the 'barrier()' calls: gcc may not move a lock
 409  * "downwards" or a unlock "upwards" when optimizing.
 410  */
 411 extern void __release_sock(struct sock *sk);
 412 
 413 static inline void lock_sock(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 414 {
 415 #if 1
 416 /* debugging code: the test isn't even 100% correct, but it can catch bugs */
 417 /* Note that a double lock is ok in theory - it's just _usually_ a bug */
 418         if (sk->users) {
 419                 __label__ here;
 420                 printk("double lock on socket at %p\n", &&here);
 421 here:
 422         }
 423 #endif
 424         sk->users++;
 425         barrier();
 426 }
 427 
 428 static inline void release_sock(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 429 {
 430         barrier();
 431 #if 1
 432 /* debugging code: remove me when ok */
 433         if (sk->users == 0) {
 434                 __label__ here;
 435                 sk->users = 1;
 436                 printk("trying to unlock unlocked socket at %p\n", &&here);
 437 here:
 438         }
 439 #endif
 440         if (!--sk->users)
 441                 __release_sock(sk);
 442 }
 443 
 444 
 445 extern struct sock *            sk_alloc(int priority);
 446 extern void                     sk_free(struct sock *sk);
 447 extern void                     destroy_sock(struct sock *sk);
 448 extern unsigned short           get_new_socknum(struct proto *,
 449                                                 unsigned short);
 450 extern void                     put_sock(unsigned short, struct sock *); 
 451 extern struct sock              *get_sock(struct proto *, unsigned short,
 452                                           unsigned long, unsigned short,
 453                                           unsigned long);
 454 extern struct sock              *get_sock_mcast(struct sock *, unsigned short,
 455                                           unsigned long, unsigned short,
 456                                           unsigned long);
 457 extern struct sock              *get_sock_raw(struct sock *, unsigned short,
 458                                           unsigned long, unsigned long);
 459 
 460 extern struct sk_buff           *sock_wmalloc(struct sock *sk,
 461                                               unsigned long size, int force,
 462                                               int priority);
 463 extern struct sk_buff           *sock_rmalloc(struct sock *sk,
 464                                               unsigned long size, int force,
 465                                               int priority);
 466 extern void                     sock_wfree(struct sock *sk,
 467                                            struct sk_buff *skb);
 468 extern void                     sock_rfree(struct sock *sk,
 469                                            struct sk_buff *skb);
 470 extern unsigned long            sock_rspace(struct sock *sk);
 471 extern unsigned long            sock_wspace(struct sock *sk);
 472 
 473 extern int                      sock_setsockopt(struct sock *sk, int level,
 474                                                 int op, char *optval,
 475                                                 int optlen);
 476 
 477 extern int                      sock_getsockopt(struct sock *sk, int level,
 478                                                 int op, char *optval, 
 479                                                 int *optlen);
 480 extern struct sk_buff           *sock_alloc_send_skb(struct sock *skb,
 481                                                      unsigned long size,
 482                                                      unsigned long fallback,
 483                                                      int noblock,
 484                                                      int *errcode);
 485 
 486 /*
 487  *      Queue a received datagram if it will fit. Stream and sequenced
 488  *      protocols can't normally use this as they need to fit buffers in
 489  *      and play with them.
 490  *
 491  *      Inlined as its very short and called for pretty much every
 492  *      packet ever received.
 493  */
 494 
 495 extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 496 {
 497         if (sk->rmem_alloc + skb->truesize >= sk->rcvbuf)
 498                 return -ENOMEM;
 499         atomic_add(skb->truesize, &sk->rmem_alloc);
 500         skb->sk=sk;
 501         __skb_queue_tail(&sk->receive_queue,skb);
 502         if (!sk->dead)
 503                 sk->data_ready(sk,skb->len);
 504         return 0;
 505 }
 506 
 507 /*
 508  *      Recover an error report and clear atomically
 509  */
 510  
 511 extern __inline__ int sock_error(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 512 {
 513         int err=xchg(&sk->err,0);
 514         return -err;
 515 }
 516 
 517 /* 
 518  *      Declarations from timer.c 
 519  */
 520  
 521 extern struct sock *timer_base;
 522 
 523 extern void delete_timer (struct sock *);
 524 extern void reset_timer (struct sock *, int, unsigned long);
 525 extern void net_timer (unsigned long);
 526 
 527 
 528 /* 
 529  *      Enable debug/info messages 
 530  */
 531 
 532 #define NETDEBUG(x)             x
 533 
 534 #endif  /* _SOCK_H */

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