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.7 KiB

  1. From 0ec5710f4872d4feb8ff96b61d4d4a7ca0fa7b09 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 07/12] check if rdomain support is available
  5. ---
  6. src/usr.sbin/ntpd/client.c | 4 ++++
  7. src/usr.sbin/ntpd/parse.y | 2 ++
  8. src/usr.sbin/ntpd/server.c | 11 ++++++++++-
  9. 3 files changed, 16 insertions(+), 1 deletion(-)
  10. diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
  11. index e59112a..9b9b522 100644
  12. --- a/src/usr.sbin/ntpd/client.c
  13. +++ b/src/usr.sbin/ntpd/client.c
  14. @@ -142,10 +142,12 @@ client_query(struct ntp_peer *p)
  15. 0)) == -1)
  16. fatal("client_query socket");
  17. +#ifdef SO_RTABLE
  18. if (p->rtable != -1 &&
  19. setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
  20. &p->rtable, sizeof(p->rtable)) == -1)
  21. fatal("client_query setsockopt SO_RTABLE");
  22. +#endif
  23. if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
  24. if (errno == ECONNREFUSED || errno == ENETUNREACH ||
  25. errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
  26. @@ -248,10 +250,12 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
  27. return (0);
  28. }
  29. +#ifdef SO_RTABLE
  30. if (p->rtable != -1 &&
  31. setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE, &p->rtable,
  32. sizeof(p->rtable)) == -1)
  33. fatal("client_dispatch setsockopt SO_RTABLE");
  34. +#endif
  35. for (cmsg = CMSG_FIRSTHDR(&somsg); cmsg != NULL;
  36. cmsg = CMSG_NXTHDR(&somsg, cmsg)) {
  37. diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
  38. index fb6e2f1..3f4065f 100644
  39. --- a/src/usr.sbin/ntpd/parse.y
  40. +++ b/src/usr.sbin/ntpd/parse.y
  41. @@ -313,10 +313,12 @@ weight : WEIGHT NUMBER {
  42. opts.weight = $2;
  43. }
  44. rtable : RTABLE NUMBER {
  45. +#ifdef RT_TABLEID_MAX
  46. if ($2 < 0 || $2 > RT_TABLEID_MAX) {
  47. yyerror("rtable must be between 1 and RT_TABLEID_MAX");
  48. YYERROR;
  49. }
  50. +#endif
  51. opts.rtable = $2;
  52. }
  53. ;
  54. diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
  55. index 2dbb01f..3c74c24 100644
  56. --- a/src/usr.sbin/ntpd/server.c
  57. +++ b/src/usr.sbin/ntpd/server.c
  58. @@ -39,7 +39,10 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  59. u_int8_t *a6;
  60. size_t sa6len = sizeof(struct in6_addr);
  61. u_int new_cnt = 0;
  62. - int tos = IPTOS_LOWDELAY, rdomain, fd;
  63. + int tos = IPTOS_LOWDELAY;
  64. +#ifdef SO_RTABLE
  65. + int rdomain, fd;
  66. +#endif
  67. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  68. switch (lap->sa.ss_family) {
  69. @@ -59,6 +62,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  70. strlcpy(ifr.ifr_name, ifap->ifa_name,
  71. sizeof(ifr.ifr_name));
  72. +#ifdef SO_RTABLE
  73. fd = socket(AF_INET, SOCK_DGRAM, 0);
  74. if (ioctl(fd, SIOCGIFRDOMAIN,
  75. (caddr_t)&ifr) == -1)
  76. @@ -69,6 +73,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  77. if (lap->rtable != -1 && rdomain != lap->rtable)
  78. continue;
  79. +#endif
  80. if (sa->sa_family == AF_INET &&
  81. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  82. @@ -87,7 +92,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  83. fatal("setup_listeners calloc");
  84. memcpy(&la->sa, sa, SA_LEN(sa));
  85. +#ifdef SO_RTABLE
  86. la->rtable = rdomain;
  87. +#endif
  88. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  89. }
  90. @@ -132,10 +139,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  91. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  92. log_warn("setsockopt IPTOS_LOWDELAY");
  93. +#ifdef SO_RTABLE
  94. if (la->rtable != -1 &&
  95. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  96. sizeof(la->rtable)) == -1)
  97. fatal("setup_listeners setsockopt SO_RTABLE");
  98. +#endif
  99. if (bind(la->fd, (struct sockaddr *)&la->sa,
  100. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  101. --
  102. 1.9.1