Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tc-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tc-wrapper - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

20

dist/index.js

@@ -75,5 +75,8 @@ 'use strict';

var params = [];
if (filterParam.network !== null) {
params.push('network=' + filterParam.network);
if (filterParam.srcNetwork !== null) {
params.push('srcNetwork=' + filterParam.srcNetwork);
}
if (filterParam.dstNetwork !== null) {
params.push('dstNetwork=' + filterParam.dstNetwork);
}
if (filterParam.srcPort !== null) {

@@ -229,3 +232,12 @@ params.push('srcPort=' + filterParam.srcPort);

// Mandatory rule parameters.
var network = rule.match(/.*network=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}).*/)[1];
var srcNetwork = null;
var dstNetwork = null;
try {
srcNetwork = rule.match(/.*srcNetwork=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}).*/)[1];
} catch (e) {/* ignored */}
try {
dstNetwork = rule.match(/.*dstNetwork=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}).*/)[1];
} catch (e) {/* ignored */}
var protocol = rule.match(/.*protocol=(\w+).*/)[1];

@@ -243,3 +255,3 @@

var tcRuler = new _TCRuler2.default(device, this.deviceQdiscMajorId, direction, network, protocol, dstPort, srcPort, rulePayload, qdiscMinorId, netemMajorId);
var tcRuler = new _TCRuler2.default(device, this.deviceQdiscMajorId, direction, dstNetwork, srcNetwork, protocol, dstPort, srcPort, rulePayload, qdiscMinorId, netemMajorId);

@@ -246,0 +258,0 @@ return tcRuler;

13

dist/TCfilterParser.js

@@ -91,3 +91,4 @@ 'use strict';

this._flowId = null;
this._filterNetwork = null;
this._filterSrcNetwork = null;
this._filterDstNetwork = null;
this._filterSrcPort = null;

@@ -101,3 +102,4 @@ this._filterDstPort = null;

flowid: this._flowId,
network: this._filterNetwork,
srcNetwork: this._filterSrcNetwork,
dstNetwork: this._filterDstNetwork,
srcPort: this._filterSrcPort,

@@ -166,3 +168,8 @@ dstPort: this._filterDstPort,

var netmask = ((parseInt(maskHex, 16) >>> 0).toString(2).match(/1/g) || []).length; // eslint-disable-line no-bitwise
this._filterNetwork = ip + '/' + netmask;
if (FilterMatchIdIpv4.INCOMING_NETWORK === matchId) {
this._filterSrcNetwork = ip + '/' + netmask;
} else {
this._filterDstNetwork = ip + '/' + netmask;
}
} else if (matchId === FilterMatchIdIpv4.PORT) {

@@ -169,0 +176,0 @@ // Ports are eight hex digits, upper-half represents src port and the bottom-half represents dst port

@@ -32,5 +32,5 @@ 'use strict';

var TCRuler = function () {
function TCRuler(device, deviceQdiscMajorId, direction, network, protocol, dstPort, srcPort, options) {
var qdiscMinorId = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : DEFAULT_CLASS_MINOR_ID;
var netemMajorId = arguments[9];
function TCRuler(device, deviceQdiscMajorId, direction, dstNetwork, srcNetwork, protocol, dstPort, srcPort, options) {
var qdiscMinorId = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : DEFAULT_CLASS_MINOR_ID;
var netemMajorId = arguments[10];

@@ -42,3 +42,4 @@ _classCallCheck(this, TCRuler);

this.direction = direction;
this.network = network;
this.dstNetwork = dstNetwork;
this.srcNetwork = srcNetwork;
this.protocol = protocol;

@@ -153,6 +154,14 @@ this.dstPort = dstPort;

var cmd = {
cmd: 'tc filter add dev ' + this.device + ' protocol ip parent ' + this.deviceQdiscMajorId + ': prio 1 ' + ('u32 match ' + this.protocol + ' ' + (this.direction === 'outgoing' ? 'dst' : 'src') + ' ' + this.network),
cmd: 'tc filter add dev ' + this.device + ' protocol ip parent ' + this.deviceQdiscMajorId + ': prio 1 u32',
allowedErrors: [new RegExp('RTNETLINK answers: File exists', 'i')]
};
if (this.srcNetwork !== null) {
cmd.cmd += ' match ' + this.protocol + ' src ' + this.srcNetwork;
}
if (this.dstNetwork !== null) {
cmd.cmd += ' match ' + this.protocol + ' dst ' + this.dstNetwork;
}
if (this.srcPort !== null) {

@@ -159,0 +168,0 @@ cmd.cmd += ' match ' + this.protocol + ' sport ' + this.srcPort + ' 0xffff';

@@ -14,3 +14,3 @@ 'use strict';

// Only ipv4 supported right now. TODO: Support v6
var ipv4RulePattern = /network=(\d{1,3}\.){3}\d{1,3}\/\d{1,2}(,srcPort=\d+)?(,dstPort=\d+)?,protocol=ip/;
var ipv4RulePattern = /^((dst|src)Network=(\d{1,3}\.){3}\d{1,3}\/\d{1,2},){1,2}(srcPort=\d+,)?(dstPort=\d+,)?protocol=ip$/;

@@ -17,0 +17,0 @@ // TODO: Improve validation!

{
"name": "tc-wrapper",
"version": "1.0.7",
"version": "1.0.8",
"description": "NodeJS wrapper for tc command (traffic control on linux)",

@@ -5,0 +5,0 @@ "author": "J. Victor Soto",

@@ -15,2 +15,6 @@ # tc-wrapper

## Changelog
* 1.0.8: Removed network parameter and included srcNetwork & dstNetwork paramenters
## Usage

@@ -45,3 +49,3 @@

"outgoing": {
"network=0.0.0.0/0,protocol=ip": {
"srcNetwork=0.0.0.0/0,protocol=ip": {
"delay": "1.0ms",

@@ -55,6 +59,6 @@ "jitter": "0.5%",

"incoming": {
"network=192.168.1.1/32,protocol=ip": {
"dstNetwork=192.168.1.1/32,protocol=ip": {
"loss": "9%",
},
"network=10.10.10.0/28,srcPort=80,protocol=ip": {
"dstNetwork=192.168.1.1/32,srcNetwork=10.10.10.0/28,srcPort=80,protocol=ip": {
"rate": "100Mbit",

@@ -77,3 +81,3 @@ }

outgoing: {
'network=0.0.0.0/0,protocol=ip':{
'dstNetwork=0.0.0.0/0,protocol=ip':{
delay: '20ms'

@@ -99,3 +103,3 @@ }

incoming: {
'network=0.0.0.0/0,protocol=ip':{
'srcNetwork=0.0.0.0/0,protocol=ip':{
rate: '20Mbit'

@@ -102,0 +106,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc