Skip to content

Commit 7edc3af

Browse files
authored
Better handling of ifb0 (#93)
* Better handling of ifb0 * fix * fix
1 parent 7288e5e commit 7edc3af

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/tc.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ async function getDefaultInterface() {
2121
async function moduleProbe() {
2222
try {
2323
await sudo('modprobe', 'ifb');
24+
// eslint-disable-next-line no-empty
25+
} catch {}
26+
}
27+
async function setupifb0() {
28+
try {
29+
// Check if ifb0 exist
30+
await sudo('ip', 'link', 'show', 'ifb0');
2431
} catch {
25-
// we are probably in a Docker env
26-
// let us hope that the host is Linux
27-
try {
28-
await sudo('ip', 'link', 'add', 'ifb0', 'type', 'ifb');
29-
} catch {
30-
// If we already setup ifb in a previous run, this will fail
31-
}
32+
// Add the interface
33+
await sudo('ip', 'link', 'add', 'ifb0', 'type', 'ifb');
3234
}
35+
36+
// Bring the interface up
37+
await sudo('ip', 'link', 'set', 'ifb0', 'up');
3338
}
3439

3540
async function setup(defaultInterface) {
36-
await sudo('ip', 'link', 'set', 'dev', 'ifb0', 'up');
3741
await sudo('tc', 'qdisc', 'add', 'dev', defaultInterface, 'ingress');
3842
await sudo(
3943
'tc',
@@ -145,6 +149,7 @@ export async function start(up, down, rtt = 0, packetLoss = 0) {
145149

146150
const indexFace = await getDefaultInterface();
147151
await moduleProbe();
152+
await setupifb0();
148153
await setup(indexFace);
149154
await setLimits(up, down, halfWayRTT, packetLoss, indexFace);
150155
}

0 commit comments

Comments
 (0)