Skip to content

Commit 7248f4b

Browse files
committed
tun_recv: removed mssfix limit for IPv4 traffic if DF is not set
Signed-off-by: Marco Baffo <[email protected]>
1 parent 9cafba7 commit 7248f4b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

openvpn/client/cliproto.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,27 @@ class Session : ProtoContextCallbackInterface,
443443
if (buf.size())
444444
{
445445
const ProtoContext::ProtoConfig &c = proto_context.conf();
446+
447+
const uint8_t* packet_data = buf.data();
448+
bool df = true;
449+
450+
// Check if the packet is IPv4
451+
if (IPCommon::version(packet_data[0]) == IPCommon::IPv4 && buf.size() >= sizeof(struct IPv4Header))
452+
{
453+
// The Flags field is in the 6th byte (starting from index 6) of the IPv4 header
454+
uint16_t flags_and_fragment_offset = ntohs(*(uint16_t*)&packet_data[6]);
455+
456+
// The DF bit is the 2nd bit in the Flags field (0x4000 in big-endian)
457+
df = (flags_and_fragment_offset & 0x4000) != 0;
458+
}
459+
446460
// when calculating mss, we take IPv4 and TCP headers into account
447461
// here we need to add it back since we check the whole IP packet size, not just TCP payload
448462
constexpr size_t MinTcpHeader = 20;
449463
constexpr size_t MinIpHeader = 20;
450464
size_t mss_no_tcp_ip_encap = c.mss_fix + (MinTcpHeader + MinIpHeader);
451-
if (c.mss_fix > 0 && buf.size() > mss_no_tcp_ip_encap)
465+
466+
if (df && c.mss_fix > 0 && buf.size() > mss_no_tcp_ip_encap)
452467
{
453468
Ptb::generate_icmp_ptb(buf, clamp_to_typerange<unsigned short>(mss_no_tcp_ip_encap));
454469
tun->tun_send(buf);

0 commit comments

Comments
 (0)