diff options
author | Deomid "rojer" Ryabkov <rojer9@fb.com> | 2021-08-17 21:14:49 +0100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2021-08-17 22:35:19 +0200 |
commit | d825980013862241bb15a5eb0499144e8aa5aaab (patch) | |
tree | 759f53ed0bc997e555aa0d2488367b325bb74bb5 | |
parent | 35f8c40455b2a8558d0da02472e321b47064a316 (diff) |
Fix a bug in MessageOptions.NTPServers
Added a unit test
Signed-off-by: Deomid "rojer" Ryabkov <rojer9@fb.com>
-rw-r--r-- | dhcpv6/dhcpv6message.go | 2 | ||||
-rw-r--r-- | dhcpv6/option_ntp_server_test.go | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index 5b76d3a..a120898 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -300,7 +300,7 @@ func (mo MessageOptions) NTPServers() []net.IP { addrs := make([]net.IP, 0) for _, opt := range opts { ntp, ok := opt.(*OptNTPServer) - if ok { + if !ok { continue } for _, subopt := range ntp.Suboptions { diff --git a/dhcpv6/option_ntp_server_test.go b/dhcpv6/option_ntp_server_test.go index 6cc5dd3..105a753 100644 --- a/dhcpv6/option_ntp_server_test.go +++ b/dhcpv6/option_ntp_server_test.go @@ -79,4 +79,10 @@ func TestParseOptNTPServer(t *testing.T) { optFQDN, ok := o.Suboptions[1].(*NTPSuboptionSrvFQDN) require.True(t, ok) assert.Equal(t, *fqdn, rfc1035label.Labels(*optFQDN)) + + var mo MessageOptions + assert.Nil(t, mo.NTPServers()) + mo.Add(o) + // MessageOptions.NTPServers only returns server address values. + assert.Equal(t, []net.IP{ip}, mo.NTPServers()) } |