addr_linux: Implement CacheInfo installation

Currently, Validity and preference information values are ignored in
addrHandle. This adds them to the netlink message when they are passed
by the caller
This commit is contained in:
Anatole Denis 2018-01-17 12:36:09 +00:00 committed by Alessandro Boch
parent 422ffe659e
commit 7291c36428
1 changed files with 11 additions and 0 deletions

View File

@ -118,6 +118,17 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
}
}
// 0 is the default value for these attributes. However, 0 means "expired", while the least-surprising default
// value should be "forever". To compensate for that, only add the attributes if at least one of the values is
// non-zero, which means the caller has explicitly set them
if addr.ValidLft > 0 || addr.PreferedLft > 0 {
cachedata := nl.IfaCacheInfo{
IfaValid: uint32(addr.ValidLft),
IfaPrefered: uint32(addr.PreferedLft),
}
req.AddData(nl.NewRtAttr(unix.IFA_CACHEINFO, cachedata.Serialize()))
}
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}