summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/test-dhcp-option.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-21 15:55:02 +0200
committerTom Gundersen <teg@jklm.no>2014-05-21 16:09:05 +0200
commit04b28be1a306fd2ba454d3ee333d63df71aa3873 (patch)
tree68b782fb9ee67a09284386a6a2ab3ab8cc3ec2c5 /src/libsystemd-network/test-dhcp-option.c
parent2688ef60de061bf188c1153c58fb41a78919b97e (diff)
downloadsystemd-04b28be1a306fd2ba454d3ee333d63df71aa3873.tar.gz
sd-dhcp: option_append - support falling back to 'sname' and 'file'
Diffstat (limited to 'src/libsystemd-network/test-dhcp-option.c')
-rw-r--r--src/libsystemd-network/test-dhcp-option.c62
1 files changed, 44 insertions, 18 deletions
diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c
index 3dd7102d82..4482a6783c 100644
--- a/src/libsystemd-network/test-dhcp-option.c
+++ b/src/libsystemd-network/test-dhcp-option.c
@@ -92,7 +92,7 @@ static void test_message_init(void)
message = malloc0(len);
assert_se(dhcp_message_init(message, BOOTREQUEST, 0x12345678,
- DHCP_DISCOVER, message->options, optlen, &optoffset) >= 0);
+ DHCP_DISCOVER, optlen, &optoffset) >= 0);
assert_se(message->xid == htobe32(0x12345678));
assert_se(message->op == BOOTREQUEST);
@@ -287,10 +287,6 @@ static void test_options(struct option_desc *desc)
printf("DHCP type %s\n", dhcp_type(res));
}
-static uint8_t result[64] = {
- 'A', 'B', 'C', 'D',
-};
-
static uint8_t options[64] = {
'A', 'B', 'C', 'D',
160, 2, 0x11, 0x12,
@@ -304,24 +300,34 @@ static uint8_t options[64] = {
static void test_option_set(void)
{
+ DHCPMessage *result;
size_t offset = 0, len, pos;
unsigned i;
- assert_se(dhcp_option_append(result, 0, &offset, DHCP_OPTION_PAD,
- 0, NULL) == -ENOBUFS);
+ result = malloc0(sizeof(DHCPMessage) + 11);
+ assert_se(result);
+
+ result->options[0] = 'A';
+ result->options[1] = 'B';
+ result->options[2] = 'C';
+ result->options[3] = 'D';
+
+ assert_se(dhcp_option_append(result, 0, &offset, 0, DHCP_OPTION_PAD,
+ 0, NULL) == -ENOBUFS);
assert_se(offset == 0);
offset = 4;
- assert_se(dhcp_option_append(result, 1, &offset, DHCP_OPTION_PAD,
- 0, NULL) >= 0);
+ assert_se(dhcp_option_append(result, 5, &offset, 0, DHCP_OPTION_PAD,
+ 0, NULL) == -ENOBUFS);
+ assert_se(offset == 4);
+ assert_se(dhcp_option_append(result, 6, &offset, 0, DHCP_OPTION_PAD,
+ 0, NULL) >= 0);
assert_se(offset == 5);
offset = pos = 4;
- len = 60;
- while (pos < 64 && options[pos] != DHCP_OPTION_END) {
- offset = pos;
-
- assert_se(dhcp_option_append(result, len, &offset,
+ len = 11;
+ while (pos < len && options[pos] != DHCP_OPTION_END) {
+ assert_se(dhcp_option_append(result, len, &offset, DHCP_OVERLOAD_SNAME,
options[pos],
options[pos + 1],
&options[pos + 2]) >= 0);
@@ -331,14 +337,34 @@ static void test_option_set(void)
else
pos += 2 + options[pos + 1];
- assert_se(offset == pos);
+ if (pos < len)
+ assert_se(offset == pos);
}
- for (i = 0; i < pos; i++) {
+ for (i = 0; i < 9; i++) {
if (verbose)
- printf("%2d: 0x%02x(0x%02x)\n", i, result[i],
+ printf("%2d: 0x%02x(0x%02x) (options)\n", i, result->options[i],
options[i]);
- assert_se(result[i] == options[i]);
+ assert_se(result->options[i] == options[i]);
+ }
+
+ if (verbose)
+ printf("%2d: 0x%02x(0x%02x) (options)\n", 9, result->options[9],
+ DHCP_OPTION_END);
+
+ assert_se(result->options[9] == DHCP_OPTION_END);
+
+ if (verbose)
+ printf("%2d: 0x%02x(0x%02x) (options)\n", 10, result->options[10],
+ DHCP_OPTION_PAD);
+
+ assert_se(result->options[10] == DHCP_OPTION_PAD);
+
+ for (i = 0; i < pos - 8; i++) {
+ if (verbose)
+ printf("%2d: 0x%02x(0x%02x) (sname)\n", i, result->sname[i],
+ options[i + 9]);
+ assert_se(result->sname[i] == options[i + 9]);
}
if (verbose)