ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

tcpcore.h
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS TCP/IP protocol driver
00004  * FILE:        include/tcpcore.h
00005  * PURPOSE:     Transmission Control Protocol definitions
00006  * REVISIONS:
00007  *   CSH 01/01-2003 Ported from linux kernel 2.4.20
00008  */
00009 
00010 /*
00011  * INET     An implementation of the TCP/IP protocol suite for the LINUX
00012  *      operating system.  INET is implemented using the  BSD Socket
00013  *      interface as the means of communication with the user level.
00014  *
00015  *      Definitions for the TCP module.
00016  *
00017  * Version: @(#)tcp.h   1.0.5   05/23/93
00018  *
00019  * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
00020  *      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
00021  *
00022  *      This program is free software; you can redistribute it and/or
00023  *      modify it under the terms of the GNU General Public License
00024  *      as published by the Free Software Foundation; either version
00025  *      2 of the License, or (at your option) any later version.
00026  */
00027 
00028 #pragma once
00029 
00030 #include "tcpdef.h"
00031 
00032 
00033 struct socket;
00034 
00035 
00036 
00037 #if 1 /* skbuff */
00038 
00039 #define HAVE_ALLOC_SKB      /* For the drivers to know */
00040 #define HAVE_ALIGNABLE_SKB  /* Ditto 8)        */
00041 #define SLAB_SKB        /* Slabified skbuffs       */
00042 
00043 #define CHECKSUM_NONE 0
00044 #define CHECKSUM_HW 1
00045 #define CHECKSUM_UNNECESSARY 2
00046 
00047 #define SKB_DATA_ALIGN(X)   (((X) + (SMP_CACHE_BYTES-1)) & ~(SMP_CACHE_BYTES-1))
00048 #define SKB_MAX_ORDER(X,ORDER)  (((PAGE_SIZE<<(ORDER)) - (X) - sizeof(struct skb_shared_info))&~(SMP_CACHE_BYTES-1))
00049 #define SKB_MAX_HEAD(X)     (SKB_MAX_ORDER((X),0))
00050 #define SKB_MAX_ALLOC       (SKB_MAX_ORDER(0,2))
00051 
00052 /* A. Checksumming of received packets by device.
00053  *
00054  *  NONE: device failed to checksum this packet.
00055  *      skb->csum is undefined.
00056  *
00057  *  UNNECESSARY: device parsed packet and wouldbe verified checksum.
00058  *      skb->csum is undefined.
00059  *        It is bad option, but, unfortunately, many of vendors do this.
00060  *        Apparently with secret goal to sell you new device, when you
00061  *        will add new protocol to your host. F.e. IPv6. 8)
00062  *
00063  *  HW: the most generic way. Device supplied checksum of _all_
00064  *      the packet as seen by netif_rx in skb->csum.
00065  *      NOTE: Even if device supports only some protocols, but
00066  *      is able to produce some skb->csum, it MUST use HW,
00067  *      not UNNECESSARY.
00068  *
00069  * B. Checksumming on output.
00070  *
00071  *  NONE: skb is checksummed by protocol or csum is not required.
00072  *
00073  *  HW: device is required to csum packet as seen by hard_start_xmit
00074  *  from skb->h.raw to the end and to record the checksum
00075  *  at skb->h.raw+skb->csum.
00076  *
00077  *  Device must show its capabilities in dev->features, set
00078  *  at device setup time.
00079  *  NETIF_F_HW_CSUM - it is clever device, it is able to checksum
00080  *            everything.
00081  *  NETIF_F_NO_CSUM - loopback or reliable single hop media.
00082  *  NETIF_F_IP_CSUM - device is dumb. It is able to csum only
00083  *            TCP/UDP over IPv4. Sigh. Vendors like this
00084  *            way by an unknown reason. Though, see comment above
00085  *            about CHECKSUM_UNNECESSARY. 8)
00086  *
00087  *  Any questions? No questions, good.      --ANK
00088  */
00089 
00090 #ifdef __i386__
00091 #define NET_CALLER(arg) (*(((void**)&arg)-1))
00092 #else
00093 #define NET_CALLER(arg) __builtin_return_address(0)
00094 #endif
00095 
00096 #ifdef CONFIG_NETFILTER
00097 struct nf_conntrack {
00098     atomic_t use;
00099     void (*destroy)(struct nf_conntrack *);
00100 };
00101 
00102 struct nf_ct_info {
00103     struct nf_conntrack *master;
00104 };
00105 #endif
00106 
00107 struct sk_buff_head {
00108     /* These two members must be first. */
00109     struct sk_buff  * next;
00110     struct sk_buff  * prev;
00111 
00112     __u32       qlen;
00113     spinlock_t  lock;
00114 };
00115 
00116 struct sk_buff;
00117 
00118 #define MAX_SKB_FRAGS 6
00119 
00120 typedef struct skb_frag_struct skb_frag_t;
00121 
00122 struct skb_frag_struct
00123 {
00124     struct page *page;
00125     __u16 page_offset;
00126     __u16 size;
00127 };
00128 
00129 /* This data is invariant across clones and lives at
00130  * the end of the header data, ie. at skb->end.
00131  */
00132 struct skb_shared_info {
00133     atomic_t    dataref;
00134     unsigned int    nr_frags;
00135     struct sk_buff  *frag_list;
00136     skb_frag_t  frags[MAX_SKB_FRAGS];
00137 };
00138 
00139 struct sk_buff {
00140     /* These two members must be first. */
00141     struct sk_buff  * next;         /* Next buffer in list              */
00142     struct sk_buff  * prev;         /* Previous buffer in list          */
00143 
00144     struct sk_buff_head * list;     /* List we are on               */
00145     struct sock *sk;            /* Socket we are owned by           */
00146     struct timeval  stamp;          /* Time we arrived              */
00147     struct net_device   *dev;       /* Device we arrived on/are leaving by      */
00148 
00149     /* Transport layer header */
00150     union
00151     {
00152         struct tcphdr   *th;
00153         struct udphdr   *uh;
00154         struct icmphdr  *icmph;
00155         struct igmphdr  *igmph;
00156         struct iphdr    *ipiph;
00157         struct spxhdr   *spxh;
00158         unsigned char   *raw;
00159     } h;
00160 
00161     /* Network layer header */
00162     union
00163     {
00164         struct iphdr    *iph;
00165         struct ipv6hdr  *ipv6h;
00166         struct arphdr   *arph;
00167         struct ipxhdr   *ipxh;
00168         unsigned char   *raw;
00169     } nh;
00170 
00171     /* Link layer header */
00172     union
00173     {
00174         struct ethhdr   *ethernet;
00175         unsigned char   *raw;
00176     } mac;
00177 
00178     struct  dst_entry *dst;
00179 
00180     /*
00181      * This is the control buffer. It is free to use for every
00182      * layer. Please put your private variables there. If you
00183      * want to keep them across layers you have to do a skb_clone()
00184      * first. This is owned by whoever has the skb queued ATM.
00185      */
00186     char        cb[48];
00187 
00188     unsigned int    len;            /* Length of actual data            */
00189     unsigned int    data_len;
00190     unsigned int    csum;           /* Checksum                     */
00191     unsigned char   __unused,       /* Dead field, may be reused            */
00192             cloned,         /* head may be cloned (check refcnt to be sure). */
00193             pkt_type,       /* Packet class                 */
00194             ip_summed;      /* Driver fed us an IP checksum         */
00195     __u32       priority;       /* Packet queueing priority         */
00196     atomic_t    users;          /* User count - see datagram.c,tcp.c        */
00197     unsigned short  protocol;       /* Packet protocol from driver.         */
00198     unsigned short  security;       /* Security level of packet         */
00199     unsigned int    truesize;       /* Buffer size                  */
00200 
00201     unsigned char   *head;          /* Head of buffer               */
00202     unsigned char   *data;          /* Data head pointer                */
00203     unsigned char   *tail;          /* Tail pointer                 */
00204     unsigned char   *end;           /* End pointer                  */
00205 
00206     void        (*destructor)(struct sk_buff *);    /* Destruct function        */
00207 #ifdef CONFIG_NETFILTER
00208     /* Can be used for communication between hooks. */
00209         unsigned long   nfmark;
00210     /* Cache info */
00211     __u32       nfcache;
00212     /* Associated connection, if any */
00213     struct nf_ct_info *nfct;
00214 #ifdef CONFIG_NETFILTER_DEBUG
00215         unsigned int nf_debug;
00216 #endif
00217 #endif /*CONFIG_NETFILTER*/
00218 
00219 #if defined(CONFIG_HIPPI)
00220     union{
00221         __u32   ifield;
00222     } private;
00223 #endif
00224 
00225 #ifdef CONFIG_NET_SCHED
00226        __u32           tc_index;               /* traffic control index */
00227 #endif
00228 };
00229 
00230 #define SK_WMEM_MAX 65535
00231 #define SK_RMEM_MAX 65535
00232 
00233 #if 1
00234 //#ifdef __KERNEL__
00235 /*
00236  *  Handling routines are only of interest to the kernel
00237  */
00238 
00239 extern void         __kfree_skb(struct sk_buff *skb);
00240 extern struct sk_buff *     alloc_skb(unsigned int size, int priority);
00241 extern void         kfree_skbmem(struct sk_buff *skb);
00242 extern struct sk_buff *     skb_clone(struct sk_buff *skb, int priority);
00243 extern struct sk_buff *     skb_copy(const struct sk_buff *skb, int priority);
00244 extern struct sk_buff *     pskb_copy(struct sk_buff *skb, int gfp_mask);
00245 extern int          pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, int gfp_mask);
00246 extern struct sk_buff *     skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom);
00247 extern struct sk_buff *     skb_copy_expand(const struct sk_buff *skb,
00248                         int newheadroom,
00249                         int newtailroom,
00250                         int priority);
00251 #define dev_kfree_skb(a)    kfree_skb(a)
00252 extern void skb_over_panic(struct sk_buff *skb, int len, void *here);
00253 extern void skb_under_panic(struct sk_buff *skb, int len, void *here);
00254 
00255 /* Internal */
00256 #define skb_shinfo(SKB)     ((struct skb_shared_info *)((SKB)->end))
00257 
00265 static __inline int skb_queue_empty(struct sk_buff_head *list)
00266 {
00267     return (list->next == (struct sk_buff *) list);
00268 }
00269 
00278 static __inline struct sk_buff *skb_get(struct sk_buff *skb)
00279 {
00280     atomic_inc(&skb->users);
00281     return skb;
00282 }
00283 
00284 /*
00285  * If users==1, we are the only owner and are can avoid redundant
00286  * atomic change.
00287  */
00288 
00297 static __inline void kfree_skb(struct sk_buff *skb)
00298 {
00299     if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
00300         __kfree_skb(skb);
00301 }
00302 
00303 /* Use this if you didn't touch the skb state [for fast switching] */
00304 static __inline void kfree_skb_fast(struct sk_buff *skb)
00305 {
00306     if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
00307         kfree_skbmem(skb);
00308 }
00309 
00319 static __inline int skb_cloned(struct sk_buff *skb)
00320 {
00321     return skb->cloned && atomic_read(&skb_shinfo(skb)->dataref) != 1;
00322 }
00323 
00332 static __inline int skb_shared(struct sk_buff *skb)
00333 {
00334     return (atomic_read(&skb->users) != 1);
00335 }
00336 
00351 static __inline struct sk_buff *skb_share_check(struct sk_buff *skb, int pri)
00352 {
00353     if (skb_shared(skb)) {
00354         struct sk_buff *nskb;
00355         nskb = skb_clone(skb, pri);
00356         kfree_skb(skb);
00357         return nskb;
00358     }
00359     return skb;
00360 }
00361 
00362 
00363 /*
00364  *  Copy shared buffers into a new sk_buff. We effectively do COW on
00365  *  packets to handle cases where we have a local reader and forward
00366  *  and a couple of other messy ones. The normal one is tcpdumping
00367  *  a packet thats being forwarded.
00368  */
00369 
00384 static __inline struct sk_buff *skb_unshare(struct sk_buff *skb, int pri)
00385 {
00386     struct sk_buff *nskb;
00387     if(!skb_cloned(skb))
00388         return skb;
00389     nskb=skb_copy(skb, pri);
00390     kfree_skb(skb);     /* Free our shared copy */
00391     return nskb;
00392 }
00393 
00408 static __inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
00409 {
00410     struct sk_buff *list = ((struct sk_buff *)list_)->next;
00411     if (list == (struct sk_buff *)list_)
00412         list = NULL;
00413     return list;
00414 }
00415 
00430 static __inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
00431 {
00432     struct sk_buff *list = ((struct sk_buff *)list_)->prev;
00433     if (list == (struct sk_buff *)list_)
00434         list = NULL;
00435     return list;
00436 }
00437 
00445 static __inline __u32 skb_queue_len(struct sk_buff_head *list_)
00446 {
00447     return(list_->qlen);
00448 }
00449 
00450 static __inline void skb_queue_head_init(struct sk_buff_head *list)
00451 {
00452     spin_lock_init(&list->lock);
00453     list->prev = (struct sk_buff *)list;
00454     list->next = (struct sk_buff *)list;
00455     list->qlen = 0;
00456 }
00457 
00458 /*
00459  *  Insert an sk_buff at the start of a list.
00460  *
00461  *  The "__skb_xxxx()" functions are the non-atomic ones that
00462  *  can only be called with interrupts disabled.
00463  */
00464 
00476 static __inline void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
00477 {
00478     struct sk_buff *prev, *next;
00479 
00480     newsk->list = list;
00481     list->qlen++;
00482     prev = (struct sk_buff *)list;
00483     next = prev->next;
00484     newsk->next = next;
00485     newsk->prev = prev;
00486     next->prev = newsk;
00487     prev->next = newsk;
00488 }
00489 
00490 
00503 static __inline void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
00504 {
00505     unsigned long flags;
00506 
00507     spin_lock_irqsave(&list->lock, flags);
00508     __skb_queue_head(list, newsk);
00509     spin_unlock_irqrestore(&list->lock, flags);
00510 }
00511 
00524 static __inline void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
00525 {
00526     struct sk_buff *prev, *next;
00527 
00528     newsk->list = list;
00529     list->qlen++;
00530     next = (struct sk_buff *)list;
00531     prev = next->prev;
00532     newsk->next = next;
00533     newsk->prev = prev;
00534     next->prev = newsk;
00535     prev->next = newsk;
00536 }
00537 
00550 static __inline void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
00551 {
00552     unsigned long flags;
00553 
00554     spin_lock_irqsave(&list->lock, flags);
00555     __skb_queue_tail(list, newsk);
00556     spin_unlock_irqrestore(&list->lock, flags);
00557 }
00558 
00568 static __inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
00569 {
00570     struct sk_buff *next, *prev, *result;
00571 
00572     prev = (struct sk_buff *) list;
00573     next = prev->next;
00574     result = NULL;
00575     if (next != prev) {
00576         result = next;
00577         next = next->next;
00578         list->qlen--;
00579         next->prev = prev;
00580         prev->next = next;
00581         result->next = NULL;
00582         result->prev = NULL;
00583         result->list = NULL;
00584     }
00585     return result;
00586 }
00587 
00597 static __inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
00598 {
00599     unsigned long flags;
00600     struct sk_buff *result;
00601 
00602     spin_lock_irqsave(&list->lock, flags);
00603     result = __skb_dequeue(list);
00604     spin_unlock_irqrestore(&list->lock, flags);
00605     return result;
00606 }
00607 
00608 /*
00609  *  Insert a packet on a list.
00610  */
00611 
00612 static __inline void __skb_insert(struct sk_buff *newsk,
00613     struct sk_buff * prev, struct sk_buff *next,
00614     struct sk_buff_head * list)
00615 {
00616     newsk->next = next;
00617     newsk->prev = prev;
00618     next->prev = newsk;
00619     prev->next = newsk;
00620     newsk->list = list;
00621     list->qlen++;
00622 }
00623 
00634 static __inline void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
00635 {
00636     unsigned long flags;
00637 
00638     spin_lock_irqsave(&old->list->lock, flags);
00639     __skb_insert(newsk, old->prev, old, old->list);
00640     spin_unlock_irqrestore(&old->list->lock, flags);
00641 }
00642 
00643 /*
00644  *  Place a packet after a given packet in a list.
00645  */
00646 
00647 static __inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk)
00648 {
00649     __skb_insert(newsk, old, old->next, old->list);
00650 }
00651 
00663 static __inline void skb_append(struct sk_buff *old, struct sk_buff *newsk)
00664 {
00665     unsigned long flags;
00666 
00667     spin_lock_irqsave(&old->list->lock, flags);
00668     __skb_append(old, newsk);
00669     spin_unlock_irqrestore(&old->list->lock, flags);
00670 }
00671 
00672 /*
00673  * remove sk_buff from list. _Must_ be called atomically, and with
00674  * the list known..
00675  */
00676 
00677 static __inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
00678 {
00679     struct sk_buff * next, * prev;
00680 
00681     list->qlen--;
00682     next = skb->next;
00683     prev = skb->prev;
00684     skb->next = NULL;
00685     skb->prev = NULL;
00686     skb->list = NULL;
00687     next->prev = prev;
00688     prev->next = next;
00689 }
00690 
00704 static __inline void skb_unlink(struct sk_buff *skb)
00705 {
00706     struct sk_buff_head *list = skb->list;
00707 
00708     if(list) {
00709         unsigned long flags;
00710 
00711         spin_lock_irqsave(&list->lock, flags);
00712         if(skb->list == list)
00713             __skb_unlink(skb, skb->list);
00714         spin_unlock_irqrestore(&list->lock, flags);
00715     }
00716 }
00717 
00718 /* XXX: more streamlined implementation */
00719 
00729 static __inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
00730 {
00731     struct sk_buff *skb = skb_peek_tail(list);
00732     if (skb)
00733         __skb_unlink(skb, list);
00734     return skb;
00735 }
00736 
00746 static __inline struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
00747 {
00748     unsigned long flags;
00749     struct sk_buff *result;
00750 
00751     spin_lock_irqsave(&list->lock, flags);
00752     result = __skb_dequeue_tail(list);
00753     spin_unlock_irqrestore(&list->lock, flags);
00754     return result;
00755 }
00756 
00757 static __inline int skb_is_nonlinear(const struct sk_buff *skb)
00758 {
00759     return skb->data_len;
00760 }
00761 
00762 static __inline int skb_headlen(const struct sk_buff *skb)
00763 {
00764     return skb->len - skb->data_len;
00765 }
00766 
00767 #define SKB_PAGE_ASSERT(skb) do { if (skb_shinfo(skb)->nr_frags) out_of_line_bug(); } while (0)
00768 #define SKB_FRAG_ASSERT(skb) do { if (skb_shinfo(skb)->frag_list) out_of_line_bug(); } while (0)
00769 #define SKB_LINEAR_ASSERT(skb) do { if (skb_is_nonlinear(skb)) out_of_line_bug(); } while (0)
00770 
00771 /*
00772  *  Add data to an sk_buff
00773  */
00774 
00775 static __inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
00776 {
00777     unsigned char *tmp=skb->tail;
00778     SKB_LINEAR_ASSERT(skb);
00779     skb->tail+=len;
00780     skb->len+=len;
00781     return tmp;
00782 }
00783 
00794 static __inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
00795 {
00796 #if 0
00797     unsigned char *tmp=skb->tail;
00798     SKB_LINEAR_ASSERT(skb);
00799     skb->tail+=len;
00800     skb->len+=len;
00801     if(skb->tail>skb->end) {
00802         skb_over_panic(skb, len, current_text_addr());
00803     }
00804     return tmp;
00805 #else
00806 return NULL;
00807 #endif
00808 }
00809 
00810 static __inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
00811 {
00812     skb->data-=len;
00813     skb->len+=len;
00814     return skb->data;
00815 }
00816 
00827 static __inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
00828 {
00829 #if 0
00830     skb->data-=len;
00831     skb->len+=len;
00832     if(skb->data<skb->head) {
00833         skb_under_panic(skb, len, current_text_addr());
00834     }
00835     return skb->data;
00836 #else
00837   return NULL;
00838 #endif
00839 }
00840 
00841 static __inline char *__skb_pull(struct sk_buff *skb, unsigned int len)
00842 {
00843     skb->len-=len;
00844     if (skb->len < skb->data_len)
00845         out_of_line_bug();
00846     return  skb->data+=len;
00847 }
00848 
00860 static __inline unsigned char * skb_pull(struct sk_buff *skb, unsigned int len)
00861 {
00862     if (len > skb->len)
00863         return NULL;
00864     return __skb_pull(skb,len);
00865 }
00866 
00867 extern unsigned char * __pskb_pull_tail(struct sk_buff *skb, int delta);
00868 
00869 static __inline char *__pskb_pull(struct sk_buff *skb, unsigned int len)
00870 {
00871     if (len > skb_headlen(skb) &&
00872         __pskb_pull_tail(skb, len-skb_headlen(skb)) == NULL)
00873         return NULL;
00874     skb->len -= len;
00875     return  skb->data += len;
00876 }
00877 
00878 static __inline unsigned char * pskb_pull(struct sk_buff *skb, unsigned int len)
00879 {
00880     if (len > skb->len)
00881         return NULL;
00882     return __pskb_pull(skb,len);
00883 }
00884 
00885 static __inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
00886 {
00887     if (len <= skb_headlen(skb))
00888         return 1;
00889     if (len > skb->len)
00890         return 0;
00891     return (__pskb_pull_tail(skb, len-skb_headlen(skb)) != NULL);
00892 }
00893 
00901 static __inline int skb_headroom(const struct sk_buff *skb)
00902 {
00903     return skb->data-skb->head;
00904 }
00905 
00913 static __inline int skb_tailroom(const struct sk_buff *skb)
00914 {
00915     return skb_is_nonlinear(skb) ? 0 : skb->end-skb->tail;
00916 }
00917 
00927 static __inline void skb_reserve(struct sk_buff *skb, unsigned int len)
00928 {
00929     skb->data+=len;
00930     skb->tail+=len;
00931 }
00932 
00933 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc);
00934 
00935 static __inline void __skb_trim(struct sk_buff *skb, unsigned int len)
00936 {
00937     if (!skb->data_len) {
00938         skb->len = len;
00939         skb->tail = skb->data+len;
00940     } else {
00941         ___pskb_trim(skb, len, 0);
00942     }
00943 }
00944 
00954 static __inline void skb_trim(struct sk_buff *skb, unsigned int len)
00955 {
00956     if (skb->len > len) {
00957         __skb_trim(skb, len);
00958     }
00959 }
00960 
00961 
00962 static __inline int __pskb_trim(struct sk_buff *skb, unsigned int len)
00963 {
00964     if (!skb->data_len) {
00965         skb->len = len;
00966         skb->tail = skb->data+len;
00967         return 0;
00968     } else {
00969         return ___pskb_trim(skb, len, 1);
00970     }
00971 }
00972 
00973 static __inline int pskb_trim(struct sk_buff *skb, unsigned int len)
00974 {
00975     if (len < skb->len)
00976         return __pskb_trim(skb, len);
00977     return 0;
00978 }
00979 
00990 static __inline void skb_orphan(struct sk_buff *skb)
00991 {
00992     if (skb->destructor)
00993         skb->destructor(skb);
00994     skb->destructor = NULL;
00995     skb->sk = NULL;
00996 }
00997 
01008 static __inline void skb_queue_purge(struct sk_buff_head *list)
01009 {
01010     struct sk_buff *skb;
01011     while ((skb=skb_dequeue(list))!=NULL)
01012         kfree_skb(skb);
01013 }
01014 
01025 static __inline void __skb_queue_purge(struct sk_buff_head *list)
01026 {
01027     struct sk_buff *skb;
01028     while ((skb=__skb_dequeue(list))!=NULL)
01029         kfree_skb(skb);
01030 }
01031 
01045 static __inline struct sk_buff *__dev_alloc_skb(unsigned int length,
01046                           int gfp_mask)
01047 {
01048     struct sk_buff *skb;
01049 
01050     skb = alloc_skb(length+16, gfp_mask);
01051     if (skb)
01052         skb_reserve(skb,16);
01053     return skb;
01054 }
01055 
01069 static __inline struct sk_buff *dev_alloc_skb(unsigned int length)
01070 {
01071 #if 0
01072     return __dev_alloc_skb(length, GFP_ATOMIC);
01073 #else
01074   return NULL;
01075 #endif
01076 }
01077 
01091 static __inline int
01092 skb_cow(struct sk_buff *skb, unsigned int headroom)
01093 {
01094 #if 0
01095     int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
01096 
01097     if (delta < 0)
01098         delta = 0;
01099 
01100     if (delta || skb_cloned(skb))
01101         return pskb_expand_head(skb, (delta+15)&~15, 0, GFP_ATOMIC);
01102     return 0;
01103 #else
01104   return 0;
01105 #endif
01106 }
01107 
01115 int skb_linearize(struct sk_buff *skb, int gfp);
01116 
01117 static __inline void *kmap_skb_frag(const skb_frag_t *frag)
01118 {
01119 #if 0
01120 #ifdef CONFIG_HIGHMEM
01121     if (in_irq())
01122         out_of_line_bug();
01123 
01124     local_bh_disable();
01125 #endif
01126     return kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ);
01127 #else
01128   return NULL;
01129 #endif
01130 }
01131 
01132 static __inline void kunmap_skb_frag(void *vaddr)
01133 {
01134 #if 0
01135     kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
01136 #ifdef CONFIG_HIGHMEM
01137     local_bh_enable();
01138 #endif
01139 #endif
01140 }
01141 
01142 #define skb_queue_walk(queue, skb) \
01143         for (skb = (queue)->next;           \
01144              (skb != (struct sk_buff *)(queue));    \
01145              skb=skb->next)
01146 
01147 
01148 extern struct sk_buff *     skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
01149 extern unsigned int     datagram_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait);
01150 extern int          skb_copy_datagram(const struct sk_buff *from, int offset, char *to,int size);
01151 extern int          skb_copy_datagram_iovec(const struct sk_buff *from, int offset, struct iovec *to,int size);
01152 extern int          skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, u8 *to, int len, unsigned int *csump);
01153 extern int          skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb, int hlen, struct iovec *iov);
01154 extern void         skb_free_datagram(struct sock * sk, struct sk_buff *skb);
01155 
01156 extern unsigned int     skb_checksum(const struct sk_buff *skb, int offset, int len, unsigned int csum);
01157 extern int          skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);
01158 extern unsigned int     skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to, int len, unsigned int csum);
01159 extern void         skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
01160 
01161 extern void skb_init(void);
01162 extern void skb_add_mtu(int mtu);
01163 
01164 #ifdef CONFIG_NETFILTER
01165 static __inline void
01166 nf_conntrack_put(struct nf_ct_info *nfct)
01167 {
01168     if (nfct && atomic_dec_and_test(&nfct->master->use))
01169         nfct->master->destroy(nfct->master);
01170 }
01171 static __inline void
01172 nf_conntrack_get(struct nf_ct_info *nfct)
01173 {
01174     if (nfct)
01175         atomic_inc(&nfct->master->use);
01176 }
01177 #endif
01178 
01179 
01180 #endif /* skbuff */
01181 
01182 
01183 
01184 
01185 
01186 struct sock;
01187 
01188 typedef struct sockaddr
01189 {
01190   int x;
01191 } _sockaddr;
01192 
01193 
01194 struct msghdr {
01195     void    *   msg_name;   /* Socket name          */
01196     int     msg_namelen;    /* Length of name       */
01197     struct iovec *  msg_iov;    /* Data blocks          */
01198     __kernel_size_t msg_iovlen; /* Number of blocks     */
01199     void    *   msg_control;    /* Per protocol magic (eg BSD file descriptor passing) */
01200     __kernel_size_t msg_controllen; /* Length of cmsg list */
01201     unsigned    msg_flags;
01202 };
01203 
01204 
01205 /* IP protocol blocks we attach to sockets.
01206  * socket layer -> transport layer interface
01207  * transport -> network interface is defined by struct inet_proto
01208  */
01209 struct proto {
01210     void            (*close)(struct sock *sk,
01211                     long timeout);
01212     int         (*connect)(struct sock *sk,
01213                         struct sockaddr *uaddr,
01214                     int addr_len);
01215     int         (*disconnect)(struct sock *sk, int flags);
01216 
01217     struct sock *       (*accept) (struct sock *sk, int flags, int *err);
01218 
01219     int         (*ioctl)(struct sock *sk, int cmd,
01220                      unsigned long arg);
01221     int         (*init)(struct sock *sk);
01222     int         (*destroy)(struct sock *sk);
01223     void            (*shutdown)(struct sock *sk, int how);
01224     int         (*setsockopt)(struct sock *sk, int level,
01225                     int optname, char *optval, int optlen);
01226     int         (*getsockopt)(struct sock *sk, int level,
01227                     int optname, char *optval,
01228                     int *option);
01229     int         (*sendmsg)(struct sock *sk, struct msghdr *msg,
01230                        int len);
01231     int         (*recvmsg)(struct sock *sk, struct msghdr *msg,
01232                     int len, int noblock, int flags,
01233                     int *addr_len);
01234     int         (*bind)(struct sock *sk,
01235                     struct sockaddr *uaddr, int addr_len);
01236 
01237     int         (*backlog_rcv) (struct sock *sk,
01238                         struct sk_buff *skb);
01239 
01240     /* Keeping track of sk's, looking them up, and port selection methods. */
01241     void            (*hash)(struct sock *sk);
01242     void            (*unhash)(struct sock *sk);
01243     int         (*get_port)(struct sock *sk, unsigned short snum);
01244 
01245     char            name[32];
01246 
01247     struct {
01248         int inuse;
01249   } stats[32];
01250 //      u8  __pad[SMP_CACHE_BYTES - sizeof(int)];
01251 //  } stats[NR_CPUS];
01252 };
01253 
01254 
01255 
01256 
01257 
01258 
01259 
01260 /* This defines a selective acknowledgement block. */
01261 struct tcp_sack_block {
01262     __u32   start_seq;
01263     __u32   end_seq;
01264 };
01265 
01266 
01267 struct tcp_opt {
01268     int tcp_header_len; /* Bytes of tcp header to send      */
01269 
01270 /*
01271  *  Header prediction flags
01272  *  0x5?10 << 16 + snd_wnd in net byte order
01273  */
01274     __u32   pred_flags;
01275 
01276 /*
01277  *  RFC793 variables by their proper names. This means you can
01278  *  read the code and the spec side by side (and laugh ...)
01279  *  See RFC793 and RFC1122. The RFC writes these in capitals.
01280  */
01281     __u32   rcv_nxt;    /* What we want to receive next     */
01282     __u32   snd_nxt;    /* Next sequence we send        */
01283 
01284     __u32   snd_una;    /* First byte we want an ack for    */
01285     __u32   snd_sml;    /* Last byte of the most recently transmitted small packet */
01286     __u32   rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
01287     __u32   lsndtime;   /* timestamp of last sent data packet (for restart window) */
01288 
01289     /* Delayed ACK control data */
01290     struct {
01291         __u8    pending;    /* ACK is pending */
01292         __u8    quick;      /* Scheduled number of quick acks   */
01293         __u8    pingpong;   /* The session is interactive       */
01294         __u8    blocked;    /* Delayed ACK was blocked by socket lock*/
01295         __u32   ato;        /* Predicted tick of soft clock     */
01296         unsigned long timeout;  /* Currently scheduled timeout      */
01297         __u32   lrcvtime;   /* timestamp of last received data packet*/
01298         __u16   last_seg_size;  /* Size of last incoming segment    */
01299         __u16   rcv_mss;    /* MSS used for delayed ACK decisions   */
01300     } ack;
01301 
01302     /* Data for direct copy to user */
01303     struct {
01304         //struct sk_buff_head   prequeue;
01305         struct task_struct  *task;
01306         struct iovec        *iov;
01307         int         memory;
01308         int         len;
01309     } ucopy;
01310 
01311     __u32   snd_wl1;    /* Sequence for window update       */
01312     __u32   snd_wnd;    /* The window we expect to receive  */
01313     __u32   max_window; /* Maximal window ever seen from peer   */
01314     __u32   pmtu_cookie;    /* Last pmtu seen by socket     */
01315     __u16   mss_cache;  /* Cached effective mss, not including SACKS */
01316     __u16   mss_clamp;  /* Maximal mss, negotiated at connection setup */
01317     __u16   ext_header_len; /* Network protocol overhead (IP/IPv6 options) */
01318     __u8    ca_state;   /* State of fast-retransmit machine     */
01319     __u8    retransmits;    /* Number of unrecovered RTO timeouts.  */
01320 
01321     __u8    reordering; /* Packet reordering metric.        */
01322     __u8    queue_shrunk;   /* Write queue has been shrunk recently.*/
01323     __u8    defer_accept;   /* User waits for some data after accept() */
01324 
01325 /* RTT measurement */
01326     __u8    backoff;    /* backoff              */
01327     __u32   srtt;       /* smothed round trip time << 3     */
01328     __u32   mdev;       /* medium deviation         */
01329     __u32   mdev_max;   /* maximal mdev for the last rtt period */
01330     __u32   rttvar;     /* smoothed mdev_max            */
01331     __u32   rtt_seq;    /* sequence number to update rttvar */
01332     __u32   rto;        /* retransmit timeout           */
01333 
01334     __u32   packets_out;    /* Packets which are "in flight"    */
01335     __u32   left_out;   /* Packets which leaved network     */
01336     __u32   retrans_out;    /* Retransmitted packets out        */
01337 
01338 
01339 /*
01340  *  Slow start and congestion control (see also Nagle, and Karn & Partridge)
01341  */
01342     __u32   snd_ssthresh;   /* Slow start size threshold        */
01343     __u32   snd_cwnd;   /* Sending congestion window        */
01344     __u16   snd_cwnd_cnt;   /* Linear increase counter      */
01345     __u16   snd_cwnd_clamp; /* Do not allow snd_cwnd to grow above this */
01346     __u32   snd_cwnd_used;
01347     __u32   snd_cwnd_stamp;
01348 
01349     /* Two commonly used timers in both sender and receiver paths. */
01350     unsigned long       timeout;
01351     struct timer_list   retransmit_timer;   /* Resend (no ack)  */
01352     struct timer_list   delack_timer;       /* Ack delay        */
01353 
01354     struct sk_buff_head out_of_order_queue; /* Out of order segments go here */
01355 
01356     struct tcp_func     *af_specific;   /* Operations which are AF_INET{4,6} specific   */
01357     struct sk_buff      *send_head; /* Front of stuff to transmit           */
01358     struct page     *sndmsg_page;   /* Cached page for sendmsg          */
01359     u32         sndmsg_off; /* Cached offset for sendmsg            */
01360 
01361     __u32   rcv_wnd;    /* Current receiver window      */
01362     __u32   rcv_wup;    /* rcv_nxt on last window update sent   */
01363     __u32   write_seq;  /* Tail(+1) of data held in tcp send buffer */
01364     __u32   pushed_seq; /* Last pushed seq, required to talk to windows */
01365     __u32   copied_seq; /* Head of yet unread data      */
01366 /*
01367  *      Options received (usually on last packet, some only on SYN packets).
01368  */
01369     char    tstamp_ok,  /* TIMESTAMP seen on SYN packet     */
01370         wscale_ok,  /* Wscale seen on SYN packet        */
01371         sack_ok;    /* SACK seen on SYN packet      */
01372     char    saw_tstamp; /* Saw TIMESTAMP on last packet     */
01373         __u8    snd_wscale; /* Window scaling received from sender  */
01374         __u8    rcv_wscale; /* Window scaling to send to receiver   */
01375     __u8    nonagle;    /* Disable Nagle algorithm?             */
01376     __u8    keepalive_probes; /* num of allowed keep alive probes   */
01377 
01378 /*  PAWS/RTTM data  */
01379         __u32   rcv_tsval;  /* Time stamp value                 */
01380         __u32   rcv_tsecr;  /* Time stamp echo reply            */
01381         __u32   ts_recent;  /* Time stamp to echo next      */
01382         long    ts_recent_stamp;/* Time we stored ts_recent (for aging) */
01383 
01384 /*  SACKs data  */
01385     __u16   user_mss;   /* mss requested by user in ioctl */
01386     __u8    dsack;      /* D-SACK is scheduled          */
01387     __u8    eff_sacks;  /* Size of SACK array to send with next packet */
01388     struct tcp_sack_block duplicate_sack[1]; /* D-SACK block */
01389     struct tcp_sack_block selective_acks[4]; /* The SACKS themselves*/
01390 
01391     __u32   window_clamp;   /* Maximal window to advertise      */
01392     __u32   rcv_ssthresh;   /* Current window clamp         */
01393     __u8    probes_out; /* unanswered 0 window probes       */
01394     __u8    num_sacks;  /* Number of SACK blocks        */
01395     __u16   advmss;     /* Advertised MSS           */
01396 
01397     __u8    syn_retries;    /* num of allowed syn retries */
01398     __u8    ecn_flags;  /* ECN status bits.         */
01399     __u16   prior_ssthresh; /* ssthresh saved at recovery start */
01400     __u32   lost_out;   /* Lost packets             */
01401     __u32   sacked_out; /* SACK'd packets           */
01402     __u32   fackets_out;    /* FACK'd packets           */
01403     __u32   high_seq;   /* snd_nxt at onset of congestion   */
01404 
01405     __u32   retrans_stamp;  /* Timestamp of the last retransmit,
01406                  * also used in SYN-SENT to remember stamp of
01407                  * the first SYN. */
01408     __u32   undo_marker;    /* tracking retrans started here. */
01409     int undo_retrans;   /* number of undoable retransmissions. */
01410     __u32   urg_seq;    /* Seq of received urgent pointer */
01411     __u16   urg_data;   /* Saved octet of OOB data and control flags */
01412     __u8    pending;    /* Scheduled timer event    */
01413     __u8    urg_mode;   /* In urgent mode       */
01414     __u32   snd_up;     /* Urgent pointer       */
01415 
01416     /* The syn_wait_lock is necessary only to avoid tcp_get_info having
01417      * to grab the main lock sock while browsing the listening hash
01418      * (otherwise it's deadlock prone).
01419      * This lock is acquired in read mode only from tcp_get_info() and
01420      * it's acquired in write mode _only_ from code that is actively
01421      * changing the syn_wait_queue. All readers that are holding
01422      * the master sock lock don't need to grab this lock in read mode
01423      * too as the syn_wait_queue writes are always protected from
01424      * the main sock lock.
01425      */
01426     rwlock_t        syn_wait_lock;
01427     struct tcp_listen_opt   *listen_opt;
01428 
01429     /* FIFO of established children */
01430     struct open_request *accept_queue;
01431     struct open_request *accept_queue_tail;
01432 
01433     int         write_pending;  /* A write to socket waits to start. */
01434 
01435     unsigned int        keepalive_time;   /* time before keep alive takes place */
01436     unsigned int        keepalive_intvl;  /* time interval between keep alive probes */
01437     int         linger2;
01438 
01439     unsigned long last_synq_overflow;
01440 };
01441 
01442 
01443 
01444 
01445 /* This is the per-socket lock.  The spinlock provides a synchronization
01446  * between user contexts and software interrupt processing, whereas the
01447  * mini-semaphore synchronizes multiple users amongst themselves.
01448  */
01449 typedef struct {
01450     spinlock_t      slock;
01451     unsigned int        users;
01452     wait_queue_head_t   wq;
01453 } socket_lock_t;
01454 
01455 struct sock {
01456     /* Socket demultiplex comparisons on incoming packets. */
01457     __u32           daddr;      /* Foreign IPv4 addr            */
01458     __u32           rcv_saddr;  /* Bound local IPv4 addr        */
01459     __u16           dport;      /* Destination port         */
01460     unsigned short      num;        /* Local port               */
01461     int         bound_dev_if;   /* Bound device index if != 0       */
01462 
01463     /* Main hash linkage for various protocol lookup tables. */
01464     struct sock     *next;
01465     struct sock     **pprev;
01466     struct sock     *bind_next;
01467     struct sock     **bind_pprev;
01468 
01469     volatile unsigned char  state,      /* Connection state         */
01470                 zapped;     /* In ax25 & ipx means not linked   */
01471     __u16           sport;      /* Source port              */
01472 
01473     unsigned short      family;     /* Address family           */
01474     unsigned char       reuse;      /* SO_REUSEADDR setting         */
01475     unsigned char       shutdown;
01476     atomic_t        refcnt;     /* Reference count          */
01477 
01478     socket_lock_t       lock;       /* Synchronizer...          */
01479     int         rcvbuf;     /* Size of receive buffer in bytes  */
01480 
01481     wait_queue_head_t   *sleep;     /* Sock wait queue          */
01482     struct dst_entry    *dst_cache; /* Destination cache            */
01483     rwlock_t        dst_lock;
01484     atomic_t        rmem_alloc; /* Receive queue bytes committed    */
01485     struct sk_buff_head receive_queue;  /* Incoming packets         */
01486     atomic_t        wmem_alloc; /* Transmit queue bytes committed   */
01487     struct sk_buff_head write_queue;    /* Packet sending queue         */
01488     atomic_t        omem_alloc; /* "o" is "option" or "other" */
01489     int         wmem_queued;    /* Persistent queue size */
01490     int         forward_alloc;  /* Space allocated forward. */
01491     __u32           saddr;      /* Sending source           */
01492     unsigned int        allocation; /* Allocation mode          */
01493     int         sndbuf;     /* Size of send buffer in bytes     */
01494     struct sock     *prev;
01495 
01496     /* Not all are volatile, but some are, so we might as well say they all are.
01497      * XXX Make this a flag word -DaveM
01498      */
01499     volatile char       dead,
01500                 done,
01501                 urginline,
01502                 keepopen,
01503                 linger,
01504                 destroy,
01505                 no_check,
01506                 broadcast,
01507                 bsdism;
01508     unsigned char       debug;
01509     unsigned char       rcvtstamp;
01510     unsigned char       use_write_queue;
01511     unsigned char       userlocks;
01512     /* Hole of 3 bytes. Try to pack. */
01513     int         route_caps;
01514     int         proc;
01515     unsigned long           lingertime;
01516 
01517     int         hashent;
01518     struct sock     *pair;
01519 
01520     /* The backlog queue is special, it is always used with
01521      * the per-socket spinlock held and requires low latency
01522      * access.  Therefore we special case it's implementation.
01523      */
01524     struct {
01525         struct sk_buff *head;
01526         struct sk_buff *tail;
01527     } backlog;
01528 
01529     rwlock_t        callback_lock;
01530 
01531     /* Error queue, rarely used. */
01532     struct sk_buff_head error_queue;
01533 
01534     struct proto        *prot;
01535 
01536 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
01537     union {
01538         struct ipv6_pinfo   af_inet6;
01539     } net_pinfo;
01540 #endif
01541 
01542     union {
01543         struct tcp_opt      af_tcp;
01544 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
01545         struct raw_opt      tp_raw4;
01546 #endif
01547 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
01548         struct raw6_opt     tp_raw;
01549 #endif /* CONFIG_IPV6 */
01550 #if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)
01551         struct spx_opt      af_spx;
01552 #endif /* CONFIG_SPX */
01553 
01554     } tp_pinfo;
01555 
01556     int         err, err_soft;  /* Soft holds errors that don't
01557                            cause failure but are the cause
01558                            of a persistent failure not just
01559                            'timed out' */
01560     unsigned short      ack_backlog;
01561     unsigned short      max_ack_backlog;
01562     __u32           priority;
01563     unsigned short      type;
01564     unsigned char       localroute; /* Route locally only */
01565     unsigned char       protocol;
01566 //  struct ucred        peercred;
01567     int         rcvlowat;
01568     long            rcvtimeo;
01569     long            sndtimeo;
01570 
01571 #ifdef CONFIG_FILTER
01572     /* Socket Filtering Instructions */
01573     struct sk_filter        *filter;
01574 #endif /* CONFIG_FILTER */
01575 
01576     /* This is where all the private (optional) areas that don't
01577      * overlap will eventually live.
01578      */
01579     union {
01580         void *destruct_hook;
01581 //      struct unix_opt af_unix;
01582 #if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
01583         struct inet_opt af_inet;
01584 #endif
01585 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
01586         struct atalk_sock   af_at;
01587 #endif
01588 #if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
01589         struct ipx_opt      af_ipx;
01590 #endif
01591 #if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
01592         struct dn_scp           dn;
01593 #endif
01594 #if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
01595         struct packet_opt   *af_packet;
01596 #endif
01597 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
01598         x25_cb          *x25;
01599 #endif
01600 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
01601         ax25_cb         *ax25;
01602 #endif
01603 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
01604         nr_cb           *nr;
01605 #endif
01606 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
01607         rose_cb         *rose;
01608 #endif
01609 #if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)
01610         struct pppox_opt    *pppox;
01611 #endif
01612         struct netlink_opt  *af_netlink;
01613 #if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)
01614         struct econet_opt   *af_econet;
01615 #endif
01616 #if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)
01617         struct atm_vcc      *af_atm;
01618 #endif
01619 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
01620         struct irda_sock        *irda;
01621 #endif
01622 #if defined(CONFIG_WAN_ROUTER) || defined(CONFIG_WAN_ROUTER_MODULE)
01623                struct wanpipe_opt      *af_wanpipe;
01624 #endif
01625     } protinfo;
01626 
01627 
01628     /* This part is used for the timeout functions. */
01629     struct timer_list   timer;      /* This is the sock cleanup timer. */
01630     struct timeval      stamp;
01631 
01632     /* Identd and reporting IO signals */
01633     struct socket       *socket;
01634 
01635     /* RPC layer private data */
01636     void            *user_data;
01637 
01638     /* Callbacks */
01639     void            (*state_change)(struct sock *sk);
01640     void            (*data_ready)(struct sock *sk,int bytes);
01641     void            (*write_space)(struct sock *sk);
01642     void            (*error_report)(struct sock *sk);
01643 
01644     int         (*backlog_rcv) (struct sock *sk,
01645                         struct sk_buff *skb);
01646     void                    (*destruct)(struct sock *sk);
01647 };
01648 
01649 
01650 
01651 
01652 #if 1 /* dst (_NET_DST_H) */
01653 
01654 #if 0
01655 #include <linux/config.h>
01656 #include <net/neighbour.h>
01657 #endif
01658 
01659 /*
01660  * 0 - no debugging messages
01661  * 1 - rare events and bugs (default)
01662  * 2 - trace mode.
01663  */
01664 #define RT_CACHE_DEBUG      0
01665 
01666 #define DST_GC_MIN  (1*HZ)
01667 #define DST_GC_INC  (5*HZ)
01668 #define DST_GC_MAX  (120*HZ)
01669 
01670 struct sk_buff;
01671 
01672 struct dst_entry
01673 {
01674     struct dst_entry        *next;
01675     atomic_t        __refcnt;   /* client references    */
01676     int         __use;
01677     struct net_device       *dev;
01678     int         obsolete;
01679     int         flags;
01680 #define DST_HOST        1
01681     unsigned long       lastuse;
01682     unsigned long       expires;
01683 
01684     unsigned        mxlock;
01685     unsigned        pmtu;
01686     unsigned        window;
01687     unsigned        rtt;
01688     unsigned        rttvar;
01689     unsigned        ssthresh;
01690     unsigned        cwnd;
01691     unsigned        advmss;
01692     unsigned        reordering;
01693 
01694     unsigned long       rate_last;  /* rate limiting for ICMP */
01695     unsigned long       rate_tokens;
01696 
01697     int         error;
01698 
01699     struct neighbour    *neighbour;
01700     struct hh_cache     *hh;
01701 
01702     int         (*input)(struct sk_buff*);
01703     int         (*output)(struct sk_buff*);
01704 
01705 #ifdef CONFIG_NET_CLS_ROUTE
01706     __u32           tclassid;
01707 #endif
01708 
01709     struct  dst_ops         *ops;
01710 
01711     char            info[0];
01712 };
01713 
01714 
01715 struct dst_ops
01716 {
01717     unsigned short      family;
01718     unsigned short      protocol;
01719     unsigned        gc_thresh;
01720 
01721     int         (*gc)(void);
01722     struct dst_entry *  (*check)(struct dst_entry *, __u32 cookie);
01723     struct dst_entry *  (*reroute)(struct dst_entry *,
01724                        struct sk_buff *);
01725     void            (*destroy)(struct dst_entry *);
01726     struct dst_entry *  (*negative_advice)(struct dst_entry *);
01727     void            (*link_failure)(struct sk_buff *);
01728     int         entry_size;
01729 
01730     atomic_t        entries;
01731     kmem_cache_t        *kmem_cachep;
01732 };
01733 
01734 #ifdef __KERNEL__
01735 
01736 static __inline void dst_hold(struct dst_entry * dst)
01737 {
01738     atomic_inc(&dst->__refcnt);
01739 }
01740 
01741 static __inline
01742 struct dst_entry * dst_clone(struct dst_entry * dst)
01743 {
01744     if (dst)
01745         atomic_inc(&dst->__refcnt);
01746     return dst;
01747 }
01748 
01749 static __inline
01750 void dst_release(struct dst_entry * dst)
01751 {
01752     if (dst)
01753         atomic_dec(&dst->__refcnt);
01754 }
01755 
01756 extern void * dst_alloc(struct dst_ops * ops);
01757 extern void __dst_free(struct dst_entry * dst);
01758 extern void dst_destroy(struct dst_entry * dst);
01759 
01760 static __inline
01761 void dst_free(struct dst_entry * dst)
01762 {
01763     if (dst->obsolete > 1)
01764         return;
01765     if (!atomic_read(&dst->__refcnt)) {
01766         dst_destroy(dst);
01767         return;
01768     }
01769     __dst_free(dst);
01770 }
01771 
01772 static __inline void dst_confirm(struct dst_entry *dst)
01773 {
01774     if (dst)
01775         neigh_confirm(dst->neighbour);
01776 }
01777 
01778 static __inline void dst_negative_advice(struct dst_entry **dst_p)
01779 {
01780     struct dst_entry * dst = *dst_p;
01781     if (dst && dst->ops->negative_advice)
01782         *dst_p = dst->ops->negative_advice(dst);
01783 }
01784 
01785 static __inline void dst_link_failure(struct sk_buff *skb)
01786 {
01787     struct dst_entry * dst = skb->dst;
01788     if (dst && dst->ops && dst->ops->link_failure)
01789         dst->ops->link_failure(skb);
01790 }
01791 
01792 static __inline void dst_set_expires(struct dst_entry *dst, int timeout)
01793 {
01794     unsigned long expires = jiffies + timeout;
01795 
01796     if (expires == 0)
01797         expires = 1;
01798 
01799     if (dst->expires == 0 || (long)(dst->expires - expires) > 0)
01800         dst->expires = expires;
01801 }
01802 
01803 extern void     dst_init(void);
01804 
01805 #endif /* dst */
01806 
01807 
01808 
01809 #if 1
01810 /* dummy types */
01811 
01812 
01813 #endif
01814 
01815 #define TCP_DEBUG 1
01816 #define FASTRETRANS_DEBUG 1
01817 
01818 /* Cancel timers, when they are not required. */
01819 #undef TCP_CLEAR_TIMERS
01820 
01821 #if 0
01822 #include <linux/config.h>
01823 #include <linux/tcp.h>
01824 #include <linux/slab.h>
01825 #include <linux/cache.h>
01826 #include <net/checksum.h>
01827 #include <net/sock.h>
01828 #else
01829 #include "linux.h"
01830 #endif
01831 
01832 /* This is for all connections with a full identity, no wildcards.
01833  * New scheme, half the table is for TIME_WAIT, the other half is
01834  * for the rest.  I'll experiment with dynamic table growth later.
01835  */
01836 struct tcp_ehash_bucket {
01837     rwlock_t    lock;
01838     struct sock *chain;
01839 } __attribute__((__aligned__(8)));
01840 
01841 /* This is for listening sockets, thus all sockets which possess wildcards. */
01842 #define TCP_LHTABLE_SIZE    32  /* Yes, really, this is all you need. */
01843 
01844 /* There are a few simple rules, which allow for local port reuse by
01845  * an application.  In essence:
01846  *
01847  *  1) Sockets bound to different interfaces may share a local port.
01848  *     Failing that, goto test 2.
01849  *  2) If all sockets have sk->reuse set, and none of them are in
01850  *     TCP_LISTEN state, the port may be shared.
01851  *     Failing that, goto test 3.
01852  *  3) If all sockets are bound to a specific sk->rcv_saddr local
01853  *     address, and none of them are the same, the port may be
01854  *     shared.
01855  *     Failing this, the port cannot be shared.
01856  *
01857  * The interesting point, is test #2.  This is what an FTP server does
01858  * all day.  To optimize this case we use a specific flag bit defined
01859  * below.  As we add sockets to a bind bucket list, we perform a
01860  * check of: (newsk->reuse && (newsk->state != TCP_LISTEN))
01861  * As long as all sockets added to a bind bucket pass this test,
01862  * the flag bit will be set.
01863  * The resulting situation is that tcp_v[46]_verify_bind() can just check
01864  * for this flag bit, if it is set and the socket trying to bind has
01865  * sk->reuse set, we don't even have to walk the owners list at all,
01866  * we return that it is ok to bind this socket to the requested local port.
01867  *
01868  * Sounds like a lot of work, but it is worth it.  In a more naive
01869  * implementation (ie. current FreeBSD etc.) the entire list of ports
01870  * must be walked for each data port opened by an ftp server.  Needless
01871  * to say, this does not scale at all.  With a couple thousand FTP
01872  * users logged onto your box, isn't it nice to know that new data
01873  * ports are created in O(1) time?  I thought so. ;-)   -DaveM
01874  */
01875 struct tcp_bind_bucket {
01876     unsigned short      port;
01877     signed short        fastreuse;
01878     struct tcp_bind_bucket  *next;
01879     struct sock     *owners;
01880     struct tcp_bind_bucket  **pprev;
01881 };
01882 
01883 struct tcp_bind_hashbucket {
01884     spinlock_t      lock;
01885     struct tcp_bind_bucket  *chain;
01886 };
01887 
01888 extern struct tcp_hashinfo {
01889     /* This is for sockets with full identity only.  Sockets here will
01890      * always be without wildcards and will have the following invariant:
01891      *
01892      *          TCP_ESTABLISHED <= sk->state < TCP_CLOSE
01893      *
01894      * First half of the table is for sockets not in TIME_WAIT, second half
01895      * is for TIME_WAIT sockets only.
01896      */
01897     struct tcp_ehash_bucket *__tcp_ehash;
01898 
01899     /* Ok, let's try this, I give up, we do need a local binding
01900      * TCP hash as well as the others for fast bind/connect.
01901      */
01902     struct tcp_bind_hashbucket *__tcp_bhash;
01903 
01904     int __tcp_bhash_size;
01905     int __tcp_ehash_size;
01906 
01907     /* All sockets in TCP_LISTEN state will be in here.  This is the only
01908      * table where wildcard'd TCP sockets can exist.  Hash function here
01909      * is just local port number.
01910      */
01911     struct sock *__tcp_listening_hash[TCP_LHTABLE_SIZE];
01912 
01913     /* All the above members are written once at bootup and
01914      * never written again _or_ are predominantly read-access.
01915      *
01916      * Now align to a new cache line as all the following members
01917      * are often dirty.
01918      */
01919     rwlock_t __tcp_lhash_lock ____cacheline_aligned;
01920     atomic_t __tcp_lhash_users;
01921     wait_queue_head_t __tcp_lhash_wait;
01922     spinlock_t __tcp_portalloc_lock;
01923 } tcp_hashinfo;
01924 
01925 #define tcp_ehash   (tcp_hashinfo.__tcp_ehash)
01926 #define tcp_bhash   (tcp_hashinfo.__tcp_bhash)
01927 #define tcp_ehash_size  (tcp_hashinfo.__tcp_ehash_size)
01928 #define tcp_bhash_size  (tcp_hashinfo.__tcp_bhash_size)
01929 #define tcp_listening_hash (tcp_hashinfo.__tcp_listening_hash)
01930 #define tcp_lhash_lock  (tcp_hashinfo.__tcp_lhash_lock)
01931 #define tcp_lhash_users (tcp_hashinfo.__tcp_lhash_users)
01932 #define tcp_lhash_wait  (tcp_hashinfo.__tcp_lhash_wait)
01933 #define tcp_portalloc_lock (tcp_hashinfo.__tcp_portalloc_lock)
01934 
01935 extern kmem_cache_t *tcp_bucket_cachep;
01936 extern struct tcp_bind_bucket *tcp_bucket_create(struct tcp_bind_hashbucket *head,
01937                          unsigned short snum);
01938 extern void tcp_bucket_unlock(struct sock *sk);
01939 extern int tcp_port_rover;
01940 extern struct sock *tcp_v4_lookup_listener(u32 addr, unsigned short hnum, int dif);
01941 
01942 /* These are AF independent. */
01943 static __inline int tcp_bhashfn(__u16 lport)
01944 {
01945     return (lport & (tcp_bhash_size - 1));
01946 }
01947 
01948 /* This is a TIME_WAIT bucket.  It works around the memory consumption
01949  * problems of sockets in such a state on heavily loaded servers, but
01950  * without violating the protocol specification.
01951  */
01952 struct tcp_tw_bucket {
01953     /* These _must_ match the beginning of struct sock precisely.
01954      * XXX Yes I know this is gross, but I'd have to edit every single
01955      * XXX networking file if I created a "struct sock_header". -DaveM
01956      */
01957     __u32           daddr;
01958     __u32           rcv_saddr;
01959     __u16           dport;
01960     unsigned short      num;
01961     int         bound_dev_if;
01962     struct sock     *next;
01963     struct sock     **pprev;
01964     struct sock     *bind_next;
01965     struct sock     **bind_pprev;
01966     unsigned char       state,
01967                 substate; /* "zapped" is replaced with "substate" */
01968     __u16           sport;
01969     unsigned short      family;
01970     unsigned char       reuse,
01971                 rcv_wscale; /* It is also TW bucket specific */
01972     atomic_t        refcnt;
01973 
01974     /* And these are ours. */
01975     int         hashent;
01976     int         timeout;
01977     __u32           rcv_nxt;
01978     __u32           snd_nxt;
01979     __u32           rcv_wnd;
01980         __u32           ts_recent;
01981         long            ts_recent_stamp;
01982     unsigned long       ttd;
01983     struct tcp_bind_bucket  *tb;
01984     struct tcp_tw_bucket    *next_death;
01985     struct tcp_tw_bucket    **pprev_death;
01986 
01987 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
01988     struct in6_addr     v6_daddr;
01989     struct in6_addr     v6_rcv_saddr;
01990 #endif
01991 };
01992 
01993 extern kmem_cache_t *tcp_timewait_cachep;
01994 
01995 static __inline void tcp_tw_put(struct tcp_tw_bucket *tw)
01996 {
01997     if (atomic_dec_and_test(&tw->refcnt)) {
01998 #ifdef INET_REFCNT_DEBUG
01999         printk(KERN_DEBUG "tw_bucket %p released\n", tw);
02000 #endif
02001         kmem_cache_free(tcp_timewait_cachep, tw);
02002     }
02003 }
02004 
02005 extern atomic_t tcp_orphan_count;
02006 extern int tcp_tw_count;
02007 extern void tcp_time_wait(struct sock *sk, int state, int timeo);
02008 extern void tcp_timewait_kill(struct tcp_tw_bucket *tw);
02009 extern void tcp_tw_schedule(struct tcp_tw_bucket *tw, int timeo);
02010 extern void tcp_tw_deschedule(struct tcp_tw_bucket *tw);
02011 
02012 
02013 /* Socket demux engine toys. */
02014 #ifdef __BIG_ENDIAN
02015 #define TCP_COMBINED_PORTS(__sport, __dport) \
02016     (((__u32)(__sport)<<16) | (__u32)(__dport))
02017 #else /* __LITTLE_ENDIAN */
02018 #define TCP_COMBINED_PORTS(__sport, __dport) \
02019     (((__u32)(__dport)<<16) | (__u32)(__sport))
02020 #endif
02021 
02022 #if (BITS_PER_LONG == 64)
02023 #ifdef __BIG_ENDIAN
02024 #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr) \
02025     __u64 __name = (((__u64)(__saddr))<<32)|((__u64)(__daddr));
02026 #else /* __LITTLE_ENDIAN */
02027 #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr) \
02028     __u64 __name = (((__u64)(__daddr))<<32)|((__u64)(__saddr));
02029 #endif /* __BIG_ENDIAN */
02030 #define TCP_IPV4_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\
02031     (((*((__u64 *)&((__sk)->daddr)))== (__cookie))  &&      \
02032      ((*((__u32 *)&((__sk)->dport)))== (__ports))   &&      \
02033      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
02034 #else /* 32-bit arch */
02035 #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr)
02036 #define TCP_IPV4_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\
02037     (((__sk)->daddr         == (__saddr))   &&      \
02038      ((__sk)->rcv_saddr     == (__daddr))   &&      \
02039      ((*((__u32 *)&((__sk)->dport)))== (__ports))   &&      \
02040      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
02041 #endif /* 64-bit arch */
02042 
02043 #define TCP_IPV6_MATCH(__sk, __saddr, __daddr, __ports, __dif)             \
02044     (((*((__u32 *)&((__sk)->dport)))== (__ports))               && \
02045      ((__sk)->family        == AF_INET6)                && \
02046      !ipv6_addr_cmp(&(__sk)->net_pinfo.af_inet6.daddr, (__saddr))       && \
02047      !ipv6_addr_cmp(&(__sk)->net_pinfo.af_inet6.rcv_saddr, (__daddr))   && \
02048      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
02049 
02050 /* These can have wildcards, don't try too hard. */
02051 static __inline int tcp_lhashfn(unsigned short num)
02052 {
02053 #if 0
02054     return num & (TCP_LHTABLE_SIZE - 1);
02055 #else
02056   return 0;
02057 #endif
02058 }
02059 
02060 static __inline int tcp_sk_listen_hashfn(struct sock *sk)
02061 {
02062 #if 0
02063     return tcp_lhashfn(sk->num);
02064 #else
02065   return 0;
02066 #endif
02067 }
02068 
02069 #define MAX_TCP_HEADER  (128 + MAX_HEADER)
02070 
02071 /*
02072  * Never offer a window over 32767 without using window scaling. Some
02073  * poor stacks do signed 16bit maths!
02074  */
02075 #define MAX_TCP_WINDOW      32767U
02076 
02077 /* Minimal accepted MSS. It is (60+60+8) - (20+20). */
02078 #define TCP_MIN_MSS     88U
02079 
02080 /* Minimal RCV_MSS. */
02081 #define TCP_MIN_RCVMSS      536U
02082 
02083 /* After receiving this amount of duplicate ACKs fast retransmit starts. */
02084 #define TCP_FASTRETRANS_THRESH 3
02085 
02086 /* Maximal reordering. */
02087 #define TCP_MAX_REORDERING  127
02088 
02089 /* Maximal number of ACKs sent quickly to accelerate slow-start. */
02090 #define TCP_MAX_QUICKACKS   16U
02091 
02092 /* urg_data states */
02093 #define TCP_URG_VALID   0x0100
02094 #define TCP_URG_NOTYET  0x0200
02095 #define TCP_URG_READ    0x0400
02096 
02097 #define TCP_RETR1   3   /*
02098                  * This is how many retries it does before it
02099                  * tries to figure out if the gateway is
02100                  * down. Minimal RFC value is 3; it corresponds
02101                  * to ~3sec-8min depending on RTO.
02102                  */
02103 
02104 #define TCP_RETR2   15  /*
02105                  * This should take at least
02106                  * 90 minutes to time out.
02107                  * RFC1122 says that the limit is 100 sec.
02108                  * 15 is ~13-30min depending on RTO.
02109                  */
02110 
02111 #define TCP_SYN_RETRIES  5  /* number of times to retry active opening a
02112                  * connection: ~180sec is RFC minumum   */
02113 
02114 #define TCP_SYNACK_RETRIES 5    /* number of times to retry passive opening a
02115                  * connection: ~180sec is RFC minumum   */
02116 
02117 
02118 #define TCP_ORPHAN_RETRIES 7    /* number of times to retry on an orphaned
02119                  * socket. 7 is ~50sec-16min.
02120                  */
02121 
02122 
02123 #define TCP_TIMEWAIT_LEN (60*1000)
02124 //#define TCP_TIMEWAIT_LEN (60*HZ)
02125 /* how long to wait to destroy TIME-WAIT
02126                   * state, about 60 seconds */
02127 #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN
02128                                  /* BSD style FIN_WAIT2 deadlock breaker.
02129                   * It used to be 3min, new value is 60sec,
02130                   * to combine FIN-WAIT-2 timeout with
02131                   * TIME-WAIT timer.
02132                   */
02133 
02134 #define TCP_DELACK_MAX  ((unsigned)(HZ/5))  /* maximal time to delay before sending an ACK */
02135 #if HZ >= 100
02136 #define TCP_DELACK_MIN  ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */
02137 #define TCP_ATO_MIN ((unsigned)(HZ/25))
02138 #else
02139 #define TCP_DELACK_MIN  4U
02140 #define TCP_ATO_MIN 4U
02141 #endif
02142 #define TCP_RTO_MAX ((unsigned)(120*HZ))
02143 #define TCP_RTO_MIN ((unsigned)(HZ/5))
02144 #define TCP_TIMEOUT_INIT ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value   */
02145 
02146 #define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes
02147                                      * for local resources.
02148                                      */
02149 
02150 #define TCP_KEEPALIVE_TIME  (120*60*HZ) /* two hours */
02151 #define TCP_KEEPALIVE_PROBES    9       /* Max of 9 keepalive probes    */
02152 #define TCP_KEEPALIVE_INTVL (75*HZ)
02153 
02154 #define MAX_TCP_KEEPIDLE    32767
02155 #define MAX_TCP_KEEPINTVL   32767
02156 #define MAX_TCP_KEEPCNT     127
02157 #define MAX_TCP_SYNCNT      127
02158 
02159 /* TIME_WAIT reaping mechanism. */
02160 #define TCP_TWKILL_SLOTS    8   /* Please keep this a power of 2. */
02161 #define TCP_TWKILL_PERIOD   (TCP_TIMEWAIT_LEN/TCP_TWKILL_SLOTS)
02162 
02163 #define TCP_SYNQ_INTERVAL   (HZ/5)  /* Period of SYNACK timer */
02164 #define TCP_SYNQ_HSIZE      512 /* Size of SYNACK hash table */
02165 
02166 #define TCP_PAWS_24DAYS (60 * 60 * 24 * 24)
02167 #define TCP_PAWS_MSL    60      /* Per-host timestamps are invalidated
02168                      * after this time. It should be equal
02169                      * (or greater than) TCP_TIMEWAIT_LEN
02170                      * to provide reliability equal to one
02171                      * provided by timewait state.
02172                      */
02173 #define TCP_PAWS_WINDOW 1       /* Replay window for per-host
02174                      * timestamps. It must be less than
02175                      * minimal timewait lifetime.
02176                      */
02177 
02178 #define TCP_TW_RECYCLE_SLOTS_LOG    5
02179 #define TCP_TW_RECYCLE_SLOTS        (1<<TCP_TW_RECYCLE_SLOTS_LOG)
02180 
02181 /* If time > 4sec, it is "slow" path, no recycling is required,
02182    so that we select tick to get range about 4 seconds.
02183  */
02184 
02185 #if 0
02186 #if HZ <= 16 || HZ > 4096
02187 # error Unsupported: HZ <= 16 or HZ > 4096
02188 #elif HZ <= 32
02189 # define TCP_TW_RECYCLE_TICK (5+2-TCP_TW_RECYCLE_SLOTS_LOG)
02190 #elif HZ <= 64
02191 # define TCP_TW_RECYCLE_TICK (6+2-TCP_TW_RECYCLE_SLOTS_LOG)
02192 #elif HZ <= 128
02193 # define TCP_TW_RECYCLE_TICK (7+2-TCP_TW_RECYCLE_SLOTS_LOG)
02194 #elif HZ <= 256
02195 # define TCP_TW_RECYCLE_TICK (8+2-TCP_TW_RECYCLE_SLOTS_LOG)
02196 #elif HZ <= 512
02197 # define TCP_TW_RECYCLE_TICK (9+2-TCP_TW_RECYCLE_SLOTS_LOG)
02198 #elif HZ <= 1024
02199 # define TCP_TW_RECYCLE_TICK (10+2-TCP_TW_RECYCLE_SLOTS_LOG)
02200 #elif HZ <= 2048
02201 # define TCP_TW_RECYCLE_TICK (11+2-TCP_TW_RECYCLE_SLOTS_LOG)
02202 #else
02203 # define TCP_TW_RECYCLE_TICK (12+2-TCP_TW_RECYCLE_SLOTS_LOG)
02204 #endif
02205 #else
02206 #define TCP_TW_RECYCLE_TICK (0)
02207 #endif
02208 
02209 /*
02210  *  TCP option
02211  */
02212 
02213 #define TCPOPT_NOP      1   /* Padding */
02214 #define TCPOPT_EOL      0   /* End of options */
02215 #define TCPOPT_MSS      2   /* Segment size negotiating */
02216 #define TCPOPT_WINDOW       3   /* Window scaling */
02217 #define TCPOPT_SACK_PERM        4       /* SACK Permitted */
02218 #define TCPOPT_SACK             5       /* SACK Block */
02219 #define TCPOPT_TIMESTAMP    8   /* Better RTT estimations/PAWS */
02220 
02221 /*
02222  *     TCP option lengths
02223  */
02224 
02225 #define TCPOLEN_MSS            4
02226 #define TCPOLEN_WINDOW         3
02227 #define TCPOLEN_SACK_PERM      2
02228 #define TCPOLEN_TIMESTAMP      10
02229 
02230 /* But this is what stacks really send out. */
02231 #define TCPOLEN_TSTAMP_ALIGNED      12
02232 #define TCPOLEN_WSCALE_ALIGNED      4
02233 #define TCPOLEN_SACKPERM_ALIGNED    4
02234 #define TCPOLEN_SACK_BASE       2
02235 #define TCPOLEN_SACK_BASE_ALIGNED   4
02236 #define TCPOLEN_SACK_PERBLOCK       8
02237 
02238 #define TCP_TIME_RETRANS    1   /* Retransmit timer */
02239 #define TCP_TIME_DACK       2   /* Delayed ack timer */
02240 #define TCP_TIME_PROBE0     3   /* Zero window probe timer */
02241 #define TCP_TIME_KEEPOPEN   4   /* Keepalive timer */
02242 
02243 #if 0
02244 /* sysctl variables for tcp */
02245 extern int sysctl_max_syn_backlog;
02246 extern int sysctl_tcp_timestamps;
02247 extern int sysctl_tcp_window_scaling;
02248 extern int sysctl_tcp_sack;
02249 extern int sysctl_tcp_fin_timeout;
02250 extern int sysctl_tcp_tw_recycle;
02251 extern int sysctl_tcp_keepalive_time;
02252 extern int sysctl_tcp_keepalive_probes;
02253 extern int sysctl_tcp_keepalive_intvl;
02254 extern int sysctl_tcp_syn_retries;
02255 extern int sysctl_tcp_synack_retries;
02256 extern int sysctl_tcp_retries1;
02257 extern int sysctl_tcp_retries2;
02258 extern int sysctl_tcp_orphan_retries;
02259 extern int sysctl_tcp_syncookies;
02260 extern int sysctl_tcp_retrans_collapse;
02261 extern int sysctl_tcp_stdurg;
02262 extern int sysctl_tcp_rfc1337;
02263 extern int sysctl_tcp_abort_on_overflow;
02264 extern int sysctl_tcp_max_orphans;
02265 extern int sysctl_tcp_max_tw_buckets;
02266 extern int sysctl_tcp_fack;
02267 extern int sysctl_tcp_reordering;
02268 extern int sysctl_tcp_ecn;
02269 extern int sysctl_tcp_dsack;
02270 extern int sysctl_tcp_mem[3];
02271 extern int sysctl_tcp_wmem[3];
02272 extern int sysctl_tcp_rmem[3];
02273 extern int sysctl_tcp_app_win;
02274 extern int sysctl_tcp_adv_win_scale;
02275 extern int sysctl_tcp_tw_reuse;
02276 #endif
02277 
02278 extern atomic_t tcp_memory_allocated;
02279 extern atomic_t tcp_sockets_allocated;
02280 extern int tcp_memory_pressure;
02281 
02282 struct open_request;
02283 
02284 struct or_calltable {
02285     int  family;
02286     int  (*rtx_syn_ack) (struct sock *sk, struct open_request *req, struct dst_entry*);
02287     void (*send_ack)    (struct sk_buff *skb, struct open_request *req);
02288     void (*destructor)  (struct open_request *req);
02289     void (*send_reset)  (struct sk_buff *skb);
02290 };
02291 
02292 struct tcp_v4_open_req {
02293     __u32           loc_addr;
02294     __u32           rmt_addr;
02295     struct ip_options   *opt;
02296 };
02297 
02298 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
02299 struct tcp_v6_open_req {
02300     struct in6_addr     loc_addr;
02301     struct in6_addr     rmt_addr;
02302     struct sk_buff      *pktopts;
02303     int         iif;
02304 };
02305 #endif
02306 
02307 /* this structure is too big */
02308 struct open_request {
02309     struct open_request *dl_next; /* Must be first member! */
02310     __u32           rcv_isn;
02311     __u32           snt_isn;
02312     __u16           rmt_port;
02313     __u16           mss;
02314     __u8            retrans;
02315     __u8            __pad;
02316     __u16   snd_wscale : 4,
02317         rcv_wscale : 4,
02318         tstamp_ok : 1,
02319         sack_ok : 1,
02320         wscale_ok : 1,
02321         ecn_ok : 1,
02322         acked : 1;
02323     /* The following two fields can be easily recomputed I think -AK */
02324     __u32           window_clamp;   /* window clamp at creation time */
02325     __u32           rcv_wnd;    /* rcv_wnd offered first time */
02326     __u32           ts_recent;
02327     unsigned long       expires;
02328     struct or_calltable *class;
02329     struct sock     *sk;
02330     union {
02331         struct tcp_v4_open_req v4_req;
02332 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
02333         struct tcp_v6_open_req v6_req;
02334 #endif
02335     } af;
02336 };
02337 
02338 /* SLAB cache for open requests. */
02339 extern kmem_cache_t *tcp_openreq_cachep;
02340 
02341 #define tcp_openreq_alloc()     kmem_cache_alloc(tcp_openreq_cachep, SLAB_ATOMIC)
02342 #define tcp_openreq_fastfree(req)   kmem_cache_free(tcp_openreq_cachep, req)
02343 
02344 static __inline void tcp_openreq_free(struct open_request *req)
02345 {
02346     req->class->destructor(req);
02347     tcp_openreq_fastfree(req);
02348 }
02349 
02350 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
02351 #define TCP_INET_FAMILY(fam) ((fam) == AF_INET)
02352 #else
02353 #define TCP_INET_FAMILY(fam) 1
02354 #endif
02355 
02356 /*
02357  *  Pointers to address related TCP functions
02358  *  (i.e. things that depend on the address family)
02359  *
02360  *  BUGGG_FUTURE: all the idea behind this struct is wrong.
02361  *  It mixes socket frontend with transport function.
02362  *  With port sharing between IPv6/v4 it gives the only advantage,
02363  *  only poor IPv6 needs to permanently recheck, that it
02364  *  is still IPv6 8)8) It must be cleaned up as soon as possible.
02365  *                      --ANK (980802)
02366  */
02367 
02368 struct tcp_func {
02369     int         (*queue_xmit)       (struct sk_buff *skb);
02370 
02371     void            (*send_check)       (struct sock *sk,
02372                              struct tcphdr *th,
02373                              int len,
02374                              struct sk_buff *skb);
02375 
02376     int         (*rebuild_header)   (struct sock *sk);
02377 
02378     int         (*conn_request)     (struct sock *sk,
02379                              struct sk_buff *skb);
02380 
02381     struct sock *       (*syn_recv_sock)    (struct sock *sk,
02382                              struct sk_buff *skb,
02383                              struct open_request *req,
02384                              struct dst_entry *dst);
02385 
02386     int         (*remember_stamp)   (struct sock *sk);
02387 
02388     __u16           net_header_len;
02389 
02390     int         (*setsockopt)       (struct sock *sk,
02391                              int level,
02392                              int optname,
02393                              char *optval,
02394                              int optlen);
02395 
02396     int         (*getsockopt)       (struct sock *sk,
02397                              int level,
02398                              int optname,
02399                              char *optval,
02400                              int *optlen);
02401 
02402 
02403     void            (*addr2sockaddr)    (struct sock *sk,
02404                              struct sockaddr *);
02405 
02406     int sockaddr_len;
02407 };
02408 
02409 /*
02410  * The next routines deal with comparing 32 bit unsigned ints
02411  * and worry about wraparound (automatic with unsigned arithmetic).
02412  */
02413 
02414 extern __inline int before(__u32 seq1, __u32 seq2)
02415 {
02416         return (__s32)(seq1-seq2) < 0;
02417 }
02418 
02419 extern __inline int after(__u32 seq1, __u32 seq2)
02420 {
02421     return (__s32)(seq2-seq1) < 0;
02422 }
02423 
02424 
02425 /* is s2<=s1<=s3 ? */
02426 extern __inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
02427 {
02428     return seq3 - seq2 >= seq1 - seq2;
02429 }
02430 
02431 
02432 extern struct proto tcp_prot;
02433 
02434 #ifdef ROS_STATISTICS
02435 extern struct tcp_mib tcp_statistics[NR_CPUS*2];
02436 
02437 #define TCP_INC_STATS(field)        SNMP_INC_STATS(tcp_statistics, field)
02438 #define TCP_INC_STATS_BH(field)     SNMP_INC_STATS_BH(tcp_statistics, field)
02439 #define TCP_INC_STATS_USER(field)   SNMP_INC_STATS_USER(tcp_statistics, field)
02440 #endif
02441 
02442 extern void         tcp_put_port(struct sock *sk);
02443 extern void         __tcp_put_port(struct sock *sk);
02444 extern void         tcp_inherit_port(struct sock *sk, struct sock *child);
02445 
02446 extern void         tcp_v4_err(struct sk_buff *skb, u32);
02447 
02448 extern void         tcp_shutdown (struct sock *sk, int how);
02449 
02450 extern int          tcp_v4_rcv(struct sk_buff *skb);
02451 
02452 extern int          tcp_v4_remember_stamp(struct sock *sk);
02453 
02454 extern int              tcp_v4_tw_remember_stamp(struct tcp_tw_bucket *tw);
02455 
02456 extern int          tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size);
02457 extern ssize_t          tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags);
02458 
02459 extern int          tcp_ioctl(struct sock *sk,
02460                       int cmd,
02461                       unsigned long arg);
02462 
02463 extern int          tcp_rcv_state_process(struct sock *sk,
02464                               struct sk_buff *skb,
02465                               struct tcphdr *th,
02466                               unsigned len);
02467 
02468 extern int          tcp_rcv_established(struct sock *sk,
02469                             struct sk_buff *skb,
02470                             struct tcphdr *th,
02471                             unsigned len);
02472 
02473 enum tcp_ack_state_t
02474 {
02475     TCP_ACK_SCHED = 1,
02476     TCP_ACK_TIMER = 2,
02477     TCP_ACK_PUSHED= 4
02478 };
02479 
02480 static __inline void tcp_schedule_ack(struct tcp_opt *tp)
02481 {
02482     tp->ack.pending |= TCP_ACK_SCHED;
02483 }
02484 
02485 static __inline int tcp_ack_scheduled(struct tcp_opt *tp)
02486 {
02487     return tp->ack.pending&TCP_ACK_SCHED;
02488 }
02489 
02490 static __inline void tcp_dec_quickack_mode(struct tcp_opt *tp)
02491 {
02492     if (tp->ack.quick && --tp->ack.quick == 0) {
02493         /* Leaving quickack mode we deflate ATO. */
02494         tp->ack.ato = TCP_ATO_MIN;
02495     }
02496 }
02497 
02498 extern void tcp_enter_quickack_mode(struct tcp_opt *tp);
02499 
02500 static __inline void tcp_delack_init(struct tcp_opt *tp)
02501 {
02502     memset(&tp->ack, 0, sizeof(tp->ack));
02503 }
02504 
02505 static __inline void tcp_clear_options(struct tcp_opt *tp)
02506 {
02507     tp->tstamp_ok = tp->sack_ok = tp->wscale_ok = tp->snd_wscale = 0;
02508 }
02509 
02510 enum tcp_tw_status
02511 {
02512     TCP_TW_SUCCESS = 0,
02513     TCP_TW_RST = 1,
02514     TCP_TW_ACK = 2,
02515     TCP_TW_SYN = 3
02516 };
02517 
02518 
02519 extern enum tcp_tw_status   tcp_timewait_state_process(struct tcp_tw_bucket *tw,
02520                                struct sk_buff *skb,
02521                                struct tcphdr *th,
02522                                unsigned len);
02523 
02524 extern struct sock *        tcp_check_req(struct sock *sk,struct sk_buff *skb,
02525                           struct open_request *req,
02526                           struct open_request **prev);
02527 extern int          tcp_child_process(struct sock *parent,
02528                           struct sock *child,
02529                           struct sk_buff *skb);
02530 extern void         tcp_enter_loss(struct sock *sk, int how);
02531 extern void         tcp_clear_retrans(struct tcp_opt *tp);
02532 extern void         tcp_update_metrics(struct sock *sk);
02533 
02534 extern void         tcp_close(struct sock *sk,
02535                       long timeout);
02536 extern struct sock *        tcp_accept(struct sock *sk, int flags, int *err);
02537 extern unsigned int     tcp_poll(struct file * file, struct socket *sock, struct poll_table_struct *wait);
02538 extern void         tcp_write_space(struct sock *sk);
02539 
02540 extern int          tcp_getsockopt(struct sock *sk, int level,
02541                            int optname, char *optval,
02542                            int *optlen);
02543 extern int          tcp_setsockopt(struct sock *sk, int level,
02544                            int optname, char *optval,
02545                            int optlen);
02546 extern void         tcp_set_keepalive(struct sock *sk, int val);
02547 extern int          tcp_recvmsg(struct sock *sk,
02548                         struct msghdr *msg,
02549                         int len, int nonblock,
02550                         int flags, int *addr_len);
02551 
02552 extern int          tcp_listen_start(struct sock *sk);
02553 
02554 extern void         tcp_parse_options(struct sk_buff *skb,
02555                           struct tcp_opt *tp,
02556                           int estab);
02557 
02558 /*
02559  *  TCP v4 functions exported for the inet6 API
02560  */
02561 
02562 extern int              tcp_v4_rebuild_header(struct sock *sk);
02563 
02564 extern int              tcp_v4_build_header(struct sock *sk,
02565                             struct sk_buff *skb);
02566 
02567 extern void             tcp_v4_send_check(struct sock *sk,
02568                           struct tcphdr *th, int len,
02569                           struct sk_buff *skb);
02570 
02571 extern int          tcp_v4_conn_request(struct sock *sk,
02572                             struct sk_buff *skb);
02573 
02574 extern struct sock *        tcp_create_openreq_child(struct sock *sk,
02575                              struct open_request *req,
02576                              struct sk_buff *skb);
02577 
02578 extern struct sock *        tcp_v4_syn_recv_sock(struct sock *sk,
02579                              struct sk_buff *skb,
02580                              struct open_request *req,
02581                             struct dst_entry *dst);
02582 
02583 extern int          tcp_v4_do_rcv(struct sock *sk,
02584                           struct sk_buff *skb);
02585 
02586 extern int          tcp_v4_connect(struct sock *sk,
02587                            struct sockaddr *uaddr,
02588                            int addr_len);
02589 
02590 extern int          tcp_connect(struct sock *sk);
02591 
02592 extern struct sk_buff *     tcp_make_synack(struct sock *sk,
02593                         struct dst_entry *dst,
02594                         struct open_request *req);
02595 
02596 extern int          tcp_disconnect(struct sock *sk, int flags);
02597 
02598 extern void         tcp_unhash(struct sock *sk);
02599 
02600 extern int          tcp_v4_hash_connecting(struct sock *sk);
02601 
02602 
02603 /* From syncookies.c */
02604 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
02605                     struct ip_options *opt);
02606 extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb,
02607                      __u16 *mss);
02608 
02609 /* tcp_output.c */
02610 
02611 extern int tcp_write_xmit(struct sock *, int nonagle);
02612 extern int tcp_retransmit_skb(struct sock *, struct sk_buff *);
02613 extern void tcp_xmit_retransmit_queue(struct sock *);
02614 extern void tcp_simple_retransmit(struct sock *);
02615 
02616 extern void tcp_send_probe0(struct sock *);
02617 extern void tcp_send_partial(struct sock *);
02618 extern int  tcp_write_wakeup(struct sock *);
02619 extern void tcp_send_fin(struct sock *sk);
02620 extern void tcp_send_active_reset(struct sock *sk, int priority);
02621 extern int  tcp_send_synack(struct sock *);
02622 extern int  tcp_transmit_skb(struct sock *, struct sk_buff *);
02623 extern void tcp_send_skb(struct sock *, struct sk_buff *, int force_queue, unsigned mss_now);
02624 extern void tcp_push_one(struct sock *, unsigned mss_now);
02625 extern void tcp_send_ack(struct sock *sk);
02626 extern void tcp_send_delayed_ack(struct sock *sk);
02627 
02628 /* tcp_timer.c */
02629 extern void tcp_init_xmit_timers(struct sock *);
02630 extern void tcp_clear_xmit_timers(struct sock *);
02631 
02632 extern void tcp_delete_keepalive_timer (struct sock *);
02633 extern void tcp_reset_keepalive_timer (struct sock *, unsigned long);
02634 extern int tcp_sync_mss(struct sock *sk, u32 pmtu);
02635 
02636 extern const char timer_bug_msg[];
02637 
02638 /* Read 'sendfile()'-style from a TCP socket */
02639 typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *,
02640                 unsigned int, size_t);
02641 extern int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
02642              sk_read_actor_t recv_actor);
02643 
02644 static __inline void tcp_clear_xmit_timer(struct sock *sk, int what)
02645 {
02646 #if 0
02647     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
02648 
02649     switch (what) {
02650     case TCP_TIME_RETRANS:
02651     case TCP_TIME_PROBE0:
02652         tp->pending = 0;
02653 
02654 #ifdef TCP_CLEAR_TIMERS
02655         if (timer_pending(&tp->retransmit_timer) &&
02656             del_timer(&tp->retransmit_timer))
02657             __sock_put(sk);
02658 #endif
02659         break;
02660     case TCP_TIME_DACK:
02661         tp->ack.blocked = 0;
02662         tp->ack.pending = 0;
02663 
02664 #ifdef TCP_CLEAR_TIMERS
02665         if (timer_pending(&tp->delack_timer) &&
02666             del_timer(&tp->delack_timer))
02667             __sock_put(sk);
02668 #endif
02669         break;
02670     default:
02671         printk(timer_bug_msg);
02672         return;
02673     };
02674 #endif
02675 }
02676 
02677 /*
02678  *  Reset the retransmission timer
02679  */
02680 static __inline void tcp_reset_xmit_timer(struct sock *sk, int what, unsigned long when)
02681 {
02682 #if 0
02683     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
02684 
02685     if (when > TCP_RTO_MAX) {
02686 #ifdef TCP_DEBUG
02687         printk(KERN_DEBUG "reset_xmit_timer sk=%p %d when=0x%lx, caller=%p\n", sk, what, when, current_text_addr());
02688 #endif
02689         when = TCP_RTO_MAX;
02690     }
02691 
02692     switch (what) {
02693     case TCP_TIME_RETRANS:
02694     case TCP_TIME_PROBE0:
02695         tp->pending = what;
02696         tp->timeout = jiffies+when;
02697         if (!mod_timer(&tp->retransmit_timer, tp->timeout))
02698             sock_hold(sk);
02699         break;
02700 
02701     case TCP_TIME_DACK:
02702         tp->ack.pending |= TCP_ACK_TIMER;
02703         tp->ack.timeout = jiffies+when;
02704         if (!mod_timer(&tp->delack_timer, tp->ack.timeout))
02705             sock_hold(sk);
02706         break;
02707 
02708     default:
02709         printk(KERN_DEBUG "bug: unknown timer value\n");
02710     };
02711 #endif
02712 }
02713 
02714 /* Compute the current effective MSS, taking SACKs and IP options,
02715  * and even PMTU discovery events into account.
02716  */
02717 
02718 static __inline unsigned int tcp_current_mss(struct sock *sk)
02719 {
02720 #if 0
02721     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
02722     struct dst_entry *dst = __sk_dst_get(sk);
02723     int mss_now = tp->mss_cache;
02724 
02725     if (dst && dst->pmtu != tp->pmtu_cookie)
02726         mss_now = tcp_sync_mss(sk, dst->pmtu);
02727 
02728     if (tp->eff_sacks)
02729         mss_now -= (TCPOLEN_SACK_BASE_ALIGNED +
02730                 (tp->eff_sacks * TCPOLEN_SACK_PERBLOCK));
02731     return mss_now;
02732 #else
02733   return 0;
02734 #endif
02735 }
02736 
02737 /* Initialize RCV_MSS value.
02738  * RCV_MSS is an our guess about MSS used by the peer.
02739  * We haven't any direct information about the MSS.
02740  * It's better to underestimate the RCV_MSS rather than overestimate.
02741  * Overestimations make us ACKing less frequently than needed.
02742  * Underestimations are more easy to detect and fix by tcp_measure_rcv_mss().
02743  */
02744 
02745 static __inline void tcp_initialize_rcv_mss(struct sock *sk)
02746 {
02747 #if 0
02748     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
02749     unsigned int hint = min(tp->advmss, tp->mss_cache);
02750 
02751     hint = min(hint, tp->rcv_wnd/2);
02752     hint = min(hint, TCP_MIN_RCVMSS);
02753     hint = max(hint, TCP_MIN_MSS);
02754 
02755     tp->ack.rcv_mss = hint;
02756 #endif
02757 }
02758 
02759 static __inline void __tcp_fast_path_on(struct tcp_opt *tp, u32 snd_wnd)
02760 {
02761 #if 0
02762     tp->pred_flags = htonl((tp->tcp_header_len << 26) |
02763                    ntohl(TCP_FLAG_ACK) |
02764                    snd_wnd);
02765 #endif
02766 }
02767 
02768 static __inline void tcp_fast_path_on(struct tcp_opt *tp)
02769 {
02770 #if 0
02771     __tcp_fast_path_on(tp, tp->snd_wnd>>tp->snd_wscale);
02772 #endif
02773 }
02774 
02775 static __inline void tcp_fast_path_check(struct sock *sk, struct tcp_opt *tp)
02776 {
02777 #if 0
02778     if (skb_queue_len(&tp->out_of_order_queue) == 0 &&
02779         tp->rcv_wnd &&
02780         atomic_read(&sk->rmem_alloc) < sk->rcvbuf &&
02781         !tp->urg_data)
02782         tcp_fast_path_on(tp);
02783 #endif
02784 }
02785 
02786 /* Compute the actual receive window we are currently advertising.
02787  * Rcv_nxt can be after the window if our peer push more data
02788  * than the offered window.
02789  */
02790 static __inline u32 tcp_receive_window(struct tcp_opt *tp)
02791 {
02792 #if 0
02793     s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt;
02794 
02795     if (win < 0)
02796         win = 0;
02797     return (u32) win;
02798 #else
02799   return 0;
02800 #endif
02801 }
02802 
02803 /* Choose a new window, without checks for shrinking, and without
02804  * scaling applied to the result.  The caller does these things
02805  * if necessary.  This is a "raw" window selection.
02806  */
02807 extern u32  __tcp_select_window(struct sock *sk);
02808 
02809 /* TCP timestamps are only 32-bits, this causes a slight
02810  * complication on 64-bit systems since we store a snapshot
02811  * of jiffies in the buffer control blocks below.  We decidely
02812  * only use of the low 32-bits of jiffies and hide the ugly
02813  * casts with the following macro.
02814  */
02815 #define tcp_time_stamp      ((__u32)(jiffies))
02816 
02817 /* This is what the send packet queueing engine uses to pass
02818  * TCP per-packet control information to the transmission
02819  * code.  We also store the host-order sequence numbers in
02820  * here too.  This is 36 bytes on 32-bit architectures,
02821  * 40 bytes on 64-bit machines, if this grows please adjust
02822  * skbuff.h:skbuff->cb[xxx] size appropriately.
02823  */
02824 struct tcp_skb_cb {
02825     union {
02826 #if 0
02827         struct inet_skb_parm    h4;
02828 #endif
02829 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
02830         struct inet6_skb_parm   h6;
02831 #endif
02832     } header;   /* For incoming frames      */
02833     __u32       seq;        /* Starting sequence number */
02834     __u32       end_seq;    /* SEQ + FIN + SYN + datalen    */
02835     __u32       when;       /* used to compute rtt's    */
02836     __u8        flags;      /* TCP header flags.        */
02837 
02838     /* NOTE: These must match up to the flags byte in a
02839      *       real TCP header.
02840      */
02841 #define TCPCB_FLAG_FIN      0x01
02842 #define TCPCB_FLAG_SYN      0x02
02843 #define TCPCB_FLAG_RST      0x04
02844 #define TCPCB_FLAG_PSH      0x08
02845 #define TCPCB_FLAG_ACK      0x10
02846 #define TCPCB_FLAG_URG      0x20
02847 #define TCPCB_FLAG_ECE      0x40
02848 #define TCPCB_FLAG_CWR      0x80
02849 
02850     __u8        sacked;     /* State flags for SACK/FACK.   */
02851 #define TCPCB_SACKED_ACKED  0x01    /* SKB ACK'd by a SACK block    */
02852 #define TCPCB_SACKED_RETRANS    0x02    /* SKB retransmitted        */
02853 #define TCPCB_LOST      0x04    /* SKB is lost          */
02854 #define TCPCB_TAGBITS       0x07    /* All tag bits         */
02855 
02856 #define TCPCB_EVER_RETRANS  0x80    /* Ever retransmitted frame */
02857 #define TCPCB_RETRANS       (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS)
02858 
02859 #define TCPCB_URG       0x20    /* Urgent pointer advenced here */
02860 
02861 #define TCPCB_AT_TAIL       (TCPCB_URG)
02862 
02863     __u16       urg_ptr;    /* Valid w/URG flags is set.    */
02864     __u32       ack_seq;    /* Sequence number ACK'd    */
02865 };
02866 
02867 #define TCP_SKB_CB(__skb)   ((struct tcp_skb_cb *)&((__skb)->cb[0]))
02868 
02869 #define for_retrans_queue(skb, sk, tp) \
02870         for (skb = (sk)->write_queue.next;          \
02871              (skb != (tp)->send_head) &&            \
02872              (skb != (struct sk_buff *)&(sk)->write_queue); \
02873              skb=skb->next)
02874 
02875 
02876 //#include <net/tcp_ecn.h>
02877 
02878 
02879 /*
02880  *  Compute minimal free write space needed to queue new packets.
02881  */
02882 static __inline int tcp_min_write_space(struct sock *sk)
02883 {
02884 #if 0
02885     return sk->wmem_queued/2;
02886 #else
02887 return 0;
02888 #endif
02889 }
02890 
02891 static __inline int tcp_wspace(struct sock *sk)
02892 {
02893 #if 0
02894     return sk->sndbuf - sk->wmem_queued;
02895 #else
02896 return 0;
02897 #endif
02898 }
02899 
02900 
02901 /* This determines how many packets are "in the network" to the best
02902  * of our knowledge.  In many cases it is conservative, but where
02903  * detailed information is available from the receiver (via SACK
02904  * blocks etc.) we can make more aggressive calculations.
02905  *
02906  * Use this for decisions involving congestion control, use just
02907  * tp->packets_out to determine if the send queue is empty or not.
02908  *
02909  * Read this equation as:
02910  *
02911  *  "Packets sent once on transmission queue" MINUS
02912  *  "Packets left network, but not honestly ACKed yet" PLUS
02913  *  "Packets fast retransmitted"
02914  */
02915 static __inline unsigned int tcp_packets_in_flight(struct tcp_opt *tp)
02916 {
02917 #if 0
02918     return tp->packets_out - tp->left_out + tp->retrans_out;
02919 #else
02920   return 0;
02921 #endif
02922 }
02923 
02924 /* Recalculate snd_ssthresh, we want to set it to:
02925  *
02926  *  one half the current congestion window, but no
02927  *  less than two segments
02928  */
02929 static __inline __u32 tcp_recalc_ssthresh(struct tcp_opt *tp)
02930 {
02931 #if 0
02932     return max(tp->snd_cwnd >> 1U, 2U);
02933 #else
02934   return 0;
02935 #endif
02936 }
02937 
02938 /* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd.
02939  * The exception is rate halving phase, when cwnd is decreasing towards
02940  * ssthresh.
02941  */
02942 static __inline __u32 tcp_current_ssthresh(struct tcp_opt *tp)
02943 {
02944 #if 0
02945     if ((1<<tp->ca_state)&(TCPF_CA_CWR|TCPF_CA_Recovery))
02946         return tp->snd_ssthresh;
02947     else
02948         return max(tp->snd_ssthresh,
02949                ((tp->snd_cwnd >> 1) +
02950                 (tp->snd_cwnd >> 2)));
02951 #else
02952   return 0;
02953 #endif
02954 }
02955 
02956 static __inline void tcp_sync_left_out(struct tcp_opt *tp)
02957 {
02958 #if 0
02959     if (tp->sack_ok && tp->sacked_out >= tp->packets_out - tp->lost_out)
02960         tp->sacked_out = tp->packets_out - tp->lost_out;
02961     tp->left_out = tp->sacked_out + tp->lost_out;
02962 #endif
02963 }
02964 
02965 extern void tcp_cwnd_application_limited(struct sock *sk);
02966 
02967 /* Congestion window validation. (RFC2861) */
02968 
02969 static __inline void tcp_cwnd_validate(struct sock *sk, struct tcp_opt *tp)
02970 {
02971 #if 0
02972     if (tp->packets_out >= tp->snd_cwnd) {
02973         /* Network is feed fully. */
02974         tp->snd_cwnd_used = 0;
02975         tp->snd_cwnd_stamp = tcp_time_stamp;
02976     } else {
02977         /* Network starves. */
02978         if (tp->packets_out > tp->snd_cwnd_used)
02979             tp->snd_cwnd_used = tp->packets_out;
02980 
02981         if ((s32)(tcp_time_stamp - tp->snd_cwnd_stamp) >= tp->rto)
02982             tcp_cwnd_application_limited(sk);
02983     }
02984 #endif
02985 }
02986 
02987 /* Set slow start threshould and cwnd not falling to slow start */
02988 static __inline void __tcp_enter_cwr(struct tcp_opt *tp)
02989 {
02990 #if 0
02991     tp->undo_marker = 0;
02992     tp->snd_ssthresh = tcp_recalc_ssthresh(tp);
02993     tp->snd_cwnd = min(tp->snd_cwnd,
02994                tcp_packets_in_flight(tp) + 1U);
02995     tp->snd_cwnd_cnt = 0;
02996     tp->high_seq = tp->snd_nxt;
02997     tp->snd_cwnd_stamp = tcp_time_stamp;
02998     TCP_ECN_queue_cwr(tp);
02999 #endif
03000 }
03001 
03002 static __inline void tcp_enter_cwr(struct tcp_opt *tp)
03003 {
03004 #if 0
03005     tp->prior_ssthresh = 0;
03006     if (tp->ca_state < TCP_CA_CWR) {
03007         __tcp_enter_cwr(tp);
03008         tp->ca_state = TCP_CA_CWR;
03009     }
03010 #endif
03011 }
03012 
03013 extern __u32 tcp_init_cwnd(struct tcp_opt *tp);
03014 
03015 /* Slow start with delack produces 3 packets of burst, so that
03016  * it is safe "de facto".
03017  */
03018 static __inline __u32 tcp_max_burst(struct tcp_opt *tp)
03019 {
03020     return 3;
03021 }
03022 
03023 static __inline__ int tcp_minshall_check(struct tcp_opt *tp)
03024 {
03025 #if 0
03026     return after(tp->snd_sml,tp->snd_una) &&
03027         !after(tp->snd_sml, tp->snd_nxt);
03028 #else
03029   return 0;
03030 #endif
03031 }
03032 
03033 static __inline void tcp_minshall_update(struct tcp_opt *tp, int mss, struct sk_buff *skb)
03034 {
03035 #if 0
03036     if (skb->len < mss)
03037         tp->snd_sml = TCP_SKB_CB(skb)->end_seq;
03038 #endif
03039 }
03040 
03041 /* Return 0, if packet can be sent now without violation Nagle's rules:
03042    1. It is full sized.
03043    2. Or it contains FIN.
03044    3. Or TCP_NODELAY was set.
03045    4. Or TCP_CORK is not set, and all sent packets are ACKed.
03046       With Minshall's modification: all sent small packets are ACKed.
03047  */
03048 
03049 static __inline int
03050 tcp_nagle_check(struct tcp_opt *tp, struct sk_buff *skb, unsigned mss_now, int nonagle)
03051 {
03052 #if 0
03053     return (skb->len < mss_now &&
03054         !(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) &&
03055         (nonagle == 2 ||
03056          (!nonagle &&
03057           tp->packets_out &&
03058           tcp_minshall_check(tp))));
03059 #else
03060   return 0;
03061 #endif
03062 }
03063 
03064 /* This checks if the data bearing packet SKB (usually tp->send_head)
03065  * should be put on the wire right now.
03066  */
03067 static __inline int tcp_snd_test(struct tcp_opt *tp, struct sk_buff *skb,
03068                    unsigned cur_mss, int nonagle)
03069 {
03070 #if 0
03071     /*  RFC 1122 - section 4.2.3.4
03072      *
03073      *  We must queue if
03074      *
03075      *  a) The right edge of this frame exceeds the window
03076      *  b) There are packets in flight and we have a small segment
03077      *     [SWS avoidance and Nagle algorithm]
03078      *     (part of SWS is done on packetization)
03079      *     Minshall version sounds: there are no _small_
03080      *     segments in flight. (tcp_nagle_check)
03081      *  c) We have too many packets 'in flight'
03082      *
03083      *  Don't use the nagle rule for urgent data (or
03084      *  for the final FIN -DaveM).
03085      *
03086      *  Also, Nagle rule does not apply to frames, which
03087      *  sit in the middle of queue (they have no chances
03088      *  to get new data) and if room at tail of skb is
03089      *  not enough to save something seriously (<32 for now).
03090      */
03091 
03092     /* Don't be strict about the congestion window for the
03093      * final FIN frame.  -DaveM
03094      */
03095     return ((nonagle==1 || tp->urg_mode
03096          || !tcp_nagle_check(tp, skb, cur_mss, nonagle)) &&
03097         ((tcp_packets_in_flight(tp) < tp->snd_cwnd) ||
03098          (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN)) &&
03099         !after(TCP_SKB_CB(skb)->end_seq, tp->snd_una + tp->snd_wnd));
03100 #else
03101   return 0;
03102 #endif
03103 }
03104 
03105 static __inline void tcp_check_probe_timer(struct sock *sk, struct tcp_opt *tp)
03106 {
03107 #if 0
03108     if (!tp->packets_out && !tp->pending)
03109         tcp_reset_xmit_timer(sk, TCP_TIME_PROBE0, tp->rto);
03110 #endif
03111 }
03112 
03113 static __inline int tcp_skb_is_last(struct sock *sk, struct sk_buff *skb)
03114 {
03115 #if 0
03116     return (skb->next == (struct sk_buff*)&sk->write_queue);
03117 #else
03118   return 0;
03119 #endif
03120 }
03121 
03122 /* Push out any pending frames which were held back due to
03123  * TCP_CORK or attempt at coalescing tiny packets.
03124  * The socket must be locked by the caller.
03125  */
03126 static __inline void __tcp_push_pending_frames(struct sock *sk,
03127                          struct tcp_opt *tp,
03128                          unsigned cur_mss,
03129                          int nonagle)
03130 {
03131 #if 0
03132     struct sk_buff *skb = tp->send_head;
03133 
03134     if (skb) {
03135         if (!tcp_skb_is_last(sk, skb))
03136             nonagle = 1;
03137         if (!tcp_snd_test(tp, skb, cur_mss, nonagle) ||
03138             tcp_write_xmit(sk, nonagle))
03139             tcp_check_probe_timer(sk, tp);
03140     }
03141     tcp_cwnd_validate(sk, tp);
03142 #endif
03143 }
03144 
03145 static __inline void tcp_push_pending_frames(struct sock *sk,
03146                            struct tcp_opt *tp)
03147 {
03148 #if 0
03149     __tcp_push_pending_frames(sk, tp, tcp_current_mss(sk), tp->nonagle);
03150 #endif
03151 }
03152 
03153 static __inline int tcp_may_send_now(struct sock *sk, struct tcp_opt *tp)
03154 {
03155 #if 0
03156     struct sk_buff *skb = tp->send_head;
03157 
03158     return (skb &&
03159         tcp_snd_test(tp, skb, tcp_current_mss(sk),
03160                  tcp_skb_is_last(sk, skb) ? 1 : tp->nonagle));
03161 #else
03162   return 0;
03163 #endif
03164 }
03165 
03166 static __inline void tcp_init_wl(struct tcp_opt *tp, u32 ack, u32 seq)
03167 {
03168 #if 0
03169     tp->snd_wl1 = seq;
03170 #endif
03171 }
03172 
03173 static __inline void tcp_update_wl(struct tcp_opt *tp, u32 ack, u32 seq)
03174 {
03175 #if 0
03176     tp->snd_wl1 = seq;
03177 #endif
03178 }
03179 
03180 extern void         tcp_destroy_sock(struct sock *sk);
03181 
03182 
03183 /*
03184  * Calculate(/check) TCP checksum
03185  */
03186 static __inline u16 tcp_v4_check(struct tcphdr *th, int len,
03187                    unsigned long saddr, unsigned long daddr,
03188                    unsigned long base)
03189 {
03190 #if 0
03191     return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base);
03192 #else
03193   return 0;
03194 #endif
03195 }
03196 
03197 static __inline int __tcp_checksum_complete(struct sk_buff *skb)
03198 {
03199 #if 0
03200     return (unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum));
03201 #else
03202   return 0;
03203 #endif
03204 }
03205 
03206 static __inline int tcp_checksum_complete(struct sk_buff *skb)
03207 {
03208 #if 0
03209     return skb->ip_summed != CHECKSUM_UNNECESSARY &&
03210         __tcp_checksum_complete(skb);
03211 #else
03212   return 0;
03213 #endif
03214 }
03215 
03216 /* Prequeue for VJ style copy to user, combined with checksumming. */
03217 
03218 static __inline void tcp_prequeue_init(struct tcp_opt *tp)
03219 {
03220 #if 0
03221     tp->ucopy.task = NULL;
03222     tp->ucopy.len = 0;
03223     tp->ucopy.memory = 0;
03224     skb_queue_head_init(&tp->ucopy.prequeue);
03225 #endif
03226 }
03227 
03228 /* Packet is added to VJ-style prequeue for processing in process
03229  * context, if a reader task is waiting. Apparently, this exciting
03230  * idea (VJ's mail "Re: query about TCP header on tcp-ip" of 07 Sep 93)
03231  * failed somewhere. Latency? Burstiness? Well, at least now we will
03232  * see, why it failed. 8)8)               --ANK
03233  *
03234  * NOTE: is this not too big to inline?
03235  */
03236 static __inline int tcp_prequeue(struct sock *sk, struct sk_buff *skb)
03237 {
03238 #if 0
03239     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
03240 
03241     if (tp->ucopy.task) {
03242         __skb_queue_tail(&tp->ucopy.prequeue, skb);
03243         tp->ucopy.memory += skb->truesize;
03244         if (tp->ucopy.memory > sk->rcvbuf) {
03245             struct sk_buff *skb1;
03246 
03247             if (sk->lock.users)
03248                 out_of_line_bug();
03249 
03250             while ((skb1 = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) {
03251                 sk->backlog_rcv(sk, skb1);
03252                 NET_INC_STATS_BH(TCPPrequeueDropped);
03253             }
03254 
03255             tp->ucopy.memory = 0;
03256         } else if (skb_queue_len(&tp->ucopy.prequeue) == 1) {
03257             wake_up_interruptible(sk->sleep);
03258             if (!tcp_ack_scheduled(tp))
03259                 tcp_reset_xmit_timer(sk, TCP_TIME_DACK, (3*TCP_RTO_MIN)/4);
03260         }
03261         return 1;
03262     }
03263     return 0;
03264 #else
03265   return 0;
03266 #endif
03267 }
03268 
03269 
03270 #undef STATE_TRACE
03271 
03272 #ifdef STATE_TRACE
03273 static char *statename[]={
03274     "Unused","Established","Syn Sent","Syn Recv",
03275     "Fin Wait 1","Fin Wait 2","Time Wait", "Close",
03276     "Close Wait","Last ACK","Listen","Closing"
03277 };
03278 #endif
03279 
03280 static __inline void tcp_set_state(struct sock *sk, int state)
03281 {
03282 #if 0
03283     int oldstate = sk->state;
03284 
03285     switch (state) {
03286     case TCP_ESTABLISHED:
03287         if (oldstate != TCP_ESTABLISHED)
03288             TCP_INC_STATS(TcpCurrEstab);
03289         break;
03290 
03291     case TCP_CLOSE:
03292         sk->prot->unhash(sk);
03293         if (sk->prev && !(sk->userlocks&SOCK_BINDPORT_LOCK))
03294             tcp_put_port(sk);
03295         /* fall through */
03296     default:
03297         if (oldstate==TCP_ESTABLISHED)
03298             tcp_statistics[smp_processor_id()*2+!in_softirq()].TcpCurrEstab--;
03299     }
03300 
03301     /* Change state AFTER socket is unhashed to avoid closed
03302      * socket sitting in hash tables.
03303      */
03304     sk->state = state;
03305 
03306 #ifdef STATE_TRACE
03307     SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]);
03308 #endif
03309 #endif
03310 }
03311 
03312 static __inline void tcp_done(struct sock *sk)
03313 {
03314 #if 0
03315     tcp_set_state(sk, TCP_CLOSE);
03316     tcp_clear_xmit_timers(sk);
03317 
03318     sk->shutdown = SHUTDOWN_MASK;
03319 
03320     if (!sk->dead)
03321         sk->state_change(sk);
03322     else
03323         tcp_destroy_sock(sk);
03324 #endif
03325 }
03326 
03327 static __inline void tcp_sack_reset(struct tcp_opt *tp)
03328 {
03329 #if 0
03330     tp->dsack = 0;
03331     tp->eff_sacks = 0;
03332     tp->num_sacks = 0;
03333 #endif
03334 }
03335 
03336 static __inline void tcp_build_and_update_options(__u32 *ptr, struct tcp_opt *tp, __u32 tstamp)
03337 {
03338 #if 0
03339     if (tp->tstamp_ok) {
03340         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) |
03341                       (TCPOPT_NOP << 16) |
03342                       (TCPOPT_TIMESTAMP << 8) |
03343                       TCPOLEN_TIMESTAMP);
03344         *ptr++ = htonl(tstamp);
03345         *ptr++ = htonl(tp->ts_recent);
03346     }
03347     if (tp->eff_sacks) {
03348         struct tcp_sack_block *sp = tp->dsack ? tp->duplicate_sack : tp->selective_acks;
03349         int this_sack;
03350 
03351         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) |
03352                       (TCPOPT_NOP << 16) |
03353                       (TCPOPT_SACK << 8) |
03354                       (TCPOLEN_SACK_BASE +
03355                        (tp->eff_sacks * TCPOLEN_SACK_PERBLOCK)));
03356         for(this_sack = 0; this_sack < tp->eff_sacks; this_sack++) {
03357             *ptr++ = htonl(sp[this_sack].start_seq);
03358             *ptr++ = htonl(sp[this_sack].end_seq);
03359         }
03360         if (tp->dsack) {
03361             tp->dsack = 0;
03362             tp->eff_sacks--;
03363         }
03364     }
03365 #endif
03366 }
03367 
03368 /* Construct a tcp options header for a SYN or SYN_ACK packet.
03369  * If this is every changed make sure to change the definition of
03370  * MAX_SYN_SIZE to match the new maximum number of options that you
03371  * can generate.
03372  */
03373 static __inline void tcp_syn_build_options(__u32 *ptr, int mss, int ts, int sack,
03374                          int offer_wscale, int wscale, __u32 tstamp, __u32 ts_recent)
03375 {
03376 #if 0
03377     /* We always get an MSS option.
03378      * The option bytes which will be seen in normal data
03379      * packets should timestamps be used, must be in the MSS
03380      * advertised.  But we subtract them from tp->mss_cache so
03381      * that calculations in tcp_sendmsg are simpler etc.
03382      * So account for this fact here if necessary.  If we
03383      * don't do this correctly, as a receiver we won't
03384      * recognize data packets as being full sized when we
03385      * should, and thus we won't abide by the delayed ACK
03386      * rules correctly.
03387      * SACKs don't matter, we never delay an ACK when we
03388      * have any of those going out.
03389      */
03390     *ptr++ = htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) | mss);
03391     if (ts) {
03392         if(sack)
03393             *ptr++ = __constant_htonl((TCPOPT_SACK_PERM << 24) | (TCPOLEN_SACK_PERM << 16) |
03394                           (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
03395         else
03396             *ptr++ = __constant_htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
03397                           (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
03398         *ptr++ = htonl(tstamp);     /* TSVAL */
03399         *ptr++ = htonl(ts_recent);  /* TSECR */
03400     } else if(sack)
03401         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
03402                       (TCPOPT_SACK_PERM << 8) | TCPOLEN_SACK_PERM);
03403     if (offer_wscale)
03404         *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_WINDOW << 16) | (TCPOLEN_WINDOW << 8) | (wscale));
03405 #endif
03406 }
03407 
03408 /* Determine a window scaling and initial window to offer.
03409  * Based on the assumption that the given amount of space
03410  * will be offered. Store the results in the tp structure.
03411  * NOTE: for smooth operation initial space offering should
03412  * be a multiple of mss if possible. We assume here that mss >= 1.
03413  * This MUST be enforced by all callers.
03414  */
03415 static __inline void tcp_select_initial_window(int __space, __u32 mss,
03416     __u32 *rcv_wnd,
03417     __u32 *window_clamp,
03418     int wscale_ok,
03419     __u8 *rcv_wscale)
03420 {
03421 #if 0
03422     unsigned int space = (__space < 0 ? 0 : __space);
03423 
03424     /* If no clamp set the clamp to the max possible scaled window */
03425     if (*window_clamp == 0)
03426         (*window_clamp) = (65535 << 14);
03427     space = min(*window_clamp, space);
03428 
03429     /* Quantize space offering to a multiple of mss if possible. */
03430     if (space > mss)
03431         space = (space / mss) * mss;
03432 
03433     /* NOTE: offering an initial window larger than 32767
03434      * will break some buggy TCP stacks. We try to be nice.
03435      * If we are not window scaling, then this truncates
03436      * our initial window offering to 32k. There should also
03437      * be a sysctl option to stop being nice.
03438      */
03439     (*rcv_wnd) = min(space, MAX_TCP_WINDOW);
03440     (*rcv_wscale) = 0;
03441     if (wscale_ok) {
03442         /* See RFC1323 for an explanation of the limit to 14 */
03443         while (space > 65535 && (*rcv_wscale) < 14) {
03444             space >>= 1;
03445             (*rcv_wscale)++;
03446         }
03447         if (*rcv_wscale && sysctl_tcp_app_win && space>=mss &&
03448             space - max((space>>sysctl_tcp_app_win), mss>>*rcv_wscale) < 65536/2)
03449             (*rcv_wscale)--;
03450     }
03451 
03452     /* Set initial window to value enough for senders,
03453      * following RFC1414. Senders, not following this RFC,
03454      * will be satisfied with 2.
03455      */
03456     if (mss > (1<<*rcv_wscale)) {
03457         int init_cwnd = 4;
03458         if (mss > 1460*3)
03459             init_cwnd = 2;
03460         else if (mss > 1460)
03461             init_cwnd = 3;
03462         if (*rcv_wnd > init_cwnd*mss)
03463             *rcv_wnd = init_cwnd*mss;
03464     }
03465     /* Set the clamp no higher than max representable value */
03466     (*window_clamp) = min(65535U << (*rcv_wscale), *window_clamp);
03467 #endif
03468 }
03469 
03470 static __inline int tcp_win_from_space(int space)
03471 {
03472 #if 0
03473     return sysctl_tcp_adv_win_scale<=0 ?
03474         (space>>(-sysctl_tcp_adv_win_scale)) :
03475         space - (space>>sysctl_tcp_adv_win_scale);
03476 #else
03477   return 0;
03478 #endif
03479 }
03480 
03481 /* Note: caller must be prepared to deal with negative returns */
03482 static __inline int tcp_space(struct sock *sk)
03483 {
03484 #if 0
03485     return tcp_win_from_space(sk->rcvbuf - atomic_read(&sk->rmem_alloc));
03486 #else
03487   return 0;
03488 #endif
03489 }
03490 
03491 static __inline int tcp_full_space( struct sock *sk)
03492 {
03493 #if 0
03494     return tcp_win_from_space(sk->rcvbuf);
03495 #else
03496   return 0;
03497 #endif
03498 }
03499 
03500 static __inline void tcp_acceptq_removed(struct sock *sk)
03501 {
03502 #if 0
03503     sk->ack_backlog--;
03504 #endif
03505 }
03506 
03507 static __inline void tcp_acceptq_added(struct sock *sk)
03508 {
03509 #if 0
03510     sk->ack_backlog++;
03511 #endif
03512 }
03513 
03514 static __inline int tcp_acceptq_is_full(struct sock *sk)
03515 {
03516 #if 0
03517     return sk->ack_backlog > sk->max_ack_backlog;
03518 #else
03519   return 0;
03520 #endif
03521 }
03522 
03523 static __inline void tcp_acceptq_queue(struct sock *sk, struct open_request *req,
03524                      struct sock *child)
03525 {
03526 #if 0
03527     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
03528 
03529     req->sk = child;
03530     tcp_acceptq_added(sk);
03531 
03532     if (!tp->accept_queue_tail) {
03533         tp->accept_queue = req;
03534     } else {
03535         tp->accept_queue_tail->dl_next = req;
03536     }
03537     tp->accept_queue_tail = req;
03538     req->dl_next = NULL;
03539 #endif
03540 }
03541 
03542 struct tcp_listen_opt
03543 {
03544     u8          max_qlen_log;   /* log_2 of maximal queued SYNs */
03545     int         qlen;
03546     int         qlen_young;
03547     int         clock_hand;
03548     struct open_request *syn_table[TCP_SYNQ_HSIZE];
03549 };
03550 
03551 static __inline void
03552 tcp_synq_removed(struct sock *sk, struct open_request *req)
03553 {
03554 #if 0
03555     struct tcp_listen_opt *lopt = sk->tp_pinfo.af_tcp.listen_opt;
03556 
03557     if (--lopt->qlen == 0)
03558         tcp_delete_keepalive_timer(sk);
03559     if (req->retrans == 0)
03560         lopt->qlen_young--;
03561 #endif
03562 }
03563 
03564 static __inline void tcp_synq_added(struct sock *sk)
03565 {
03566 #if 0
03567     struct tcp_listen_opt *lopt = sk->tp_pinfo.af_tcp.listen_opt;
03568 
03569     if (lopt->qlen++ == 0)
03570         tcp_reset_keepalive_timer(sk, TCP_TIMEOUT_INIT);
03571     lopt->qlen_young++;
03572 #endif
03573 }
03574 
03575 static __inline int tcp_synq_len(struct sock *sk)
03576 {
03577 #if 0
03578     return sk->tp_pinfo.af_tcp.listen_opt->qlen;
03579 #else
03580   return 0;
03581 #endif
03582 }
03583 
03584 static __inline int tcp_synq_young(struct sock *sk)
03585 {
03586 #if 0
03587     return sk->tp_pinfo.af_tcp.listen_opt->qlen_young;
03588 #else
03589   return 0;
03590 #endif
03591 }
03592 
03593 static __inline int tcp_synq_is_full(struct sock *sk)
03594 {
03595 #if 0
03596     return tcp_synq_len(sk)>>sk->tp_pinfo.af_tcp.listen_opt->max_qlen_log;
03597 #else
03598   return 0;
03599 #endif
03600 }
03601 
03602 static __inline void tcp_synq_unlink(struct tcp_opt *tp, struct open_request *req,
03603                        struct open_request **prev)
03604 {
03605 #if 0
03606     write_lock(&tp->syn_wait_lock);
03607     *prev = req->dl_next;
03608     write_unlock(&tp->syn_wait_lock);
03609 #endif
03610 }
03611 
03612 static __inline void tcp_synq_drop(struct sock *sk, struct open_request *req,
03613                      struct open_request **prev)
03614 {
03615 #if 0
03616     tcp_synq_unlink(&sk->tp_pinfo.af_tcp, req, prev);
03617     tcp_synq_removed(sk, req);
03618     tcp_openreq_free(req);
03619 #endif
03620 }
03621 
03622 static __inline void tcp_openreq_init(struct open_request *req,
03623                     struct tcp_opt *tp,
03624                     struct sk_buff *skb)
03625 {
03626 #if 0
03627     req->rcv_wnd = 0;       /* So that tcp_send_synack() knows! */
03628     req->rcv_isn = TCP_SKB_CB(skb)->seq;
03629     req->mss = tp->mss_clamp;
03630     req->ts_recent = tp->saw_tstamp ? tp->rcv_tsval : 0;
03631     req->tstamp_ok = tp->tstamp_ok;
03632     req->sack_ok = tp->sack_ok;
03633     req->snd_wscale = tp->snd_wscale;
03634     req->wscale_ok = tp->wscale_ok;
03635     req->acked = 0;
03636     req->ecn_ok = 0;
03637     req->rmt_port = skb->h.th->source;
03638 #endif
03639 }
03640 
03641 #define TCP_MEM_QUANTUM ((int)PAGE_SIZE)
03642 
03643 static __inline void tcp_free_skb(struct sock *sk, struct sk_buff *skb)
03644 {
03645 #if 0
03646     sk->tp_pinfo.af_tcp.queue_shrunk = 1;
03647     sk->wmem_queued -= skb->truesize;
03648     sk->forward_alloc += skb->truesize;
03649     __kfree_skb(skb);
03650 #endif
03651 }
03652 
03653 static __inline void tcp_charge_skb(struct sock *sk, struct sk_buff *skb)
03654 {
03655 #if 0
03656     sk->wmem_queued += skb->truesize;
03657     sk->forward_alloc -= skb->truesize;
03658 #endif
03659 }
03660 
03661 extern void __tcp_mem_reclaim(struct sock *sk);
03662 extern int tcp_mem_schedule(struct sock *sk, int size, int kind);
03663 
03664 static __inline void tcp_mem_reclaim(struct sock *sk)
03665 {
03666 #if 0
03667     if (sk->forward_alloc >= TCP_MEM_QUANTUM)
03668         __tcp_mem_reclaim(sk);
03669 #endif
03670 }
03671 
03672 static __inline void tcp_enter_memory_pressure(void)
03673 {
03674 #if 0
03675     if (!tcp_memory_pressure) {
03676         NET_INC_STATS(TCPMemoryPressures);
03677         tcp_memory_pressure = 1;
03678     }
03679 #endif
03680 }
03681 
03682 static __inline void tcp_moderate_sndbuf(struct sock *sk)
03683 {
03684 #if 0
03685     if (!(sk->userlocks&SOCK_SNDBUF_LOCK)) {
03686         sk->sndbuf = min(sk->sndbuf, sk->wmem_queued/2);
03687         sk->sndbuf = max(sk->sndbuf, SOCK_MIN_SNDBUF);
03688     }
03689 #endif
03690 }
03691 
03692 static __inline struct sk_buff *tcp_alloc_pskb(struct sock *sk, int size, int mem, int gfp)
03693 {
03694 #if 0
03695     struct sk_buff *skb = alloc_skb(size+MAX_TCP_HEADER, gfp);
03696 
03697     if (skb) {
03698         skb->truesize += mem;
03699         if (sk->forward_alloc >= (int)skb->truesize ||
03700             tcp_mem_schedule(sk, skb->truesize, 0)) {
03701             skb_reserve(skb, MAX_TCP_HEADER);
03702             return skb;
03703         }
03704         __kfree_skb(skb);
03705     } else {
03706         tcp_enter_memory_pressure();
03707         tcp_moderate_sndbuf(sk);
03708     }
03709     return NULL;
03710 #else
03711   return NULL;
03712 #endif
03713 }
03714 
03715 static __inline struct sk_buff *tcp_alloc_skb(struct sock *sk, int size, int gfp)
03716 {
03717 #if 0
03718     return tcp_alloc_pskb(sk, size, 0, gfp);
03719 #else
03720   return NULL;
03721 #endif
03722 }
03723 
03724 static __inline struct page * tcp_alloc_page(struct sock *sk)
03725 {
03726 #if 0
03727     if (sk->forward_alloc >= (int)PAGE_SIZE ||
03728         tcp_mem_schedule(sk, PAGE_SIZE, 0)) {
03729         struct page *page = alloc_pages(sk->allocation, 0);
03730         if (page)
03731             return page;
03732     }
03733     tcp_enter_memory_pressure();
03734     tcp_moderate_sndbuf(sk);
03735     return NULL;
03736 #else
03737   return NULL;
03738 #endif
03739 }
03740 
03741 static __inline void tcp_writequeue_purge(struct sock *sk)
03742 {
03743 #if 0
03744     struct sk_buff *skb;
03745 
03746     while ((skb = __skb_dequeue(&sk->write_queue)) != NULL)
03747         tcp_free_skb(sk, skb);
03748     tcp_mem_reclaim(sk);
03749 #endif
03750 }
03751 
03752 extern void tcp_rfree(struct sk_buff *skb);
03753 
03754 static __inline void tcp_set_owner_r(struct sk_buff *skb, struct sock *sk)
03755 {
03756 #if 0
03757     skb->sk = sk;
03758     skb->destructor = tcp_rfree;
03759     atomic_add(skb->truesize, &sk->rmem_alloc);
03760     sk->forward_alloc -= skb->truesize;
03761 #endif
03762 }
03763 
03764 extern void tcp_listen_wlock(void);
03765 
03766 /* - We may sleep inside this lock.
03767  * - If sleeping is not required (or called from BH),
03768  *   use plain read_(un)lock(&tcp_lhash_lock).
03769  */
03770 
03771 static __inline void tcp_listen_lock(void)
03772 {
03773 #if 0
03774     /* read_lock synchronizes to candidates to writers */
03775     read_lock(&tcp_lhash_lock);
03776     atomic_inc(&tcp_lhash_users);
03777     read_unlock(&tcp_lhash_lock);
03778 #endif
03779 }
03780 
03781 static __inline void tcp_listen_unlock(void)
03782 {
03783 #if 0
03784     if (atomic_dec_and_test(&tcp_lhash_users))
03785         wake_up(&tcp_lhash_wait);
03786 #endif
03787 }
03788 
03789 static __inline int keepalive_intvl_when(struct tcp_opt *tp)
03790 {
03791 #if 0
03792     return tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl;
03793 #else
03794   return 0;
03795 #endif
03796 }
03797 
03798 static __inline int keepalive_time_when(struct tcp_opt *tp)
03799 {
03800 #if 0
03801     return tp->keepalive_time ? : sysctl_tcp_keepalive_time;
03802 #else
03803   return 0;
03804 #endif
03805 }
03806 
03807 static __inline int tcp_fin_time(struct tcp_opt *tp)
03808 {
03809 #if 0
03810     int fin_timeout = tp->linger2 ? : sysctl_tcp_fin_timeout;
03811 
03812     if (fin_timeout < (tp->rto<<2) - (tp->rto>>1))
03813         fin_timeout = (tp->rto<<2) - (tp->rto>>1);
03814 
03815     return fin_timeout;
03816 #else
03817   return 0;
03818 #endif
03819 }
03820 
03821 static __inline int tcp_paws_check(struct tcp_opt *tp, int rst)
03822 {
03823 #if 0
03824     if ((s32)(tp->rcv_tsval - tp->ts_recent) >= 0)
03825         return 0;
03826     if (xtime.tv_sec >= tp->ts_recent_stamp + TCP_PAWS_24DAYS)
03827         return 0;
03828 
03829     /* RST segments are not recommended to carry timestamp,
03830        and, if they do, it is recommended to ignore PAWS because
03831        "their cleanup function should take precedence over timestamps."
03832        Certainly, it is mistake. It is necessary to understand the reasons
03833        of this constraint to relax it: if peer reboots, clock may go
03834        out-of-sync and half-open connections will not be reset.
03835        Actually, the problem would be not existing if all
03836        the implementations followed draft about maintaining clock
03837        via reboots. Linux-2.2 DOES NOT!
03838 
03839        However, we can relax time bounds for RST segments to MSL.
03840      */
03841     if (rst && xtime.tv_sec >= tp->ts_recent_stamp + TCP_PAWS_MSL)
03842         return 0;
03843     return 1;
03844 #else
03845   return 0;
03846 #endif
03847 }
03848 
03849 #define TCP_CHECK_TIMER(sk) do { } while (0)
03850 
03851 #endif /* __TCPCORE_H */
03852 
03853 
03854 //
03855 #endif

Generated on Fri May 25 2012 04:26:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.