From bd70190c4dbb738528a2180d112b27f04dbe175d Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 22 Jun 2021 14:00:25 +0200 Subject: [PATCH] Move makeDataOpt into edns.go (#1273) Make it more obvious that these two lists (const, and case) need to be in sync. Also sort the list to match the const sorting. Signed-off-by: Miek Gieben --- edns.go | 35 +++++++++++++++++++++++++++++++++++ msg_helpers.go | 33 --------------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/edns.go b/edns.go index 60228d85..c9181783 100644 --- a/edns.go +++ b/edns.go @@ -28,6 +28,41 @@ const ( _DO = 1 << 15 // DNSSEC OK ) +// makeDataOpt is used to unpack the EDNS0 option(s) from a message. +func makeDataOpt(code uint16) EDNS0 { + // All the EDNS0.* constants above need to be in this switch. + switch code { + case EDNS0LLQ: + return new(EDNS0_LLQ) + case EDNS0UL: + return new(EDNS0_UL) + case EDNS0NSID: + return new(EDNS0_NSID) + case EDNS0DAU: + return new(EDNS0_DAU) + case EDNS0DHU: + return new(EDNS0_DHU) + case EDNS0N3U: + return new(EDNS0_N3U) + case EDNS0SUBNET: + return new(EDNS0_SUBNET) + case EDNS0EXPIRE: + return new(EDNS0_EXPIRE) + case EDNS0COOKIE: + return new(EDNS0_COOKIE) + case EDNS0TCPKEEPALIVE: + return new(EDNS0_TCP_KEEPALIVE) + case EDNS0PADDING: + return new(EDNS0_PADDING) + case EDNS0EDE: + return new(EDNS0_EDE) + default: + e := new(EDNS0_LOCAL) + e.Code = code + return e + } +} + // OPT is the EDNS0 RR appended to messages to convey extra (meta) information. // See RFC 6891. type OPT struct { diff --git a/msg_helpers.go b/msg_helpers.go index 97c1b5ee..5904927c 100644 --- a/msg_helpers.go +++ b/msg_helpers.go @@ -438,39 +438,6 @@ Option: return edns, off, nil } -func makeDataOpt(code uint16) EDNS0 { - switch code { - case EDNS0NSID: - return new(EDNS0_NSID) - case EDNS0SUBNET: - return new(EDNS0_SUBNET) - case EDNS0COOKIE: - return new(EDNS0_COOKIE) - case EDNS0EXPIRE: - return new(EDNS0_EXPIRE) - case EDNS0UL: - return new(EDNS0_UL) - case EDNS0LLQ: - return new(EDNS0_LLQ) - case EDNS0DAU: - return new(EDNS0_DAU) - case EDNS0DHU: - return new(EDNS0_DHU) - case EDNS0N3U: - return new(EDNS0_N3U) - case EDNS0PADDING: - return new(EDNS0_PADDING) - case EDNS0EDE: - return new(EDNS0_EDE) - case EDNS0TCPKEEPALIVE: - return new(EDNS0_TCP_KEEPALIVE) - default: - e := new(EDNS0_LOCAL) - e.Code = code - return e - } -} - func packDataOpt(options []EDNS0, msg []byte, off int) (int, error) { for _, el := range options { b, err := el.pack()