From: haxibami Date: Tue, 22 Jul 2025 07:36:53 +0000 (+0900) Subject: sd-dhcp6-client: add SIP server domain support X-Git-Tag: v258-rc1~15^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2191515baf1ff710ebadc75f479d8cd31d4bbc3;p=thirdparty%2Fsystemd.git sd-dhcp6-client: add SIP server domain support --- diff --git a/src/libsystemd-network/dhcp6-lease-internal.h b/src/libsystemd-network/dhcp6-lease-internal.h index 95a0049d307..a841ce62712 100644 --- a/src/libsystemd-network/dhcp6-lease-internal.h +++ b/src/libsystemd-network/dhcp6-lease-internal.h @@ -45,6 +45,7 @@ struct sd_dhcp6_lease { size_t sntp_count; struct in6_addr *sip; size_t sip_count; + char **sip_domains; char *fqdn; char *captive_portal; struct sd_dhcp6_option **sorted_vendor_options; @@ -65,6 +66,7 @@ int dhcp6_lease_add_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t int dhcp6_lease_add_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_add_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_add_sip_addrs(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); +int dhcp6_lease_add_sip_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_set_fqdn(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_set_captive_portal(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c index b26573f3e0a..a3a22d1e2b9 100644 --- a/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/libsystemd-network/sd-dhcp6-lease.c @@ -651,6 +651,34 @@ int sd_dhcp6_lease_get_sip_addrs(sd_dhcp6_lease *lease, const struct in6_addr ** return -ENODATA; } +int dhcp6_lease_add_sip_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) { + _cleanup_strv_free_ char **domains = NULL; + int r; + + assert(lease); + assert(optval || optlen == 0); + + if (optlen == 0) + return 0; + + r = dhcp6_option_parse_domainname_list(optval, optlen, &domains); + if (r < 0) + return r; + + return strv_extend_strv_consume(&lease->sip_domains, TAKE_PTR(domains), /* filter_duplicates = */ true); +} + +int sd_dhcp6_lease_get_sip_domains(sd_dhcp6_lease *lease, char ***ret) { + assert_return(lease, -EINVAL); + assert_return(ret, -EINVAL); + + if (!lease->sip_domains) + return -ENODATA; + + *ret = lease->sip_domains; + return strv_length(lease->sip_domains); +} + int dhcp6_lease_set_fqdn(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) { char *fqdn; int r; @@ -959,6 +987,12 @@ static int dhcp6_lease_parse_message( break; + case SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME: + r = dhcp6_lease_add_sip_domains(lease, optval, optlen); + if (r < 0) + log_dhcp6_client_errno(client, r, "Failed to parse SIP server domain name option, ignoring: %m"); + break; + case SD_DHCP6_OPTION_CAPTIVE_PORTAL: r = dhcp6_lease_set_captive_portal(lease, optval, optlen); if (r < 0) @@ -1050,6 +1084,7 @@ static sd_dhcp6_lease *dhcp6_lease_free(sd_dhcp6_lease *lease) { strv_free(lease->ntp_fqdn); free(lease->sntp); free(lease->sip); + strv_free(lease->sip_domains); return mfree(lease); } diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index 34b9eb86d1c..f2b6ce8598b 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -114,6 +114,7 @@ TEST(client_basic) { assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_NTP_SERVER) >= 0); assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_SNTP_SERVER) >= 0); assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_SIP_SERVER_ADDRESS) >= 0); + assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME) >= 0); assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_VENDOR_OPTS) >= 0); assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DOMAIN) >= 0); assert_se(sd_dhcp6_client_set_request_option(client, 10) == -EINVAL); @@ -748,6 +749,9 @@ static const uint8_t msg_reply[] = { 0x00, SD_DHCP6_OPTION_SIP_SERVER_ADDRESS, 0x00, 0x20, SIP1_BYTES, SIP2_BYTES, + /* SIP server domains */ + 0x00, SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME, 0x00, 0x0b, + 0x03, 's', 'i', 'p', 0x05, 'i', 'n', 't', 'r', 'a', 0x00, /* Domain list */ 0x00, SD_DHCP6_OPTION_DOMAIN, 0x00, 0x0b, 0x03, 'l', 'a', 'b', 0x05, 'i', 'n', 't', 'r', 'a', 0x00, @@ -834,6 +838,9 @@ static const uint8_t msg_advertise[] = { 0x00, SD_DHCP6_OPTION_SIP_SERVER_ADDRESS, 0x00, 0x20, SIP1_BYTES, SIP2_BYTES, + /* SIP server domains */ + 0x00, SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME, 0x00, 0x0b, + 0x03, 's', 'i', 'p', 0x05, 'i', 'n', 't', 'r', 'a', 0x00, /* Domain list */ 0x00, SD_DHCP6_OPTION_DOMAIN, 0x00, 0x0b, 0x03, 'l', 'a', 'b', 0x05, 'i', 'n', 't', 'r', 'a', 0x00, @@ -918,6 +925,10 @@ static void test_lease_common(sd_dhcp6_client *client) { assert_se(in6_addr_equal(&addrs[0], &sip1)); assert_se(in6_addr_equal(&addrs[1], &sip2)); + assert_se(sd_dhcp6_lease_get_sip_domains(lease, &strv) == 1); + assert_se(streq(strv[0], "sip.intra")); + assert_se(!strv[1]); + assert_se(lease->sntp_count == 2); assert_se(in6_addr_equal(&lease->sntp[0], &sntp1)); assert_se(in6_addr_equal(&lease->sntp[1], &sntp2)); diff --git a/src/systemd/sd-dhcp6-lease.h b/src/systemd/sd-dhcp6-lease.h index 340744c97b4..02852fc5759 100644 --- a/src/systemd/sd-dhcp6-lease.h +++ b/src/systemd/sd-dhcp6-lease.h @@ -78,6 +78,7 @@ int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***ret); int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease, const struct in6_addr **ret); int sd_dhcp6_lease_get_ntp_fqdn(sd_dhcp6_lease *lease, char ***ret); int sd_dhcp6_lease_get_sip_addrs(sd_dhcp6_lease *lease, const struct in6_addr **ret); +int sd_dhcp6_lease_get_sip_domains(sd_dhcp6_lease *lease, char ***ret); int sd_dhcp6_lease_get_fqdn(sd_dhcp6_lease *lease, const char **ret); int sd_dhcp6_lease_get_captive_portal(sd_dhcp6_lease *lease, const char **ret); int sd_dhcp6_lease_get_vendor_options(sd_dhcp6_lease *lease, sd_dhcp6_option ***ret);