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

Ipv4_packet improvements #1915

Closed
wants to merge 2 commits into from
Closed

Conversation

jschlatow
Copy link
Member

Adding write accessors to the Ipv4 header fields, including checksum generation. Also fixing the header_length field.

unsigned _header_length : 4;
unsigned _version : 4;
Copy link
Member

Choose a reason for hiding this comment

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

why do you change the order of version and IHL header fields here? The standard says that the version field is followed by the header length field, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this was a byte-order issue. Apparently, bitfields are affected by the endianess so both fields where shuffled in the memory layout. I tested this with wireshark.

Copy link
Member

Choose a reason for hiding this comment

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

A strong sign to replace the bit fields with our register/bit set framework.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, the problem is that although it is one byte (version and IHL) and byte-order is correct here, within bitfields the bit-order is not correctly reproduced here. As an interims fix the re-order is a good solution. In general, I agree to chelmuth that we should get rid of bitfields here and use the register framework (which did not exist yet when those headers got written).
Apart from that, it would be nice when the header length return value would be expressed in bytes instead of 32bit words.

@chelmuth
Copy link
Member

I'd like to merge these improvements, but am uncertain about the state of the header-length return value discussion... @skalk? @ValiValpas?

@skalk
Copy link
Member

skalk commented Apr 12, 2016

@ValiValpas @chelmuth as I already wrote, the re-ordering of the bitfields is good as an interims solution before we replace them with the register framework. On the other hand I'd like to replace the header length return value to not return 32-bit word count, but byte count. Because although the IPv4 standard says that this field in the header returns 32-bit fields, I assume most programmers suppose to get byte count when having a size_t return value, and otherwise have to turn the value into byte count anyway.

chelmuth added a commit that referenced this pull request May 9, 2016
Supports stronger typing of raw accesses and const correctness.

Issue #1915
chelmuth pushed a commit that referenced this pull request May 9, 2016
chelmuth added a commit that referenced this pull request May 9, 2016
… message amendment)

Replace size_t by uint8_t in accessors for the IPv4 header fields
'version' and 'header_length' - uint8_t is the smallest integral type
for 4 bit of information. Note, as the _internet header length_ field is
defined to reflect the number of 32-bit words the header occupies, we
also stick to the specification with our accessor.

Issue #1915
chelmuth pushed a commit that referenced this pull request May 9, 2016
Also adds header-checksum calculation function.

Fixes #1915
chelmuth added a commit that referenced this pull request May 9, 2016
chelmuth added a commit that referenced this pull request May 10, 2016
@chelmuth
Copy link
Member

@ValiValpas can you confirm that de0a115 and 4b98b6d restore the original function?

@jschlatow
Copy link
Member Author

@chelmuth I couldn't test this in my original setup because the nic_drv for linux is segfaulting. I was able to run the essential part on hw_zynq though and had a look at the packets with wireshark. Looks perfekt!

@chelmuth
Copy link
Member

Thanks. Regarding nic_drv segfault I assume you're using a recent Linux distro. We had some issues with Ubuntu 15.10 / 16.04 recently and will address these in the next weeks.

@jschlatow
Copy link
Member Author

Yes, I'm using Archlinux:

segfault at 1e42c18 ip 00007f3d494cd3eb sp 00007ffce0e5fc10 error 4 in libc-2.23.so[7f3d49454000+198000]

chelmuth added a commit that referenced this pull request May 23, 2016
Supports stronger typing of raw accesses and const correctness.

Issue #1915
chelmuth pushed a commit that referenced this pull request May 23, 2016
Replace size_t by uint8_t in accessors for the IPv4 header fields
'version' and 'header_length' - uint8_t is the smallest integral type
for 4 bit of information. Note, as the _internet header length_ field is
defined to reflect the number of 32-bit words the header occupies, we
also stick to the specification with our accessor.

Issue #1915
@chelmuth chelmuth closed this in 27a73b8 May 27, 2016
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.

3 participants