Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/libalias/alias_db.c
Show First 20 Lines • Show All 590 Lines • ▼ Show 20 Lines | */ | ||||
if (alias_port_param == GET_ALIAS_PORT) { | if (alias_port_param == GET_ALIAS_PORT) { | ||||
/* | /* | ||||
* The aliasing port is automatically selected by one of | * The aliasing port is automatically selected by one of | ||||
* two methods below: | * two methods below: | ||||
*/ | */ | ||||
max_trials = GET_NEW_PORT_MAX_ATTEMPTS; | max_trials = GET_NEW_PORT_MAX_ATTEMPTS; | ||||
if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS) { | if (la->packetAliasMode & PKT_ALIAS_SAME_PORTS) { | ||||
donner: So PKT_ALIAS_SAME_PORT is incompatible with port ranges?
Can we prevent setting both flags with… | |||||
/* | /* | ||||
* When the PKT_ALIAS_SAME_PORTS option is chosen, | * When the PKT_ALIAS_SAME_PORTS option is chosen, | ||||
* the first try will be the actual source port. If | * the first try will be the actual source port. If | ||||
* this is already in use, the remainder of the | * this is already in use, the remainder of the | ||||
* trials will be random. | * trials will be random. | ||||
*/ | */ | ||||
port_net = lnk->src_port; | port_net = lnk->src_port; | ||||
port_sys = ntohs(port_net); | port_sys = ntohs(port_net); | ||||
} else if (la->portRange.lower && la->portRange.upper) { | |||||
Done Inline ActionsWhy do we need to check for both lower and upper in fast path? melifaro: Why do we need to check for both lower and upper in fast path? | |||||
/* First trial is a random port in the aliasing range. */ | |||||
port_sys = la->portRange.lower + (arc4random() % | |||||
(la->portRange.upper - la->portRange.lower)); | |||||
Done Inline ActionsIn terms of performance, it would be interesting to replace "Upper" with a precomputed "Range" or "Length". This part is used for ever new flow (very often). For printing the configuration, the "Upper" value an be synthesized on demand. donner: In terms of performance, it would be interesting to replace "Upper" with a precomputed "Range"… | |||||
port_net = htons(port_sys); | |||||
} else { | } else { | ||||
/* First trial and all subsequent are random. */ | /* First trial and all subsequent are random. */ | ||||
port_sys = arc4random() & ALIAS_PORT_MASK; | port_sys = arc4random() & ALIAS_PORT_MASK; | ||||
port_sys += ALIAS_PORT_BASE; | port_sys += ALIAS_PORT_BASE; | ||||
port_net = htons(port_sys); | port_net = htons(port_sys); | ||||
} | } | ||||
} else if (alias_port_param >= 0 && alias_port_param < 0x10000) { | } else if (alias_port_param >= 0 && alias_port_param < 0x10000) { | ||||
lnk->alias_port = (u_short) alias_port_param; | lnk->alias_port = (u_short) alias_port_param; | ||||
Show All 37 Lines | #ifndef NO_USE_SOCKETS | ||||
} else { | } else { | ||||
#endif | #endif | ||||
lnk->alias_port = port_net; | lnk->alias_port = port_net; | ||||
return (0); | return (0); | ||||
#ifndef NO_USE_SOCKETS | #ifndef NO_USE_SOCKETS | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
if (la->portRange.lower && la->portRange.upper) { | |||||
port_sys = la->portRange.lower + (arc4random() % | |||||
(la->portRange.upper - la->portRange.lower)); | |||||
port_net = htons(port_sys); | |||||
} else { | |||||
port_sys = arc4random() & ALIAS_PORT_MASK; | port_sys = arc4random() & ALIAS_PORT_MASK; | ||||
port_sys += ALIAS_PORT_BASE; | port_sys += ALIAS_PORT_BASE; | ||||
port_net = htons(port_sys); | port_net = htons(port_sys); | ||||
} | } | ||||
} | |||||
#ifdef LIBALIAS_DEBUG | #ifdef LIBALIAS_DEBUG | ||||
fprintf(stderr, "PacketAlias/GetNewPort(): "); | fprintf(stderr, "PacketAlias/GetNewPort(): "); | ||||
fprintf(stderr, "could not find free port\n"); | fprintf(stderr, "could not find free port\n"); | ||||
#endif | #endif | ||||
return (-1); | return (-1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,765 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
LIBALIAS_LOCK(la); | LIBALIAS_LOCK(la); | ||||
if (la->packetAliasMode & PKT_ALIAS_RESET_ON_ADDR_CHANGE | if (la->packetAliasMode & PKT_ALIAS_RESET_ON_ADDR_CHANGE | ||||
&& la->aliasAddress.s_addr != addr.s_addr) | && la->aliasAddress.s_addr != addr.s_addr) | ||||
CleanupAliasData(la); | CleanupAliasData(la); | ||||
la->aliasAddress = addr; | la->aliasAddress = addr; | ||||
LIBALIAS_UNLOCK(la); | |||||
} | |||||
void | |||||
LibAliasSetAliasPortRange(struct libalias *la, u_short port_low, | |||||
u_short port_high) | |||||
{ | |||||
LIBALIAS_LOCK(la); | |||||
la->portRange.lower = port_low; | |||||
la->portRange.upper = port_high; | |||||
LIBALIAS_UNLOCK(la); | LIBALIAS_UNLOCK(la); | ||||
} | } | ||||
void | void | ||||
LibAliasSetTarget(struct libalias *la, struct in_addr target_addr) | LibAliasSetTarget(struct libalias *la, struct in_addr target_addr) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 466 Lines • Show Last 20 Lines |
So PKT_ALIAS_SAME_PORT is incompatible with port ranges?
Can we prevent setting both flags with an error message in parsing the config?