blob: 3d75b132def6cf44656154b1ab682f7fb3c4d058 [file] [log] [blame] [raw]
Yu Watanabe426c1d32019-07-13 03:35:04 +09001/* SPDX-License-Identifier: LGPL-2.1+ */
2#pragma once
3
4#include <net/ethernet.h>
5#include <stdio.h>
6
7#include "hashmap.h"
8#include "in-addr-util.h"
9#include "list.h"
10
11typedef enum DHCPType {
12 DHCP_TYPE_NONE,
13 DHCP_TYPE_OFF,
14 DHCP_TYPE_ON,
15 DHCP_TYPE_ANY,
16 DHCP_TYPE_DHCP,
17 DHCP_TYPE_DHCP6,
18 DHCP_TYPE_AUTO6,
19 DHCP_TYPE_EITHER6,
20 DHCP_TYPE_IBFT,
21 _DHCP_TYPE_MAX,
22 _DHCP_TYPE_INVALID = -1,
23} DHCPType;
24
25typedef struct Address Address;
26typedef struct Link Link;
27typedef struct NetDev NetDev;
28typedef struct Network Network;
29typedef struct Route Route;
30typedef struct Context Context;
31
32struct Address {
33 Network *network;
34
35 union in_addr_union address, peer;
36 unsigned char prefixlen;
37 int family;
38
39 LIST_FIELDS(Address, addresses);
40};
41
42struct Route {
43 Network *network;
44
45 union in_addr_union dest, gateway;
46 unsigned char prefixlen;
47 int family;
48
49 LIST_FIELDS(Route, routes);
50};
51
52struct Network {
53 /* [Match] */
54 char *ifname;
55
56 /* [Link] */
57 struct ether_addr mac;
58 uint32_t mtu;
59
60 /* [Network] */
61 DHCPType dhcp_type;
62 char **dns;
63 char *vlan;
64 char *bridge;
65 char *bond;
66
67 /* [DHCP] */
68 char *hostname;
69 int dhcp_use_dns;
70
71 LIST_HEAD(Address, addresses);
72 LIST_HEAD(Route, routes);
73};
74
75struct NetDev {
76 /* [NetDev] */
77 char *ifname;
78 char *kind;
79 uint32_t mtu;
80};
81
82struct Link {
83 /* [Match] */
84 char *ifname;
85 struct ether_addr mac;
86};
87
88typedef struct Context {
89 Hashmap *networks_by_name;
90 Hashmap *netdevs_by_name;
91 Hashmap *links_by_name;
92} Context;
93
94int parse_cmdline_item(const char *key, const char *value, void *data);
95int context_merge_networks(Context *context);
96void context_clear(Context *context);
97
98Network *network_get(Context *context, const char *ifname);
99void network_dump(Network *network, FILE *f);
100int network_format(Network *network, char **ret);
101
102NetDev *netdev_get(Context *context, const char *ifname);
103void netdev_dump(NetDev *netdev, FILE *f);
104int netdev_format(NetDev *netdev, char **ret);
105
106Link *link_get(Context *context, const char *ifname);
107void link_dump(Link *link, FILE *f);
108int link_format(Link *link, char **ret);