From 59dde15e8256c4393a0419fafc780164debfbec2 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Mon, 27 Jun 2005 07:36:02 +0000 Subject: [PATCH] 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) --- sys/netinet/libalias/alias_ftp.c | 4 ++++ sys/netinet/libalias/alias_irc.c | 4 ++++ sys/netinet/libalias/alias_local.h | 11 ++++++++++- sys/netinet/libalias/alias_proxy.c | 4 ++++ sys/netinet/libalias/alias_skinny.c | 14 ++++++++++++-- sys/netinet/libalias/alias_smedia.c | 9 ++++++++- sys/netinet/libalias/alias_util.c | 16 ++++++++-------- 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/sys/netinet/libalias/alias_ftp.c b/sys/netinet/libalias/alias_ftp.c index 2eb885944fc..d91e1cde018 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 6d8bf3dd051..defdb561384 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 63f6288fb67..4dc2e0a9574 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 b2789f36ec1..f683ba09524 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 4493b1b4514..f109f74c4d6 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 61848bb1d4e..c314a65f770 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 4234276921e..dc70bc12667 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 #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)