Skip to content

Commit

Permalink
Export more fields from iface command
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed May 14, 2024
1 parent 51e9d8b commit 4d0c3db
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/network-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ const InterfaceConfigurationSource = fromProtobufEnum(proto.InterfaceConfigurati
DHCPV6: 'DHCPV6'
});

const InterfaceFlag = fromProtobufEnum(proto.InterfaceFlag, {
NONE: 'IFF_NONE',
UP: 'IFF_UP',
BROADCAST: 'IFF_BROADCAST',
DEBUG: 'IFF_DEBUG',
LOOPBACK: 'IFF_LOOPBACK',
POINTOPOINT: 'IFF_POINTTOPOINT',
RUNNING : 'IFF_RUNNING',
LOWER_UP : 'IFF_LOWER_UP',
NOARP : 'IFF_NOARP',
PROMISC : 'IFF_PROMISC',
ALLMULTI : 'IFF_ALLMULTI',
MULTICAST : 'IFF_MULTICAST',
NOND6 : 'IFF_NOND6'
});

/**
* Converts a given interface IP address into a string
*
Expand Down Expand Up @@ -155,6 +171,17 @@ const NetworkDevice = base => class extends base {
}));
}

// Helper function to get active flags of a network interface
_getActiveFlags(flags, flagDefinitions) {
const activeFlags = [];
for (const [key, value] of Object.entries(flagDefinitions)) {

Check failure on line 177 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'key' is assigned a value but never used

Check failure on line 177 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'key' is assigned a value but never used

Check failure on line 177 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'key' is assigned a value but never used
if (value !== 0 && (flags & value)) {
activeFlags.push(value);
}
}
return activeFlags;
}

/**
* Gets the network interface and its fields
*
Expand All @@ -173,13 +200,34 @@ const NetworkDevice = base => class extends base {
throw new NotFoundError();
}

const { index: ifaceIndex, name, type, ipv4Config, ipv6Config, hwAddress } = reply.interface;
const {
index: ifaceIndex,
name,
type,
flags,
extFlags,
ipv4Config,
ipv6Config,
hwAddress,
mtu,
metric,
profile
} = reply.interface;

const activeFlags = this._getActiveFlags(flags, proto.InterfaceFlag);
const flagsStrings = activeFlags.map(flag => InterfaceFlag.fromProtobuf(flag));

Check failure on line 219 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Trailing spaces not allowed

Check failure on line 219 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Trailing spaces not allowed

Check failure on line 219 in src/network-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Trailing spaces not allowed
const result = {
index: ifaceIndex,
name,
type: InterfaceType.fromProtobuf(type),
hwAddress: convertBufferToMacAddress(hwAddress)
hwAddress: convertBufferToMacAddress(hwAddress),
mtu,
flagsVal: flags,
extFlags,
flagsStrings,
metric,
profile
};

if (ipv4Config) {
Expand Down

0 comments on commit 4d0c3db

Please sign in to comment.