Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/libalias/alias_db.c
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | |||||
/* Dummy port number codes used for FindLinkIn/Out() and AddLink(). | /* Dummy port number codes used for FindLinkIn/Out() and AddLink(). | ||||
These constants can be anything except zero, which indicates an | These constants can be anything except zero, which indicates an | ||||
unknown port number. */ | unknown port number. */ | ||||
#define NO_DEST_PORT 1 | #define NO_DEST_PORT 1 | ||||
#define NO_SRC_PORT 1 | #define NO_SRC_PORT 1 | ||||
/* Dummy address used for FindLinkIn/Out() and AddLink(). | |||||
hselasky: Should it be:
static const struct in_addr ??? | |||||
Done Inline ActionsThe compiler had the same question. Thank you for spotting this. donner: The compiler had the same question. Thank you for spotting this. | |||||
The value of this variable is never used. */ | |||||
static struct in_addr const NO_ADDR; | |||||
Done Inline ActionsShould you also add "const" keyword here? hselasky: Should you also add "const" keyword here? | |||||
Done Inline ActionsYou are right. Added const. donner: You are right. Added const. | |||||
/* Data Structures | /* Data Structures | ||||
The fundamental data structure used in this program is | The fundamental data structure used in this program is | ||||
"struct alias_link". Whenever a TCP connection is made, | "struct alias_link". Whenever a TCP connection is made, | ||||
a UDP datagram is sent out, or an ICMP echo request is made, | a UDP datagram is sent out, or an ICMP echo request is made, | ||||
a link record is made (if it has not already been created). | a link record is made (if it has not already been created). | ||||
The link record is identified by the source address/port | The link record is identified by the source address/port | ||||
and the destination address/port. In the case of an ICMP | and the destination address/port. In the case of an ICMP | ||||
▲ Show 20 Lines • Show All 871 Lines • ▼ Show 20 Lines | _FindLinkOut(struct libalias *la, struct in_addr src_addr, | ||||
} | } | ||||
/* Search for partially specified links. */ | /* Search for partially specified links. */ | ||||
if (lnk == NULL && replace_partial_links) { | if (lnk == NULL && replace_partial_links) { | ||||
if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY) { | if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY) { | ||||
lnk = _FindLinkOut(la, src_addr, dst_addr, src_port, 0, | lnk = _FindLinkOut(la, src_addr, dst_addr, src_port, 0, | ||||
link_type, 0); | link_type, 0); | ||||
if (lnk == NULL) | if (lnk == NULL) | ||||
lnk = _FindLinkOut(la, src_addr, la->nullAddress, src_port, | lnk = _FindLinkOut(la, src_addr, NO_ADDR, src_port, | ||||
dst_port, link_type, 0); | dst_port, link_type, 0); | ||||
} | } | ||||
if (lnk == NULL && | if (lnk == NULL && | ||||
(dst_port != 0 || dst_addr.s_addr != INADDR_ANY)) { | (dst_port != 0 || dst_addr.s_addr != INADDR_ANY)) { | ||||
lnk = _FindLinkOut(la, src_addr, la->nullAddress, src_port, 0, | lnk = _FindLinkOut(la, src_addr, NO_ADDR, src_port, 0, | ||||
link_type, 0); | link_type, 0); | ||||
} | } | ||||
if (lnk != NULL) { | if (lnk != NULL) { | ||||
lnk = ReLink(lnk, | lnk = ReLink(lnk, | ||||
src_addr, dst_addr, lnk->alias_addr, | src_addr, dst_addr, lnk->alias_addr, | ||||
src_port, dst_port, lnk->alias_port, | src_port, dst_port, lnk->alias_port, | ||||
link_type); | link_type); | ||||
} | } | ||||
Show All 19 Lines | if (lnk == NULL) { | ||||
/* | /* | ||||
* The following allows permanent links to be specified as | * The following allows permanent links to be specified as | ||||
* using the default source address (i.e. device interface | * using the default source address (i.e. device interface | ||||
* address) without knowing in advance what that address | * address) without knowing in advance what that address | ||||
* is. | * is. | ||||
*/ | */ | ||||
if (la->aliasAddress.s_addr != INADDR_ANY && | if (la->aliasAddress.s_addr != INADDR_ANY && | ||||
src_addr.s_addr == la->aliasAddress.s_addr) { | src_addr.s_addr == la->aliasAddress.s_addr) { | ||||
lnk = _FindLinkOut(la, la->nullAddress, dst_addr, src_port, dst_port, | lnk = _FindLinkOut(la, NO_ADDR, dst_addr, src_port, dst_port, | ||||
link_type, replace_partial_links); | link_type, replace_partial_links); | ||||
} | } | ||||
} | } | ||||
return (lnk); | return (lnk); | ||||
} | } | ||||
static struct alias_link * | static struct alias_link * | ||||
_FindLinkIn(struct libalias *la, struct in_addr dst_addr, | _FindLinkIn(struct libalias *la, struct in_addr dst_addr, | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | if (lnk == NULL) { | ||||
/* | /* | ||||
* The following allows permanent links to be specified as | * The following allows permanent links to be specified as | ||||
* using the default aliasing address (i.e. device | * using the default aliasing address (i.e. device | ||||
* interface address) without knowing in advance what that | * interface address) without knowing in advance what that | ||||
* address is. | * address is. | ||||
*/ | */ | ||||
if (la->aliasAddress.s_addr != INADDR_ANY && | if (la->aliasAddress.s_addr != INADDR_ANY && | ||||
alias_addr.s_addr == la->aliasAddress.s_addr) { | alias_addr.s_addr == la->aliasAddress.s_addr) { | ||||
lnk = _FindLinkIn(la, dst_addr, la->nullAddress, dst_port, alias_port, | lnk = _FindLinkIn(la, dst_addr, NO_ADDR, dst_port, alias_port, | ||||
link_type, replace_partial_links); | link_type, replace_partial_links); | ||||
} | } | ||||
} | } | ||||
return (lnk); | return (lnk); | ||||
} | } | ||||
/* External routines for finding/adding links | /* External routines for finding/adding links | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | FindFragmentIn1(struct libalias *la, struct in_addr dst_addr, | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
lnk = FindLinkIn(la, dst_addr, alias_addr, | lnk = FindLinkIn(la, dst_addr, alias_addr, | ||||
NO_DEST_PORT, ip_id, | NO_DEST_PORT, ip_id, | ||||
LINK_FRAGMENT_ID, 0); | LINK_FRAGMENT_ID, 0); | ||||
if (lnk == NULL) { | if (lnk == NULL) { | ||||
lnk = AddLink(la, la->nullAddress, dst_addr, alias_addr, | lnk = AddLink(la, NO_ADDR, dst_addr, alias_addr, | ||||
NO_SRC_PORT, NO_DEST_PORT, ip_id, | NO_SRC_PORT, NO_DEST_PORT, ip_id, | ||||
LINK_FRAGMENT_ID); | LINK_FRAGMENT_ID); | ||||
} | } | ||||
return (lnk); | return (lnk); | ||||
} | } | ||||
/* Doesn't add a link if one is not found. */ | /* Doesn't add a link if one is not found. */ | ||||
struct alias_link * | struct alias_link * | ||||
FindFragmentIn2(struct libalias *la, struct in_addr dst_addr, | FindFragmentIn2(struct libalias *la, struct in_addr dst_addr, | ||||
struct in_addr alias_addr, u_short ip_id) | struct in_addr alias_addr, u_short ip_id) | ||||
{ | { | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
return FindLinkIn(la, dst_addr, alias_addr, | return FindLinkIn(la, dst_addr, alias_addr, | ||||
NO_DEST_PORT, ip_id, | NO_DEST_PORT, ip_id, | ||||
LINK_FRAGMENT_ID, 0); | LINK_FRAGMENT_ID, 0); | ||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
AddFragmentPtrLink(struct libalias *la, struct in_addr dst_addr, | AddFragmentPtrLink(struct libalias *la, struct in_addr dst_addr, | ||||
u_short ip_id) | u_short ip_id) | ||||
{ | { | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
return AddLink(la, la->nullAddress, dst_addr, la->nullAddress, | return AddLink(la, NO_ADDR, dst_addr, NO_ADDR, | ||||
NO_SRC_PORT, NO_DEST_PORT, ip_id, | NO_SRC_PORT, NO_DEST_PORT, ip_id, | ||||
LINK_FRAGMENT_PTR); | LINK_FRAGMENT_PTR); | ||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
FindFragmentPtr(struct libalias *la, struct in_addr dst_addr, | FindFragmentPtr(struct libalias *la, struct in_addr dst_addr, | ||||
u_short ip_id) | u_short ip_id) | ||||
{ | { | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
return FindLinkIn(la, dst_addr, la->nullAddress, | return FindLinkIn(la, dst_addr, NO_ADDR, | ||||
NO_DEST_PORT, ip_id, | NO_DEST_PORT, ip_id, | ||||
LINK_FRAGMENT_PTR, 0); | LINK_FRAGMENT_PTR, 0); | ||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
FindProtoIn(struct libalias *la, struct in_addr dst_addr, | FindProtoIn(struct libalias *la, struct in_addr dst_addr, | ||||
struct in_addr alias_addr, | struct in_addr alias_addr, | ||||
u_char proto) | u_char proto) | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
struct in_addr | struct in_addr | ||||
FindOriginalAddress(struct libalias *la, struct in_addr alias_addr) | FindOriginalAddress(struct libalias *la, struct in_addr alias_addr) | ||||
{ | { | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
lnk = FindLinkIn(la, la->nullAddress, alias_addr, | lnk = FindLinkIn(la, NO_ADDR, alias_addr, | ||||
0, 0, LINK_ADDR, 0); | 0, 0, LINK_ADDR, 0); | ||||
if (lnk == NULL) { | if (lnk == NULL) { | ||||
la->newDefaultLink = 1; | la->newDefaultLink = 1; | ||||
if (la->targetAddress.s_addr == INADDR_ANY) | if (la->targetAddress.s_addr == INADDR_ANY) | ||||
return (alias_addr); | return (alias_addr); | ||||
else if (la->targetAddress.s_addr == INADDR_NONE) | else if (la->targetAddress.s_addr == INADDR_NONE) | ||||
return (la->aliasAddress.s_addr != INADDR_ANY) ? | return (la->aliasAddress.s_addr != INADDR_ANY) ? | ||||
la->aliasAddress : alias_addr; | la->aliasAddress : alias_addr; | ||||
Show All 15 Lines | |||||
} | } | ||||
struct in_addr | struct in_addr | ||||
FindAliasAddress(struct libalias *la, struct in_addr original_addr) | FindAliasAddress(struct libalias *la, struct in_addr original_addr) | ||||
{ | { | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
lnk = FindLinkOut(la, original_addr, la->nullAddress, | lnk = FindLinkOut(la, original_addr, NO_ADDR, | ||||
0, 0, LINK_ADDR, 0); | 0, 0, LINK_ADDR, 0); | ||||
if (lnk == NULL) { | if (lnk == NULL) { | ||||
return (la->aliasAddress.s_addr != INADDR_ANY) ? | return (la->aliasAddress.s_addr != INADDR_ANY) ? | ||||
la->aliasAddress : original_addr; | la->aliasAddress : original_addr; | ||||
} else { | } else { | ||||
if (lnk->alias_addr.s_addr == INADDR_ANY) | if (lnk->alias_addr.s_addr == INADDR_ANY) | ||||
return (la->aliasAddress.s_addr != INADDR_ANY) ? | return (la->aliasAddress.s_addr != INADDR_ANY) ? | ||||
la->aliasAddress : original_addr; | la->aliasAddress : original_addr; | ||||
▲ Show 20 Lines • Show All 599 Lines • ▼ Show 20 Lines | |||||
/* Static address translation */ | /* Static address translation */ | ||||
struct alias_link * | struct alias_link * | ||||
LibAliasRedirectAddr(struct libalias *la, struct in_addr src_addr, | LibAliasRedirectAddr(struct libalias *la, struct in_addr src_addr, | ||||
struct in_addr alias_addr) | struct in_addr alias_addr) | ||||
{ | { | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK(la); | LIBALIAS_LOCK(la); | ||||
lnk = AddLink(la, src_addr, la->nullAddress, alias_addr, | lnk = AddLink(la, src_addr, NO_ADDR, alias_addr, | ||||
0, 0, 0, | 0, 0, 0, | ||||
LINK_ADDR); | LINK_ADDR); | ||||
if (lnk != NULL) { | if (lnk != NULL) { | ||||
lnk->flags |= LINK_PERMANENT; | lnk->flags |= LINK_PERMANENT; | ||||
} | } | ||||
#ifdef LIBALIAS_DEBUG | #ifdef LIBALIAS_DEBUG | ||||
else { | else { | ||||
▲ Show 20 Lines • Show All 522 Lines • Show Last 20 Lines |
Should it be:
static const struct in_addr ???