• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Farhan/openssh


Commit MetaInfo

Revision721b075c99229747ef85cc53d5883a9138ebd42f (tree)
Time2017-10-19 07:08:36
AuthorTomasz Wiszkowski <ender@goog...>
CommiterTomasz Wiszkowski

Log Message

Allow SSH to function with more strict android network stack.

This change relocates SSH listening port to external network namespace,
that is not under direct android supervision. SSH is functional even when
ssh_key_fetcher is not.

Test: manual
BUG=67899876
Change-Id: Ia729103d7bf0ec84abb5969d8b4edf733e525702

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -258,6 +258,9 @@ LOCAL_SRC_FILES := \
258258 LOCAL_MODULE := sshd
259259
260260 LOCAL_CFLAGS += -Wno-unused-parameter
261+ifneq ($(filter gce_x86 calypso, $(TARGET_DEVICE)),)
262+LOCAL_CFLAGS += -DANDROID_GCE $(GCE_VERSION_CFLAGS)
263+endif
261264
262265 LOCAL_C_INCLUDES := \
263266 external/zlib \
--- a/sshd.c
+++ b/sshd.c
@@ -1034,9 +1034,44 @@ server_listen(void)
10341034 ssh_gai_strerror(ret));
10351035 continue;
10361036 }
1037+
1038+#if defined(ANDROID_GCE) && defined(GCE_PLATFORM_SDK_VERSION) && GCE_PLATFORM_SDK_VERSION >= 28
1039+ /*
1040+ * Android GCE specific, bug 67899876
1041+ * Open socket in external namespace, making it possible to serve SSH
1042+ * connections regardless of internal interface states.
1043+ */
1044+ int outerfd = open("/var/run/netns/outer.net", O_RDONLY);
1045+ int androidfd = open("/var/run/netns/android.net", O_RDONLY);
1046+ if (outerfd > 0 && androidfd > 0) {
1047+ if (setns(outerfd, 0) != 0) {
1048+ fprintf(stderr, "Could not set netns: %s\n",
1049+ strerror(errno));
1050+ exit(1);
1051+ }
1052+ }
1053+#endif
1054+
10371055 /* Create socket for listening. */
10381056 listen_sock = socket(ai->ai_family, ai->ai_socktype,
10391057 ai->ai_protocol);
1058+
1059+#if defined(ANDROID_GCE) && defined(GCE_PLATFORM_SDK_VERSION) && GCE_PLATFORM_SDK_VERSION >= 28
1060+ if (androidfd > 0) {
1061+ if (setns(androidfd, 0) != 0) {
1062+ fprintf(stderr, "Could not set netns: %s\n",
1063+ strerror(errno));
1064+ exit(1);
1065+ }
1066+ }
1067+ if (outerfd > 0) {
1068+ close(outerfd);
1069+ }
1070+ if (androidfd > 0) {
1071+ close(androidfd);
1072+ }
1073+#endif
1074+
10401075 if (listen_sock < 0) {
10411076 /* kernel may not support ipv6 */
10421077 verbose("socket: %.100s", strerror(errno));