Make partially specified permanent links without `dst_addr'

but with `dst_port' work for outgoing packets.

This case was not handled properly when I first fixed this
in revision 1.17.

This change is also required for the upcoming improved PPTP
support patches -- that is how I found the problem.

Before this change:

# natd -v -a aliasIP \
  -redirect_port tcp localIP:localPORT publicIP:publicPORT 0:remotePORT

Out [TCP]  [TCP] localIP:localPORT -> remoteIP:remotePORT aliased to
           [TCP] aliasIP:localPORT -> remoteIP:remotePORT

After this change:

# natd -v -a aliasIP \
  -redirect_port tcp localIP:localPORT publicIP:publicPORT 0:remotePORT

Out [TCP]  [TCP] localIP:localPORT -> remoteIP:remotePORT aliased to
           [TCP] publicIP:publicPORT -> remoteIP:remotePORT
This commit is contained in:
Ruslan Ermilov 2000-04-12 18:44:50 +00:00
parent 70c1e1b6d9
commit f167e54283
2 changed files with 30 additions and 22 deletions

View File

@ -1046,25 +1046,29 @@ _FindLinkOut(struct in_addr src_addr,
}
/* Search for partially specified links. */
if (link == NULL)
if (link == NULL && replace_partial_links)
{
if (dst_port != 0)
if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY)
{
link = _FindLinkOut(src_addr, dst_addr, src_port, 0,
link_type, 0);
if (link != NULL && replace_partial_links)
{
link = ReLink(link,
src_addr, dst_addr, link->alias_addr,
src_port, dst_port, link->alias_port,
link_type);
}
if (link == NULL)
link = _FindLinkOut(src_addr, nullAddress, src_port,
dst_port, link_type, 0);
}
else if (dst_addr.s_addr != 0)
if (link == NULL &&
(dst_port != 0 || dst_addr.s_addr != INADDR_ANY))
{
link = _FindLinkOut(src_addr, nullAddress, src_port, 0,
link_type, 0);
}
if (link != NULL)
{
link = ReLink(link,
src_addr, dst_addr, link->alias_addr,
src_port, dst_port, link->alias_port,
link_type);
}
}
return(link);
@ -1228,7 +1232,7 @@ _FindLinkIn(struct in_addr dst_addr,
}
}
struct alias_link *
static struct alias_link *
FindLinkIn(struct in_addr dst_addr,
struct in_addr alias_addr,
u_short dst_port,

View File

@ -1046,25 +1046,29 @@ _FindLinkOut(struct in_addr src_addr,
}
/* Search for partially specified links. */
if (link == NULL)
if (link == NULL && replace_partial_links)
{
if (dst_port != 0)
if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY)
{
link = _FindLinkOut(src_addr, dst_addr, src_port, 0,
link_type, 0);
if (link != NULL && replace_partial_links)
{
link = ReLink(link,
src_addr, dst_addr, link->alias_addr,
src_port, dst_port, link->alias_port,
link_type);
}
if (link == NULL)
link = _FindLinkOut(src_addr, nullAddress, src_port,
dst_port, link_type, 0);
}
else if (dst_addr.s_addr != 0)
if (link == NULL &&
(dst_port != 0 || dst_addr.s_addr != INADDR_ANY))
{
link = _FindLinkOut(src_addr, nullAddress, src_port, 0,
link_type, 0);
}
if (link != NULL)
{
link = ReLink(link,
src_addr, dst_addr, link->alias_addr,
src_port, dst_port, link->alias_port,
link_type);
}
}
return(link);
@ -1228,7 +1232,7 @@ _FindLinkIn(struct in_addr dst_addr,
}
}
struct alias_link *
static struct alias_link *
FindLinkIn(struct in_addr dst_addr,
struct in_addr alias_addr,
u_short dst_port,