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.

136 lines
4.3 KiB

10 years ago
  1. From 61ae467395cfbd7675ad2731e7db7f84b2ab39fd 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 08/11] 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 c18d8c5..a06d5fe 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 464353c..e5e7f4e 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 74e3fcd..09a6d9d 100644
  58. --- a/src/usr.sbin/ntpd/parse.y
  59. +++ b/src/usr.sbin/ntpd/parse.y
  60. @@ -313,10 +313,12 @@ 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 and RT_TABLEID_MAX");
  67. YYERROR;
  68. }
  69. +#endif
  70. opts.rtable = $2;
  71. }
  72. ;
  73. diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
  74. index 2dbb01f..3c74c24 100644
  75. --- a/src/usr.sbin/ntpd/server.c
  76. +++ b/src/usr.sbin/ntpd/server.c
  77. @@ -39,7 +39,10 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  78. u_int8_t *a6;
  79. size_t sa6len = sizeof(struct in6_addr);
  80. u_int new_cnt = 0;
  81. - int tos = IPTOS_LOWDELAY, rdomain, fd;
  82. + int tos = IPTOS_LOWDELAY;
  83. +#ifdef SO_RTABLE
  84. + int rdomain, fd;
  85. +#endif
  86. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  87. switch (lap->sa.ss_family) {
  88. @@ -59,6 +62,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  89. strlcpy(ifr.ifr_name, ifap->ifa_name,
  90. sizeof(ifr.ifr_name));
  91. +#ifdef SO_RTABLE
  92. fd = socket(AF_INET, SOCK_DGRAM, 0);
  93. if (ioctl(fd, SIOCGIFRDOMAIN,
  94. (caddr_t)&ifr) == -1)
  95. @@ -69,6 +73,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  96. if (lap->rtable != -1 && rdomain != lap->rtable)
  97. continue;
  98. +#endif
  99. if (sa->sa_family == AF_INET &&
  100. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  101. @@ -87,7 +92,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  102. fatal("setup_listeners calloc");
  103. memcpy(&la->sa, sa, SA_LEN(sa));
  104. +#ifdef SO_RTABLE
  105. la->rtable = rdomain;
  106. +#endif
  107. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  108. }
  109. @@ -132,10 +139,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  110. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  111. log_warn("setsockopt IPTOS_LOWDELAY");
  112. +#ifdef SO_RTABLE
  113. if (la->rtable != -1 &&
  114. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  115. sizeof(la->rtable)) == -1)
  116. fatal("setup_listeners setsockopt SO_RTABLE");
  117. +#endif
  118. if (bind(la->fd, (struct sockaddr *)&la->sa,
  119. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  120. --
  121. 1.9.1