Skip to content

sync gold 1.981 staging #1485

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

Merged
merged 4 commits into from
May 12, 2025
Merged
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
5 changes: 5 additions & 0 deletions plugins/interface/intf_base_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ class InterfaceBasePlugin extends Plugin {
return state;
}

async linkSpeed() {
const speed = Number(await this._getSysFSClassNetValue("speed"));
return !isNaN(speed) ? speed : 0;
}

// is the interface physically ready to connect
async readyToConnect() {
const carrierState = await this.carrierState();
Expand Down
18 changes: 18 additions & 0 deletions plugins/nat_passthrough/nat_passthrough_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NATPassthroughPlugin extends Plugin {
await exec("sudo rmmod nf_conntrack_pptp").catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -D FR_PASSTHROUGH -p gre -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -t raw -D PREROUTING -p tcp --dport 1723 -j CT --helper pptp")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p gre -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j DROP")}`).catch((err) => {});
break;
Expand All @@ -57,6 +58,7 @@ class NATPassthroughPlugin extends Plugin {
case "sip": {
await exec("sudo rmmod nf_nat_sip").catch((err) => {});
await exec("sudo rmmod nf_conntrack_sip").catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -t raw -D PREROUTING -p udp --dport 5060 -j CT --helper sip")}`).catch((err) => {});
break;
}
default:
Expand All @@ -73,9 +75,23 @@ class NATPassthroughPlugin extends Plugin {
await exec(`${util.wrapIptables("sudo iptables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p gre -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j DROP")}`).catch((err) => {});

await exec(`${util.wrapIptables("sudo iptables -w -A FR_PASSTHROUGH -p gre -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -A FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -A FR_PASSTHROUGH -p gre -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -A FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j ACCEPT")}`).catch((err) => {});

await exec(`${util.wrapIptables("sudo iptables -w -t raw -A PREROUTING -p tcp --dport 1723 -j CT --helper pptp")}`).catch((err) => {});
} else {
await exec("sudo rmmod nf_nat_pptp").catch((err) => {});
await exec("sudo rmmod nf_conntrack_pptp").catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -D FR_PASSTHROUGH -p gre -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p gre -j ACCEPT")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -D FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j ACCEPT")}`).catch((err) => {});

await exec(`${util.wrapIptables("sudo iptables -w -t raw -D PREROUTING -p tcp --dport 1723 -j CT --helper pptp")}`).catch((err) => {});

await exec(`${util.wrapIptables("sudo iptables -w -A FR_PASSTHROUGH -p gre -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -A FR_PASSTHROUGH -p tcp -m tcp --dport 1723 -j DROP")}`).catch((err) => {});
await exec(`${util.wrapIptables("sudo ip6tables -w -A FR_PASSTHROUGH -p gre -j DROP")}`).catch((err) => {});
Expand Down Expand Up @@ -119,9 +135,11 @@ class NATPassthroughPlugin extends Plugin {
case "sip": {
if (enabled) {
await exec("sudo modprobe ip_nat_sip").catch((err) => {}); // this will load nf_nat_sip and nf_conntrack_sip
await exec(`${util.wrapIptables("sudo iptables -w -t raw -A PREROUTING -p udp --dport 5060 -j CT --helper sip")}`).catch((err) => {});
} else {
await exec("sudo rmmod nf_nat_sip").catch((err) => {});
await exec("sudo rmmod nf_conntrack_sip").catch((err) => {});
await exec(`${util.wrapIptables("sudo iptables -w -t raw -D PREROUTING -p udp --dport 5060 -j CT --helper sip")}`).catch((err) => {});
}
break;
}
Expand Down
5 changes: 3 additions & 2 deletions sensors/ifplug_sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class IfPlugSensor extends Sensor {
});
}, 60000)

sclient.on("message", (channel, message) => {
sclient.on("message", async(channel, message) => {
switch (channel) {
case "ifup": {
const iface = message;
Expand All @@ -102,9 +102,10 @@ class IfPlugSensor extends Sensor {
}
// filter out VPN interface
if (intfPlugin && intfPlugin.constructor.name === "PhyInterfacePlugin") {
const labels = {"current_speed": await intfPlugin.linkSpeed()};
ifStates[iface] = 1;
this.log.info("ifStates:",ifStates);
era.addStateEvent(EventConstants.EVENT_ETHER_STATE, iface, 0);
era.addStateEvent(EventConstants.EVENT_ETHER_STATE, iface, 0, labels);
}
this.toggleLedNormalVisible().catch((err) => {
this.log.error("Failed to toggle led visible", err.message);
Expand Down
9 changes: 8 additions & 1 deletion tests/plugins/test_intf_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ describe('Test interface base dhcp6', function(){
expect(this.plugin._getDuidType('00:03:00:01:20:6d:31:01:2b:43')).to.be.equal('DUID-LL');
expect(this.plugin._getDuidType('00:04:7e:89:20:22:89:15:45:b8:ac:05:3c:68:2b:08:04:8f')).to.be.equal('DUID-UUID');
});
});

it('should get link speed', async() => {
const speed = await this.plugin.linkSpeed();
log.debug(this.plugin.name,"speed:", speed);
expect(isNaN(speed)).to.be.equal(false);
});

});


describe('Test interface base dns', function(){
Expand Down