test-dhcp6-client.c revision 2ea8857effb833615b16d10fc7a19a7104c19e13
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2014 Intel Corporation. All rights reserved.
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <net/ethernet.h>
#include "socket-util.h"
#include "macro.h"
#include "sd-event.h"
#include "event-util.h"
#include "virt.h"
#include "sd-dhcp6-client.h"
#include "dhcp6-protocol.h"
#include "dhcp6-internal.h"
static struct ether_addr mac_addr = {
};
static bool verbose = false;
static sd_event_source *hangcheck;
static int test_dhcp_fd[2];
static int test_index = 42;
static int test_client_basic(sd_event *e) {
if (verbose)
return 0;
}
static int test_option(sd_event *e) {
'F', 'O', 'O',
'A', 'B', 'C', 'D', 'E', 'F', 'G',
'1', '2', '3', '4', '5', '6', '7', '8', '9',
'B', 'A', 'R',
};
'F', 'O', 'O',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
'B', 'A', 'R',
};
if (verbose)
buflen -= 3;
outlen -= 3;
&optval) >= 0);
optval) >= 0);
&optval) >= 0);
optval) >= 0);
return 0;
}
assert_not_reached("Test case should have completed in 2 seconds");
return 0;
}
return 1;
}
int detect_container(const char **id) {
return 1;
}
int detect_virtualization(const char **id) {
return 1;
}
return -errno;
return test_dhcp_fd[0];
}
bool found_clientid = false, found_iana = false;
int r;
switch(optcode) {
case DHCP6_OPTION_CLIENTID:
found_clientid = true;
break;
case DHCP6_OPTION_IA_NA:
found_iana = true;
break;
}
}
sd_event_exit(e_solicit, 0);
return 0;
}
assert_se(s == test_dhcp_fd[0]);
len -= sizeof(DHCP6Message);
return len;
}
void *userdata) {
assert_se(e);
if (verbose)
sd_event_exit(e, 0);
}
static int test_client_solicit(sd_event *e) {
if (verbose)
test_client_solicit_cb, e) >= 0);
test_hangcheck, NULL) >= 0);
e_solicit = e;
sd_event_loop(e);
return 0;
}
assert_se(sd_event_new(&e) >= 0);
log_open();
test_option(e);
assert_se(!sd_event_unref(e));
return 0;
}