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.

147 lines
4.5 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
9 years ago
9 years ago
9 years ago
9 years ago
  1. From 2e02b774dc28b1db74bd9c1837fd056c57234080 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/12] 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 | 15 ++++++++++++++-
  12. 4 files changed, 26 insertions(+), 1 deletion(-)
  13. diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
  14. index e717d69..2be1f93 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 de4cd84..5bdd7a7 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) && defined(FREEBSD_SO_RTABLE_ENABLED)
  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 4b9ef49..375f609 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 ef448d3..618cd8f 100644
  76. --- a/src/usr.sbin/ntpd/server.c
  77. +++ b/src/usr.sbin/ntpd/server.c
  78. @@ -35,11 +35,16 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  79. struct listen_addr *la, *nla, *lap;
  80. struct ifaddrs *ifa, *ifap;
  81. struct sockaddr *sa;
  82. +#ifdef SO_RTABLE
  83. struct if_data *ifd;
  84. +#endif
  85. u_int8_t *a6;
  86. size_t sa6len = sizeof(struct in6_addr);
  87. u_int new_cnt = 0;
  88. - int tos = IPTOS_LOWDELAY, rdomain = 0;
  89. + int tos = IPTOS_LOWDELAY;
  90. +#ifdef SO_RTABLE
  91. + int rdomain = 0;
  92. +#endif
  93. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  94. switch (lap->sa.ss_family) {
  95. @@ -51,15 +56,19 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  96. sa = ifap->ifa_addr;
  97. if (sa == NULL || SA_LEN(sa) == 0)
  98. continue;
  99. +#ifdef SO_RTABLE
  100. if (sa->sa_family == AF_LINK) {
  101. ifd = ifap->ifa_data;
  102. rdomain = ifd->ifi_rdomain;
  103. }
  104. +#endif
  105. if (sa->sa_family != AF_INET &&
  106. sa->sa_family != AF_INET6)
  107. continue;
  108. +#ifdef SO_RTABLE
  109. if (lap->rtable != -1 && rdomain != lap->rtable)
  110. continue;
  111. +#endif
  112. if (sa->sa_family == AF_INET &&
  113. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  114. @@ -78,7 +87,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  115. fatal("setup_listeners calloc");
  116. memcpy(&la->sa, sa, SA_LEN(sa));
  117. +#ifdef SO_RTABLE
  118. la->rtable = rdomain;
  119. +#endif
  120. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  121. }
  122. @@ -123,10 +134,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  123. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  124. log_warn("setsockopt IPTOS_LOWDELAY");
  125. +#ifdef SO_RTABLE
  126. if (la->rtable != -1 &&
  127. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  128. sizeof(la->rtable)) == -1)
  129. fatal("setup_listeners setsockopt SO_RTABLE");
  130. +#endif
  131. if (bind(la->fd, (struct sockaddr *)&la->sa,
  132. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  133. --
  134. 2.4.5