kaitai-io / kaitai_struct_formats

Kaitai Struct: library of binary file formats (.ksy)
http://formats.kaitai.io
712 stars 203 forks source link

Ethernet doesn't account for 802.1Q #690

Open elliottecton opened 6 years ago

elliottecton commented 6 years ago

If 2 Bytes starting at byte 13 is x8100, everything gets thrown off. x8100 is for 802.1Q, and there are an additional 4 Bytes added before the IP packet. I've been trying to fix this, but the compiler seems to cache old .ksy file, and frankly I'm about to pull my hair out. I would love a little bit of help from the community.

GreyCat commented 6 years ago

Generally, you need to:

  1. Add 0x8100 definition in ether_type_enum
  2. Add related switch entry into body like that:
  - id: body
    size-eos: true
    type:
      switch-on: ether_type
      cases:
        'ether_type_enum::ipv4': ipv4_packet
        'ether_type_enum::ipv6': ipv6_packet
        'ether_type_enum::ieee_802_1q': ieee_802_1q_packet
  1. Add implementation of ieee_802_1q_packet, which would specify what is in these 4 bytes in the beginning and then would just re-apply original ethernet frame type.