summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6message.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2021-08-09 17:48:57 +0200
committerinsomniac <insomniacslk@users.noreply.github.com>2021-08-13 12:35:03 +0200
commitc143d771146ef619fc01b272a1ce49b35c3d9c7c (patch)
treedad5ebb8aa8c8dfc55140c7d18bba1d80d2382b2 /dhcpv6/dhcpv6message.go
parentdecc701b36654be7f26b9c91537d509b8db85425 (diff)
Added OptNTPServer
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Diffstat (limited to 'dhcpv6/dhcpv6message.go')
-rw-r--r--dhcpv6/dhcpv6message.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go
index e18fd59..5b76d3a 100644
--- a/dhcpv6/dhcpv6message.go
+++ b/dhcpv6/dhcpv6message.go
@@ -288,6 +288,32 @@ func (mo MessageOptions) DHCP4oDHCP6Server() *OptDHCP4oDHCP6Server {
return nil
}
+// NTPServers returns the NTP server addresses contained in the
+// NTP_SUBOPTION_SRV_ADDR of an OPTION_NTP_SERVER.
+// If multiple NTP server options exist, the function will return all the NTP
+// server addresses it finds, as defined by RFC 5908.
+func (mo MessageOptions) NTPServers() []net.IP {
+ opts := mo.Options.Get(OptionNTPServer)
+ if opts == nil {
+ return nil
+ }
+ addrs := make([]net.IP, 0)
+ for _, opt := range opts {
+ ntp, ok := opt.(*OptNTPServer)
+ if ok {
+ continue
+ }
+ for _, subopt := range ntp.Suboptions {
+ so, ok := subopt.(*NTPSuboptionSrvAddr)
+ if !ok {
+ continue
+ }
+ addrs = append(addrs, net.IP(*so))
+ }
+ }
+ return addrs
+}
+
// Message represents a DHCPv6 Message as defined by RFC 3315 Section 6.
type Message struct {
MessageType MessageType