From 09e9a903dfe557f92bab66940e04cf126f5f2407 Mon Sep 17 00:00:00 2001 From: ru Date: Sun, 1 Jun 2003 22:49:59 +0000 Subject: Make the PacketAliasSetAddress() function call optional. If it is not called, and no static rules match an outgoing packet, the latter retains its source IP address. This is in support of the "static NAT only" mode. --- lib/libalias/alias_db.c | 16 ++++++++++------ lib/libalias/libalias.3 | 13 ++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'lib/libalias') diff --git a/lib/libalias/alias_db.c b/lib/libalias/alias_db.c index e3aab97..1b59b05 100644 --- a/lib/libalias/alias_db.c +++ b/lib/libalias/alias_db.c @@ -1239,7 +1239,7 @@ FindLinkOut(struct in_addr src_addr, specified as using the default source address (i.e. device interface address) without knowing in advance what that address is. */ - if (aliasAddress.s_addr != 0 && + if (aliasAddress.s_addr != INADDR_ANY && src_addr.s_addr == aliasAddress.s_addr) { link = _FindLinkOut(nullAddress, dst_addr, src_port, dst_port, @@ -1395,7 +1395,7 @@ FindLinkIn(struct in_addr dst_addr, specified as using the default aliasing address (i.e. device interface address) without knowing in advance what that address is. */ - if (aliasAddress.s_addr != 0 && + if (aliasAddress.s_addr != INADDR_ANY && alias_addr.s_addr == aliasAddress.s_addr) { link = _FindLinkIn(dst_addr, nullAddress, dst_port, alias_port, @@ -1805,7 +1805,8 @@ FindOriginalAddress(struct in_addr alias_addr) if (targetAddress.s_addr == INADDR_ANY) return alias_addr; else if (targetAddress.s_addr == INADDR_NONE) - return aliasAddress; + return (aliasAddress.s_addr != INADDR_ANY) ? + aliasAddress : alias_addr; else return targetAddress; } @@ -1818,7 +1819,8 @@ FindOriginalAddress(struct in_addr alias_addr) link->server = link->server->next; return (src_addr); } else if (link->src_addr.s_addr == INADDR_ANY) - return aliasAddress; + return (aliasAddress.s_addr != INADDR_ANY) ? + aliasAddress : alias_addr; else return link->src_addr; } @@ -1834,12 +1836,14 @@ FindAliasAddress(struct in_addr original_addr) 0, 0, LINK_ADDR, 0); if (link == NULL) { - return aliasAddress; + return (aliasAddress.s_addr != INADDR_ANY) ? + aliasAddress : original_addr; } else { if (link->alias_addr.s_addr == INADDR_ANY) - return aliasAddress; + return (aliasAddress.s_addr != INADDR_ANY) ? + aliasAddress : original_addr; else return link->alias_addr; } diff --git a/lib/libalias/libalias.3 b/lib/libalias/libalias.3 index cd8b97c..71735b2 100644 --- a/lib/libalias/libalias.3 +++ b/lib/libalias/libalias.3 @@ -66,11 +66,12 @@ The packet aliasing engine was designed to operate in user space outside of the kernel, without any access to private kernel data structure, but the source code can also be ported to a kernel environment. .Sh INITIALIZATION AND CONTROL -Two special functions, -.Fn PacketAliasInit -and -.Fn PacketAliasSetAddress , +One special function, +.Fn PacketAliasInit , must always be called before any packet handling may be performed. +Normally, the +.Fn PacketAliasSetAddress +function is called afterwards, to set the default aliasing address. In addition, the operating mode of the packet aliasing engine can be customized by calling .Fn PacketAliasSetMode . @@ -98,7 +99,7 @@ below for the meaning of these mode bits. This function will always return the packet aliasing engine to the same initial state. .Fn PacketAliasSetAddress -must be called afterwards, and any desired changes from the default mode +is normally called afterwards, and any desired changes from the default mode bits listed above require a call to .Fn PacketAliasSetMode . .Pp @@ -130,6 +131,8 @@ local area network are aliased. All outgoing packets are re-mapped to this address unless overridden by a static address mapping established by .Fn PacketAliasRedirectAddr . +If this function is not called, and no static rules match, an outgoing +packet retains its source address. .Pp If the .Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE -- cgit v1.1