From patchwork Fri Oct 26 00:03:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: max7255 X-Patchwork-Id: 10656877 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 E0173109C for ; Fri, 26 Oct 2018 01:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D56462C571 for ; Fri, 26 Oct 2018 01:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9E522C57B; Fri, 26 Oct 2018 01:26:09 +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 5BD9A2C571 for ; Fri, 26 Oct 2018 01:26:09 +0000 (UTC) Received: from localhost ([::1]:57570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFqt3-0003i8-Bc 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]:37602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFpbm-0002v5-A8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFpbk-0007eJ-Hx for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:10 -0400 Received: from forwardcorp1j.cmail.yandex.net ([2a02:6b8:0:1630::190]:34832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFpbk-0007dL-0D for qemu-devel@nongnu.org; Thu, 25 Oct 2018 20:04:08 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id 637D920F69 for ; Fri, 26 Oct 2018 03:04:04 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id yiWmMSqtqQ-44rKuC3C; Fri, 26 Oct 2018 03:04:04 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1540512244; bh=DKbEDdhIJzUlQWUs0aXMGMSwUDYheHnIAu4V97dUgJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GX/SJEEdXcBTxKbSRQYPEWWzvlx9nHYyt69X74V1vCEQG3UQGfFb4Un5/9eVZyJNv VBhivIQ8WFQwLpkscBIedUJU8FqtIQVGuXhyTl0wmlnRSXEZdto1sVvKWcLzTVrkLc hq0WGWRNOBBLOTZZ9W0PZnQhoB/Ve9Z2R5e9diWA= 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-43FqBbMH; 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=DKbEDdhIJzUlQWUs0aXMGMSwUDYheHnIAu4V97dUgJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GX/SJEEdXcBTxKbSRQYPEWWzvlx9nHYyt69X74V1vCEQG3UQGfFb4Un5/9eVZyJNv VBhivIQ8WFQwLpkscBIedUJU8FqtIQVGuXhyTl0wmlnRSXEZdto1sVvKWcLzTVrkLc hq0WGWRNOBBLOTZZ9W0PZnQhoB/Ve9Z2R5e9diWA= 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:41 +0300 Message-Id: <1540512223-21199-3-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 2/4] slirp: add helper for udp6 socket creation 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/udp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ slirp/udp.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/slirp/udp.c b/slirp/udp.c index e5bf065..ab24935 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -366,3 +366,51 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, return so; } + +struct socket * +udp6_listen(Slirp *slirp, struct in6_addr haddr, u_int hport, + struct in6_addr laddr, u_int lport, int flags) +{ + struct sockaddr_in6 addr; + struct socket *so; + socklen_t addrlen = sizeof(addr); + + memset(&addr, 0, sizeof(addr)); + + so = socreate(slirp); + if (!so) { + return NULL; + } + so->s = qemu_socket(AF_INET6, SOCK_DGRAM, 0); + if (so->s < 0) { + sofree(so); + return NULL; + } + so->so_expire = curtime + SO_EXPIRE; + insque(so, &slirp->udb); + + addr.sin6_family = AF_INET6; + addr.sin6_addr = haddr; + addr.sin6_port = hport; + + if (bind(so->s, (struct sockaddr *)&addr, addrlen) < 0) { + udp_detach(so); + return NULL; + } + socket_set_fast_reuse(so->s); + + getsockname(so->s, (struct sockaddr *)&addr, &addrlen); + so->fhost.sin6 = addr; + sotranslate_accept(so); + so->so_lfamily = AF_INET6; + so->so_lport = lport; + so->so_laddr6 = laddr; + if (flags != SS_FACCEPTONCE) { + so->so_expire = 0; + } + + so->so_state &= SS_PERSISTENT_MASK; + so->so_state |= SS_ISFCONNECTED | flags; + + return so; +} diff --git a/slirp/udp.h b/slirp/udp.h index be657cf..862c6e8 100644 --- a/slirp/udp.h +++ b/slirp/udp.h @@ -80,6 +80,8 @@ int udp_attach(struct socket *, unsigned short af); void udp_detach(struct socket *); struct socket * udp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, int); +struct socket *udp6_listen(Slirp *slirp, struct in6_addr, u_int, + struct in6_addr, u_int, int); int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, struct sockaddr_in *daddr, int iptos);