-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Common/Network+BBA/Builtin: Cleanup #10831
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13957a6
Common/Network: Remove unused constructors
sepalani b7bd2a4
Common/Network: Use member initializer list
sepalani 4efe1e7
Common/Network: Ensure offsetof is valid
sepalani 6238834
Common/Network: Add InsertObj helper
sepalani b206f98
Common/Network: Remove unnecessary size checks
sepalani d902b04
Common/Network: Remove unused offset variables
sepalani 5fdf255
Common/Network: Make Build() methods const
sepalani b950d03
Common/Network: Update IP checksum since total_len might have changed
sepalani be2ede6
BBA/BuiltIn: Move functions to anonymous namespace
sepalani File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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'm not super familiar with some of these Dolphin helper classes.
This seems odd to me; I'm probably missing something. I get the first equal is effectively creating the
BitCastPtrType
and the second equal is memcopy'ing 0 to that pointer. But why bother with that when the 3rd equal you set it to a different value?Basically, why not do this:
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 will awnser for him, the crc calculation include the crc field, it need to be set to 0 for this process
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.
Thank you but I don't get it. I'd understand if all the bytes were getting zero'd out and then writing just some bytes after. But here the value is being set to 0 and then set to whatever
htons
returns. Why are both required?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.
ComputeNetworkChecksum()
is doing the actual work here and it needs the field set to 0 to return the correct value, but the field when the packet is actually sent needs to be the result ofComputeNetworkChecksum()
. Basically what is happening here is: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.
See https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation for reference. I don't know why the checksum is in the middle of the data either, but that's how it works.
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.
Ah, I was so focused on the code flow / logic, I didn't stop to think what was going on. Has nothing to do with the
memcpy
here. We're literally wanting to set the checksum value to 0 to avoid including it in the checksum calculation. I should have seen that. Thanks @AdmiralCurtiss .This isn't relevant to the PR really because I see this is just a cleanup.
But is there a reason to redo the checksum calculation? Yes, we flipped the bits to send over the wire but flipping the checksum should be adequate? Additionally, just personally I find something like this a little clearer than the pointer arithmetic:
I guess it incurs the cost of the copy constructor, but I feel like that's worth the gain in readability.
Additionally, also curious why are we only handling some of the fields? Ex, why isn't
source_port
,identification
, etc being handled?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.
Build()
is the method used to serialise the packet into bytes.Since this method is used for serialisation, before calling it we can change the parts we want of the structure, like updating members such as the TCP options, IP options, payload data and many fields of the IP and TCP headers. That's why we have to make sure the checksums and total_len are up-to-date and haven't changed.
Using a copy isn't the only issue, we need several objects to be contiguous in memory (IP header struct, IP options vector, TCP header struct, TCP options vector, data vector), these are needed to compute the checksum easily. That's why working on the vector directly is more straight forward. Otherwise, we have to compute several checksums separately, sum them and set them in the packet_result.
These fields are set in the packet constructor or when necessary by the code in the BBA/BuiltIn file.