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

Better support for the len type #75

Closed
xairy opened this issue Sep 19, 2016 · 4 comments
Closed

Better support for the len type #75

xairy opened this issue Sep 19, 2016 · 4 comments

Comments

@xairy
Copy link
Collaborator

xairy commented Sep 19, 2016

  1. Allow to use len to denote the length of any other field of the same struct, not just for buffer/vma/arrayptr fields.

  2. Sometimes one of the fields in a struct denotes not the length of the entire struct or the length of some particular field in bytes, but the length in 32-bit words of the length of a few fields. Not sure exactly how to support that, maybe by adding a support of some simple arithmetic for the len type, along the lines of sizeof(field1) / 4.

    A few examples:

    IPv4 packets (https://en.wikipedia.org/wiki/IPv4#Header) contain IHL field, which is "the number of 32-bit words in the header" (the header is variable in size). More over there is a Total Length field, which "defines the entire packet size, including header and data, in bytes".

    Some IPv6 extension headers (https://en.wikipedia.org/wiki/IPv6_packet#Hop-by-hop_options_and_destination_options) contain Hdr Ext Len fields, which is the "length of this header in 8-octet units, not including the first 8 octets" (octet == byte).

@xairy
Copy link
Collaborator Author

xairy commented Sep 20, 2016

  1. Many networking protocols expect packet field values to be big-endian. While it's possible to use define KERNEL_CONST_BE htons(KERNEL_CONST) for constants, it's unclear what to do with the length fields.

@xairy
Copy link
Collaborator Author

xairy commented Sep 30, 2016

2 can be resolved by adding a few special types: bytesize4 to denote the size of a filed in 32-bit words and bytesize8 to denote the size of the field in 64-bit words. The IPv4 example is then can be resolved by using bitfields (#72) and bytesize4[parent] and the IPv6 example - by using bytesize8[parent].

@xairy
Copy link
Collaborator Author

xairy commented Sep 30, 2016

3 can be resolved by adding a few more types: int16be, int32be and int64be, which will denote an integer of appropriate bit size that should be converted to the big endian byte order (the value should probably be converted while parsing the templates and generating types).

@xairy
Copy link
Collaborator Author

xairy commented Jan 17, 2017

Bitfields (#72), be suffix and bytesizeN types are now supported.
This can be closed.

@xairy xairy closed this as completed Jan 17, 2017
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

No branches or pull requests

1 participant