230-ntpd_delayed_resolve.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --- a/networking/ntpd.c
  2. +++ b/networking/ntpd.c
  3. @@ -251,6 +251,7 @@ typedef struct {
  4. typedef struct {
  5. len_and_sockaddr *p_lsa;
  6. char *p_dotted;
  7. + char *p_hostname;
  8. int p_fd;
  9. int datapoint_idx;
  10. uint32_t lastpkt_refid;
  11. @@ -756,8 +757,9 @@ add_peers(const char *s)
  12. peer_t *p;
  13. p = xzalloc(sizeof(*p));
  14. - p->p_lsa = xhost2sockaddr(s, 123);
  15. - p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
  16. + p->p_hostname = s;
  17. + p->p_lsa = NULL;
  18. + p->p_dotted = NULL;
  19. p->p_fd = -1;
  20. p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3);
  21. p->next_action_time = G.cur_time; /* = set_next(p, 0); */
  22. @@ -806,6 +808,25 @@ send_query_to_peer(peer_t *p)
  23. *
  24. * Uncomment this and use strace to see it in action:
  25. */
  26. +
  27. + /* See if the peer hostname already resolved yet, if not, retry to resolv and return on failure */
  28. + if (!p->p_lsa)
  29. + {
  30. + p->p_lsa = host2sockaddr(p->p_hostname, 123);
  31. +
  32. + if (p->p_lsa)
  33. + {
  34. + p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
  35. + VERB1 bb_error_msg("resolved peer %s to %s", p->p_hostname, p->p_dotted);
  36. + }
  37. + else
  38. + {
  39. + set_next(p, RETRY_INTERVAL);
  40. + VERB1 bb_error_msg("could not resolve peer %s, skipping", p->p_hostname);
  41. + return;
  42. + }
  43. + }
  44. +
  45. #define PROBE_LOCAL_ADDR /* { len_and_sockaddr lsa; lsa.len = LSA_SIZEOF_SA; getsockname(p->query.fd, &lsa.u.sa, &lsa.len); } */
  46. if (p->p_fd == -1) {