getting there...

This commit is contained in:
Adam Ierymenko 2019-09-21 18:22:25 -07:00
parent 5e35346f17
commit 2eef9d22e6
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
11 changed files with 278 additions and 45 deletions

View file

@ -116,3 +116,36 @@ func (n *Network) Tap() Tap {
defer n.tapLock.RUnlock()
return n.tap
}
func (n *Network) handleNetworkConfigUpdate(nc *NetworkConfig) {
n.tapLock.RLock()
n.configLock.Lock()
defer n.configLock.Unlock()
defer n.tapLock.RUnlock()
if n.tap == nil { // sanity check
return
}
// Add IPs to tap that are newly assigned in this config update,
// and remove any IPs from the tap that were assigned that are no
// longer wanted. IPs assigned to the tap externally (e.g. by an
// "ifconfig" command) are left alone.
haveAssignedIPs := make(map[[3]uint64]*net.IPNet)
for _, ip := range n.config.AssignedAddresses {
haveAssignedIPs[ipNetToKey(&ip)] = &ip
}
wantAssignedIPs := make(map[[3]uint64]bool)
for _, ip := range nc.AssignedAddresses {
k := ipNetToKey(&ip)
wantAssignedIPs[k] = true
if _, have := haveAssignedIPs[k]; !have {
n.tap.AddIP(&ip)
}
}
for k, ip := range haveAssignedIPs {
if _, want := wantAssignedIPs[k]; !want {
n.tap.RemoveIP(ip)
}
}
}