Yu Watanabe | 426c1d3 | 2019-07-13 03:35:04 +0900 | [diff] [blame] | 1 | /* 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 | |
| 11 | typedef 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 | |
| 25 | typedef struct Address Address; |
| 26 | typedef struct Link Link; |
| 27 | typedef struct NetDev NetDev; |
| 28 | typedef struct Network Network; |
| 29 | typedef struct Route Route; |
| 30 | typedef struct Context Context; |
| 31 | |
| 32 | struct 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 | |
| 42 | struct 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 | |
| 52 | struct 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 | |
| 75 | struct NetDev { |
| 76 | /* [NetDev] */ |
| 77 | char *ifname; |
| 78 | char *kind; |
| 79 | uint32_t mtu; |
| 80 | }; |
| 81 | |
| 82 | struct Link { |
| 83 | /* [Match] */ |
| 84 | char *ifname; |
| 85 | struct ether_addr mac; |
| 86 | }; |
| 87 | |
| 88 | typedef struct Context { |
| 89 | Hashmap *networks_by_name; |
| 90 | Hashmap *netdevs_by_name; |
| 91 | Hashmap *links_by_name; |
| 92 | } Context; |
| 93 | |
| 94 | int parse_cmdline_item(const char *key, const char *value, void *data); |
| 95 | int context_merge_networks(Context *context); |
| 96 | void context_clear(Context *context); |
| 97 | |
| 98 | Network *network_get(Context *context, const char *ifname); |
| 99 | void network_dump(Network *network, FILE *f); |
| 100 | int network_format(Network *network, char **ret); |
| 101 | |
| 102 | NetDev *netdev_get(Context *context, const char *ifname); |
| 103 | void netdev_dump(NetDev *netdev, FILE *f); |
| 104 | int netdev_format(NetDev *netdev, char **ret); |
| 105 | |
| 106 | Link *link_get(Context *context, const char *ifname); |
| 107 | void link_dump(Link *link, FILE *f); |
| 108 | int link_format(Link *link, char **ret); |