mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 10:51:20 +03:00
dhcp: add test for dhcp_identifier_set_iaid()
This commit is contained in:
parent
7d7c8ea944
commit
43fc095532
@ -7,6 +7,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
#include "sd-dhcp-client.h"
|
#include "sd-dhcp-client.h"
|
||||||
#include "sd-event.h"
|
#include "sd-event.h"
|
||||||
@ -16,6 +17,7 @@
|
|||||||
#include "dhcp-internal.h"
|
#include "dhcp-internal.h"
|
||||||
#include "dhcp-protocol.h"
|
#include "dhcp-protocol.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
|
#include "random-util.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -153,6 +155,27 @@ static void test_checksum(void) {
|
|||||||
assert_se(dhcp_packet_checksum((uint8_t*)&buf, 20) == be16toh(0x78ae));
|
assert_se(dhcp_packet_checksum((uint8_t*)&buf, 20) == be16toh(0x78ae));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_dhcp_identifier_set_iaid(void) {
|
||||||
|
uint32_t iaid;
|
||||||
|
int ifindex;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
char ifname[IFNAMSIZ];
|
||||||
|
|
||||||
|
/* try to find an ifindex which does not exist. I causes dhcp_identifier_set_iaid()
|
||||||
|
* to hash the MAC address. */
|
||||||
|
pseudo_random_bytes(&ifindex, sizeof(ifindex));
|
||||||
|
if (ifindex > 0 && !if_indextoname(ifindex, ifname))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_se(dhcp_identifier_set_iaid(ifindex, mac_addr, sizeof(mac_addr), &iaid) >= 0);
|
||||||
|
|
||||||
|
/* we expect, that the MAC address was hashed. Note that the value is in native
|
||||||
|
* endianness. */
|
||||||
|
assert_se(iaid == 0x8dde4ba8u);
|
||||||
|
}
|
||||||
|
|
||||||
static int check_options(uint8_t code, uint8_t len, const void *option, void *userdata) {
|
static int check_options(uint8_t code, uint8_t len, const void *option, void *userdata) {
|
||||||
switch(code) {
|
switch(code) {
|
||||||
case SD_DHCP_OPTION_CLIENT_IDENTIFIER:
|
case SD_DHCP_OPTION_CLIENT_IDENTIFIER:
|
||||||
@ -532,6 +555,7 @@ int main(int argc, char *argv[]) {
|
|||||||
test_request_basic(e);
|
test_request_basic(e);
|
||||||
test_request_anonymize(e);
|
test_request_anonymize(e);
|
||||||
test_checksum();
|
test_checksum();
|
||||||
|
test_dhcp_identifier_set_iaid();
|
||||||
|
|
||||||
test_discover_message(e);
|
test_discover_message(e);
|
||||||
test_addr_acq(e);
|
test_addr_acq(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user