o Support a compile-time -DNO_FW_PUNCH for portability

(and those of us that don't want the functionality).
o Don't assume sizeof(long) == 4.
Ok'd by: Charles Mott <cmott@srv.net>
This commit is contained in:
Brian Somers 1998-04-19 21:42:07 +00:00
parent 6493d9f3bb
commit 9feab75ab7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35314
8 changed files with 46 additions and 8 deletions

View File

@ -318,12 +318,12 @@ IcmpAliasIn2(struct ip *pip)
link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
tc->th_dport, tc->th_sport,
IPPROTO_TCP);
else if (ip->ip_p == IPPROTO_ICMP)
else if (ip->ip_p == IPPROTO_ICMP) {
if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id);
else
link = NULL;
else
} else
link = NULL;
if (link != NULL)

View File

@ -7,7 +7,7 @@
This software is placed into the public domain with no restrictions
on its distribution.
$Id$
$Id: alias.h,v 1.7 1998/01/16 12:56:07 bde Exp $
*/
@ -36,8 +36,10 @@ struct alias_link;
extern unsigned int
PacketAliasSetMode(unsigned int, unsigned int);
#ifndef NO_FW_PUNCH
extern void
PacketAliasSetFWBase(unsigned int, unsigned int);
#endif
/* Packet Handling */
extern int
@ -150,6 +152,7 @@ extern u_short InternetChecksum(u_short *, int);
bit is set after a call to PacketAliasInit(). */
#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
#ifndef NO_FW_PUNCH
/* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
will create a 'hole' in the firewall to allow the transfers to
work. Where (IPFW "line-numbers") the hole is created is
@ -157,6 +160,7 @@ extern u_short InternetChecksum(u_short *, int);
attached to that particular alias_link, so when the link goes away
so do the hole. */
#define PKT_ALIAS_PUNCH_FW 0x40
#endif
/* Return Codes */
#define PKT_ALIAS_ERROR -1

View File

@ -340,11 +340,13 @@ static int newDefaultLink; /* Indicates if a new aliasing */
/* link has been created after a */
/* call to PacketAliasIn/Out(). */
#ifndef NO_FW_PUNCH
static int fireWallFD = -1; /* File descriptor to be able to */
/* control firewall. Opened by */
/* PacketAliasSetMode on first */
/* setting the PKT_ALIAS_PUNCH_FW */
/* flag. */
#endif
@ -375,10 +377,12 @@ static int SeqDiff(u_long, u_long);
static void ShowAliasStats(void);
#ifndef NO_FW_PUNCH
/* Firewall control */
static void InitPunchFW(void);
static void UninitPunchFW(void);
static void ClearFWHole(struct alias_link *link);
#endif
/* Log file control */
static void InitPacketAliasLog(void);
@ -750,8 +754,10 @@ DeleteLink(struct alias_link *link)
if (deleteAllLinks == 0 && link->flags & LINK_PERMANENT)
return;
#ifndef NO_FW_PUNCH
/* Delete associatied firewall hole, if any */
ClearFWHole(link);
#endif
/* Adjust output table pointers */
link_last = link->last_out;
@ -987,12 +993,14 @@ ReLink(struct alias_link *old_link,
new_link = AddLink(src_addr, dst_addr, alias_addr,
src_port, dst_port, alias_port_param,
link_type);
#ifndef NO_FW_PUNCH
if (new_link != NULL &&
old_link->link_type == LINK_TCP &&
old_link->data.tcp &&
old_link->data.tcp->fwhole > 0) {
PunchFWHole(new_link);
}
#endif
DeleteLink(old_link);
return new_link;
}
@ -2005,7 +2013,9 @@ PacketAliasUninit(void) {
CleanupAliasData();
deleteAllLinks = 0;
UninitPacketAliasLog();
#ifndef NO_FW_PUNCH
UninitPunchFW();
#endif
}
@ -2027,6 +2037,7 @@ PacketAliasSetMode(
UninitPacketAliasLog();
}
#ifndef NO_FW_PUNCH
/* Start punching holes in the firewall? */
if (flags & mask & PKT_ALIAS_PUNCH_FW) {
InitPunchFW();
@ -2035,6 +2046,7 @@ PacketAliasSetMode(
if (~flags & mask & PKT_ALIAS_PUNCH_FW) {
UninitPunchFW();
}
#endif
/* Other flags can be set/cleared without special action */
packetAliasMode = (flags & mask) | (packetAliasMode & ~mask);
@ -2049,6 +2061,8 @@ PacketAliasCheckNewLink(void)
}
#ifndef NO_FW_PUNCH
/*****************
Code to support firewall punching. This shouldn't really be in this
file, but making variables global is evil too.
@ -2222,3 +2236,4 @@ ClearAllFWHoles(void) {
}
memset(fireWallField, 0, fireWallNumNums);
}
#endif

View File

@ -229,7 +229,7 @@ lFOUND_CTCP:
alias_address = GetAliasAddress(link);
iCopy += snprintf(&newpacket[iCopy],
sizeof(newpacket)-iCopy,
"%lu ", htonl(alias_address.s_addr));
"%lu ", (u_long)htonl(alias_address.s_addr));
if( iCopy >= sizeof(newpacket) ) { /* Truncated/fit exactly - bad news */
DBprintf(("DCC constructed packet overflow.\n"));
goto lBAD_CTCP;

View File

@ -318,12 +318,12 @@ IcmpAliasIn2(struct ip *pip)
link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
tc->th_dport, tc->th_sport,
IPPROTO_TCP);
else if (ip->ip_p == IPPROTO_ICMP)
else if (ip->ip_p == IPPROTO_ICMP) {
if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id);
else
link = NULL;
else
} else
link = NULL;
if (link != NULL)

