a go dns packet parser

feature: add linting and test all fields for edns

+38
+11
.golangci.toml
··· 1 + version = "2" 2 + [linters.settings.govet] 3 + enable_all = true 4 + [linters.settings.staticcheck] 5 + checks = ["all"] 6 + [linters.settings.exhaustive] 7 + check = ["switch"] 8 + [linters.settings.exhaustruct] 9 + [linters.settings.goconst] 10 + [linters.settings.testifylint] 11 + enable-all = true
+7
Justfile
··· 1 + format: 2 + go fmt ./... 3 + gofumpt -l -w $(fd .go) 4 + 5 + verify: 6 + go vet ./... 7 + golangci-lint run
+20
message_test.go
··· 65 65 name: "Valid DNS query message with one question", 66 66 input: buildQuery(1234, "www.example.com", AType, IN), 67 67 expected: Message{ 68 + HasEDNS: false, 68 69 Header: Header{ 69 70 ID: 1234, 70 71 QR: false, ··· 92 93 &A{Address: net.ParseIP("10.0.0.1").To4()}, 93 94 ), 94 95 expected: Message{ 96 + HasEDNS: false, 95 97 Header: Header{ 96 98 ID: 5678, 97 99 QR: true, ··· 181 183 input: []byte{0xea, 0x7c, 0x1, 0x20, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x6, 0x6c, 0x6f, 0x62, 0x73, 0x74, 0x65, 0x2, 0x72, 0x73, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x29, 0x4, 0xd0, 0x0, 0x64, 0x0, 0x0, 0x0, 0x8, 0x0, 0x64, 0x0, 0x4, 0x66, 0x6f, 0x6f, 0xa}, 182 184 wantErr: false, 183 185 expected: Message{ 186 + HasEDNS: true, 184 187 Header: Header{ 185 188 ID: 0xea7c, 186 189 QR: false, ··· 216 219 }, 217 220 }, 218 221 Authority: []ResourceRecord{}, 222 + EDNSOptions: []EDNSOption{ 223 + { 224 + Code: 100, 225 + Data: []byte("foo\n"), 226 + }, 227 + }, 228 + EDNSVersion: 0x64, 229 + UDPSize: 0x4d0, 219 230 }, 220 231 }, 221 232 } ··· 247 258 assert.Equal(t, tt.expected.Answer, m.Answer, "Answer section mismatch") 248 259 assert.Equal(t, tt.expected.Authority, m.Authority, "Authority section mismatch") 249 260 assert.Equal(t, tt.expected.Additional, m.Additional, "Additional section mismatch") 261 + 262 + assert.Equal(t, tt.expected.HasEDNS, m.HasEDNS, "HasEDNS mismatch") 263 + if m.HasEDNS { 264 + assert.Equal(t, tt.expected.EDNSOptions, m.EDNSOptions, "EDNS Options mismatch") 265 + assert.Equal(t, tt.expected.ExtendedRCode, m.ExtendedRCode, "ExtendedRCode mismatch") 266 + assert.Equal(t, tt.expected.EDNSVersion, m.EDNSVersion, "EDNSVersion mismatch") 267 + assert.Equal(t, tt.expected.EDNSFlags, m.EDNSFlags, "EDNSFlags mismatch") 268 + assert.Equal(t, tt.expected.UDPSize, m.UDPSize, "UDPSize mismatch") 269 + } 250 270 251 271 b, err := m.Encode() 252 272 assert.NoError(t, err, "Expected no error on round trip")