summaryrefslogtreecommitdiffstats
path: root/sys/netinet/libalias
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-06-27 07:36:02 +0000
committerglebius <glebius@FreeBSD.org>2005-06-27 07:36:02 +0000
commitc6e57e046e743ecb35b9a7c48c8fb5e6d30b6ac1 (patch)
tree31bc69409e5f746eb4521a8499f88fae66f48cbb /sys/netinet/libalias
parent49d602bcb1eba547fdc15540603f3f9303f3418a (diff)
downloadFreeBSD-src-c6e57e046e743ecb35b9a7c48c8fb5e6d30b6ac1.zip
FreeBSD-src-c6e57e046e743ecb35b9a7c48c8fb5e6d30b6ac1.tar.gz
Disable checksum processing in LibAlias, when it works as a
kernel module. LibAlias is not aware about checksum offloading, so the caller should provide checksum calculation. (The only current consumer is ng_nat(4)). When TCP packet internals has been changed and it requires checksum recalculation, a cookie is set in th_x2 field of TCP packet, to inform caller that it needs to recalculate checksum. This ugly hack would be removed when LibAlias is made more kernel friendly. Incremental checksum updates are left as is, since they don't conflict with offloading. Approved by: re (scottl)
Diffstat (limited to 'sys/netinet/libalias')
-rw-r--r--sys/netinet/libalias/alias_ftp.c4
-rw-r--r--sys/netinet/libalias/alias_irc.c4
-rw-r--r--sys/netinet/libalias/alias_local.h11
-rw-r--r--sys/netinet/libalias/alias_proxy.c4
-rw-r--r--sys/netinet/libalias/alias_skinny.c14
-rw-r--r--sys/netinet/libalias/alias_smedia.c9
-rw-r--r--sys/netinet/libalias/alias_util.c16
7 files changed, 50 insertions, 12 deletions
diff --git a/sys/netinet/libalias/alias_ftp.c b/sys/netinet/libalias/alias_ftp.c
index 2eb8859..d91e1cd 100644
--- a/sys/netinet/libalias/alias_ftp.c
+++ b/sys/netinet/libalias/alias_ftp.c
@@ -677,7 +677,11 @@ NewFtpMessage(struct libalias *la, struct ip *pip,
/* Compute TCP checksum for revised packet */
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
+#endif
} else {
#ifdef LIBALIAS_DEBUG
fprintf(stderr,
diff --git a/sys/netinet/libalias/alias_irc.c b/sys/netinet/libalias/alias_irc.c
index 6d8bf3d..defdb56 100644
--- a/sys/netinet/libalias/alias_irc.c
+++ b/sys/netinet/libalias/alias_irc.c
@@ -374,7 +374,11 @@ lPACKET_DONE:
/* Compute TCP checksum for revised packet */
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
+#endif
return;
}
}
diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h
index 63f6288..4dc2e0a 100644
--- a/sys/netinet/libalias/alias_local.h
+++ b/sys/netinet/libalias/alias_local.h
@@ -178,9 +178,18 @@ struct libalias {
/* Prototypes */
-/* General utilities */
+/*
+ * We do not calculate TCP checksums when libalias is a kernel
+ * module, since it has no idea about checksum offloading.
+ * If TCP data has changed, then we just set checksum to zero,
+ * and caller must recalculate it himself.
+ * In case if libalias will edit UDP data, the same approach
+ * should be used.
+ */
+#ifndef _KERNEL
u_short IpChecksum(struct ip *_pip);
u_short TcpChecksum(struct ip *_pip);
+#endif
void
DifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
diff --git a/sys/netinet/libalias/alias_proxy.c b/sys/netinet/libalias/alias_proxy.c
index b2789f3..f683ba0 100644
--- a/sys/netinet/libalias/alias_proxy.c
+++ b/sys/netinet/libalias/alias_proxy.c
@@ -474,7 +474,11 @@ ProxyEncodeTcpStream(struct alias_link *lnk,
already changed. */
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
+#endif
}
static void
diff --git a/sys/netinet/libalias/alias_skinny.c b/sys/netinet/libalias/alias_skinny.c
index 4493b1b..f109f74 100644
--- a/sys/netinet/libalias/alias_skinny.c
+++ b/sys/netinet/libalias/alias_skinny.c
@@ -150,7 +150,11 @@ alias_skinny_reg_msg(struct RegisterMessage *reg_msg, struct ip *pip,
reg_msg->ipAddr = (u_int32_t) GetAliasAddress(lnk).s_addr;
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
+#endif
return (0);
}
@@ -189,8 +193,11 @@ alias_skinny_port_msg(struct IpPortMessage *port_msg, struct ip *pip,
port_msg->stationIpPort = (u_int32_t) ntohs(GetAliasPort(lnk));
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
-
+#endif
return (0);
}
@@ -218,8 +225,11 @@ alias_skinny_opnrcvch_ack(struct libalias *la, struct OpenReceiveChannelAck *opn
opnrcvch_ack->port = (u_int32_t) ntohs(GetAliasPort(opnrcv_lnk));
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
-
+#endif
return (0);
}
diff --git a/sys/netinet/libalias/alias_smedia.c b/sys/netinet/libalias/alias_smedia.c
index 61848bb..c314a65 100644
--- a/sys/netinet/libalias/alias_smedia.c
+++ b/sys/netinet/libalias/alias_smedia.c
@@ -331,8 +331,11 @@ alias_rtsp_out(struct libalias *la, struct ip *pip,
pip->ip_len = new_len;
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
-
+#endif
return (0);
}
@@ -376,7 +379,11 @@ alias_pna_out(struct libalias *la, struct ip *pip,
/* Compute TCP checksum for revised packet */
tc->th_sum = 0;
+#ifdef _KERNEL
+ tc->th_x2 = 1;
+#else
tc->th_sum = TcpChecksum(pip);
+#endif
}
}
work += ntohs(msg_len);
diff --git a/sys/netinet/libalias/alias_util.c b/sys/netinet/libalias/alias_util.c
index 4234276..dc70bc1 100644
--- a/sys/netinet/libalias/alias_util.c
+++ b/sys/netinet/libalias/alias_util.c
@@ -43,13 +43,6 @@ __FBSDID("$FreeBSD$");
Added differential checksum update function.
*/
-/*
-Note: the checksum routines assume that the actual checksum word has
-been zeroed out. If the checksum word is filled with the proper value,
-then these routines will give a result of zero (useful for testing
-purposes);
-*/
-
#ifdef _KERNEL
#include <sys/param.h>
#else
@@ -70,6 +63,12 @@ purposes);
#include "alias_local.h"
#endif
+/*
+ * Note: the checksum routines assume that the actual checksum word has
+ * been zeroed out. If the checksum word is filled with the proper value,
+ * then these routines will give a result of zero (useful for testing
+ * purposes);
+ */
u_short
LibAliasInternetChecksum(struct libalias *la __unused, u_short * ptr,
int nbytes)
@@ -92,6 +91,7 @@ LibAliasInternetChecksum(struct libalias *la __unused, u_short * ptr,
return (~sum);
}
+#ifndef _KERNEL
u_short
IpChecksum(struct ip *pip)
{
@@ -144,7 +144,7 @@ TcpChecksum(struct ip *pip)
/* Return checksum */
return ((u_short) ~ sum);
}
-
+#endif /* not _KERNEL */
void
DifferentialChecksum(u_short * cksum, void *newp, void *oldp, int n)
OpenPOWER on IntegriCloud