Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit e47501a

Browse files
committed
add intf uuid to sensor message
1 parent 3f2e566 commit e47501a

File tree

5 files changed

+53
-50
lines changed

5 files changed

+53
-50
lines changed

extension/dhcpdump/dhcpdump.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ module.exports = class {
164164

165165
this.parseEvents(message).map(e => {
166166
if (e) {
167-
e.intf_mac = intf.mac_address
167+
e.intf_mac = intf.mac_address;
168+
e.intf_uuid = intf.uuid;
168169
}
169170
callback(e)
170171
})

sensor/DHCPSensor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class DHCPSensor extends Sensor {
5151
type: "NewDeviceWithMacOnly",
5252
mac: obj.mac,
5353
intf_mac: obj.intf_mac,
54+
intf_uuid: obj.intf_uuid,
5455
name: obj.name,
5556
mtype: obj.mtype,
5657
from: 'dhcp',
@@ -67,7 +68,7 @@ class DHCPSensor extends Sensor {
6768
this.dhcpDump.install((obj) => {
6869
log.info("DHCPDUMP is installed");
6970
this.scheduleReload();
70-
71+
7172
sclient.on("message", (channel, message) => {
7273
if (channel === Message.MSG_SYS_NETWORK_INFO_RELOADED) {
7374
log.info("Schedule reload DHCPSensor since network info is reloaded");

sensor/ICMP6Sensor.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ICMP6Sensor extends Sensor {
4141
const pid = this.intfPidMap[intf];
4242
const childPid = await execAsync(`ps -ef| awk '$3 == '${pid}' { print $2 }'`).then(result => result.stdout.trim()).catch(() => null);
4343
if (childPid)
44-
await execAsync(`sudo kill -9 ${childPid}`).catch((err) => {});
44+
await execAsync(`sudo kill -9 ${childPid}`).catch((err) => { });
4545
}
4646
this.intfPidMap = {};
4747
const interfaces = sysManager.getMonitoringInterfaces();
@@ -59,7 +59,7 @@ class ICMP6Sensor extends Sensor {
5959
input: tcpdumpSpawn.stdout
6060
});
6161
reader.on('line', (line) => {
62-
this.processNeighborAdvertisement(line, intf.mac_address);
62+
this.processNeighborAdvertisement(line, intf);
6363
});
6464
tcpdumpSpawn.on('close', (code) => {
6565
log.info("TCPDump icmp6 exited with code: ", code);
@@ -88,7 +88,7 @@ class ICMP6Sensor extends Sensor {
8888
sclient.subscribe(Message.MSG_SYS_NETWORK_INFO_RELOADED);
8989
}
9090

91-
processNeighborAdvertisement(line, intf_mac) {
91+
processNeighborAdvertisement(line, intf) {
9292
// Each line of neighbor advertisement is like:
9393
// 03:06:30.894621 00:0c:29:96:3c:30 > 02:01:f4:16:26:dc, ethertype IPv6 (0x86dd), length 78: 2601:646:8800:eb7:dc04:b1fa:d0c2:6cbb > fe80::1:f4ff:fe16:26dc: ICMP6, neighbor advertisement, tgt is 2601:646:8800:eb7:dc04:b1fa:d0c2:6cbb, length 24
9494
try {
@@ -109,7 +109,8 @@ class ICMP6Sensor extends Sensor {
109109
host: {
110110
ipv6Addr: [tgtIp],
111111
mac: dstMac.toUpperCase(),
112-
intf_mac: intf_mac
112+
intf_mac: intf.mac_address,
113+
intf_uuid: intf.uuid
113114
}
114115
});
115116
}

sensor/IPv6DiscoverySensor.js

+39-40
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,9 @@ class IPv6DiscoverySensor extends Sensor {
5050
}
5151

5252
async checkAndRunOnce() {
53-
log.info("Starting IPv6DiscoverySensor Scanning", new Date() / 1000);
5453
if (this.isSensorEnabled()) {
55-
const results = sysManager.getMonitoringInterfaces();
56-
if (results) {
57-
for (let i in results) {
58-
let intf = results[i];
59-
await this.neighborDiscoveryV6(intf.name, intf);
60-
}
61-
}
54+
log.info("Starting IPv6DiscoverySensor Scanning", new Date() / 1000);
55+
await this.neighborDiscoveryV6();
6256
}
6357
}
6458

@@ -76,59 +70,64 @@ class IPv6DiscoverySensor extends Sensor {
7670
}
7771

7872

79-
addV6Host(v6addrs, mac, intf_mac) {
73+
addV6Host(v6addrs, mac, intf) {
8074
sem.emitEvent({
8175
type: "DeviceUpdate",
8276
message: `A new ipv6 is found @ IPv6DisocverySensor ${v6addrs} ${mac}`,
8377
suppressAlarm: true,
8478
host: {
8579
ipv6Addr: v6addrs,
8680
mac: mac.toUpperCase(),
87-
intf_mac: intf_mac,
81+
intf_mac: intf.mac_address,
82+
intf_uuid: intf.uuid,
8883
from: "ip6neighbor"
8984
}
9085
});
9186
}
9287

93-
async neighborDiscoveryV6(intf, obj) {
94-
if (obj.ip6_addresses == null || obj.ip6_addresses.length <= 1) {
95-
log.info("Discovery:v6Neighbor:NoV6", intf, JSON.stringify(obj));
96-
return;
88+
async neighborDiscoveryV6() {
89+
const interfaces = sysManager.getMonitoringInterfaces();
90+
for (const intf of interfaces) {
91+
if (intf.ip6_addresses == null || intf.ip6_addresses.length <= 1) {
92+
log.info("Discovery:v6Neighbor:NoV6", intf.name, JSON.stringify(intf));
93+
continue;
94+
}
95+
await this.ping6ForDiscovery(intf.name, intf);
9796
}
98-
await this.ping6ForDiscovery(intf, obj)
9997
let cmdline = 'ip -6 neighbor show';
10098
log.info("Running commandline: ", cmdline);
101-
10299
const { stdout } = await execAsync(cmdline)
103100
let lines = stdout.split("\n");
104-
let macHostMap = {};
105-
for (const o of lines) {
106-
log.debug("Discover:v6Neighbor:Scan:Line", o, "of interface", intf);
107-
let parts = o.split(" ");
108-
if (parts[2] == intf) {
109-
let v6addr = parts[0];
110-
let mac = parts[4].toUpperCase();
111-
if (mac == "FAILED" || mac.length < 16) {
112-
continue
113-
} else {
114-
/*
115-
hostTool.linkMacWithIPv6(v6addr, mac,(err)=>{
116-
cb();
117-
});
118-
*/
119-
let _host = macHostMap[mac];
120-
if (_host) {
121-
_host.push(v6addr);
101+
for (const intf of interfaces) {
102+
let macHostMap = {};
103+
for (const o of lines) {
104+
log.debug("Discover:v6Neighbor:Scan:Line", o, "of interface", intf.name);
105+
let parts = o.split(" ");
106+
if (parts[2] == intf.name) {
107+
let v6addr = parts[0];
108+
let mac = parts[4].toUpperCase();
109+
if (mac == "FAILED" || mac.length < 16) {
110+
continue
122111
} else {
123-
_host = [v6addr];
124-
macHostMap[mac] = _host;
112+
/*
113+
hostTool.linkMacWithIPv6(v6addr, mac,(err)=>{
114+
cb();
115+
});
116+
*/
117+
let _host = macHostMap[mac];
118+
if (_host) {
119+
_host.push(v6addr);
120+
} else {
121+
_host = [v6addr];
122+
macHostMap[mac] = _host;
123+
}
124+
continue
125125
}
126-
continue
127126
}
128127
}
129-
}
130-
for (let mac in macHostMap) {
131-
this.addV6Host(macHostMap[mac], mac, obj.mac_address)
128+
for (let mac in macHostMap) {
129+
this.addV6Host(macHostMap[mac], mac, intf);
130+
}
132131
}
133132

134133
// FIXME

sensor/NmapSensor.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class NmapSensor extends Sensor {
169169

170170
getNetworkRanges() {
171171
return this.interfaces && this.interfaces.filter(i => i.name && !i.name.includes("vpn")).map((x) => { // do not scan vpn interface
172-
return { range: networkTool.capSubnet(x.subnet), intf_mac: x.mac_address }
172+
return { range: networkTool.capSubnet(x.subnet), intf_mac: x.mac_address, intf_uuid: x.uuid }
173173
})
174174
}
175175

@@ -211,7 +211,7 @@ class NmapSensor extends Sensor {
211211
if (!networkRanges)
212212
return Promise.reject(new Error("network range is required"));
213213

214-
return Promise.all(networkRanges.map(({ range, intf_mac }) => {
214+
return Promise.all(networkRanges.map(({ range, intf_mac, intf_uuid }) => {
215215

216216
log.info("Scanning network", range, "to detect new devices...");
217217

@@ -236,7 +236,7 @@ class NmapSensor extends Sensor {
236236
}
237237
hosts.forEach((h) => {
238238
log.debug("Found device:", h.ipv4Addr);
239-
this._processHost(h, intf_mac);
239+
this._processHost(h, intf_mac, intf_uuid);
240240
})
241241

242242
}).catch((err) => {
@@ -260,7 +260,7 @@ class NmapSensor extends Sensor {
260260
});
261261
}
262262

263-
_processHost(host, intf_mac) {
263+
_processHost(host, intf_mac, intf_uuid) {
264264
if (!host.mac) {
265265
for (const intf of this.interfaces) {
266266
const intfName = intf.name;
@@ -287,6 +287,7 @@ class NmapSensor extends Sensor {
287287
mac: host.mac,
288288
macVendor: host.macVendor,
289289
intf_mac: intf_mac,
290+
intf_uuid: intf_uuid,
290291
from: "nmap"
291292
};
292293

0 commit comments

Comments
 (0)