Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async start bug(OUI), fix junk records(failover dhcp cluster) #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ let dhcp_log_watcher = require('./core/dhcp-log-watcher');
let app_timers = require('./core/app-timers');

/**
* Run routines
* Run routines in seq order
*/
oui_reader.initOuiDatabase();
dhcp_leases.parseLeasesFileOnce(glass_config);
dhcp_leases.startLeaseListener(glass_config);
dhcp_leases.setLeasesCleanTimer();
glass_config_watcher.init();
dhcp_log_watcher.init(glass_config);
(async () => {
await oui_reader.initOuiDatabase();
dhcp_leases.parseLeasesFileOnce(glass_config);
dhcp_leases.startLeaseListener(glass_config);
dhcp_leases.setLeasesCleanTimer();
glass_config_watcher.init();
dhcp_log_watcher.init(glass_config);
})();


/**
* Timers
Expand Down
8 changes: 7 additions & 1 deletion core/lease-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ module.exports = {

/* Mac OUI Lookup */
var mac_oui = dhcp_lease_data[ip_address].mac.split(":").join("").toUpperCase().slice(0, 6);

dhcp_lease_data[ip_address].mac_oui_vendor = '';
if (typeof oui_data[mac_oui] !== "undefined") {
dhcp_lease_data[ip_address].mac_oui_vendor = oui_data[mac_oui];
}
}
}
if (/binding/i.test(lines[l])) {
/* Need to ignore binding, when it is not first. Cause "next binding state expired" in Leases. */
if (line_data_arg[0] == "binding" && line_data_arg[2] != "active;") {
delete dhcp_lease_data[ip_address];
break;
}
}
if (/hostname/i.test(lines[l])) {
if (typeof line_data_arg[1] !== "undefined")
dhcp_lease_data[ip_address].host = line_data_arg[1].replace(/;/gi, '').replace(/"/gi, '').trim();
Expand Down
48 changes: 25 additions & 23 deletions core/oui-reader.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var fs = require('fs');

module.exports = {
initOuiDatabase: function () {
var oui_database_file = "bin/oui_table.txt";

if (fs.existsSync(oui_database_file)) {
fs.readFile(oui_database_file, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
else {
lines = data.split("\n");
for (l = 0; l < lines.length; l++) {
/* Trim whitespaces at each ends of the line */
lines[l] = lines[l].trim();
var oui_line_data = lines[l].split(":::");

if (typeof oui_line_data[1] !== "undefined")
oui_data[oui_line_data[0].trim()] = oui_line_data[1].trim();
initOuiDatabase: async function () {
return new Promise((resolve) => {
var oui_database_file = "bin/oui_table.txt";
if (fs.existsSync(oui_database_file)) {
fs.readFile(oui_database_file, 'utf8', function (err, data) {
if (err) {
console.log(err);
}
else {
lines = data.split("\n");
for (l = 0; l < lines.length; l++) {
/* Trim whitespaces at each ends of the line */
lines[l] = lines[l].trim();
var oui_line_data = lines[l].split(":::");

if (typeof oui_line_data[1] !== "undefined")
oui_data[oui_line_data[0].trim()] = oui_line_data[1].trim();
}
console.log("[Glass Server] OUI Database Loaded");
resolve()
}
console.log("[Glass Server] OUI Database Loaded");
}
});
}
},
};
});
}
})
}
}