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

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