From ddfc1044259d23bd86700ab682097e4ad49843ba Mon Sep 17 00:00:00 2001 From: Adam Briles Date: Wed, 9 Nov 2022 14:33:00 -0700 Subject: [PATCH 1/3] check lldp and nmap for more Ips and updated merge test --- services/discovery/devices_list_test.go | 83 +++++++++++++++++++++---- services/discovery/types.go | 16 ++++- 2 files changed, 87 insertions(+), 12 deletions(-) diff --git a/services/discovery/devices_list_test.go b/services/discovery/devices_list_test.go index a66651a1..694cb849 100644 --- a/services/discovery/devices_list_test.go +++ b/services/discovery/devices_list_test.go @@ -54,7 +54,7 @@ func (suite *DeviceListTestSuite) SetupTest() { suite.mac2: {DiscoveryEntry: disco.DiscoveryEntry{ MacAddress: suite.mac2, LastUpdate: suite.halfHourAgo.Unix(), - Nmap: []*disco.NMAP{{Hostname: "TestHostname0"}, {Hostname: "TestHostname1"}}, + Nmap: []*disco.NMAP{{Hostname: "TestHostname0"}, {Hostname: "TestHostname1", Ip: "ff90::a00:37ff:feb8:e927"}}, }}, suite.mac3: {DiscoveryEntry: disco.DiscoveryEntry{ MacAddress: suite.mac3, @@ -64,7 +64,7 @@ func (suite *DeviceListTestSuite) SetupTest() { suite.mac4: {DiscoveryEntry: disco.DiscoveryEntry{ MacAddress: suite.mac4, LastUpdate: suite.aDayago.Unix(), - Lldp: []*disco.LLDP{{SysName: "Sysname0"}, {SysName: "Sysname1"}}, + Lldp: []*disco.LLDP{{SysName: "Sysname0"}, {SysName: "Sysname1", Ip: "ee80::a00:37ff:feb0:e927"}}, }}, suite.mac5: {DiscoveryEntry: disco.DiscoveryEntry{ MacAddress: suite.mac5, @@ -81,21 +81,82 @@ func (suite *DeviceListTestSuite) SetupTest() { // Test if MergeOrAddDeviceEntry can merge a DeviceEntry with just an IP address // if a DeviceEntry is already present in the DeviceList with a matching IP and a MAC Address func (suite *DeviceListTestSuite) TestMergeByIp() { - expectedSysName := "testIfThisFieldPresent" + // Try to merge in a new LLDP entry containing an expected field to check for + // If expectedLldpSysname isn't present in a Device Entry, then it wasn't merged + // properly + type expected struct { + mergeIp string + expectedLldpSysName string + } + macToExpected := make(map[string]*expected) + + // Merge new Device Entries + macToExpected[suite.mac2] = &expected{mergeIp: suite.devicesTable[suite.mac2].Nmap[1].Ip, expectedLldpSysName: "Ipv6MergeNmap"} + macToExpected[suite.mac3] = &expected{mergeIp: suite.devicesTable[suite.mac3].Neigh[0].Ip, expectedLldpSysName: "Ipv4Merge"} + macToExpected[suite.mac4] = &expected{mergeIp: suite.devicesTable[suite.mac4].Lldp[1].Ip, expectedLldpSysName: "Ipv6MergeLldp"} + + suite.deviceList.MergeOrAddDeviceEntry(&DeviceEntry{DiscoveryEntry: disco.DiscoveryEntry{ + Neigh: []*disco.NEIGH{{Ip: macToExpected[suite.mac3].mergeIp}}, + Lldp: []*disco.LLDP{{SysName: macToExpected[suite.mac3].expectedLldpSysName}}, + }}, func() {}) suite.deviceList.MergeOrAddDeviceEntry(&DeviceEntry{DiscoveryEntry: disco.DiscoveryEntry{ - Neigh: []*disco.NEIGH{{Ip: suite.devicesTable[suite.mac3].Neigh[0].Ip}}, - Lldp: []*disco.LLDP{{SysName: expectedSysName}}, + Lldp: []*disco.LLDP{{SysName: macToExpected[suite.mac2].expectedLldpSysName, Ip: macToExpected[suite.mac2].mergeIp}}, }}, func() {}) - dev := suite.deviceList.listDevices(func(d *DeviceEntry) bool { - if len(d.Lldp) > 0 && d.Lldp[0].SysName == expectedSysName { - return true + suite.deviceList.MergeOrAddDeviceEntry(&DeviceEntry{DiscoveryEntry: disco.DiscoveryEntry{ + Lldp: []*disco.LLDP{{SysName: macToExpected[suite.mac4].expectedLldpSysName}}, + Nmap: []*disco.NMAP{{Ip: macToExpected[suite.mac4].mergeIp}}, + }}, func() {}) + + // Retrieve the updated device entries + ipv4DevEntry := suite.deviceList.GetDeviceEntryFromIP(macToExpected[suite.mac3].mergeIp) + ipv6NmapDevEntry := suite.deviceList.GetDeviceEntryFromIP(macToExpected[suite.mac2].mergeIp) + ipv6LldpDevEntry := suite.deviceList.GetDeviceEntryFromIP(macToExpected[suite.mac4].mergeIp) + + // Get all the lldp entries to use a contains assertion later with the expected SysName + ipv4SysNames := getLldpSysNameList(ipv4DevEntry.Lldp) + ipv6LldpSysNames := getLldpSysNameList(ipv6LldpDevEntry.Lldp) + ipv6NmapSysNames := getLldpSysNameList(ipv6NmapDevEntry.Lldp) + + suite.Contains(ipv4SysNames, macToExpected[suite.mac3].expectedLldpSysName) + suite.Contains(ipv6LldpSysNames, macToExpected[suite.mac4].expectedLldpSysName) + suite.Contains(ipv6NmapSysNames, macToExpected[suite.mac2].expectedLldpSysName) + + suite.Equal(1, + getAppearanceCount(macToExpected[suite.mac3].expectedLldpSysName, ipv4SysNames), + "Mismatch in the occurrence of an expected LLDP SysName after a merge") + + suite.Equal(1, + getAppearanceCount(macToExpected[suite.mac4].expectedLldpSysName, ipv6LldpSysNames), + "Mismatch in the occurrence of an expected LLDP SysName after a merge") + + suite.Equal(1, + getAppearanceCount(macToExpected[suite.mac2].expectedLldpSysName, ipv6NmapSysNames), + "Mismatch in the occurrence of an expected LLDP SysName after a merge") + +} + +// Counts the number of times a given string appears in a list. +// Used to check that duplicates don't happen during a merge +func getAppearanceCount(match string, list []string) int { + count := 0 + for _, element := range list { + if element == match { + count += 1 } - return false - }) + } + return count +} + +// Gets a list of lldp sysnames for a device +func getLldpSysNameList(lldpEntries []*disco.LLDP) []string { + var sysNames []string + for _, lldp := range lldpEntries { + sysNames = append(sysNames, lldp.SysName) + } - suite.True(len(dev) > 0) + return sysNames } // TestListing tests that applying various predicates to the list diff --git a/services/discovery/types.go b/services/discovery/types.go index 3491c3cb..c65fa285 100644 --- a/services/discovery/types.go +++ b/services/discovery/types.go @@ -201,7 +201,8 @@ func (n *DeviceEntry) Init() { } // Returns the list of IPs being used by a device. Does not acquire any locks -// before accessing device list elements +// before accessing device list elements. The IPs are fetched by going through +// each collector entry and adding any IPs found to a set func (n *DeviceEntry) getDeviceIpsUnsafe() []string { // Use a set to easily get the list of unique IPs assigned to a device ipSet := make(map[string]string) @@ -212,6 +213,19 @@ func (n *DeviceEntry) getDeviceIpsUnsafe() []string { } } + for _, lldpEntry := range n.Lldp { + if lldpEntry.Ip != "" { + ipSet[lldpEntry.Ip] = "" + } + } + + for _, nmapEntry := range n.Nmap { + if nmapEntry.Ip != "" { + ipSet[nmapEntry.Ip] = "" + } + + } + var ipList []string for ip := range ipSet { ipList = append(ipList, ip) From da08a39d430f6051f4272d8997a67f14700b4397 Mon Sep 17 00:00:00 2001 From: Adam Briles Date: Wed, 9 Nov 2022 14:56:22 -0700 Subject: [PATCH 2/3] added tests to make sure ipv6 doesn't cause any issues --- services/discovery/devices_list_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/services/discovery/devices_list_test.go b/services/discovery/devices_list_test.go index 694cb849..b87fd73b 100644 --- a/services/discovery/devices_list_test.go +++ b/services/discovery/devices_list_test.go @@ -119,10 +119,6 @@ func (suite *DeviceListTestSuite) TestMergeByIp() { ipv6LldpSysNames := getLldpSysNameList(ipv6LldpDevEntry.Lldp) ipv6NmapSysNames := getLldpSysNameList(ipv6NmapDevEntry.Lldp) - suite.Contains(ipv4SysNames, macToExpected[suite.mac3].expectedLldpSysName) - suite.Contains(ipv6LldpSysNames, macToExpected[suite.mac4].expectedLldpSysName) - suite.Contains(ipv6NmapSysNames, macToExpected[suite.mac2].expectedLldpSysName) - suite.Equal(1, getAppearanceCount(macToExpected[suite.mac3].expectedLldpSysName, ipv4SysNames), "Mismatch in the occurrence of an expected LLDP SysName after a merge") @@ -363,7 +359,7 @@ func (suite *DeviceListTestSuite) TestCleanDeviceEntry() { } //device_ip_count is six since there are six IPs present in the device entries - device_ip_count = 6 + device_ip_count = 8 //Clean entries which are 48 hours older predicates1 := []ListPredicate{ @@ -381,7 +377,7 @@ func (suite *DeviceListTestSuite) TestCleanDeviceEntry() { deviceList.CleanOldDeviceEntry(predicates2...) //two device entries should be deleted from the device list which entry has LastUpdate with >24 hours suite.EqualValues(device_count-2, len(deviceList.Devices), "Cleaned 24 hours older entry") - suite.EqualValues(device_ip_count-2, len(deviceList.devicesByIP), "Cleaned 24 hours older entry") + suite.EqualValues(device_ip_count-3, len(deviceList.devicesByIP), "Cleaned 24 hours older entry") } @@ -417,6 +413,12 @@ func (suite *DeviceListTestSuite) TestMergeSessions() { ClientBytes: 0, ServerBytes: 10, }, + { + Bytes: 10, + ClientBytes: 0, + ServerBytes: 10, + ClientAddress: suite.devicesTable[suite.mac4].getDeviceIpsUnsafe()[0], + }, } suite.deviceList.MergeSessions(sessions) @@ -424,6 +426,8 @@ func (suite *DeviceListTestSuite) TestMergeSessions() { suite.Equal(len(dev.sessions), 1) suite.Equal(1, len(suite.deviceList.Devices[suite.mac3].sessions)) + + suite.Equal(1, len(suite.deviceList.Devices[suite.mac4].sessions)) } func (suite *DeviceListTestSuite) TestDeviceMarshal() { From 1692f4390b9567d2ddbf4bb60695faea3ae13061 Mon Sep 17 00:00:00 2001 From: Adam Briles Date: Mon, 14 Nov 2022 09:23:25 -0700 Subject: [PATCH 3/3] idiomatic way to use map as set --- go.mod | 3 +- go.sum | 59 +++---------------------- services/discovery/devices_list_test.go | 2 +- services/discovery/types.go | 9 ++-- 4 files changed, 13 insertions(+), 60 deletions(-) diff --git a/go.mod b/go.mod index 303a77af..8b177216 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/untangle/golang-shared go 1.12 require ( + github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/gin-gonic/gin v1.8.1 github.com/golang/protobuf v1.5.2 // indirect github.com/mitchellh/mapstructure v1.5.0 @@ -14,6 +15,4 @@ require ( golang.org/x/net v0.0.0-20220728211354-c7608f3a8462 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect - gopkg.in/go-playground/validator.v9 v9.29.1 // indirect ) diff --git a/go.sum b/go.sum index 99c505e0..3825dc76 100644 --- a/go.sum +++ b/go.sum @@ -1,24 +1,14 @@ -github.com/GehirnInc/crypt v0.0.0-20190301055215-6c0105aabd46/go.mod h1:kC29dT1vFpj7py2OvG1khBdQpo3kInWP+6QipLbdngo= -github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw= -github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= -github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1/go.mod h1:dkChI7Tbtx7H1Tj7TqGSZMOeGpMP5gLHtjroHd4agiI= -github.com/c9s/goprocinfo v0.0.0-20190309065803-0b2ad9ac246b/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gin-contrib/location v0.0.0-20190301062650-0462caccbb9c/go.mod h1:Y9jJgyrzeIqCnTAIlB0Hi36xeXH1BukBJLPf0JsTDjo= -github.com/gin-contrib/sessions v0.0.0-20190226023029-1532893d996f/go.mod h1:8Xd9k6zfW7ekJjy3wJrgbgB2KWvP+GWywe6PanyMVwI= -github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= -github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= +github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= +github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg= -github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= -github.com/gin-gonic/gin v1.3.1-0.20190321071206-1d462bbe3713/go.mod h1:/W62MbsSEZVEVf10SqiWTuY8bNxkrS9F2ntZdV5XV4M= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= -github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= @@ -28,52 +18,35 @@ github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gopacket v1.1.16 h1:u6Afvia5C5srlLcbTwpHaFW918asLYPxieziOaWwz8M= -github.com/google/gopacket v1.1.16/go.mod h1:UCLx9mCmAwsVbn6qQl1WIEt2SO7Nd2fD0th1TBAsqBw= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= -github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= -github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b/go.mod h1:g2nVr8KZVXJSS97Jo8pJ0jgq29P6H7dG0oplUA86MQw= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= -github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/oschwald/geoip2-golang v1.2.1/go.mod h1:0LTTzix/Ao1uMvOhAV4iLU0Lz7eCrP94qZWBTDKf0iE= github.com/oschwald/geoip2-golang v1.8.0 h1:KfjYB8ojCEn/QLqsDU0AzrJ3R5Qa9vFlx3z6SLNcKTs= github.com/oschwald/geoip2-golang v1.8.0/go.mod h1:R7bRvYjOeaoenAp9sKRS8GX5bJWcZ0laWO5+DauEktw= -github.com/oschwald/maxminddb-golang v1.3.0/go.mod h1:3jhIUymTJ5VREKyIhWm66LJiQt04F0UCDdodShpjWsY= github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg= github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0= github.com/pebbe/zmq4 v1.2.9 h1:JlHcdgq6zpppNR1tH0wXJq0XK03pRUc4lBlHTD7aj/4= @@ -83,15 +56,14 @@ github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZO github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/quasoft/memstore v0.0.0-20180925164028-84a050167438/go.mod h1:wTPjTepVu7uJBYgZ0SdWHQlIas582j6cn2jgk4DDdlg= github.com/r3labs/diff/v2 v2.15.1 h1:EOrVqPUzi+njlumoqJwiS/TgGgmZo83619FNDB9xQUg= github.com/r3labs/diff/v2 v2.15.1/go.mod h1:I8noH9Fc2fjSaMxqF3G2lhDdC0b+JXCfyx85tWFM9kc= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -100,15 +72,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.3/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= -github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/untangle/packetd v0.1.2 h1:l2Ta70U1gsWaysyChuMdtUcw2IDyPil5I66+n4H1y2U= -github.com/untangle/packetd v0.1.2/go.mod h1:awjwmKwEgZQpkKajw2tJRDNkO9WwTON4B+tL1zlemTc= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= go.uber.org/dig v1.15.0 h1:vq3YWr8zRj1eFGC7Gvf907hE0eRjPTZ1d3xHadD6liE= @@ -116,19 +83,11 @@ go.uber.org/dig v1.15.0/go.mod h1:pKHs0wMynzL6brANhB2hLMro+zalv1osARTviTcqHLM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220728211354-c7608f3a8462 h1:UreQrH7DbFXSi9ZFox6FNT3WBooWmdANpU+IfkT1T4I= golang.org/x/net v0.0.0-20220728211354-c7608f3a8462/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -150,20 +109,16 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= -gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/services/discovery/devices_list_test.go b/services/discovery/devices_list_test.go index b87fd73b..5d851190 100644 --- a/services/discovery/devices_list_test.go +++ b/services/discovery/devices_list_test.go @@ -358,7 +358,7 @@ func (suite *DeviceListTestSuite) TestCleanDeviceEntry() { } - //device_ip_count is six since there are six IPs present in the device entries + //device_ip_count is eight since there are eight IPs present in the device entries device_ip_count = 8 //Clean entries which are 48 hours older diff --git a/services/discovery/types.go b/services/discovery/types.go index c65fa285..50467ca8 100644 --- a/services/discovery/types.go +++ b/services/discovery/types.go @@ -65,7 +65,6 @@ func (list *DevicesList) PutDevice(entry *DeviceEntry) { list.Lock.Lock() defer list.Lock.Unlock() list.putDeviceUnsafe(entry) - } // Get 24hours older device discovery entry from device list and delete the entry from device list @@ -205,23 +204,23 @@ func (n *DeviceEntry) Init() { // each collector entry and adding any IPs found to a set func (n *DeviceEntry) getDeviceIpsUnsafe() []string { // Use a set to easily get the list of unique IPs assigned to a device - ipSet := make(map[string]string) + ipSet := make(map[string]struct{}) for _, neighEntry := range n.Neigh { if neighEntry.Ip != "" { - ipSet[neighEntry.Ip] = "" + ipSet[neighEntry.Ip] = struct{}{} } } for _, lldpEntry := range n.Lldp { if lldpEntry.Ip != "" { - ipSet[lldpEntry.Ip] = "" + ipSet[lldpEntry.Ip] = struct{}{} } } for _, nmapEntry := range n.Nmap { if nmapEntry.Ip != "" { - ipSet[nmapEntry.Ip] = "" + ipSet[nmapEntry.Ip] = struct{}{} } }