test-dhcp-client.c revision c4acff1275e8d3a1c29c9b417b93f6cf6f10e258
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright (C) 2013 Intel Corporation. All rights reserved.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersentypedef int (*test_callback_recv_t)(size_t size, DHCPMessage *dhcp);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic bool verbose = false;
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_not_reached("Test case should have completed in 2 seconds");
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen r = sd_dhcp_client_attach_event(client, e, 0);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_index(client, 15) == 0);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_index(client, -42) == -EINVAL);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_index(client, -1) == 0);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client, 33) == 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client, 44) == 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenstatic void test_checksum(void)
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen 0x45, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen 0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(dhcp_packet_checksum(&buf, 20) == be16toh(0x78ae));
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenstatic int check_options(uint8_t code, uint8_t len, const uint8_t *option,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(memcmp(&option[1], &mac_addr, ETH_ALEN) == 0);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenint dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(discover->ip.protocol == IPPROTO_UDP);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(discover->ip.daddr == INADDR_BROADCAST);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen assert_se(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen udp_check = ~dhcp_packet_checksum(&discover->ip.ttl, len - 8);
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen ip_check = ~dhcp_packet_checksum(&discover->ip, sizeof(discover->ip));
return -errno;
return test_fd[0];
int res;
if (verbose)
int res, r;
if (verbose)
assert_se(r >= 0);
assert_se(r >= 0);
void *userdata) {
if (verbose)
sd_event_exit(e, 0);
int res;
if (verbose)
sizeof(test_addr_acq_ack));
if (verbose)
int res;
if (verbose)
sizeof(test_addr_acq_offer));
if (verbose)
int res, r;
if (verbose)
assert_se(r >= 0);
assert_se(r >= 0);
sd_event_loop(e);
xid = 0;
sd_event *e;
test_addr_acq(e);