Skip to content

Commit bd70190

Browse files
authored
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 <miek@miek.nl>
1 parent 595ee5a commit bd70190

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

edns.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ const (
2828
_DO = 1 << 15 // DNSSEC OK
2929
)
3030

31+
// makeDataOpt is used to unpack the EDNS0 option(s) from a message.
32+
func makeDataOpt(code uint16) EDNS0 {
33+
// All the EDNS0.* constants above need to be in this switch.
34+
switch code {
35+
case EDNS0LLQ:
36+
return new(EDNS0_LLQ)
37+
case EDNS0UL:
38+
return new(EDNS0_UL)
39+
case EDNS0NSID:
40+
return new(EDNS0_NSID)
41+
case EDNS0DAU:
42+
return new(EDNS0_DAU)
43+
case EDNS0DHU:
44+
return new(EDNS0_DHU)
45+
case EDNS0N3U:
46+
return new(EDNS0_N3U)
47+
case EDNS0SUBNET:
48+
return new(EDNS0_SUBNET)
49+
case EDNS0EXPIRE:
50+
return new(EDNS0_EXPIRE)
51+
case EDNS0COOKIE:
52+
return new(EDNS0_COOKIE)
53+
case EDNS0TCPKEEPALIVE:
54+
return new(EDNS0_TCP_KEEPALIVE)
55+
case EDNS0PADDING:
56+
return new(EDNS0_PADDING)
57+
case EDNS0EDE:
58+
return new(EDNS0_EDE)
59+
default:
60+
e := new(EDNS0_LOCAL)
61+
e.Code = code
62+
return e
63+
}
64+
}
65+
3166
// OPT is the EDNS0 RR appended to messages to convey extra (meta) information.
3267
// See RFC 6891.
3368
type OPT struct {

msg_helpers.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -438,39 +438,6 @@ Option:
438438
return edns, off, nil
439439
}
440440

441-
func makeDataOpt(code uint16) EDNS0 {
442-
switch code {
443-
case EDNS0NSID:
444-
return new(EDNS0_NSID)
445-
case EDNS0SUBNET:
446-
return new(EDNS0_SUBNET)
447-
case EDNS0COOKIE:
448-
return new(EDNS0_COOKIE)
449-
case EDNS0EXPIRE:
450-
return new(EDNS0_EXPIRE)
451-
case EDNS0UL:
452-
return new(EDNS0_UL)
453-
case EDNS0LLQ:
454-
return new(EDNS0_LLQ)
455-
case EDNS0DAU:
456-
return new(EDNS0_DAU)
457-
case EDNS0DHU:
458-
return new(EDNS0_DHU)
459-
case EDNS0N3U:
460-
return new(EDNS0_N3U)
461-
case EDNS0PADDING:
462-
return new(EDNS0_PADDING)
463-
case EDNS0EDE:
464-
return new(EDNS0_EDE)
465-
case EDNS0TCPKEEPALIVE:
466-
return new(EDNS0_TCP_KEEPALIVE)
467-
default:
468-
e := new(EDNS0_LOCAL)
469-
e.Code = code
470-
return e
471-
}
472-
}
473-
474441
func packDataOpt(options []EDNS0, msg []byte, off int) (int, error) {
475442
for _, el := range options {
476443
b, err := el.pack()

0 commit comments

Comments
 (0)