Deleted Added
full compact
tcp_hostcache.c (133509) tcp_hostcache.c (133874)
1/*
2 * Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*
2 * Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/netinet/tcp_hostcache.c 133509 2004-08-11 17:08:31Z andre $
29 * $FreeBSD: head/sys/netinet/tcp_hostcache.c 133874 2004-08-16 18:32:07Z rwatson $
30 */
31
32/*
33 * The tcp_hostcache moves the tcp specific cached metrics from the routing
34 * table into a dedicated structure indexed by the remote IP address. It
35 * keeps information on the measured tcp parameters of past tcp sessions
36 * to have better initial start values for following connections from the
37 * same source. Depending on the network parameters (delay, bandwidth, max

--- 139 unchanged lines hidden (view full) ---

177SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list,
178 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP, 0, 0,
179 sysctl_tcp_hc_list, "A", "List of all hostcache entries");
180
181
182static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache");
183
184#define HOSTCACHE_HASH(ip) \
30 */
31
32/*
33 * The tcp_hostcache moves the tcp specific cached metrics from the routing
34 * table into a dedicated structure indexed by the remote IP address. It
35 * keeps information on the measured tcp parameters of past tcp sessions
36 * to have better initial start values for following connections from the
37 * same source. Depending on the network parameters (delay, bandwidth, max

--- 139 unchanged lines hidden (view full) ---

177SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list,
178 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP, 0, 0,
179 sysctl_tcp_hc_list, "A", "List of all hostcache entries");
180
181
182static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache");
183
184#define HOSTCACHE_HASH(ip) \
185 (((ip)->s_addr ^ ((ip)->s_addr >> 7) ^ ((ip)->s_addr >> 17)) & \
185 (((ip)->s_addr ^ ((ip)->s_addr >> 7) ^ ((ip)->s_addr >> 17)) & \
186 tcp_hostcache.hashmask)
187
188/* XXX: What is the recommended hash to get good entropy for IPv6 addresses? */
186 tcp_hostcache.hashmask)
187
188/* XXX: What is the recommended hash to get good entropy for IPv6 addresses? */
189#define HOSTCACHE_HASH6(ip6) \
189#define HOSTCACHE_HASH6(ip6) \
190 (((ip6)->s6_addr32[0] ^ \
191 (ip6)->s6_addr32[1] ^ \
192 (ip6)->s6_addr32[2] ^ \
193 (ip6)->s6_addr32[3]) & \
194 tcp_hostcache.hashmask)
195
196#define THC_LOCK(lp) mtx_lock(lp)
197#define THC_UNLOCK(lp) mtx_unlock(lp)

--- 8 unchanged lines hidden (view full) ---

206 */
207 tcp_hostcache.cache_count = 0;
208 tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE;
209 tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT;
210 tcp_hostcache.cache_limit =
211 tcp_hostcache.hashsize * tcp_hostcache.bucket_limit;
212 tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE;
213
190 (((ip6)->s6_addr32[0] ^ \
191 (ip6)->s6_addr32[1] ^ \
192 (ip6)->s6_addr32[2] ^ \
193 (ip6)->s6_addr32[3]) & \
194 tcp_hostcache.hashmask)
195
196#define THC_LOCK(lp) mtx_lock(lp)
197#define THC_UNLOCK(lp) mtx_unlock(lp)

--- 8 unchanged lines hidden (view full) ---

206 */
207 tcp_hostcache.cache_count = 0;
208 tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE;
209 tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT;
210 tcp_hostcache.cache_limit =
211 tcp_hostcache.hashsize * tcp_hostcache.bucket_limit;
212 tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE;
213
214 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize",
214 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize",
215 &tcp_hostcache.hashsize);
215 &tcp_hostcache.hashsize);
216 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit",
216 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit",
217 &tcp_hostcache.cache_limit);
217 &tcp_hostcache.cache_limit);
218 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit",
218 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit",
219 &tcp_hostcache.bucket_limit);
220 if (!powerof2(tcp_hostcache.hashsize)) {
219 &tcp_hostcache.bucket_limit);
220 if (!powerof2(tcp_hostcache.hashsize)) {
221 printf("WARNING: hostcache hash size is not a power of 2.\n");
221 printf("WARNING: hostcache hash size is not a power of 2.\n");
222 tcp_hostcache.hashsize = 512; /* safe default */
222 tcp_hostcache.hashsize = 512; /* safe default */
223 }
223 }
224 tcp_hostcache.hashmask = tcp_hostcache.hashsize - 1;
225
226 /*
227 * Allocate the hash table
228 */
229 tcp_hostcache.hashbase = (struct hc_head *)
230 malloc(tcp_hostcache.hashsize * sizeof(struct hc_head),
231 M_HOSTCACHE, M_WAITOK | M_ZERO);

--- 74 unchanged lines hidden (view full) ---

