Debian Codegraph @

src/network/generator/network-generator.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdio.h>
5
6 #include "ether-addr-util.h"
7 #include "hashmap.h"
8 #include "in-addr-util.h"
9 #include "list.h"
10
11 typedef enum DHCPType {
12 DHCP_TYPE_NONE,
13 DHCP_TYPE_OFF, /* Same as DHCP_TYPE_NONE */
14 DHCP_TYPE_ON,
15 DHCP_TYPE_ANY, /* Same as DHCP_TYPE_ON */
16 DHCP_TYPE_DHCP, /* Actually means: DHCPv4 */
17 DHCP_TYPE_DHCP6,
18 DHCP_TYPE_AUTO6,
19 DHCP_TYPE_EITHER6,
20 DHCP_TYPE_IBFT,
21 DHCP_TYPE_LINK6,
22 DHCP_TYPE_LINK_LOCAL,
23 _DHCP_TYPE_MAX,
24 _DHCP_TYPE_INVALID = -EINVAL,
25 } DHCPType;
26
27 typedef struct Address Address;
28 typedef struct Link Link;
29 typedef struct NetDev NetDev;
30 typedef struct Network Network;
31 typedef struct Route Route;
32 typedef struct Context Context;
33
34 struct Address {
35 Network *network;
36
37 union in_addr_union address, peer;
38 unsigned char prefixlen;
39 int family;
40
41 LIST_FIELDS(Address, addresses);
42 };
43
44 struct Route {
45 Network *network;
46
47 union in_addr_union dest, gateway;
48 unsigned char prefixlen;
49 int family;
50
51 LIST_FIELDS(Route, routes);
52 };
53
54 struct Network {
55 /* [Match] */
56 char *ifname;
57 /* Parsed from BOOTIF= parameter. */
58 struct hw_addr_data match_mac;
59
60 /* [Link] */
61 struct ether_addr mac;
62 uint32_t mtu;
63
64 /* [Network] */
65 DHCPType dhcp_type;
66 char **dns;
67 char **vlan;
68 char *bridge;
69 char *bond;
70 char *ntp;
71
72 /* [DHCP] */
73 char *hostname;
74 int dhcp_use_dns;
75
76 LIST_HEAD(Address, addresses);
77 LIST_HEAD(Route, routes);
78 };
79
80 struct NetDev {
81 /* [NetDev] */
82 char *ifname;
83 char *kind;
84 uint32_t mtu;
85
86 /* [VLAN] */
87 uint16_t vlan_id;
88 };
89
90 struct Link {
91 char *filename;
92
93 /* [Match] */
94 struct hw_addr_data mac;
95
96 /* [Link] */
97 char *ifname;
98 char **policies;
99 char **alt_policies;
100 };
101
102 typedef struct Context {
103 Hashmap *networks_by_name;
104 Hashmap *netdevs_by_name;
105 Hashmap *links_by_filename;
106
107 /* If rd.bootif=0, ignore BOOTIF= parsing */
108 bool skip_bootif;
109 } Context;
110
111 int parse_cmdline_item(const char *key, const char *value, void *data);
112 int context_merge_networks(Context *context);
113 void context_clear(Context *context);
114 void context_finalize_bootif(Context *context);
115
116 Network *network_get(Context *context, const char *ifname);
117 void network_dump(Network *network, FILE *f);
118 int network_format(Network *network, char **ret);
119
120 NetDev *netdev_get(Context *context, const char *ifname);
121 void netdev_dump(NetDev *netdev, FILE *f);
122 int netdev_format(NetDev *netdev, char **ret);
123
124 Link *link_get(Context *context, const char *filename);
125 void link_dump(Link *link, FILE *f);
126 int link_format(Link *link, char **ret);