OpenGFW icon indicating copy to clipboard operation
OpenGFW copied to clipboard

feat: add support for pcap replay

Open eddc005 opened this issue 1 year ago • 3 comments

Description

Completes #122. Added support for pcap replay. Implementation based on the prototype posted in the issue (Thanks to @66hh)

Introduced a new command line argument

$ ./OpenGFW -h
...
  -p, --pcap string         pcap file (optional)

# run a pcap replay
$ ./OpenGFW -c config.yaml rules.yaml -p capture.pcap

Added a new configuration block for pcap replay

replay:
  realtime: false   # whether the replay uses capture's timestamps. Default to true
  replayDelay: 10ms   # if not realtime, the fixed-time gap between replaying each packet. Default to 10ms

Implementation

  • StreamID is solely based on source and destination IP. A future improvement could incorporate Transport Layer information.
  • Tweaked some engine logics to ensure that application quits when replay finishes.

eddc005 avatar May 06 '24 20:05 eddc005

Hi @eddc005 thanks for your PR. It just so happens that I'm also changing the packet part... Can you update your code to match the latest interface?

https://github.com/apernet/OpenGFW/pull/133/files

tobyxdd avatar May 06 '24 21:05 tobyxdd

Also, I'm not sure why replayDelay is needed. I see in the comments that it's to "avoid flooding the workers". As far as I know, workers use buffered channels which do not drop values when they are full - they just block the writer (the callback) - which should be fine in this case?

tobyxdd avatar May 06 '24 21:05 tobyxdd

Certainly!

Ah you are right I'll remove replayDelay. Thanks!

eddc005 avatar May 06 '24 21:05 eddc005

Updated! Hopefully I understand ProtectedDialContext correctly.

Appreciate a lot for your review! I'm fairly new to networking programming in Go. Forgive me for making obvious mistakes sometimes.

eddc005 avatar May 07 '24 20:05 eddc005

Merged, thanks again :)

tobyxdd avatar May 08 '24 06:05 tobyxdd

https://github.com/apernet/OpenGFW/pull/135

I have reverted the changes. We need to find a way to not rely on CGO - the current pcap implementation in gopacket requires CGO

tobyxdd avatar May 08 '24 06:05 tobyxdd