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.

98 lines
2.9 KiB

4 years ago
8 years ago
4 years ago
4 years ago
4 years ago
  1. From 9e3c26b3a97be2a6f381edff36cf410eda895798 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/18] check if rdomain support is available.
  5. Handle FreeBSD's calling rdomain 'FIB'.
  6. - from naddy@openbsd.org
  7. ---
  8. src/usr.sbin/ntpd/parse.y | 2 ++
  9. src/usr.sbin/ntpd/server.c | 15 ++++++++++++++-
  10. 2 files changed, 16 insertions(+), 1 deletion(-)
  11. diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
  12. index ab87872cfe..4a101bcd6d 100644
  13. --- a/src/usr.sbin/ntpd/parse.y
  14. +++ b/src/usr.sbin/ntpd/parse.y
  15. @@ -479,11 +479,13 @@ weight : WEIGHT NUMBER {
  16. opts.weight = $2;
  17. }
  18. rtable : RTABLE NUMBER {
  19. +#ifdef RT_TABLEID_MAX
  20. if ($2 < 0 || $2 > RT_TABLEID_MAX) {
  21. yyerror("rtable must be between 1"
  22. " and RT_TABLEID_MAX");
  23. YYERROR;
  24. }
  25. +#endif
  26. opts.rtable = $2;
  27. }
  28. ;
  29. diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
  30. index 123b6939a2..8c18eb7610 100644
  31. --- a/src/usr.sbin/ntpd/server.c
  32. +++ b/src/usr.sbin/ntpd/server.c
  33. @@ -35,11 +35,16 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  34. struct listen_addr *la, *nla, *lap;
  35. struct ifaddrs *ifa, *ifap;
  36. struct sockaddr *sa;
  37. +#ifdef SO_RTABLE
  38. struct if_data *ifd;
  39. +#endif
  40. u_int8_t *a6;
  41. size_t sa6len = sizeof(struct in6_addr);
  42. u_int new_cnt = 0;
  43. - int tos = IPTOS_LOWDELAY, rdomain = 0;
  44. + int tos = IPTOS_LOWDELAY;
  45. +#ifdef SO_RTABLE
  46. + int rdomain = 0;
  47. +#endif
  48. TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
  49. switch (lap->sa.ss_family) {
  50. @@ -51,15 +56,19 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  51. sa = ifap->ifa_addr;
  52. if (sa == NULL || SA_LEN(sa) == 0)
  53. continue;
  54. +#ifdef SO_RTABLE
  55. if (sa->sa_family == AF_LINK) {
  56. ifd = ifap->ifa_data;
  57. rdomain = ifd->ifi_rdomain;
  58. }
  59. +#endif
  60. if (sa->sa_family != AF_INET &&
  61. sa->sa_family != AF_INET6)
  62. continue;
  63. +#ifdef SO_RTABLE
  64. if (lap->rtable != -1 && rdomain != lap->rtable)
  65. continue;
  66. +#endif
  67. if (sa->sa_family == AF_INET &&
  68. ((struct sockaddr_in *)sa)->sin_addr.s_addr ==
  69. @@ -78,7 +87,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  70. fatal("setup_listeners calloc");
  71. memcpy(&la->sa, sa, SA_LEN(sa));
  72. +#ifdef SO_RTABLE
  73. la->rtable = rdomain;
  74. +#endif
  75. TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
  76. }
  77. @@ -123,10 +134,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
  78. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  79. log_warn("setsockopt IPTOS_LOWDELAY");
  80. +#ifdef SO_RTABLE
  81. if (la->rtable != -1 &&
  82. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  83. sizeof(la->rtable)) == -1)
  84. fatal("setup_listeners setsockopt SO_RTABLE");
  85. +#endif
  86. if (bind(la->fd, (struct sockaddr *)&la->sa,
  87. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  88. --
  89. 2.27.0