apernet / OpenGFW

OpenGFW is a flexible, easy-to-use, open source implementation of GFW (Great Firewall of China) on Linux
https://gfw.dev/
Mozilla Public License 2.0
9.31k stars 703 forks source link

feat: add support for pcap replay #132

Closed eddc005 closed 2 months ago

eddc005 commented 2 months ago

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

tobyxdd commented 2 months ago

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 commented 2 months ago

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?

eddc005 commented 2 months ago

Certainly!

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

eddc005 commented 2 months ago

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.

tobyxdd commented 2 months ago

Merged, thanks again :)

tobyxdd commented 2 months ago

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