Run through indent(1) so I can read the code without getting a headache.
The result isn't quite knf, but it's knfer than the original, and far more consistent.
This commit is contained in:
parent
f02660b050
commit
f0f93429cf
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127094
@ -1,5 +1,3 @@
|
||||
/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 Charles Mott <cm@linktel.net>
|
||||
* All rights reserved.
|
||||
@ -165,8 +163,7 @@ TcpMonitorIn(struct ip *pip, struct alias_link *link)
|
||||
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
switch (GetStateIn(link))
|
||||
{
|
||||
switch (GetStateIn(link)) {
|
||||
case ALIAS_TCP_STATE_NOT_CONNECTED:
|
||||
if (tc->th_flags & TH_RST)
|
||||
SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED);
|
||||
@ -187,8 +184,7 @@ TcpMonitorOut(struct ip *pip, struct alias_link *link)
|
||||
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
switch (GetStateOut(link))
|
||||
{
|
||||
switch (GetStateOut(link)) {
|
||||
case ALIAS_TCP_STATE_NOT_CONNECTED:
|
||||
if (tc->th_flags & TH_RST)
|
||||
SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED);
|
||||
@ -279,8 +275,7 @@ IcmpAliasIn1(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* Get source address from ICMP data field and restore original data */
|
||||
link = FindIcmpIn(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short original_id;
|
||||
int accumulate;
|
||||
|
||||
@ -347,10 +342,8 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
|
||||
} else
|
||||
link = NULL;
|
||||
|
||||
if (link != NULL)
|
||||
{
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate, accumulate2;
|
||||
struct in_addr original_address;
|
||||
@ -385,9 +378,7 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
|
||||
fragment contained in ICMP data section */
|
||||
ip->ip_src = original_address;
|
||||
ud->uh_sport = original_port;
|
||||
}
|
||||
else if (ip->ip_p == IPPROTO_ICMP)
|
||||
{
|
||||
} else if (ip->ip_p == IPPROTO_ICMP) {
|
||||
u_short *sptr;
|
||||
int accumulate, accumulate2;
|
||||
struct in_addr original_address;
|
||||
@ -442,12 +433,10 @@ IcmpAliasIn(struct libalias *la, struct ip *pip)
|
||||
ic = (struct icmp *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
switch (ic->icmp_type)
|
||||
{
|
||||
switch (ic->icmp_type) {
|
||||
case ICMP_ECHOREPLY:
|
||||
case ICMP_TSTAMPREPLY:
|
||||
if (ic->icmp_code == 0)
|
||||
{
|
||||
if (ic->icmp_code == 0) {
|
||||
iresult = IcmpAliasIn1(la, pip);
|
||||
}
|
||||
break;
|
||||
@ -480,8 +469,7 @@ IcmpAliasOut1(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* Save overwritten data for when echo packet returns */
|
||||
link = FindIcmpOut(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_id;
|
||||
int accumulate;
|
||||
|
||||
@ -549,10 +537,8 @@ IcmpAliasOut2(struct libalias *la, struct ip *pip)
|
||||
} else
|
||||
link = NULL;
|
||||
|
||||
if (link != NULL)
|
||||
{
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr alias_address;
|
||||
@ -583,14 +569,11 @@ IcmpAliasOut2(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_src = alias_address;
|
||||
}
|
||||
|
||||
/* Alias address and port number of original IP packet
|
||||
fragment contained in ICMP data section */
|
||||
ip->ip_dst = alias_address;
|
||||
ud->uh_dport = alias_port;
|
||||
}
|
||||
else if (ip->ip_p == IPPROTO_ICMP)
|
||||
{
|
||||
} else if (ip->ip_p == IPPROTO_ICMP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr alias_address;
|
||||
@ -621,7 +604,6 @@ fragment contained in ICMP data section */
|
||||
2);
|
||||
pip->ip_src = alias_address;
|
||||
}
|
||||
|
||||
/* Alias address of original IP packet and sequence number of
|
||||
embedded ICMP datagram */
|
||||
ip->ip_dst = alias_address;
|
||||
@ -646,12 +628,10 @@ IcmpAliasOut(struct libalias *la, struct ip *pip)
|
||||
ic = (struct icmp *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
switch (ic->icmp_type)
|
||||
{
|
||||
switch (ic->icmp_type) {
|
||||
case ICMP_ECHO:
|
||||
case ICMP_TSTAMP:
|
||||
if (ic->icmp_code == 0)
|
||||
{
|
||||
if (ic->icmp_code == 0) {
|
||||
iresult = IcmpAliasOut1(la, pip);
|
||||
}
|
||||
break;
|
||||
@ -686,8 +666,7 @@ ProtoAliasIn(struct libalias *la, struct ip *pip)
|
||||
return PKT_ALIAS_OK;
|
||||
|
||||
link = FindProtoIn(la, pip->ip_src, pip->ip_dst, pip->ip_p);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr original_address;
|
||||
|
||||
original_address = GetOriginalAddress(link);
|
||||
@ -720,8 +699,7 @@ ProtoAliasOut(struct libalias *la, struct ip *pip)
|
||||
return PKT_ALIAS_OK;
|
||||
|
||||
link = FindProtoOut(la, pip->ip_src, pip->ip_dst, pip->ip_p);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
|
||||
alias_address = GetAliasAddress(link);
|
||||
@ -754,8 +732,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
link = FindUdpTcpIn(la, pip->ip_src, pip->ip_dst,
|
||||
ud->uh_sport, ud->uh_dport,
|
||||
IPPROTO_UDP, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
struct in_addr original_address;
|
||||
u_short alias_port;
|
||||
@ -782,8 +759,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If UDP checksum is not zero, then adjust since destination port */
|
||||
/* is being unaliased and destination address is being altered. */
|
||||
if (ud->uh_sum != 0)
|
||||
{
|
||||
if (ud->uh_sum != 0) {
|
||||
accumulate = alias_port;
|
||||
accumulate -= ud->uh_dport;
|
||||
sptr = (u_short *) & alias_address;
|
||||
@ -794,7 +770,6 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
|
||||
}
|
||||
|
||||
/* Restore original IP address */
|
||||
DifferentialChecksum(&pip->ip_sum,
|
||||
(u_short *) & original_address,
|
||||
@ -828,8 +803,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
|
||||
ud->uh_sport, ud->uh_dport,
|
||||
IPPROTO_UDP, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_port;
|
||||
struct in_addr alias_address;
|
||||
|
||||
@ -858,8 +832,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If UDP checksum is not zero, adjust since source port is */
|
||||
/* being aliased and source address is being altered */
|
||||
if (ud->uh_sum != 0)
|
||||
{
|
||||
if (ud->uh_sum != 0) {
|
||||
int accumulate;
|
||||
u_short *sptr;
|
||||
|
||||
@ -873,7 +846,6 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
|
||||
}
|
||||
|
||||
/* Put alias port in UDP header */
|
||||
ud->uh_sport = alias_port;
|
||||
|
||||
@ -903,8 +875,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
tc->th_sport, tc->th_dport,
|
||||
IPPROTO_TCP,
|
||||
!(la->packetAliasMode & PKT_ALIAS_PROXY_ONLY));
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
struct in_addr original_address;
|
||||
struct in_addr proxy_address;
|
||||
@ -941,8 +912,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If this is a proxy, then modify the TCP source port and
|
||||
checksum accumulation */
|
||||
if (proxy_port != 0)
|
||||
{
|
||||
if (proxy_port != 0) {
|
||||
accumulate += tc->th_sport;
|
||||
tc->th_sport = proxy_port;
|
||||
accumulate -= tc->th_sport;
|
||||
@ -954,15 +924,12 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr++;
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
|
||||
/* See if ACK number needs to be modified */
|
||||
if (GetAckModified(link) == 1)
|
||||
{
|
||||
if (GetAckModified(link) == 1) {
|
||||
int delta;
|
||||
|
||||
delta = GetDeltaAckIn(pip, link);
|
||||
if (delta != 0)
|
||||
{
|
||||
if (delta != 0) {
|
||||
sptr = (u_short *) & tc->th_ack;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -972,7 +939,6 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, tc->th_sum);
|
||||
|
||||
/* Restore original IP address */
|
||||
@ -986,8 +952,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If this is a transparent proxy packet, then modify the source
|
||||
address */
|
||||
if (proxy_address.s_addr != 0)
|
||||
{
|
||||
if (proxy_address.s_addr != 0) {
|
||||
sptr = (u_short *) & pip->ip_src;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -996,7 +961,6 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr++;
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, pip->ip_sum);
|
||||
|
||||
/* Monitor TCP connection state */
|
||||
@ -1029,8 +993,7 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
then alter the destination and adjust checksums */
|
||||
dest_port = tc->th_dport;
|
||||
dest_address = pip->ip_dst;
|
||||
if (proxy_type != 0)
|
||||
{
|
||||
if (proxy_type != 0) {
|
||||
int accumulate;
|
||||
u_short *sptr;
|
||||
|
||||
@ -1057,12 +1020,10 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, pip->ip_sum);
|
||||
}
|
||||
|
||||
link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
|
||||
tc->th_sport, tc->th_dport,
|
||||
IPPROTO_TCP, 1);
|
||||
if (link !=NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_port;
|
||||
struct in_addr alias_address;
|
||||
int accumulate;
|
||||
@ -1071,14 +1032,12 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
/* Save original destination address, if this is a proxy packet.
|
||||
Also modify packet to include destination encoding. This may
|
||||
change the size of IP header. */
|
||||
if (proxy_type != 0)
|
||||
{
|
||||
if (proxy_type != 0) {
|
||||
SetProxyPort(link, dest_port);
|
||||
SetProxyAddress(link, dest_address);
|
||||
ProxyModify(la, link, pip, maxpacketsize, proxy_type);
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
}
|
||||
|
||||
/* Get alias address and port */
|
||||
alias_port = GetAliasPort(link);
|
||||
alias_address = GetAliasAddress(link);
|
||||
@ -1119,13 +1078,11 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
accumulate -= *sptr;
|
||||
|
||||
/* Modify sequence number if necessary */
|
||||
if (GetAckModified(link) == 1)
|
||||
{
|
||||
if (GetAckModified(link) == 1) {
|
||||
int delta;
|
||||
|
||||
delta = GetDeltaSeqOut(pip, link);
|
||||
if (delta != 0)
|
||||
{
|
||||
if (delta != 0) {
|
||||
sptr = (u_short *) & tc->th_seq;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -1135,7 +1092,6 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, tc->th_sum);
|
||||
|
||||
/* Change source address */
|
||||
@ -1181,8 +1137,7 @@ FragmentIn(struct libalias *la, struct ip *pip)
|
||||
struct alias_link *link;
|
||||
|
||||
link = FindFragmentIn2(la, pip->ip_src, pip->ip_dst, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr original_address;
|
||||
|
||||
GetFragmentAddr(link, &original_address);
|
||||
@ -1241,8 +1196,7 @@ LibAliasSaveFragment(struct libalias *la, char *ptr)
|
||||
pip = (struct ip *)ptr;
|
||||
link = AddFragmentPtrLink(la, pip->ip_src, pip->ip_id);
|
||||
iresult = PKT_ALIAS_ERROR;
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
SetFragmentPtr(link, ptr);
|
||||
iresult = PKT_ALIAS_OK;
|
||||
}
|
||||
@ -1259,26 +1213,24 @@ LibAliasGetFragment(struct libalias *la, char *ptr)
|
||||
|
||||
pip = (struct ip *)ptr;
|
||||
link = FindFragmentPtr(la, pip->ip_src, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
GetFragmentPtr(link, &fptr);
|
||||
SetFragmentPtr(link, NULL);
|
||||
SetExpire(link, 0); /* Deletes link */
|
||||
|
||||
return (fptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly de-aliased
|
||||
header fragment */
|
||||
char *ptr_fragment /* Points to fragment which must
|
||||
be de-aliased */
|
||||
LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly
|
||||
* de-aliased header
|
||||
* fragment */
|
||||
char *ptr_fragment /* Points to fragment which must be
|
||||
* de-aliased */
|
||||
)
|
||||
{
|
||||
struct ip *pip;
|
||||
@ -1308,7 +1260,6 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
la->packetAliasMode |= PKT_ALIAS_REVERSE;
|
||||
return iresult;
|
||||
}
|
||||
|
||||
HouseKeeping(la);
|
||||
ClearCheckNewLink(la);
|
||||
pip = (struct ip *)ptr;
|
||||
@ -1320,10 +1271,8 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
return PKT_ALIAS_IGNORED;
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
if ( (ntohs(pip->ip_off) & IP_OFFMASK) == 0 )
|
||||
{
|
||||
switch (pip->ip_p)
|
||||
{
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
iresult = IcmpAliasIn(la, pip);
|
||||
break;
|
||||
@ -1345,24 +1294,18 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ntohs(pip->ip_off) & IP_MF)
|
||||
{
|
||||
if (ntohs(pip->ip_off) & IP_MF) {
|
||||
struct alias_link *link;
|
||||
|
||||
link = FindFragmentIn1(la, pip->ip_src, alias_addr, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
iresult = PKT_ALIAS_FOUND_HEADER_FRAGMENT;
|
||||
SetFragmentAddr(link, pip->ip_dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = PKT_ALIAS_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = FragmentIn(la, pip);
|
||||
}
|
||||
|
||||
@ -1387,8 +1330,8 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
|
||||
int
|
||||
LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
int maxpacketsize /* How much the packet data may grow
|
||||
(FTP and IRC inline changes) */
|
||||
int maxpacketsize /* How much the packet data may grow (FTP
|
||||
* and IRC inline changes) */
|
||||
)
|
||||
{
|
||||
int iresult;
|
||||
@ -1401,7 +1344,6 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
la->packetAliasMode |= PKT_ALIAS_REVERSE;
|
||||
return iresult;
|
||||
}
|
||||
|
||||
HouseKeeping(la);
|
||||
ClearCheckNewLink(la);
|
||||
pip = (struct ip *)ptr;
|
||||
@ -1412,8 +1354,7 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
return PKT_ALIAS_IGNORED;
|
||||
|
||||
addr_save = GetDefaultAliasAddress(la);
|
||||
if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY)
|
||||
{
|
||||
if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY) {
|
||||
u_long addr;
|
||||
int iclass;
|
||||
|
||||
@ -1426,21 +1367,15 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
else if (addr >= UNREG_ADDR_A_LOWER && addr <= UNREG_ADDR_A_UPPER)
|
||||
iclass = 1;
|
||||
|
||||
if (iclass == 0)
|
||||
{
|
||||
if (iclass == 0) {
|
||||
SetDefaultAliasAddress(la, pip->ip_src);
|
||||
}
|
||||
}
|
||||
else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
|
||||
{
|
||||
} else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) {
|
||||
SetDefaultAliasAddress(la, pip->ip_src);
|
||||
}
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0)
|
||||
{
|
||||
switch (pip->ip_p)
|
||||
{
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
iresult = IcmpAliasOut(la, pip);
|
||||
break;
|
||||
@ -1460,9 +1395,7 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
iresult = ProtoAliasOut(la, pip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = FragmentOut(la, pip);
|
||||
}
|
||||
|
||||
@ -1508,10 +1441,8 @@ LibAliasUnaliasOut(struct libalias *la, char *ptr, /* valid IP packet
|
||||
link = NULL;
|
||||
|
||||
/* Change it from an aliased packet to an unaliased packet */
|
||||
if (link != NULL)
|
||||
{
|
||||
if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr original_address;
|
||||
|
@ -88,7 +88,8 @@ int PacketUnaliasOut(char *_ptr, int _maxpacketsize);
|
||||
/* Port and address redirection functions. */
|
||||
|
||||
|
||||
int PacketAliasAddServer(struct alias_link *_link,
|
||||
int
|
||||
PacketAliasAddServer(struct alias_link *_link,
|
||||
struct in_addr _addr, unsigned short _port);
|
||||
struct alias_link *
|
||||
PacketAliasRedirectAddr(struct in_addr _src_addr,
|
||||
@ -137,7 +138,8 @@ int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
|
||||
|
||||
/* Port and address redirection functions. */
|
||||
|
||||
int LibAliasAddServer(struct libalias *, struct alias_link *_link,
|
||||
int
|
||||
LibAliasAddServer(struct libalias *, struct alias_link *_link,
|
||||
struct in_addr _addr, unsigned short _port);
|
||||
struct alias_link *
|
||||
LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
|
||||
|
@ -63,7 +63,8 @@ struct oc_header {
|
||||
/* client info structures */
|
||||
struct client_info {
|
||||
u_int32_t address;/* Client address */
|
||||
char reserved[8]; /* Flags, pruning bitfield, packet counts etc */
|
||||
char reserved [8]; /* Flags, pruning bitfield, packet
|
||||
* counts etc */
|
||||
};
|
||||
|
||||
void
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -105,7 +105,8 @@ AliasHandleFtpOut(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link, /* The link to go through (aliased port) */
|
||||
int maxpacketsize /* The maximum size this packet can grow to (including headers) */)
|
||||
int maxpacketsize /* The maximum size this packet can grow to
|
||||
(including headers) */ )
|
||||
{
|
||||
int hlen, tlen, dlen, pflags;
|
||||
char *sptr;
|
||||
@ -153,12 +154,12 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
if (ftp_message_type != FTP_UNKNOWN_MESSAGE)
|
||||
NewFtpMessage(la, pip, link, maxpacketsize, ftp_message_type);
|
||||
}
|
||||
|
||||
/* Track the msgs which are CRLF term'd for PORT/PASV FW breach */
|
||||
|
||||
if (dlen) { /* only if there's data */
|
||||
sptr = (char *)pip; /* start over at beginning */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may have grown */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may
|
||||
* have grown */
|
||||
if (sptr[tlen - 2] == '\r' && sptr[tlen - 1] == '\n')
|
||||
pflags &= ~WAIT_CRLF;
|
||||
else
|
||||
@ -187,24 +188,52 @@ ParseFtpPortCommand(struct libalias *la, char *sptr, int dlen)
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state) {
|
||||
case -4: if (ch == 'P') state++; else return 0; break;
|
||||
case -3: if (ch == 'O') state++; else return 0; break;
|
||||
case -2: if (ch == 'R') state++; else return 0; break;
|
||||
case -1: if (ch == 'T') state++; else return 0; break;
|
||||
case -4:
|
||||
if (ch == 'P')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -3:
|
||||
if (ch == 'O')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == 'R')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == 'T')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (isspace(ch))
|
||||
break;
|
||||
else
|
||||
state++;
|
||||
case 1: case 3: case 5: case 7: case 9: case 11:
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
case 11:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 2: case 4: case 6: case 8:
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',') {
|
||||
@ -213,7 +242,8 @@ ParseFtpPortCommand(struct libalias *la, char *sptr, int dlen)
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 10: case 12:
|
||||
case 10:
|
||||
case 12:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',' || state == 12) {
|
||||
@ -253,12 +283,31 @@ ParseFtpEprtCommand(struct libalias *la, char *sptr, int dlen)
|
||||
state = -4;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -4: if (ch == 'E') state++; else return 0; break;
|
||||
case -3: if (ch == 'P') state++; else return 0; break;
|
||||
case -2: if (ch == 'R') state++; else return 0; break;
|
||||
case -1: if (ch == 'T') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -4:
|
||||
if (ch == 'E')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -3:
|
||||
if (ch == 'P')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == 'R')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == 'T')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (!isspace(ch)) {
|
||||
@ -278,14 +327,20 @@ ParseFtpEprtCommand(struct libalias *la, char *sptr, int dlen)
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case 3: case 5: case 7: case 9:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 4: case 6: case 8: case 10:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
case 10:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == '.' || state == 10) {
|
||||
@ -340,24 +395,46 @@ ParseFtp227Reply(struct libalias *la, char *sptr, int dlen)
|
||||
state = -3;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -3: if (ch == '2') state++; else return 0; break;
|
||||
case -2: if (ch == '2') state++; else return 0; break;
|
||||
case -1: if (ch == '7') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -3:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == '7')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (ch == '(')
|
||||
state++;
|
||||
break;
|
||||
case 1: case 3: case 5: case 7: case 9: case 11:
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
case 11:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 2: case 4: case 6: case 8:
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',') {
|
||||
@ -366,7 +443,8 @@ ParseFtp227Reply(struct libalias *la, char *sptr, int dlen)
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 10: case 12:
|
||||
case 10:
|
||||
case 12:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',' || (state == 12 && ch == ')')) {
|
||||
@ -405,11 +483,25 @@ ParseFtp229Reply(struct libalias *la, char *sptr, int dlen)
|
||||
state = -3;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -3: if (ch == '2') state++; else return 0; break;
|
||||
case -2: if (ch == '2') state++; else return 0; break;
|
||||
case -1: if (ch == '9') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -3:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == '9')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (ch == '(')
|
||||
@ -419,7 +511,8 @@ ParseFtp229Reply(struct libalias *la, char *sptr, int dlen)
|
||||
delim = ch;
|
||||
state++;
|
||||
break;
|
||||
case 2: case 3:
|
||||
case 2:
|
||||
case 3:
|
||||
if (ch == delim)
|
||||
state++;
|
||||
else
|
||||
@ -475,8 +568,7 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
ftp_link = FindUdpTcpOut(la, la->true_addr, GetDestAddress(link),
|
||||
htons(la->true_port), 0, IPPROTO_TCP, 1);
|
||||
|
||||
if (ftp_link != NULL)
|
||||
{
|
||||
if (ftp_link != NULL) {
|
||||
int slen, hlen, tlen, dlen;
|
||||
struct tcphdr *tc;
|
||||
|
||||
@ -503,17 +595,20 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
/* Decompose alias address into quad format */
|
||||
alias_address = GetAliasAddress(link);
|
||||
ptr = (u_char *) & alias_address.s_addr;
|
||||
a1 = *ptr++; a2=*ptr++; a3=*ptr++; a4=*ptr;
|
||||
a1 = *ptr++;
|
||||
a2 = *ptr++;
|
||||
a3 = *ptr++;
|
||||
a4 = *ptr;
|
||||
|
||||
alias_port = GetAliasPort(ftp_link);
|
||||
|
||||
switch (ftp_message_type)
|
||||
{
|
||||
switch (ftp_message_type) {
|
||||
case FTP_PORT_COMMAND:
|
||||
case FTP_227_REPLY:
|
||||
/* Decompose alias port into pair format. */
|
||||
ptr = (char *)&alias_port;
|
||||
p1 = *ptr++; p2=*ptr;
|
||||
p1 = *ptr++;
|
||||
p2 = *ptr;
|
||||
|
||||
if (ftp_message_type == FTP_PORT_COMMAND) {
|
||||
/* Generate PORT command string. */
|
||||
@ -542,7 +637,8 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
slen = strlen(stemp);
|
||||
|
||||
/* Copy modified buffer into IP packet. */
|
||||
sptr = (char *) pip; sptr += hlen;
|
||||
sptr = (char *)pip;
|
||||
sptr += hlen;
|
||||
strncpy(sptr, stemp, maxpacketsize - hlen);
|
||||
}
|
||||
|
||||
@ -570,9 +666,7 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
/* Compute TCP checksum for revised packet */
|
||||
tc->th_sum = 0;
|
||||
tc->th_sum = TcpChecksum(pip);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"PacketAlias/HandleFtpOut: Cannot allocate FTP data port\n");
|
||||
|
@ -68,7 +68,8 @@ void
|
||||
AliasHandleIrcOut(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine */
|
||||
struct alias_link *link, /* Which link are we on? */
|
||||
int maxsize /* Maximum size of IP packet including headers */
|
||||
int maxsize /* Maximum size of IP packet including
|
||||
* headers */
|
||||
)
|
||||
{
|
||||
int hlen, tlen, dlen;
|
||||
@ -84,14 +85,18 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
tlen = ntohs(pip->ip_len);
|
||||
dlen = tlen - hlen;
|
||||
|
||||
/* Return if data length is too short - assume an entire PRIVMSG in each packet. */
|
||||
/*
|
||||
* Return if data length is too short - assume an entire PRIVMSG in
|
||||
* each packet.
|
||||
*/
|
||||
if (dlen < sizeof(":A!a@n.n PRIVMSG A :aDCC 1 1a") - 1)
|
||||
return;
|
||||
|
||||
/* Place string pointer at beginning of data */
|
||||
sptr = (char *)pip;
|
||||
sptr += hlen;
|
||||
maxsize -= hlen; /* We're interested in maximum size of data, not packet */
|
||||
maxsize -= hlen; /* We're interested in maximum size of
|
||||
* data, not packet */
|
||||
|
||||
/* Search for a CTCP command [Note 1] */
|
||||
for (i = 0; i < dlen; i++) {
|
||||
@ -102,15 +107,20 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
/* Handle CTCP commands - the buffer may have to be copied */
|
||||
lFOUND_CTCP:
|
||||
{
|
||||
char newpacket[65536]; /* Estimate of maximum packet size :) */
|
||||
char newpacket[65536]; /* Estimate of maximum packet size
|
||||
* :) */
|
||||
int copyat = i; /* Same */
|
||||
int iCopy = 0; /* How much data have we written to copy-back string? */
|
||||
int iCopy = 0; /* How much data have we written to
|
||||
* copy-back string? */
|
||||
unsigned long org_addr; /* Original IP address */
|
||||
unsigned short org_port; /* Original source port address */
|
||||
unsigned short org_port; /* Original source port
|
||||
* address */
|
||||
|
||||
lCTCP_START:
|
||||
if (i >= dlen || iCopy >= sizeof(newpacket))
|
||||
goto lPACKET_DONE;
|
||||
newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start character */
|
||||
newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start
|
||||
* character */
|
||||
/* Start of a CTCP */
|
||||
if (i + 4 >= dlen) /* Too short for DCC */
|
||||
goto lBAD_CTCP;
|
||||
@ -132,8 +142,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = ' ';
|
||||
|
||||
DBprintf(("Found DCC\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces\n"));
|
||||
@ -154,8 +166,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = sptr[i++];
|
||||
|
||||
DBprintf(("Done command - removing spaces\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces (post-command)\n"));
|
||||
@ -176,8 +190,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = sptr[i++];
|
||||
|
||||
DBprintf(("Done filename - removing spaces\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces (post-filename)\n"));
|
||||
@ -201,9 +217,11 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
DBprintf(("Overflow (%d >= %d) or bad character (%02x) terminating IP address\n", i + 1, dlen, sptr[i]));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway, so we might
|
||||
as well play it safe */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway, so we
|
||||
* might as well play it safe
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("Packet failure - space overflow.\n"));
|
||||
@ -214,7 +232,8 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
/* Fetch source port */
|
||||
org_port = 0;
|
||||
while (i < dlen && isdigit(sptr[i])) {
|
||||
if( org_port > 6554 ) { /* Terminate on overflow (65536/10 rounded up*/
|
||||
if (org_port > 6554) { /* Terminate on overflow
|
||||
* (65536/10 rounded up */
|
||||
DBprintf(("DCC: port number overflow\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
@ -244,16 +263,19 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
org_port < IPPORT_RESERVED)
|
||||
goto lBAD_CTCP;
|
||||
|
||||
/* Steal the FTP_DATA_PORT - it doesn't really matter, and this
|
||||
would probably allow it through at least _some_
|
||||
firewalls. */
|
||||
/*
|
||||
* Steal the FTP_DATA_PORT - it doesn't really
|
||||
* matter, and this would probably allow it through
|
||||
* at least _some_ firewalls.
|
||||
*/
|
||||
dcc_link = FindUdpTcpOut(la, true_addr, destaddr,
|
||||
true_port, 0,
|
||||
IPPROTO_TCP, 1);
|
||||
DBprintf(("Got a DCC link\n"));
|
||||
if (dcc_link) {
|
||||
struct in_addr alias_address; /* Address from aliasing */
|
||||
u_short alias_port; /* Port given by aliasing */
|
||||
u_short alias_port; /* Port given by
|
||||
* aliasing */
|
||||
int n;
|
||||
|
||||
#ifndef NO_FW_PUNCH
|
||||
@ -269,7 +291,8 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
DBprintf(("DCC packet construct failure.\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
if( (iCopy += n) >= sizeof(newpacket) ) { /* Truncated/fit exactly - bad news */
|
||||
if ((iCopy += n) >= sizeof(newpacket)) { /* Truncated/fit exactly
|
||||
* - bad news */
|
||||
DBprintf(("DCC constructed packet overflow.\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
@ -282,13 +305,18 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
iCopy += n;
|
||||
/* Done - truncated cases will be taken care of by lBAD_CTCP */
|
||||
/*
|
||||
* Done - truncated cases will be taken
|
||||
* care of by lBAD_CTCP
|
||||
*/
|
||||
DBprintf(("Aliased IP %lu and port %u\n", alias_address.s_addr, (unsigned)alias_port));
|
||||
}
|
||||
}
|
||||
/* An uninteresting CTCP - state entered right after '\001' has
|
||||
been pushed. Also used to copy the rest of a DCC, after IP
|
||||
address and port has been handled */
|
||||
/*
|
||||
* An uninteresting CTCP - state entered right after '\001'
|
||||
* has been pushed. Also used to copy the rest of a DCC,
|
||||
* after IP address and port has been handled
|
||||
*/
|
||||
lBAD_CTCP:
|
||||
for (; i < dlen && iCopy < sizeof(newpacket); i++, iCopy++) {
|
||||
newpacket[iCopy] = sptr[i]; /* Copy CTCP unchanged */
|
||||
|
@ -95,7 +95,8 @@ struct libalias {
|
||||
int timeStamp; /* System time in seconds for */
|
||||
/* current packet */
|
||||
|
||||
int lastCleanupTime; /* Last time IncrementalCleanup() */
|
||||
int lastCleanupTime; /* Last time
|
||||
* IncrementalCleanup() */
|
||||
/* was called */
|
||||
|
||||
int houseKeepingResidual; /* used by HouseKeeping() */
|
||||
@ -116,9 +117,12 @@ struct libalias {
|
||||
/* PacketAliasSetMode on first */
|
||||
/* setting the PKT_ALIAS_PUNCH_FW */
|
||||
/* flag. */
|
||||
int fireWallBaseNum; /* The first firewall entry free for our use */
|
||||
int fireWallNumNums; /* How many entries can we use? */
|
||||
int fireWallActiveNum; /* Which entry did we last use? */
|
||||
int fireWallBaseNum; /* The first firewall entry
|
||||
* free for our use */
|
||||
int fireWallNumNums; /* How many entries can we
|
||||
* use? */
|
||||
int fireWallActiveNum; /* Which entry did we last
|
||||
* use? */
|
||||
char *fireWallField; /* bool array for entries */
|
||||
#endif
|
||||
|
||||
@ -163,7 +167,8 @@ struct libalias {
|
||||
/* General utilities */
|
||||
u_short IpChecksum(struct ip *_pip);
|
||||
u_short TcpChecksum(struct ip *_pip);
|
||||
void DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old,
|
||||
void
|
||||
DifferentialChecksum(u_short * _cksum, u_short * _new, u_short * _old,
|
||||
int _n);
|
||||
|
||||
/* Internal data access */
|
||||
@ -219,7 +224,8 @@ struct in_addr
|
||||
FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
|
||||
|
||||
/* External data access/modification */
|
||||
int FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
|
||||
int
|
||||
FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
|
||||
u_short _src_port, u_short _dst_port, u_short _port_count,
|
||||
u_char _proto, u_char _align);
|
||||
void GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
|
||||
@ -256,8 +262,10 @@ void ClearCheckNewLink(struct libalias *la);
|
||||
void SetProtocolFlags(struct alias_link *_link, int _pflags);
|
||||
int GetProtocolFlags(struct alias_link *_link);
|
||||
void SetDestCallId(struct alias_link *_link, u_int16_t _cid);
|
||||
|
||||
#ifndef NO_FW_PUNCH
|
||||
void PunchFWHole(struct alias_link *_link);
|
||||
|
||||
#endif
|
||||
|
||||
/* Housekeeping function */
|
||||
@ -267,15 +275,18 @@ void HouseKeeping(struct libalias *);
|
||||
/* lint -save -library Suppress flexelint warnings */
|
||||
|
||||
/* FTP routines */
|
||||
void AliasHandleFtpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleFtpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxpacketsize);
|
||||
|
||||
/* IRC routines */
|
||||
void AliasHandleIrcOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleIrcOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxsize);
|
||||
|
||||
/* RTSP routines */
|
||||
void AliasHandleRtspOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleRtspOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxpacketsize);
|
||||
|
||||
/* PPTP routines */
|
||||
@ -285,9 +296,11 @@ int AliasHandlePptpGreOut(struct libalias *la, struct ip *_pip);
|
||||
int AliasHandlePptpGreIn(struct libalias *la, struct ip *_pip);
|
||||
|
||||
/* NetBIOS routines */
|
||||
int AliasHandleUdpNbt(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int
|
||||
AliasHandleUdpNbt(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
struct in_addr *_alias_address, u_short _alias_port);
|
||||
int AliasHandleUdpNbtNS(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int
|
||||
AliasHandleUdpNbtNS(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
struct in_addr *_alias_address, u_short * _alias_port,
|
||||
struct in_addr *_original_address, u_short * _original_port);
|
||||
|
||||
@ -299,9 +312,11 @@ void AliasHandleCUSeeMeIn(struct libalias *la, struct ip *_pip, struct in_addr
|
||||
void AliasHandleSkinny(struct libalias *la, struct ip *_pip, struct alias_link *_link);
|
||||
|
||||
/* Transparent proxy routines */
|
||||
int ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
|
||||
int
|
||||
ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
|
||||
u_short * _proxy_server_port);
|
||||
void ProxyModify(struct libalias *la, struct alias_link *_link, struct ip *_pip,
|
||||
void
|
||||
ProxyModify(struct libalias *la, struct alias_link *_link, struct ip *_pip,
|
||||
int _maxpacketsize, int _proxy_type);
|
||||
|
||||
enum alias_tcp_state {
|
||||
|
@ -96,7 +96,9 @@ typedef struct {
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
static void PrintRcode( u_char rcode ) {
|
||||
static void
|
||||
PrintRcode(u_char rcode)
|
||||
{
|
||||
|
||||
switch (rcode) {
|
||||
case FMT_ERR:
|
||||
@ -116,11 +118,14 @@ static void PrintRcode( u_char rcode ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Handling Name field */
|
||||
static u_char *AliasHandleName ( u_char *p, char *pmax ) {
|
||||
static u_char *
|
||||
AliasHandleName(u_char * p, char *pmax)
|
||||
{
|
||||
|
||||
u_char *s;
|
||||
u_char c;
|
||||
@ -195,13 +200,15 @@ static u_char *AliasHandleName ( u_char *p, char *pmax ) {
|
||||
#define DGM_POSITIVE_RES 0x15
|
||||
#define DGM_NEGATIVE_RES 0x16
|
||||
|
||||
int AliasHandleUdpNbt(
|
||||
int
|
||||
AliasHandleUdpNbt(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link,
|
||||
struct in_addr *alias_address,
|
||||
u_short alias_port
|
||||
) {
|
||||
)
|
||||
{
|
||||
struct udphdr *uh;
|
||||
NbtDataHeader *ndh;
|
||||
u_char *p = NULL;
|
||||
@ -244,6 +251,7 @@ int AliasHandleUdpNbt(
|
||||
if (uh->uh_sum != 0) {
|
||||
int acc;
|
||||
u_short *sptr;
|
||||
|
||||
acc = ndh->source_port;
|
||||
acc -= alias_port;
|
||||
sptr = (u_short *) & (ndh->source_ip);
|
||||
@ -262,6 +270,7 @@ int AliasHandleUdpNbt(
|
||||
#endif
|
||||
return ((p == NULL) ? -1 : 0);
|
||||
}
|
||||
|
||||
/* Question Section */
|
||||
#define QS_TYPE_NB 0x0020
|
||||
#define QS_TYPE_NBSTAT 0x0021
|
||||
@ -287,7 +296,6 @@ AliasHandleQuestion(
|
||||
q = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Type and Class filed */
|
||||
switch (ntohs(q->type)) {
|
||||
case QS_TYPE_NB:
|
||||
@ -371,7 +379,6 @@ AliasHandleResourceNB(
|
||||
acc -= *sptr;
|
||||
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
||||
}
|
||||
|
||||
nb->addr = nbtarg->newaddr;
|
||||
#ifdef DEBUG
|
||||
printf("O");
|
||||
@ -388,7 +395,6 @@ AliasHandleResourceNB(
|
||||
if (nb == NULL || (char *)(nb + 1) > pmax) {
|
||||
nb = NULL;
|
||||
}
|
||||
|
||||
return ((u_char *) nb);
|
||||
}
|
||||
|
||||
@ -439,7 +445,6 @@ AliasHandleResourceA(
|
||||
acc -= *sptr;
|
||||
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
||||
}
|
||||
|
||||
a->addr = nbtarg->newaddr;
|
||||
}
|
||||
a++; /* XXXX */
|
||||
@ -612,7 +617,8 @@ AliasHandleResource(
|
||||
return ((u_char *) q);
|
||||
}
|
||||
|
||||
int AliasHandleUdpNbtNS(
|
||||
int
|
||||
AliasHandleUdpNbtNS(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link,
|
||||
@ -668,7 +674,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Answer Resource Records */
|
||||
if (ntohs(nsh->ancount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -678,7 +683,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Authority Resource Recodrs */
|
||||
if (ntohs(nsh->nscount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -688,7 +692,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Additional Resource Recodrs */
|
||||
if (ntohs(nsh->arcount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -698,7 +701,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
PrintRcode(nsh->rcode);
|
||||
#endif
|
||||
|
@ -80,14 +80,14 @@ __FBSDID("$FreeBSD$");
|
||||
* PPTP definitions
|
||||
*/
|
||||
|
||||
struct grehdr /* Enhanced GRE header. */
|
||||
{
|
||||
struct grehdr { /* Enhanced GRE header. */
|
||||
u_int16_t gh_flags; /* Flags. */
|
||||
u_int16_t gh_protocol; /* Protocol type. */
|
||||
u_int16_t gh_length; /* Payload length. */
|
||||
u_int16_t gh_call_id; /* Call ID. */
|
||||
u_int32_t gh_seq_no; /* Sequence number (optional). */
|
||||
u_int32_t gh_ack_no; /* Acknowledgment number (optional). */
|
||||
u_int32_t gh_ack_no; /* Acknowledgment number
|
||||
* (optional). */
|
||||
};
|
||||
typedef struct grehdr GreHdr;
|
||||
|
||||
@ -147,8 +147,8 @@ static PptpCallId AliasVerifyPptp(struct ip *, u_int16_t *);
|
||||
void
|
||||
AliasHandlePptpOut(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link) /* The PPTP control link */
|
||||
{
|
||||
struct alias_link *link)
|
||||
{ /* The PPTP control link */
|
||||
struct alias_link *pptp_link;
|
||||
PptpCallId cptr;
|
||||
PptpCode codes;
|
||||
@ -165,13 +165,19 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
case PPTP_OutCallReply:
|
||||
case PPTP_InCallRequest:
|
||||
case PPTP_InCallReply:
|
||||
/* Establish PPTP link for address and Call ID found in control message. */
|
||||
/*
|
||||
* Establish PPTP link for address and Call ID found in
|
||||
* control message.
|
||||
*/
|
||||
pptp_link = AddPptp(la, GetOriginalAddress(link), GetDestAddress(link),
|
||||
GetAliasAddress(link), cptr->cid1);
|
||||
break;
|
||||
case PPTP_CallClearRequest:
|
||||
case PPTP_CallDiscNotify:
|
||||
/* Find PPTP link for address and Call ID found in control message. */
|
||||
/*
|
||||
* Find PPTP link for address and Call ID found in control
|
||||
* message.
|
||||
*/
|
||||
pptp_link = FindPptpOutByCallId(la, GetOriginalAddress(link),
|
||||
GetDestAddress(link),
|
||||
cptr->cid1);
|
||||
@ -195,8 +201,10 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
case PPTP_OutCallReply:
|
||||
case PPTP_InCallReply:
|
||||
codes = (PptpCode) (cptr + 1);
|
||||
if (codes->resCode == 1) /* Connection established, */
|
||||
SetDestCallId(pptp_link, /* note the Peer's Call ID. */
|
||||
if (codes->resCode == 1) /* Connection
|
||||
* established, */
|
||||
SetDestCallId(pptp_link, /* note the Peer's Call
|
||||
* ID. */
|
||||
cptr->cid2);
|
||||
else
|
||||
SetExpire(pptp_link, 0); /* Connection refused. */
|
||||
@ -211,8 +219,8 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
void
|
||||
AliasHandlePptpIn(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link) /* The PPTP control link */
|
||||
{
|
||||
struct alias_link *link)
|
||||
{ /* The PPTP control link */
|
||||
struct alias_link *pptp_link;
|
||||
PptpCallId cptr;
|
||||
u_int16_t *pcall_id;
|
||||
@ -224,8 +232,7 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
return;
|
||||
|
||||
/* Modify certain PPTP messages */
|
||||
switch (ctl_type)
|
||||
{
|
||||
switch (ctl_type) {
|
||||
case PPTP_InCallConn:
|
||||
case PPTP_WanErrorNotify:
|
||||
case PPTP_SetLinkInfo:
|
||||
@ -265,7 +272,8 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
if (ctl_type == PPTP_OutCallReply || ctl_type == PPTP_InCallReply) {
|
||||
PptpCode codes = (PptpCode) (cptr + 1);
|
||||
|
||||
if (codes->resCode == 1) /* Connection established, */
|
||||
if (codes->resCode == 1) /* Connection
|
||||
* established, */
|
||||
SetDestCallId(pptp_link, /* note the Call ID. */
|
||||
cptr->cid1);
|
||||
else
|
||||
@ -275,8 +283,8 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
}
|
||||
|
||||
static PptpCallId
|
||||
AliasVerifyPptp(struct ip *pip, u_int16_t *ptype) /* IP packet to examine/patch */
|
||||
{
|
||||
AliasVerifyPptp(struct ip *pip, u_int16_t * ptype)
|
||||
{ /* IP packet to examine/patch */
|
||||
int hlen, tlen, dlen;
|
||||
PptpMsgHead hptr;
|
||||
struct tcphdr *tc;
|
||||
@ -335,7 +343,6 @@ AliasHandlePptpGreOut(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_src = alias_addr;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -366,6 +373,5 @@ AliasHandlePptpGreIn(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_dst = src_addr;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -84,8 +84,7 @@ __FBSDID("$FreeBSD$");
|
||||
* A linked list of arbitrary length, based on struct proxy_entry is
|
||||
* used to store proxy rules.
|
||||
*/
|
||||
struct proxy_entry
|
||||
{
|
||||
struct proxy_entry {
|
||||
struct libalias *la;
|
||||
#define PROXY_TYPE_ENCODE_NONE 1
|
||||
#define PROXY_TYPE_ENCODE_TCPSTREAM 2
|
||||
@ -175,8 +174,7 @@ IpPort(char *s, int proto, int *port)
|
||||
int n;
|
||||
|
||||
n = sscanf(s, "%d", port);
|
||||
if (n != 1)
|
||||
{
|
||||
if (n != 1) {
|
||||
struct servent *se;
|
||||
|
||||
if (proto == IPPROTO_TCP)
|
||||
@ -191,7 +189,6 @@ IpPort(char *s, int proto, int *port)
|
||||
|
||||
*port = (u_int) ntohs(se->s_port);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -202,8 +199,7 @@ RuleAdd(struct libalias *la, struct proxy_entry *entry)
|
||||
struct proxy_entry *ptr;
|
||||
struct proxy_entry *ptr_last;
|
||||
|
||||
if (la->proxyList == NULL)
|
||||
{
|
||||
if (la->proxyList == NULL) {
|
||||
la->proxyList = entry;
|
||||
entry->last = NULL;
|
||||
entry->next = NULL;
|
||||
@ -214,19 +210,15 @@ RuleAdd(struct libalias *la, struct proxy_entry *entry)
|
||||
rule_index = entry->rule_index;
|
||||
ptr = la->proxyList;
|
||||
ptr_last = NULL;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
if (ptr->rule_index >= rule_index)
|
||||
{
|
||||
if (ptr_last == NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
if (ptr->rule_index >= rule_index) {
|
||||
if (ptr_last == NULL) {
|
||||
entry->next = la->proxyList;
|
||||
entry->last = NULL;
|
||||
la->proxyList->last = entry;
|
||||
la->proxyList = entry;
|
||||
return;
|
||||
}
|
||||
|
||||
ptr_last->next = entry;
|
||||
ptr->last = entry;
|
||||
entry->last = ptr->last;
|
||||
@ -267,17 +259,14 @@ RuleNumberDelete(struct libalias *la, int rule_index)
|
||||
|
||||
err = -1;
|
||||
ptr = la->proxyList;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
struct proxy_entry *ptr_next;
|
||||
|
||||
ptr_next = ptr->next;
|
||||
if (ptr->rule_index == rule_index)
|
||||
{
|
||||
if (ptr->rule_index == rule_index) {
|
||||
err = 0;
|
||||
RuleDelete(ptr);
|
||||
}
|
||||
|
||||
ptr = ptr_next;
|
||||
}
|
||||
|
||||
@ -307,8 +296,7 @@ ProxyEncodeTcpStream(struct alias_link *link,
|
||||
|
||||
/* Pad string out to a multiple of two in length */
|
||||
slen = strlen(buffer);
|
||||
switch (slen % 2)
|
||||
{
|
||||
switch (slen % 2) {
|
||||
case 0:
|
||||
strcat(buffer, " \n");
|
||||
slen += 2;
|
||||
@ -465,15 +453,13 @@ ProxyCheck(struct libalias *la, struct ip *pip,
|
||||
->th_dport;
|
||||
|
||||
ptr = la->proxyList;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
u_short proxy_port;
|
||||
|
||||
proxy_port = ptr->proxy_port;
|
||||
if ((dst_port == proxy_port || proxy_port == 0)
|
||||
&& pip->ip_p == ptr->proto
|
||||
&& src_addr.s_addr != ptr->server_addr.s_addr)
|
||||
{
|
||||
&& src_addr.s_addr != ptr->server_addr.s_addr) {
|
||||
struct in_addr src_addr_masked;
|
||||
struct in_addr dst_addr_masked;
|
||||
|
||||
@ -481,8 +467,7 @@ ProxyCheck(struct libalias *la, struct ip *pip,
|
||||
dst_addr_masked.s_addr = dst_addr.s_addr & ptr->dst_mask.s_addr;
|
||||
|
||||
if ((src_addr_masked.s_addr == ptr->src_addr.s_addr)
|
||||
&& (dst_addr_masked.s_addr == ptr->dst_addr.s_addr))
|
||||
{
|
||||
&& (dst_addr_masked.s_addr == ptr->dst_addr.s_addr)) {
|
||||
if ((*proxy_server_port = ptr->server_port) == 0)
|
||||
*proxy_server_port = dst_port;
|
||||
*proxy_server_addr = ptr->server_addr;
|
||||
@ -501,8 +486,7 @@ ProxyModify(struct libalias *la, struct alias_link *link,
|
||||
int maxpacketsize,
|
||||
int proxy_type)
|
||||
{
|
||||
switch (proxy_type)
|
||||
{
|
||||
switch (proxy_type) {
|
||||
case PROXY_TYPE_ENCODE_IPHDR:
|
||||
ProxyEncodeIpHeader(pip, maxpacketsize);
|
||||
break;
|
||||
@ -604,11 +588,9 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
state = STATE_READ_KEYWORD;
|
||||
token = strsep(&res, " \t");
|
||||
token_count = 0;
|
||||
while (token != NULL)
|
||||
{
|
||||
while (token != NULL) {
|
||||
token_count++;
|
||||
switch (state)
|
||||
{
|
||||
switch (state) {
|
||||
case STATE_READ_KEYWORD:
|
||||
if (strcmp(token, "type") == 0)
|
||||
state = STATE_READ_TYPE;
|
||||
@ -657,14 +639,11 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
while (*p != ':' && *p != 0)
|
||||
p++;
|
||||
|
||||
if (*p != ':')
|
||||
{
|
||||
if (*p != ':') {
|
||||
err = IpAddr(token, &server_addr);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*p = ' ';
|
||||
|
||||
n = sscanf(token, "%s %s", s, str_server_port);
|
||||
@ -725,15 +704,12 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
while (*p != '/' && *p != 0)
|
||||
p++;
|
||||
|
||||
if (*p != '/')
|
||||
{
|
||||
if (*p != '/') {
|
||||
IpMask(32, &mask);
|
||||
err = IpAddr(token, &addr);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int nbits;
|
||||
char s[sizeof(buffer)];
|
||||
|
||||
@ -751,13 +727,10 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (state == STATE_READ_SRC)
|
||||
{
|
||||
if (state == STATE_READ_SRC) {
|
||||
src_addr = addr;
|
||||
src_mask = mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dst_addr = addr;
|
||||
dst_mask = mask;
|
||||
}
|
||||
@ -788,29 +761,23 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
the string is parsed, because the prototype might not be designated
|
||||
before the ports (which might be symbolic entries in /etc/services) */
|
||||
|
||||
if (strlen(str_port) != 0)
|
||||
{
|
||||
if (strlen(str_port) != 0) {
|
||||
int err;
|
||||
|
||||
err = IpPort(str_port, proto, &proxy_port);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
proxy_port = 0;
|
||||
}
|
||||
|
||||
if (strlen(str_server_port) != 0)
|
||||
{
|
||||
if (strlen(str_server_port) != 0) {
|
||||
int err;
|
||||
|
||||
err = IpPort(str_server_port, proto, &server_port);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
server_port = 0;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,10 @@ alias_skinny_startmedia(struct StartMediaTransmission *start_media,
|
||||
dst.s_addr = start_media->remoteIpAddr;
|
||||
src.s_addr = localIpAddr;
|
||||
|
||||
/* XXX I should probably handle in bound global translations as well. */
|
||||
/*
|
||||
* XXX I should probably handle in bound global translations as
|
||||
* well.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -234,11 +237,11 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
|
||||
orig_len = dlen;
|
||||
/*
|
||||
* Skinny packets can contain many messages. We need to loop through
|
||||
* the packet using len to determine message boundaries. This comes
|
||||
* into play big time with port messages being in the same packet as
|
||||
* register messages. Also, open receive channel acks are
|
||||
* usually buried in a pakcet some 400 bytes long.
|
||||
* Skinny packets can contain many messages. We need to loop
|
||||
* through the packet using len to determine message boundaries.
|
||||
* This comes into play big time with port messages being in the
|
||||
* same packet as register messages. Also, open receive channel
|
||||
* acks are usually buried in a pakcet some 400 bytes long.
|
||||
*/
|
||||
while (dlen >= skinny_hdr_len) {
|
||||
len = (sd->len);
|
||||
@ -253,8 +256,7 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
return;
|
||||
}
|
||||
switch (msgId) {
|
||||
case REG_MSG:
|
||||
{
|
||||
case REG_MSG: {
|
||||
struct RegisterMessage *reg_mesg;
|
||||
|
||||
if (len < sizeof(struct RegisterMessage)) {
|
||||
@ -270,11 +272,11 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
"PacketAlias/Skinny: Received a register message");
|
||||
#endif
|
||||
alias_skinny_reg_msg(reg_mesg, pip, tc, link, direction);
|
||||
}
|
||||
break;
|
||||
case IP_PORT_MSG:
|
||||
{
|
||||
}
|
||||
case IP_PORT_MSG: {
|
||||
struct IpPortMessage *port_mesg;
|
||||
|
||||
if (len < sizeof(struct IpPortMessage)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
@ -288,10 +290,9 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
port_mesg = (struct IpPortMessage *)&sd->msgId;
|
||||
alias_skinny_port_msg(port_mesg, pip, tc, link, direction);
|
||||
}
|
||||
break;
|
||||
case OPNRCVCH_ACK:
|
||||
{
|
||||
}
|
||||
case OPNRCVCH_ACK: {
|
||||
struct OpenReceiveChannelAck *opnrcvchn_ack;
|
||||
|
||||
if (len < sizeof(struct OpenReceiveChannelAck)) {
|
||||
@ -307,10 +308,9 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
opnrcvchn_ack = (struct OpenReceiveChannelAck *)&sd->msgId;
|
||||
alias_skinny_opnrcvch_ack(la, opnrcvchn_ack, pip, tc, link, &lip, direction);
|
||||
}
|
||||
break;
|
||||
case START_MEDIATX:
|
||||
{
|
||||
}
|
||||
case START_MEDIATX: {
|
||||
struct StartMediaTransmission *startmedia_tx;
|
||||
|
||||
if (len < sizeof(struct StartMediaTransmission)) {
|
||||
@ -326,8 +326,8 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
startmedia_tx = (struct StartMediaTransmission *)&sd->msgId;
|
||||
alias_skinny_startmedia(startmedia_tx, pip, tc, link, lip, direction);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -177,7 +177,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
if (pos < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(port_newdata, port_data, pos + 1);
|
||||
port_newdata += (pos + 1);
|
||||
|
||||
@ -218,8 +217,12 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
if (!links_created) {
|
||||
|
||||
links_created = 1;
|
||||
/* Find an even numbered port number base that
|
||||
satisfies the contiguous number of ports we need */
|
||||
/*
|
||||
* Find an even numbered port
|
||||
* number base that satisfies the
|
||||
* contiguous number of ports we
|
||||
* need
|
||||
*/
|
||||
null_addr.s_addr = 0;
|
||||
if (0 == (salias = FindNewPortGroup(la, null_addr,
|
||||
FindAliasAddress(la, pip->ip_src),
|
||||
@ -234,13 +237,21 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
|
||||
base_alias = ntohs(salias);
|
||||
for (j = 0; j < RTSP_PORT_GROUP; j++) {
|
||||
/* Establish link to port found in RTSP packet */
|
||||
/*
|
||||
* Establish link
|
||||
* to port found in
|
||||
* RTSP packet
|
||||
*/
|
||||
rtsp_link = FindRtspOut(la, GetOriginalAddress(link), null_addr,
|
||||
htons(base_port + j), htons(base_alias + j),
|
||||
IPPROTO_UDP);
|
||||
if (rtsp_link != NULL) {
|
||||
#ifndef NO_FW_PUNCH
|
||||
/* Punch hole in firewall */
|
||||
/*
|
||||
* Punch
|
||||
* hole in
|
||||
* firewall
|
||||
*/
|
||||
PunchFWHole(rtsp_link);
|
||||
#endif
|
||||
} else {
|
||||
@ -254,7 +265,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
}
|
||||
ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
|
||||
}
|
||||
|
||||
if (salias && rtsp_link) {
|
||||
|
||||
pkt_updated = 1;
|
||||
@ -273,7 +283,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
memcpy(port_newdata, stemp, strlen(stemp));
|
||||
port_newdata += strlen(stemp);
|
||||
}
|
||||
|
||||
*port_newdata = ';';
|
||||
port_newdata++;
|
||||
}
|
||||
@ -399,11 +408,12 @@ AliasHandleRtspOut(struct libalias *la, struct ip *pip, struct alias_link *link,
|
||||
alias_pna_out(la, pip, link, data, dlen);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* When aliasing a server, check for the 200 reply
|
||||
Accomodate varying number of blanks between 200 & OK */
|
||||
/*
|
||||
* When aliasing a server, check for the 200 reply
|
||||
* Accomodate varying number of blanks between 200 & OK
|
||||
*/
|
||||
|
||||
if (dlen >= strlen(str200)) {
|
||||
|
||||
|
@ -66,13 +66,11 @@ LibAliasInternetChecksum(struct libalias *la, u_short *ptr, int nbytes)
|
||||
int sum, oddbyte;
|
||||
|
||||
sum = 0;
|
||||
while (nbytes > 1)
|
||||
{
|
||||
while (nbytes > 1) {
|
||||
sum += *ptr++;
|
||||
nbytes -= 2;
|
||||
}
|
||||
if (nbytes == 1)
|
||||
{
|
||||
if (nbytes == 1) {
|
||||
oddbyte = 0;
|
||||
((u_char *) & oddbyte)[0] = *(u_char *) ptr;
|
||||
((u_char *) & oddbyte)[1] = 0;
|
||||
@ -108,19 +106,16 @@ TcpChecksum(struct ip *pip)
|
||||
/* Add up TCP header and data */
|
||||
nbytes = ntcp;
|
||||
sum = 0;
|
||||
while (nbytes > 1)
|
||||
{
|
||||
while (nbytes > 1) {
|
||||
sum += *ptr++;
|
||||
nbytes -= 2;
|
||||
}
|
||||
if (nbytes == 1)
|
||||
{
|
||||
if (nbytes == 1) {
|
||||
oddbyte = 0;
|
||||
((u_char *) & oddbyte)[0] = *(u_char *) ptr;
|
||||
((u_char *) & oddbyte)[1] = 0;
|
||||
sum += oddbyte;
|
||||
}
|
||||
|
||||
/* "Pseudo-header" data */
|
||||
ptr = (u_short *) & (pip->ip_dst);
|
||||
sum += *ptr++;
|
||||
@ -147,24 +142,19 @@ DifferentialChecksum(u_short *cksum, u_short *new, u_short *old, int n)
|
||||
int accumulate;
|
||||
|
||||
accumulate = *cksum;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
accumulate -= *new++;
|
||||
accumulate += *old++;
|
||||
}
|
||||
|
||||
if (accumulate < 0)
|
||||
{
|
||||
if (accumulate < 0) {
|
||||
accumulate = -accumulate;
|
||||
accumulate = (accumulate >> 16) + (accumulate & 0xffff);
|
||||
accumulate += accumulate >> 16;
|
||||
*cksum = (u_short) ~ accumulate;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
accumulate = (accumulate >> 16) + (accumulate & 0xffff);
|
||||
accumulate += accumulate >> 16;
|
||||
*cksum = (u_short) accumulate;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 Charles Mott <cm@linktel.net>
|
||||
* All rights reserved.
|
||||
@ -165,8 +163,7 @@ TcpMonitorIn(struct ip *pip, struct alias_link *link)
|
||||
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
switch (GetStateIn(link))
|
||||
{
|
||||
switch (GetStateIn(link)) {
|
||||
case ALIAS_TCP_STATE_NOT_CONNECTED:
|
||||
if (tc->th_flags & TH_RST)
|
||||
SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED);
|
||||
@ -187,8 +184,7 @@ TcpMonitorOut(struct ip *pip, struct alias_link *link)
|
||||
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
switch (GetStateOut(link))
|
||||
{
|
||||
switch (GetStateOut(link)) {
|
||||
case ALIAS_TCP_STATE_NOT_CONNECTED:
|
||||
if (tc->th_flags & TH_RST)
|
||||
SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED);
|
||||
@ -279,8 +275,7 @@ IcmpAliasIn1(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* Get source address from ICMP data field and restore original data */
|
||||
link = FindIcmpIn(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short original_id;
|
||||
int accumulate;
|
||||
|
||||
@ -347,10 +342,8 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
|
||||
} else
|
||||
link = NULL;
|
||||
|
||||
if (link != NULL)
|
||||
{
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate, accumulate2;
|
||||
struct in_addr original_address;
|
||||
@ -385,9 +378,7 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
|
||||
fragment contained in ICMP data section */
|
||||
ip->ip_src = original_address;
|
||||
ud->uh_sport = original_port;
|
||||
}
|
||||
else if (ip->ip_p == IPPROTO_ICMP)
|
||||
{
|
||||
} else if (ip->ip_p == IPPROTO_ICMP) {
|
||||
u_short *sptr;
|
||||
int accumulate, accumulate2;
|
||||
struct in_addr original_address;
|
||||
@ -442,12 +433,10 @@ IcmpAliasIn(struct libalias *la, struct ip *pip)
|
||||
ic = (struct icmp *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
switch (ic->icmp_type)
|
||||
{
|
||||
switch (ic->icmp_type) {
|
||||
case ICMP_ECHOREPLY:
|
||||
case ICMP_TSTAMPREPLY:
|
||||
if (ic->icmp_code == 0)
|
||||
{
|
||||
if (ic->icmp_code == 0) {
|
||||
iresult = IcmpAliasIn1(la, pip);
|
||||
}
|
||||
break;
|
||||
@ -480,8 +469,7 @@ IcmpAliasOut1(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* Save overwritten data for when echo packet returns */
|
||||
link = FindIcmpOut(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_id;
|
||||
int accumulate;
|
||||
|
||||
@ -549,10 +537,8 @@ IcmpAliasOut2(struct libalias *la, struct ip *pip)
|
||||
} else
|
||||
link = NULL;
|
||||
|
||||
if (link != NULL)
|
||||
{
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr alias_address;
|
||||
@ -583,14 +569,11 @@ IcmpAliasOut2(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_src = alias_address;
|
||||
}
|
||||
|
||||
/* Alias address and port number of original IP packet
|
||||
fragment contained in ICMP data section */
|
||||
ip->ip_dst = alias_address;
|
||||
ud->uh_dport = alias_port;
|
||||
}
|
||||
else if (ip->ip_p == IPPROTO_ICMP)
|
||||
{
|
||||
} else if (ip->ip_p == IPPROTO_ICMP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr alias_address;
|
||||
@ -621,7 +604,6 @@ fragment contained in ICMP data section */
|
||||
2);
|
||||
pip->ip_src = alias_address;
|
||||
}
|
||||
|
||||
/* Alias address of original IP packet and sequence number of
|
||||
embedded ICMP datagram */
|
||||
ip->ip_dst = alias_address;
|
||||
@ -646,12 +628,10 @@ IcmpAliasOut(struct libalias *la, struct ip *pip)
|
||||
ic = (struct icmp *)((char *)pip + (pip->ip_hl << 2));
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
switch (ic->icmp_type)
|
||||
{
|
||||
switch (ic->icmp_type) {
|
||||
case ICMP_ECHO:
|
||||
case ICMP_TSTAMP:
|
||||
if (ic->icmp_code == 0)
|
||||
{
|
||||
if (ic->icmp_code == 0) {
|
||||
iresult = IcmpAliasOut1(la, pip);
|
||||
}
|
||||
break;
|
||||
@ -686,8 +666,7 @@ ProtoAliasIn(struct libalias *la, struct ip *pip)
|
||||
return PKT_ALIAS_OK;
|
||||
|
||||
link = FindProtoIn(la, pip->ip_src, pip->ip_dst, pip->ip_p);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr original_address;
|
||||
|
||||
original_address = GetOriginalAddress(link);
|
||||
@ -720,8 +699,7 @@ ProtoAliasOut(struct libalias *la, struct ip *pip)
|
||||
return PKT_ALIAS_OK;
|
||||
|
||||
link = FindProtoOut(la, pip->ip_src, pip->ip_dst, pip->ip_p);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
|
||||
alias_address = GetAliasAddress(link);
|
||||
@ -754,8 +732,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
link = FindUdpTcpIn(la, pip->ip_src, pip->ip_dst,
|
||||
ud->uh_sport, ud->uh_dport,
|
||||
IPPROTO_UDP, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
struct in_addr original_address;
|
||||
u_short alias_port;
|
||||
@ -782,8 +759,7 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If UDP checksum is not zero, then adjust since destination port */
|
||||
/* is being unaliased and destination address is being altered. */
|
||||
if (ud->uh_sum != 0)
|
||||
{
|
||||
if (ud->uh_sum != 0) {
|
||||
accumulate = alias_port;
|
||||
accumulate -= ud->uh_dport;
|
||||
sptr = (u_short *) & alias_address;
|
||||
@ -794,7 +770,6 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
|
||||
}
|
||||
|
||||
/* Restore original IP address */
|
||||
DifferentialChecksum(&pip->ip_sum,
|
||||
(u_short *) & original_address,
|
||||
@ -828,8 +803,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
|
||||
ud->uh_sport, ud->uh_dport,
|
||||
IPPROTO_UDP, 1);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_port;
|
||||
struct in_addr alias_address;
|
||||
|
||||
@ -858,8 +832,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If UDP checksum is not zero, adjust since source port is */
|
||||
/* being aliased and source address is being altered */
|
||||
if (ud->uh_sum != 0)
|
||||
{
|
||||
if (ud->uh_sum != 0) {
|
||||
int accumulate;
|
||||
u_short *sptr;
|
||||
|
||||
@ -873,7 +846,6 @@ UdpAliasOut(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
|
||||
}
|
||||
|
||||
/* Put alias port in UDP header */
|
||||
ud->uh_sport = alias_port;
|
||||
|
||||
@ -903,8 +875,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
tc->th_sport, tc->th_dport,
|
||||
IPPROTO_TCP,
|
||||
!(la->packetAliasMode & PKT_ALIAS_PROXY_ONLY));
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr alias_address;
|
||||
struct in_addr original_address;
|
||||
struct in_addr proxy_address;
|
||||
@ -941,8 +912,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If this is a proxy, then modify the TCP source port and
|
||||
checksum accumulation */
|
||||
if (proxy_port != 0)
|
||||
{
|
||||
if (proxy_port != 0) {
|
||||
accumulate += tc->th_sport;
|
||||
tc->th_sport = proxy_port;
|
||||
accumulate -= tc->th_sport;
|
||||
@ -954,15 +924,12 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr++;
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
|
||||
/* See if ACK number needs to be modified */
|
||||
if (GetAckModified(link) == 1)
|
||||
{
|
||||
if (GetAckModified(link) == 1) {
|
||||
int delta;
|
||||
|
||||
delta = GetDeltaAckIn(pip, link);
|
||||
if (delta != 0)
|
||||
{
|
||||
if (delta != 0) {
|
||||
sptr = (u_short *) & tc->th_ack;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -972,7 +939,6 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, tc->th_sum);
|
||||
|
||||
/* Restore original IP address */
|
||||
@ -986,8 +952,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
|
||||
/* If this is a transparent proxy packet, then modify the source
|
||||
address */
|
||||
if (proxy_address.s_addr != 0)
|
||||
{
|
||||
if (proxy_address.s_addr != 0) {
|
||||
sptr = (u_short *) & pip->ip_src;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -996,7 +961,6 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
|
||||
accumulate -= *sptr++;
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, pip->ip_sum);
|
||||
|
||||
/* Monitor TCP connection state */
|
||||
@ -1029,8 +993,7 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
then alter the destination and adjust checksums */
|
||||
dest_port = tc->th_dport;
|
||||
dest_address = pip->ip_dst;
|
||||
if (proxy_type != 0)
|
||||
{
|
||||
if (proxy_type != 0) {
|
||||
int accumulate;
|
||||
u_short *sptr;
|
||||
|
||||
@ -1057,12 +1020,10 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, pip->ip_sum);
|
||||
}
|
||||
|
||||
link = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
|
||||
tc->th_sport, tc->th_dport,
|
||||
IPPROTO_TCP, 1);
|
||||
if (link !=NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
u_short alias_port;
|
||||
struct in_addr alias_address;
|
||||
int accumulate;
|
||||
@ -1071,14 +1032,12 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
/* Save original destination address, if this is a proxy packet.
|
||||
Also modify packet to include destination encoding. This may
|
||||
change the size of IP header. */
|
||||
if (proxy_type != 0)
|
||||
{
|
||||
if (proxy_type != 0) {
|
||||
SetProxyPort(link, dest_port);
|
||||
SetProxyAddress(link, dest_address);
|
||||
ProxyModify(la, link, pip, maxpacketsize, proxy_type);
|
||||
tc = (struct tcphdr *)((char *)pip + (pip->ip_hl << 2));
|
||||
}
|
||||
|
||||
/* Get alias address and port */
|
||||
alias_port = GetAliasPort(link);
|
||||
alias_address = GetAliasAddress(link);
|
||||
@ -1119,13 +1078,11 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
accumulate -= *sptr;
|
||||
|
||||
/* Modify sequence number if necessary */
|
||||
if (GetAckModified(link) == 1)
|
||||
{
|
||||
if (GetAckModified(link) == 1) {
|
||||
int delta;
|
||||
|
||||
delta = GetDeltaSeqOut(pip, link);
|
||||
if (delta != 0)
|
||||
{
|
||||
if (delta != 0) {
|
||||
sptr = (u_short *) & tc->th_seq;
|
||||
accumulate += *sptr++;
|
||||
accumulate += *sptr;
|
||||
@ -1135,7 +1092,6 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize)
|
||||
accumulate -= *sptr;
|
||||
}
|
||||
}
|
||||
|
||||
ADJUST_CHECKSUM(accumulate, tc->th_sum);
|
||||
|
||||
/* Change source address */
|
||||
@ -1181,8 +1137,7 @@ FragmentIn(struct libalias *la, struct ip *pip)
|
||||
struct alias_link *link;
|
||||
|
||||
link = FindFragmentIn2(la, pip->ip_src, pip->ip_dst, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
struct in_addr original_address;
|
||||
|
||||
GetFragmentAddr(link, &original_address);
|
||||
@ -1241,8 +1196,7 @@ LibAliasSaveFragment(struct libalias *la, char *ptr)
|
||||
pip = (struct ip *)ptr;
|
||||
link = AddFragmentPtrLink(la, pip->ip_src, pip->ip_id);
|
||||
iresult = PKT_ALIAS_ERROR;
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
SetFragmentPtr(link, ptr);
|
||||
iresult = PKT_ALIAS_OK;
|
||||
}
|
||||
@ -1259,26 +1213,24 @@ LibAliasGetFragment(struct libalias *la, char *ptr)
|
||||
|
||||
pip = (struct ip *)ptr;
|
||||
link = FindFragmentPtr(la, pip->ip_src, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
GetFragmentPtr(link, &fptr);
|
||||
SetFragmentPtr(link, NULL);
|
||||
SetExpire(link, 0); /* Deletes link */
|
||||
|
||||
return (fptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly de-aliased
|
||||
header fragment */
|
||||
char *ptr_fragment /* Points to fragment which must
|
||||
be de-aliased */
|
||||
LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly
|
||||
* de-aliased header
|
||||
* fragment */
|
||||
char *ptr_fragment /* Points to fragment which must be
|
||||
* de-aliased */
|
||||
)
|
||||
{
|
||||
struct ip *pip;
|
||||
@ -1308,7 +1260,6 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
la->packetAliasMode |= PKT_ALIAS_REVERSE;
|
||||
return iresult;
|
||||
}
|
||||
|
||||
HouseKeeping(la);
|
||||
ClearCheckNewLink(la);
|
||||
pip = (struct ip *)ptr;
|
||||
@ -1320,10 +1271,8 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
return PKT_ALIAS_IGNORED;
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
if ( (ntohs(pip->ip_off) & IP_OFFMASK) == 0 )
|
||||
{
|
||||
switch (pip->ip_p)
|
||||
{
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
iresult = IcmpAliasIn(la, pip);
|
||||
break;
|
||||
@ -1345,24 +1294,18 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ntohs(pip->ip_off) & IP_MF)
|
||||
{
|
||||
if (ntohs(pip->ip_off) & IP_MF) {
|
||||
struct alias_link *link;
|
||||
|
||||
link = FindFragmentIn1(la, pip->ip_src, alias_addr, pip->ip_id);
|
||||
if (link != NULL)
|
||||
{
|
||||
if (link != NULL) {
|
||||
iresult = PKT_ALIAS_FOUND_HEADER_FRAGMENT;
|
||||
SetFragmentAddr(link, pip->ip_dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = PKT_ALIAS_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = FragmentIn(la, pip);
|
||||
}
|
||||
|
||||
@ -1387,8 +1330,8 @@ LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
|
||||
|
||||
int
|
||||
LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
int maxpacketsize /* How much the packet data may grow
|
||||
(FTP and IRC inline changes) */
|
||||
int maxpacketsize /* How much the packet data may grow (FTP
|
||||
* and IRC inline changes) */
|
||||
)
|
||||
{
|
||||
int iresult;
|
||||
@ -1401,7 +1344,6 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
la->packetAliasMode |= PKT_ALIAS_REVERSE;
|
||||
return iresult;
|
||||
}
|
||||
|
||||
HouseKeeping(la);
|
||||
ClearCheckNewLink(la);
|
||||
pip = (struct ip *)ptr;
|
||||
@ -1412,8 +1354,7 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
return PKT_ALIAS_IGNORED;
|
||||
|
||||
addr_save = GetDefaultAliasAddress(la);
|
||||
if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY)
|
||||
{
|
||||
if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY) {
|
||||
u_long addr;
|
||||
int iclass;
|
||||
|
||||
@ -1426,21 +1367,15 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
else if (addr >= UNREG_ADDR_A_LOWER && addr <= UNREG_ADDR_A_UPPER)
|
||||
iclass = 1;
|
||||
|
||||
if (iclass == 0)
|
||||
{
|
||||
if (iclass == 0) {
|
||||
SetDefaultAliasAddress(la, pip->ip_src);
|
||||
}
|
||||
}
|
||||
else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
|
||||
{
|
||||
} else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) {
|
||||
SetDefaultAliasAddress(la, pip->ip_src);
|
||||
}
|
||||
|
||||
iresult = PKT_ALIAS_IGNORED;
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0)
|
||||
{
|
||||
switch (pip->ip_p)
|
||||
{
|
||||
if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
iresult = IcmpAliasOut(la, pip);
|
||||
break;
|
||||
@ -1460,9 +1395,7 @@ LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */
|
||||
iresult = ProtoAliasOut(la, pip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iresult = FragmentOut(la, pip);
|
||||
}
|
||||
|
||||
@ -1508,10 +1441,8 @@ LibAliasUnaliasOut(struct libalias *la, char *ptr, /* valid IP packet
|
||||
link = NULL;
|
||||
|
||||
/* Change it from an aliased packet to an unaliased packet */
|
||||
if (link != NULL)
|
||||
{
|
||||
if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP)
|
||||
{
|
||||
if (link != NULL) {
|
||||
if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP) {
|
||||
u_short *sptr;
|
||||
int accumulate;
|
||||
struct in_addr original_address;
|
||||
|
@ -88,7 +88,8 @@ int PacketUnaliasOut(char *_ptr, int _maxpacketsize);
|
||||
/* Port and address redirection functions. */
|
||||
|
||||
|
||||
int PacketAliasAddServer(struct alias_link *_link,
|
||||
int
|
||||
PacketAliasAddServer(struct alias_link *_link,
|
||||
struct in_addr _addr, unsigned short _port);
|
||||
struct alias_link *
|
||||
PacketAliasRedirectAddr(struct in_addr _src_addr,
|
||||
@ -137,7 +138,8 @@ int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
|
||||
|
||||
/* Port and address redirection functions. */
|
||||
|
||||
int LibAliasAddServer(struct libalias *, struct alias_link *_link,
|
||||
int
|
||||
LibAliasAddServer(struct libalias *, struct alias_link *_link,
|
||||
struct in_addr _addr, unsigned short _port);
|
||||
struct alias_link *
|
||||
LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
|
||||
|
@ -63,7 +63,8 @@ struct oc_header {
|
||||
/* client info structures */
|
||||
struct client_info {
|
||||
u_int32_t address;/* Client address */
|
||||
char reserved[8]; /* Flags, pruning bitfield, packet counts etc */
|
||||
char reserved [8]; /* Flags, pruning bitfield, packet
|
||||
* counts etc */
|
||||
};
|
||||
|
||||
void
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -105,7 +105,8 @@ AliasHandleFtpOut(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link, /* The link to go through (aliased port) */
|
||||
int maxpacketsize /* The maximum size this packet can grow to (including headers) */)
|
||||
int maxpacketsize /* The maximum size this packet can grow to
|
||||
(including headers) */ )
|
||||
{
|
||||
int hlen, tlen, dlen, pflags;
|
||||
char *sptr;
|
||||
@ -153,12 +154,12 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
if (ftp_message_type != FTP_UNKNOWN_MESSAGE)
|
||||
NewFtpMessage(la, pip, link, maxpacketsize, ftp_message_type);
|
||||
}
|
||||
|
||||
/* Track the msgs which are CRLF term'd for PORT/PASV FW breach */
|
||||
|
||||
if (dlen) { /* only if there's data */
|
||||
sptr = (char *)pip; /* start over at beginning */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may have grown */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may
|
||||
* have grown */
|
||||
if (sptr[tlen - 2] == '\r' && sptr[tlen - 1] == '\n')
|
||||
pflags &= ~WAIT_CRLF;
|
||||
else
|
||||
@ -187,24 +188,52 @@ ParseFtpPortCommand(struct libalias *la, char *sptr, int dlen)
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state) {
|
||||
case -4: if (ch == 'P') state++; else return 0; break;
|
||||
case -3: if (ch == 'O') state++; else return 0; break;
|
||||
case -2: if (ch == 'R') state++; else return 0; break;
|
||||
case -1: if (ch == 'T') state++; else return 0; break;
|
||||
case -4:
|
||||
if (ch == 'P')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -3:
|
||||
if (ch == 'O')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == 'R')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == 'T')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (isspace(ch))
|
||||
break;
|
||||
else
|
||||
state++;
|
||||
case 1: case 3: case 5: case 7: case 9: case 11:
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
case 11:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 2: case 4: case 6: case 8:
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',') {
|
||||
@ -213,7 +242,8 @@ ParseFtpPortCommand(struct libalias *la, char *sptr, int dlen)
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 10: case 12:
|
||||
case 10:
|
||||
case 12:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',' || state == 12) {
|
||||
@ -253,12 +283,31 @@ ParseFtpEprtCommand(struct libalias *la, char *sptr, int dlen)
|
||||
state = -4;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -4: if (ch == 'E') state++; else return 0; break;
|
||||
case -3: if (ch == 'P') state++; else return 0; break;
|
||||
case -2: if (ch == 'R') state++; else return 0; break;
|
||||
case -1: if (ch == 'T') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -4:
|
||||
if (ch == 'E')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -3:
|
||||
if (ch == 'P')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == 'R')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == 'T')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (!isspace(ch)) {
|
||||
@ -278,14 +327,20 @@ ParseFtpEprtCommand(struct libalias *la, char *sptr, int dlen)
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case 3: case 5: case 7: case 9:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 4: case 6: case 8: case 10:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
case 10:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == '.' || state == 10) {
|
||||
@ -340,24 +395,46 @@ ParseFtp227Reply(struct libalias *la, char *sptr, int dlen)
|
||||
state = -3;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -3: if (ch == '2') state++; else return 0; break;
|
||||
case -2: if (ch == '2') state++; else return 0; break;
|
||||
case -1: if (ch == '7') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -3:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == '7')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (ch == '(')
|
||||
state++;
|
||||
break;
|
||||
case 1: case 3: case 5: case 7: case 9: case 11:
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 9:
|
||||
case 11:
|
||||
if (isdigit(ch)) {
|
||||
octet = ch - '0';
|
||||
state++;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 2: case 4: case 6: case 8:
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',') {
|
||||
@ -366,7 +443,8 @@ ParseFtp227Reply(struct libalias *la, char *sptr, int dlen)
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
case 10: case 12:
|
||||
case 10:
|
||||
case 12:
|
||||
if (isdigit(ch))
|
||||
octet = 10 * octet + ch - '0';
|
||||
else if (ch == ',' || (state == 12 && ch == ')')) {
|
||||
@ -405,11 +483,25 @@ ParseFtp229Reply(struct libalias *la, char *sptr, int dlen)
|
||||
state = -3;
|
||||
for (i = 0; i < dlen; i++) {
|
||||
ch = sptr[i];
|
||||
switch (state)
|
||||
{
|
||||
case -3: if (ch == '2') state++; else return 0; break;
|
||||
case -2: if (ch == '2') state++; else return 0; break;
|
||||
case -1: if (ch == '9') state++; else return 0; break;
|
||||
switch (state) {
|
||||
case -3:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -2:
|
||||
if (ch == '2')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case -1:
|
||||
if (ch == '9')
|
||||
state++;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (ch == '(')
|
||||
@ -419,7 +511,8 @@ ParseFtp229Reply(struct libalias *la, char *sptr, int dlen)
|
||||
delim = ch;
|
||||
state++;
|
||||
break;
|
||||
case 2: case 3:
|
||||
case 2:
|
||||
case 3:
|
||||
if (ch == delim)
|
||||
state++;
|
||||
else
|
||||
@ -475,8 +568,7 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
ftp_link = FindUdpTcpOut(la, la->true_addr, GetDestAddress(link),
|
||||
htons(la->true_port), 0, IPPROTO_TCP, 1);
|
||||
|
||||
if (ftp_link != NULL)
|
||||
{
|
||||
if (ftp_link != NULL) {
|
||||
int slen, hlen, tlen, dlen;
|
||||
struct tcphdr *tc;
|
||||
|
||||
@ -503,17 +595,20 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
/* Decompose alias address into quad format */
|
||||
alias_address = GetAliasAddress(link);
|
||||
ptr = (u_char *) & alias_address.s_addr;
|
||||
a1 = *ptr++; a2=*ptr++; a3=*ptr++; a4=*ptr;
|
||||
a1 = *ptr++;
|
||||
a2 = *ptr++;
|
||||
a3 = *ptr++;
|
||||
a4 = *ptr;
|
||||
|
||||
alias_port = GetAliasPort(ftp_link);
|
||||
|
||||
switch (ftp_message_type)
|
||||
{
|
||||
switch (ftp_message_type) {
|
||||
case FTP_PORT_COMMAND:
|
||||
case FTP_227_REPLY:
|
||||
/* Decompose alias port into pair format. */
|
||||
ptr = (char *)&alias_port;
|
||||
p1 = *ptr++; p2=*ptr;
|
||||
p1 = *ptr++;
|
||||
p2 = *ptr;
|
||||
|
||||
if (ftp_message_type == FTP_PORT_COMMAND) {
|
||||
/* Generate PORT command string. */
|
||||
@ -542,7 +637,8 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
slen = strlen(stemp);
|
||||
|
||||
/* Copy modified buffer into IP packet. */
|
||||
sptr = (char *) pip; sptr += hlen;
|
||||
sptr = (char *)pip;
|
||||
sptr += hlen;
|
||||
strncpy(sptr, stemp, maxpacketsize - hlen);
|
||||
}
|
||||
|
||||
@ -570,9 +666,7 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
|
||||
/* Compute TCP checksum for revised packet */
|
||||
tc->th_sum = 0;
|
||||
tc->th_sum = TcpChecksum(pip);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"PacketAlias/HandleFtpOut: Cannot allocate FTP data port\n");
|
||||
|
@ -68,7 +68,8 @@ void
|
||||
AliasHandleIrcOut(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine */
|
||||
struct alias_link *link, /* Which link are we on? */
|
||||
int maxsize /* Maximum size of IP packet including headers */
|
||||
int maxsize /* Maximum size of IP packet including
|
||||
* headers */
|
||||
)
|
||||
{
|
||||
int hlen, tlen, dlen;
|
||||
@ -84,14 +85,18 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
tlen = ntohs(pip->ip_len);
|
||||
dlen = tlen - hlen;
|
||||
|
||||
/* Return if data length is too short - assume an entire PRIVMSG in each packet. */
|
||||
/*
|
||||
* Return if data length is too short - assume an entire PRIVMSG in
|
||||
* each packet.
|
||||
*/
|
||||
if (dlen < sizeof(":A!a@n.n PRIVMSG A :aDCC 1 1a") - 1)
|
||||
return;
|
||||
|
||||
/* Place string pointer at beginning of data */
|
||||
sptr = (char *)pip;
|
||||
sptr += hlen;
|
||||
maxsize -= hlen; /* We're interested in maximum size of data, not packet */
|
||||
maxsize -= hlen; /* We're interested in maximum size of
|
||||
* data, not packet */
|
||||
|
||||
/* Search for a CTCP command [Note 1] */
|
||||
for (i = 0; i < dlen; i++) {
|
||||
@ -102,15 +107,20 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
/* Handle CTCP commands - the buffer may have to be copied */
|
||||
lFOUND_CTCP:
|
||||
{
|
||||
char newpacket[65536]; /* Estimate of maximum packet size :) */
|
||||
char newpacket[65536]; /* Estimate of maximum packet size
|
||||
* :) */
|
||||
int copyat = i; /* Same */
|
||||
int iCopy = 0; /* How much data have we written to copy-back string? */
|
||||
int iCopy = 0; /* How much data have we written to
|
||||
* copy-back string? */
|
||||
unsigned long org_addr; /* Original IP address */
|
||||
unsigned short org_port; /* Original source port address */
|
||||
unsigned short org_port; /* Original source port
|
||||
* address */
|
||||
|
||||
lCTCP_START:
|
||||
if (i >= dlen || iCopy >= sizeof(newpacket))
|
||||
goto lPACKET_DONE;
|
||||
newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start character */
|
||||
newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start
|
||||
* character */
|
||||
/* Start of a CTCP */
|
||||
if (i + 4 >= dlen) /* Too short for DCC */
|
||||
goto lBAD_CTCP;
|
||||
@ -132,8 +142,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = ' ';
|
||||
|
||||
DBprintf(("Found DCC\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces\n"));
|
||||
@ -154,8 +166,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = sptr[i++];
|
||||
|
||||
DBprintf(("Done command - removing spaces\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces (post-command)\n"));
|
||||
@ -176,8 +190,10 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
newpacket[iCopy++] = sptr[i++];
|
||||
|
||||
DBprintf(("Done filename - removing spaces\n"));
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("DCC packet terminated in just spaces (post-filename)\n"));
|
||||
@ -201,9 +217,11 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
DBprintf(("Overflow (%d >= %d) or bad character (%02x) terminating IP address\n", i + 1, dlen, sptr[i]));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
/* Skip any extra spaces (should not occur according to
|
||||
protocol, but DCC breaks CTCP protocol anyway, so we might
|
||||
as well play it safe */
|
||||
/*
|
||||
* Skip any extra spaces (should not occur according to
|
||||
* protocol, but DCC breaks CTCP protocol anyway, so we
|
||||
* might as well play it safe
|
||||
*/
|
||||
while (sptr[i] == ' ') {
|
||||
if (++i >= dlen) {
|
||||
DBprintf(("Packet failure - space overflow.\n"));
|
||||
@ -214,7 +232,8 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
/* Fetch source port */
|
||||
org_port = 0;
|
||||
while (i < dlen && isdigit(sptr[i])) {
|
||||
if( org_port > 6554 ) { /* Terminate on overflow (65536/10 rounded up*/
|
||||
if (org_port > 6554) { /* Terminate on overflow
|
||||
* (65536/10 rounded up */
|
||||
DBprintf(("DCC: port number overflow\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
@ -244,16 +263,19 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
org_port < IPPORT_RESERVED)
|
||||
goto lBAD_CTCP;
|
||||
|
||||
/* Steal the FTP_DATA_PORT - it doesn't really matter, and this
|
||||
would probably allow it through at least _some_
|
||||
firewalls. */
|
||||
/*
|
||||
* Steal the FTP_DATA_PORT - it doesn't really
|
||||
* matter, and this would probably allow it through
|
||||
* at least _some_ firewalls.
|
||||
*/
|
||||
dcc_link = FindUdpTcpOut(la, true_addr, destaddr,
|
||||
true_port, 0,
|
||||
IPPROTO_TCP, 1);
|
||||
DBprintf(("Got a DCC link\n"));
|
||||
if (dcc_link) {
|
||||
struct in_addr alias_address; /* Address from aliasing */
|
||||
u_short alias_port; /* Port given by aliasing */
|
||||
u_short alias_port; /* Port given by
|
||||
* aliasing */
|
||||
int n;
|
||||
|
||||
#ifndef NO_FW_PUNCH
|
||||
@ -269,7 +291,8 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
DBprintf(("DCC packet construct failure.\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
if( (iCopy += n) >= sizeof(newpacket) ) { /* Truncated/fit exactly - bad news */
|
||||
if ((iCopy += n) >= sizeof(newpacket)) { /* Truncated/fit exactly
|
||||
* - bad news */
|
||||
DBprintf(("DCC constructed packet overflow.\n"));
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
@ -282,13 +305,18 @@ AliasHandleIrcOut(struct libalias *la,
|
||||
goto lBAD_CTCP;
|
||||
}
|
||||
iCopy += n;
|
||||
/* Done - truncated cases will be taken care of by lBAD_CTCP */
|
||||
/*
|
||||
* Done - truncated cases will be taken
|
||||
* care of by lBAD_CTCP
|
||||
*/
|
||||
DBprintf(("Aliased IP %lu and port %u\n", alias_address.s_addr, (unsigned)alias_port));
|
||||
}
|
||||
}
|
||||
/* An uninteresting CTCP - state entered right after '\001' has
|
||||
been pushed. Also used to copy the rest of a DCC, after IP
|
||||
address and port has been handled */
|
||||
/*
|
||||
* An uninteresting CTCP - state entered right after '\001'
|
||||
* has been pushed. Also used to copy the rest of a DCC,
|
||||
* after IP address and port has been handled
|
||||
*/
|
||||
lBAD_CTCP:
|
||||
for (; i < dlen && iCopy < sizeof(newpacket); i++, iCopy++) {
|
||||
newpacket[iCopy] = sptr[i]; /* Copy CTCP unchanged */
|
||||
|
@ -95,7 +95,8 @@ struct libalias {
|
||||
int timeStamp; /* System time in seconds for */
|
||||
/* current packet */
|
||||
|
||||
int lastCleanupTime; /* Last time IncrementalCleanup() */
|
||||
int lastCleanupTime; /* Last time
|
||||
* IncrementalCleanup() */
|
||||
/* was called */
|
||||
|
||||
int houseKeepingResidual; /* used by HouseKeeping() */
|
||||
@ -116,9 +117,12 @@ struct libalias {
|
||||
/* PacketAliasSetMode on first */
|
||||
/* setting the PKT_ALIAS_PUNCH_FW */
|
||||
/* flag. */
|
||||
int fireWallBaseNum; /* The first firewall entry free for our use */
|
||||
int fireWallNumNums; /* How many entries can we use? */
|
||||
int fireWallActiveNum; /* Which entry did we last use? */
|
||||
int fireWallBaseNum; /* The first firewall entry
|
||||
* free for our use */
|
||||
int fireWallNumNums; /* How many entries can we
|
||||
* use? */
|
||||
int fireWallActiveNum; /* Which entry did we last
|
||||
* use? */
|
||||
char *fireWallField; /* bool array for entries */
|
||||
#endif
|
||||
|
||||
@ -163,7 +167,8 @@ struct libalias {
|
||||
/* General utilities */
|
||||
u_short IpChecksum(struct ip *_pip);
|
||||
u_short TcpChecksum(struct ip *_pip);
|
||||
void DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old,
|
||||
void
|
||||
DifferentialChecksum(u_short * _cksum, u_short * _new, u_short * _old,
|
||||
int _n);
|
||||
|
||||
/* Internal data access */
|
||||
@ -219,7 +224,8 @@ struct in_addr
|
||||
FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
|
||||
|
||||
/* External data access/modification */
|
||||
int FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
|
||||
int
|
||||
FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
|
||||
u_short _src_port, u_short _dst_port, u_short _port_count,
|
||||
u_char _proto, u_char _align);
|
||||
void GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
|
||||
@ -256,8 +262,10 @@ void ClearCheckNewLink(struct libalias *la);
|
||||
void SetProtocolFlags(struct alias_link *_link, int _pflags);
|
||||
int GetProtocolFlags(struct alias_link *_link);
|
||||
void SetDestCallId(struct alias_link *_link, u_int16_t _cid);
|
||||
|
||||
#ifndef NO_FW_PUNCH
|
||||
void PunchFWHole(struct alias_link *_link);
|
||||
|
||||
#endif
|
||||
|
||||
/* Housekeeping function */
|
||||
@ -267,15 +275,18 @@ void HouseKeeping(struct libalias *);
|
||||
/* lint -save -library Suppress flexelint warnings */
|
||||
|
||||
/* FTP routines */
|
||||
void AliasHandleFtpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleFtpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxpacketsize);
|
||||
|
||||
/* IRC routines */
|
||||
void AliasHandleIrcOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleIrcOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxsize);
|
||||
|
||||
/* RTSP routines */
|
||||
void AliasHandleRtspOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
void
|
||||
AliasHandleRtspOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int _maxpacketsize);
|
||||
|
||||
/* PPTP routines */
|
||||
@ -285,9 +296,11 @@ int AliasHandlePptpGreOut(struct libalias *la, struct ip *_pip);
|
||||
int AliasHandlePptpGreIn(struct libalias *la, struct ip *_pip);
|
||||
|
||||
/* NetBIOS routines */
|
||||
int AliasHandleUdpNbt(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int
|
||||
AliasHandleUdpNbt(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
struct in_addr *_alias_address, u_short _alias_port);
|
||||
int AliasHandleUdpNbtNS(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
int
|
||||
AliasHandleUdpNbtNS(struct libalias *la, struct ip *_pip, struct alias_link *_link,
|
||||
struct in_addr *_alias_address, u_short * _alias_port,
|
||||
struct in_addr *_original_address, u_short * _original_port);
|
||||
|
||||
@ -299,9 +312,11 @@ void AliasHandleCUSeeMeIn(struct libalias *la, struct ip *_pip, struct in_addr
|
||||
void AliasHandleSkinny(struct libalias *la, struct ip *_pip, struct alias_link *_link);
|
||||
|
||||
/* Transparent proxy routines */
|
||||
int ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
|
||||
int
|
||||
ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
|
||||
u_short * _proxy_server_port);
|
||||
void ProxyModify(struct libalias *la, struct alias_link *_link, struct ip *_pip,
|
||||
void
|
||||
ProxyModify(struct libalias *la, struct alias_link *_link, struct ip *_pip,
|
||||
int _maxpacketsize, int _proxy_type);
|
||||
|
||||
enum alias_tcp_state {
|
||||
|
@ -96,7 +96,9 @@ typedef struct {
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
static void PrintRcode( u_char rcode ) {
|
||||
static void
|
||||
PrintRcode(u_char rcode)
|
||||
{
|
||||
|
||||
switch (rcode) {
|
||||
case FMT_ERR:
|
||||
@ -116,11 +118,14 @@ static void PrintRcode( u_char rcode ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Handling Name field */
|
||||
static u_char *AliasHandleName ( u_char *p, char *pmax ) {
|
||||
static u_char *
|
||||
AliasHandleName(u_char * p, char *pmax)
|
||||
{
|
||||
|
||||
u_char *s;
|
||||
u_char c;
|
||||
@ -195,13 +200,15 @@ static u_char *AliasHandleName ( u_char *p, char *pmax ) {
|
||||
#define DGM_POSITIVE_RES 0x15
|
||||
#define DGM_NEGATIVE_RES 0x16
|
||||
|
||||
int AliasHandleUdpNbt(
|
||||
int
|
||||
AliasHandleUdpNbt(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link,
|
||||
struct in_addr *alias_address,
|
||||
u_short alias_port
|
||||
) {
|
||||
)
|
||||
{
|
||||
struct udphdr *uh;
|
||||
NbtDataHeader *ndh;
|
||||
u_char *p = NULL;
|
||||
@ -244,6 +251,7 @@ int AliasHandleUdpNbt(
|
||||
if (uh->uh_sum != 0) {
|
||||
int acc;
|
||||
u_short *sptr;
|
||||
|
||||
acc = ndh->source_port;
|
||||
acc -= alias_port;
|
||||
sptr = (u_short *) & (ndh->source_ip);
|
||||
@ -262,6 +270,7 @@ int AliasHandleUdpNbt(
|
||||
#endif
|
||||
return ((p == NULL) ? -1 : 0);
|
||||
}
|
||||
|
||||
/* Question Section */
|
||||
#define QS_TYPE_NB 0x0020
|
||||
#define QS_TYPE_NBSTAT 0x0021
|
||||
@ -287,7 +296,6 @@ AliasHandleQuestion(
|
||||
q = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Type and Class filed */
|
||||
switch (ntohs(q->type)) {
|
||||
case QS_TYPE_NB:
|
||||
@ -371,7 +379,6 @@ AliasHandleResourceNB(
|
||||
acc -= *sptr;
|
||||
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
||||
}
|
||||
|
||||
nb->addr = nbtarg->newaddr;
|
||||
#ifdef DEBUG
|
||||
printf("O");
|
||||
@ -388,7 +395,6 @@ AliasHandleResourceNB(
|
||||
if (nb == NULL || (char *)(nb + 1) > pmax) {
|
||||
nb = NULL;
|
||||
}
|
||||
|
||||
return ((u_char *) nb);
|
||||
}
|
||||
|
||||
@ -439,7 +445,6 @@ AliasHandleResourceA(
|
||||
acc -= *sptr;
|
||||
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
||||
}
|
||||
|
||||
a->addr = nbtarg->newaddr;
|
||||
}
|
||||
a++; /* XXXX */
|
||||
@ -612,7 +617,8 @@ AliasHandleResource(
|
||||
return ((u_char *) q);
|
||||
}
|
||||
|
||||
int AliasHandleUdpNbtNS(
|
||||
int
|
||||
AliasHandleUdpNbtNS(
|
||||
struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link,
|
||||
@ -668,7 +674,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Answer Resource Records */
|
||||
if (ntohs(nsh->ancount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -678,7 +683,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Authority Resource Recodrs */
|
||||
if (ntohs(nsh->nscount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -688,7 +692,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
/* Additional Resource Recodrs */
|
||||
if (ntohs(nsh->arcount) != 0) {
|
||||
p = AliasHandleResource(
|
||||
@ -698,7 +701,6 @@ int AliasHandleUdpNbtNS(
|
||||
&nbtarg
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
PrintRcode(nsh->rcode);
|
||||
#endif
|
||||
|
@ -80,14 +80,14 @@ __FBSDID("$FreeBSD$");
|
||||
* PPTP definitions
|
||||
*/
|
||||
|
||||
struct grehdr /* Enhanced GRE header. */
|
||||
{
|
||||
struct grehdr { /* Enhanced GRE header. */
|
||||
u_int16_t gh_flags; /* Flags. */
|
||||
u_int16_t gh_protocol; /* Protocol type. */
|
||||
u_int16_t gh_length; /* Payload length. */
|
||||
u_int16_t gh_call_id; /* Call ID. */
|
||||
u_int32_t gh_seq_no; /* Sequence number (optional). */
|
||||
u_int32_t gh_ack_no; /* Acknowledgment number (optional). */
|
||||
u_int32_t gh_ack_no; /* Acknowledgment number
|
||||
* (optional). */
|
||||
};
|
||||
typedef struct grehdr GreHdr;
|
||||
|
||||
@ -147,8 +147,8 @@ static PptpCallId AliasVerifyPptp(struct ip *, u_int16_t *);
|
||||
void
|
||||
AliasHandlePptpOut(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link) /* The PPTP control link */
|
||||
{
|
||||
struct alias_link *link)
|
||||
{ /* The PPTP control link */
|
||||
struct alias_link *pptp_link;
|
||||
PptpCallId cptr;
|
||||
PptpCode codes;
|
||||
@ -165,13 +165,19 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
case PPTP_OutCallReply:
|
||||
case PPTP_InCallRequest:
|
||||
case PPTP_InCallReply:
|
||||
/* Establish PPTP link for address and Call ID found in control message. */
|
||||
/*
|
||||
* Establish PPTP link for address and Call ID found in
|
||||
* control message.
|
||||
*/
|
||||
pptp_link = AddPptp(la, GetOriginalAddress(link), GetDestAddress(link),
|
||||
GetAliasAddress(link), cptr->cid1);
|
||||
break;
|
||||
case PPTP_CallClearRequest:
|
||||
case PPTP_CallDiscNotify:
|
||||
/* Find PPTP link for address and Call ID found in control message. */
|
||||
/*
|
||||
* Find PPTP link for address and Call ID found in control
|
||||
* message.
|
||||
*/
|
||||
pptp_link = FindPptpOutByCallId(la, GetOriginalAddress(link),
|
||||
GetDestAddress(link),
|
||||
cptr->cid1);
|
||||
@ -195,8 +201,10 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
case PPTP_OutCallReply:
|
||||
case PPTP_InCallReply:
|
||||
codes = (PptpCode) (cptr + 1);
|
||||
if (codes->resCode == 1) /* Connection established, */
|
||||
SetDestCallId(pptp_link, /* note the Peer's Call ID. */
|
||||
if (codes->resCode == 1) /* Connection
|
||||
* established, */
|
||||
SetDestCallId(pptp_link, /* note the Peer's Call
|
||||
* ID. */
|
||||
cptr->cid2);
|
||||
else
|
||||
SetExpire(pptp_link, 0); /* Connection refused. */
|
||||
@ -211,8 +219,8 @@ AliasHandlePptpOut(struct libalias *la,
|
||||
void
|
||||
AliasHandlePptpIn(struct libalias *la,
|
||||
struct ip *pip, /* IP packet to examine/patch */
|
||||
struct alias_link *link) /* The PPTP control link */
|
||||
{
|
||||
struct alias_link *link)
|
||||
{ /* The PPTP control link */
|
||||
struct alias_link *pptp_link;
|
||||
PptpCallId cptr;
|
||||
u_int16_t *pcall_id;
|
||||
@ -224,8 +232,7 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
return;
|
||||
|
||||
/* Modify certain PPTP messages */
|
||||
switch (ctl_type)
|
||||
{
|
||||
switch (ctl_type) {
|
||||
case PPTP_InCallConn:
|
||||
case PPTP_WanErrorNotify:
|
||||
case PPTP_SetLinkInfo:
|
||||
@ -265,7 +272,8 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
if (ctl_type == PPTP_OutCallReply || ctl_type == PPTP_InCallReply) {
|
||||
PptpCode codes = (PptpCode) (cptr + 1);
|
||||
|
||||
if (codes->resCode == 1) /* Connection established, */
|
||||
if (codes->resCode == 1) /* Connection
|
||||
* established, */
|
||||
SetDestCallId(pptp_link, /* note the Call ID. */
|
||||
cptr->cid1);
|
||||
else
|
||||
@ -275,8 +283,8 @@ AliasHandlePptpIn(struct libalias *la,
|
||||
}
|
||||
|
||||
static PptpCallId
|
||||
AliasVerifyPptp(struct ip *pip, u_int16_t *ptype) /* IP packet to examine/patch */
|
||||
{
|
||||
AliasVerifyPptp(struct ip *pip, u_int16_t * ptype)
|
||||
{ /* IP packet to examine/patch */
|
||||
int hlen, tlen, dlen;
|
||||
PptpMsgHead hptr;
|
||||
struct tcphdr *tc;
|
||||
@ -335,7 +343,6 @@ AliasHandlePptpGreOut(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_src = alias_addr;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -366,6 +373,5 @@ AliasHandlePptpGreIn(struct libalias *la, struct ip *pip)
|
||||
2);
|
||||
pip->ip_dst = src_addr;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -84,8 +84,7 @@ __FBSDID("$FreeBSD$");
|
||||
* A linked list of arbitrary length, based on struct proxy_entry is
|
||||
* used to store proxy rules.
|
||||
*/
|
||||
struct proxy_entry
|
||||
{
|
||||
struct proxy_entry {
|
||||
struct libalias *la;
|
||||
#define PROXY_TYPE_ENCODE_NONE 1
|
||||
#define PROXY_TYPE_ENCODE_TCPSTREAM 2
|
||||
@ -175,8 +174,7 @@ IpPort(char *s, int proto, int *port)
|
||||
int n;
|
||||
|
||||
n = sscanf(s, "%d", port);
|
||||
if (n != 1)
|
||||
{
|
||||
if (n != 1) {
|
||||
struct servent *se;
|
||||
|
||||
if (proto == IPPROTO_TCP)
|
||||
@ -191,7 +189,6 @@ IpPort(char *s, int proto, int *port)
|
||||
|
||||
*port = (u_int) ntohs(se->s_port);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -202,8 +199,7 @@ RuleAdd(struct libalias *la, struct proxy_entry *entry)
|
||||
struct proxy_entry *ptr;
|
||||
struct proxy_entry *ptr_last;
|
||||
|
||||
if (la->proxyList == NULL)
|
||||
{
|
||||
if (la->proxyList == NULL) {
|
||||
la->proxyList = entry;
|
||||
entry->last = NULL;
|
||||
entry->next = NULL;
|
||||
@ -214,19 +210,15 @@ RuleAdd(struct libalias *la, struct proxy_entry *entry)
|
||||
rule_index = entry->rule_index;
|
||||
ptr = la->proxyList;
|
||||
ptr_last = NULL;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
if (ptr->rule_index >= rule_index)
|
||||
{
|
||||
if (ptr_last == NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
if (ptr->rule_index >= rule_index) {
|
||||
if (ptr_last == NULL) {
|
||||
entry->next = la->proxyList;
|
||||
entry->last = NULL;
|
||||
la->proxyList->last = entry;
|
||||
la->proxyList = entry;
|
||||
return;
|
||||
}
|
||||
|
||||
ptr_last->next = entry;
|
||||
ptr->last = entry;
|
||||
entry->last = ptr->last;
|
||||
@ -267,17 +259,14 @@ RuleNumberDelete(struct libalias *la, int rule_index)
|
||||
|
||||
err = -1;
|
||||
ptr = la->proxyList;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
struct proxy_entry *ptr_next;
|
||||
|
||||
ptr_next = ptr->next;
|
||||
if (ptr->rule_index == rule_index)
|
||||
{
|
||||
if (ptr->rule_index == rule_index) {
|
||||
err = 0;
|
||||
RuleDelete(ptr);
|
||||
}
|
||||
|
||||
ptr = ptr_next;
|
||||
}
|
||||
|
||||
@ -307,8 +296,7 @@ ProxyEncodeTcpStream(struct alias_link *link,
|
||||
|
||||
/* Pad string out to a multiple of two in length */
|
||||
slen = strlen(buffer);
|
||||
switch (slen % 2)
|
||||
{
|
||||
switch (slen % 2) {
|
||||
case 0:
|
||||
strcat(buffer, " \n");
|
||||
slen += 2;
|
||||
@ -465,15 +453,13 @@ ProxyCheck(struct libalias *la, struct ip *pip,
|
||||
->th_dport;
|
||||
|
||||
ptr = la->proxyList;
|
||||
while (ptr != NULL)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
u_short proxy_port;
|
||||
|
||||
proxy_port = ptr->proxy_port;
|
||||
if ((dst_port == proxy_port || proxy_port == 0)
|
||||
&& pip->ip_p == ptr->proto
|
||||
&& src_addr.s_addr != ptr->server_addr.s_addr)
|
||||
{
|
||||
&& src_addr.s_addr != ptr->server_addr.s_addr) {
|
||||
struct in_addr src_addr_masked;
|
||||
struct in_addr dst_addr_masked;
|
||||
|
||||
@ -481,8 +467,7 @@ ProxyCheck(struct libalias *la, struct ip *pip,
|
||||
dst_addr_masked.s_addr = dst_addr.s_addr & ptr->dst_mask.s_addr;
|
||||
|
||||
if ((src_addr_masked.s_addr == ptr->src_addr.s_addr)
|
||||
&& (dst_addr_masked.s_addr == ptr->dst_addr.s_addr))
|
||||
{
|
||||
&& (dst_addr_masked.s_addr == ptr->dst_addr.s_addr)) {
|
||||
if ((*proxy_server_port = ptr->server_port) == 0)
|
||||
*proxy_server_port = dst_port;
|
||||
*proxy_server_addr = ptr->server_addr;
|
||||
@ -501,8 +486,7 @@ ProxyModify(struct libalias *la, struct alias_link *link,
|
||||
int maxpacketsize,
|
||||
int proxy_type)
|
||||
{
|
||||
switch (proxy_type)
|
||||
{
|
||||
switch (proxy_type) {
|
||||
case PROXY_TYPE_ENCODE_IPHDR:
|
||||
ProxyEncodeIpHeader(pip, maxpacketsize);
|
||||
break;
|
||||
@ -604,11 +588,9 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
state = STATE_READ_KEYWORD;
|
||||
token = strsep(&res, " \t");
|
||||
token_count = 0;
|
||||
while (token != NULL)
|
||||
{
|
||||
while (token != NULL) {
|
||||
token_count++;
|
||||
switch (state)
|
||||
{
|
||||
switch (state) {
|
||||
case STATE_READ_KEYWORD:
|
||||
if (strcmp(token, "type") == 0)
|
||||
state = STATE_READ_TYPE;
|
||||
@ -657,14 +639,11 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
while (*p != ':' && *p != 0)
|
||||
p++;
|
||||
|
||||
if (*p != ':')
|
||||
{
|
||||
if (*p != ':') {
|
||||
err = IpAddr(token, &server_addr);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*p = ' ';
|
||||
|
||||
n = sscanf(token, "%s %s", s, str_server_port);
|
||||
@ -725,15 +704,12 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
while (*p != '/' && *p != 0)
|
||||
p++;
|
||||
|
||||
if (*p != '/')
|
||||
{
|
||||
if (*p != '/') {
|
||||
IpMask(32, &mask);
|
||||
err = IpAddr(token, &addr);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int nbits;
|
||||
char s[sizeof(buffer)];
|
||||
|
||||
@ -751,13 +727,10 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (state == STATE_READ_SRC)
|
||||
{
|
||||
if (state == STATE_READ_SRC) {
|
||||
src_addr = addr;
|
||||
src_mask = mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dst_addr = addr;
|
||||
dst_mask = mask;
|
||||
}
|
||||
@ -788,29 +761,23 @@ LibAliasProxyRule(struct libalias *la, const char *cmd)
|
||||
the string is parsed, because the prototype might not be designated
|
||||
before the ports (which might be symbolic entries in /etc/services) */
|
||||
|
||||
if (strlen(str_port) != 0)
|
||||
{
|
||||
if (strlen(str_port) != 0) {
|
||||
int err;
|
||||
|
||||
err = IpPort(str_port, proto, &proxy_port);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
proxy_port = 0;
|
||||
}
|
||||
|
||||
if (strlen(str_server_port) != 0)
|
||||
{
|
||||
if (strlen(str_server_port) != 0) {
|
||||
int err;
|
||||
|
||||
err = IpPort(str_server_port, proto, &server_port);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
server_port = 0;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,10 @@ alias_skinny_startmedia(struct StartMediaTransmission *start_media,
|
||||
dst.s_addr = start_media->remoteIpAddr;
|
||||
src.s_addr = localIpAddr;
|
||||
|
||||
/* XXX I should probably handle in bound global translations as well. */
|
||||
/*
|
||||
* XXX I should probably handle in bound global translations as
|
||||
* well.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -234,11 +237,11 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
|
||||
orig_len = dlen;
|
||||
/*
|
||||
* Skinny packets can contain many messages. We need to loop through
|
||||
* the packet using len to determine message boundaries. This comes
|
||||
* into play big time with port messages being in the same packet as
|
||||
* register messages. Also, open receive channel acks are
|
||||
* usually buried in a pakcet some 400 bytes long.
|
||||
* Skinny packets can contain many messages. We need to loop
|
||||
* through the packet using len to determine message boundaries.
|
||||
* This comes into play big time with port messages being in the
|
||||
* same packet as register messages. Also, open receive channel
|
||||
* acks are usually buried in a pakcet some 400 bytes long.
|
||||
*/
|
||||
while (dlen >= skinny_hdr_len) {
|
||||
len = (sd->len);
|
||||
@ -253,8 +256,7 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
return;
|
||||
}
|
||||
switch (msgId) {
|
||||
case REG_MSG:
|
||||
{
|
||||
case REG_MSG: {
|
||||
struct RegisterMessage *reg_mesg;
|
||||
|
||||
if (len < sizeof(struct RegisterMessage)) {
|
||||
@ -270,11 +272,11 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
"PacketAlias/Skinny: Received a register message");
|
||||
#endif
|
||||
alias_skinny_reg_msg(reg_mesg, pip, tc, link, direction);
|
||||
}
|
||||
break;
|
||||
case IP_PORT_MSG:
|
||||
{
|
||||
}
|
||||
case IP_PORT_MSG: {
|
||||
struct IpPortMessage *port_mesg;
|
||||
|
||||
if (len < sizeof(struct IpPortMessage)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
@ -288,10 +290,9 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
port_mesg = (struct IpPortMessage *)&sd->msgId;
|
||||
alias_skinny_port_msg(port_mesg, pip, tc, link, direction);
|
||||
}
|
||||
break;
|
||||
case OPNRCVCH_ACK:
|
||||
{
|
||||
}
|
||||
case OPNRCVCH_ACK: {
|
||||
struct OpenReceiveChannelAck *opnrcvchn_ack;
|
||||
|
||||
if (len < sizeof(struct OpenReceiveChannelAck)) {
|
||||
@ -307,10 +308,9 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
opnrcvchn_ack = (struct OpenReceiveChannelAck *)&sd->msgId;
|
||||
alias_skinny_opnrcvch_ack(la, opnrcvchn_ack, pip, tc, link, &lip, direction);
|
||||
}
|
||||
break;
|
||||
case START_MEDIATX:
|
||||
{
|
||||
}
|
||||
case START_MEDIATX: {
|
||||
struct StartMediaTransmission *startmedia_tx;
|
||||
|
||||
if (len < sizeof(struct StartMediaTransmission)) {
|
||||
@ -326,8 +326,8 @@ AliasHandleSkinny(struct libalias *la, struct ip *pip, struct alias_link *link)
|
||||
#endif
|
||||
startmedia_tx = (struct StartMediaTransmission *)&sd->msgId;
|
||||
alias_skinny_startmedia(startmedia_tx, pip, tc, link, lip, direction);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -177,7 +177,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
if (pos < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(port_newdata, port_data, pos + 1);
|
||||
port_newdata += (pos + 1);
|
||||
|
||||
@ -218,8 +217,12 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
if (!links_created) {
|
||||
|
||||
links_created = 1;
|
||||
/* Find an even numbered port number base that
|
||||
satisfies the contiguous number of ports we need */
|
||||
/*
|
||||
* Find an even numbered port
|
||||
* number base that satisfies the
|
||||
* contiguous number of ports we
|
||||
* need
|
||||
*/
|
||||
null_addr.s_addr = 0;
|
||||
if (0 == (salias = FindNewPortGroup(la, null_addr,
|
||||
FindAliasAddress(la, pip->ip_src),
|
||||
@ -234,13 +237,21 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
|
||||
base_alias = ntohs(salias);
|
||||
for (j = 0; j < RTSP_PORT_GROUP; j++) {
|
||||
/* Establish link to port found in RTSP packet */
|
||||
/*
|
||||
* Establish link
|
||||
* to port found in
|
||||
* RTSP packet
|
||||
*/
|
||||
rtsp_link = FindRtspOut(la, GetOriginalAddress(link), null_addr,
|
||||
htons(base_port + j), htons(base_alias + j),
|
||||
IPPROTO_UDP);
|
||||
if (rtsp_link != NULL) {
|
||||
#ifndef NO_FW_PUNCH
|
||||
/* Punch hole in firewall */
|
||||
/*
|
||||
* Punch
|
||||
* hole in
|
||||
* firewall
|
||||
*/
|
||||
PunchFWHole(rtsp_link);
|
||||
#endif
|
||||
} else {
|
||||
@ -254,7 +265,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
}
|
||||
ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
|
||||
}
|
||||
|
||||
if (salias && rtsp_link) {
|
||||
|
||||
pkt_updated = 1;
|
||||
@ -273,7 +283,6 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
|
||||
memcpy(port_newdata, stemp, strlen(stemp));
|
||||
port_newdata += strlen(stemp);
|
||||
}
|
||||
|
||||
*port_newdata = ';';
|
||||
port_newdata++;
|
||||
}
|
||||
@ -399,11 +408,12 @@ AliasHandleRtspOut(struct libalias *la, struct ip *pip, struct alias_link *link,
|
||||
alias_pna_out(la, pip, link, data, dlen);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* When aliasing a server, check for the 200 reply
|
||||
Accomodate varying number of blanks between 200 & OK */
|
||||
/*
|
||||
* When aliasing a server, check for the 200 reply
|
||||
* Accomodate varying number of blanks between 200 & OK
|
||||
*/
|
||||
|
||||
if (dlen >= strlen(str200)) {
|
||||
|
||||
|
@ -66,13 +66,11 @@ LibAliasInternetChecksum(struct libalias *la, u_short *ptr, int nbytes)
|
||||
int sum, oddbyte;
|
||||
|
||||
sum = 0;
|
||||
while (nbytes > 1)
|
||||
{
|
||||
while (nbytes > 1) {
|
||||
sum += *ptr++;
|
||||
nbytes -= 2;
|
||||
}
|
||||
if (nbytes == 1)
|
||||
{
|
||||
if (nbytes == 1) {
|
||||
oddbyte = 0;
|
||||
((u_char *) & oddbyte)[0] = *(u_char *) ptr;
|
||||
((u_char *) & oddbyte)[1] = 0;
|
||||
@ -108,19 +106,16 @@ TcpChecksum(struct ip *pip)
|
||||
/* Add up TCP header and data */
|
||||
nbytes = ntcp;
|
||||
sum = 0;
|
||||
while (nbytes > 1)
|
||||
{
|
||||
while (nbytes > 1) {
|
||||
sum += *ptr++;
|
||||
nbytes -= 2;
|
||||
}
|
||||
if (nbytes == 1)
|
||||
{
|
||||
if (nbytes == 1) {
|
||||
oddbyte = 0;
|
||||
((u_char *) & oddbyte)[0] = *(u_char *) ptr;
|
||||
((u_char *) & oddbyte)[1] = 0;
|
||||
sum += oddbyte;
|
||||
}
|
||||
|
||||
/* "Pseudo-header" data */
|
||||
ptr = (u_short *) & (pip->ip_dst);
|
||||
sum += *ptr++;
|
||||
@ -147,24 +142,19 @@ DifferentialChecksum(u_short *cksum, u_short *new, u_short *old, int n)
|
||||
int accumulate;
|
||||
|
||||
accumulate = *cksum;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
accumulate -= *new++;
|
||||
accumulate += *old++;
|
||||
}
|
||||
|
||||
if (accumulate < 0)
|
||||
{
|
||||
if (accumulate < 0) {
|
||||
accumulate = -accumulate;
|
||||
accumulate = (accumulate >> 16) + (accumulate & 0xffff);
|
||||
accumulate += accumulate >> 16;
|
||||
*cksum = (u_short) ~ accumulate;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
accumulate = (accumulate >> 16) + (accumulate & 0xffff);
|
||||
accumulate += accumulate >> 16;
|
||||
*cksum = (u_short) accumulate;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user