{"record":{"id":"4a357f4acc4010fd","repo":"netbirdio/netbird","slug":"serialize-layers-w","errorCode":null,"errorMessage":"serialize layers: %w","messagePattern":"serialize layers: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/iface/wgproxy/udp/rawsocket.go","lineNumber":92,"sourceCode":"\treturn f, nil\n}\n\nfunc (f *SrcFaker) Close() error {\n\treturn f.rawSocket.Close()\n}\n\nfunc (f *SrcFaker) SendPkg(data []byte) (int, error) {\n\tdefer func() {\n\t\tif err := f.layerBuffer.Clear(); err != nil {\n\t\t\tlog.Errorf(\"failed to clear layer buffer: %s\", err)\n\t\t}\n\t}()\n\n\tpayload := gopacket.Payload(data)\n\n\terr := gopacket.SerializeLayers(f.layerBuffer, serializeOpts, f.ipH, f.udpH, payload)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"serialize layers: %w\", err)\n\t}\n\tn, err := f.rawSocket.WriteTo(f.layerBuffer.Bytes(), f.localHostAddr)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"write to raw conn: %w\", err)\n\t}\n\treturn n, nil\n}\n\nfunc prepareHeaders(dstPort int, srcAddr *net.UDPAddr) (gopacket.SerializableLayer, gopacket.SerializableLayer, error) {\n\tvar ipH gopacket.SerializableLayer\n\tvar networkLayer gopacket.NetworkLayer\n\n\t// Check if source IP is IPv4 or IPv6\n\tif srcAddr.IP.To4() != nil {\n\t\t// IPv4\n\t\tipv4 := &layers.IPv4{\n\t\t\tDstIP:    localHostNetIPAddrV4.IP,\n\t\t\tSrcIP:    srcAddr.IP,","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/iface/wgproxy/udp/rawsocket.go#L74-L110","documentation":"Returned by SrcFaker.SendPkg when gopacket.SerializeLayers fails to serialize the IP header + UDP header + payload into the reuse buffer with ComputeChecksums and FixLengths enabled. gopacket errors here when a layer is internally inconsistent - most commonly the UDP length field overflowing 16 bits (payload too large for one UDP datagram) or the fixed-size IPv4 header receiving invalid values. The prebuilt headers come from NewSrcFaker's prepareHeaders, so in practice the variable is the payload size.","triggerScenarios":"A proxied packet larger than what a UDP datagram can express (data > ~65507 bytes after headers), which requires an oversized interface MTU (e.g. jumbo/UDP GRO aggregation bugs feeding SendPkg buffers beyond 64KB); or corrupted header state after the buffer was not cleared (the deferred layerBuffer.Clear guards that).","commonSituations":"MTU misconfiguration on the NetBird interface (values near or above 65535); virtualization/GRO delivering aggregated super-packets; memory corruption. Rare in the field.","solutions":["Check the interface MTU: keep it in the normal 1280-1500 (or at most ~9000 jumbo) range - `ip link show wt0`","Inspect the wrapped gopacket error to see which layer rejected the write","Restart the agent after fixing MTU so proxies rebuild with a sane buffer size (mtu+bufsize.WGBufferOverhead)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// cap payloads to what one UDP datagram can carry before serializing\nconst maxUDPPayload = 65535 - 8 - 20 // v4 worst case\n\nfunc fitForDatagram(data []byte) ([]byte, bool) {\n    if len(data) <= maxUDPPayload {\n        return data, true\n    }\n    return nil, false\n}","typeGuard":null,"tryCatchPattern":"if _, err := f.SendPkg(data); err != nil {\n    if strings.Contains(err.Error(), \"serialize layers\") {\n        log.Errorf(\"packet of %d bytes exceeds UDP datagram limits; check interface MTU\", len(data))\n        return // drop - cannot be sent as one datagram\n    }\n    return err\n}","preventionTips":["Keep the NetBird interface MTU within 1280-9000; never set it near 65535","Disable GRO/GSO aggregation feeding the proxy if super-packets appear","Buffer sizes derive from mtu+bufsize.WGBufferOverhead - re-create proxies after MTU changes"],"tags":["go","netbird","gopacket","udp-proxy","mtu","serialization"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}