aboutsummaryrefslogtreecommitdiff
path: root/request
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-10-04 09:44:58 +0100
committerGravatar GitHub <noreply@github.com> 2019-10-04 09:44:58 +0100
commit03ea2ae955823612da2e3b2ebf21da7ab8eea1bd (patch)
tree8b140512f8000f4d2042ad43a3dd5e8e301a3328 /request
parentf8551df27284b93e9f95e064ec65a9df60f4a528 (diff)
downloadcoredns-03ea2ae955823612da2e3b2ebf21da7ab8eea1bd.tar.gz
coredns-03ea2ae955823612da2e3b2ebf21da7ab8eea1bd.tar.zst
coredns-03ea2ae955823612da2e3b2ebf21da7ab8eea1bd.zip
Make request.Request smaller (#3351)
* Make request.Request smaller This makes the request struct smaller and removes the pointer to the do boolean (tri-bool) as size == 0 will indicate if we have cached it. Family can be a int8 because it only carries 3 values, Size itself is just a uint16 under the covers. This is a more comprehensive fix than #3292 Closes #3292 Signed-off-by: Miek Gieben <miek@miek.nl> * cache: fix test this now needs a valid response writter Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'request')
-rw-r--r--request/request.go43
-rw-r--r--request/request_test.go2
2 files changed, 19 insertions, 26 deletions
diff --git a/request/request.go b/request/request.go
index 6f1a1de0e..76bb6a787 100644
--- a/request/request.go
+++ b/request/request.go
@@ -18,15 +18,16 @@ type Request struct {
// Optional lowercased zone of this query.
Zone string
- // Cache size after first call to Size or Do.
- size int
- do *bool // nil: nothing, otherwise *do value
+ // Cache size after first call to Size or Do. If size is zero nothing has been cached yet.
+ // Both Size and Do set these values (and cache them).
+ size uint16 // UDP buffer size, or 64K in case of TCP.
+ do bool // DNSSEC OK value
// Caches
+ family int8 // transport's family.
name string // lowercase qname.
ip string // client's ip.
port string // client's port.
- family int // transport's family.
localPort string // server's port.
localIP string // server's ip.
}
@@ -127,7 +128,7 @@ func Proto(w dns.ResponseWriter) string {
// Family returns the family of the transport, 1 for IPv4 and 2 for IPv6.
func (r *Request) Family() int {
if r.family != 0 {
- return r.family
+ return int(r.family)
}
var a net.IP
@@ -141,26 +142,20 @@ func (r *Request) Family() int {
if a.To4() != nil {
r.family = 1
- return r.family
+ return 1
}
r.family = 2
- return r.family
+ return 2
}
// Do returns if the request has the DO (DNSSEC OK) bit set.
func (r *Request) Do() bool {
- if r.do != nil {
- return *r.do
+ if r.size != 0 {
+ return r.do
}
- r.do = new(bool)
-
- if o := r.Req.IsEdns0(); o != nil {
- *r.do = o.Do()
- return *r.do
- }
- *r.do = false
- return false
+ r.Size()
+ return r.do
}
// Len returns the length in bytes in the request.
@@ -170,21 +165,19 @@ func (r *Request) Len() int { return r.Req.Len() }
// Or when the request was over TCP, we return the maximum allowed size of 64K.
func (r *Request) Size() int {
if r.size != 0 {
- return r.size
+ return int(r.size)
}
- size := 0
+ size := uint16(0)
if o := r.Req.IsEdns0(); o != nil {
- if r.do == nil {
- r.do = new(bool)
- }
- *r.do = o.Do()
- size = int(o.UDPSize())
+ r.do = o.Do()
+ size = o.UDPSize()
}
+ // normalize size
size = edns.Size(r.Proto(), size)
r.size = size
- return size
+ return int(size)
}
// SizeAndDo adds an OPT record that the reflects the intent from request.
diff --git a/request/request_test.go b/request/request_test.go
index a62fc51bf..0a3b1f2d8 100644
--- a/request/request_test.go
+++ b/request/request_test.go
@@ -13,7 +13,7 @@ func TestRequestDo(t *testing.T) {
st := testRequest()
st.Do()
- if st.do == nil {
+ if !st.do {
t.Errorf("Expected st.do to be set")
}
}