From patchwork Mon Mar 28 23:44:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8680731 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8716CC0554 for ; Mon, 28 Mar 2016 23:46:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D54CD201FE for ; Mon, 28 Mar 2016 23:46:54 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 18139201CE for ; Mon, 28 Mar 2016 23:46:54 +0000 (UTC) Received: from localhost ([::1]:43561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgs1-0002YH-IH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Mar 2016 19:46:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgq2-0007Ji-0j for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akgpy-0006Eu-9b for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:49 -0400 Received: from domu-toccata.ens-lyon.fr ([140.77.166.138]:47090 helo=sonata.ens-lyon.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgpy-0006EE-2H for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:46 -0400 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 6846B200D7; Tue, 29 Mar 2016 01:44:44 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xDtRXtmMGnWX; Tue, 29 Mar 2016 01:44:44 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (LFbn-1-6757-94.w90-120.abo.wanadoo.fr [90.120.189.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 02276200D8; Tue, 29 Mar 2016 01:44:43 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.86_2) (envelope-from ) id 1akgpv-0007FS-6n; Tue, 29 Mar 2016 01:44:43 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Tue, 29 Mar 2016 01:44:38 +0200 Message-Id: <1459208679-27805-5-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1459208679-27805-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1459208679-27805-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: 140.77.166.138 Cc: thuth@redhat.com, jan.kiszka@siemens.com, jasowang@redhat.com, armbru@redhat.com, Samuel Thibault Subject: [Qemu-devel] [PATCH 4/5] slirp: Support link-local DNS addresses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP They look like fe80::%eth0 Signed-off-by: Samuel Thibault Reviewed-by: Thomas Huth --- slirp/libslirp.h | 2 +- slirp/slirp.c | 26 ++++++++++++++++++++++---- slirp/socket.c | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index b0cfbc5..81bd139 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -7,7 +7,7 @@ struct Slirp; typedef struct Slirp Slirp; int get_dns_addr(struct in_addr *pdns_addr); -int get_dns6_addr(struct in6_addr *pdns6_addr); +int get_dns6_addr(struct in6_addr *pdns6_addr, unsigned *scope_id); Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, struct in_addr vnetmask, struct in_addr vhost, diff --git a/slirp/slirp.c b/slirp/slirp.c index 3558b47..eaf843a 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -29,6 +29,10 @@ #include "slirp.h" #include "hw/hw.h" +#ifndef _WIN32 +#include +#endif + /* host loopback address */ struct in_addr loopback_addr; /* host loopback network mask */ @@ -137,13 +141,15 @@ static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, } static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, - socklen_t addrlen, u_int *cached_time) + socklen_t addrlen, unsigned *scope_id, + u_int *cached_time) { char buff[512]; char buff2[257]; FILE *f; int found = 0; void *tmp_addr = alloca(addrlen); + unsigned if_index; #ifdef DEBUG char s[INET6_ADDRSTRLEN]; #endif @@ -157,6 +163,14 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, #endif while (fgets(buff, 512, f) != NULL) { if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { + char *c = strchr(buff2, '%'); + if (c) { + if_index = if_nametoindex(c + 1); + *c = '\0'; + } else { + if_index = 0; + } + if (!inet_pton(af, buff2, tmp_addr)) { continue; } @@ -164,6 +178,9 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (!found) { memcpy(pdns_addr, tmp_addr, addrlen); memcpy(cached_addr, tmp_addr, addrlen); + if (scope_id) { + *scope_id = if_index; + } *cached_time = curtime; } #ifdef DEBUG @@ -201,12 +218,12 @@ int get_dns_addr(struct in_addr *pdns_addr) } } return get_dns_addr_resolv_conf(AF_INET, pdns_addr, &dns_addr, - sizeof(dns_addr), &dns_addr_time); + sizeof(dns_addr), NULL, &dns_addr_time); } static struct stat dns6_addr_stat; -int get_dns6_addr(struct in6_addr *pdns6_addr) +int get_dns6_addr(struct in6_addr *pdns6_addr, unsigned *scope_id) { if (!in6_zero(&dns6_addr)) { int ret; @@ -217,7 +234,8 @@ int get_dns6_addr(struct in6_addr *pdns6_addr) } } return get_dns_addr_resolv_conf(AF_INET6, pdns6_addr, &dns6_addr, - sizeof(dns6_addr), &dns6_addr_time); + sizeof(dns6_addr), + scope_id, &dns6_addr_time); } #endif diff --git a/slirp/socket.c b/slirp/socket.c index 653257d..896c27e 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -796,7 +796,7 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr) if (in6_equal_net(&so->so_faddr6, &slirp->vprefix_addr6, slirp->vprefix_len)) { if (in6_equal(&so->so_faddr6, &slirp->vnameserver_addr6)) { - if (get_dns6_addr(&sin6->sin6_addr) < 0) { + if (get_dns6_addr(&sin6->sin6_addr, &sin6->sin6_scope_id) < 0) { sin6->sin6_addr = in6addr_loopback; } } else {