From patchwork Sun Jul 3 22:04:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 9211465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 781A260752 for ; Sun, 3 Jul 2016 22:05:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65F12285C8 for ; Sun, 3 Jul 2016 22:05:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A90428607; Sun, 3 Jul 2016 22:05:36 +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=-6.9 required=2.0 tests=BAYES_00,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 E51C9285C8 for ; Sun, 3 Jul 2016 22:05:35 +0000 (UTC) Received: from localhost ([::1]:44285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJpWB-0004Wt-2A for patchwork-qemu-devel@patchwork.kernel.org; Sun, 03 Jul 2016 18:05:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJpVa-0004UP-EZ for qemu-devel@nongnu.org; Sun, 03 Jul 2016 18:04:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJpVU-0001zH-FA for qemu-devel@nongnu.org; Sun, 03 Jul 2016 18:04:57 -0400 Received: from hera.aquilenet.fr ([141.255.128.1]:38971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJpVU-0001yj-4d for qemu-devel@nongnu.org; Sun, 03 Jul 2016 18:04:52 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 160AB3D3; Mon, 4 Jul 2016 00:04:44 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yHHYVM61XqqM; Mon, 4 Jul 2016 00:04:43 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:1af:4600:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9C5808CA9; Mon, 4 Jul 2016 00:04:43 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1bJpVP-0002DM-45; Mon, 04 Jul 2016 00:04:47 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Mon, 4 Jul 2016 00:04:41 +0200 Message-Id: <1467583483-8462-5-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1467583483-8462-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1467583483-8462-1-git-send-email-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 141.255.128.1 Subject: [Qemu-devel] [PULL 4/6] slirp: Add RDNSS advertisement 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: Samuel Thibault , jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds the RDNSS option to IPv6 router advertisements, so that the guest can autoconfigure the DNS server address. Signed-off-by: Samuel Thibault Reviewed-by: Thomas Huth --- Changes since last submission: - Disable on windows, until we have support for it --- slirp/ip6_icmp.c | 27 ++++++++++++++++++++++++--- slirp/ip6_icmp.h | 12 ++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 48016a9..6d18e28 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -148,7 +148,11 @@ void ndp_send_ra(Slirp *slirp) rip->ip_nh = IPPROTO_ICMPV6; rip->ip_pl = htons(ICMP6_NDP_RA_MINLEN + NDPOPT_LINKLAYER_LEN - + NDPOPT_PREFIXINFO_LEN); + + NDPOPT_PREFIXINFO_LEN +#ifndef _WIN32 + + NDPOPT_RDNSS_LEN +#endif + ); t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); /* Build ICMPv6 packet */ @@ -166,16 +170,16 @@ void ndp_send_ra(Slirp *slirp) ricmp->icmp6_nra.lifetime = htons(NDP_AdvDefaultLifetime); ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime); ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime); + t->m_data += ICMP6_NDP_RA_MINLEN; /* Source link-layer address (NDP option) */ - t->m_data += ICMP6_NDP_RA_MINLEN; struct ndpopt *opt = mtod(t, struct ndpopt *); opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE; opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer); + t->m_data += NDPOPT_LINKLAYER_LEN; /* Prefix information (NDP option) */ - t->m_data += NDPOPT_LINKLAYER_LEN; struct ndpopt *opt2 = mtod(t, struct ndpopt *); opt2->ndpopt_type = NDPOPT_PREFIX_INFO; opt2->ndpopt_len = NDPOPT_PREFIXINFO_LEN / 8; @@ -187,8 +191,25 @@ void ndp_send_ra(Slirp *slirp) opt2->ndpopt_prefixinfo.pref_lt = htonl(NDP_AdvPrefLifetime); opt2->ndpopt_prefixinfo.reserved2 = 0; opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6; + t->m_data += NDPOPT_PREFIXINFO_LEN; + +#ifndef _WIN32 + /* Prefix information (NDP option) */ + /* disabled for windows for now, until get_dns6_addr is implemented */ + struct ndpopt *opt3 = mtod(t, struct ndpopt *); + opt3->ndpopt_type = NDPOPT_RDNSS; + opt3->ndpopt_len = NDPOPT_RDNSS_LEN / 8; + opt3->ndpopt_rdnss.reserved = 0; + opt3->ndpopt_rdnss.lifetime = htonl(2 * NDP_MaxRtrAdvInterval); + opt3->ndpopt_rdnss.addr = slirp->vnameserver_addr6; + t->m_data += NDPOPT_RDNSS_LEN; +#endif /* ICMPv6 Checksum */ +#ifndef _WIN32 + t->m_data -= NDPOPT_RDNSS_LEN; +#endif + t->m_data -= NDPOPT_PREFIXINFO_LEN; t->m_data -= NDPOPT_LINKLAYER_LEN; t->m_data -= ICMP6_NDP_RA_MINLEN; t->m_data -= sizeof(struct ip6); diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h index 9460bf8..2282d29 100644 --- a/slirp/ip6_icmp.h +++ b/slirp/ip6_icmp.h @@ -122,6 +122,7 @@ struct ndpopt { uint8_t ndpopt_len; /* /!\ In units of 8 octets */ union { unsigned char linklayer_addr[6]; /* Source/Target Link-layer */ +#define ndpopt_linklayer ndpopt_body.linklayer_addr struct prefixinfo { /* Prefix Information */ uint8_t prefix_length; #ifdef HOST_WORDS_BIGENDIAN @@ -134,19 +135,26 @@ struct ndpopt { uint32_t reserved2; struct in6_addr prefix; } QEMU_PACKED prefixinfo; - } ndpopt_body; -#define ndpopt_linklayer ndpopt_body.linklayer_addr #define ndpopt_prefixinfo ndpopt_body.prefixinfo + struct rdnss { + uint16_t reserved; + uint32_t lifetime; + struct in6_addr addr; + } QEMU_PACKED rdnss; +#define ndpopt_rdnss ndpopt_body.rdnss + } ndpopt_body; } QEMU_PACKED; /* NDP options type */ #define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */ #define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */ #define NDPOPT_PREFIX_INFO 3 /* Prefix Information */ +#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */ /* NDP options size, in octets. */ #define NDPOPT_LINKLAYER_LEN 8 #define NDPOPT_PREFIXINFO_LEN 32 +#define NDPOPT_RDNSS_LEN 24 /* * Definition of type and code field values.