diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-26 19:19:32 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-26 20:44:20 +0200 |
commit | 8eb9058dc1f99a5eb9b8726a978fcc0720837a10 (patch) | |
tree | 9e2670f8a77d6fd01d763c7097908f6824694571 /src/libsystemd-network/sd-dhcp-lease.c | |
parent | 43f447b121b38c01a7c5626a51cc571a822250b8 (diff) |
dhcp,network: implement RFC 4833 (DHCP Timezone option)
This one is simply to add: encode the tzdata timezone in the DHCP
options and optionally make use of it.
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 57369a353d..c312c7cad0 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -608,6 +608,22 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_NEW_TZDB_TIMEZONE: { + _cleanup_free_ char *tz = NULL; + + r = lease_parse_string(option, len, &tz); + if (r < 0) + return r; + + if (!timezone_is_valid(tz)) + return -EINVAL; + + free(lease->timezone); + lease->timezone = tz; + tz = NULL; + break; + } + case DHCP_OPTION_VENDOR_SPECIFIC: if (len >= 1) { free(lease->vendor_specific); @@ -757,6 +773,10 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { if (r >= 0) serialize_dhcp_routes(f, "ROUTES", routes, r); + r = sd_dhcp_lease_get_timezone(lease, &string); + if (r >= 0) + fprintf(f, "TIMEZONE=%s\n", string); + r = sd_dhcp_lease_get_client_id(lease, &client_id, &client_id_len); if (r >= 0) { _cleanup_free_ char *client_id_hex; @@ -840,6 +860,7 @@ int sd_dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { "ROOT_PATH", &lease->root_path, "ROUTES", &routes, "CLIENTID", &client_id_hex, + "TIMEZONE", &lease->timezone, "VENDOR_SPECIFIC", &vendor_specific_hex, "OPTION_224", &options[0], "OPTION_225", &options[1], @@ -1026,3 +1047,14 @@ int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const uint8_t *client_id, return 0; } + +int sd_dhcp_lease_get_timezone(sd_dhcp_lease *lease, const char **timezone) { + assert_return(lease, -EINVAL); + assert_return(timezone, -EINVAL); + + if (!lease->timezone) + return -ENXIO; + + *timezone = lease->timezone; + return 0; +} |