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)
This commit is contained in:
parent
49d602bcb1
commit
c6e57e046e
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user