qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Samoylov <max7255@yandex-team.ru>
To: qemu-devel@nongnu.org
Cc: max7255@yandex-team.ru
Subject: [Qemu-devel] [PATCH RFC 3/4] slirp: add helpers for ipv6 hostfwd manipulation
Date: Fri, 26 Oct 2018 03:03:42 +0300	[thread overview]
Message-ID: <1540512223-21199-4-git-send-email-max7255@yandex-team.ru> (raw)
In-Reply-To: <1540512223-21199-1-git-send-email-max7255@yandex-team.ru>

Signed-off-by: Maxim Samoylov <max7255@yandex-team.ru>
---
 slirp/libslirp.h |  6 ++++++
 slirp/slirp.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 42e42e9..3710650 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -34,6 +34,12 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp,
                       struct in_addr guest_addr, int guest_port);
 int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
                          struct in_addr host_addr, int host_port);
+int slirp_add_ipv6_hostfwd(Slirp *slirp, int is_udp,
+                           struct in6_addr host_addr, int host_port,
+                           struct in6_addr guest_addr, int guest_port);
+int slirp_remove_ipv6_hostfwd(Slirp *slirp, int is_udp,
+                              struct in6_addr host_addr, int host_port);
+
 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
                    struct in_addr *guest_addr, int guest_port);
 
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 51de41f..143ddea 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -1065,6 +1065,49 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
     return 0;
 }
 
+int slirp_remove_ipv6_hostfwd(Slirp *slirp, int is_udp,
+                              struct in6_addr host_addr, int host_port)
+{
+    struct socket *so;
+    struct socket *head = (is_udp ? &slirp->udb : &slirp->tcb);
+    struct sockaddr_in6 addr;
+    int port = htons(host_port);
+    socklen_t addr_len;
+
+    for (so = head->so_next; so != head; so = so->so_next) {
+        addr_len = sizeof(addr);
+        if ((so->so_state & SS_HOSTFWD) &&
+            getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 &&
+            addr_len == sizeof(host_addr) &&
+            !memcmp(&host_addr, &addr, addr_len) &&
+            addr.sin6_port == port) {
+
+            close(so->s);
+            sofree(so);
+            return 0;
+        }
+    }
+
+    return -1;
+}
+
+int slirp_add_ipv6_hostfwd(Slirp *slirp, int is_udp,
+                          struct in6_addr host_addr, int host_port,
+                          struct in6_addr guest_addr, int guest_port)
+{
+    if (is_udp) {
+        if (!udp6_listen(slirp, host_addr, htons(host_port),
+                         guest_addr, htons(guest_port), SS_HOSTFWD))
+            return -1;
+    } else {
+        if (!tcp6_listen(slirp, host_addr, htons(host_port),
+                         guest_addr, htons(guest_port), SS_HOSTFWD))
+            return -1;
+    }
+
+    return 0;
+}
+
 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
                    struct in_addr *guest_addr, int guest_port)
 {
-- 
2.7.4

  parent reply	other threads:[~2018-10-26  0:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-26  0:03 [Qemu-devel] [PATCH RFC 0/4] slirp: support hostfwd for ipv6 addresses Maxim Samoylov
2018-10-26  0:03 ` [Qemu-devel] [PATCH RFC 1/4] slirp: add helper for tcp6 socket creation Maxim Samoylov
2018-10-27 11:11   ` Samuel Thibault
2018-10-27 11:13     ` Samuel Thibault
2018-10-30 13:58     ` Maxim Samoylov
2018-10-30 16:00       ` Samuel Thibault
2018-10-26  0:03 ` [Qemu-devel] [PATCH RFC 2/4] slirp: add helper for udp6 " Maxim Samoylov
2018-10-27 11:13   ` Samuel Thibault
2018-10-26  0:03 ` Maxim Samoylov [this message]
2018-10-27 11:23   ` [Qemu-devel] [PATCH RFC 3/4] slirp: add helpers for ipv6 hostfwd manipulation Samuel Thibault
2018-10-26  0:03 ` [Qemu-devel] [PATCH RFC 4/4] net/slirp: add ipv6-hostfwd option for user netdev type Maxim Samoylov
2018-10-26  6:14   ` Thomas Huth
2018-10-30 14:00     ` Maxim Samoylov
2018-10-27 11:38   ` Samuel Thibault
2018-11-05 23:05   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1540512223-21199-4-git-send-email-max7255@yandex-team.ru \
    --to=max7255@yandex-team.ru \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).