{"record":{"id":"870556ddb3210448","repo":"TechnitiumSoftware/DnsServer","slug":"invalid-edns-udp-payload-size-valid-range-is-512","errorCode":null,"errorMessage":"Invalid EDNS UDP payload size: valid range is 512-4096 bytes.","messagePattern":"Invalid EDNS UDP payload size: valid range is 512-4096 bytes\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/DnsServer.cs","lineNumber":7292,"sourceCode":"                            else\n                                UdpClientConnection.DisposeSocketPool();\n                        }\n                        catch (Exception ex)\n                        {\n                            _log.Write(ex);\n                        }\n                    });\n                }\n            }\n        }\n\n        public ushort UdpPayloadSize\n        {\n            get { return _udpPayloadSize; }\n            set\n            {\n                if ((value < 512) || (value > 4096))\n                    throw new ArgumentOutOfRangeException(nameof(UdpPayloadSize), \"Invalid EDNS UDP payload size: valid range is 512-4096 bytes.\");\n\n                _udpPayloadSize = value;\n            }\n        }\n\n        public bool DnssecValidation\n        {\n            get { return _dnssecValidation; }\n            set\n            {\n                if (_dnssecValidation != value)\n                {\n                    if (!_dnssecValidation)\n                        _cacheZoneManager.Flush(); //flush cache to remove non validated data\n\n                    _dnssecValidation = value;\n                }\n            }","sourceCodeStart":7274,"sourceCodeEnd":7310,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/DnsServer.cs#L7274-L7310","documentation":"Thrown by the UdpPayloadSize property setter when the value is below 512 or above 4096 bytes. This controls the EDNS(0) UDP payload size advertised in DNS responses; values below 512 would break baseline DNS and values above 4096 risk IP fragmentation issues on the network.","triggerScenarios":"Setting server.UdpPayloadSize to any ushort value < 512 or > 4096.","commonSituations":"Tuning for large DNS responses (DNSSEC) by increasing payload; loading a config with an out-of-range value; copying a value from another DNS implementation with different bounds.","solutions":["Set UdpPayloadSize to a value between 512 and 4096 (1232 is the common recommended value to avoid fragmentation).","If loading from config, clamp the value before assignment: Math.Clamp(value, 512, 4096)."],"exampleFix":"// before\nserver.UdpPayloadSize = 8192; // throws\n\n// after\nserver.UdpPayloadSize = 1232; // DNS Flag Day recommended","handlingStrategy":"validation","validationCode":"ushort safeSize = (ushort)Math.Clamp(value, 512, 4096);\nserver.UdpPayloadSize = safeSize;","typeGuard":"static bool IsValidUdpPayloadSize(ushort s) => s >= 512 && s <= 4096;","tryCatchPattern":"try { server.UdpPayloadSize = value; }\ncatch (ArgumentOutOfRangeException) { server.UdpPayloadSize = 1232; }","preventionTips":["Use the DNS Flag Day recommended value of 1232 to stay safely in range.","Clamp loaded config values before assignment."],"tags":["dns","edns","udp","configuration"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}