Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. From d5d1799dba61af8a263507839a9a2f92293093ae Mon Sep 17 00:00:00 2001
  2. From: Brent Cook <busterb@gmail.com>
  3. Date: Tue, 30 Dec 2014 09:05:46 -0600
  4. Subject: [PATCH 05/10] check if rdomain support is available.
  5. Handle FreeBSD's calling rdomain 'FIB'.
  6. - from naddy@openbsd.org
  7. ---
  8. src/usr.sbin/ntpd/client.c | 4 ++++
  9. src/usr.sbin/ntpd/ntpd.h | 6 ++++++
  10. src/usr.sbin/ntpd/parse.y | 2 ++
  11. src/usr.sbin/ntpd/server.c | 11 ++++++++++-
  12. 4 files changed, 22 insertions(+), 1 deletion(-)
  13. diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
  14. index 18aa81d..d47869b 100644
  15. --- a/src/usr.sbin/ntpd/client.c
  16. +++ b/src/usr.sbin/ntpd/client.c
  17. @@ -149,10 +149,12 @@ client_query(struct ntp_peer *p)
  18. fatal("client_query socket");
  19. }
  20. +#ifdef SO_RTABLE
  21. if (p->rtable != -1 &&
  22. setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
  23. &p->rtable, sizeof(p->rtable)) == -1)
  24. fatal("client_query setsockopt SO_RTABLE");
  25. +#endif
  26. if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
  27. if (errno == ECONNREFUSED || errno == ENETUNREACH ||
  28. errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
  29. @@ -255,10 +257,12 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
  30. return (0);
  31. }
  32. +#ifdef SO_RTABLE
  33. if (p->rtable != -1 &&
  34. setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE, &p->rtable,
  35. sizeof(p->rtable)) == -1)
  36. fatal("client_dispatch setsockopt SO_RTABLE");
  37. +#endif
  38. for (cmsg = CMSG_FIRSTHDR(&somsg); cmsg != NULL;
  39. cmsg = CMSG_NXTHDR(&somsg, cmsg)) {
  40. diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h
  41. index f6e3acf..28ab1ba 100644
  42. --- a/src/usr.sbin/ntpd/ntpd.h
  43. +++ b/src/usr.sbin/ntpd/ntpd.h
  44. @@ -41,6 +41,12 @@
  45. #define DRIFTFILE "/var/db/ntpd.drift"
  46. #define CTLSOCKET "/var/run/ntpd.sock"
  47. +#if defined(SO_SETFIB)
  48. +#define SO_RTABLE SO_SETFIB
  49. +#define SIOCGIFRDOMAIN SIOCGIFFIB
  50. +#define ifr_rdomainid ifr_fib
  51. +#endif
  52. +
  53. #define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
  54. #define INTERVAL_QUERY_PATHETIC 60
  55. #define INTERVAL_QUERY_AGGRESSIVE 5
  56. diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
  57. index 8faff66..ebf85ca 100644
  58. --- a/src/usr.sbin/ntpd/parse.y
  59. +++ b/src/usr.sbin/ntpd/parse.y
  60. @@ -412,11 +412,13 @@ weight : WEIGHT NUMBER {
  61. opts.weight = $2;
  62. }
  63. rtable : RTABLE NUMBER {
  64. +#ifdef RT_TABLEID_MAX
  65. if ($2 < 0 || $2 > RT_TABLEID_MAX) {
  66. yyerror("rtable must be between 1"
  67. " and RT_TABLEID_MAX");
  68. YYERROR;
  69. }
  70. +#endif
  71. opts.rtable = $2;
  72. }
  73. ;
  74. diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
  75. index dc58b32..0c0d3dc 100644
  76. --- a/src/usr.sbin/ntpd/server.c
  77. +++ b/src/usr.sbin/ntpd/server.c
  78. @@ -39,7 +39,10 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  79. u_int8_t *a6;
  80. size_t sa6len = sizeof(struct in6_addr);
  81. u_int new_cnt = 0;
  82. - int tos = IPTOS_LOWDELAY, rdomain, fd;
  83. + int tos = IPTOS_LOWDELAY;
  84. +#ifdef SO_RTABLE
  85. + int rdomain, fd;
  86. +#endif
  87. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  88. switch (lap->sa.ss_family) {
  89. @@ -59,6 +62,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  90. strlcpy(ifr.ifr_name, ifap->ifa_name,
  91. sizeof(ifr.ifr_name));
  92. +#ifdef SO_RTABLE
  93. fd = socket(AF_INET, SOCK_DGRAM, 0);
  94. if (ioctl(fd, SIOCGIFRDOMAIN,
  95. (caddr_t)&ifr) == -1)
  96. @@ -69,6 +73,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  97. if (lap->rtable != -1 && rdomain != lap->rtable)
  98. continue;
  99. +#endif
  100. if (sa->sa_family == AF_INET &&
  101. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  102. @@ -87,7 +92,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  103. fatal("setup_listeners calloc");
  104. memcpy(&la->sa, sa, SA_LEN(sa));
  105. +#ifdef SO_RTABLE
  106. la->rtable = rdomain;
  107. +#endif
  108. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  109. }
  110. @@ -132,10 +139,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  111. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  112. log_warn("setsockopt IPTOS_LOWDELAY");
  113. +#ifdef SO_RTABLE
  114. if (la->rtable != -1 &&
  115. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  116. sizeof(la->rtable)) == -1)
  117. fatal("setup_listeners setsockopt SO_RTABLE");
  118. +#endif
  119. if (bind(la->fd, (struct sockaddr *)&la->sa,
  120. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  121. --
  122. 1.9.1