File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments