From patchwork Fri Oct 26 00:03:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: max7255 X-Patchwork-Id: 10656873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8424114BB for ; Fri, 26 Oct 2018 01:26:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4EF2C571 for ; Fri, 26 Oct 2018 01:26:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5ED772C592; Fri, 26 Oct 2018 01:26:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 05D332C571 for ; Fri, 26 Oct 2018 01:26:05 +0000 (UTC) Received: from localhost ([::1]:57576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFqt3-0004uA-3W for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 21:26:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFpbm-0002v6-Af for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFpbk-0007eK-Hy for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:10 -0400 Received: from forwardcorp1j.cmail.yandex.net ([2a02:6b8:0:1630::190]:34835) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFpbk-0007dP-0C for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:08 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id 0F65F20F6F for ; Fri, 26 Oct 2018 03:04:05 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id RnuLfnKwEP-44xeEIHe; Fri, 26 Oct 2018 03:04:05 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1540512245; bh=FttTaZ5olyP43jy6tGDRHv2G9vKibYR95w4VTfl8s5I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GPDjsFI57OWRfXmsuQx9qZ02p7TG64dna3gl3WZXDUDf6zsEQxftfOuZYl+ZlIgbu fjp3yCy1My3Iz5ofgZsei4//x/08GPMRth/APTj16nmqGJCV5qw9uCvIwyXdEujME/ Hm9KHcFr+ZyUZIg4dIiexaI87lCBV1HSG4RngKGQ= Received: from dynamic-iva.dhcp.yndx.net (dynamic-iva.dhcp.yndx.net [2a02:6b8:b010:d002::1:1]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bOfpZ9lZrb-44FGPvXa; Fri, 26 Oct 2018 03:04:04 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1540512244; bh=FttTaZ5olyP43jy6tGDRHv2G9vKibYR95w4VTfl8s5I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=TL2jzTUGlBDCDyWVons0LgWGSZGah9QjsyLF9XIpWF25pqVtPGE4V61GHiar+/Xdb q7T23Z+W0UEWGp5x9BF+S/plpqkQq8KdnGewqErVh+GMGdgXs1mxsdSEJbJW7ELNdl bIJyurkZeHsa/dlhO8xcxN+Ui9s9Jx98HO3Oeoes= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Maxim Samoylov To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 03:03:42 +0300 Message-Id: <1540512223-21199-4-git-send-email-max7255@yandex-team.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540512223-21199-1-git-send-email-max7255@yandex-team.ru> References: <1540512223-21199-1-git-send-email-max7255@yandex-team.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1630::190 X-Mailman-Approved-At: Thu, 25 Oct 2018 21:24:29 -0400 Subject: [Qemu-devel] [PATCH RFC 3/4] slirp: add helpers for ipv6 hostfwd manipulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: max7255@yandex-team.ru Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Maxim Samoylov --- 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) {