mike01 / pypacker

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

IP.len is not recomputed when upper layer protocol has variable padding #36

Closed ebertland closed 6 years ago

ebertland commented 7 years ago

In a custom layer5 protocol, I added variable padding to ensure that the number of bytes of the payload (body bytes of the TCP segment) is a multiple of 4. I followed an example and did this by adding the pad byte string to the end in the protocol's bin() implementation. The IP.len is not recomputed after this, so it is always off by the size of the variable pad.

I tried both released version 4.0 and the current HEAD of master.

mike01 commented 7 years ago

Based on your description is assume the callflow (by ovverwriting bin()) is: "overwritten bin()" -> "super.bin()" -> _update_fields() -> "overwritten bin() returns response of super.bin() + padding", so the padding isn't considered in _update_fields(). One option would be something like:

def bin(self, update_auto_fields=True):
  #  TODO: change body length to multiple of 4
  return pypacker.Packet.bin(self, update_auto_fields=update_auto_fields)

Update: Length should be updated now with current master

mike01 commented 6 years ago

Response timeout, closing ticket.