Skip to content

Commit

Permalink
Update Single Line Output
Browse files Browse the repository at this point in the history
Added counters for in, out, accepted and rejected.
Now placed in output.
  • Loading branch information
Dustyn Blackmore committed Apr 13, 2018
1 parent bdf6782 commit 9aa54e6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const PC_UDP = 17;
const buffer = 131070;

let packetsAccepted = 0;
let packetsAcceptedIn = 0;
let packetsAcceptedOut = 0;
let packetsRejected = 0;
let packetsRejectedIn = 0;
let packetsRejectedOut = 0;

const interfaces = []

Expand Down Expand Up @@ -176,12 +180,14 @@ function bindQueueHandlers () {
// Allow us to set a META MARK for requeue and reject.
if (thisVerdict === NF_REJECT) {
packetsRejected++;
packetsRejectedIn++;
nfpacket.setVerdict(thisVerdict, 666);
} else {
packetsAccepted++;
packetsAcceptedIn++;
nfpacket.setVerdict(4, 999);
}
process.stdout.write('Connections - Accepted: ' + packetsAccepted + ' - Rejected: ' + packetsRejected + '\r');
process.stdout.write('Connections - Accepted: ' + packetsAccepted + ' (I: ' + packetsAcceptedIn + ' O: ' + packetsAcceptedOut + ') - Rejected: ' + packetsRejected + ' (I: ' + packetsRejectedIn + ' O: ' + packetsRejectedOut + ')\r');
});
interface.queueOut = nfq.createQueueHandler(parseInt('100' + interface.number), buffer, (nfpacket) => {
let packet = new IPv4().decode(nfpacket.payload, 0);
Expand Down Expand Up @@ -255,15 +261,17 @@ function bindQueueHandlers () {
// Allow us to set a META MARK for requeue and reject.
if (thisVerdict === NF_REJECT) {
packetsRejected++;
packetsRejectedOut++;
// Outgoing packets set META MARK 777 - allows use of REJECT
// icmp-admin-prohibited (so connections fail immediately, instead
// of timing out over a period of time... which is annoying locally)
nfpacket.setVerdict(thisVerdict, 777);
} else {
packetsAccepted++;
packetsAcceptedOut++;
nfpacket.setVerdict(4, 999);
}
process.stdout.write('Connections - Accepted: ' + packetsAccepted + ' - Rejected: ' + packetsRejected + '\r');
process.stdout.write('Connections - Accepted: ' + packetsAccepted + ' (I: ' + packetsAcceptedIn + ' O: ' + packetsAcceptedOut + ') - Rejected: ' + packetsRejected + ' (I: ' + packetsRejectedIn + ' O: ' + packetsRejectedOut + ')\r');
});
})
}
Expand Down

0 comments on commit 9aa54e6

Please sign in to comment.