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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <net/ethernet.h>
#include <stdio.h>
#include "hashmap.h"
#include "in-addr-util.h"
#include "list.h"
typedef enum DHCPType {
DHCP_TYPE_NONE,
DHCP_TYPE_OFF,
DHCP_TYPE_ON,
DHCP_TYPE_ANY,
DHCP_TYPE_DHCP,
DHCP_TYPE_DHCP6,
DHCP_TYPE_AUTO6,
DHCP_TYPE_EITHER6,
DHCP_TYPE_IBFT,
_DHCP_TYPE_MAX,
_DHCP_TYPE_INVALID = -1,
} DHCPType;
typedef struct Address Address;
typedef struct Link Link;
typedef struct NetDev NetDev;
typedef struct Network Network;
typedef struct Route Route;
typedef struct Context Context;
struct Address {
Network *network;
union in_addr_union address, peer;
unsigned char prefixlen;
int family;
LIST_FIELDS(Address, addresses);
};
struct Route {
Network *network;
union in_addr_union dest, gateway;
unsigned char prefixlen;
int family;
LIST_FIELDS(Route, routes);
};
struct Network {
/* [Match] */
char *ifname;
/* [Link] */
struct ether_addr mac;
uint32_t mtu;
/* [Network] */
DHCPType dhcp_type;
char **dns;
char *vlan;
char *bridge;
char *bond;
/* [DHCP] */
char *hostname;
int dhcp_use_dns;
LIST_HEAD(Address, addresses);
LIST_HEAD(Route, routes);
};
struct NetDev {
/* [NetDev] */
char *ifname;
char *kind;
uint32_t mtu;
};
struct Link {
/* [Match] */
char *ifname;
struct ether_addr mac;
};
typedef struct Context {
Hashmap *networks_by_name;
Hashmap *netdevs_by_name;
Hashmap *links_by_name;
} Context;
int parse_cmdline_item(const char *key, const char *value, void *data);
int context_merge_networks(Context *context);
void context_clear(Context *context);
Network *network_get(Context *context, const char *ifname);
void network_dump(Network *network, FILE *f);
int network_format(Network *network, char **ret);
NetDev *netdev_get(Context *context, const char *ifname);
void netdev_dump(NetDev *netdev, FILE *f);
int netdev_format(NetDev *netdev, char **ret);
Link *link_get(Context *context, const char *ifname);
void link_dump(Link *link, FILE *f);
int link_format(Link *link, char **ret);
|