feat: add support for pcap replay
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.
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
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?
Certainly!
Ah you are right I'll remove replayDelay. Thanks!
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.
Merged, thanks again :)
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