Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/libalias/alias_db.c
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | ||||||||||
#include "alias.h" | #include "alias.h" | |||||||||
#include "alias_local.h" | #include "alias_local.h" | |||||||||
#include "alias_mod.h" | #include "alias_mod.h" | |||||||||
#endif | #endif | |||||||||
#include "alias_db.h" | #include "alias_db.h" | |||||||||
static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead); | static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead); | |||||||||
int LibAliasTime; | int LibAliasTime; | |||||||||
seUnsubmitted Not Done Inline Actions
se: | ||||||||||
/* Kernel module definition. */ | /* Kernel module definition. */ | |||||||||
#ifdef _KERNEL | #ifdef _KERNEL | |||||||||
MALLOC_DEFINE(M_ALIAS, "libalias", "packet aliasing"); | MALLOC_DEFINE(M_ALIAS, "libalias", "packet aliasing"); | |||||||||
MODULE_VERSION(libalias, 1); | MODULE_VERSION(libalias, 1); | |||||||||
static int | static int | |||||||||
▲ Show 20 Lines • Show All 1,688 Lines • ▼ Show 20 Lines | HouseKeeping(struct libalias *la) | |||||||||
* | * | |||||||||
* Save system time (seconds) in global variable LibAliasTime | * Save system time (seconds) in global variable LibAliasTime | |||||||||
* for use by other functions. This is done so as not to | * for use by other functions. This is done so as not to | |||||||||
* unnecessarily waste timeline by making system calls. | * unnecessarily waste timeline by making system calls. | |||||||||
* | * | |||||||||
* Reduce the amount of house keeping work substantially by | * Reduce the amount of house keeping work substantially by | |||||||||
* sampling over the packets. | * sampling over the packets. | |||||||||
*/ | */ | |||||||||
if (packet_limit <= 1 || packets % packet_limit == 0) { | if (packets % packet_limit == 0) { | |||||||||
time_t now; | time_t now; | |||||||||
seUnsubmitted Not Done Inline Actions
se: | ||||||||||
#ifdef _KERNEL | #ifdef _KERNEL | |||||||||
now = time_uptime; | now = time_uptime; | |||||||||
#else | #else | |||||||||
now = time(NULL); | now = time(NULL); | |||||||||
#endif | #endif | |||||||||
if (now != LibAliasTime) { | if (now != LibAliasTime) { | |||||||||
seUnsubmitted Not Done Inline Actions
se: | ||||||||||
/* retry three times a second */ | /* retry three times a second */ | |||||||||
packet_limit = packets / 3; | packet_limit = packets / 3 + 10; | |||||||||
seUnsubmitted Not Done Inline Actions
I'd use a different approach, since the suggested one does not work well for very low packet rates. u_long seconds = (u_long)now - (u_long)LibAliasTime; if (seconds != 0) { /* retry three times a second */ packet_limit = packets / (3 * seconds) + 1; packets = 0; LibAliasTime = now; } For the (pathological, but possible) case of a constant rate of 1 packet per second, the packet_limit would be 10, leading to 10 seconds before the modulo calculation results in a value of 0. BEWARE: LibAliasTime is currently of type int, not time_t, and will not be able to hold the value of "now" after 2038, and thus "now != LibAliasTime" will then be always true ... se: I'd use a different approach, since the suggested one does not work well for very low packet… | ||||||||||
packets = 0; | packets = 0; | |||||||||
LibAliasTime = now; | LibAliasTime = now; | |||||||||
} | } | |||||||||
} | } | |||||||||
/* Do a cleanup for the first packets of the new second only */ | /* Do a cleanup for the first packets of the new second only */ | |||||||||
if (packets < (la->udpLinkCount + la->tcpLinkCount)) { | if (packets < (la->udpLinkCount + la->tcpLinkCount)) { | |||||||||
struct alias_link * lnk = TAILQ_FIRST(&la->checkExpire); | struct alias_link * lnk = TAILQ_FIRST(&la->checkExpire); | |||||||||
▲ Show 20 Lines • Show All 693 Lines • Show Last 20 Lines |