summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/test-dhcp-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-network/test-dhcp-client.c')
-rw-r--r--src/libsystemd-network/test-dhcp-client.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c
index f5f1284e6d..1942199294 100644
--- a/src/libsystemd-network/test-dhcp-client.c
+++ b/src/libsystemd-network/test-dhcp-client.c
@@ -56,7 +56,8 @@ static void test_request_basic(sd_event *e) {
if (verbose)
printf("* %s\n", __FUNCTION__);
- r = sd_dhcp_client_new(&client);
+ /* Initialize client without Anonymize settings. */
+ r = sd_dhcp_client_new(&client, false);
assert_se(r >= 0);
assert_se(client);
@@ -78,6 +79,8 @@ static void test_request_basic(sd_event *e) {
SD_DHCP_OPTION_SUBNET_MASK) == -EEXIST);
assert_se(sd_dhcp_client_set_request_option(client,
SD_DHCP_OPTION_ROUTER) == -EEXIST);
+ /* This PRL option is not set when using Anonymize, but in this test
+ * Anonymize settings are not being used. */
assert_se(sd_dhcp_client_set_request_option(client,
SD_DHCP_OPTION_HOST_NAME) == -EEXIST);
assert_se(sd_dhcp_client_set_request_option(client,
@@ -97,10 +100,49 @@ static void test_request_basic(sd_event *e) {
SD_DHCP_OPTION_PARAMETER_REQUEST_LIST)
== -EINVAL);
- assert_se(sd_dhcp_client_set_request_option(client, 33) == 0);
- assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
- assert_se(sd_dhcp_client_set_request_option(client, 44) == 0);
- assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+ /* RFC7844: option 33 (SD_DHCP_OPTION_STATIC_ROUTE) is set in the
+ * default PRL when using Anonymize, so it is changed to other option
+ * that is not set by default, to check that it succed setting it.
+ * Ooptions not set by default (using or not anonymize) are option 17
+ * (SD_DHCP_OPTION_ROOT_PATH) and 42 (SD_DHCP_OPTION_NTP_SERVER) */
+ assert_se(sd_dhcp_client_set_request_option(client, 17) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 17) == -EEXIST);
+ assert_se(sd_dhcp_client_set_request_option(client, 42) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 17) == -EEXIST);
+
+ sd_dhcp_client_unref(client);
+}
+
+static void test_request_anonymize(sd_event *e) {
+ int r;
+
+ sd_dhcp_client *client;
+
+ if (verbose)
+ printf("* %s\n", __FUNCTION__);
+
+ /* Initialize client with Anonymize settings. */
+ r = sd_dhcp_client_new(&client, true);
+
+ assert_se(r >= 0);
+ assert_se(client);
+
+ r = sd_dhcp_client_attach_event(client, e, 0);
+ assert_se(r >= 0);
+
+ assert_se(sd_dhcp_client_set_request_option(client,
+ SD_DHCP_OPTION_NETBIOS_NAMESERVER) == -EEXIST);
+ /* This PRL option is not set when using Anonymize */
+ assert_se(sd_dhcp_client_set_request_option(client,
+ SD_DHCP_OPTION_HOST_NAME) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client,
+ SD_DHCP_OPTION_PARAMETER_REQUEST_LIST)
+ == -EINVAL);
+
+ /* RFC7844: option 101 (SD_DHCP_OPTION_NEW_TZDB_TIMEZONE) is not set in the
+ * default PRL when using Anonymize, */
+ assert_se(sd_dhcp_client_set_request_option(client, 101) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 101) == -EEXIST);
sd_dhcp_client_unref(client);
}
@@ -236,7 +278,7 @@ static void test_discover_message(sd_event *e) {
if (verbose)
printf("* %s\n", __FUNCTION__);
- r = sd_dhcp_client_new(&client);
+ r = sd_dhcp_client_new(&client, false);
assert_se(r >= 0);
assert_se(client);
@@ -252,7 +294,7 @@ static void test_discover_message(sd_event *e) {
res = sd_dhcp_client_start(client);
- assert_se(res == 0 || res == -EINPROGRESS);
+ assert_se(IN_SET(res, 0, -EINPROGRESS));
sd_event_run(e, (uint64_t) -1);
@@ -451,7 +493,7 @@ static void test_addr_acq(sd_event *e) {
if (verbose)
printf("* %s\n", __FUNCTION__);
- r = sd_dhcp_client_new(&client);
+ r = sd_dhcp_client_new(&client, false);
assert_se(r >= 0);
assert_se(client);
@@ -471,7 +513,7 @@ static void test_addr_acq(sd_event *e) {
test_dhcp_hangcheck, NULL) >= 0);
res = sd_dhcp_client_start(client);
- assert_se(res == 0 || res == -EINPROGRESS);
+ assert_se(IN_SET(res, 0, -EINPROGRESS));
assert_se(sd_event_loop(e) >= 0);
@@ -497,6 +539,7 @@ int main(int argc, char *argv[]) {
assert_se(sd_event_new(&e) >= 0);
test_request_basic(e);
+ test_request_anonymize(e);
test_checksum();
test_discover_message(e);