dhcp6: use new IAPD & Prefix getters (#41)
Signed-off-by: Chris Koch <chrisko@google.com>
This commit is contained in:
parent
e67fb4dd71
commit
4f0efc7b18
2
go.mod
2
go.mod
@ -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-20200306230118-99cbb09fb7b9
|
||||
github.com/insomniacslk/dhcp v0.0.0-20200311205251-eed709df9494
|
||||
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
2
go.sum
@ -49,6 +49,8 @@ github.com/insomniacslk/dhcp v0.0.0-20200210095418-45e5f320b2f0 h1:jzkAy3xl8j58y
|
||||
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/insomniacslk/dhcp v0.0.0-20200311205251-eed709df9494 h1:KDhUkNE73wlQNDk9xW8anpphV9vDiPZNwfgVC5yHmhk=
|
||||
github.com/insomniacslk/dhcp v0.0.0-20200311205251-eed709df9494/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=
|
||||
|
@ -234,12 +234,7 @@ func (c *Client) solicit(solicit *dhcpv6.Message) (*dhcpv6.Message, *dhcpv6.Mess
|
||||
c.transactionIDs = c.transactionIDs[1:]
|
||||
solicit.TransactionID = id
|
||||
}
|
||||
iapd := []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
opt, err := dhcpv6.ParseOptIAForPrefixDelegation(iapd)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
solicit.AddOption(opt)
|
||||
solicit.AddOption(&dhcpv6.OptIAPD{IaId: [4]byte{0, 0, 0, 1}})
|
||||
advertise, err := c.sendReceive(solicit, dhcpv6.MessageTypeNone)
|
||||
return solicit, advertise, err
|
||||
}
|
||||
@ -249,7 +244,7 @@ func (c *Client) request(advertise *dhcpv6.Message) (*dhcpv6.Message, *dhcpv6.Me
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if iapd := advertise.GetOneOption(dhcpv6.OptionIAPD); iapd != nil {
|
||||
if iapd := advertise.Options.OneIAPD(); iapd != nil {
|
||||
request.AddOption(iapd)
|
||||
}
|
||||
|
||||
@ -277,17 +272,13 @@ func (c *Client) ObtainOrRenew() bool {
|
||||
return true
|
||||
}
|
||||
var newCfg Config
|
||||
for _, o := range reply.Options.IAPD() {
|
||||
t1 := c.timeNow().Add(o.T1)
|
||||
for _, iapd := range reply.Options.IAPD() {
|
||||
t1 := c.timeNow().Add(iapd.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 _, prefix := range iapd.Options.Prefixes() {
|
||||
newCfg.Prefixes = append(newCfg.Prefixes, *prefix.Prefix)
|
||||
}
|
||||
}
|
||||
for _, dns := range reply.Options.DNS() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user