306 */
307 THC_UNLOCK(&hc_head->hch_mtx);
308 return NULL;
309}
310
311/*
312 * Internal function: insert an entry into the hostcache or return NULL
313 * if unable to allocate a new one.
224 tcp_hostcache.hashmask = tcp_hostcache.hashsize - 1;
225
226 /*
227 * Allocate the hash table
228 */
229 tcp_hostcache.hashbase = (struct hc_head *)
230 malloc(tcp_hostcache.hashsize * sizeof(struct hc_head),
231 M_HOSTCACHE, M_WAITOK | M_ZERO);

--- 74 unchanged lines hidden (view full) ---

306 */
307 THC_UNLOCK(&hc_head->hch_mtx);
308 return NULL;
309}
310
311/*
312 * Internal function: insert an entry into the hostcache or return NULL
313 * if unable to allocate a new one.
314 *
314 *
315 * If an entry has been returned, the caller becomes responsible for
316 * unlocking the bucket row after he is done reading/modifying the entry.
317 */
318static struct hc_metrics *
319tcp_hc_insert(struct in_conninfo *inc)
320{
321 int hash;
322 struct hc_head *hc_head;

--- 217 unchanged lines hidden (view full) ---

540 hc_entry->rmx_rtt = hcml->rmx_rtt;
541 else
542 hc_entry->rmx_rtt =
543 (hc_entry->rmx_rtt + hcml->rmx_rtt) / 2;
544 tcpstat.tcps_cachedrtt++;
545 }
546 if (hcml->rmx_rttvar != 0) {
547 if (hc_entry->rmx_rttvar == 0)
315 * If an entry has been returned, the caller becomes responsible for
316 * unlocking the bucket row after he is done reading/modifying the entry.
317 */
318static struct hc_metrics *
319tcp_hc_insert(struct in_conninfo *inc)
320{
321 int hash;
322 struct hc_head *hc_head;

--- 217 unchanged lines hidden (view full) ---

540 hc_entry->rmx_rtt = hcml->rmx_rtt;
541 else
542 hc_entry->rmx_rtt =
543 (hc_entry->rmx_rtt + hcml->rmx_rtt) / 2;
544 tcpstat.tcps_cachedrtt++;
545 }
546 if (hcml->rmx_rttvar != 0) {
547 if (hc_entry->rmx_rttvar == 0)
548 hc_entry->rmx_rttvar = hcml->rmx_rttvar;
548 hc_entry->rmx_rttvar = hcml->rmx_rttvar;
549 else
550 hc_entry->rmx_rttvar =
551 (hc_entry->rmx_rttvar + hcml->rmx_rttvar) / 2;
552 tcpstat.tcps_cachedrttvar++;
553 }
554 if (hcml->rmx_ssthresh != 0) {
555 if (hc_entry->rmx_ssthresh == 0)
556 hc_entry->rmx_ssthresh = hcml->rmx_ssthresh;

--- 19 unchanged lines hidden (view full) ---

576 /* tcpstat.tcps_cachedcwnd++; */
577 }
578 if (hcml->rmx_sendpipe != 0) {
579 if (hc_entry->rmx_sendpipe == 0)
580 hc_entry->rmx_sendpipe = hcml->rmx_sendpipe;
581 else
582 hc_entry->rmx_sendpipe =
583 (hc_entry->rmx_sendpipe + hcml->rmx_sendpipe) /2;
549 else
550 hc_entry->rmx_rttvar =
551 (hc_entry->rmx_rttvar + hcml->rmx_rttvar) / 2;
552 tcpstat.tcps_cachedrttvar++;
553 }
554 if (hcml->rmx_ssthresh != 0) {
555 if (hc_entry->rmx_ssthresh == 0)
556 hc_entry->rmx_ssthresh = hcml->rmx_ssthresh;

--- 19 unchanged lines hidden (view full) ---

576 /* tcpstat.tcps_cachedcwnd++; */
577 }
578 if (hcml->rmx_sendpipe != 0) {
579 if (hc_entry->rmx_sendpipe == 0)
580 hc_entry->rmx_sendpipe = hcml->rmx_sendpipe;
581 else
582 hc_entry->rmx_sendpipe =
583 (hc_entry->rmx_sendpipe + hcml->rmx_sendpipe) /2;
584 /* tcpstat.tcps_cachedsendpipe++; */
585 }
584 /* tcpstat.tcps_cachedsendpipe++; */
585 }
586 if (hcml->rmx_recvpipe != 0) {
587 if (hc_entry->rmx_recvpipe == 0)
588 hc_entry->rmx_recvpipe = hcml->rmx_recvpipe;
589 else
590 hc_entry->rmx_recvpipe =
591 (hc_entry->rmx_recvpipe + hcml->rmx_recvpipe) /2;
592 /* tcpstat.tcps_cachedrecvpipe++; */
593 }

--- 135 unchanged lines hidden ---
586 if (hcml->rmx_recvpipe != 0) {
587 if (hc_entry->rmx_recvpipe == 0)
588 hc_entry->rmx_recvpipe = hcml->rmx_recvpipe;
589 else
590 hc_entry->rmx_recvpipe =
591 (hc_entry->rmx_recvpipe + hcml->rmx_recvpipe) /2;
592 /* tcpstat.tcps_cachedrecvpipe++; */
593 }

--- 135 unchanged lines hidden ---