From 4d0c3dbe73893556fc0eea47bfc946ba75f0bb43 Mon Sep 17 00:00:00 2001 From: keeramis Date: Mon, 13 May 2024 17:16:22 -0700 Subject: [PATCH] Export more fields from iface command --- src/network-device.js | 52 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/network-device.js b/src/network-device.js index b09ddd44..aa0d05e 100644 --- a/src/network-device.js +++ b/src/network-device.js @@ -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 * @@ -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)) { + if (value !== 0 && (flags & value)) { + activeFlags.push(value); + } + } + return activeFlags; + } + /** * Gets the network interface and its fields * @@ -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)); + const result = { index: ifaceIndex, name, type: InterfaceType.fromProtobuf(type), - hwAddress: convertBufferToMacAddress(hwAddress) + hwAddress: convertBufferToMacAddress(hwAddress), + mtu, + flagsVal: flags, + extFlags, + flagsStrings, + metric, + profile }; if (ipv4Config) {