test-dhcp-client.c revision d47e1de40e410ab2149918c3269038d2c264b01d
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering This file is part of systemd.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Copyright (C) 2013 Intel Corporation. All rights reserved.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is free software; you can redistribute it and/or modify it
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering under the terms of the GNU Lesser General Public License as published by
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (at your option) any later version.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is distributed in the hope that it will be useful, but
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Lesser General Public License for more details.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering You should have received a copy of the GNU Lesser General Public License
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringtypedef int (*test_callback_recv_t)(size_t size, DHCPMessage *dhcp);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic bool verbose = false;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic test_callback_recv_t callback_recv;
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallacestatic int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_not_reached("Test case should have completed in 2 seconds");
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering r = sd_dhcp_client_attach_event(client, e, 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(client, 15) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(client, -42) == -EINVAL);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(client, -1) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client, 33) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client, 44) == 0);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversstatic void test_checksum(void)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(dhcp_packet_checksum(&buf, 20) == be16toh(0x78ae));
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversstatic int check_options(uint8_t code, uint8_t len, const uint8_t *option,
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(memcmp(&option[1], &mac_addr, ETH_ALEN) == 0);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversint dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(discover->ip.protocol == IPPROTO_UDP);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(discover->ip.daddr == INADDR_BROADCAST);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek udp_check = ~dhcp_packet_checksum(&discover->ip.ttl, len - 8);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ip_check = ~dhcp_packet_checksum(&discover->ip, sizeof(discover->ip));
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers size = len - sizeof(struct iphdr) - sizeof(struct udphdr);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversint dhcp_network_bind_raw_socket(int index, union sockaddr_union *link, uint32_t id)
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers if (socketpair(AF_UNIX, SOCK_STREAM, 0, test_fd) < 0)
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversint dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversint dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic int test_discover_message_verify(size_t size, struct DHCPMessage *dhcp)
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers res = dhcp_option_parse(dhcp, size, check_options, NULL);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers printf(" recv DHCP Discover 0x%08x\n", be32toh(dhcp->xid));
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering r = sd_dhcp_client_attach_event(client, e, 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_request_option(client, 248) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering callback_recv = test_discover_message_verify;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(res == 0 || res == -EINPROGRESS);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x80, 0x11, 0xb3, 0x84, 0xc0, 0xa8, 0x02, 0x01,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0xc0, 0xa8, 0x02, 0xbf, 0x00, 0x43, 0x00, 0x44,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x6f, 0x95, 0x2f, 0x30, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0xbf,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna 0xc0, 0xa8, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x02, 0x36,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x04, 0xc0, 0xa8, 0x02, 0x01, 0x33, 0x04, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x02, 0x58, 0x01, 0x04, 0xff, 0xff, 0xff,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x2a, 0x04, 0xc0, 0xa8, 0x02, 0x01, 0x0f,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x09, 0x6c, 0x61, 0x62, 0x2e, 0x69, 0x6e, 0x74,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x72, 0x61, 0x03, 0x04, 0xc0, 0xa8, 0x02, 0x01,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x80, 0x11, 0xb3, 0x84, 0xc0, 0xa8, 0x02, 0x01,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0xc0, 0xa8, 0x02, 0xbf, 0x00, 0x43, 0x00, 0x44,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x01, 0x34, 0x00, 0x00, 0x02, 0x01, 0x06, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0xbf,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0xc0, 0xa8, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x05, 0x36,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x04, 0xc0, 0xa8, 0x02, 0x01, 0x33, 0x04, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x02, 0x58, 0x01, 0x04, 0xff, 0xff, 0xff,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x2a, 0x04, 0xc0, 0xa8, 0x02, 0x01, 0x0f,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x09, 0x6c, 0x61, 0x62, 0x2e, 0x69, 0x6e, 0x74,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x72, 0x61, 0x03, 0x04, 0xc0, 0xa8, 0x02, 0x01,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic void test_addr_acq_acquired(sd_dhcp_client *client, int event,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(event == DHCP_EVENT_IP_ACQUIRE);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_get_lease(client, &lease) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_lease_get_address(lease, &addr) >= 0);
0affed79d2e30013f07cb94e6f07e3fcb81c02faLennart Poettering assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[44],
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_lease_get_netmask(lease, &addr) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[285],
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_lease_get_router(lease, &addr) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[308],
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnastatic int test_addr_acq_recv_request(size_t size, DHCPMessage *request) {
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna res = dhcp_option_parse(request, size, check_options, NULL);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer assert_se(msg_bytes[size - 1] == DHCP_OPTION_END);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna printf(" recv DHCP Request 0x%08x\n", be32toh(xid));
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna memcpy(&test_addr_acq_ack[26], &udp_check, sizeof(udp_check));
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna memcpy(&test_addr_acq_ack[32], &xid, sizeof(xid));
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek memcpy(&test_addr_acq_ack[56], &mac_addr.ether_addr_octet,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna res = write(test_fd[1], test_addr_acq_ack,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna assert_se(res == sizeof(test_addr_acq_ack));
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekstatic int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover) {
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmek uint8_t *msg_bytes = (uint8_t *)discover;
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmek res = dhcp_option_parse(discover, size, check_options, NULL);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna assert_se(msg_bytes[size - 1] == DHCP_OPTION_END);
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek printf(" recv DHCP Discover 0x%08x\n", be32toh(xid));
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna memcpy(&test_addr_acq_offer[26], &udp_check, sizeof(udp_check));
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek memcpy(&test_addr_acq_offer[32], &xid, sizeof(xid));
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna memcpy(&test_addr_acq_offer[56], &mac_addr.ether_addr_octet,
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek callback_recv = test_addr_acq_recv_request;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna res = write(test_fd[1], test_addr_acq_offer,
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna assert_se(res == sizeof(test_addr_acq_offer));
7c2d80944afb4196f2eff614e8da1450dffcbeaaThomas Hindoe Paaboel Andersen r = sd_dhcp_client_attach_event(client, e, 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering callback_recv = test_addr_acq_recv_discover;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(sd_event_add_time(e, &test_hangcheck,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(res == 0 || res == -EINPROGRESS);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering test_hangcheck = sd_event_source_unref(test_hangcheck);