Skip to content

Commit

Permalink
Proposed rename from "ana" to "adapter"
Browse files Browse the repository at this point in the history
Signed-off-by: eriknordmark <[email protected]>
  • Loading branch information
eriknordmark committed Oct 24, 2023
1 parent 0eac569 commit f2ccce8
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 123 deletions.
88 changes: 44 additions & 44 deletions pkg/pillar/cmd/zedrouter/appnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,31 @@ func (z *zedrouter) updateVIFsForStateCollecting(
func (z *zedrouter) prepareConfigForVIFs(config types.AppNetworkConfig,
status *types.AppNetworkStatus) (vifs []nireconciler.AppVIF, err error) {
for i := range status.AppNetAdapterList {
anaNum := i + 1
anaStatus := &status.AppNetAdapterList[i]
netInstStatus := z.lookupNetworkInstanceStatus(anaStatus.Network.String())
adapterNum := i + 1
adapterStatus := &status.AppNetAdapterList[i]
netInstStatus := z.lookupNetworkInstanceStatus(adapterStatus.Network.String())
if netInstStatus == nil {
// Should be unreachable.
err := fmt.Errorf("missing network instance status for %s",
anaStatus.Network.String())
adapterStatus.Network.String())
z.log.Errorf("doActivateAppNetwork(%v/%v): %v",
config.UUIDandVersion.UUID, config.DisplayName, err)
z.addAppNetworkError(status, "doActivateAppNetwork", err)
return nil, err
}
anaStatus.Bridge = netInstStatus.BridgeName
anaStatus.BridgeMac = netInstStatus.BridgeMac
anaStatus.BridgeIPAddr = netInstStatus.BridgeIPAddr
if anaStatus.AppMacAddr != nil {
adapterStatus.Bridge = netInstStatus.BridgeName
adapterStatus.BridgeMac = netInstStatus.BridgeMac
adapterStatus.BridgeIPAddr = netInstStatus.BridgeIPAddr
if adapterStatus.AppMacAddr != nil {
// User-configured static MAC address.
anaStatus.Mac = anaStatus.AppMacAddr
adapterStatus.Mac = adapterStatus.AppMacAddr
} else {
anaStatus.Mac = z.generateAppMac(config.UUIDandVersion.UUID, anaNum,
adapterStatus.Mac = z.generateAppMac(config.UUIDandVersion.UUID, adapterNum,
status.AppNum, netInstStatus)
}
anaStatus.HostName = config.Key()
adapterStatus.HostName = config.Key()
guestIP, err := z.lookupOrAllocateIPv4ForVIF(
netInstStatus, *anaStatus, status.UUIDandVersion.UUID)
netInstStatus, *adapterStatus, status.UUIDandVersion.UUID)
if err != nil {
z.log.Errorf("doActivateAppNetwork(%v/%v): %v",
config.UUIDandVersion.UUID, config.DisplayName, err)
Expand All @@ -106,10 +106,10 @@ func (z *zedrouter) prepareConfigForVIFs(config types.AppNetworkConfig,
}
vifs = append(vifs, nireconciler.AppVIF{
App: status.UUIDandVersion.UUID,
NI: anaStatus.Network,
NetAdapterName: anaStatus.Name,
VIFNum: anaNum,
GuestIfMAC: anaStatus.Mac,
NI: adapterStatus.Network,
NetAdapterName: adapterStatus.Name,
VIFNum: adapterNum,
GuestIfMAC: adapterStatus.Mac,
GuestIP: guestIP,
})
}
Expand Down Expand Up @@ -150,51 +150,51 @@ func (z *zedrouter) doActivateAppNetwork(config types.AppNetworkConfig,
}

func (z *zedrouter) updateNIStatusAfterAppNetworkActivate(status *types.AppNetworkStatus) {
for _, anaStatus := range status.AppNetAdapterList {
netInstStatus := z.lookupNetworkInstanceStatus(anaStatus.Network.String())
for _, adapterStatus := range status.AppNetAdapterList {
netInstStatus := z.lookupNetworkInstanceStatus(adapterStatus.Network.String())
if netInstStatus == nil {
err := fmt.Errorf("missing network instance status for %s",
anaStatus.Network.String())
adapterStatus.Network.String())
z.log.Error(err)
continue
}
if netInstStatus.Type == types.NetworkInstanceTypeSwitch {
if anaStatus.AccessVlanID <= 1 {
if adapterStatus.AccessVlanID <= 1 {
netInstStatus.NumTrunkPorts++
} else {
netInstStatus.VlanMap[anaStatus.AccessVlanID]++
netInstStatus.VlanMap[adapterStatus.AccessVlanID]++
}
}
netInstStatus.AddVif(z.log, anaStatus.Vif, anaStatus.Mac,
netInstStatus.AddVif(z.log, adapterStatus.Vif, adapterStatus.Mac,
status.UUIDandVersion.UUID)
netInstStatus.IPAssignments[anaStatus.Mac.String()] =
netInstStatus.IPAssignments[adapterStatus.Mac.String()] =
types.AssignedAddrs{
IPv4Addr: anaStatus.AllocatedIPv4Addr,
IPv6Addrs: anaStatus.AllocatedIPv6List,
IPv4Addr: adapterStatus.AllocatedIPv4Addr,
IPv6Addrs: adapterStatus.AllocatedIPv6List,
}
z.publishNetworkInstanceStatus(netInstStatus)
}
}

func (z *zedrouter) updateNIStatusAfterAppNetworkInactivate(
status *types.AppNetworkStatus) {
for _, anaStatus := range status.AppNetAdapterList {
netInstStatus := z.lookupNetworkInstanceStatus(anaStatus.Network.String())
for _, adapterStatus := range status.AppNetAdapterList {
netInstStatus := z.lookupNetworkInstanceStatus(adapterStatus.Network.String())
if netInstStatus == nil {
err := fmt.Errorf("missing network instance status for %s",
anaStatus.Network.String())
adapterStatus.Network.String())
z.log.Error(err)
continue
}
if netInstStatus.Type == types.NetworkInstanceTypeSwitch {
if anaStatus.AccessVlanID <= 1 {
if adapterStatus.AccessVlanID <= 1 {
netInstStatus.NumTrunkPorts--
} else {
netInstStatus.VlanMap[anaStatus.AccessVlanID]--
netInstStatus.VlanMap[adapterStatus.AccessVlanID]--
}
}
netInstStatus.RemoveVif(z.log, anaStatus.Vif)
delete(netInstStatus.IPAssignments, anaStatus.Mac.String())
netInstStatus.RemoveVif(z.log, adapterStatus.Vif)
delete(netInstStatus.IPAssignments, adapterStatus.Mac.String())
z.publishNetworkInstanceStatus(netInstStatus)
}
}
Expand Down Expand Up @@ -346,18 +346,18 @@ func (z *zedrouter) checkAppNetworkModifyAppIntfNums(config types.AppNetworkConf

// Check if any AppNetAdapter have changes to the Networks they use
for i := range config.AppNetAdapterList {
anaConfig := &config.AppNetAdapterList[i]
anaStatus := &status.AppNetAdapterList[i]
if anaConfig.Network == anaStatus.Network {
adapterConfig := &config.AppNetAdapterList[i]
adapterStatus := &status.AppNetAdapterList[i]
if adapterConfig.Network == adapterStatus.Network {
continue
}
z.log.Functionf(
"checkAppNetworkModifyAppIntfNums(%v) for %s: change from %s to %s",
config.UUIDandVersion, config.DisplayName,
anaStatus.Network, anaConfig.Network)
adapterStatus.Network, adapterConfig.Network)
// update the reference to the network instance
err := z.doAppNetworkModifyAppIntfNum(
status.UUIDandVersion.UUID, anaConfig, anaStatus)
status.UUIDandVersion.UUID, adapterConfig, adapterStatus)
if err != nil {
err = fmt.Errorf("failed to modify appIntfNum: %v", err)
z.log.Errorf(
Expand All @@ -373,13 +373,13 @@ func (z *zedrouter) checkAppNetworkModifyAppIntfNums(config types.AppNetworkConf
// Assumes the caller has checked that such a change is present.
// Release the current appIntfNum and acquire appIntfNum on the new network instance.
func (z *zedrouter) doAppNetworkModifyAppIntfNum(appID uuid.UUID,
anaConfig *types.AppNetAdapterConfig,
anaStatus *types.AppNetAdapterStatus) error {
adapterConfig *types.AppNetAdapterConfig,
adapterStatus *types.AppNetAdapterStatus) error {

newNetworkID := anaConfig.Network
oldNetworkID := anaStatus.Network
newIfIdx := anaConfig.IfIdx
oldIfIdx := anaStatus.IfIdx
newNetworkID := adapterConfig.Network
oldNetworkID := adapterStatus.Network
newIfIdx := adapterConfig.IfIdx
oldIfIdx := adapterStatus.IfIdx

// Try to release the app number on the old network.
err := z.freeAppIntfNum(oldNetworkID, appID, oldIfIdx)
Expand All @@ -389,7 +389,7 @@ func (z *zedrouter) doAppNetworkModifyAppIntfNum(appID uuid.UUID,
}

// Allocate an app number on the new network.
withStaticIP := anaConfig.AppIPAddr != nil
withStaticIP := adapterConfig.AppIPAddr != nil
err = z.allocateAppIntfNum(newNetworkID, appID, newIfIdx, withStaticIP)
if err != nil {
z.log.Error(err)
Expand Down
52 changes: 26 additions & 26 deletions pkg/pillar/cmd/zedrouter/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func (z *zedrouter) generateBridgeMAC(brNum int) net.HardwareAddr {
// Since these MAC addresses will not appear on external Ethernet networks, we can also
// use OUI octets for randomness. Only I/G and U/L bits need to stay constant and set
// appropriately.
func (z *zedrouter) generateAppMac(appUUID uuid.UUID, anaNum int, appNum int,
func (z *zedrouter) generateAppMac(appUUID uuid.UUID, adapterNum int, appNum int,
netInstStatus *types.NetworkInstanceStatus) net.HardwareAddr {
h := sha256.New()
h.Write(appUUID[:])
h.Write(netInstStatus.UUIDandVersion.UUID[:])
nums := make([]byte, 2)
nums[0] = byte(anaNum)
nums[0] = byte(adapterNum)
nums[1] = byte(appNum)
h.Write(nums)
hash := h.Sum(nil)
Expand All @@ -70,7 +70,7 @@ func (z *zedrouter) generateAppMac(appUUID uuid.UUID, anaNum int, appNum int,

// Returns an IPv4 address allocated for the guest side of an application VIF.
func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceStatus,
anaStatus types.AppNetAdapterStatus, appID uuid.UUID) (net.IP, error) {
adapterStatus types.AppNetAdapterStatus, appID uuid.UUID) (net.IP, error) {
var err error
var ipAddr net.IP
networkID := niStatus.UUID
Expand All @@ -80,24 +80,24 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt
networkID, appID)
return nil, nil
}
if anaStatus.Mac == nil {
if adapterStatus.Mac == nil {
z.log.Functionf("lookupOrAllocateIPv4(NI:%v, app:%v): no MAC address",
networkID, appID)
return nil, nil
}

if anaStatus.AppIPAddr != nil {
if adapterStatus.AppIPAddr != nil {
// User-configured static IP address.
ipAddr = anaStatus.AppIPAddr
if niStatus.DhcpRange.Contains(anaStatus.AppIPAddr) {
ipAddr = adapterStatus.AppIPAddr
if niStatus.DhcpRange.Contains(adapterStatus.AppIPAddr) {
err = fmt.Errorf("static IP(%v) is in DhcpRange(%v, %v)",
ipAddr, niStatus.DhcpRange.Start,
niStatus.DhcpRange.End)
z.log.Errorf("lookupOrAllocateIPv4(NI:%v, app:%v): %v",
networkID, appID, err)
return nil, err
}
if !niStatus.Subnet.Contains(anaStatus.AppIPAddr) {
if !niStatus.Subnet.Contains(adapterStatus.AppIPAddr) {
err = fmt.Errorf("static IP(%s) is outside subnet range",
ipAddr)
z.log.Errorf("lookupOrAllocateIPv4(NI:%v, app:%v): %v",
Expand All @@ -108,10 +108,10 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt

// Lookup to see if it is already allocated.
if ipAddr == nil {
addrs := niStatus.IPAssignments[anaStatus.Mac.String()]
addrs := niStatus.IPAssignments[adapterStatus.Mac.String()]
if !isEmptyIP(addrs.IPv4Addr) {
z.log.Functionf("lookupOrAllocateIPv4(NI:%v, app:%v): found IP %v for MAC %v",
networkID, appID, addrs.IPv4Addr, anaStatus.Mac)
networkID, appID, addrs.IPv4Addr, adapterStatus.Mac)
ipAddr = addrs.IPv4Addr
}
}
Expand All @@ -120,7 +120,7 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt
// Allocate IP address dynamically.
// Get the app number for the AppNetAdapter entry.
var appNum int
appNum, err = z.getAppIntfNum(networkID, appID, anaStatus.IfIdx)
appNum, err = z.getAppIntfNum(networkID, appID, adapterStatus.IfIdx)
if err != nil {
err = fmt.Errorf("failed to get app number: %w", err)
z.log.Errorf("lookupOrAllocateIPv4(NI:%v, app:%v): %v",
Expand All @@ -142,7 +142,7 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt
// will then produce a valid IP address fitting the DHCP range.
// Otherwise, zedrouter would just try to use the same IP address outside
// the DHCP range and fail repeatedly, even after there is free IP available.
err2 := z.freeAppIntfNum(networkID, appID, anaStatus.IfIdx)
err2 := z.freeAppIntfNum(networkID, appID, adapterStatus.IfIdx)
if err2 != nil {
// Should be unreachable.
z.log.Error(err2)
Expand All @@ -153,21 +153,21 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt
// Later will be overwritten with addresses received from nistate.Collector,
// which snoops DHCP traffic and watches DNS server leases to learn the *actual*
// IP address assignments.
addrs := niStatus.IPAssignments[anaStatus.Mac.String()] // preserve IPv6 addresses
addrs := niStatus.IPAssignments[adapterStatus.Mac.String()] // preserve IPv6 addresses
addrs.IPv4Addr = ipAddr
niStatus.IPAssignments[anaStatus.Mac.String()] = addrs
niStatus.IPAssignments[adapterStatus.Mac.String()] = addrs
z.publishNetworkInstanceStatus(niStatus)
z.log.Functionf("lookupOrAllocateIPv4(NI:%v, app:%v): allocated IP %v for MAC %v",
networkID, appID, ipAddr, anaStatus.Mac)
networkID, appID, ipAddr, adapterStatus.Mac)
return ipAddr, nil
}

func (z *zedrouter) reloadStatusOfAssignedIPs(status *types.AppNetworkStatus) {
for i := range status.AppNetAdapterList {
anaStatus := &status.AppNetAdapterList[i]
allAddrs, _ := z.niStateCollector.GetIPAssignments(anaStatus.Network)
vifAddrs := allAddrs.LookupByAdapterName(status.UUIDandVersion.UUID, anaStatus.Name)
z.recordAssignedIPsToULStatus(anaStatus, vifAddrs)
adapterStatus := &status.AppNetAdapterList[i]
allAddrs, _ := z.niStateCollector.GetIPAssignments(adapterStatus.Network)
vifAddrs := allAddrs.LookupByAdapterName(status.UUIDandVersion.UUID, adapterStatus.Name)
z.recordAssignedIPsToULStatus(adapterStatus, vifAddrs)
}
}

Expand All @@ -191,16 +191,16 @@ func (z *zedrouter) recordAssignedIPsToULStatus(ul *types.AppNetAdapterStatus,

func (z *zedrouter) removeAssignedIPsFromAppNetStatus(status *types.AppNetworkStatus) {
for i := range status.AppNetAdapterList {
anaStatus := &status.AppNetAdapterList[i]
z.removeAssignedIPsFromULStatus(anaStatus)
adapterStatus := &status.AppNetAdapterList[i]
z.removeAssignedIPsFromULStatus(adapterStatus)
}
}

func (z *zedrouter) removeAssignedIPsFromULStatus(anaStatus *types.AppNetAdapterStatus) {
anaStatus.AllocatedIPv6List = nil
anaStatus.AllocatedIPv4Addr = nil
anaStatus.IPAddrMisMatch = false
anaStatus.IPv4Assigned = false
func (z *zedrouter) removeAssignedIPsFromULStatus(adapterStatus *types.AppNetAdapterStatus) {
adapterStatus.AllocatedIPv6List = nil
adapterStatus.AllocatedIPv4Addr = nil
adapterStatus.IPAddrMisMatch = false
adapterStatus.IPv4Assigned = false
}

func isEmptyIP(ip net.IP) bool {
Expand Down
8 changes: 4 additions & 4 deletions pkg/pillar/cmd/zedrouter/networkinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func (z *zedrouter) getArgsForNIStateCollecting(niID uuid.UUID) (
if appNetConfig == nil || !appNetConfig.Activate {
continue
}
for _, anaStatus := range appNetStatus.GetAdaptersStatusForNI(niID) {
for _, adapterStatus := range appNetStatus.GetAdaptersStatusForNI(niID) {
vifs = append(vifs, nistate.AppVIF{
App: appNetStatus.UUIDandVersion.UUID,
NI: niID,
AppNum: appNetStatus.AppNum,
NetAdapterName: anaStatus.Name,
HostIfName: anaStatus.Vif,
GuestIfMAC: anaStatus.Mac,
NetAdapterName: adapterStatus.Name,
HostIfName: adapterStatus.Vif,
GuestIfMAC: adapterStatus.Mac,
})
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/pillar/cmd/zedrouter/numallocators.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func (z *zedrouter) delAppIntfAllocator(netInstID uuid.UUID) error {
// Allocate numbers for all interfaces of a given app.
func (z *zedrouter) allocateAppIntfNums(appID uuid.UUID,
unets []types.AppNetAdapterConfig) error {
for _, anaConfig := range unets {
netInstID := anaConfig.Network
ifIdx := anaConfig.IfIdx
withStaticIP := anaConfig.AppIPAddr != nil
for _, adapterConfig := range unets {
netInstID := adapterConfig.Network
ifIdx := adapterConfig.IfIdx
withStaticIP := adapterConfig.AppIPAddr != nil
err := z.allocateAppIntfNum(netInstID, appID, ifIdx, withStaticIP)
if err != nil {
return err
Expand Down Expand Up @@ -207,9 +207,9 @@ func (z *zedrouter) getAppIntfNum(netInstID uuid.UUID, appID uuid.UUID,
// Free numbers allocated for interfaces of a given app.
func (z *zedrouter) freeAppIntfNums(status *types.AppNetworkStatus) {
appID := status.UUIDandVersion.UUID
for _, anaStatus := range status.AppNetAdapterList {
netInstID := anaStatus.Network
ifIdx := anaStatus.IfIdx
for _, adapterStatus := range status.AppNetAdapterList {
netInstID := adapterStatus.Network
ifIdx := adapterStatus.IfIdx
err := z.freeAppIntfNum(netInstID, appID, ifIdx)
if err != nil {
// Just log error and continue. Try to free as many numbers as possible.
Expand Down
4 changes: 2 additions & 2 deletions pkg/pillar/cmd/zedrouter/pubsubhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ func (z *zedrouter) handleAppNetworkDelete(ctxArg interface{}, key string,

// Did this free up any last references against any deleted Network Instance?
for i := range status.AppNetAdapterList {
anaStatus := &status.AppNetAdapterList[i]
netstatus := z.lookupNetworkInstanceStatus(anaStatus.Network.String())
adapterStatus := &status.AppNetAdapterList[i]
netstatus := z.lookupNetworkInstanceStatus(adapterStatus.Network.String())
if netstatus != nil {
if z.maybeDelOrInactivateNetworkInstance(netstatus) {
z.log.Functionf(
Expand Down
Loading

0 comments on commit f2ccce8

Please sign in to comment.