tcp_hostcache.c (182633) | tcp_hostcache.c (183550) |
---|---|
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 --- 49 unchanged lines hidden (view full) --- 58 */ 59 60/* 61 * Many thanks to jlemon for basic structure of tcp_syncache which is being 62 * followed here. 63 */ 64 65#include <sys/cdefs.h> | 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 --- 49 unchanged lines hidden (view full) --- 58 */ 59 60/* 61 * Many thanks to jlemon for basic structure of tcp_syncache which is being 62 * followed here. 63 */ 64 65#include <sys/cdefs.h> |
66__FBSDID("$FreeBSD: head/sys/netinet/tcp_hostcache.c 182633 2008-09-01 19:25:27Z brooks $"); | 66__FBSDID("$FreeBSD: head/sys/netinet/tcp_hostcache.c 183550 2008-10-02 15:37:58Z zec $"); |
67 68#include "opt_inet6.h" 69 70#include <sys/param.h> 71#include <sys/systm.h> 72#include <sys/kernel.h> 73#include <sys/lock.h> 74#include <sys/mutex.h> --- 78 unchanged lines hidden (view full) --- 153static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); 154static struct hc_metrics *tcp_hc_insert(struct in_conninfo *); 155static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); 156static void tcp_hc_purge(void *); 157 158SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache, CTLFLAG_RW, 0, 159 "TCP Host cache"); 160 | 67 68#include "opt_inet6.h" 69 70#include <sys/param.h> 71#include <sys/systm.h> 72#include <sys/kernel.h> 73#include <sys/lock.h> 74#include <sys/mutex.h> --- 78 unchanged lines hidden (view full) --- 153static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); 154static struct hc_metrics *tcp_hc_insert(struct in_conninfo *); 155static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); 156static void tcp_hc_purge(void *); 157 158SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache, CTLFLAG_RW, 0, 159 "TCP Host cache"); 160 |
161SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, cachelimit, CTLFLAG_RDTUN, 162 &tcp_hostcache.cache_limit, 0, "Overall entry limit for hostcache"); | 161SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, cachelimit, 162 CTLFLAG_RDTUN, tcp_hostcache.cache_limit, 0, 163 "Overall entry limit for hostcache"); |
163 | 164 |
164SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, hashsize, CTLFLAG_RDTUN, 165 &tcp_hostcache.hashsize, 0, "Size of TCP hostcache hashtable"); | 165SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, hashsize, 166 CTLFLAG_RDTUN, tcp_hostcache.hashsize, 0, 167 "Size of TCP hostcache hashtable"); |
166 | 168 |
167SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, bucketlimit, CTLFLAG_RDTUN, 168 &tcp_hostcache.bucket_limit, 0, "Per-bucket hash limit for hostcache"); | 169SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, bucketlimit, 170 CTLFLAG_RDTUN, tcp_hostcache.bucket_limit, 0, 171 "Per-bucket hash limit for hostcache"); |
169 | 172 |
170SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_RD, 171 &tcp_hostcache.cache_count, 0, "Current number of entries in hostcache"); | 173SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, count, 174 CTLFLAG_RD, tcp_hostcache.cache_count, 0, 175 "Current number of entries in hostcache"); |
172 | 176 |
173SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_RW, 174 &tcp_hostcache.expire, 0, "Expire time of TCP hostcache entries"); | 177SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, expire, 178 CTLFLAG_RW, tcp_hostcache.expire, 0, 179 "Expire time of TCP hostcache entries"); |
175 | 180 |
176SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, prune, CTLFLAG_RW, 177 &tcp_hostcache.prune, 0, "Time between purge runs"); | 181SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, prune, 182 CTLFLAG_RW, tcp_hostcache.prune, 0, "Time between purge runs"); |
178 | 183 |
179SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_RW, 180 &tcp_hostcache.purgeall, 0, "Expire all entires on next purge run"); | 184SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, purge, 185 CTLFLAG_RW, tcp_hostcache.purgeall, 0, 186 "Expire all entires on next purge run"); |
181 182SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list, 183 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP, 0, 0, 184 sysctl_tcp_hc_list, "A", "List of all hostcache entries"); 185 186 187static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache"); 188 --- 10 unchanged lines hidden (view full) --- 199 V_tcp_hostcache.hashmask) 200 201#define THC_LOCK(lp) mtx_lock(lp) 202#define THC_UNLOCK(lp) mtx_unlock(lp) 203 204void 205tcp_hc_init(void) 206{ | 187 188SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list, 189 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP, 0, 0, 190 sysctl_tcp_hc_list, "A", "List of all hostcache entries"); 191 192 193static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache"); 194 --- 10 unchanged lines hidden (view full) --- 205 V_tcp_hostcache.hashmask) 206 207#define THC_LOCK(lp) mtx_lock(lp) 208#define THC_UNLOCK(lp) mtx_unlock(lp) 209 210void 211tcp_hc_init(void) 212{ |
213 INIT_VNET_INET(curvnet); |
|
207 int i; 208 209 /* 210 * Initialize hostcache structures. 211 */ 212 V_tcp_hostcache.cache_count = 0; 213 V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; 214 V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT; --- 51 unchanged lines hidden (view full) --- 266 * Internal function: look up an entry in the hostcache or return NULL. 267 * 268 * If an entry has been returned, the caller becomes responsible for 269 * unlocking the bucket row after he is done reading/modifying the entry. 270 */ 271static struct hc_metrics * 272tcp_hc_lookup(struct in_conninfo *inc) 273{ | 214 int i; 215 216 /* 217 * Initialize hostcache structures. 218 */ 219 V_tcp_hostcache.cache_count = 0; 220 V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; 221 V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT; --- 51 unchanged lines hidden (view full) --- 273 * Internal function: look up an entry in the hostcache or return NULL. 274 * 275 * If an entry has been returned, the caller becomes responsible for 276 * unlocking the bucket row after he is done reading/modifying the entry. 277 */ 278static struct hc_metrics * 279tcp_hc_lookup(struct in_conninfo *inc) 280{ |
281 INIT_VNET_INET(curvnet); |
|
274 int hash; 275 struct hc_head *hc_head; 276 struct hc_metrics *hc_entry; 277 278 KASSERT(inc != NULL, ("tcp_hc_lookup with NULL in_conninfo pointer")); 279 280 /* 281 * Hash the foreign ip address. --- 39 unchanged lines hidden (view full) --- 321 * unable to allocate a new one. 322 * 323 * If an entry has been returned, the caller becomes responsible for 324 * unlocking the bucket row after he is done reading/modifying the entry. 325 */ 326static struct hc_metrics * 327tcp_hc_insert(struct in_conninfo *inc) 328{ | 282 int hash; 283 struct hc_head *hc_head; 284 struct hc_metrics *hc_entry; 285 286 KASSERT(inc != NULL, ("tcp_hc_lookup with NULL in_conninfo pointer")); 287 288 /* 289 * Hash the foreign ip address. --- 39 unchanged lines hidden (view full) --- 329 * unable to allocate a new one. 330 * 331 * If an entry has been returned, the caller becomes responsible for 332 * unlocking the bucket row after he is done reading/modifying the entry. 333 */ 334static struct hc_metrics * 335tcp_hc_insert(struct in_conninfo *inc) 336{ |
337 INIT_VNET_INET(curvnet); |
|
329 int hash; 330 struct hc_head *hc_head; 331 struct hc_metrics *hc_entry; 332 333 KASSERT(inc != NULL, ("tcp_hc_insert with NULL in_conninfo pointer")); 334 335 /* 336 * Hash the foreign ip address. --- 74 unchanged lines hidden (view full) --- 411/* 412 * External function: look up an entry in the hostcache and fill out the 413 * supplied TCP metrics structure. Fills in NULL when no entry was found or 414 * a value is not set. 415 */ 416void 417tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite) 418{ | 338 int hash; 339 struct hc_head *hc_head; 340 struct hc_metrics *hc_entry; 341 342 KASSERT(inc != NULL, ("tcp_hc_insert with NULL in_conninfo pointer")); 343 344 /* 345 * Hash the foreign ip address. --- 74 unchanged lines hidden (view full) --- 420/* 421 * External function: look up an entry in the hostcache and fill out the 422 * supplied TCP metrics structure. Fills in NULL when no entry was found or 423 * a value is not set. 424 */ 425void 426tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite) 427{ |
428 INIT_VNET_INET(curvnet); |
|
419 struct hc_metrics *hc_entry; 420 421 /* 422 * Find the right bucket. 423 */ 424 hc_entry = tcp_hc_lookup(inc); 425 426 /* --- 24 unchanged lines hidden (view full) --- 451/* 452 * External function: look up an entry in the hostcache and return the 453 * discovered path MTU. Returns NULL if no entry is found or value is not 454 * set. 455 */ 456u_long 457tcp_hc_getmtu(struct in_conninfo *inc) 458{ | 429 struct hc_metrics *hc_entry; 430 431 /* 432 * Find the right bucket. 433 */ 434 hc_entry = tcp_hc_lookup(inc); 435 436 /* --- 24 unchanged lines hidden (view full) --- 461/* 462 * External function: look up an entry in the hostcache and return the 463 * discovered path MTU. Returns NULL if no entry is found or value is not 464 * set. 465 */ 466u_long 467tcp_hc_getmtu(struct in_conninfo *inc) 468{ |
469 INIT_VNET_INET(curvnet); |
|
459 struct hc_metrics *hc_entry; 460 u_long mtu; 461 462 hc_entry = tcp_hc_lookup(inc); 463 if (hc_entry == NULL) { 464 return 0; 465 } 466 hc_entry->rmx_hits++; --- 6 unchanged lines hidden (view full) --- 473 474/* 475 * External function: update the MTU value of an entry in the hostcache. 476 * Creates a new entry if none was found. 477 */ 478void 479tcp_hc_updatemtu(struct in_conninfo *inc, u_long mtu) 480{ | 470 struct hc_metrics *hc_entry; 471 u_long mtu; 472 473 hc_entry = tcp_hc_lookup(inc); 474 if (hc_entry == NULL) { 475 return 0; 476 } 477 hc_entry->rmx_hits++; --- 6 unchanged lines hidden (view full) --- 484 485/* 486 * External function: update the MTU value of an entry in the hostcache. 487 * Creates a new entry if none was found. 488 */ 489void 490tcp_hc_updatemtu(struct in_conninfo *inc, u_long mtu) 491{ |
492 INIT_VNET_INET(curvnet); |
|
481 struct hc_metrics *hc_entry; 482 483 /* 484 * Find the right bucket. 485 */ 486 hc_entry = tcp_hc_lookup(inc); 487 488 /* --- 23 unchanged lines hidden (view full) --- 512 513/* 514 * External function: update the TCP metrics of an entry in the hostcache. 515 * Creates a new entry if none was found. 516 */ 517void 518tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml) 519{ | 493 struct hc_metrics *hc_entry; 494 495 /* 496 * Find the right bucket. 497 */ 498 hc_entry = tcp_hc_lookup(inc); 499 500 /* --- 23 unchanged lines hidden (view full) --- 524 525/* 526 * External function: update the TCP metrics of an entry in the hostcache. 527 * Creates a new entry if none was found. 528 */ 529void 530tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml) 531{ |
532 INIT_VNET_INET(curvnet); |
|
520 struct hc_metrics *hc_entry; 521 522 hc_entry = tcp_hc_lookup(inc); 523 if (hc_entry == NULL) { 524 hc_entry = tcp_hc_insert(inc); 525 if (hc_entry == NULL) 526 return; 527 } --- 64 unchanged lines hidden (view full) --- 592 593/* 594 * Sysctl function: prints the list and values of all hostcache entries in 595 * unsorted order. 596 */ 597static int 598sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) 599{ | 533 struct hc_metrics *hc_entry; 534 535 hc_entry = tcp_hc_lookup(inc); 536 if (hc_entry == NULL) { 537 hc_entry = tcp_hc_insert(inc); 538 if (hc_entry == NULL) 539 return; 540 } --- 64 unchanged lines hidden (view full) --- 605 606/* 607 * Sysctl function: prints the list and values of all hostcache entries in 608 * unsorted order. 609 */ 610static int 611sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) 612{ |
613 INIT_VNET_INET(curvnet); |
|
600 int bufsize; 601 int linesize = 128; 602 char *p, *buf; 603 int len, i, error; 604 struct hc_metrics *hc_entry; 605#ifdef INET6 606 char ip6buf[INET6_ADDRSTRLEN]; 607#endif --- 46 unchanged lines hidden (view full) --- 654 655/* 656 * Expire and purge (old|all) entries in the tcp_hostcache. Runs 657 * periodically from the callout. 658 */ 659static void 660tcp_hc_purge(void *arg) 661{ | 614 int bufsize; 615 int linesize = 128; 616 char *p, *buf; 617 int len, i, error; 618 struct hc_metrics *hc_entry; 619#ifdef INET6 620 char ip6buf[INET6_ADDRSTRLEN]; 621#endif --- 46 unchanged lines hidden (view full) --- 668 669/* 670 * Expire and purge (old|all) entries in the tcp_hostcache. Runs 671 * periodically from the callout. 672 */ 673static void 674tcp_hc_purge(void *arg) 675{ |
676 INIT_VNET_INET(curvnet); |
|
662 struct hc_metrics *hc_entry, *hc_next; 663 int all = (intptr_t)arg; 664 int i; 665 666 if (V_tcp_hostcache.purgeall) { 667 all = 1; 668 V_tcp_hostcache.purgeall = 0; 669 } --- 20 unchanged lines hidden --- | 677 struct hc_metrics *hc_entry, *hc_next; 678 int all = (intptr_t)arg; 679 int i; 680 681 if (V_tcp_hostcache.purgeall) { 682 all = 1; 683 V_tcp_hostcache.purgeall = 0; 684 } --- 20 unchanged lines hidden --- |