Skip to content

Fix frame length #324

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

Merged
merged 2 commits into from
Jan 27, 2019
Merged

Fix frame length #324

merged 2 commits into from
Jan 27, 2019

Conversation

pepper-jk
Copy link
Contributor

@pepper-jk pepper-jk commented Jan 16, 2019

This pull request should fix issue #300.

I implemented a virtual method PDU::advertised_size(), which defaults to the sum of header_size() + trailer_size() plus advertised_size() of all inner PDUs down to the IP PDU.

The IP::advertised_size() method returns the tot_len instead.

The PacketWriter now uses this virtual method to determine the frame length before writing the packet out.

Please let me know if this solution is to your liking.

src/pdu.cpp Outdated
const PDU* ptr(inner_pdu_);
while (ptr) {
sz += ptr->advertised_size();
if(ptr->pdu_type() != IP) {
Copy link
Owner

Choose a reason for hiding this comment

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

This check shouldn't be here. This has to work no matter what PDUs a packet contains. I think a better and generic solution to this is to have the default implementation return header_size() + trailer_size() + inner_pdu()->size() (this last one obviously only if there's an inner PDU). This way you're defining the advertised PDU size to be the size of the current PDU + whatever the next PDU tells you. So if the next PDU is IP, then it will simply return its total length without going further down the chain.

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I mean inner_pdu()->advertised_size() here.

Copy link
Contributor Author

@pepper-jk pepper-jk Jan 22, 2019

Choose a reason for hiding this comment

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

Well the IP::tot_len() contains the length of all inner PDUs does it not?

That was my understanding after looking at the IP header in wireshark.

Copy link
Owner

Choose a reason for hiding this comment

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

Exactly, which is why IP can get away with just returning tot_len as its advertised size vs the rest of the PDUs which need to keep going down the PDU chain to find out.

Copy link
Contributor Author

@pepper-jk pepper-jk Jan 22, 2019

Choose a reason for hiding this comment

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

I see the check is no longer needed, since IP::advertised_size() will be the recursion anchor.

I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes, just waiting for your continuous integration.

@@ -281,6 +281,11 @@ class TINS_API IP : public PDU {

/* Getters */

uint32_t advertised_size() const {
uint32_t sz = static_cast<uint32_t>(tot_len());
Copy link
Owner

Choose a reason for hiding this comment

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

Let's just make this a single return, no need for an intermediate variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes, just waiting for your continuous integration.

src/pdu.cpp Outdated
@@ -85,6 +85,10 @@ uint32_t PDU::size() const {
return sz;
}

uint32_t PDU::advertised_size() const {
return header_size() + trailer_size() + inner_pdu()->advertised_size();
Copy link
Owner

Choose a reason for hiding this comment

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

As I mentioned in my comment, this should first check if there's an inner_pdu, otherwise this will blow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. Fixed.

@pepper-jk
Copy link
Contributor Author

Is there anything else that needs changing?

@mfontanini
Copy link
Owner

Nope, it looks good. I just didn't get to merge this. Thanks!

@mfontanini mfontanini merged commit 1f5456b into mfontanini:master Jan 27, 2019
@pepper-jk
Copy link
Contributor Author

Cool, thanks for merging.
Any chance there will be a release with this fix in the near future?

@mfontanini
Copy link
Owner

I could probably release a patch version soon.

@pepper-jk
Copy link
Contributor Author

Any updates on the patch version?

@mfontanini
Copy link
Owner

Oops, I completely forgot. I'll definitely do this tonight! Sorry about that

@mfontanini
Copy link
Owner

I just pushed v4.2. Sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants