Skip to content

Commit

Permalink
add tsval, mss, other tcp opts
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-schneider committed Sep 11, 2024
1 parent 82b8ed0 commit b087123
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/networkpath/traceroute/tcp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tcp

import (
"context"
"encoding/binary"
"fmt"
"net"
"strconv"
Expand Down Expand Up @@ -98,12 +99,41 @@ func createRawTCPSyn(sourceIP net.IP, sourcePort uint16, destIP net.IP, destPort
SrcIP: sourceIP,
}

tsVal := make([]byte, 8)
binary.BigEndian.PutUint32(tsVal, uint32(time.Now().UnixMilli()))

tcpLayer := &layers.TCP{
SrcPort: layers.TCPPort(sourcePort),
DstPort: layers.TCPPort(destPort),
Seq: seqNum,
Ack: 0,
SYN: true,
Window: 35844,
Options: []layers.TCPOption{
{
OptionType: layers.TCPOptionKindMSS,
OptionLength: 4,
OptionData: []byte{0x23, 0x01}, // 8961
},
{
OptionType: layers.TCPOptionKindSACKPermitted,
OptionLength: 2,
},
{
OptionType: layers.TCPOptionKindTimestamps,
OptionLength: 10,
OptionData: tsVal,
},
{
OptionType: layers.TCPOptionKindNop,
OptionLength: 1,
},
{
OptionType: layers.TCPOptionKindWindowScale,
OptionLength: 3,
OptionData: []byte{0x02}, // 2
},
},
}

err := tcpLayer.SetNetworkLayerForChecksum(ipLayer)
Expand Down

0 comments on commit b087123

Please sign in to comment.