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, 14 DHCP_TYPE_ON, 15 DHCP_TYPE_ANY, 16 DHCP_TYPE_DHCP4, 17 DHCP_TYPE_DHCP6, 18 DHCP_TYPE_AUTO6, 19 DHCP_TYPE_EITHER6, 20 DHCP_TYPE_IBFT, 21 DHCP_TYPE_LINK6, 22 _DHCP_TYPE_MAX, 23 _DHCP_TYPE_INVALID = -EINVAL, 24 } DHCPType; 25 26 typedef struct Address Address; 27 typedef struct Link Link; 28 typedef struct NetDev NetDev; 29 typedef struct Network Network; 30 typedef struct Route Route; 31 typedef struct Context Context; 32 33 struct Address { 34 Network *network; 35 36 union in_addr_union address, peer; 37 unsigned char prefixlen; 38 int family; 39 40 LIST_FIELDS(Address, addresses); 41 }; 42 43 struct Route { 44 Network *network; 45 46 union in_addr_union dest, gateway; 47 unsigned char prefixlen; 48 int family; 49 50 LIST_FIELDS(Route, routes); 51 }; 52 53 struct Network { 54 /* [Match] */ 55 char *ifname; 56 57 /* [Link] */ 58 struct ether_addr mac; 59 uint32_t mtu; 60 61 /* [Network] */ 62 DHCPType dhcp_type; 63 char **dns; 64 char *vlan; 65 char *bridge; 66 char *bond; 67 68 /* [DHCP] */ 69 char *hostname; 70 int dhcp_use_dns; 71 72 LIST_HEAD(Address, addresses); 73 LIST_HEAD(Route, routes); 74 }; 75 76 struct NetDev { 77 /* [NetDev] */ 78 char *ifname; 79 char *kind; 80 uint32_t mtu; 81 }; 82 83 struct Link { 84 char *filename; 85 86 /* [Match] */ 87 struct hw_addr_data mac; 88 89 /* [Link] */ 90 char *ifname; 91 char **policies; 92 char **alt_policies; 93 }; 94 95 typedef struct Context { 96 Hashmap *networks_by_name; 97 Hashmap *netdevs_by_name; 98 Hashmap *links_by_filename; 99 } Context; 100 101 int parse_cmdline_item(const char *key, const char *value, void *data); 102 int context_merge_networks(Context *context); 103 void context_clear(Context *context); 104 105 Network *network_get(Context *context, const char *ifname); 106 void network_dump(Network *network, FILE *f); 107 int network_format(Network *network, char **ret); 108 109 NetDev *netdev_get(Context *context, const char *ifname); 110 void netdev_dump(NetDev *netdev, FILE *f); 111 int netdev_format(NetDev *netdev, char **ret); 112 113 Link *link_get(Context *context, const char *filename); 114 void link_dump(Link *link, FILE *f); 115 int link_format(Link *link, char **ret); 116