X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-network%2Ftest-dhcp6-client.c;h=96c68e1feb460a8fb1b53ca5a88861e38f833b4e;hb=9c92ce6d67f88beb31dd6555d12ae3f632218a39;hp=40fd8f5faf3b1be86ba6c8882a0c21cc86d55521;hpb=5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53e;p=elogind.git diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index 40fd8f5fa..96c68e1fe 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -49,7 +49,6 @@ static int test_index = 42; static int test_client_message_num; static be32_t test_iaid = 0; static uint8_t test_duid[14] = { }; -static sd_event *e_solicit; static int test_client_basic(sd_event *e) { sd_dhcp6_client *client; @@ -69,6 +68,13 @@ static int test_client_basic(sd_event *e) { assert_se(sd_dhcp6_client_set_mac(client, &mac_addr) >= 0); + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_CLIENTID) == -EINVAL); + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_DNS_SERVERS) == -EEXIST); + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_NTP_SERVER) == -EEXIST); + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_SNTP_SERVERS) == 0); + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_DOMAIN_LIST) == -EEXIST); + assert_se(sd_dhcp6_client_set_request_option(client, 10) == -EINVAL); + assert_se(sd_dhcp6_client_set_callback(client, NULL, NULL) >= 0); assert_se(sd_dhcp6_client_detach_event(client) >= 0); @@ -171,6 +177,31 @@ static uint8_t msg_advertise[198] = { 0x53, 0x00, 0x07, 0x00, 0x01, 0x00 }; +static uint8_t msg_reply[173] = { + 0x07, 0xf7, 0x4e, 0x57, 0x00, 0x02, 0x00, 0x0e, + 0x00, 0x01, 0x00, 0x01, 0x19, 0x40, 0x5c, 0x53, + 0x78, 0x2b, 0xcb, 0xb3, 0x6d, 0x53, 0x00, 0x01, + 0x00, 0x0e, 0x00, 0x01, 0x00, 0x01, 0x1a, 0x6b, + 0xf3, 0x30, 0x3c, 0x97, 0x0e, 0xcf, 0xa3, 0x7d, + 0x00, 0x03, 0x00, 0x4a, 0x0e, 0xcf, 0xa3, 0x7d, + 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x78, + 0x00, 0x05, 0x00, 0x18, 0x20, 0x01, 0x0d, 0xb8, + 0xde, 0xad, 0xbe, 0xef, 0x78, 0xee, 0x1c, 0xf3, + 0x09, 0x3c, 0x55, 0xad, 0x00, 0x00, 0x00, 0x96, + 0x00, 0x00, 0x00, 0xb4, 0x00, 0x0d, 0x00, 0x1e, + 0x00, 0x00, 0x41, 0x6c, 0x6c, 0x20, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x20, + 0x77, 0x65, 0x72, 0x65, 0x20, 0x61, 0x73, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x64, 0x2e, 0x00, 0x17, + 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, + 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x18, 0x00, 0x0b, 0x03, 0x6c, + 0x61, 0x62, 0x05, 0x69, 0x6e, 0x74, 0x72, 0x61, + 0x00, 0x00, 0x1f, 0x00, 0x10, 0x20, 0x01, 0x0d, + 0xb8, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01 +}; + static int test_advertise_option(sd_event *e) { _cleanup_dhcp6_lease_free_ sd_dhcp6_lease *lease = NULL; DHCP6Message *advertise = (DHCP6Message *)msg_advertise; @@ -307,6 +338,20 @@ int dhcp6_network_bind_udp_socket(int index, struct in6_addr *local_address) { } static int test_client_send_reply(DHCP6Message *request) { + DHCP6Message reply; + + reply.transaction_id = request->transaction_id; + reply.type = DHCP6_REPLY; + + memcpy(msg_reply, &reply.transaction_id, 4); + + memcpy(&msg_reply[26], test_duid, sizeof(test_duid)); + + memcpy(&msg_reply[44], &test_iaid, sizeof(test_iaid)); + + assert_se(write(test_dhcp_fd[1], msg_reply, sizeof(msg_reply)) + == sizeof(msg_reply)); + return 0; } @@ -380,8 +425,6 @@ static int test_client_verify_request(DHCP6Message *request, uint8_t *option, assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, <_pref, <_valid) == -ENOMSG); - sd_event_exit(e_solicit, 0); - return 0; } @@ -482,6 +525,9 @@ static void test_client_solicit_cb(sd_dhcp6_client *client, int event, sd_event *e = userdata; assert_se(e); + assert_se(event == DHCP6_EVENT_IP_ACQUIRE); + + assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_DNS_SERVERS) == -EBUSY); if (verbose) printf(" got DHCPv6 event %d\n", event); @@ -491,7 +537,7 @@ static void test_client_solicit_cb(sd_dhcp6_client *client, int event, static int test_client_solicit(sd_event *e) { sd_dhcp6_client *client; - usec_t time_now = now(CLOCK_MONOTONIC); + usec_t time_now = now(clock_boottime_or_monotonic()); if (verbose) printf("* %s\n", __FUNCTION__); @@ -507,12 +553,10 @@ static int test_client_solicit(sd_event *e) { assert_se(sd_dhcp6_client_set_callback(client, test_client_solicit_cb, e) >= 0); - assert_se(sd_event_add_time(e, &hangcheck, CLOCK_MONOTONIC, + assert_se(sd_event_add_time(e, &hangcheck, clock_boottime_or_monotonic(), time_now + 2 * USEC_PER_SEC, 0, test_hangcheck, NULL) >= 0); - e_solicit = e; - assert_se(sd_dhcp6_client_start(client) >= 0); sd_event_loop(e);