Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Port getifaddrs implementation from Xamarin.Android #71943

Merged
merged 5 commits into from
Jul 12, 2022

Conversation

simonrozsival
Copy link
Member

In recent Android versions the data returned by getifaddrs is invalid and doesn't allow us to implement System.Net.NetworkInformation.GetAllNetworkInterfaces(). It's possible to reimplement getifaddrs using Netlink and there's already an existing implementation in Xamarin.Android.

Fixes dotnet/android#6973
Ref #62780
Ref #51303

/cc @grendello

@simonrozsival
Copy link
Member Author

/azp run runtime-extra-platforms

@ghost
Copy link

ghost commented Jul 11, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

In recent Android versions the data returned by getifaddrs is invalid and doesn't allow us to implement System.Net.NetworkInformation.GetAllNetworkInterfaces(). It's possible to reimplement getifaddrs using Netlink and there's already an existing implementation in Xamarin.Android.

Fixes dotnet/android#6973
Ref #62780
Ref #51303

/cc @grendello

Author: simonrozsival
Assignees: simonrozsival
Labels:

area-System.Net

Milestone: -

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


#include <android/log.h>
#define LOG(level, fmt, ...) __android_log_print(level, "DOTNET_NETLINK", fmt, ## __VA_ARGS__)
#define LOG_DEBUG(fmt, ...) LOG(ANDROID_LOG_DEBUG, fmt, ## __VA_ARGS__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calls to LOG_DEBUG should ideally be hidden behind some sort of flag, and off by default. Logging on Android is very costly and should be avoided as much as possible, especially where there might be a lot of data logged.

@simonrozsival
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@simonrozsival
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@simonrozsival
Copy link
Member Author

The failing tests are unrelated to this PR (on Android x86 they are all System.Text.Json, on Linux x64 there's a failing System.Numerics test, on Browser there are various failures, mostly HTTP and WebSockets related).

I suggest checking the output of System.Net.NetworkInformation.Tests stdout for android-arm64 where the network interfaces information of the test device is printed.

@steveisok steveisok self-requested a review July 12, 2022 17:28
@steveisok
Copy link
Member

Extra-platforms failures are known and not caused by this change

@steveisok steveisok merged commit 1de4a5c into dotnet:main Jul 12, 2022
@@ -517,9 +517,6 @@
/* Have getifaddrs */
#cmakedefine HAVE_GETIFADDRS 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonrozsival we can also remove this one, it is unused in mono now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonrozsival that is part of System.Native, not mono. It has its own check:

check_function_exists(
getifaddrs
HAVE_GETIFADDRS)

@simonrozsival
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2664136084

@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] NetworkInterface.GetAllNetworkInterfaces() returns strange values on Android 11 + IPv6
5 participants