File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ const CLOSE_WAIT_TIMEOUT: Duration = Duration::from_secs(5);
2828const LAST_ACK_MAX_RETRIES : usize = 3 ;
2929const LAST_ACK_TIMEOUT : Duration = Duration :: from_millis ( 500 ) ;
3030const TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
31+ const TCP_HEADER_LEN : u16 = 20 ;
3132
3233#[ non_exhaustive]
3334#[ derive( Debug , Clone ) ]
@@ -52,6 +53,9 @@ pub struct TcpConfig {
5253pub enum TcpOptions {
5354 /// Maximum segment size (MSS) for TCP connections. Default is 1460 bytes.
5455 MaximumSegmentSize ( u16 ) ,
56+
57+ /// MTU option,helps to set the MSS (Maximum Segment Size) option in the TCP header.
58+ IpMtu ( u16 ) ,
5559}
5660
5761impl Default for TcpConfig {
@@ -913,7 +917,17 @@ pub(crate) fn create_raw_packet(
913917 let mut tcp_options = Vec :: new ( ) ;
914918 for opt in opts {
915919 match opt {
916- TcpOptions :: MaximumSegmentSize ( mss) => tcp_options. push ( TcpOptionElement :: MaximumSegmentSize ( * mss) ) ,
920+ TcpOptions :: MaximumSegmentSize ( mss) => tcp_options. push ( etherparse:: TcpOptionElement :: MaximumSegmentSize ( * mss) ) ,
921+ TcpOptions :: IpMtu ( mtu) => {
922+ tcp_options. push ( etherparse:: TcpOptionElement :: MaximumSegmentSize (
923+ mtu - TCP_HEADER_LEN
924+ - if src_addr. is_ipv6 ( ) || dst_addr. is_ipv6 ( ) {
925+ 40
926+ } else {
927+ 20 // minimum IPv4 header size
928+ } ,
929+ ) ) ;
930+ }
917931 }
918932 }
919933 tcp_header
You can’t perform that action at this time.
0 commit comments