From 7937d24b12b3ef87ef4714381b4ad11ca18b6e5b Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Thu, 1 Apr 2010 10:41:01 +0000 Subject: [PATCH] Remove alignment constraints. --- sys/netgraph/ng_tcpmss.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/netgraph/ng_tcpmss.c b/sys/netgraph/ng_tcpmss.c index bcc421a9e081..19f9edc74c1d 100644 --- a/sys/netgraph/ng_tcpmss.c +++ b/sys/netgraph/ng_tcpmss.c @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -410,9 +411,9 @@ correct_mss(struct tcphdr *tc, int hlen, uint16_t maxmss, int flags) { int olen, optlen; u_char *opt; - uint16_t *mss; int accumulate; int res = 0; + uint16_t sum; for (olen = hlen - sizeof(struct tcphdr), opt = (u_char *)(tc + 1); olen > 0; olen -= optlen, opt += optlen) { @@ -427,13 +428,15 @@ correct_mss(struct tcphdr *tc, int hlen, uint16_t maxmss, int flags) if (*opt == TCPOPT_MAXSEG) { if (optlen != TCPOLEN_MAXSEG) continue; - mss = (uint16_t *)(opt + 2); - if (ntohs(*mss) > maxmss) { - accumulate = *mss; - *mss = htons(maxmss); - accumulate -= *mss; - if ((flags & CSUM_TCP) == 0) - TCPMSS_ADJUST_CHECKSUM(accumulate, tc->th_sum); + accumulate = be16dec(opt + 2); + if (accumulate > maxmss) { + if ((flags & CSUM_TCP) == 0) { + accumulate -= maxmss; + sum = be16dec(&tc->th_sum); + TCPMSS_ADJUST_CHECKSUM(accumulate, sum); + be16enc(&tc->th_sum, sum); + } + be16enc(opt + 2, maxmss); res = 1; } }