diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-12-09 23:43:26 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-12 11:43:34 -0500 |
commit | 8c00042c939938818365753023ff2d50f984dec6 (patch) | |
tree | afffca11004c504d8c6e98ca3efea1d8911e8f13 /src/libsystemd-dhcp/test-dhcp-client.c | |
parent | d3d8ac2f2bac721d99f893c0a0128d21db636d4c (diff) |
dhcp: Handle received DHCP Offer message
Create a function for handling the full IP, UDP and DHCP packet
and tie it to the main loop. Verify IP and UDP headers and checksum.
Creat a new lease structure with using the values supplied in the
DHCP message. Free the lease structure when client is stopped.
Split out socket handling into a creation and a sending part. As a
result modify the test code.
Diffstat (limited to 'src/libsystemd-dhcp/test-dhcp-client.c')
-rw-r--r-- | src/libsystemd-dhcp/test-dhcp-client.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c index b8a448d0dc..d398510745 100644 --- a/src/libsystemd-dhcp/test-dhcp-client.c +++ b/src/libsystemd-dhcp/test-dhcp-client.c @@ -23,8 +23,12 @@ #include <assert.h> #include <errno.h> #include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <unistd.h> #include "util.h" +#include "socket-util.h" #include "dhcp-protocol.h" #include "dhcp-internal.h" @@ -34,6 +38,8 @@ static struct ether_addr mac_addr = { .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'} }; +static int test_fd[2]; + static void test_request_basic(sd_event *e) { sd_dhcp_client *client; @@ -125,14 +131,15 @@ static int check_options(uint8_t code, uint8_t len, const uint8_t *option, return 0; } -int dhcp_network_send_raw_packet(int index, const void *packet, size_t len) +int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link, + const void *packet, size_t len) { size_t size; _cleanup_free_ DHCPPacket *discover; uint16_t ip_check, udp_check; int res; - assert(index == 42); + assert(s >= 0); assert(packet); size = sizeof(DHCPPacket) + 4; @@ -146,8 +153,8 @@ int dhcp_network_send_raw_packet(int index, const void *packet, size_t len) assert(discover->ip.protocol == IPPROTO_UDP); assert(discover->ip.saddr == INADDR_ANY); assert(discover->ip.daddr == INADDR_BROADCAST); - assert(discover->udp.source == ntohs(DHCP_PORT_CLIENT)); - assert(discover->udp.dest == ntohs(DHCP_PORT_SERVER)); + assert(discover->udp.source == be16toh(DHCP_PORT_CLIENT)); + assert(discover->udp.dest == be16toh(DHCP_PORT_SERVER)); ip_check = discover->ip.check; @@ -172,6 +179,14 @@ int dhcp_network_send_raw_packet(int index, const void *packet, size_t len) return 575; } +int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link) +{ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, test_fd) < 0) + return -errno; + + return test_fd[0]; +} + static void test_discover_message(sd_event *e) { sd_dhcp_client *client; @@ -188,6 +203,9 @@ static void test_discover_message(sd_event *e) res = sd_dhcp_client_start(client); assert(res == 0 || res == -EINPROGRESS); + + close(test_fd[0]); + close(test_fd[1]); } int main(int argc, char *argv[]) |