git: 0742d99f5387 - stable/12 - libalias: Style cleanup
Lutz Donnerhacke
donner at FreeBSD.org
Sun May 30 20:04:41 UTC 2021
The branch stable/12 has been updated by donner:
URL: https://cgit.FreeBSD.org/src/commit/?id=0742d99f53872df1a3f14e7a584e94aa5ba6daf6
commit 0742d99f53872df1a3f14e7a584e94aa5ba6daf6
Author: Lutz Donnerhacke <donner at FreeBSD.org>
AuthorDate: 2021-05-14 13:08:08 +0000
Commit: Lutz Donnerhacke <donner at FreeBSD.org>
CommitDate: 2021-05-30 20:03:40 +0000
libalias: Style cleanup
libalias is a convolut of various coding styles modified by a series
of different editors enforcing interesting convetions on spacing and
comments.
This patch is a baseline to start with a perfomance rework of
libalias. Upcoming patches should be focus on the code, not on the
style. That's why most annoying style errors should be fixed
beforehand.
Reviewed by: hselasky
Discussed by: emaste
Differential Revision: https://reviews.freebsd.org/D30259
(cherry picked from commit effc8e57fbf03d7f1423c662caf2b63f0d1d21a9)
At some places the ASSERT was inserted before variable declarations are
finished. This is fixed now.
Reported by: kib
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D30282
(cherry picked from commit 2e6b07866f9e1520626a1523f6609cc411bdda1c)
---
sys/netinet/libalias/alias.c | 379 ++++++++++++++++-----------------
sys/netinet/libalias/alias.h | 44 ++--
sys/netinet/libalias/alias_db.c | 413 +++++++++++++++++-------------------
sys/netinet/libalias/alias_dummy.c | 15 +-
sys/netinet/libalias/alias_ftp.c | 68 +++---
sys/netinet/libalias/alias_irc.c | 52 +++--
sys/netinet/libalias/alias_local.h | 178 +++++++---------
sys/netinet/libalias/alias_mod.c | 2 -
sys/netinet/libalias/alias_nbt.c | 253 ++++++++++------------
sys/netinet/libalias/alias_pptp.c | 84 ++++----
sys/netinet/libalias/alias_proxy.c | 271 ++++++++++++-----------
sys/netinet/libalias/alias_sctp.c | 138 ++++++------
sys/netinet/libalias/alias_sctp.h | 26 +--
sys/netinet/libalias/alias_skinny.c | 30 ++-
sys/netinet/libalias/alias_smedia.c | 91 ++++----
sys/netinet/libalias/alias_util.c | 30 +--
16 files changed, 975 insertions(+), 1099 deletions(-)
diff --git a/sys/netinet/libalias/alias.c b/sys/netinet/libalias/alias.c
index 4dfe65d29f6a..8a18c61b452e 100644
--- a/sys/netinet/libalias/alias.c
+++ b/sys/netinet/libalias/alias.c
@@ -146,7 +146,7 @@ __FBSDID("$FreeBSD$");
#include "alias_mod.h"
#endif
-/*
+/*
* Define libalias SYSCTL Node
*/
#ifdef SYSCTL_NODE
@@ -191,7 +191,6 @@ static void TcpMonitorOut(u_char, struct alias_link *);
static void
TcpMonitorIn(u_char th_flags, struct alias_link *lnk)
{
-
switch (GetStateIn(lnk)) {
case ALIAS_TCP_STATE_NOT_CONNECTED:
if (th_flags & TH_RST)
@@ -209,7 +208,6 @@ TcpMonitorIn(u_char th_flags, struct alias_link *lnk)
static void
TcpMonitorOut(u_char th_flags, struct alias_link *lnk)
{
-
switch (GetStateOut(lnk)) {
case ALIAS_TCP_STATE_NOT_CONNECTED:
if (th_flags & TH_RST)
@@ -284,21 +282,20 @@ static int UdpAliasOut(struct libalias *, struct ip *, int, int create);
static int TcpAliasIn(struct libalias *, struct ip *);
static int TcpAliasOut(struct libalias *, struct ip *, int, int create);
-static int
-IcmpAliasIn1(struct libalias *la, struct ip *pip)
-{
-
- LIBALIAS_LOCK_ASSERT(la);
/*
De-alias incoming echo and timestamp replies.
Alias incoming echo and timestamp requests.
*/
+static int
+IcmpAliasIn1(struct libalias *la, struct ip *pip)
+{
struct alias_link *lnk;
struct icmp *ic;
+ LIBALIAS_LOCK_ASSERT(la);
ic = (struct icmp *)ip_next(pip);
-/* Get source address from ICMP data field and restore original data */
+ /* Get source address from ICMP data field and restore original data */
lnk = FindIcmpIn(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
if (lnk != NULL) {
u_short original_id;
@@ -306,15 +303,15 @@ IcmpAliasIn1(struct libalias *la, struct ip *pip)
original_id = GetOriginalPort(lnk);
-/* Adjust ICMP checksum */
+ /* Adjust ICMP checksum */
accumulate = ic->icmp_id;
accumulate -= original_id;
ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-/* Put original sequence number back in */
+ /* Put original sequence number back in */
ic->icmp_id = original_id;
-/* Put original address back into IP header */
+ /* Put original address back into IP header */
{
struct in_addr original_address;
@@ -329,21 +326,20 @@ IcmpAliasIn1(struct libalias *la, struct ip *pip)
return (PKT_ALIAS_IGNORED);
}
-static int
-IcmpAliasIn2(struct libalias *la, struct ip *pip)
-{
-
- LIBALIAS_LOCK_ASSERT(la);
/*
Alias incoming ICMP error messages containing
IP header and first 64 bits of datagram.
*/
+static int
+IcmpAliasIn2(struct libalias *la, struct ip *pip)
+{
struct ip *ip;
struct icmp *ic, *ic2;
struct udphdr *ud;
struct tcphdr *tc;
struct alias_link *lnk;
+ LIBALIAS_LOCK_ASSERT(la);
ic = (struct icmp *)ip_next(pip);
ip = &ic->icmp_ip;
@@ -376,7 +372,7 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
original_address = GetOriginalAddress(lnk);
original_port = GetOriginalPort(lnk);
-/* Adjust ICMP checksum */
+ /* Adjust ICMP checksum */
accumulate = twowords(&ip->ip_src);
accumulate -= twowords(&original_address);
accumulate += ud->uh_sport;
@@ -387,13 +383,14 @@ IcmpAliasIn2(struct libalias *la, struct ip *pip)
accumulate2 -= ip->ip_sum;
ADJUST_CHECKSUM(accumulate2, ic->icmp_cksum);
-/* Un-alias address in IP header */
+ /* Un-alias address in IP header */
DifferentialChecksum(&pip->ip_sum,
&original_address, &pip->ip_dst, 2);
pip->ip_dst = original_address;
-/* Un-alias address and port number of original IP packet
-fragment contained in ICMP data section */
+ /* Un-alias address and port number of
+ * original IP packet fragment contained
+ * in ICMP data section */
ip->ip_src = original_address;
ud->uh_sport = original_port;
} else if (ip->ip_p == IPPROTO_ICMP) {
@@ -404,7 +401,7 @@ fragment contained in ICMP data section */
original_address = GetOriginalAddress(lnk);
original_id = GetOriginalPort(lnk);
-/* Adjust ICMP checksum */
+ /* Adjust ICMP checksum */
accumulate = twowords(&ip->ip_src);
accumulate -= twowords(&original_address);
accumulate += ic2->icmp_id;
@@ -415,13 +412,13 @@ fragment contained in ICMP data section */
accumulate2 -= ip->ip_sum;
ADJUST_CHECKSUM(accumulate2, ic->icmp_cksum);
-/* Un-alias address in IP header */
+ /* Un-alias address in IP header */
DifferentialChecksum(&pip->ip_sum,
&original_address, &pip->ip_dst, 2);
pip->ip_dst = original_address;
-/* Un-alias address of original IP packet and sequence number of
- embedded ICMP datagram */
+ /* Un-alias address of original IP packet and
+ * sequence number of embedded ICMP datagram */
ip->ip_src = original_address;
ic2->icmp_id = original_id;
}
@@ -443,7 +440,7 @@ IcmpAliasIn(struct libalias *la, struct ip *pip)
if (dlen < ICMP_MINLEN)
return (PKT_ALIAS_IGNORED);
-/* Return if proxy-only mode is enabled */
+ /* Return if proxy-only mode is enabled */
if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
return (PKT_ALIAS_OK);
@@ -474,20 +471,20 @@ IcmpAliasIn(struct libalias *la, struct ip *pip)
return (iresult);
}
-static int
-IcmpAliasOut1(struct libalias *la, struct ip *pip, int create)
-{
/*
Alias outgoing echo and timestamp requests.
De-alias outgoing echo and timestamp replies.
*/
+static int
+IcmpAliasOut1(struct libalias *la, struct ip *pip, int create)
+{
struct alias_link *lnk;
struct icmp *ic;
LIBALIAS_LOCK_ASSERT(la);
ic = (struct icmp *)ip_next(pip);
-/* Save overwritten data for when echo packet returns */
+ /* Save overwritten data for when echo packet returns */
lnk = FindIcmpOut(la, pip->ip_src, pip->ip_dst, ic->icmp_id, create);
if (lnk != NULL) {
u_short alias_id;
@@ -495,15 +492,15 @@ IcmpAliasOut1(struct libalias *la, struct ip *pip, int create)
alias_id = GetAliasPort(lnk);
-/* Since data field is being modified, adjust ICMP checksum */
+ /* Since data field is being modified, adjust ICMP checksum */
accumulate = ic->icmp_id;
accumulate -= alias_id;
ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-/* Alias sequence number */
+ /* Alias sequence number */
ic->icmp_id = alias_id;
-/* Change source address */
+ /* Change source address */
{
struct in_addr alias_address;
@@ -518,13 +515,13 @@ IcmpAliasOut1(struct libalias *la, struct ip *pip, int create)
return (PKT_ALIAS_IGNORED);
}
-static int
-IcmpAliasOut2(struct libalias *la, struct ip *pip)
-{
/*
Alias outgoing ICMP error messages containing
IP header and first 64 bits of datagram.
*/
+static int
+IcmpAliasOut2(struct libalias *la, struct ip *pip)
+{
struct ip *ip;
struct icmp *ic, *ic2;
struct udphdr *ud;
@@ -564,24 +561,24 @@ IcmpAliasOut2(struct libalias *la, struct ip *pip)
alias_address = GetAliasAddress(lnk);
alias_port = GetAliasPort(lnk);
-/* Adjust ICMP checksum */
+ /* Adjust ICMP checksum */
accumulate = twowords(&ip->ip_dst);
accumulate -= twowords(&alias_address);
accumulate += ud->uh_dport;
accumulate -= alias_port;
ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-/*
- * Alias address in IP header if it comes from the host
- * the original TCP/UDP packet was destined for.
- */
+ /*
+ * Alias address in IP header if it comes from the host
+ * the original TCP/UDP packet was destined for.
+ */
if (pip->ip_src.s_addr == ip->ip_dst.s_addr) {
DifferentialChecksum(&pip->ip_sum,
&alias_address, &pip->ip_src, 2);
pip->ip_src = alias_address;
}
-/* Alias address and port number of original IP packet
-fragment contained in ICMP data section */
+ /* 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) {
@@ -592,24 +589,24 @@ fragment contained in ICMP data section */
alias_address = GetAliasAddress(lnk);
alias_id = GetAliasPort(lnk);
-/* Adjust ICMP checksum */
+ /* Adjust ICMP checksum */
accumulate = twowords(&ip->ip_dst);
accumulate -= twowords(&alias_address);
accumulate += ic2->icmp_id;
accumulate -= alias_id;
ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);
-/*
- * Alias address in IP header if it comes from the host
- * the original ICMP message was destined for.
- */
+ /*
+ * Alias address in IP header if it comes from the host
+ * the original ICMP message was destined for.
+ */
if (pip->ip_src.s_addr == ip->ip_dst.s_addr) {
DifferentialChecksum(&pip->ip_sum,
&alias_address, &pip->ip_src, 2);
pip->ip_src = alias_address;
}
-/* Alias address of original IP packet and sequence number of
- embedded ICMP datagram */
+ /* Alias address of original IP packet and
+ * sequence number of embedded ICMP datagram */
ip->ip_dst = alias_address;
ic2->icmp_id = alias_id;
}
@@ -627,7 +624,7 @@ IcmpAliasOut(struct libalias *la, struct ip *pip, int create)
LIBALIAS_LOCK_ASSERT(la);
(void)create;
-/* Return if proxy-only mode is enabled */
+ /* Return if proxy-only mode is enabled */
if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
return (PKT_ALIAS_OK);
@@ -654,20 +651,20 @@ IcmpAliasOut(struct libalias *la, struct ip *pip, int create)
return (iresult);
}
-static int
-ProtoAliasIn(struct libalias *la, struct in_addr ip_src,
- struct ip *pip, u_char ip_p, u_short *ip_sum)
-{
/*
Handle incoming IP packets. The
only thing which is done in this case is to alias
the dest IP address of the packet to our inside
machine.
*/
+static int
+ProtoAliasIn(struct libalias *la, struct in_addr ip_src,
+ struct ip *pip, u_char ip_p, u_short *ip_sum)
+{
struct alias_link *lnk;
LIBALIAS_LOCK_ASSERT(la);
-/* Return if proxy-only mode is enabled */
+ /* Return if proxy-only mode is enabled */
if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
return (PKT_ALIAS_OK);
@@ -677,7 +674,7 @@ ProtoAliasIn(struct libalias *la, struct in_addr ip_src,
original_address = GetOriginalAddress(lnk);
-/* Restore original IP address */
+ /* Restore original IP address */
DifferentialChecksum(ip_sum,
&original_address, &pip->ip_dst, 2);
pip->ip_dst = original_address;
@@ -687,20 +684,20 @@ ProtoAliasIn(struct libalias *la, struct in_addr ip_src,
return (PKT_ALIAS_IGNORED);
}
-static int
-ProtoAliasOut(struct libalias *la, struct ip *pip,
- struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, int create)
-{
/*
Handle outgoing IP packets. The
only thing which is done in this case is to alias
the source IP address of the packet.
*/
+static int
+ProtoAliasOut(struct libalias *la, struct ip *pip,
+ struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, int create)
+{
struct alias_link *lnk;
LIBALIAS_LOCK_ASSERT(la);
-/* Return if proxy-only mode is enabled */
+ /* Return if proxy-only mode is enabled */
if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
return (PKT_ALIAS_OK);
@@ -713,7 +710,7 @@ ProtoAliasOut(struct libalias *la, struct ip *pip,
alias_address = GetAliasAddress(lnk);
-/* Change source address */
+ /* Change source address */
DifferentialChecksum(ip_sum,
&alias_address, &pip->ip_src, 2);
pip->ip_src = alias_address;
@@ -752,8 +749,8 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
int accumulate;
int error;
struct alias_data ad = {
- .lnk = lnk,
- .oaddr = &original_address,
+ .lnk = lnk,
+ .oaddr = &original_address,
.aaddr = &alias_address,
.aport = &alias_port,
.sport = &ud->uh_sport,
@@ -768,46 +765,48 @@ UdpAliasIn(struct libalias *la, struct ip *pip)
ud->uh_dport = GetOriginalPort(lnk);
proxy_port = GetProxyPort(lnk);
- /* Walk out chain. */
+ /* Walk out chain. */
error = find_handler(IN, UDP, la, pip, &ad);
/* If we cannot figure out the packet, ignore it. */
if (error < 0)
return (PKT_ALIAS_IGNORED);
-/* If UDP checksum is not zero, then adjust since destination port */
-/* is being unaliased and destination address is being altered. */
+ /* 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) {
accumulate = alias_port;
accumulate -= ud->uh_dport;
accumulate += twowords(&alias_address);
accumulate -= twowords(&original_address);
-/* If this is a proxy packet, modify checksum because of source change.*/
- if (proxy_port != 0) {
- accumulate += ud->uh_sport;
- accumulate -= proxy_port;
- }
+ /* If this is a proxy packet, modify checksum
+ * because of source change.*/
+ if (proxy_port != 0) {
+ accumulate += ud->uh_sport;
+ accumulate -= proxy_port;
+ }
- if (proxy_address.s_addr != 0) {
+ if (proxy_address.s_addr != 0) {
accumulate += twowords(&pip->ip_src);
accumulate -= twowords(&proxy_address);
- }
+ }
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
}
-/* XXX: Could the two if's below be concatenated to one ? */
-/* Restore source port and/or address in case of proxying*/
- if (proxy_port != 0)
- ud->uh_sport = proxy_port;
+ /* XXX: Could the two if's below be concatenated to one ? */
+ /* Restore source port and/or address in case of proxying*/
+ if (proxy_port != 0)
+ ud->uh_sport = proxy_port;
- if (proxy_address.s_addr != 0) {
- DifferentialChecksum(&pip->ip_sum,
- &proxy_address, &pip->ip_src, 2);
- pip->ip_src = proxy_address;
- }
+ if (proxy_address.s_addr != 0) {
+ DifferentialChecksum(&pip->ip_sum,
+ &proxy_address, &pip->ip_src, 2);
+ pip->ip_src = proxy_address;
+ }
-/* Restore original IP address */
+ /* Restore original IP address */
DifferentialChecksum(&pip->ip_sum,
&original_address, &pip->ip_dst, 2);
pip->ip_dst = original_address;
@@ -832,7 +831,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
LIBALIAS_LOCK_ASSERT(la);
-/* Return if proxy-only mode is enabled and not proxyrule found.*/
+ /* Return if proxy-only mode is enabled and not proxyrule found.*/
dlen = ntohs(pip->ip_len) - (pip->ip_hl << 2);
if (dlen < sizeof(struct udphdr))
return (PKT_ALIAS_IGNORED);
@@ -841,34 +840,33 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
if (dlen < ntohs(ud->uh_ulen))
return (PKT_ALIAS_IGNORED);
- proxy_type = ProxyCheck(la, &proxy_server_address,
- &proxy_server_port, pip->ip_src, pip->ip_dst,
- ud->uh_dport, pip->ip_p);
+ proxy_type = ProxyCheck(la, &proxy_server_address, &proxy_server_port,
+ pip->ip_src, pip->ip_dst, ud->uh_dport, pip->ip_p);
if (proxy_type == 0 && (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY))
return (PKT_ALIAS_OK);
-/* If this is a transparent proxy, save original destination,
- * then alter the destination and adjust checksums */
+ /* If this is a transparent proxy, save original destination,
+ * then alter the destination and adjust checksums */
dest_port = ud->uh_dport;
dest_address = pip->ip_dst;
if (proxy_type != 0) {
- int accumulate;
+ int accumulate;
accumulate = twowords(&pip->ip_dst);
accumulate -= twowords(&proxy_server_address);
- ADJUST_CHECKSUM(accumulate, pip->ip_sum);
+ ADJUST_CHECKSUM(accumulate, pip->ip_sum);
if (ud->uh_sum != 0) {
accumulate = twowords(&pip->ip_dst);
accumulate -= twowords(&proxy_server_address);
- accumulate += ud->uh_dport;
- accumulate -= proxy_server_port;
- ADJUST_CHECKSUM(accumulate, ud->uh_sum);
+ accumulate += ud->uh_dport;
+ accumulate -= proxy_server_port;
+ ADJUST_CHECKSUM(accumulate, ud->uh_sum);
}
- pip->ip_dst = proxy_server_address;
- ud->uh_dport = proxy_server_port;
+ pip->ip_dst = proxy_server_address;
+ ud->uh_dport = proxy_server_port;
}
lnk = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
ud->uh_sport, ud->uh_dport,
@@ -877,7 +875,7 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
u_short alias_port;
struct in_addr alias_address;
struct alias_data ad = {
- .lnk = lnk,
+ .lnk = lnk,
.oaddr = NULL,
.aaddr = &alias_address,
.aport = &alias_port,
@@ -886,24 +884,24 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
.maxpktsize = 0
};
-/* 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. */
+ /* 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) {
- SetProxyPort(lnk, dest_port);
- SetProxyAddress(lnk, dest_address);
- ProxyModify(la, lnk, pip, maxpacketsize, proxy_type);
- ud = (struct udphdr *)ip_next(pip);
- }
+ SetProxyPort(lnk, dest_port);
+ SetProxyAddress(lnk, dest_address);
+ ProxyModify(la, lnk, pip, maxpacketsize, proxy_type);
+ ud = (struct udphdr *)ip_next(pip);
+ }
alias_address = GetAliasAddress(lnk);
alias_port = GetAliasPort(lnk);
- /* Walk out chain. */
+ /* Walk out chain. */
error = find_handler(OUT, UDP, la, pip, &ad);
-/* If UDP checksum is not zero, adjust since source port is */
-/* being aliased and source address is being altered */
+ /* If UDP checksum is not zero, adjust since source port is */
+ /* being aliased and source address is being altered */
if (ud->uh_sum != 0) {
int accumulate;
@@ -913,10 +911,10 @@ UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
accumulate -= twowords(&alias_address);
ADJUST_CHECKSUM(accumulate, ud->uh_sum);
}
-/* Put alias port in UDP header */
+ /* Put alias port in UDP header */
ud->uh_sport = alias_port;
-/* Change source address */
+ /* Change source address */
DifferentialChecksum(&pip->ip_sum,
&alias_address, &pip->ip_src, 2);
pip->ip_src = alias_address;
@@ -952,14 +950,14 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
u_short proxy_port;
int accumulate, error;
- /*
- * The init of MANY vars is a bit below, but aliashandlepptpin
+ /*
+ * The init of MANY vars is a bit below, but aliashandlepptpin
* seems to need the destination port that came within the
* packet and not the original one looks below [*].
*/
struct alias_data ad = {
- .lnk = lnk,
+ .lnk = lnk,
.oaddr = NULL,
.aaddr = NULL,
.aport = NULL,
@@ -968,7 +966,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
.maxpktsize = 0
};
- /* Walk out chain. */
+ /* Walk out chain. */
error = find_handler(IN, TCP, la, pip, &ad);
alias_address = GetAliasAddress(lnk);
@@ -978,8 +976,8 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
tc->th_dport = GetOriginalPort(lnk);
proxy_port = GetProxyPort(lnk);
- /*
- * Look above, if anyone is going to add find_handler AFTER
+ /*
+ * Look above, if anyone is going to add find_handler AFTER
* this aliashandlepptpin/point, please redo alias_data too.
* Uncommenting the piece here below should be enough.
*/
@@ -993,22 +991,22 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
.dport = &ud->uh_dport,
.maxpktsize = 0
};
-
+
/* Walk out chain. */
error = find_handler(la, pip, &ad);
if (error == EHDNOF)
printf("Protocol handler not found\n");
#endif
-/* Adjust TCP checksum since destination port is being unaliased */
-/* and destination port is being altered. */
+ /* Adjust TCP checksum since destination port is being
+ * unaliased and destination port is being altered. */
accumulate = alias_port;
accumulate -= tc->th_dport;
accumulate += twowords(&alias_address);
accumulate -= twowords(&original_address);
-/* If this is a proxy, then modify the TCP source port and
- checksum accumulation */
+ /* If this is a proxy, then modify the TCP source port
+ * and checksum accumulation */
if (proxy_port != 0) {
accumulate += tc->th_sport;
tc->th_sport = proxy_port;
@@ -1016,7 +1014,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
accumulate += twowords(&pip->ip_src);
accumulate -= twowords(&proxy_address);
}
-/* See if ACK number needs to be modified */
+ /* See if ACK number needs to be modified */
if (GetAckModified(lnk) == 1) {
int delta;
@@ -1030,13 +1028,13 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
}
ADJUST_CHECKSUM(accumulate, tc->th_sum);
-/* Restore original IP address */
+ /* Restore original IP address */
accumulate = twowords(&pip->ip_dst);
pip->ip_dst = original_address;
accumulate -= twowords(&pip->ip_dst);
-/* If this is a transparent proxy packet, then modify the source
- address */
+ /* If this is a transparent proxy packet,
+ * then modify the source address */
if (proxy_address.s_addr != 0) {
accumulate += twowords(&pip->ip_src);
pip->ip_src = proxy_address;
@@ -1044,7 +1042,7 @@ TcpAliasIn(struct libalias *la, struct ip *pip)
}
ADJUST_CHECKSUM(accumulate, pip->ip_sum);
-/* Monitor TCP connection state */
+ /* Monitor TCP connection state */
tc = (struct tcphdr *)ip_next(pip);
TcpMonitorIn(tc->th_flags, lnk);
@@ -1073,8 +1071,8 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
tc = (struct tcphdr *)ip_next(pip);
if (create)
- proxy_type = ProxyCheck(la, &proxy_server_address,
- &proxy_server_port, pip->ip_src, pip->ip_dst,
+ proxy_type = ProxyCheck(la, &proxy_server_address,
+ &proxy_server_port, pip->ip_src, pip->ip_dst,
tc->th_dport, pip->ip_p);
else
proxy_type = 0;
@@ -1082,8 +1080,8 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
if (proxy_type == 0 && (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY))
return (PKT_ALIAS_OK);
-/* If this is a transparent proxy, save original destination,
- then alter the destination and adjust checksums */
+ /* If this is a transparent proxy, save original destination,
+ * then alter the destination and adjust checksums */
dest_port = tc->th_dport;
dest_address = pip->ip_dst;
if (proxy_type != 0) {
@@ -1111,7 +1109,7 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
struct in_addr alias_address;
int accumulate;
struct alias_data ad = {
- .lnk = lnk,
+ .lnk = lnk,
.oaddr = NULL,
.aaddr = &alias_address,
.aport = &alias_port,
@@ -1120,38 +1118,38 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
.maxpktsize = 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. */
+ /* 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) {
SetProxyPort(lnk, dest_port);
SetProxyAddress(lnk, dest_address);
ProxyModify(la, lnk, pip, maxpacketsize, proxy_type);
tc = (struct tcphdr *)ip_next(pip);
}
-/* Get alias address and port */
+ /* Get alias address and port */
alias_port = GetAliasPort(lnk);
alias_address = GetAliasAddress(lnk);
-/* Monitor TCP connection state */
+ /* Monitor TCP connection state */
tc = (struct tcphdr *)ip_next(pip);
TcpMonitorOut(tc->th_flags, lnk);
-
- /* Walk out chain. */
+
+ /* Walk out chain. */
error = find_handler(OUT, TCP, la, pip, &ad);
-/* Adjust TCP checksum since source port is being aliased */
-/* and source address is being altered */
+ /* Adjust TCP checksum since source port is being aliased
+ * and source address is being altered */
accumulate = tc->th_sport;
tc->th_sport = alias_port;
accumulate -= tc->th_sport;
accumulate += twowords(&pip->ip_src);
accumulate -= twowords(&alias_address);
-/* Modify sequence number if necessary */
+ /* Modify sequence number if necessary */
if (GetAckModified(lnk) == 1) {
int delta;
-
+
tc = (struct tcphdr *)ip_next(pip);
delta = GetDeltaSeqOut(tc->th_seq, lnk);
if (delta != 0) {
@@ -1162,7 +1160,7 @@ TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
}
ADJUST_CHECKSUM(accumulate, tc->th_sum);
-/* Change source address */
+ /* Change source address */
accumulate = twowords(&pip->ip_src);
pip->ip_src = alias_address;
accumulate -= twowords(&pip->ip_src);
@@ -1258,7 +1256,7 @@ LibAliasSaveFragment(struct libalias *la, void *ptr)
return (iresult);
}
-void *
+void *
LibAliasGetFragment(struct libalias *la, void *ptr)
{
struct alias_link *lnk;
@@ -1272,7 +1270,7 @@ LibAliasGetFragment(struct libalias *la, void *ptr)
GetFragmentPtr(lnk, &fptr);
SetFragmentPtr(lnk, NULL);
SetExpire(lnk, 0); /* Deletes link */
- } else
+ } else
fptr = NULL;
LIBALIAS_UNLOCK(la);
@@ -1280,11 +1278,9 @@ LibAliasGetFragment(struct libalias *la, void *ptr)
}
void
-LibAliasFragmentIn(struct libalias *la, void *ptr, /* Points to correctly
- * de-aliased header
- * fragment */
- void *ptr_fragment /* Points to fragment which must be
- * de-aliased */
+LibAliasFragmentIn(struct libalias *la,
+ void *ptr, /* Points to correctly de-aliased header fragment */
+ void *ptr_fragment /* fragment which must be de-aliased */
)
{
struct ip *pip;
@@ -1304,10 +1300,10 @@ LibAliasFragmentIn(struct libalias *la, void *ptr, /* Points to correctly
/* Local prototypes */
static int
LibAliasOutLocked(struct libalias *la, struct ip *pip,
- int maxpacketsize, int create);
+ int maxpacketsize, int create);
static int
LibAliasInLocked(struct libalias *la, struct ip *pip,
- int maxpacketsize);
+ int maxpacketsize);
int
LibAliasIn(struct libalias *la, void *ptr, int maxpacketsize)
@@ -1339,7 +1335,7 @@ LibAliasInLocked(struct libalias *la, struct ip *pip, int maxpacketsize)
/* Defense against mangled packets */
if (ntohs(pip->ip_len) > maxpacketsize
|| (pip->ip_hl << 2) > maxpacketsize) {
- iresult = PKT_ALIAS_IGNORED;
+ iresult = PKT_ALIAS_IGNORED;
goto getout;
}
@@ -1357,30 +1353,30 @@ LibAliasInLocked(struct libalias *la, struct ip *pip, int maxpacketsize)
break;
#ifdef _KERNEL
case IPPROTO_SCTP:
- iresult = SctpAlias(la, pip, SN_TO_LOCAL);
+ iresult = SctpAlias(la, pip, SN_TO_LOCAL);
break;
#endif
- case IPPROTO_GRE: {
+ case IPPROTO_GRE: {
int error;
struct alias_data ad = {
- .lnk = NULL,
- .oaddr = NULL,
+ .lnk = NULL,
+ .oaddr = NULL,
.aaddr = NULL,
.aport = NULL,
.sport = NULL,
.dport = NULL,
- .maxpktsize = 0
+ .maxpktsize = 0
};
-
- /* Walk out chain. */
+
+ /* Walk out chain. */
error = find_handler(IN, IP, la, pip, &ad);
- if (error == 0)
+ if (error == 0)
iresult = PKT_ALIAS_OK;
else
iresult = ProtoAliasIn(la, pip->ip_src,
pip, pip->ip_p, &pip->ip_sum);
+ break;
}
- break;
default:
iresult = ProtoAliasIn(la, pip->ip_src, pip,
pip->ip_p, &pip->ip_sum);
@@ -1448,10 +1444,10 @@ LibAliasOutTry(struct libalias *la, void *ptr, int maxpacketsize, int create)
}
static int
-LibAliasOutLocked(struct libalias *la, struct ip *pip, /* valid IP packet */
- int maxpacketsize, /* How much the packet data may grow (FTP
- * and IRC inline changes) */
- int create /* Create new entries ? */
+LibAliasOutLocked(struct libalias *la,
+ struct ip *pip, /* valid IP packet */
+ int maxpacketsize, /* How much the packet data may grow (FTP and IRC inline changes) */
+ int create /* Create new entries ? */
)
{
int iresult;
@@ -1511,29 +1507,29 @@ LibAliasOutLocked(struct libalias *la, struct ip *pip, /* valid IP packet */
break;
#ifdef _KERNEL
case IPPROTO_SCTP:
- iresult = SctpAlias(la, pip, SN_TO_GLOBAL);
+ iresult = SctpAlias(la, pip, SN_TO_GLOBAL);
break;
#endif
case IPPROTO_GRE: {
int error;
struct alias_data ad = {
- .lnk = NULL,
- .oaddr = NULL,
+ .lnk = NULL,
+ .oaddr = NULL,
.aaddr = NULL,
.aport = NULL,
.sport = NULL,
.dport = NULL,
- .maxpktsize = 0
+ .maxpktsize = 0
};
- /* Walk out chain. */
+ /* Walk out chain. */
error = find_handler(OUT, IP, la, pip, &ad);
if (error == 0)
- iresult = PKT_ALIAS_OK;
- else
+ iresult = PKT_ALIAS_OK;
+ else
iresult = ProtoAliasOut(la, pip,
pip->ip_dst, pip->ip_p, &pip->ip_sum, create);
+ break;
}
- break;
default:
iresult = ProtoAliasOut(la, pip,
pip->ip_dst, pip->ip_p, &pip->ip_sum, create);
@@ -1549,8 +1545,9 @@ getout:
}
int
-LibAliasUnaliasOut(struct libalias *la, void *ptr, /* valid IP packet */
- int maxpacketsize /* for error checking */
+LibAliasUnaliasOut(struct libalias *la,
+ void *ptr, /* valid IP packet */
+ int maxpacketsize /* for error checking */
)
{
struct ip *pip;
@@ -1622,7 +1619,6 @@ LibAliasUnaliasOut(struct libalias *la, void *ptr, /* valid IP packet */
tc->th_sport = original_port;
iresult = PKT_ALIAS_OK;
-
} else if (pip->ip_p == IPPROTO_ICMP) {
int accumulate;
struct in_addr original_address;
@@ -1652,7 +1648,6 @@ LibAliasUnaliasOut(struct libalias *la, void *ptr, /* valid IP packet */
getout:
LIBALIAS_UNLOCK(la);
return (iresult);
-
}
#ifndef _KERNEL
@@ -1672,8 +1667,8 @@ LibAliasRefreshModules(void)
for (;;) {
fgets(buf, 256, fd);
- if (feof(fd))
- break;
*** 4308 LINES SKIPPED ***
More information about the dev-commits-src-all
mailing list