a go dns packet parser

Merge pull request 'fix error in how rname and mname were being added to soa records' (#7) from bugfix/soa-encoded-domains into main

Reviewed-on: https://code.kiri.systems/kiri/magna/pulls/7

blu abb0522b 2c2a1c50

+40 -2
+2 -2
resource_record.go
··· 138 138 } 139 139 140 140 func (soa *SOA) Encode(bytes []byte, offsets *map[string]uint16) []byte { 141 - bytes = append(bytes, encode_domain(bytes, soa.MName, offsets)...) 142 - bytes = append(bytes, encode_domain(bytes, soa.RName, offsets)...) 141 + bytes = encode_domain(bytes, soa.MName, offsets) 142 + bytes = encode_domain(bytes, soa.RName, offsets) 143 143 bytes = binary.BigEndian.AppendUint32(bytes, soa.Serial) 144 144 bytes = binary.BigEndian.AppendUint32(bytes, soa.Refresh) 145 145 bytes = binary.BigEndian.AppendUint32(bytes, soa.Retry)
+38
resource_record_test.go
··· 1 + package magna 2 + 3 + import ( 4 + // "bytes" 5 + "testing" 6 + 7 + "github.com/stretchr/testify/assert" 8 + ) 9 + 10 + func TestSOADecodeWithCompression(t *testing.T) { 11 + input := []byte{0x69, 0x7b, 0x81, 0x83, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0xf, 0x6e, 0x6f, 0x77, 0x61, 0x79, 0x74, 0x68, 0x69, 0x73, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x3, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x1, 0x0, 0x1, 0xc0, 0x1c, 0x0, 0x6, 0x0, 0x1, 0x0, 0x0, 0x3, 0x84, 0x0, 0x3d, 0x1, 0x61, 0xc, 0x67, 0x74, 0x6c, 0x64, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x3, 0x6e, 0x65, 0x74, 0x0, 0x5, 0x6e, 0x73, 0x74, 0x6c, 0x64, 0xc, 0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2d, 0x67, 0x72, 0x73, 0xc0, 0x1c, 0x67, 0xaa, 0xc5, 0x6b, 0x0, 0x0, 0x7, 0x8, 0x0, 0x0, 0x3, 0x84, 0x0, 0x9, 0x3a, 0x80, 0x0, 0x0, 0x3, 0x84} 12 + 13 + msg := &Message{} 14 + err := msg.Decode(input) 15 + assert.NoError(t, err) 16 + 17 + assert.Equal(t, 1, len(msg.Authority)) 18 + 19 + rr := msg.Authority[0] 20 + assert.Equal(t, DNSType(6), rr.RType) 21 + assert.Equal(t, DNSClass(1), rr.RClass) 22 + assert.Equal(t, uint32(900), rr.TTL) 23 + assert.Equal(t, uint16(61), rr.RDLength) 24 + 25 + soa, ok := msg.Authority[0].RData.(*SOA) 26 + assert.True(t, ok) 27 + 28 + assert.Equal(t, "a.gtld-servers.net", soa.MName) 29 + assert.Equal(t, "nstld.verisign-grs.com", soa.RName) 30 + assert.Equal(t, uint32(1739244907), soa.Serial) 31 + assert.Equal(t, uint32(1800), soa.Refresh) 32 + assert.Equal(t, uint32(900), soa.Retry) 33 + assert.Equal(t, uint32(604800), soa.Expire) 34 + assert.Equal(t, uint32(900), soa.Minimum) 35 + 36 + encoded := msg.Encode() 37 + assert.Equal(t, input, encoded) 38 + }