dhcp6: use new getters (#37)

Signed-off-by: Chris Koch <chrisko@google.com>
This commit is contained in:
Chris K 2020-03-07 00:35:59 -08:00 committed by GitHub
parent 989bfadc88
commit ffc4c21bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 20 deletions

2
go.mod
View File

@ -11,7 +11,7 @@ require (
github.com/google/gopacket v1.1.17
github.com/google/nftables v0.0.0-20200210101420-1c56a1906fbf
github.com/google/renameio v0.1.0
github.com/insomniacslk/dhcp v0.0.0-20200210095418-45e5f320b2f0
github.com/insomniacslk/dhcp v0.0.0-20200306230118-99cbb09fb7b9
github.com/jpillora/backoff v1.0.0
github.com/krolaw/dhcp4 v0.0.0-20190909130307-a50d88189771
github.com/mdlayher/raw v0.0.0-20191009151244-50f2db8cc065

2
go.sum
View File

@ -47,6 +47,8 @@ github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/insomniacslk/dhcp v0.0.0-20200210095418-45e5f320b2f0 h1:jzkAy3xl8j58ylC1cleuFZyBDCGy+swFc0cdxvVawkc=
github.com/insomniacslk/dhcp v0.0.0-20200210095418-45e5f320b2f0/go.mod h1:CfMdguCK66I5DAUJgGKyNz8aB6vO5dZzkm9Xep6WGvw=
github.com/insomniacslk/dhcp v0.0.0-20200306230118-99cbb09fb7b9 h1:5gifC0gFQ6VowQOXA1Yn1z4NFXlWRLbDT3oFxIZowJk=
github.com/insomniacslk/dhcp v0.0.0-20200306230118-99cbb09fb7b9/go.mod h1:CfMdguCK66I5DAUJgGKyNz8aB6vO5dZzkm9Xep6WGvw=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw=

View File

@ -277,26 +277,21 @@ func (c *Client) ObtainOrRenew() bool {
return true
}
var newCfg Config
for _, opt := range reply.Options {
switch o := opt.(type) {
case *dhcpv6.OptIAForPrefixDelegation:
t1 := c.timeNow().Add(o.T1)
if t1.Before(newCfg.RenewAfter) || newCfg.RenewAfter.IsZero() {
newCfg.RenewAfter = t1
}
if sopt := o.GetOneOption(dhcpv6.OptionIAPrefix); sopt != nil {
prefix := sopt.(*dhcpv6.OptIAPrefix)
newCfg.Prefixes = append(newCfg.Prefixes, net.IPNet{
IP: prefix.IPv6Prefix(),
Mask: net.CIDRMask(int(prefix.PrefixLength()), 128),
})
}
case *dhcpv6.OptDNSRecursiveNameServer:
for _, ns := range o.NameServers {
newCfg.DNS = append(newCfg.DNS, ns.String())
}
for _, o := range reply.Options.IAPD() {
t1 := c.timeNow().Add(o.T1)
if t1.Before(newCfg.RenewAfter) || newCfg.RenewAfter.IsZero() {
newCfg.RenewAfter = t1
}
if sopt := o.GetOneOption(dhcpv6.OptionIAPrefix); sopt != nil {
prefix := sopt.(*dhcpv6.OptIAPrefix)
newCfg.Prefixes = append(newCfg.Prefixes, net.IPNet{
IP: prefix.IPv6Prefix(),
Mask: net.CIDRMask(int(prefix.PrefixLength()), 128),
})
}
}
for _, dns := range reply.Options.DNS() {
newCfg.DNS = append(newCfg.DNS, dns.String())
}
c.cfg = newCfg
return true