1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-08 11:27:32 +03:00

test-dhcp6-client: Add tests for DNS and NTP options

Test option setting and getting in test_advertise_option(). Verify
that the information provided in DHCPv6 Reply messages is also
available in the Information and Solicit callbacks.
This commit is contained in:
Patrik Flykt 2015-07-10 11:42:11 +03:00
parent 41e4615d4f
commit bc152ff879

View File

@ -216,6 +216,8 @@ static int test_advertise_option(sd_event *e) {
uint32_t lt_pref, lt_valid; uint32_t lt_pref, lt_valid;
int r; int r;
bool opt_clientid = false; bool opt_clientid = false;
struct in6_addr *addrs;
char **domains;
if (verbose) if (verbose)
printf("* %s\n", __FUNCTION__); printf("* %s\n", __FUNCTION__);
@ -276,6 +278,24 @@ static int test_advertise_option(sd_event *e) {
break; break;
case DHCP6_OPTION_DNS_SERVERS:
assert_se(optlen == 16);
assert_se(dhcp6_lease_set_dns(lease, optval,
optlen) >= 0);
break;
case DHCP6_OPTION_DOMAIN_LIST:
assert_se(optlen == 11);
assert_se(dhcp6_lease_set_domains(lease, optval,
optlen) >= 0);
break;
case DHCP6_OPTION_SNTP_SERVERS:
assert_se(optlen == 16);
assert_se(dhcp6_lease_set_sntp(lease, optval,
optlen) >= 0);
break;
default: default:
break; break;
} }
@ -315,6 +335,19 @@ static int test_advertise_option(sd_event *e) {
assert_se(dhcp6_lease_get_preference(lease, &preference) >= 0); assert_se(dhcp6_lease_get_preference(lease, &preference) >= 0);
assert_se(preference == 0); assert_se(preference == 0);
r = sd_dhcp6_lease_get_dns(lease, &addrs);
assert_se(r == 1);
assert_se(!memcmp(addrs, &msg_advertise[124], r * 16));
r = sd_dhcp6_lease_get_domains(lease, &domains);
assert_se(r == 1);
assert_se(!strcmp("lab.intra", domains[0]));
assert_se(domains[1] == NULL);
r = sd_dhcp6_lease_get_ntp_addrs(lease, &addrs);
assert_se(r == 1);
assert_se(!memcmp(addrs, &msg_advertise[159], r * 16));
return 0; return 0;
} }
@ -339,10 +372,25 @@ int detect_virtualization(const char **id) {
static void test_client_solicit_cb(sd_dhcp6_client *client, int event, static void test_client_solicit_cb(sd_dhcp6_client *client, int event,
void *userdata) { void *userdata) {
sd_event *e = userdata; sd_event *e = userdata;
sd_dhcp6_lease *lease;
struct in6_addr *addrs;
char **domains;
assert_se(e); assert_se(e);
assert_se(event == DHCP6_EVENT_IP_ACQUIRE); assert_se(event == DHCP6_EVENT_IP_ACQUIRE);
assert_se(sd_dhcp6_client_get_lease(client, &lease) >= 0);
assert_se(sd_dhcp6_lease_get_domains(lease, &domains) == 1);
assert_se(!strcmp("lab.intra", domains[0]));
assert_se(domains[1] == NULL);
assert_se(sd_dhcp6_lease_get_dns(lease, &addrs) == 1);
assert_se(!memcmp(addrs, &msg_advertise[124], 16));
assert_se(sd_dhcp6_lease_get_ntp_addrs(lease, &addrs) == 1);
assert_se(!memcmp(addrs, &msg_advertise[159], 16));
assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_DNS_SERVERS) == -EBUSY); assert_se(sd_dhcp6_client_set_request_option(client, DHCP6_OPTION_DNS_SERVERS) == -EBUSY);
if (verbose) if (verbose)
@ -524,10 +572,25 @@ static int test_client_verify_solicit(DHCP6Message *solicit, uint8_t *option,
static void test_client_information_cb(sd_dhcp6_client *client, int event, static void test_client_information_cb(sd_dhcp6_client *client, int event,
void *userdata) { void *userdata) {
sd_event *e = userdata; sd_event *e = userdata;
sd_dhcp6_lease *lease;
struct in6_addr *addrs;
char **domains;
assert_se(e); assert_se(e);
assert_se(event == DHCP6_EVENT_INFORMATION_REQUEST); assert_se(event == DHCP6_EVENT_INFORMATION_REQUEST);
assert_se(sd_dhcp6_client_get_lease(client, &lease) >= 0);
assert_se(sd_dhcp6_lease_get_domains(lease, &domains) == 1);
assert_se(!strcmp("lab.intra", domains[0]));
assert_se(domains[1] == NULL);
assert_se(sd_dhcp6_lease_get_dns(lease, &addrs) == 1);
assert_se(!memcmp(addrs, &msg_advertise[124], 16));
assert_se(sd_dhcp6_lease_get_ntp_addrs(lease, &addrs) == 1);
assert_se(!memcmp(addrs, &msg_advertise[159], 16));
if (verbose) if (verbose)
printf(" got DHCPv6 event %d\n", event); printf(" got DHCPv6 event %d\n", event);