Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for pcap replay #132

Merged
merged 7 commits into from
May 8, 2024
Merged

Conversation

eddc005
Copy link
Contributor

@eddc005 eddc005 commented May 6, 2024

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.

@tobyxdd tobyxdd self-requested a review May 6, 2024 20:40
@tobyxdd tobyxdd self-assigned this May 6, 2024
@tobyxdd tobyxdd added the enhancement New feature or request label May 6, 2024
@tobyxdd
Copy link
Collaborator

tobyxdd commented May 6, 2024

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
Copy link
Collaborator

tobyxdd commented May 6, 2024

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
Copy link
Contributor Author

eddc005 commented May 6, 2024

Certainly!

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

@tobyxdd tobyxdd requested a review from haruue May 6, 2024 22:19
io/pcap.go Show resolved Hide resolved
io/pcap.go Show resolved Hide resolved
Copy link
Collaborator

@tobyxdd tobyxdd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the following two changes

@eddc005
Copy link
Contributor Author

eddc005 commented May 7, 2024

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 tobyxdd merged commit c453020 into apernet:master May 8, 2024
2 checks passed
@tobyxdd
Copy link
Collaborator

tobyxdd commented May 8, 2024

Merged, thanks again :)

tobyxdd added a commit that referenced this pull request May 8, 2024
This reverts commit c453020, reversing
changes made to 5723490.
@tobyxdd
Copy link
Collaborator

tobyxdd commented May 8, 2024

#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

haruue added a commit that referenced this pull request May 8, 2024
@haruue haruue mentioned this pull request May 8, 2024
@haruue haruue removed their request for review May 9, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants