Ticket #12167: 0001-busybox-make-ntpd-prefer-IPv6-addresses.patch

File 0001-busybox-make-ntpd-prefer-IPv6-addresses.patch, 3.3 KB (added by mwarning, 3 years ago)

Let ntpd prefer IPv6 over IPv4

  • new file package/utils/busybox/patches/231-ntpd_prefer_ipv6_address_and_then_alternate.patch

    From c9f15d342293eb66d22f8161f88384af640fae93 Mon Sep 17 00:00:00 2001
    From: Moritz Warning <moritzwarning@web.de>
    Date: Mon, 26 Jan 2015 19:07:59 +0100
    Subject: [PATCH 1/1] busybox: make ntpd prefer IPv6 addresses
    
    ntpd uses host2sockaddr to get the first address returned by DNS and does so only once.
    Since the first address is often an IPv4 address, this causes ntpd to fail in IPv6 only environments.
    This patch starts by requesting an IPv6 address and then alternate between AF_INET6 and AF_UNSPEC (which might likely return an IPv4 address).
    ---
     ...pd_prefer_ipv6_address_and_then_alternate.patch | 73 ++++++++++++++++++++++
     1 file changed, 73 insertions(+)
     create mode 100644 package/utils/busybox/patches/231-ntpd_prefer_ipv6_address_and_then_alternate.patch
    
    diff --git a/package/utils/busybox/patches/231-ntpd_prefer_ipv6_address_and_then_alternate.patch b/package/utils/busybox/patches/231-ntpd_prefer_ipv6_address_and_then_alternate.patch
    new file mode 100644
    index 0000000..1168261
    - +  
     1Index: busybox-1.22.1/networking/ntpd.c 
     2=================================================================== 
     3--- busybox-1.22.1.orig/networking/ntpd.c 
     4+++ busybox-1.22.1/networking/ntpd.c 
     5@@ -237,6 +237,9 @@ typedef struct { 
     6  
     7 typedef struct { 
     8        len_and_sockaddr *p_lsa; 
     9+#if ENABLE_FEATURE_IPV6 
     10+       int                             p_lookup_af; 
     11+#endif 
     12        char             *p_dotted; 
     13        char             *p_hostname; 
     14        int              p_fd; 
     15@@ -741,6 +744,9 @@ add_peers(char *s) 
     16        p = xzalloc(sizeof(*p)); 
     17        p->p_hostname = s; 
     18        p->p_lsa = NULL; 
     19+#if ENABLE_FEATURE_IPV6 
     20+       p->p_lookup_af = AF_INET6; /* Try IPv6 address first */ 
     21+#endif 
     22        p->p_dotted = NULL; 
     23        p->p_fd = -1; 
     24        p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); 
     25@@ -791,22 +797,33 @@ send_query_to_peer(peer_t *p) 
     26         * Uncomment this and use strace to see it in action: 
     27         */ 
     28  
     29-       /* See if the peer hostname already resolved yet, if not, retry to resolv and return on failure */ 
     30-       if (!p->p_lsa) 
     31-       { 
     32-               p->p_lsa = host2sockaddr(p->p_hostname, 123); 
     33+       if (p->p_lsa) { 
     34+               free( p->p_lsa ); 
     35+               free( p->p_dotted ); 
     36+               p->p_lsa = NULL; 
     37+               p->p_dotted = NULL; 
     38+       } 
     39  
     40-               if (p->p_lsa) 
     41-               { 
     42-                       p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); 
     43-                       VERB1 bb_error_msg("resolved peer %s to %s", p->p_hostname, p->p_dotted); 
     44-               } 
     45-               else 
     46-               { 
     47-                       set_next(p, RETRY_INTERVAL); 
     48-                       VERB1 bb_error_msg("could not resolve peer %s, skipping", p->p_hostname); 
     49-                       return; 
     50-               } 
     51+       /* Resolve hostname, return on failure */ 
     52+#if ENABLE_FEATURE_IPV6 
     53+       p->p_lsa = host_and_af2sockaddr(p->p_hostname, 123, p->p_lookup_af); 
     54+ 
     55+       /* Alternate between IPv6 and an unspecified protocol (will be IPv4 if present) */ 
     56+       p->p_lookup_af = (p->p_lookup_af == AF_INET6) ? AF_UNSPEC : AF_INET6; 
     57+#else 
     58+       p->p_lsa = host2sockaddr(p->p_hostname, 123); 
     59+#endif 
     60+ 
     61+       if (p->p_lsa) 
     62+       { 
     63+               p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); 
     64+               VERB1 bb_error_msg("resolved peer %s to %s", p->p_hostname, p->p_dotted); 
     65+       } 
     66+       else 
     67+       { 
     68+               set_next(p, RETRY_INTERVAL); 
     69+               VERB1 bb_error_msg("could not resolve peer %s, skipping", p->p_hostname); 
     70+               return; 
     71        } 
     72  
     73 #define PROBE_LOCAL_ADDR /* { len_and_sockaddr lsa; lsa.len = LSA_SIZEOF_SA; getsockname(p->query.fd, &lsa.u.sa, &lsa.len); } */