2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "config-win32.h"
37 * Lower MSS on TCP SYN packets to fix MTU
38 * problems which arise from protocol
42 mss_fixup (struct buffer
*buf
, int maxmss
)
44 const struct openvpn_iphdr
*pip
;
47 if (BLEN (buf
) < (int) sizeof (struct openvpn_iphdr
))
51 pip
= (struct openvpn_iphdr
*) BPTR (buf
);
53 hlen
= OPENVPN_IPH_GET_LEN (pip
->version_len
);
55 if (pip
->protocol
== OPENVPN_IPPROTO_TCP
56 && ntohs (pip
->tot_len
) == BLEN (buf
)
57 && (ntohs (pip
->frag_off
) & OPENVPN_IP_OFFMASK
) == 0
60 >= (int) sizeof (struct openvpn_tcphdr
))
62 struct buffer newbuf
= *buf
;
63 if (buf_advance (&newbuf
, hlen
))
65 struct openvpn_tcphdr
*tc
= (struct openvpn_tcphdr
*) BPTR (&newbuf
);
66 if (tc
->flags
& OPENVPN_TCPH_SYN_MASK
)
67 mss_fixup_dowork (&newbuf
, (uint16_t) maxmss
);
73 mss_fixup_dowork (struct buffer
*buf
, uint16_t maxmss
)
75 int hlen
, olen
, optlen
;
79 struct openvpn_tcphdr
*tc
;
81 ASSERT (BLEN (buf
) >= (int) sizeof (struct openvpn_tcphdr
));
84 tc
= (struct openvpn_tcphdr
*) BPTR (buf
);
85 hlen
= OPENVPN_TCPH_GET_DOFF (tc
->doff_res
);
87 /* Invalid header length or header without options. */
88 if (hlen
<= (int) sizeof (struct openvpn_tcphdr
)
92 for (olen
= hlen
- sizeof (struct openvpn_tcphdr
),
93 opt
= (uint8_t *)(tc
+ 1);
95 olen
-= optlen
, opt
+= optlen
) {
96 if (*opt
== OPENVPN_TCPOPT_EOL
)
98 else if (*opt
== OPENVPN_TCPOPT_NOP
)
102 if (optlen
<= 0 || optlen
> olen
)
104 if (*opt
== OPENVPN_TCPOPT_MAXSEG
) {
105 if (optlen
!= OPENVPN_TCPOLEN_MAXSEG
)
107 mss
= (uint16_t *)(opt
+ 2);
108 if (ntohs (*mss
) > maxmss
) {
109 dmsg (D_MSS
, "MSS: %d -> %d",
113 *mss
= htons (maxmss
);
115 ADJUST_CHECKSUM (accumulate
, tc
->check
);