summaryrefslogtreecommitdiffstats
path: root/test/parser/network.c
blob: 9c5730994adc3043f172ee59d3c40db71d69d488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <string.h>
#include <types/types.h>
#include <talloc/talloc.h>
#include <sys/socket.h>
#include <linux/if.h>
#include "network.h"

struct interface {
	int	ifindex;
	char	name[IFNAMSIZ];
	uint8_t	hwaddr[HWADDR_SIZE];

	enum {
		IFSTATE_NEW,
		IFSTATE_UP_WAITING_LINK,
		IFSTATE_CONFIGURED,
		IFSTATE_IGNORED,
	} state;

	struct list_item list;
	struct process *udhcpc_process;
	struct discover_device *dev;
};

static struct interface test = {
	.name = "em1",
	.hwaddr = {1,2,3,4,5,6},
};

static struct interface *find_interface_by_name(struct network *network,
				const char *name)
{
	(void)network;

	if (!strcmp(test.name, name))
		return &test;

	return NULL;
}

uint8_t *find_mac_by_name(void *ctx, struct network *network,
		const char *name)
{
	struct interface *interface;
	(void)network;

	interface = find_interface_by_name(network, name);
	if (!interface)
		return NULL;

	return talloc_memdup(ctx, &interface->hwaddr,
			     sizeof(uint8_t) * HWADDR_SIZE);
}
OpenPOWER on IntegriCloud