mike01 / pypacker

:package: The fastest and simplest packet manipulation lib for Python
GNU General Public License v2.0
252 stars 46 forks source link

TCP.sum is not recomputed after _update_fields is called on an upper layer #37

Closed ebertland closed 6 years ago

ebertland commented 7 years ago

In a custom layer5 protocol, I added a header "length" in the hdr tuple of tuples. It is fixed size (2 octets) and I used the FIELD_FLAG_AUTOUPDATE option. I wrote the code for _update_fields (for current HEAD of master) and for bin() (version 4.0) to calculate the length of the upper_layer body and store that in self.length. For both, the correct length is written to the header of my custom protocol.

The problem is that the TCP.sum is never recalculated to account for the updated length field. I traced the calls, and I see that TCP._update_fields() is only called once and it is before the call to my custom protocol's _update_fields() (or bin() in the case of version 4.0).

Can you recommend an example where a layer567 protocol is layered above TCP, and it has automatically updated simple header fields? I am not doing anything complicated that requires dynamic fields, deactivated fields, or trigger lists.

mike01 commented 7 years ago

Seems to be a regression when _update_fields() was newly introduced. A quick fix would be to force checksum recalculation by changing the TCP header like "tcp.sum = tcp.sum"

mike01 commented 7 years ago

Should be fixed now in current master branch

mike01 commented 6 years ago

Response timeout, closing ticket.