Skip to content

Commit

Permalink
Minor Refactor
Browse files Browse the repository at this point in the history
Fixed bug with interface.json changes not working.

Changed actions to verdicts on nfpacket object.

Minor other undocumented changes.
  • Loading branch information
Dustyn Blackmore committed May 17, 2018
1 parent 1a6441d commit ea9d750
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function checkConfig (err, filename) {
fs.readFile('./config/interfaces.json', 'utf8', (err, data) => {
if (err) throw err;
let newInterfaces = JSON.parse(data);
Object.keys(newInterfaces.interfaces).forEach(interface => {
interfaces.forEach(thisInterface => {
if (thisInterface.name === interface && thisInterface.zone !== newInterfaces.interfaces[interface].zone) {
thisInterface.zone = newInterfaces.interfaces[interface].zone;
}
})
});

systemInterfaces = newInterfaces.interfaces;
});
break;
Expand Down Expand Up @@ -147,14 +155,14 @@ function handlePacket (packet) {
}
}
// Do not further traverse ruleset, or this function ; wasted cycles.
return packet.actions.verdict(packet.verdict, packet.mark);
return packet.verdicts.getVerdict();
// packet.nfpacket.setVerdict(packet.verdict, packet.mark);
}
// The global default is enabled, yet there is no ports key..
// (Likely) means this is a port-less protocol, or a blanket 'allow' rule is in place.
} else {
packet.verdict = packet.enums.netfilterVerdict.NF_ACCEPT;
return packet.actions.verdict(packet.verdict, packet.mark);
return packet.verdicts.getVerdict();
//packet.nfpacket.setVerdict(packet.verdict, packet.mark);
}
// Else, as if globally accepted we don't need to traverse other zones.
Expand Down Expand Up @@ -189,7 +197,7 @@ function handlePacket (packet) {
}
}

return packet.actions.verdict(packet.verdict, packet.mark);
return packet.verdicts.getVerdict();
}

function updateOutput () {
Expand Down Expand Up @@ -267,4 +275,4 @@ nft.flush().then(
(err) => console.log('Failed to insert final counters: ' + err)
);

const outputInterval = setInterval(updateOutput, 5000);
const outputInterval = setInterval(updateOutput, 25000);
4 changes: 2 additions & 2 deletions src/nfpacket/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const actions = require('./actions');
const verdicts = require('./verdicts');
const encoding = require('./encoding');
const enums = require('./enums.js');
const statable = require('./../state');
Expand All @@ -17,7 +17,7 @@ module.exports = (dependencies) => (nfpacket) => {
return Object.assign(
state,
{
actions: actions(dependencies)(state),
verdicts: verdicts(dependencies)(state),
encoding: encoding(dependencies.pcapIPv4)(state)
}
);
Expand Down
26 changes: 12 additions & 14 deletions src/nfpacket/actions.js → src/nfpacket/verdicts.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
const actions = (dependencies) => (state) => ({
accept: (mark) => {
module.exports = (dependencies) => (state) => ({
accept: () => {
state.nfpacket
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_ACCEPT, mark)
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_ACCEPT, state.mark)
: false
},
reject: (mark) => {
reject: () => {
// This allows us to admin-prohibit and immediately reject outgoing, intead of droop (timeout).
if (state.direction === 'outgoing') {
state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_REPEAT, 777)
} else {
state.nfpacket
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_DROP, mark)
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_DROP, state.mark)
: false
}
},
requeue: (mark) => {
requeue: () => {
state.nfpacket
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_REPEAT, mark)
? state.nfpacket.setVerdict(state.enums.netfilterVerdict.NF_REPEAT, state.mark)
: false
},
verdict: (verdict, mark) => {
switch (verdict) {
getVerdict: () => {
switch (state.verdict) {
case state.enums.netfilterVerdict.NF_ACCEPT:
return state.actions.accept;
return state.verdicts.accept;
break;
case state.enums.netfilterVerdict.NF_REPEAT:
return state.actions.requeue;
return state.verdicts.requeue;
break;
default:
return state.actions.reject;
return state.verdicts.reject;
break;
}
}
})

module.exports = actions;

0 comments on commit ea9d750

Please sign in to comment.