test-dhcp6-client.c revision 947527f8326d3591f252c48fee5426a563f03544
/*-*- 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"
#include "dhcp6-lease-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_message_num;
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;
}
0x02, 0x0f, 0xb4, 0xe5, 0x00, 0x01, 0x00, 0x0e,
0x00, 0x01, 0x00, 0x01, 0x1a, 0x6b, 0xf3, 0x30,
0x3c, 0x97, 0x0e, 0xcf, 0xa3, 0x7d, 0x00, 0x03,
0x00, 0x5e, 0x0e, 0xcf, 0xa3, 0x7d, 0x00, 0x00,
0x00, 0x50, 0x00, 0x00, 0x00, 0x78, 0x00, 0x05,
0x00, 0x18, 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad,
0xbe, 0xef, 0x78, 0xee, 0x1c, 0xf3, 0x09, 0x3c,
0x55, 0xad, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00,
0x00, 0xb4, 0x00, 0x0d, 0x00, 0x32, 0x00, 0x00,
0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x28,
0x65, 0x73, 0x29, 0x20, 0x72, 0x65, 0x6e, 0x65,
0x77, 0x65, 0x64, 0x2e, 0x20, 0x47, 0x72, 0x65,
0x65, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x66,
0x72, 0x6f, 0x6d, 0x20, 0x70, 0x6c, 0x61, 0x6e,
0x65, 0x74, 0x20, 0x45, 0x61, 0x72, 0x74, 0x68,
0x00, 0x17, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8,
0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x0b,
0x03, 0x6c, 0x61, 0x62, 0x05, 0x69, 0x6e, 0x74,
0x72, 0x61, 0x00, 0x00, 0x1f, 0x00, 0x10, 0x20,
0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xef, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x02, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x01, 0x19,
0x40, 0x5c, 0x53, 0x78, 0x2b, 0xcb, 0xb3, 0x6d,
0x53, 0x00, 0x07, 0x00, 0x01, 0x00
};
0x07, 0xf7, 0x4e, 0x57, 0x00, 0x02, 0x00, 0x0e,
0x00, 0x01, 0x00, 0x01, 0x19, 0x40, 0x5c, 0x53,
0x78, 0x2b, 0xcb, 0xb3, 0x6d, 0x53, 0x00, 0x01,
0x00, 0x0e, 0x00, 0x01, 0x00, 0x01, 0x1a, 0x6b,
0xf3, 0x30, 0x3c, 0x97, 0x0e, 0xcf, 0xa3, 0x7d,
0x00, 0x03, 0x00, 0x4a, 0x0e, 0xcf, 0xa3, 0x7d,
0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x78,
0x00, 0x05, 0x00, 0x18, 0x20, 0x01, 0x0d, 0xb8,
0xde, 0xad, 0xbe, 0xef, 0x78, 0xee, 0x1c, 0xf3,
0x09, 0x3c, 0x55, 0xad, 0x00, 0x00, 0x00, 0x96,
0x00, 0x00, 0x00, 0xb4, 0x00, 0x0d, 0x00, 0x1e,
0x00, 0x00, 0x41, 0x6c, 0x6c, 0x20, 0x61, 0x64,
0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x20,
0x77, 0x65, 0x72, 0x65, 0x20, 0x61, 0x73, 0x73,
0x69, 0x67, 0x6e, 0x65, 0x64, 0x2e, 0x00, 0x17,
0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad,
0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x18, 0x00, 0x0b, 0x03, 0x6c,
0x61, 0x62, 0x05, 0x69, 0x6e, 0x74, 0x72, 0x61,
0x00, 0x00, 0x1f, 0x00, 0x10, 0x20, 0x01, 0x0d,
0xb8, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01
};
static int test_advertise_option(sd_event *e) {
int r;
bool opt_clientid = false;
if (verbose)
0x0fb4e5);
&optval)) >= 0) {
switch(optcode) {
case DHCP6_OPTION_CLIENTID:
opt_clientid = true;
break;
case DHCP6_OPTION_IA_NA:
break;
case DHCP6_OPTION_SERVERID:
optlen) >= 0);
break;
case DHCP6_OPTION_PREFERENCE:
*optval) >= 0);
break;
default:
break;
}
}
<_valid) >= 0);
<_valid) >= 0);
<_valid) >= 0);
assert_se(preference == 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];
}
== sizeof(msg_reply));
return 0;
}
int r;
switch(optcode) {
case DHCP6_OPTION_CLIENTID:
found_clientid = true;
sizeof(test_duid)));
break;
case DHCP6_OPTION_IA_NA:
found_iana = true;
break;
case DHCP6_OPTION_SERVERID:
found_serverid = true;
break;
}
}
<_valid) >= 0);
return 0;
}
{
== sizeof(msg_advertise));
return 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;
}
}
return 0;
}
assert_se(s == test_dhcp_fd[0]);
len -= sizeof(DHCP6Message);
if (test_client_message_num == 0) {
} else if (test_client_message_num == 1) {
}
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);
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;
}