qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Samuel Thibault <samuel.thibault@ens-lyon.org>, qemu-devel@nongnu.org
Cc: jan.kiszka@siemens.com, jasowang@redhat.com, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 4/5] slirp: Support link-local DNS addresses
Date: Wed, 30 Mar 2016 11:49:10 +0200	[thread overview]
Message-ID: <56FBA116.3050603@redhat.com> (raw)
In-Reply-To: <1459208679-27805-5-git-send-email-samuel.thibault@ens-lyon.org>

On 29.03.2016 01:44, Samuel Thibault wrote:
> They look like fe80::%eth0
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  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 <net/if.h>
> +#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 {
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>

  reply	other threads:[~2016-03-30  9:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-28 23:44 [Qemu-devel] [PATCH 0/5] ipv4-only and ipv6-only support Samuel Thibault
2016-03-28 23:44 ` [Qemu-devel] [PATCH 1/5] slirp: Allow disabling IPv4 or IPv6 Samuel Thibault
2016-03-30  8:38   ` Thomas Huth
2016-03-30 15:04     ` Samuel Thibault
2016-03-30 15:06       ` Thomas Huth
2016-03-30 15:13         ` Samuel Thibault
2016-03-30 15:29           ` Thomas Huth
2016-03-30 15:36             ` Samuel Thibault
2016-03-30 15:54               ` Eric Blake
2016-03-28 23:44 ` [Qemu-devel] [PATCH 2/5] slirp: Split get_dns_addr Samuel Thibault
2016-03-30  8:57   ` Thomas Huth
2016-03-28 23:44 ` [Qemu-devel] [PATCH 3/5] slirp: Add dns6 resolution Samuel Thibault
2016-03-30  9:32   ` Thomas Huth
2016-03-28 23:44 ` [Qemu-devel] [PATCH 4/5] slirp: Support link-local DNS addresses Samuel Thibault
2016-03-30  9:49   ` Thomas Huth [this message]
2016-03-28 23:44 ` [Qemu-devel] [PATCH 5/5] slirp: Add RDNSS advertisement Samuel Thibault
2016-03-30  9:55   ` Thomas Huth

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=56FBA116.3050603@redhat.com \
    --to=thuth@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=samuel.thibault@ens-lyon.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).