Tags: gopacket/gopacket
Tags
Feature/add serialize to ipv6 routing (#111) * add SerializeTo IPv6Routing Signed-off-by: sat0ken <15720506+sat0ken@users.noreply.github.com> * add SerializeTo IPv6Routing Signed-off-by: sat0ken <15720506+sat0ken@users.noreply.github.com> * Update layers/ip6.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: sat0ken <15720506+sat0ken@users.noreply.github.com> Co-authored-by: Ali <hi@n0p.me> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
refactor: don't fill empty metadata slots (#32) Some metadata arrays are pretty big (e.g. `EthernetTypeMetadata` has 65536 slots), while only a small subset of the values are filled with actual decoders (e.g. for `EthernetTypeMetadata` that is 18 entries). The rest were filled in `func init()` to return error on access. This leads to noticeable startup time delay, as these mappings are pretty big. This change simply leaves not used slots unset (zero value), and the request error values are generated on access to the slot. Comparing time with `GODEBUG=inittrace=1` on a simple test program which imports `gopacket/layers`: before: ``` init internal/bytealg @0 ms, 0 ms clock, 0 bytes, 0 allocs init runtime @0.009 ms, 0.063 ms clock, 0 bytes, 0 allocs init math @0.18 ms, 0 ms clock, 0 bytes, 0 allocs init errors @0.19 ms, 0 ms clock, 0 bytes, 0 allocs init sync @0.20 ms, 0.002 ms clock, 16 bytes, 1 allocs init internal/godebug @0.21 ms, 0.020 ms clock, 816 bytes, 20 allocs init internal/intern @0.23 ms, 0.002 ms clock, 408 bytes, 8 allocs init hash/crc32 @0.24 ms, 0.008 ms clock, 1024 bytes, 1 allocs init net/netip @0.26 ms, 0 ms clock, 48 bytes, 2 allocs init syscall @0.26 ms, 0.003 ms clock, 640 bytes, 3 allocs init time @0.27 ms, 0.002 ms clock, 0 bytes, 0 allocs init context @0.28 ms, 0 ms clock, 96 bytes, 1 allocs init io/fs @0.29 ms, 0 ms clock, 0 bytes, 0 allocs init os @0.30 ms, 0.006 ms clock, 328 bytes, 7 allocs init unicode @0.31 ms, 0 ms clock, 512 bytes, 4 allocs init reflect @0.32 ms, 0 ms clock, 0 bytes, 0 allocs init vendor/golang.org/x/net/dns/dnsmessage @0.32 ms, 0.002 ms clock, 624 bytes, 6 allocs init net @0.33 ms, 0.002 ms clock, 688 bytes, 13 allocs init github.com/gopacket/gopacket @0.34 ms, 0.003 ms clock, 720 bytes, 5 allocs init github.com/gopacket/gopacket/layers @0.35 ms, 1.3 ms clock, 25136 bytes, 63 allocs ``` after: ``` init internal/bytealg @0 ms, 0 ms clock, 0 bytes, 0 allocs init runtime @0.011 ms, 0.070 ms clock, 0 bytes, 0 allocs init math @0.26 ms, 0 ms clock, 0 bytes, 0 allocs init errors @0.27 ms, 0 ms clock, 0 bytes, 0 allocs init sync @0.27 ms, 0.003 ms clock, 16 bytes, 1 allocs init internal/godebug @0.28 ms, 0.023 ms clock, 816 bytes, 20 allocs init internal/intern @0.31 ms, 0.002 ms clock, 408 bytes, 8 allocs init hash/crc32 @0.32 ms, 0.008 ms clock, 1024 bytes, 1 allocs init net/netip @0.33 ms, 0 ms clock, 48 bytes, 2 allocs init syscall @0.34 ms, 0.003 ms clock, 640 bytes, 3 allocs init time @0.35 ms, 0.003 ms clock, 0 bytes, 0 allocs init context @0.37 ms, 0 ms clock, 96 bytes, 1 allocs init io/fs @0.38 ms, 0 ms clock, 0 bytes, 0 allocs init os @0.38 ms, 0.009 ms clock, 328 bytes, 7 allocs init unicode @0.40 ms, 0 ms clock, 512 bytes, 4 allocs init reflect @0.41 ms, 0 ms clock, 0 bytes, 0 allocs init vendor/golang.org/x/net/dns/dnsmessage @0.42 ms, 0.002 ms clock, 624 bytes, 6 allocs init net @0.43 ms, 0.004 ms clock, 688 bytes, 13 allocs init github.com/gopacket/gopacket @0.44 ms, 0.003 ms clock, 720 bytes, 5 allocs init github.com/gopacket/gopacket/layers @0.46 ms, 0.086 ms clock, 25872 bytes, 66 allocs ``` Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
Fixes for Geneve option flags/length field (#17) * Fix Geneve option flags/length field decoding The option header length is 5 bits, not 4, so fix the bit shift for decoding flags, and fix the mask for decoding the length. This also adds a unit test for decoding a max length option (124 byte payload). * Fix Geneve option flags/length field serialization OR-assigning the flag bits into the byte offset for the Geneve option header flags/length field produced corrupt packets because the buffer returned by PrependBytes is not guaranteed to be zeroed out. Since this is the first time that offset is touched, just assign instead. --------- Co-authored-by: Simeon Miteff <simeon.miteff@corelight.com>
Geneve SerializeTo improvements (#9) * geneve: Fix crash in SerializeTo when lengths are wrong We run the risk of panicing on buffer overflow if option lengths in the packet are blindly trusted in serialization. In line with the precedent set elsewhere (e.g. IPv4, TCP), compute the necessary buffer size based on the actual options size. Fill lengths fields from user-provided values, even if those are wrong. Signed-off-by: Nick Zavaritsky <mejedi@gmail.com> * geneve: support FixLengths option in SerializeTo Signed-off-by: Nick Zavaritsky <mejedi@gmail.com> Signed-off-by: Nick Zavaritsky <mejedi@gmail.com>