View File

@ -7,7 +7,7 @@
This software is placed into the public domain with no restrictions
on its distribution.
$Id$
$Id: alias.h,v 1.7 1998/01/16 12:56:07 bde Exp $
*/
@ -36,8 +36,10 @@ struct alias_link;
extern unsigned int
PacketAliasSetMode(unsigned int, unsigned int);
#ifndef NO_FW_PUNCH
extern void
PacketAliasSetFWBase(unsigned int, unsigned int);
#endif
/* Packet Handling */
extern int
@ -150,6 +152,7 @@ extern u_short InternetChecksum(u_short *, int);
bit is set after a call to PacketAliasInit(). */
#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
#ifndef NO_FW_PUNCH
/* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
will create a 'hole' in the firewall to allow the transfers to
work. Where (IPFW "line-numbers") the hole is created is
@ -157,6 +160,7 @@ extern u_short InternetChecksum(u_short *, int);
attached to that particular alias_link, so when the link goes away
so do the hole. */
#define PKT_ALIAS_PUNCH_FW 0x40
#endif
/* Return Codes */
#define PKT_ALIAS_ERROR -1

View File

@ -340,11 +340,13 @@ static int newDefaultLink; /* Indicates if a new aliasing */
/* link has been created after a */
/* call to PacketAliasIn/Out(). */
#ifndef NO_FW_PUNCH
static int fireWallFD = -1; /* File descriptor to be able to */
/* control firewall. Opened by */
/* PacketAliasSetMode on first */
/* setting the PKT_ALIAS_PUNCH_FW */
/* flag. */
#endif
@ -375,10 +377,12 @@ static int SeqDiff(u_long, u_long);
static void ShowAliasStats(void);
#ifndef NO_FW_PUNCH
/* Firewall control */
static void InitPunchFW(void);
static void UninitPunchFW(void);
static void ClearFWHole(struct alias_link *link);
#endif
/* Log file control */
static void InitPacketAliasLog(void);
@ -750,8 +754,10 @@ DeleteLink(struct alias_link *link)
if (deleteAllLinks == 0 && link->flags & LINK_PERMANENT)
return;
#ifndef NO_FW_PUNCH
/* Delete associatied firewall hole, if any */
ClearFWHole(link);
#endif
/* Adjust output table pointers */
link_last = link->last_out;
@ -987,12 +993,14 @@ ReLink(struct alias_link *old_link,
new_link = AddLink(src_addr, dst_addr, alias_addr,
src_port, dst_port, alias_port_param,
link_type);
#ifndef NO_FW_PUNCH
if (new_link != NULL &&
old_link->link_type == LINK_TCP &&
old_link->data.tcp &&
old_link->data.tcp->fwhole > 0) {
PunchFWHole(new_link);
}
#endif
DeleteLink(old_link);
return new_link;
}
@ -2005,7 +2013,9 @@ PacketAliasUninit(void) {
CleanupAliasData();
deleteAllLinks = 0;
UninitPacketAliasLog();
#ifndef NO_FW_PUNCH
UninitPunchFW();
#endif
}
@ -2027,6 +2037,7 @@ PacketAliasSetMode(
UninitPacketAliasLog();
}
#ifndef NO_FW_PUNCH
/* Start punching holes in the firewall? */
if (flags & mask & PKT_ALIAS_PUNCH_FW) {
InitPunchFW();
@ -2035,6 +2046,7 @@ PacketAliasSetMode(
if (~flags & mask & PKT_ALIAS_PUNCH_FW) {
UninitPunchFW();
}
#endif
/* Other flags can be set/cleared without special action */
packetAliasMode = (flags & mask) | (packetAliasMode & ~mask);
@ -2049,6 +2061,8 @@ PacketAliasCheckNewLink(void)
}
#ifndef NO_FW_PUNCH
/*****************
Code to support firewall punching. This shouldn't really be in this
file, but making variables global is evil too.
@ -2222,3 +2236,4 @@ ClearAllFWHoles(void) {
}
memset(fireWallField, 0, fireWallNumNums);
}
#endif

View File

@ -229,7 +229,7 @@ lFOUND_CTCP:
alias_address = GetAliasAddress(link);
iCopy += snprintf(&newpacket[iCopy],
sizeof(newpacket)-iCopy,
"%lu ", htonl(alias_address.s_addr));
"%lu ", (u_long)htonl(alias_address.s_addr));
if( iCopy >= sizeof(newpacket) ) { /* Truncated/fit exactly - bad news */
DBprintf(("DCC constructed packet overflow.\n"));
goto lBAD_CTCP;