fix(ios,tvos): Remove IPv4-only paths to prevent App Store warnings #431
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
For #300…
Refactored
ios/RNCNetInfo.m
frominet_ntoa
(which causes warnings around Apple AppStore requirements for dual-stack networking code) toinet_ntop
which itself supports both IPv4 and IPv6.Options Considered
Approach 1: Don't call
inet_ntoa
which is IPv4-only (bare minimum)This invocation causes warnings related to Apple's AppStore requirements…
Refactoring from
inet_ntoa
(IPv4-only) withinet_ntop
(which supports both) inRNCNetInfo
'sipAddress
andsubnet
methods gets rid of a symbol match oninet_ntoa
, and is a simple refactor to get the same value via the new function.Ex:
What risks could come of adding? None foreseen - net net, this is replacing the same "what" with a different "how" but should return the same values.
What risks could come of not adding? Continued findings for adopting teams that use scanning tools to find issues such as AppStore guidline gaps, and teams will continue to see this warning.
Approach 2:
inet_ntop
is good, but not sufficient per AppleApple isn't really after "better IPv4" code, and recommends being truly dual-stack-ready:
RNCNetInfo
'sipAddress
andsubnet
methods loop through all interfaces, but ignore any that aren'tAF_INET
(IPv4) skipping all other values. By not addingAF_INET6
support, the current implementation doesn't support IPv6-only.The fix for this isn't that much more difficult and can be easily slotted in to the two methods…
What risks could come of not adding?
Devices running on an IPv6-only networks would only ever return
0.0.0.0
as there would be noAF_INET
record to extact another IP address or subnet from. So in some cases, the value being returned is not accurate for the user's situation, which in turn could complicate tasks such as debugging network issues related to connectivity.What risks could come of adding?
I admittedly don't know enough to accurately predict global ramifications to consuming code if these methods return non-IPv4 records, but this was my starter list of possible issues…
INET6_ADDRSTRLEN
is 46 bytes, which is larger thanINET_ADDRSTRLEN
(16 bytes) - anyone with a strict storage schema for, say, persisting the data where code is expecting only 16 bytes would either get errors or unexpected data truncation. (feels unlikely)Ref:
Approach 3: Add more clarity to the selection of the proper IP addresses/subnet
Building on Approach 2's proposal, let's consider what would happen if we do add IPv6 support.
Further note that in the current algorithm…
en0
anden1
are considered for iOS/tvOS/(watchOS?)break
after this https://github.com/react-native-netinfo/react-native-netinfo/blob/master/ios/RNCNetInfo.m#L167)Example 1
Let's take first a mixed config approach:
en0
en0.ipv6
en1
en1.ipv4
en1.ipv4
en1.ipv4
Example 2
Now, let's flip that table:
en0
en0.ipv4
en1
en1.ipv6
en0.ipv4
en1.ipv6
Because there is no
break
, the last value wins, and in this case, the IPv6 record would winExample 3
Now, let's say we have a full config like so:
en0
en0.ipv4
en0.ipv6
en1
en1.ipv4
en1.ipv6
en1.ipv4
en1.ipv4
Example 4
Now, let's say it's IPv6 only
en0
en0.ipv6
en1
en1.ipv6
0.0.0.0
(default, no IPv4 found)en1.ipv6
–––
Unpacking the above, I think this produces an ambiguous result and it's not clear what the user actually is looking for.
en0.ipv6
)en1.ipv6
even though an address (en0.ipv4
) was seen previously.en1.ipv4
even thoughen0
has both IPv4 and IPv6 records and there's also the matter ofen1.ipv6
en1.ipv6
even thoughen0
had a value as wellIn the first three of these cases, a value that is one of the addresses is returned, but it's not clear to me if it eliminates the principle of least surprise for the caller.
Proposals
To remove the ambiguity, I think there could be one of a few algorithms, with two provided here:
Prefer first interface with an IPv4/6 address, and prefer IPv4 over IPv6 (this is what chore: Remove deprecated code #2 effectively is with a
break
added in)en0.ipv6
en0.ipv4
en0.ipv4
en0.ipv6
Prefer first IPv4 address regardless of interface, then IPv6 if no IPv4
en1.ipv4
en0.ipv4
en0.ipv4
en0.ipv6
Add'l note
Trying to assess things holistically, the
ssid
andbssid
methods take a wholly different codepaths to grab their values, and I would suggest that they should also be aligned with the above algo and aligned to the same interface chosen for the IP/subnet values.That is, if the chosen IP/subnet interface is an Ethernet interface, logically, there is no (B)SSID.
As there have been notes about more full macOS support, which has so many other potential interfaces (i.e. USB Ethernet adapters, FireWire/Thunderbolt hubs w/ Ethernet, etc.) and let's you order the interfaces yourself in System Preferences, I thought it was at least worth the note that disambiguation may be preferable.
Summary
I'm honestly not sure what the right algo is. But if Option 2 were implemented, I think it's worth the discussion.
Test Plan
Attn: @matt-oakes
I have not yet been able to validate what I think is a fairly small change as I cannot reproduce the testing path described in #312 and the repo instructions as the repo doesn't build cleanly for me, and I would ask for some guidance.
Where did I test?
Locally
GitHub Actions
In my fork, I enabled Actions, and it failed the same way, and seems to be…
–––
There are some related issues that had to do with Xcode 12 that I see in the
react-native-macos
projectIn experimenting, I tried updating the
react-native-macos
version to a version that fixes #534 above……which seems the earliest version that has fixes for both of the above PRs. While that fixed the issue related to missing symbols, errors related to building detox and some libraries not found persisted.
I am uncertain how to proceed as the patch here may fix the purported issue (it does in a separate command line Xcode project where I copied over the data), I can't give y'all affirmative signal - and I suspect that there is some deeper work needed to fully support Xcode 12.
Any advice would be appreciated.