]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
fix NTP server option handling
authorKaspar Schleiser <kaspar@schleiser.de>
Tue, 7 Jan 2014 12:58:38 +0000 (13:58 +0100)
committerSteven Barth <steven@midlink.org>
Mon, 27 Jan 2014 13:16:44 +0000 (14:16 +0100)
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

src/dhcpv6.c
src/odhcp6c.c
src/odhcp6c.h
src/script.c

index 9e3d6c437bf4785e3356490cfd068ae5e8ceb7a1..dca0ed4a2ee49454b3cba7981f3ed696d63e0ace 100644 (file)
@@ -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) {
index e9937ad633f9724495a679a1318ee78120117c7c..2159363dd08c9c1d4c8540df640163d68b8546df 100644 (file)
@@ -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);
index d4458ffd04b3a8f37009df89131a7e114dcd7e84..e3c6c5eeacf71b4ad187aab4e4033226ff372316 100644 (file)
@@ -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,
index e5b83415561729f77e72109b6986234d497ab38b..5a021dff5a2297b44978572f975e5909ad0748fb 100644 (file)
@@ -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);