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 2/5] slirp: Split get_dns_addr
Date: Wed, 30 Mar 2016 10:57:03 +0200	[thread overview]
Message-ID: <56FB94DF.1090408@redhat.com> (raw)
In-Reply-To: <1459208679-27805-3-git-send-email-samuel.thibault@ens-lyon.org>

On 29.03.2016 01:44, Samuel Thibault wrote:
> Separate get_dns_addr into get_dns_addr_cached and get_dns_addr_resolv_conf
> to make conversion to IPv6 easier.
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  slirp/slirp.c | 53 ++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 34 insertions(+), 19 deletions(-)
> 
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 6256c89..2f0d3a3 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -108,7 +108,28 @@ static void winsock_cleanup(void)
>  
>  static struct stat dns_addr_stat;
>  
> -int get_dns_addr(struct in_addr *pdns_addr)
> +static int get_dns_addr_cached(struct in_addr *pdns_addr)
> +{
> +    struct stat old_stat;
> +    if ((curtime - dns_addr_time) < TIMEOUT_DEFAULT) {

Cosmetic nit: While you're at it, you could also remove the superfluous
parentheses here.

> +        *pdns_addr = dns_addr;
> +        return 0;
> +    }
> +    old_stat = dns_addr_stat;
> +    if (stat("/etc/resolv.conf", &dns_addr_stat) != 0) {
> +        return -1;
> +    }
> +    if ((dns_addr_stat.st_dev == old_stat.st_dev)
> +        && (dns_addr_stat.st_ino == old_stat.st_ino)
> +        && (dns_addr_stat.st_size == old_stat.st_size)
> +        && (dns_addr_stat.st_mtime == old_stat.st_mtime)) {

dito.

> +        *pdns_addr = dns_addr;
> +        return 0;
> +    }
> +    return 1;
> +}
> +
> +static int get_dns_addr_resolv_conf(struct in_addr *pdns_addr)
>  {
>      char buff[512];
>      char buff2[257];
> @@ -116,24 +137,6 @@ int get_dns_addr(struct in_addr *pdns_addr)
>      int found = 0;
>      struct in_addr tmp_addr;
>  
> -    if (dns_addr.s_addr != 0) {
> -        struct stat old_stat;
> -        if ((curtime - dns_addr_time) < TIMEOUT_DEFAULT) {
> -            *pdns_addr = dns_addr;
> -            return 0;
> -        }
> -        old_stat = dns_addr_stat;
> -        if (stat("/etc/resolv.conf", &dns_addr_stat) != 0)
> -            return -1;
> -        if ((dns_addr_stat.st_dev == old_stat.st_dev)
> -            && (dns_addr_stat.st_ino == old_stat.st_ino)
> -            && (dns_addr_stat.st_size == old_stat.st_size)
> -            && (dns_addr_stat.st_mtime == old_stat.st_mtime)) {
> -            *pdns_addr = dns_addr;
> -            return 0;
> -        }
> -    }
> -
>      f = fopen("/etc/resolv.conf", "r");
>      if (!f)
>          return -1;
> @@ -173,6 +176,18 @@ int get_dns_addr(struct in_addr *pdns_addr)
>      return 0;
>  }
>  
> +int get_dns_addr(struct in_addr *pdns_addr)
> +{
> +    if (dns_addr.s_addr != 0) {
> +        int ret;
> +        ret = get_dns_addr_cached(pdns_addr);
> +        if (ret <= 0) {
> +            return ret;
> +        }
> +    }
> +    return get_dns_addr_resolv_conf(pdns_addr);
> +}
> +
>  #endif
>  
>  static void slirp_init_once(void)
> 

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

  reply	other threads:[~2016-03-30  8:57 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 [this message]
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
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=56FB94DF.1090408@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).