-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
NETLINK_ROUTE
socket binding not available on Android 11+, can we live without it for Android?
#6251
Comments
Netlink is enabled on all Linux systems, including Android. Netlink is used to enumerate network interfaces and routes as well as get notification when the system's network interfaces change. Unfortunately it looks like Google intends to remove the ability of native code to do any of those things. Without the ability to enumerate network interfaces libtorrent will have to fall back to listening on the unspecified address. This will produce incorrect behavior if the system is multi-homed (e.g. has both Wi-Fi and LTE connections). NAT-PMP support will not work without the ability to enumerate routes. Setting |
As of API 24, according to the stackoverflow thread shared by @wrtorrent, the solution is to enumerate interfaces using ifaddrs. Not sure if it ifaddrs also covers routes and network interface change callbacks. Nonetheless, I see the libtorrent code uses ifaddr when not using netlink |
@ssiloti, @arvidn I'm trying this on my config.jam (perhaps redundantly)
However when it's building I see a bunch of pre-processors warnings that these macros keep getting redefined, so I think it's not having the effect I wish, which is to disable NETLINK sockets and use instead IFADDR (given the SELinux limitations imposed on Android 11+)
Once the library is used on Android's SDK 30 (Android 11) it's forbidden by SELinux to bind netlink sockets. I wish I could build for Android 29 and be done, but as of November 2021 it will be mandatory making this upgrade and a bunch of torrent clients using jlibtorrent will break or won't be able to support android 11 devices, which we see are getting a very fast uptake the last few months. |
@gubatron , the ability to switch to You will definitely lose the ability to get notifications on network interfaces changes, but we were already prepared for this with |
@arvidn, I looked at this in detail, and there is no way |
This is correct, So far I was able to rebuild no problem with NDK API=24 (which I believe is Android 7.0 Nougat), I rather drop support for Android 6 (not that many users now, I believe it's from 2016) when I look at the existing ratio of Android 10, and increasingly fast growth of Android 11 users. But still, I don't think the way I've set the flags has worked.
At this point these are decisions for the app to survive going forward, Google has made some very tough calls on Android 11. |
🙏 Thanks for this @aldenml . I'll move away from defining those preprocessor constants in the cxxflags in Maybe something like this diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp
index 04c32ad68..600e4188d 100644
--- a/include/libtorrent/config.hpp
+++ b/include/libtorrent/config.hpp
@@ -159,6 +159,11 @@ see LICENSE file.
#define TORRENT_HAS_FTELLO 0
#endif // API < 24
+#if __ANDROID_API__ >= 24
+#define TORRENT_USE_IFADDRS 1
+#define TORRENT_USE_NETLINK 0
+#endif
+
#else // ANDROID
// posix_fallocate() is not available in glibc under these condition |
Managed to create a patch that hardcodes Here's the current patch in case anybody needs it. (to be applied on libtorrent's RC_1_2 branch) diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp
index ab874a247..9ace38065 100644
--- a/include/libtorrent/alert.hpp
+++ b/include/libtorrent/alert.hpp
@@ -177,7 +177,7 @@ namespace alert_category {
// interpreted as -1. For instance, boost.python
// does that and fails when assigning it to an
// unsigned parameter.
- constexpr alert_category_t all = alert_category_t::all();
+ //deleted temporarily because it is defined twice
} // namespace alert_category
diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp
index bec1b4756..e11d7df9d 100644
--- a/include/libtorrent/config.hpp
+++ b/include/libtorrent/config.hpp
@@ -170,8 +170,8 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_HAS_SYMLINK 1
#define TORRENT_HAVE_MMAP 1
-#define TORRENT_USE_NETLINK 1
-#define TORRENT_USE_IFADDRS 0
+#define TORRENT_USE_NETLINK 0
+#define TORRENT_USE_IFADDRS 1
#define TORRENT_USE_IFCONF 1
#define TORRENT_HAS_SALEN 0
#define TORRENT_USE_FDATASYNC 1
@@ -185,6 +185,10 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ANDROID
#define TORRENT_HAS_FALLOCATE 0
#define TORRENT_USE_ICONV 0
+#undef TORRENT_USE_NETLINK
+#undef TORRENT_USE_IFADDRS
+#define TORRENT_USE_NETLINK 0
+#define TORRENT_USE_IFADDRS 1
#else // ANDROID
// posix_fallocate() is not available in glibc under these condition
@@ -434,7 +438,7 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#ifndef TORRENT_USE_IFADDRS
-#define TORRENT_USE_IFADDRS 0
+#define TORRENT_USE_IFADDRS 1
#endif
// if preadv() exists, we assume pwritev() does as well
diff --git a/src/enum_net.cpp b/src/enum_net.cpp
index 1ba578c6e..b6b685a5c 100644
--- a/src/enum_net.cpp
+++ b/src/enum_net.cpp
@@ -31,7 +31,10 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
-
+#undef TORRENT_USE_NETLINK
+#undef TORRENT_USE_IFADDRS
+#define TORRENT_USE_IFADDRS 1
+#define TORRENT_USE_NETLINK 0
#include "libtorrent/enum_net.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/assert.hpp"
@@ -1409,7 +1412,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
}
#else
-#error "don't know how to enumerate network routes on this platform"
+ //#error "don't know how to enumerate network routes on this platform"
#endif
return ret;
} Android clients that use jlibtorrent will be able to get a hold of this fix on the 1.2.14.0 release coming out soon, hopefully keeping everything working for Android 11 and beyond. |
did a fix for this land in |
Not sure I understand the question. To build jlibtorrent for android, we currently check out We tried passing That patch is applied only right before building for android as a desperate measure in my build script. We plan on migrating to |
libtorrent version (or branch): 1.2.x
platform/architecture: android
Once again Android is about to introduce mandatory breaking changes, all apps must be fixed before November 2021.
Some users already running Android 11 are reporting crashes with jlibtorrent
Luckily I see that in:
include/libtorrent/netlink.hpp
src/enum_net.cpp
src/ip_notifier.cpp
all the code with
NETLINK_ROUTE
exists within a compile time defined (I think)TORRENT_USE_NETLINK
flag.I have 2 questions:
TORRENT_USE_NETLINK
a default compilation flag set for android and linux? or is it optional and it has to be set explicitly (which would mean those crashes they're reporting are not coming from jlibtorrent since I can't find a mention to the flag in any of my build scripts)The text was updated successfully, but these errors were encountered: