From 4a58bef7322b830b2e87be39c611a1bf4845ef49 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Wed, 2 Jan 2013 14:28:09 +0100 Subject: [PATCH] Implement RFC 3319 options --- src/dhcpv6.c | 13 ++++++++++++- src/odhcp6c.c | 2 ++ src/odhcp6c.h | 4 ++++ src/script.c | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index e93d894..9a451d0 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -574,12 +574,15 @@ static int dhcpv6_handle_reply(_unused enum dhcpv6_msg orig, t1 = t2 = t3 = 86400; size_t ia_na_len, dns_len, search_len, sntp_ip_len, sntp_dns_len; + size_t sip_ip_len, sip_fqdn_len; uint8_t *ia_na = odhcp6c_get_state(STATE_IA_NA, &ia_na_len); uint8_t *ia_end; odhcp6c_get_state(STATE_DNS, &dns_len); odhcp6c_get_state(STATE_SEARCH, &search_len); odhcp6c_get_state(STATE_SNTP_IP, &sntp_ip_len); odhcp6c_get_state(STATE_SNTP_FQDN, &sntp_dns_len); + odhcp6c_get_state(STATE_SIP_IP, &sip_ip_len); + odhcp6c_get_state(STATE_SIP_FQDN, &sip_fqdn_len); // Decrease valid and preferred lifetime of prefixes size_t ia_pd_len; @@ -648,7 +651,8 @@ static int dhcpv6_handle_reply(_unused enum dhcpv6_msg orig, t3 = n; } else if (otype == DHCPV6_OPT_DNS_SERVERS) { - odhcp6c_add_state(STATE_DNS, odata, olen); + if (olen == 16) + 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_NTP_SERVER) { @@ -665,6 +669,11 @@ static int dhcpv6_handle_reply(_unused enum dhcpv6_msg orig, odhcp6c_add_state(STATE_SNTP_FQDN, sdata, slen); } + } else if (otype == DHCPV6_OPT_SIP_SERVER_A) { + if (olen == 16) + odhcp6c_add_state(STATE_SIP_IP, odata, olen); + } else if (otype == DHCPV6_OPT_SIP_SERVER_D) { + odhcp6c_add_state(STATE_SIP_FQDN, odata, olen); } else if (otype == DHCPV6_OPT_INFO_REFRESH && olen >= 4) { uint32_t refresh = ntohl(*((uint32_t*)odata)); if (refresh < (uint32_t)t1) @@ -683,6 +692,8 @@ static int dhcpv6_handle_reply(_unused enum dhcpv6_msg orig, sntp_ip_len); have_update |= odhcp6c_commit_state(STATE_SNTP_FQDN, sntp_dns_len); + have_update |= odhcp6c_commit_state(STATE_SIP_IP, sip_ip_len); + have_update |= odhcp6c_commit_state(STATE_SIP_FQDN, sip_fqdn_len); size_t new_ia_pd_len, new_ia_na_len; odhcp6c_get_state(STATE_IA_PD, &new_ia_pd_len); odhcp6c_get_state(STATE_IA_NA, &new_ia_na_len); diff --git a/src/odhcp6c.c b/src/odhcp6c.c index f3634d2..163db09 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -173,6 +173,8 @@ int main(_unused int argc, char* const argv[]) odhcp6c_clear_state(STATE_IA_PD_LOST); odhcp6c_clear_state(STATE_SNTP_IP); odhcp6c_clear_state(STATE_SNTP_FQDN); + odhcp6c_clear_state(STATE_SIP_IP); + odhcp6c_clear_state(STATE_SIP_FQDN); dhcpv6_set_ia_na_mode(ia_na_mode); alarm(timeout); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index 2b3ce9f..442393b 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -49,6 +49,8 @@ enum dhcvp6_opt { DHCPV6_OPT_INFO_REFRESH = 32, DHCPV6_OPT_FQDN = 39, DHCPV6_OPT_NTP_SERVER = 56, + DHCPV6_OPT_SIP_SERVER_D = 21, + DHCPV6_OPT_SIP_SERVER_A = 22, }; enum dhcpv6_opt_npt { @@ -159,6 +161,8 @@ enum odhcp6c_state { STATE_CUSTOM_OPTS, STATE_SNTP_IP, STATE_SNTP_FQDN, + STATE_SIP_IP, + STATE_SIP_FQDN, _STATE_MAX }; diff --git a/src/script.c b/src/script.c index d082ff6..ae791cc 100644 --- a/src/script.c +++ b/src/script.c @@ -160,11 +160,15 @@ void script_call(const char *status) { syslog(LOG_WARNING, "State for %s changed to %s", argv[1], status); size_t dns_len, search_len, custom_len, sntp_ip_len, sntp_dns_len; + size_t sip_ip_len, sip_fqdn_len; + struct in6_addr *dns = odhcp6c_get_state(STATE_DNS, &dns_len); 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 *sip = odhcp6c_get_state(STATE_SIP_IP, &sip_ip_len); + uint8_t *sip_fqdn = odhcp6c_get_state(STATE_SIP_FQDN, &sip_fqdn_len); size_t prefix_len, lost_pd_len; uint8_t *prefix = odhcp6c_get_state(STATE_IA_PD, &prefix_len); @@ -174,8 +178,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("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); bin_to_env(custom, custom_len); prefix_to_env("PREFIXES", prefix, prefix_len); prefix_to_env("PREFIXES_LOST", lost_pd, lost_pd_len); -- 2.39.2