Perform MSS fixups on incoming packets as well as outgoing.

MFC after: 1 week
This commit is contained in:
Brian Somers 2001-07-13 02:04:19 +00:00
parent e7be9f9a1a
commit 6cee8a8317

View File

@ -70,37 +70,6 @@
#define MAXMSS(mtu) (mtu - sizeof(struct ip) - sizeof(struct tcphdr))
static void MSSFixup(struct tcphdr *, ssize_t, u_int16_t);
static struct mbuf *
tcpmss_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp,
int pri, u_short *proto)
{
struct ip *pip;
int hlen, plen;
if (!Enabled(bundle, OPT_TCPMSSFIXUP))
return bp;
bp = m_pullup(bp);
plen = m_length(bp);
pip = (struct ip *)MBUF_CTOP(bp);
hlen = pip->ip_hl << 2;
/*
* Check for MSS option only for TCP packets with zero fragment offsets
* and correct total and header lengths.
*/
if (pip->ip_p == IPPROTO_TCP && (ntohs(pip->ip_off) & IP_OFFMASK) == 0 &&
ntohs(pip->ip_len) == plen && hlen <= plen &&
plen - hlen >= sizeof(struct tcphdr))
MSSFixup((struct tcphdr *)(MBUF_CTOP(bp) + hlen), plen - hlen,
MAXMSS(bundle->iface->mtu));
return bp;
}
/*-
* The following macro is used to update an
* internet checksum. "acc" is a 32-bit
@ -168,4 +137,46 @@ MSSFixup(struct tcphdr *tc, ssize_t pktlen, u_int16_t maxmss)
}
}
struct layer tcpmsslayer = { LAYER_PROTO, "tcpmss", tcpmss_LayerPush, NULL };
static struct mbuf *
tcpmss_Check(struct bundle *bundle, struct mbuf *bp)
{
struct ip *pip;
int hlen, plen;
if (!Enabled(bundle, OPT_TCPMSSFIXUP))
return bp;
bp = m_pullup(bp);
plen = m_length(bp);
pip = (struct ip *)MBUF_CTOP(bp);
hlen = pip->ip_hl << 2;
/*
* Check for MSS option only for TCP packets with zero fragment offsets
* and correct total and header lengths.
*/
if (pip->ip_p == IPPROTO_TCP && (ntohs(pip->ip_off) & IP_OFFMASK) == 0 &&
ntohs(pip->ip_len) == plen && hlen <= plen &&
plen - hlen >= sizeof(struct tcphdr))
MSSFixup((struct tcphdr *)(MBUF_CTOP(bp) + hlen), plen - hlen,
MAXMSS(bundle->iface->mtu));
return bp;
}
static struct mbuf *
tcpmss_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp,
int pri, u_short *proto)
{
return tcpmss_Check(bundle, bp);
}
static struct mbuf *
tcpmss_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp,
u_short *proto)
{
return tcpmss_Check(bundle, bp);
}
struct layer tcpmsslayer =
{ LAYER_PROTO, "tcpmss", tcpmss_LayerPush, tcpmss_LayerPull };