Home | History | Annotate | Line # | Download | only in netinet
tcp_vtw.h revision 1.3.2.2
      1  1.3.2.2  rmind /*
      2  1.3.2.2  rmind  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      3  1.3.2.2  rmind  * All rights reserved.
      4  1.3.2.2  rmind  *
      5  1.3.2.2  rmind  * This code is derived from software contributed to The NetBSD Foundation
      6  1.3.2.2  rmind  * by Coyote Point Systems, Inc.
      7  1.3.2.2  rmind  *
      8  1.3.2.2  rmind  * Redistribution and use in source and binary forms, with or without
      9  1.3.2.2  rmind  * modification, are permitted provided that the following conditions
     10  1.3.2.2  rmind  * are met:
     11  1.3.2.2  rmind  * 1. Redistributions of source code must retain the above copyright
     12  1.3.2.2  rmind  *    notice, this list of conditions and the following disclaimer.
     13  1.3.2.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.3.2.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     15  1.3.2.2  rmind  *    documentation and/or other materials provided with the distribution.
     16  1.3.2.2  rmind  *
     17  1.3.2.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  1.3.2.2  rmind  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.3.2.2  rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  1.3.2.2  rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  1.3.2.2  rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.3.2.2  rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.3.2.2  rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.3.2.2  rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.3.2.2  rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.3.2.2  rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.3.2.2  rmind  * POSSIBILITY OF SUCH DAMAGE.
     28  1.3.2.2  rmind  */
     29  1.3.2.2  rmind 
     30  1.3.2.2  rmind /*
     31  1.3.2.2  rmind  * Vestigial time-wait.
     32  1.3.2.2  rmind  *
     33  1.3.2.2  rmind  * This implementation uses cache-efficient techniques, which will
     34  1.3.2.2  rmind  * appear somewhat peculiar.  The main philosophy is to optimise the
     35  1.3.2.2  rmind  * amount of information available within a cache line.  Cache miss is
     36  1.3.2.2  rmind  * expensive.  So we employ ad-hoc techniques to pull a series of
     37  1.3.2.2  rmind  * linked-list follows into a cache line.  One cache line, multiple
     38  1.3.2.2  rmind  * linked-list equivalents.
     39  1.3.2.2  rmind  *
     40  1.3.2.2  rmind  * One such ad-hoc technique is fat pointers.  Additional degrees of
     41  1.3.2.2  rmind  * ad-hoqueness result from having to hand tune it for pointer size
     42  1.3.2.2  rmind  * and for cache line size.
     43  1.3.2.2  rmind  *
     44  1.3.2.2  rmind  * The 'fat pointer' approach aggregates, for x86_32, 15 linked-list
     45  1.3.2.2  rmind  * data structures into one cache line.  The additional 32 bits in the
     46  1.3.2.2  rmind  * cache line are used for linking fat pointers, and for
     47  1.3.2.2  rmind  * allocation/bookkeeping.
     48  1.3.2.2  rmind  *
     49  1.3.2.2  rmind  * The 15 32-bit tags encode the pointers to the linked list elements,
     50  1.3.2.2  rmind  * and also encode the results of a search comparison.
     51  1.3.2.2  rmind  *
     52  1.3.2.2  rmind  * First, some more assumptions/restrictions.
     53  1.3.2.2  rmind  *
     54  1.3.2.2  rmind  * All the fat pointers are from a contiguous allocation arena.  Thus,
     55  1.3.2.2  rmind  * we can refer to them by offset from a base, not as full pointers.
     56  1.3.2.2  rmind  *
     57  1.3.2.2  rmind  * All the linked list data elements are also from a contiguous
     58  1.3.2.2  rmind  * allocation arena, again so that we can refer to them as offset from
     59  1.3.2.2  rmind  * a base.
     60  1.3.2.2  rmind  *
     61  1.3.2.2  rmind  * In order to add a data element to a fat pointer, a key value is
     62  1.3.2.2  rmind  * computed, based on unique data within the data element.  It is the
     63  1.3.2.2  rmind  * linear searching of the linked lists of these elements based on
     64  1.3.2.2  rmind  * these unique data that are being optimised here.
     65  1.3.2.2  rmind  *
     66  1.3.2.2  rmind  * Lets call the function that computes the key k(e), where e is the
     67  1.3.2.2  rmind  * data element.  In this example, k(e) returns 32-bits.
     68  1.3.2.2  rmind  *
     69  1.3.2.2  rmind  * Consider a set E (say of order 15) of data elements.  Let K be
     70  1.3.2.2  rmind  * the set of the k(e) for e in E.
     71  1.3.2.2  rmind  *
     72  1.3.2.2  rmind  * Let O be the set of the offsets from the base of the data elements in E.
     73  1.3.2.2  rmind  *
     74  1.3.2.2  rmind  * For each x in K, for each matching o in O, let t be x ^ o.  These
     75  1.3.2.2  rmind  * are the tags. (More or less).
     76  1.3.2.2  rmind  *
     77  1.3.2.2  rmind  * In order to search all the data elements in E, we compute the
     78  1.3.2.2  rmind  * search key, and one at a time, XOR the key into the tags.  If any
     79  1.3.2.2  rmind  * result is a valid data element index, we have a possible match.  If
     80  1.3.2.2  rmind  * not, there is no match.
     81  1.3.2.2  rmind  *
     82  1.3.2.2  rmind  * The no-match cases mean we do not have to de-reference the pointer
     83  1.3.2.2  rmind  * to the data element in question.  We save cache miss penalty and
     84  1.3.2.2  rmind  * cache load decreases.  Only in the case of a valid looking data
     85  1.3.2.2  rmind  * element index, do we have to look closer.
     86  1.3.2.2  rmind  *
     87  1.3.2.2  rmind  * Thus, in the absence of false positives, 15 data elements can be
     88  1.3.2.2  rmind  * searched with one cache line fill, as opposed to 15 cache line
     89  1.3.2.2  rmind  * fills for the usual implementation.
     90  1.3.2.2  rmind  *
     91  1.3.2.2  rmind  * The vestigial time waits (vtw_t), the data elements in the above, are
     92  1.3.2.2  rmind  * searched by faddr, fport, laddr, lport.  The key is a function of
     93  1.3.2.2  rmind  * these values.
     94  1.3.2.2  rmind  *
     95  1.3.2.2  rmind  * We hash these keys into the traditional hash chains to reduce the
     96  1.3.2.2  rmind  * search time, and use fat pointers to reduce the cache impacts of
     97  1.3.2.2  rmind  * searching.
     98  1.3.2.2  rmind  *
     99  1.3.2.2  rmind  * The vtw_t are, per requirement, in a contiguous chunk.  Allocation
    100  1.3.2.2  rmind  * is done with a clock hand, and all vtw_t within one allocation
    101  1.3.2.2  rmind  * domain have the same lifetime, so they will always be sorted by
    102  1.3.2.2  rmind  * age.
    103  1.3.2.2  rmind  *
    104  1.3.2.2  rmind  * A vtw_t will be allocated, timestamped, and have a fixed future
    105  1.3.2.2  rmind  * expiration.  It will be added to a hash bucket implemented with fat
    106  1.3.2.2  rmind  * pointers, which means that a cache line will be allocated in the
    107  1.3.2.2  rmind  * hash bucket, placed at the head (more recent in time) and the vtw_t
    108  1.3.2.2  rmind  * will be added to this.  As more entries are added, the fat pointer
    109  1.3.2.2  rmind  * cache line will fill, requiring additional cache lines for fat
    110  1.3.2.2  rmind  * pointers to be allocated. These will be added at the head, and the
    111  1.3.2.2  rmind  * aged entries will hang down, tapeworm like.  As the vtw_t entries
    112  1.3.2.2  rmind  * expire, the corresponding slot in the fat pointer will be
    113  1.3.2.2  rmind  * reclaimed, and eventually the cache line will completely empty and
    114  1.3.2.2  rmind  * be re-cycled, if not at the head of the chain.
    115  1.3.2.2  rmind  *
    116  1.3.2.2  rmind  * At times, a time-wait timer is restarted.  This corresponds to
    117  1.3.2.2  rmind  * deleting the current entry and re-adding it.
    118  1.3.2.2  rmind  *
    119  1.3.2.2  rmind  * Most of the time, they are just placed here to die.
    120  1.3.2.2  rmind  */
    121  1.3.2.2  rmind #ifndef _NETINET_TCP_VTW_H
    122  1.3.2.2  rmind #define _NETINET_TCP_VTW_H
    123  1.3.2.2  rmind 
    124  1.3.2.2  rmind #include <sys/types.h>
    125  1.3.2.2  rmind #include <sys/socket.h>
    126  1.3.2.2  rmind #include <sys/sysctl.h>
    127  1.3.2.2  rmind #include <net/if.h>
    128  1.3.2.2  rmind #include <net/route.h>
    129  1.3.2.2  rmind #include <netinet/in.h>
    130  1.3.2.2  rmind #include <netinet/in_systm.h>
    131  1.3.2.2  rmind #include <netinet/ip.h>
    132  1.3.2.2  rmind #include <netinet/in_pcb.h>
    133  1.3.2.2  rmind #include <netinet/in_var.h>
    134  1.3.2.2  rmind #include <netinet/ip_var.h>
    135  1.3.2.2  rmind #include <netinet/in.h>
    136  1.3.2.2  rmind #include <netinet/tcp.h>
    137  1.3.2.2  rmind #include <netinet/tcp_timer.h>
    138  1.3.2.2  rmind #include <netinet/tcp_var.h>
    139  1.3.2.2  rmind #include <netinet6/in6.h>
    140  1.3.2.2  rmind #include <netinet/ip6.h>
    141  1.3.2.2  rmind #include <netinet6/ip6_var.h>
    142  1.3.2.2  rmind #include <netinet6/in6_pcb.h>
    143  1.3.2.2  rmind #include <netinet6/ip6_var.h>
    144  1.3.2.2  rmind #include <netinet6/in6_var.h>
    145  1.3.2.2  rmind #include <netinet/icmp6.h>
    146  1.3.2.2  rmind #include <netinet6/nd6.h>
    147  1.3.2.2  rmind 
    148  1.3.2.2  rmind #define	VTW_NCLASS	(1+3)		/* # different classes */
    149  1.3.2.2  rmind 
    150  1.3.2.2  rmind /*
    151  1.3.2.2  rmind  * fat pointers, MI.
    152  1.3.2.2  rmind  */
    153  1.3.2.2  rmind struct fatp_mi;
    154  1.3.2.2  rmind 
    155  1.3.2.2  rmind typedef uint32_t fatp_word_t;
    156  1.3.2.2  rmind 
    157  1.3.2.2  rmind typedef struct fatp_mi	fatp_t;
    158  1.3.2.2  rmind 
    159  1.3.2.2  rmind /* Supported cacheline sizes: 32 64 128 bytes.  See fatp_key(),
    160  1.3.2.2  rmind  * fatp_slot_from_key(), fatp_xtra[].
    161  1.3.2.2  rmind  */
    162  1.3.2.2  rmind #define	FATP_NTAGS	(CACHE_LINE_SIZE / sizeof(fatp_word_t) - 1)
    163  1.3.2.2  rmind #define	FATP_NXT_WIDTH	(sizeof(fatp_word_t) * NBBY - FATP_NTAGS)
    164  1.3.2.2  rmind 
    165  1.3.2.2  rmind #define	FATP_MAX	(1 << FATP_NXT_WIDTH)
    166  1.3.2.2  rmind 
    167  1.3.2.2  rmind /* Worked example: ULP32 with 64-byte cacheline (32-bit x86):
    168  1.3.2.2  rmind  * 15 tags per cacheline.  At most 2^17 fat pointers per fatp_ctl_t.
    169  1.3.2.2  rmind  * The comments on the fatp_mi members, below, correspond to the worked
    170  1.3.2.2  rmind  * example.
    171  1.3.2.2  rmind  */
    172  1.3.2.2  rmind struct fatp_mi {
    173  1.3.2.2  rmind 	fatp_word_t	inuse	: FATP_NTAGS;	/* (1+15)*4 == CL_SIZE */
    174  1.3.2.2  rmind 	fatp_word_t	nxt	: FATP_NXT_WIDTH;/* at most 2^17 fat pointers */
    175  1.3.2.2  rmind 	fatp_word_t	tag[FATP_NTAGS];	/* 15 tags per CL */
    176  1.3.2.2  rmind };
    177  1.3.2.2  rmind 
    178  1.3.2.2  rmind static inline int
    179  1.3.2.2  rmind fatp_ntags(void)
    180  1.3.2.2  rmind {
    181  1.3.2.2  rmind 	return FATP_NTAGS;
    182  1.3.2.2  rmind }
    183  1.3.2.2  rmind 
    184  1.3.2.2  rmind static inline int
    185  1.3.2.2  rmind fatp_full(fatp_t *fp)
    186  1.3.2.2  rmind {
    187  1.3.2.2  rmind 	fatp_t full;
    188  1.3.2.2  rmind 
    189  1.3.2.2  rmind 	full.inuse = ~0;
    190  1.3.2.2  rmind 
    191  1.3.2.2  rmind 	return (fp->inuse == full.inuse);
    192  1.3.2.2  rmind }
    193  1.3.2.2  rmind 
    194  1.3.2.2  rmind struct vtw_common;
    195  1.3.2.2  rmind struct vtw_v4;
    196  1.3.2.2  rmind struct vtw_v6;
    197  1.3.2.2  rmind struct vtw_ctl;
    198  1.3.2.2  rmind 
    199  1.3.2.2  rmind /*!\brief common to all vtw
    200  1.3.2.2  rmind  */
    201  1.3.2.2  rmind typedef struct vtw_common {
    202  1.3.2.2  rmind 	struct timeval	expire;		/* date of birth+msl */
    203  1.3.2.2  rmind 	uint32_t	key;		/* hash key: full hash */
    204  1.3.2.2  rmind 	uint32_t	port_key;	/* hash key: local port hash */
    205  1.3.2.2  rmind 	uint32_t	rcv_nxt;
    206  1.3.2.2  rmind 	uint32_t	rcv_wnd;
    207  1.3.2.2  rmind 	uint32_t	snd_nxt;
    208  1.3.2.2  rmind 	uint32_t	snd_scale	: 8;	/* window scaling for send win */
    209  1.3.2.2  rmind 	uint32_t	msl_class	: 2;	/* TCP MSL class {0,1,2,3} */
    210  1.3.2.2  rmind 	uint32_t	reuse_port	: 1;
    211  1.3.2.2  rmind 	uint32_t	reuse_addr	: 1;
    212  1.3.2.2  rmind 	uint32_t	v6only		: 1;
    213  1.3.2.2  rmind 	uint32_t	hashed		: 1;	/* reachable via FATP */
    214  1.3.2.2  rmind 	uint32_t	uid;
    215  1.3.2.2  rmind } vtw_t;
    216  1.3.2.2  rmind 
    217  1.3.2.2  rmind /*!\brief vestigial timewait for IPv4
    218  1.3.2.2  rmind  */
    219  1.3.2.2  rmind typedef struct vtw_v4 {
    220  1.3.2.2  rmind 	vtw_t		common;		/*  must be first */
    221  1.3.2.2  rmind 	uint16_t	lport;
    222  1.3.2.2  rmind 	uint16_t	fport;
    223  1.3.2.2  rmind 	uint32_t	laddr;
    224  1.3.2.2  rmind 	uint32_t	faddr;
    225  1.3.2.2  rmind } vtw_v4_t;
    226  1.3.2.2  rmind 
    227  1.3.2.2  rmind /*!\brief vestigial timewait for IPv6
    228  1.3.2.2  rmind  */
    229  1.3.2.2  rmind typedef struct vtw_v6 {
    230  1.3.2.2  rmind 	vtw_t		common;		/* must be first */
    231  1.3.2.2  rmind 	uint16_t	lport;
    232  1.3.2.2  rmind 	uint16_t	fport;
    233  1.3.2.2  rmind 	struct in6_addr	laddr;
    234  1.3.2.2  rmind 	struct in6_addr	faddr;
    235  1.3.2.2  rmind } vtw_v6_t;
    236  1.3.2.2  rmind 
    237  1.3.2.2  rmind struct fatp_ctl;
    238  1.3.2.2  rmind typedef struct vtw_ctl		vtw_ctl_t;
    239  1.3.2.2  rmind typedef struct fatp_ctl		fatp_ctl_t;
    240  1.3.2.2  rmind 
    241  1.3.2.2  rmind /*
    242  1.3.2.2  rmind  * The vestigial time waits are kept in a contiguous chunk.
    243  1.3.2.2  rmind  * Allocation and free pointers run as clock hands thru this array.
    244  1.3.2.2  rmind  */
    245  1.3.2.2  rmind struct vtw_ctl {
    246  1.3.2.2  rmind 	fatp_ctl_t	*fat;		/* collection of fatp to use	*/
    247  1.3.2.2  rmind 	vtw_ctl_t	*ctl;		/* <! controller's controller	*/
    248  1.3.2.2  rmind 	union {
    249  1.3.2.2  rmind 		vtw_t		*v;	/* common			*/
    250  1.3.2.2  rmind 		struct vtw_v4	*v4;	/* IPv4 resources		*/
    251  1.3.2.2  rmind 		struct vtw_v6	*v6;	/* IPv6 resources		*/
    252  1.3.2.2  rmind 	}		base,		/* base of vtw_t array		*/
    253  1.3.2.2  rmind 		/**/	lim,		/* extent of vtw_t array	*/
    254  1.3.2.2  rmind 		/**/	alloc,		/* allocation pointer		*/
    255  1.3.2.2  rmind 		/**/	oldest;		/* ^ to oldest			*/
    256  1.3.2.2  rmind 	uint32_t	nfree;		/* # free			*/
    257  1.3.2.2  rmind 	uint32_t	nalloc;		/* # allocated			*/
    258  1.3.2.2  rmind 	uint32_t	idx_mask;	/* mask capturing all index bits*/
    259  1.3.2.2  rmind 	uint32_t	is_v4	: 1;
    260  1.3.2.2  rmind 	uint32_t	is_v6	: 1;
    261  1.3.2.2  rmind 	uint32_t	idx_bits: 6;
    262  1.3.2.2  rmind 	uint32_t	clidx	: 3;	/* <! class index */
    263  1.3.2.2  rmind };
    264  1.3.2.2  rmind 
    265  1.3.2.2  rmind /*!\brief Collections of fat pointers.
    266  1.3.2.2  rmind  */
    267  1.3.2.2  rmind struct fatp_ctl {
    268  1.3.2.2  rmind 	vtw_ctl_t	*vtw;		/* associated VTWs		*/
    269  1.3.2.2  rmind 	fatp_t		*base;		/* base of fatp_t array		*/
    270  1.3.2.2  rmind 	fatp_t		*lim;		/* extent of fatp_t array	*/
    271  1.3.2.2  rmind 	fatp_t		*free;		/* free list			*/
    272  1.3.2.2  rmind 	uint32_t	mask;		/* hash mask			*/
    273  1.3.2.2  rmind 	uint32_t	nfree;		/* # free			*/
    274  1.3.2.2  rmind 	uint32_t	nalloc;		/* # allocated			*/
    275  1.3.2.2  rmind 	fatp_t		**hash;		/* hash anchors			*/
    276  1.3.2.2  rmind 	fatp_t		**port;		/* port hash anchors		*/
    277  1.3.2.2  rmind };
    278  1.3.2.2  rmind 
    279  1.3.2.2  rmind /*!\brief stats
    280  1.3.2.2  rmind  */
    281  1.3.2.2  rmind struct vtw_stats {
    282  1.3.2.2  rmind 	uint64_t	ins;		/* <! inserts */
    283  1.3.2.2  rmind 	uint64_t	del;		/* <! deleted */
    284  1.3.2.2  rmind 	uint64_t	kill;		/* <! assassination */
    285  1.3.2.2  rmind 	uint64_t	look[2];	/* <! lookup: full hash, port hash */
    286  1.3.2.2  rmind 	uint64_t	hit[2];		/* <! lookups that hit */
    287  1.3.2.2  rmind 	uint64_t	miss[2];	/* <! lookups that miss */
    288  1.3.2.2  rmind 	uint64_t	probe[2];	/* <! hits+miss */
    289  1.3.2.2  rmind 	uint64_t	losing[2];	/* <! misses requiring dereference */
    290  1.3.2.2  rmind 	uint64_t	max_chain[2];	/* <! max fatp chain traversed */
    291  1.3.2.2  rmind 	uint64_t	max_probe[2];	/* <! max probes in any one chain */
    292  1.3.2.2  rmind 	uint64_t	max_loss[2];	/* <! max losing probes in any one
    293  1.3.2.2  rmind 					 * chain
    294  1.3.2.2  rmind 					 */
    295  1.3.2.2  rmind };
    296  1.3.2.2  rmind 
    297  1.3.2.2  rmind typedef struct vtw_stats	vtw_stats_t;
    298  1.3.2.2  rmind 
    299  1.3.2.2  rmind /*!\brief	follow fatp next 'pointer'
    300  1.3.2.2  rmind  */
    301  1.3.2.2  rmind static inline fatp_t *
    302  1.3.2.2  rmind fatp_next(fatp_ctl_t *fat, fatp_t *fp)
    303  1.3.2.2  rmind {
    304  1.3.2.2  rmind 	return fp->nxt ? fat->base + fp->nxt-1 : 0;
    305  1.3.2.2  rmind }
    306  1.3.2.2  rmind 
    307  1.3.2.2  rmind /*!\brief determine a collection-relative fat pointer index.
    308  1.3.2.2  rmind  */
    309  1.3.2.2  rmind static inline uint32_t
    310  1.3.2.2  rmind fatp_index(fatp_ctl_t *fat, fatp_t *fp)
    311  1.3.2.2  rmind {
    312  1.3.2.2  rmind 	return fp ? 1 + (fp - fat->base) : 0;
    313  1.3.2.2  rmind }
    314  1.3.2.2  rmind 
    315  1.3.2.2  rmind 
    316  1.3.2.2  rmind static inline uint32_t
    317  1.3.2.2  rmind v4_tag(uint32_t faddr, uint32_t fport, uint32_t laddr, uint32_t lport)
    318  1.3.2.2  rmind {
    319  1.3.2.2  rmind 	return (ntohl(faddr)   + ntohs(fport)
    320  1.3.2.2  rmind 		+ ntohl(laddr) + ntohs(lport));
    321  1.3.2.2  rmind }
    322  1.3.2.2  rmind 
    323  1.3.2.2  rmind static inline uint32_t
    324  1.3.2.2  rmind v6_tag(const struct in6_addr *faddr, uint16_t fport,
    325  1.3.2.2  rmind        const struct in6_addr *laddr, uint16_t lport)
    326  1.3.2.2  rmind {
    327  1.3.2.2  rmind #ifdef IN6_HASH
    328  1.3.2.2  rmind 	return IN6_HASH(faddr, fport, laddr, lport);
    329  1.3.2.2  rmind #else
    330  1.3.2.2  rmind 	return 0;
    331  1.3.2.2  rmind #endif
    332  1.3.2.2  rmind }
    333  1.3.2.2  rmind 
    334  1.3.2.2  rmind static inline uint32_t
    335  1.3.2.2  rmind v4_port_tag(uint16_t lport)
    336  1.3.2.2  rmind {
    337  1.3.2.2  rmind 	uint32_t tag = lport ^ (lport << 11);
    338  1.3.2.2  rmind 
    339  1.3.2.2  rmind 	tag ^= tag << 3;
    340  1.3.2.2  rmind 	tag += tag >> 5;
    341  1.3.2.2  rmind 	tag ^= tag << 4;
    342  1.3.2.2  rmind 	tag += tag >> 17;
    343  1.3.2.2  rmind 	tag ^= tag << 25;
    344  1.3.2.2  rmind 	tag += tag >> 6;
    345  1.3.2.2  rmind 
    346  1.3.2.2  rmind 	return tag;
    347  1.3.2.2  rmind }
    348  1.3.2.2  rmind 
    349  1.3.2.2  rmind static inline uint32_t
    350  1.3.2.2  rmind v6_port_tag(uint16_t lport)
    351  1.3.2.2  rmind {
    352  1.3.2.2  rmind 	return v4_port_tag(lport);
    353  1.3.2.2  rmind }
    354  1.3.2.2  rmind 
    355  1.3.2.2  rmind struct tcpcb;
    356  1.3.2.2  rmind struct tcphdr;
    357  1.3.2.2  rmind 
    358  1.3.2.2  rmind int  vtw_add(int, struct tcpcb *);
    359  1.3.2.2  rmind void vtw_del(vtw_ctl_t *, vtw_t *);
    360  1.3.2.2  rmind int vtw_lookup_v4(const struct ip *ip, const struct tcphdr *th,
    361  1.3.2.2  rmind 		  uint32_t faddr, uint16_t fport,
    362  1.3.2.2  rmind 		  uint32_t laddr, uint16_t lport);
    363  1.3.2.2  rmind struct ip6_hdr;
    364  1.3.2.2  rmind struct in6_addr;
    365  1.3.2.2  rmind 
    366  1.3.2.2  rmind int vtw_lookup_v6(const struct ip6_hdr *ip, const struct tcphdr *th,
    367  1.3.2.2  rmind 		  const struct in6_addr *faddr, uint16_t fport,
    368  1.3.2.2  rmind 		  const struct in6_addr *laddr, uint16_t lport);
    369  1.3.2.2  rmind 
    370  1.3.2.2  rmind typedef struct vestigial_inpcb {
    371  1.3.2.2  rmind 	union {
    372  1.3.2.2  rmind 		struct in_addr	v4;
    373  1.3.2.2  rmind 		struct in6_addr	v6;
    374  1.3.2.2  rmind 	} faddr, laddr;
    375  1.3.2.2  rmind 	uint16_t		fport, lport;
    376  1.3.2.2  rmind 	uint32_t		valid		: 1;
    377  1.3.2.2  rmind 	uint32_t		v4		: 1;
    378  1.3.2.2  rmind 	uint32_t		reuse_addr	: 1;
    379  1.3.2.2  rmind 	uint32_t		reuse_port	: 1;
    380  1.3.2.2  rmind 	uint32_t		v6only		: 1;
    381  1.3.2.2  rmind 	uint32_t		more_tbd	: 1;
    382  1.3.2.2  rmind 	uint32_t		uid;
    383  1.3.2.2  rmind 	uint32_t		rcv_nxt;
    384  1.3.2.2  rmind 	uint32_t		rcv_wnd;
    385  1.3.2.2  rmind 	uint32_t		snd_nxt;
    386  1.3.2.2  rmind 	struct vtw_common	*vtw;
    387  1.3.2.2  rmind 	struct vtw_ctl		*ctl;
    388  1.3.2.2  rmind } vestigial_inpcb_t;
    389  1.3.2.2  rmind 
    390  1.3.2.2  rmind void vtw_restart(vestigial_inpcb_t*);
    391  1.3.2.2  rmind int vtw_earlyinit(void);
    392  1.3.2.2  rmind 
    393  1.3.2.2  rmind #ifdef VTW_DEBUG
    394  1.3.2.2  rmind typedef struct sin_either {
    395  1.3.2.2  rmind 	uint8_t		sin_len;
    396  1.3.2.2  rmind 	uint8_t		sin_family;
    397  1.3.2.2  rmind 	uint16_t	sin_port;
    398  1.3.2.2  rmind 	union {
    399  1.3.2.2  rmind 		struct in_addr	v4;
    400  1.3.2.2  rmind 		struct in6_addr	v6;
    401  1.3.2.2  rmind 	}		sin_addr;
    402  1.3.2.2  rmind } sin_either_t;
    403  1.3.2.2  rmind 
    404  1.3.2.2  rmind int vtw_debug_add(int af, sin_either_t *, sin_either_t *, int, int);
    405  1.3.2.2  rmind 
    406  1.3.2.2  rmind typedef struct vtw_sysargs {
    407  1.3.2.2  rmind 	uint32_t	op;
    408  1.3.2.2  rmind 	sin_either_t	fa;
    409  1.3.2.2  rmind 	sin_either_t	la;
    410  1.3.2.2  rmind } vtw_sysargs_t;
    411  1.3.2.2  rmind 
    412  1.3.2.2  rmind #endif /* VTW_DEBUG */
    413  1.3.2.2  rmind 
    414  1.3.2.2  rmind #endif /* _NETINET_TCP_VTW_H */
    415