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.

116 lines
3.4 KiB

8 years ago
8 years ago
8 years ago
  1. From cc20e4c83593f1fc5f6616b944a30a51afe94730 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 04/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/ntpd.h | 6 ++++++
  9. src/usr.sbin/ntpd/parse.y | 2 ++
  10. src/usr.sbin/ntpd/server.c | 15 ++++++++++++++-
  11. 3 files changed, 22 insertions(+), 1 deletion(-)
  12. diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h
  13. index 3089c14..1d46c6c 100644
  14. --- a/src/usr.sbin/ntpd/ntpd.h
  15. +++ b/src/usr.sbin/ntpd/ntpd.h
  16. @@ -40,6 +40,12 @@
  17. #define DRIFTFILE "/var/db/ntpd.drift"
  18. #define CTLSOCKET "/var/run/ntpd.sock"
  19. +#if defined(SO_SETFIB)
  20. +#define SO_RTABLE SO_SETFIB
  21. +#define SIOCGIFRDOMAIN SIOCGIFFIB
  22. +#define ifr_rdomainid ifr_fib
  23. +#endif
  24. +
  25. #define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
  26. #define INTERVAL_QUERY_PATHETIC 60
  27. #define INTERVAL_QUERY_AGGRESSIVE 5
  28. diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
  29. index 6d50795..33fe13d 100644
  30. --- a/src/usr.sbin/ntpd/parse.y
  31. +++ b/src/usr.sbin/ntpd/parse.y
  32. @@ -404,11 +404,13 @@ weight : WEIGHT NUMBER {
  33. opts.weight = $2;
  34. }
  35. rtable : RTABLE NUMBER {
  36. +#ifdef RT_TABLEID_MAX
  37. if ($2 < 0 || $2 > RT_TABLEID_MAX) {
  38. yyerror("rtable must be between 1"
  39. " and RT_TABLEID_MAX");
  40. YYERROR;
  41. }
  42. +#endif
  43. opts.rtable = $2;
  44. }
  45. ;
  46. diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
  47. index fb297d7..2e28b9b 100644
  48. --- a/src/usr.sbin/ntpd/server.c
  49. +++ b/src/usr.sbin/ntpd/server.c
  50. @@ -35,11 +35,16 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  51. struct listen_addr *la, *nla, *lap;
  52. struct ifaddrs *ifa, *ifap;
  53. struct sockaddr *sa;
  54. +#ifdef SO_RTABLE
  55. struct if_data *ifd;
  56. +#endif
  57. u_int8_t *a6;
  58. size_t sa6len = sizeof(struct in6_addr);
  59. u_int new_cnt = 0;
  60. - int tos = IPTOS_LOWDELAY, rdomain = 0;
  61. + int tos = IPTOS_LOWDELAY;
  62. +#ifdef SO_RTABLE
  63. + int rdomain = 0;
  64. +#endif
  65. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  66. switch (lap->sa.ss_family) {
  67. @@ -51,15 +56,19 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  68. sa = ifap->ifa_addr;
  69. if (sa == NULL || SA_LEN(sa) == 0)
  70. continue;
  71. +#ifdef SO_RTABLE
  72. if (sa->sa_family == AF_LINK) {
  73. ifd = ifap->ifa_data;
  74. rdomain = ifd->ifi_rdomain;
  75. }
  76. +#endif
  77. if (sa->sa_family != AF_INET &&
  78. sa->sa_family != AF_INET6)
  79. continue;
  80. +#ifdef SO_RTABLE
  81. if (lap->rtable != -1 && rdomain != lap->rtable)
  82. continue;
  83. +#endif
  84. if (sa->sa_family == AF_INET &&
  85. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  86. @@ -78,7 +87,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  87. fatal("setup_listeners calloc");
  88. memcpy(&la->sa, sa, SA_LEN(sa));
  89. +#ifdef SO_RTABLE
  90. la->rtable = rdomain;
  91. +#endif
  92. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  93. }
  94. @@ -123,10 +134,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  95. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  96. log_warn("setsockopt IPTOS_LOWDELAY");
  97. +#ifdef SO_RTABLE
  98. if (la->rtable != -1 &&
  99. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  100. sizeof(la->rtable)) == -1)
  101. fatal("setup_listeners setsockopt SO_RTABLE");
  102. +#endif
  103. if (bind(la->fd, (struct sockaddr *)&la->sa,
  104. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  105. --
  106. 2.7.0