diff mbox

[2/2] slirp: Send RDNSS in RA only if host has an IPv6 DNS server

Message ID 20170326184634.25042-3-samuel.thibault@ens-lyon.org
State New
Headers show

Commit Message

Samuel Thibault March 26, 2017, 6:46 p.m. UTC
Previously we would always send an RDNSS option in the RA, making the guest
try to resolve DNS through IPv6, even if the host does not actually have
and IPv6 DNS server available.

This makes the RDNSS option enabled only when an IPv6 DNS server is
available.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/ip6_icmp.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé March 27, 2017, 2:56 p.m. UTC | #1
Hi Samuel,

On 03/26/2017 03:46 PM, Samuel Thibault wrote:
> Previously we would always send an RDNSS option in the RA, making the guest
> try to resolve DNS through IPv6, even if the host does not actually have
> and IPv6 DNS server available.
>
> This makes the RDNSS option enabled only when an IPv6 DNS server is
> available.
>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  slirp/ip6_icmp.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
> index d0f5cc1456..00183e5945 100644
> --- a/slirp/ip6_icmp.c
> +++ b/slirp/ip6_icmp.c
> @@ -189,18 +189,22 @@ void ndp_send_ra(Slirp *slirp)
>      t->m_data += NDPOPT_PREFIXINFO_LEN;
>      pl_size += 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;
> -    pl_size += NDPOPT_RDNSS_LEN;
> -#endif
> +    {

Why don't declare at function begining and remove this { } ?
Else reading the file one might ask himself "what if () condition was 
missed here?".
Except this indentation issue the patch is Ok for me.

> +        struct in6_addr addr;
> +        uint32_t scope_id;
> +        if (get_dns6_addr(&addr, &scope_id) >= 0) {
> +            /* Host system does have an IPv6 DNS server, announce our proxy.  */
> +            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;
> +            pl_size += NDPOPT_RDNSS_LEN;
> +        }
> +    }
>
>      rip->ip_pl = htons(pl_size);
>      t->m_data -= sizeof(struct ip6) + pl_size;
>

Phil.
Samuel Thibault March 27, 2017, 3:04 p.m. UTC | #2
Hello,

Philippe Mathieu-Daudé, on lun. 27 mars 2017 11:56:00 -0300, wrote:
> Why don't declare at function begining and remove this { } ?

Oh, right, now I can.  While working on the code I still had ifdef
WIN32, so it'd lead to an unused variable warning.  But now that the
ifdef is gone, we can just put the variable at the beginning of the
function indeed.

Thanks,
Samuel
diff mbox

Patch

diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index d0f5cc1456..00183e5945 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -189,18 +189,22 @@  void ndp_send_ra(Slirp *slirp)
     t->m_data += NDPOPT_PREFIXINFO_LEN;
     pl_size += 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;
-    pl_size += NDPOPT_RDNSS_LEN;
-#endif
+    {
+        struct in6_addr addr;
+        uint32_t scope_id;
+        if (get_dns6_addr(&addr, &scope_id) >= 0) {
+            /* Host system does have an IPv6 DNS server, announce our proxy.  */
+            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;
+            pl_size += NDPOPT_RDNSS_LEN;
+        }
+    }
 
     rip->ip_pl = htons(pl_size);
     t->m_data -= sizeof(struct ip6) + pl_size;