diff options
author | David 'Digit' Turner <digit@google.com> | 2016-09-15 10:47:18 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2016-10-18 15:44:39 +0200 |
commit | 61962c4a15841b3345798e4b3eca88b7cd194da3 (patch) | |
tree | 979adf2b367ef20ffa73ce119a0c98c2fc08be6c | |
parent | 1b2936892bb81746a78d71cbb4e5598dd55ef2b6 (diff) | |
download | qemu-android-61962c4a15841b3345798e4b3eca88b7cd194da3.tar.gz |
android: glue: Add network agent support.
Change-Id: I2cc51c6d160e881c13a2535990f8e8f32221e087
-rw-r--r-- | android-qemu2-glue/build/Makefile.qemu2-glue.mk | 2 | ||||
-rw-r--r-- | android-qemu2-glue/qemu-net-agent-impl.c | 53 |
2 files changed, 55 insertions, 0 deletions
diff --git a/android-qemu2-glue/build/Makefile.qemu2-glue.mk b/android-qemu2-glue/build/Makefile.qemu2-glue.mk index 88c2768e71..45408c5b31 100644 --- a/android-qemu2-glue/build/Makefile.qemu2-glue.mk +++ b/android-qemu2-glue/build/Makefile.qemu2-glue.mk @@ -9,6 +9,7 @@ LOCAL_CFLAGS += $(QEMU2_CFLAGS) LOCAL_C_INCLUDES += \ $(QEMU2_INCLUDES) \ $(QEMU2_GLUE_INCLUDES) \ + $(LOCAL_PATH)/slirp \ LOCAL_SRC_FILES := \ android_qemud.cpp \ @@ -25,6 +26,7 @@ LOCAL_SRC_FILES := \ qemu-cellular-agent-impl.c \ qemu-finger-agent-impl.c \ qemu-location-agent-impl.c \ + qemu-net-agent-impl.c \ qemu-setup.cpp \ qemu-telephony-agent-impl.c \ telephony/modem_init.c \ diff --git a/android-qemu2-glue/qemu-net-agent-impl.c b/android-qemu2-glue/qemu-net-agent-impl.c new file mode 100644 index 0000000000..eac5b77ad9 --- /dev/null +++ b/android-qemu2-glue/qemu-net-agent-impl.c @@ -0,0 +1,53 @@ +// Copyright 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "android/emulation/control/net_agent.h" + +#include "android/utils/sockets.h" +#include "qemu/osdep.h" +#include "qemu/sockets.h" +#include "net/slirp.h" + +#ifdef CONFIG_SLIRP +#include "libslirp.h" + +static bool isSlirpInited() { + return net_slirp_state() != NULL; +} + +static bool slirpRedir(bool isUdp, int hostPort, + uint32_t guestAddr, int guestPort) { + struct in_addr host = { .s_addr = htonl(SOCK_ADDRESS_INET_LOOPBACK) }; + struct in_addr guest = { .s_addr = 0 }; + return slirp_add_hostfwd(net_slirp_state(), isUdp, host, hostPort, guest, + guestPort) == 0; +} + +bool slirpUnredir(bool isUdp, int hostPort) { + struct in_addr host = { .s_addr = htonl(SOCK_ADDRESS_INET_LOOPBACK) }; + return slirp_remove_hostfwd(net_slirp_state(), isUdp, host, hostPort) == 0; +} + + +static const QAndroidNetAgent netAgent = { + .isSlirpInited = &isSlirpInited, + .slirpRedir = &slirpRedir, + .slirpUnredir = &slirpUnredir +}; +const QAndroidNetAgent* const gQAndroidNetAgent = &netAgent; + +#else +const QAndroidNetAgent* const gQAndroidNetAgent = NULL; + +#endif |