Skip to content

Commit

Permalink
add next TCP packet selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Nov 26, 2023
1 parent 04ce5d7 commit 12239f7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions stacks/port_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ func (port *tcpPort) HandleEth(dst []byte) (n int, err error) {

// nextPacket returns the next packet that is pending handling or the first packet if none are pending.
func (port *tcpPort) nextPacket() *TCPPacket {
for i := range port.packets {
if port.packets[i].pendingHandling() {
return &port.packets[i]
idx := 0
minSeq := port.packets[0].TCP.Seq
for i := 1; i < len(port.packets); i++ {
pkt := &port.packets[i]
if pkt.pendingHandling() && pkt.TCP.Seq < minSeq {
// We are interested in the minimum incoming sequence number.
minSeq = pkt.TCP.Seq
idx = i
}
}
return &port.packets[0]
return &port.packets[idx]
}

// freePacket returns the first packet that is not pending handling or nil if all packets are pending.
Expand Down

0 comments on commit 12239f7

Please sign in to comment.