summaryrefslogtreecommitdiff
path: root/net/slirp.c
diff options
context:
space:
mode:
authorSeokYeon Hwang <syeon.hwang@samsung.com>2016-01-04 19:28:26 +0900
committerSeokYeon Hwang <syeon.hwang@samsung.com>2016-01-05 21:15:21 +0900
commit346ee8b1ee5cccd871ba7bc2c0a78c4e98d88748 (patch)
treef47ecdfe195bcb018ea1483cdefa24748bf31fd8 /net/slirp.c
parent67a8399cae344e2261475fb054914385624f19a5 (diff)
downloadqemu-346ee8b1ee5cccd871ba7bc2c0a78c4e98d88748.tar.gz
qemu-346ee8b1ee5cccd871ba7bc2c0a78c4e98d88748.tar.bz2
qemu-346ee8b1ee5cccd871ba7bc2c0a78c4e98d88748.zip
emulator: clean-up emulator network initialization
Do port forwarding and base port initialization at once. Some emul_state getters/setters are refined. "sdb.c" is "net_helper.c" now and it use new_debug_channel. Change-Id: I0659b35e231a8f60bd3707a2d04b09213a9cb830 Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com> Signed-off-by: Jinhyung Choi <jinh0.choi@samsung.com>
Diffstat (limited to 'net/slirp.c')
-rw-r--r--net/slirp.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/net/slirp.c b/net/slirp.c
index f505570adb..7cf1eeb764 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -275,6 +275,56 @@ error:
return -1;
}
+#ifdef CONFIG_MARU
+bool hostfwd_try_add(int is_udp, const char *host_addr_str,
+ int host_port, const char *guest_addr_str, int guest_port)
+{
+ if (QTAILQ_EMPTY(&slirp_stacks)) {
+ return false;
+ }
+
+ SlirpState *s = QTAILQ_FIRST(&slirp_stacks);
+ struct in_addr host_addr = { .s_addr = INADDR_ANY };
+ struct in_addr guest_addr = { .s_addr = 0 };
+
+ if ((host_addr_str && !inet_aton(host_addr_str, &host_addr)) ||
+ (guest_addr_str && !inet_aton(guest_addr_str, &guest_addr))) {
+ error_report("invalid host forwarding rule '%s' '%s",
+ host_addr_str, guest_addr_str);
+ return false;
+ }
+
+ if (slirp_add_hostfwd(s->slirp, is_udp, host_addr, host_port, guest_addr,
+ guest_port) < 0) {
+ return false;
+ }
+
+ return true;
+}
+
+bool hostfwd_try_remove(int is_udp, const char *host_addr_str, int host_port)
+{
+ if (QTAILQ_EMPTY(&slirp_stacks)) {
+ return false;
+ }
+
+ SlirpState *s = QTAILQ_FIRST(&slirp_stacks);
+ struct in_addr host_addr = { .s_addr = INADDR_ANY };
+
+ if (host_addr_str && !inet_aton(host_addr_str, &host_addr)) {
+ error_report("invalid host forwarding rule '%s",
+ host_addr_str);
+ return false;
+ }
+
+ if (slirp_remove_hostfwd(s->slirp, is_udp, host_addr, host_port) < 0) {
+ return false;
+ }
+
+ return true;
+}
+#endif
+
static SlirpState *slirp_lookup(Monitor *mon, const char *vlan,
const char *stack)
{