Files
Eugene Burkov 65b5293105 Pull request 285: AG-23599 use hostsfile vol.2
Merge in GO/dnsproxy from AG-23599-use-hostsfile-vol.2 to master

Squashed commit of the following:

commit b8fd8d5bbd2803ea6908a5ca938d60b9f256530f
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 10 19:21:33 2023 +0300

    upstream: fix nil deref

commit 11ec4feb9f1f5e575f12310c0438ed89c81c722e
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 10 18:54:45 2023 +0300

    bootstrap: imp docs

commit 93aa3b1c54f762f59bcadd145294028f38fe4d93
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 10 17:30:15 2023 +0300

    bootstrap: imp doc

commit 9779260e70d5ef7a3d8ff1d550bf5558007879d6
Merge: 1240ee1 ea0f2b1
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 10 16:43:54 2023 +0300

    Merge branch 'master' into AG-23599-use-hostsfile-vol.2

commit 1240ee16e968b63aca8ac27a024716b6f4159cb4
Author: Eugene Burkov <[email protected]>
Date:   Thu Nov 9 17:37:58 2023 +0300

    upstream: remove sort from upstream resolver

commit f22fe9bdfdcaf4ef9b81cbb0f94bd926eb45b6bb
Author: Eugene Burkov <[email protected]>
Date:   Thu Nov 9 15:37:01 2023 +0300

    all: upd go

commit 45c52151c8ed50a94fc040fbfd585499f3beabae
Author: Eugene Burkov <[email protected]>
Date:   Thu Nov 9 15:34:22 2023 +0300

    upstream: remove empty impl

commit 8582ed91e27955660bd787896d7945b07e204140
Author: Eugene Burkov <[email protected]>
Date:   Wed Nov 8 13:00:14 2023 +0300

    upstream: imp cognit

commit 35ce9dcac57b3eb9e4e80fe6dd0152e568077d73
Author: Eugene Burkov <[email protected]>
Date:   Wed Nov 8 12:47:25 2023 +0300

    all: imp code, fmt

commit 1823da58c765fdeb17a1ab70aebb0bd5eee8cdcf
Author: Eugene Burkov <[email protected]>
Date:   Wed Nov 8 12:33:35 2023 +0300

    all: imp docs, restore behavior

commit aeda1791f483e9ddb6910a66a1415ed424578fbb
Author: Eugene Burkov <[email protected]>
Date:   Tue Nov 7 15:23:17 2023 +0300

    main: fix import

commit fa3746453f77e32fe90f9cb53f9dbbc10e421dc8
Merge: eb12aec 254e5a8
Author: Eugene Burkov <[email protected]>
Date:   Tue Nov 7 14:33:18 2023 +0300

    Merge branch 'master' into AG-23599-use-hostsfile-vol.2

commit eb12aecb33afcb6c05f86c4787bffeb8a6018a33
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 3 19:44:15 2023 +0300

    upstream: fix nil deref

commit e8975360323190e91043ad4ec13e302696210971
Author: Eugene Burkov <[email protected]>
Date:   Fri Nov 3 18:38:00 2023 +0300

    all: imp code, docs

commit 60e709976413d5c64b54b000eb243ff4d83f6ca2
Merge: 0e6e9ad 8d20902
Author: Eugene Burkov <[email protected]>
Date:   Tue Oct 31 17:16:14 2023 +0300

    Merge branch 'master' into AG-23599-use-hostsfile-vol.2

commit 0e6e9ad9ca61f11ebf17de6e047f005d94d630d1
Merge: b10f900 b4abccf
Author: Eugene Burkov <[email protected]>
Date:   Wed Oct 11 17:09:08 2023 +0300

    Merge branch 'master' into AG-23599-use-hostsfile-vol.2

commit b10f900a3bb8682e6de2105569c0e6569ef84afb
Author: Eugene Burkov <[email protected]>
Date:   Wed Oct 11 16:30:18 2023 +0300

    upstream: imp returning types & docs

commit a5f50776da1b0396bd0e66d784996ea4832ab26b
Author: Eugene Burkov <[email protected]>
Date:   Thu Oct 5 18:52:20 2023 +0300

    proxy: fix merged test

commit a1535566677d6a1b7ccbfd7c89efeff87501d7b5
Author: Eugene Burkov <[email protected]>
Date:   Thu Oct 5 18:50:27 2023 +0300

    netutil: doc more, fix type check

commit 718aee887448e5fc38c9069579c69757ba067c38
Merge: 34750a6 60d2174
Author: Eugene Burkov <[email protected]>
Date:   Thu Oct 5 16:07:10 2023 +0300

    Merge branch 'master' into AG-23599-use-hostsfile-vol.2

... and 8 more commits
2023-11-10 19:35:11 +03:00

37 lines
680 B
Go

// Package proxyutil contains helper functions that are used in all other
// dnsproxy packages.
package proxyutil
import (
"encoding/binary"
"net/netip"
"github.com/miekg/dns"
)
// AddPrefix adds a 2-byte prefix with the DNS message length.
func AddPrefix(b []byte) (m []byte) {
m = make([]byte, 2+len(b))
binary.BigEndian.PutUint16(m, uint16(len(b)))
copy(m[2:], b)
return m
}
// IPFromRR returns the IP address from rr if any.
func IPFromRR(rr dns.RR) (ip netip.Addr) {
var data []byte
switch rr := rr.(type) {
case *dns.A:
data = rr.A.To4()
case *dns.AAAA:
data = rr.AAAA
default:
return netip.Addr{}
}
ip, _ = netip.AddrFromSlice(data)
return ip
}