summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaspar Schleiser <kaspar@schleiser.de>2014-01-07 13:58:38 +0100
committerSteven Barth <steven@midlink.org>2014-01-27 14:16:44 +0100
commit62ea2821e389332d13cc05eb1ac6e77a7787f2db (patch)
tree73af795a9e69583e64dafc48d58a07b2cd3741f9
parent8152153cb9c5b09862bf0c8a0d1005fa8dfdf262 (diff)
downloadodhcp6c-62ea2821e389332d13cc05eb1ac6e77a7787f2db.tar.gz
fix NTP server option handling
previously, only option 56 (NTP server) was supported, but named SNTP_* throughout code and in the scripts environment. This patch fixes this and adds optnion 31 (SNTP Servers) support. Uses NTP_IP and NTP_FQDN and SNTP_IP in script environment. Contributed by T-Labs, Deutsche Telekom Innovation Laboratories
-rw-r--r--src/dhcpv6.c11
-rw-r--r--src/odhcp6c.c3
-rw-r--r--src/odhcp6c.h4
-rw-r--r--src/script.c8
4 files changed, 18 insertions, 8 deletions
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index 9e3d6c4..dca0ed4 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -163,6 +163,7 @@ int init_dhcpv6(const char *ifname, int request_pd, int sol_timeout)
htons(DHCPV6_OPT_SIP_SERVER_A),
htons(DHCPV6_OPT_DNS_SERVERS),
htons(DHCPV6_OPT_DNS_DOMAIN),
+ htons(DHCPV6_OPT_SNTP_SERVERS),
htons(DHCPV6_OPT_NTP_SERVER),
htons(DHCPV6_OPT_AFTR_NAME),
htons(DHCPV6_OPT_PD_EXCLUDE),
@@ -808,7 +809,8 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
odhcp6c_clear_state(STATE_DNS);
odhcp6c_clear_state(STATE_SEARCH);
odhcp6c_clear_state(STATE_SNTP_IP);
- odhcp6c_clear_state(STATE_SNTP_FQDN);
+ odhcp6c_clear_state(STATE_NTP_IP);
+ odhcp6c_clear_state(STATE_NTP_FQDN);
odhcp6c_clear_state(STATE_SIP_IP);
odhcp6c_clear_state(STATE_SIP_FQDN);
odhcp6c_clear_state(STATE_AFTR_NAME);
@@ -865,6 +867,9 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
odhcp6c_add_state(STATE_DNS, odata, olen);
} else if (otype == DHCPV6_OPT_DNS_DOMAIN) {
odhcp6c_add_state(STATE_SEARCH, odata, olen);
+ } else if (otype == DHCPV6_OPT_SNTP_SERVERS) {
+ if (olen % 16 == 0)
+ odhcp6c_add_state(STATE_SNTP_IP, odata, olen);
} else if (otype == DHCPV6_OPT_NTP_SERVER) {
uint16_t stype, slen;
uint8_t *sdata;
@@ -873,10 +878,10 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
stype, slen, sdata) {
if (slen == 16 && (stype == NTP_MC_ADDR ||
stype == NTP_SRV_ADDR))
- odhcp6c_add_state(STATE_SNTP_IP,
+ odhcp6c_add_state(STATE_NTP_IP,
sdata, slen);
else if (slen > 0 && stype == NTP_SRV_FQDN)
- odhcp6c_add_state(STATE_SNTP_FQDN,
+ odhcp6c_add_state(STATE_NTP_FQDN,
sdata, slen);
}
} else if (otype == DHCPV6_OPT_SIP_SERVER_A) {
diff --git a/src/odhcp6c.c b/src/odhcp6c.c
index e9937ad..2159363 100644
--- a/src/odhcp6c.c
+++ b/src/odhcp6c.c
@@ -226,7 +226,8 @@ int main(_unused int argc, char* const argv[])
odhcp6c_clear_state(STATE_IA_NA);
odhcp6c_clear_state(STATE_IA_PD);
odhcp6c_clear_state(STATE_SNTP_IP);
- odhcp6c_clear_state(STATE_SNTP_FQDN);
+ odhcp6c_clear_state(STATE_NTP_IP);
+ odhcp6c_clear_state(STATE_NTP_FQDN);
odhcp6c_clear_state(STATE_SIP_IP);
odhcp6c_clear_state(STATE_SIP_FQDN);
dhcpv6_set_ia_mode(ia_na_mode, ia_pd_mode);
diff --git a/src/odhcp6c.h b/src/odhcp6c.h
index d4458ff..e3c6c5e 100644
--- a/src/odhcp6c.h
+++ b/src/odhcp6c.h
@@ -49,6 +49,7 @@ enum dhcvp6_opt {
DHCPV6_OPT_DNS_DOMAIN = 24,
DHCPV6_OPT_IA_PD = 25,
DHCPV6_OPT_IA_PREFIX = 26,
+ DHCPV6_OPT_SNTP_SERVERS = 31,
DHCPV6_OPT_INFO_REFRESH = 32,
DHCPV6_OPT_FQDN = 39,
DHCPV6_OPT_NTP_SERVER = 56,
@@ -193,7 +194,8 @@ enum odhcp6c_state {
STATE_IA_PD,
STATE_CUSTOM_OPTS,
STATE_SNTP_IP,
- STATE_SNTP_FQDN,
+ STATE_NTP_IP,
+ STATE_NTP_FQDN,
STATE_SIP_IP,
STATE_SIP_FQDN,
STATE_RA_ROUTE,
diff --git a/src/script.c b/src/script.c
index e5b8341..5a021df 100644
--- a/src/script.c
+++ b/src/script.c
@@ -228,7 +228,7 @@ void script_delay_call(const char *status, int timeout)
void script_call(const char *status)
{
- size_t dns_len, search_len, custom_len, sntp_ip_len, sntp_dns_len;
+ size_t dns_len, search_len, custom_len, sntp_ip_len, ntp_ip_len, ntp_dns_len;
size_t sip_ip_len, sip_fqdn_len, aftr_name_len;
odhcp6c_expire();
@@ -241,7 +241,8 @@ void script_call(const char *status)
uint8_t *search = odhcp6c_get_state(STATE_SEARCH, &search_len);
uint8_t *custom = odhcp6c_get_state(STATE_CUSTOM_OPTS, &custom_len);
struct in6_addr *sntp = odhcp6c_get_state(STATE_SNTP_IP, &sntp_ip_len);
- uint8_t *sntp_dns = odhcp6c_get_state(STATE_SNTP_FQDN, &sntp_dns_len);
+ struct in6_addr *ntp = odhcp6c_get_state(STATE_NTP_IP, &ntp_ip_len);
+ uint8_t *ntp_dns = odhcp6c_get_state(STATE_NTP_FQDN, &ntp_dns_len);
struct in6_addr *sip = odhcp6c_get_state(STATE_SIP_IP, &sip_ip_len);
uint8_t *sip_fqdn = odhcp6c_get_state(STATE_SIP_FQDN, &sip_fqdn_len);
uint8_t *aftr_name = odhcp6c_get_state(STATE_AFTR_NAME, &aftr_name_len);
@@ -257,9 +258,10 @@ void script_call(const char *status)
if (fork() == 0) {
ipv6_to_env("RDNSS", dns, dns_len / sizeof(*dns));
ipv6_to_env("SNTP_IP", sntp, sntp_ip_len / sizeof(*sntp));
+ ipv6_to_env("NTP_IP", ntp, ntp_ip_len / sizeof(*ntp));
+ fqdn_to_env("NTP_FQDN", ntp_dns, ntp_dns_len);
ipv6_to_env("SIP_IP", sip, sip_ip_len / sizeof(*sip));
fqdn_to_env("DOMAINS", search, search_len);
- fqdn_to_env("SNTP_FQDN", sntp_dns, sntp_dns_len);
fqdn_to_env("SIP_DOMAIN", sip_fqdn, sip_fqdn_len);
fqdn_to_env("AFTR", aftr_name, aftr_name_len);
fqdn_to_ip_env("AFTR_IP", aftr_name, aftr_name_len);