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

From 991f5af3c5543d4e1870e35392c9eda53ae89dcc Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:05:46 -0600
Subject: [PATCH 07/12] check if rdomain support is available.
Handle FreeBSD's calling rdomain 'FIB'.
- from naddy@openbsd.org
---
src/usr.sbin/ntpd/client.c | 4 ++++
src/usr.sbin/ntpd/ntpd.h | 6 ++++++
src/usr.sbin/ntpd/parse.y | 2 ++
src/usr.sbin/ntpd/server.c | 11 ++++++++++-
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
index 3d4714e..339120b 100644
--- a/src/usr.sbin/ntpd/client.c
+++ b/src/usr.sbin/ntpd/client.c
@@ -149,10 +149,12 @@ client_query(struct ntp_peer *p)
fatal("client_query socket");
}
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
&p->rtable, sizeof(p->rtable)) == -1)
fatal("client_query setsockopt SO_RTABLE");
+#endif
if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
@@ -255,10 +257,12 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
return (0);
}
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE, &p->rtable,
sizeof(p->rtable)) == -1)
fatal("client_dispatch setsockopt SO_RTABLE");
+#endif
for (cmsg = CMSG_FIRSTHDR(&somsg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&somsg, cmsg)) {
diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h
index 45e14bb..03d6b0c 100644
--- a/src/usr.sbin/ntpd/ntpd.h
+++ b/src/usr.sbin/ntpd/ntpd.h
@@ -41,6 +41,12 @@
#define DRIFTFILE "/var/db/ntpd.drift"
#define CTLSOCKET "/var/run/ntpd.sock"
+#if defined(SO_SETFIB)
+#define SO_RTABLE SO_SETFIB
+#define SIOCGIFRDOMAIN SIOCGIFFIB
+#define ifr_rdomainid ifr_fib
+#endif
+
#define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
#define INTERVAL_QUERY_PATHETIC 60
#define INTERVAL_QUERY_AGGRESSIVE 5
diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
index f3db4ae..42a49f7 100644
--- a/src/usr.sbin/ntpd/parse.y
+++ b/src/usr.sbin/ntpd/parse.y
@@ -307,10 +307,12 @@ weight : WEIGHT NUMBER {
opts.weight = $2;
}
rtable : RTABLE NUMBER {
+#ifdef RT_TABLEID_MAX
if ($2 < 0 || $2 > RT_TABLEID_MAX) {
yyerror("rtable must be between 1 and RT_TABLEID_MAX");
YYERROR;
}
+#endif
opts.rtable = $2;
}
;
diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
index 66d8bbe..f17891f 100644
--- a/src/usr.sbin/ntpd/server.c
+++ b/src/usr.sbin/ntpd/server.c
@@ -39,7 +39,10 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
u_int8_t *a6;
size_t sa6len = sizeof(struct in6_addr);
u_int new_cnt = 0;
- int tos = IPTOS_LOWDELAY, rdomain, fd;
+ int tos = IPTOS_LOWDELAY;
+#ifdef SO_RTABLE
+ int rdomain, fd;
+#endif
TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
switch (lap->sa.ss_family) {
@@ -59,6 +62,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
strlcpy(ifr.ifr_name, ifap->ifa_name,
sizeof(ifr.ifr_name));
+#ifdef SO_RTABLE
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (ioctl(fd, SIOCGIFRDOMAIN,
(caddr_t)&ifr) == -1)
@@ -69,6 +73,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
if (lap->rtable != -1 && rdomain != lap->rtable)
continue;
+#endif
if (sa->sa_family == AF_INET &&
((struct sockaddr_in *)sa)->sin_addr.s_addr ==
@@ -87,7 +92,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
fatal("setup_listeners calloc");
memcpy(&la->sa, sa, SA_LEN(sa));
+#ifdef SO_RTABLE
la->rtable = rdomain;
+#endif
TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
}
@@ -132,10 +139,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
log_warn("setsockopt IPTOS_LOWDELAY");
+#ifdef SO_RTABLE
if (la->rtable != -1 &&
setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
sizeof(la->rtable)) == -1)
fatal("setup_listeners setsockopt SO_RTABLE");
+#endif
if (bind(la->fd, (struct sockaddr *)&la->sa,
SA_LEN((struct sockaddr *)&la->sa)) == -1) {
--
1.9.1