diff --git a/sys/netinet/libalias/alias_ftp.c b/sys/netinet/libalias/alias_ftp.c index 2eb885944fce..d91e1cde018f 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 6d8bf3dd051d..defdb561384e 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 63f6288fb67b..4dc2e0a95742 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 b2789f36ec13..f683ba095240 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 4493b1b45142..f109f74c4d65 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 61848bb1d4ec..c314a65f770d 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 4234276921e2..dc70bc12667e 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)