silverwind / default-gateway

Get the default network gateway, cross-platform.
86 stars 19 forks source link

Support generic AIX platform (non-OS400) #5

Closed silverwind closed 5 years ago

silverwind commented 7 years ago

PRs welcome. Implementation must be pure JS.

silverwind commented 7 years ago

Seems it's impossible to virtualize AIX on x86 hardware, so I have to pass on supporting it.

patrickhrastnik commented 5 years ago

Hi there, we‘re having an AIX system (ppc64 architecture) and we‘re interested in making this package available on it. Since this package is a dependency for Angular as well as React, it‘s kind of necessary for us to get it working on our machine, in order to use these frameworks. So, if you‘re still interested on working on support, please let us know.

silverwind commented 5 years ago

Can you post the exact output of these commands on a machine that ideally has both IPv4 and IPv6 gateways?

netstat -rn -f inet
netstat -rn -f inet6
patrickhrastnik commented 5 years ago

I‘ll come back on Monday with the results. Thanks!

patrickhrastnik commented 5 years ago

Unfortunately, the netstat command is not available in the AIX terminal. I tried other commands as well (ifconfig, ip, net stat) but none of them is available. There's a system command called netstat, but you cannot execute it in the bash ("Command NETSTAT invalid in this environment") We're currently looking for some solution to access this information in node. One option might be using IBM/nodejs-itoolkit - but I have to dig into it first.

silverwind commented 5 years ago

Would like to avoid additional dependencies if possible. Is there a /proc/net/route and /proc/net/ipv6_route file maybe?

patrickhrastnik commented 5 years ago

There's a database table qsys2/netstat_route_info where I can find the default gateway. There's a command "db2" available to run sql through the shell. But the statement will throw a "permission denied" exception when I try to just run it in the shell. It might work if I run it with the proper package. I'm working on some prototype to test this.

What I didn't mention so far: It's actually not a full AIX setup we're using - It's an integrated subsystem inside a System i (also known as AS/400). That's why not all the AIX commands will work here.

patrickhrastnik commented 5 years ago

It took a few moments, but I was able to make an aix.js file that runs on our system (tested with test.js) You can have a look on it here: https://github.com/patrickhrastnik/default-gateway Do you want me to increase the version number in package.json before I create a PR?

patrickhrastnik commented 5 years ago

Sorry to say, but I wasn't able to make the aix.js file without any of the packages IBM provides for database access in node... I added the idb-connector as an optional dependency, thus installing default-gateway won't raise an error if you're installing it on another system but aix.

silverwind commented 5 years ago

Do you want me to increase the version number in package.json before I create a PR?

No need, I will handle that after merging.

patrickhrastnik commented 5 years ago

According to this: https://docs.npmjs.com/files/package.json#optionaldependencies

The difference is that build failures do not cause installation to fail.

silverwind commented 5 years ago

Yeah, i was reminded of https://github.com/joyent/node-ldapjs/issues/451, but as I see now, that failure there is on require when the optional dependency failed to build, not on the actual build build.

So as long as we guard the require in try ... catch, we should be fine.

silverwind commented 5 years ago

Fixed in https://github.com/silverwind/default-gateway/commit/f32b88139b1da2c88ca06f5cffc29132a41947a1 ... https://github.com/silverwind/default-gateway/commit/f7903f51c0563049e4a703694ddddcf43fbd0642.

patrickhrastnik commented 5 years ago

Is this current version now available in npm, or is there something left/pending? Is it still version 3.0.1, or is it gonna be another release version containing these changes? Sorry for the dumb question, Idk how things work with npm package contribution.

silverwind commented 5 years ago

Publishing soon after I finish travis changes. Then the change will need to propagate through the dependency chain. I'll do it for https://github.com/sindresorhus/internal-ip because that one is not depending on v3 yet.

patrickhrastnik commented 5 years ago

Okay, thanks :)

silverwind commented 5 years ago

3.1.0 released, https://github.com/sindresorhus/internal-ip/pull/20 for downstream support.

silverwind commented 5 years ago

This is open again, see #10. I will only accept pure JS support for AIX.

patrickhrastnik commented 5 years ago

I‘m sorry the idb-connector package was kinda a miss... but what about a solution with odbc? This will involve another dependency as well, but odbc is much more available (and less prone to fail on installation) than the idb-connector.

ThePrez commented 5 years ago

I second @patrickhrastnik's question, but also curious if you would accept the current change if https://github.com/IBM/nodejs-idb-connector/issues/54 gets resolved. Currently, this issue only exists for AIX, and only for the non-IBMi variants of AIX. Once that issue is resolved, we will avoid the compile failures for any AIX

silverwind commented 5 years ago

I would not accept a native dependency, sorry. What we could do is drop the os field in package.json which would prevent installation failures on AIX, so react development could still work, even without the module returning anything useful.

ThePrez commented 5 years ago

Ok. We have figured out a game plan for a pure js implementation, and should have it ready within a few days.

silverwind commented 5 years ago

Great! Generally, the current approach with unspecified os should make react and friends still work on AIX if they treat the negative result from default-gateway (and in turn internal-ip) gracefully.

ThePrez commented 5 years ago

Installs of react-scripts still fail because of the old internal-ip


npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for internal-ip@3.0.1: wanted {"os":"android,darwin,freebsd,linux,openbsd,sunos,win32","arch":"any"} (current: {"os":"aix","arch":"ppc64"})

(I think this is expected, just documenting a reminder of the upstream changes, as we will want to request version bumps).

webpack-dev-server installs fine as it pulls in internal-ip 4.1

silverwind commented 5 years ago

Yes, I assume react-scripts needs to update to webpack-dev-server 3.2.0 or higher.

ThePrez commented 5 years ago

To implement on mainline AIX, we could parse out the following command: netstat -r -f inet -n/netstat -r -f inet6 -n I'd gladly work on this, but it may take me a while to procure a machine for development. That work can be tracked in this (or a separate) issue. In the meantime, I'd love for #11 to land as soon as the new db2util utility is available.

silverwind commented 5 years ago

Sounds like a plan. For netstat parsing, you can use the other unixes like sunos.js as a template. The only difference between them is on which column the gateway entry is.

ThePrez commented 5 years ago

Thanks for landing the PR! Would you like to take the task of the upstream request to webpack-dev-server? I'd happily do it if you prefer, but I suspect origination from the package maintainer gives the request more legitimacy.

silverwind commented 5 years ago

No need to update webpack-dev-server, caret version takes care of it and they updated to internal-ip@4.2.0 already.

ThePrez commented 5 years ago

Upon further inspection, it looks like the sunos implementation can be used as-is for AIX! (I will try to find somewhere to test)

ThePrez commented 5 years ago

ahh, so it's just react-scripts that needs to pull in a newer webpack-dev-server

silverwind commented 5 years ago

Yes, exactly, they to update to 3.2.1 or higher.

ThePrez commented 5 years ago

PR opened to react here: https://github.com/facebook/create-react-app/pull/6483

silverwind commented 5 years ago

Fixed in https://github.com/silverwind/default-gateway/commit/eb1bce7f559d56f2d68cb10f8d0f1620b63972d6 and released as default-gateway@4.2.0.