Skip to content

Commit

Permalink
MFW-2307 Ignore device updates where mac address is a broadcast. (#67)
Browse files Browse the repository at this point in the history
* MFW-2307 Ignore device updates where mac address is a broadcast.
  • Loading branch information
rasmussen-untangle authored Oct 4, 2022
1 parent 4b535d0 commit d42a52f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 35 additions & 1 deletion services/discovery/devices_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func (suite *DeviceListTestSuite) TestMerge() {
}
wg.Wait()
suite.Equal(count, uint32(len(deviceTests)))

}

// Here we make sure the merge logic is tested by deleting some fields
Expand All @@ -212,6 +211,41 @@ func (suite *DeviceListTestSuite) createEmptyFieldsForMerge(oldDevice *DeviceEnt
}
}

// TestBroadcastInsertion tests that we do not add in a broadcast entry.
func (suite *DeviceListTestSuite) TestBroadcastInsertion() {

var deviceList DevicesList
var count uint32
deviceList.Devices = map[string]*DeviceEntry{}

for _, entry := range suite.devicesTable.Devices {
deviceList.Devices[entry.MacAddress] = &DeviceEntry{
DiscoveryEntry: disco.DiscoveryEntry{
IPv4Address: entry.IPv4Address,
MacAddress: entry.MacAddress,
LastUpdate: entry.LastUpdate,
},
}
count++
}

newBroadcastDiscovery := DeviceEntry{
DiscoveryEntry: disco.DiscoveryEntry{
MacAddress: "00:00:00:00:00:00",
LastUpdate: suite.halfHourAgo.Unix(),
IPv4Address: "192.168.56.4",
},
}

deviceList.MergeOrAddDeviceEntry(&newBroadcastDiscovery,
func() {
})

// Asssert that broadcast entry was not added.
suite.EqualValues(count, len(deviceList.Devices), "Adding broadcast discovery entry.")
suite.Equal(suite.devicesTable.Devices, deviceList.Devices, "Adding broadcast discovery entry.")
}

// TestMarshallingList tests that we can marshal a list of devices
// obtained via the ApplyToDeviceList function to JSON without getting
// an exception.
Expand Down
3 changes: 3 additions & 0 deletions services/discovery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (list *DevicesList) GetDeviceEntryFromIP(ip string) *disco.DiscoveryEntry {
// called after everything is merged but before the lock is
// released. This can allow you to clone/copy the merged device.
func (list *DevicesList) MergeOrAddDeviceEntry(entry *DeviceEntry, callback func()) {
if entry.MacAddress == "00:00:00:00:00:00" {
return
}
list.Lock.Lock()
defer list.Lock.Unlock()
if entry.MacAddress == "" && entry.IPv4Address != "" {
Expand Down

0 comments on commit d42a52f

Please sign in to comment.