root/net/inet/sock.h

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

INCLUDED FROM


   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/tcp.h>          /* struct tcphdr */
  36 
  37 #include <linux/skbuff.h>       /* struct sk_buff */
  38 #include "protocol.h"           /* struct inet_protocol */
  39 #ifdef CONFIG_AX25
  40 #include "ax25.h"
  41 #endif
  42 #ifdef CONFIG_IPX
  43 #include "ipx.h"
  44 #endif
  45 
  46 #include "igmp.h"
  47 
  48 #define SOCK_ARRAY_SIZE 256             /* Think big (also on some systems a byte is faster */
  49 
  50 
  51 /*
  52  * This structure really needs to be cleaned up.
  53  * Most of it is for TCP, and not used by any of
  54  * the other protocols.
  55  */
  56 struct sock {
  57   struct options                *opt;
  58   volatile unsigned long        wmem_alloc;
  59   volatile unsigned long        rmem_alloc;
  60   unsigned long                 write_seq;
  61   unsigned long                 sent_seq;
  62   unsigned long                 acked_seq;
  63   unsigned long                 copied_seq;
  64   unsigned long                 rcv_ack_seq;
  65   unsigned long                 window_seq;
  66   unsigned long                 fin_seq;
  67   unsigned long                 urg_seq;
  68   unsigned long                 urg_data;
  69 
  70   /*
  71    * Not all are volatile, but some are, so we
  72    * might as well say they all are.
  73    */
  74   volatile char                 inuse,
  75                                 dead,
  76                                 urginline,
  77                                 intr,
  78                                 blog,
  79                                 done,
  80                                 reuse,
  81                                 keepopen,
  82                                 linger,
  83                                 delay_acks,
  84                                 destroy,
  85                                 ack_timed,
  86                                 no_check,
  87                                 zapped, /* In ax25 & ipx means not linked */
  88                                 broadcast,
  89                                 nonagle;
  90   unsigned long                 lingertime;
  91   int                           proc;
  92   struct sock                   *next;
  93   struct sock                   *pair;
  94   struct sk_buff                * volatile send_head;
  95   struct sk_buff                * volatile send_tail;
  96   struct sk_buff_head           back_log;
  97   struct sk_buff                *partial;
  98   struct timer_list             partial_timer;
  99   long                          retransmits;
 100   struct sk_buff_head           write_queue,
 101                                 receive_queue;
 102   struct proto                  *prot;
 103   struct wait_queue             **sleep;
 104   unsigned long                 daddr;
 105   unsigned long                 saddr;
 106   unsigned short                max_unacked;
 107   unsigned short                window;
 108   unsigned short                bytes_rcv;
 109 /* mss is min(mtu, max_window) */
 110   unsigned short                mtu;       /* mss negotiated in the syn's */
 111   volatile unsigned short       mss;       /* current eff. mss - can change */
 112   volatile unsigned short       user_mss;  /* mss requested by user in ioctl */
 113   volatile unsigned short       max_window;
 114   unsigned long                 window_clamp;
 115   unsigned short                num;
 116   volatile unsigned short       cong_window;
 117   volatile unsigned short       cong_count;
 118   volatile unsigned short       ssthresh;
 119   volatile unsigned short       packets_out;
 120   volatile unsigned short       shutdown;
 121   volatile unsigned long        rtt;
 122   volatile unsigned long        mdev;
 123   volatile unsigned long        rto;
 124 /* currently backoff isn't used, but I'm maintaining it in case
 125  * we want to go back to a backoff formula that needs it
 126  */
 127   volatile unsigned short       backoff;
 128   volatile short                err;
 129   unsigned char                 protocol;
 130   volatile unsigned char        state;
 131   volatile unsigned char        ack_backlog;
 132   unsigned char                 max_ack_backlog;
 133   unsigned char                 priority;
 134   unsigned char                 debug;
 135   unsigned short                rcvbuf;
 136   unsigned short                sndbuf;
 137   unsigned short                type;
 138   unsigned char                 localroute;     /* Route locally only */
 139 #ifdef CONFIG_IPX
 140   ipx_address                   ipx_source_addr,ipx_dest_addr;
 141   unsigned short                ipx_type;
 142 #endif
 143 #ifdef CONFIG_AX25
 144 /* Really we want to add a per protocol private area */
 145   ax25_address                  ax25_source_addr,ax25_dest_addr;
 146   struct sk_buff *volatile      ax25_retxq[8];
 147   char                          ax25_state,ax25_vs,ax25_vr,ax25_lastrxnr,ax25_lasttxnr;
 148   char                          ax25_condition;
 149   char                          ax25_retxcnt;
 150   char                          ax25_xx;
 151   char                          ax25_retxqi;
 152   char                          ax25_rrtimer;
 153   char                          ax25_timer;
 154   unsigned char                 ax25_n2;
 155   unsigned short                ax25_t1,ax25_t2,ax25_t3;
 156   ax25_digi                     *ax25_digipeat;
 157 #endif  
 158 /* IP 'private area' or will be eventually */
 159   int                           ip_ttl;         /* TTL setting */
 160   int                           ip_tos;         /* TOS */
 161   struct tcphdr                 dummy_th;
 162 #ifdef CONFIG_IP_MULTICAST  
 163   int                           ip_mc_ttl;                      /* Multicasting TTL */
 164   int                           ip_mc_loop;                     /* Loopback (not implemented yet) */
 165   char                          ip_mc_name[MAX_ADDR_LEN];       /* Multicast device name */
 166   struct ip_mc_socklist         *ip_mc_list;                    /* Group array */
 167 #endif  
 168 
 169   /* This part is used for the timeout functions (timer.c). */
 170   int                           timeout;        /* What are we waiting for? */
 171   struct timer_list             timer;
 172   struct timeval                stamp;
 173 
 174   /* identd */
 175   struct socket                 *socket;
 176   
 177   /* Callbacks */
 178   void                          (*state_change)(struct sock *sk);
 179   void                          (*data_ready)(struct sock *sk,int bytes);
 180   void                          (*write_space)(struct sock *sk);
 181   void                          (*error_report)(struct sock *sk);
 182   
 183 };
 184 
 185 struct proto {
 186   struct sk_buff *      (*wmalloc)(struct sock *sk,
 187                                     unsigned long size, int force,
 188                                     int priority);
 189   struct sk_buff *      (*rmalloc)(struct sock *sk,
 190                                     unsigned long size, int force,
 191                                     int priority);
 192   void                  (*wfree)(struct sock *sk, struct sk_buff *skb,
 193                                  unsigned long size);
 194   void                  (*rfree)(struct sock *sk, struct sk_buff *skb,
 195                                  unsigned long size);
 196   unsigned long         (*rspace)(struct sock *sk);
 197   unsigned long         (*wspace)(struct sock *sk);
 198   void                  (*close)(struct sock *sk, int timeout);
 199   int                   (*read)(struct sock *sk, unsigned char *to,
 200                                 int len, int nonblock, unsigned flags);
 201   int                   (*write)(struct sock *sk, unsigned char *to,
 202                                  int len, int nonblock, unsigned flags);
 203   int                   (*sendto)(struct sock *sk,
 204                                   unsigned char *from, int len, int noblock,
 205                                   unsigned flags, struct sockaddr_in *usin,
 206                                   int addr_len);
 207   int                   (*recvfrom)(struct sock *sk,
 208                                     unsigned char *from, int len, int noblock,
 209                                     unsigned flags, struct sockaddr_in *usin,
 210                                     int *addr_len);
 211   int                   (*build_header)(struct sk_buff *skb,
 212                                         unsigned long saddr,
 213                                         unsigned long daddr,
 214                                         struct device **dev, int type,
 215                                         struct options *opt, int len, int tos, int ttl);
 216   int                   (*connect)(struct sock *sk,
 217                                   struct sockaddr_in *usin, int addr_len);
 218   struct sock *         (*accept) (struct sock *sk, int flags);
 219   void                  (*queue_xmit)(struct sock *sk,
 220                                       struct device *dev, struct sk_buff *skb,
 221                                       int free);
 222   void                  (*retransmit)(struct sock *sk, int all);
 223   void                  (*write_wakeup)(struct sock *sk);
 224   void                  (*read_wakeup)(struct sock *sk);
 225   int                   (*rcv)(struct sk_buff *buff, struct device *dev,
 226                                struct options *opt, unsigned long daddr,
 227                                unsigned short len, unsigned long saddr,
 228                                int redo, struct inet_protocol *protocol);
 229   int                   (*select)(struct sock *sk, int which,
 230                                   select_table *wait);
 231   int                   (*ioctl)(struct sock *sk, int cmd,
 232                                  unsigned long arg);
 233   int                   (*init)(struct sock *sk);
 234   void                  (*shutdown)(struct sock *sk, int how);
 235   int                   (*setsockopt)(struct sock *sk, int level, int optname,
 236                                  char *optval, int optlen);
 237   int                   (*getsockopt)(struct sock *sk, int level, int optname,
 238                                 char *optval, int *option);      
 239   unsigned short        max_header;
 240   unsigned long         retransmits;
 241   struct sock *         sock_array[SOCK_ARRAY_SIZE];
 242   char                  name[80];
 243 };
 244 
 245 #define TIME_WRITE      1
 246 #define TIME_CLOSE      2
 247 #define TIME_KEEPOPEN   3
 248 #define TIME_DESTROY    4
 249 #define TIME_DONE       5       /* used to absorb those last few packets */
 250 #define TIME_PROBE0     6
 251 #define SOCK_DESTROY_TIME 1000  /* about 10 seconds                     */
 252 
 253 #define PROT_SOCK       1024    /* Sockets 0-1023 can't be bound too unless you are superuser */
 254 
 255 #define SHUTDOWN_MASK   3
 256 #define RCV_SHUTDOWN    1
 257 #define SEND_SHUTDOWN   2
 258 
 259 
 260 extern void                     destroy_sock(struct sock *sk);
 261 extern unsigned short           get_new_socknum(struct proto *, unsigned short);
 262 extern void                     put_sock(unsigned short, struct sock *); 
 263 extern void                     release_sock(struct sock *sk);
 264 extern struct sock              *get_sock(struct proto *, unsigned short,
 265                                           unsigned long, unsigned short,
 266                                           unsigned long);
 267 extern struct sock              *get_sock_mcast(struct sock *, unsigned short,
 268                                           unsigned long, unsigned short,
 269                                           unsigned long);
 270 extern struct sock              *get_sock_raw(struct sock *, unsigned short,
 271                                           unsigned long, unsigned long);
 272 
 273 extern struct sk_buff           *sock_wmalloc(struct sock *sk,
 274                                               unsigned long size, int force,
 275                                               int priority);
 276 extern struct sk_buff           *sock_rmalloc(struct sock *sk,
 277                                               unsigned long size, int force,
 278                                               int priority);
 279 extern void                     sock_wfree(struct sock *sk, struct sk_buff *skb,
 280                                            unsigned long size);
 281 extern void                     sock_rfree(struct sock *sk, struct sk_buff *skb,
 282                                            unsigned long size);
 283 extern unsigned long            sock_rspace(struct sock *sk);
 284 extern unsigned long            sock_wspace(struct sock *sk);
 285 
 286 extern int                      sock_setsockopt(struct sock *sk,int level,int op,char *optval,int optlen);
 287 
 288 extern int                      sock_getsockopt(struct sock *sk,int level,int op,char *optval,int *optlen);
 289 extern struct sk_buff           *sock_alloc_send_skb(struct sock *skb, unsigned long size, int noblock, int *errcode);
 290 extern int                      sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
 291 
 292 /* declarations from timer.c */
 293 extern struct sock *timer_base;
 294 
 295 void delete_timer (struct sock *);
 296 void reset_timer (struct sock *, int, unsigned long);
 297 void net_timer (unsigned long);
 298 
 299 
 300 #endif  /* _SOCK_H */

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