Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add bidirectional packet capture #6882
base: main
Are you sure you want to change the base?
Add bidirectional packet capture #6882
Changes from all commits
875dde4
1307c17
25d581b
60d3e7e
79a26c0
6e5898c
e5ef842
7eb34de
5d04e5d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the way these helper functions are written doesn't make a lot of sense to me. The functions have a generic name, yet they have very specialized implementation that is dependent on a bunch of parameters. To me, the fact that
direction
is a parameter to this function is a bit of a red flag.overall, I would expect the implementation to be more streamlined. There should be a helper function to generate IP + port matching. We can call the function for the
SourceToDestination
direction. We can also call the function for theDestinationToSource
direction by swapping src / dst function parameters. For theBoth
direction, the function should just be called twice, and the caller should add the glue to make it work (or
operator). Am I missing something? Does it have to be much more complex than that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we may also support tcp flags and other layer4 configs, if that happens, we should consider make the current code structure more modularized, or it would be extremely hard to extend this function . This won't be easy but i suggest to review this part and see if we can do better.
not sure if we can separate the ip section and ports section apart, call sub functions to calculate their instruments size and sums up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try my best to improve the code structure and explore separating the IP and port sections as suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangyan I am thinking of refactoring the code as you suggested by modularizing the logic for IP and port comparison by adding helper functions for taking decisions based on direction and other parameters.
I’ve created a function
compareIP
to handle the conditional logic for building the instruction to compare IP address depending on the direction and which IP address is loaded for comparison (the booleanisSrc
tells if I have loaded the source or destination IP address)Similarly a function
comparePort
builds instruction for comparing portAdditional functions to calculate number of
SkipTrue
andSkipFalse
instructions dynamicallyLet me know if this looks better or if you have any suggestions for further improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code above assumes that
srcIP
anddstIP
are never nil. There was a discussion about it, which was marked as resolved. We should be consistent. If this is a precondition for the function, then we should not include these nil checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment for this one?
based on your function comment, in the
Both
direction case, we have to repeat the source host and destination host filters. Is that what this is for? This seems "small" to me, as I see the following above:but I assume you validated it in your unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that you are not checking for
packet != nil
here, which doesn't match the above code?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct me if I'm wrong but this code looks like a perfect duplicate of the code above
you could do something like this:
Note that I have changed the spelling of
transPort
totransport
, as the current version makes no sense.