mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
dispatch on rst flag
This commit is contained in:
+6
-2
@@ -120,15 +120,19 @@ func (sock *SockRaw) ReadPacketData() (buf []byte, ci gopacket.CaptureInfo, err
|
||||
read:
|
||||
i = int(sock.frame * FRAMESIZE)
|
||||
tpHdr = (*unix.Tpacket2Hdr)(unsafe.Pointer(&sock.buf[i]))
|
||||
sock.frame = (sock.frame + 1) % FRAMENR
|
||||
|
||||
for tpHdr.Status&unix.TP_STATUS_USER == 0 {
|
||||
if tpHdr.Status&unix.TP_STATUS_USER == 0 {
|
||||
_, _, e := unix.Syscall(unix.SYS_POLL, uintptr(unsafe.Pointer(poll)), 1, sock.pollTimeout)
|
||||
if e != 0 && e != unix.EINTR {
|
||||
return buf, ci, e
|
||||
}
|
||||
// it might be some other frame with data!
|
||||
if tpHdr.Status&unix.TP_STATUS_USER == 0 {
|
||||
goto read
|
||||
}
|
||||
}
|
||||
|
||||
sock.frame = (sock.frame + 1) % FRAMENR
|
||||
tpHdr.Status = unix.TP_STATUS_KERNEL
|
||||
sockAddr := (*unix.RawSockaddrLinklayer)(unsafe.Pointer(&sock.buf[i+tpacket2hdrlen]))
|
||||
|
||||
|
||||
+14
-3
@@ -139,7 +139,7 @@ func NewMessagePool(maxSize size.Size, messageExpire time.Duration, debugger Deb
|
||||
func (pool *MessagePool) Handler(packet gopacket.Packet) {
|
||||
var in, out bool
|
||||
pckt, err := ParsePacket(packet)
|
||||
if err != nil {
|
||||
if err != nil || pckt == nil {
|
||||
go pool.say(4, fmt.Sprintf("error decoding packet(%dBytes):%s\n", packet.Metadata().CaptureLength, err))
|
||||
return
|
||||
}
|
||||
@@ -151,6 +151,19 @@ func (pool *MessagePool) Handler(packet gopacket.Packet) {
|
||||
if !ok {
|
||||
m, ok = pool.pool[dstKey]
|
||||
}
|
||||
if pckt.RST {
|
||||
if ok {
|
||||
<-m.done
|
||||
}
|
||||
if m, ok = pool.pool[pckt.Dst()]; !ok {
|
||||
m, ok = pool.pool[pckt.Dst()+"="+srcKey]
|
||||
}
|
||||
if ok {
|
||||
<-m.done
|
||||
}
|
||||
go pool.say(4, fmt.Sprintf("RST flag from %s to %s at %s\n", pckt.Src(), pckt.Dst(), pckt.Timestamp))
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case ok:
|
||||
pool.addPacket(m, pckt)
|
||||
@@ -201,8 +214,6 @@ func (pool *MessagePool) addPacket(m *Message, pckt *Packet) {
|
||||
case trunc >= 0:
|
||||
case pool.End != nil && pool.End(m):
|
||||
case pckt.FIN:
|
||||
case pckt.RST:
|
||||
go pool.say(4, fmt.Sprintf("RST flag from %s to %s at %s\n", pckt.Src(), pckt.Dst(), pckt.Timestamp))
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
@@ -146,6 +146,19 @@ func (pckt *Packet) SYNOptions() (mss uint16, windowscale byte) {
|
||||
return
|
||||
}
|
||||
|
||||
// LinkInfo returns info about the link layer
|
||||
func (pckt *Packet) LinkInfo() string {
|
||||
if l, ok := pckt.LinkLayer.(*layers.Ethernet); ok {
|
||||
return fmt.Sprintf(
|
||||
"Source Mac: %s\nDestination Mac: %s\nProtocol: %s",
|
||||
l.SrcMAC,
|
||||
l.DstMAC,
|
||||
l.EthernetType,
|
||||
)
|
||||
}
|
||||
return "<Not Ethernet>"
|
||||
}
|
||||
|
||||
// Flag returns formatted tcp flags
|
||||
func (pckt *Packet) Flag() (flag string) {
|
||||
if pckt.FIN {
|
||||
@@ -175,6 +188,7 @@ func (pckt *Packet) Flag() (flag string) {
|
||||
// String output for a TCP Packet
|
||||
func (pckt *Packet) String() string {
|
||||
return fmt.Sprintf(`Time: %s
|
||||
%s
|
||||
Source: %s
|
||||
Destination: %s
|
||||
IHL: %d
|
||||
@@ -188,6 +202,7 @@ Options: %s
|
||||
Data Size: %d
|
||||
Lost Data: %d`,
|
||||
pckt.Timestamp.Format(time.StampNano),
|
||||
pckt.LinkInfo(),
|
||||
pckt.Src(),
|
||||
pckt.Dst(),
|
||||
pckt.IHL(),
|
||||
|
||||
Reference in New Issue
Block a user