diff options
author | Tom Gundersen <teg@jklm.no> | 2014-04-29 12:17:27 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-04-29 12:25:58 +0200 |
commit | 4684469639d0893d78fc8e1a1966ce11eb9c7e31 (patch) | |
tree | 415d38db50452f2664a3dc1af80b19cc7734c2c0 /src/libsystemd-network/sd-dhcp-lease.c | |
parent | 39594d49cf22d022bf370d6534c07186e9d8fb8a (diff) |
sd-dhcp-lease: add NTP support
Export the NTP servers so timesyncd can use them.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-lease.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index aa479ffe15..69418d98ea 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -72,6 +72,20 @@ int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *a return 0; } +int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + assert_return(addr_size, -EINVAL); + + if (lease->ntp_size) { + *addr_size = lease->ntp_size; + *addr = lease->ntp; + } else + return -ENOENT; + + return 0; +} + int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) { assert_return(lease, -EINVAL); assert_return(domainname, -EINVAL); @@ -213,6 +227,24 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_NTP_SERVER: + if (len && !(len % 4)) { + unsigned i; + + lease->ntp_size = len / 4; + + free(lease->ntp); + lease->ntp = new0(struct in_addr, lease->ntp_size); + if (!lease->ntp) + return -ENOMEM; + + for (i = 0; i < lease->ntp_size; i++) { + memcpy(&lease->ntp[i].s_addr, option + 4 * i, 4); + } + } + + break; + case DHCP_OPTION_INTERFACE_MTU: if (len >= 2) { be16_t mtu; |