]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-dhcp-common.h
network: move config_parse_uplink() to networkd-dhcp-common.[ch]
[thirdparty/systemd.git] / src / network / networkd-dhcp-common.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
ca5ad760
YW
2#pragma once
3
cde74a65
YW
4#include <netinet/in.h>
5
ca5ad760
YW
6#include "conf-parser.h"
7#include "dhcp-identifier.h"
c995fa02
YW
8#include "in-addr-util.h"
9#include "set.h"
ca5ad760
YW
10#include "time-util.h"
11
2cba2146
YW
12/* Special values for *_uplink_index. */
13#define UPLINK_INDEX_AUTO 0 /* uplink will be selected automatically */
14#define UPLINK_INDEX_NONE -1 /* uplink will not be selected automatically */
15
ca5ad760 16#define DHCP_ROUTE_METRIC 1024
d0619f2c 17#define DHCP6PD_ROUTE_METRIC 256
ca5ad760 18
67c311ab 19typedef struct Link Link;
256c75fd 20typedef struct Manager Manager;
22d37e5d 21typedef struct Network Network;
67c311ab 22
ca5ad760
YW
23typedef enum DHCPUseDomains {
24 DHCP_USE_DOMAINS_NO,
25 DHCP_USE_DOMAINS_YES,
26 DHCP_USE_DOMAINS_ROUTE,
27 _DHCP_USE_DOMAINS_MAX,
2d93c20e 28 _DHCP_USE_DOMAINS_INVALID = -EINVAL,
ca5ad760
YW
29} DHCPUseDomains;
30
2e5580a8
YW
31typedef enum DHCPOptionDataType {
32 DHCP_OPTION_DATA_UINT8,
33 DHCP_OPTION_DATA_UINT16,
34 DHCP_OPTION_DATA_UINT32,
35 DHCP_OPTION_DATA_STRING,
36 DHCP_OPTION_DATA_IPV4ADDRESS,
e7d5fe17 37 DHCP_OPTION_DATA_IPV6ADDRESS,
2e5580a8
YW
38 _DHCP_OPTION_DATA_MAX,
39 _DHCP_OPTION_DATA_INVALID,
40} DHCPOptionDataType;
41
ca5ad760
YW
42typedef struct DUID {
43 /* Value of Type in [DHCP] section */
44 DUIDType type;
45
46 uint8_t raw_data_len;
47 uint8_t raw_data[MAX_DUID_LEN];
48 usec_t llt_time;
4e26a5ba 49 bool set;
ca5ad760
YW
50} DUID;
51
e47bcb7d
YW
52uint32_t link_get_dhcp4_route_table(Link *link);
53uint32_t link_get_dhcp6_route_table(Link *link);
54uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
55
67c311ab
YW
56bool link_dhcp_enabled(Link *link, int family);
57static inline bool link_dhcp4_enabled(Link *link) {
58 return link_dhcp_enabled(link, AF_INET);
59}
60static inline bool link_dhcp6_enabled(Link *link) {
61 return link_dhcp_enabled(link, AF_INET6);
62}
63
22d37e5d
YW
64void network_adjust_dhcp(Network *network);
65
28f9667d
YW
66const DUID *link_get_duid(Link *link, int family);
67static inline const DUID *link_get_dhcp4_duid(Link *link) {
4e26a5ba
YW
68 return link_get_duid(link, AF_INET);
69}
28f9667d 70static inline const DUID *link_get_dhcp6_duid(Link *link) {
4e26a5ba
YW
71 return link_get_duid(link, AF_INET6);
72}
73
28f9667d 74int dhcp_configure_duid(Link *link, const DUID *duid);
4e26a5ba 75int manager_request_product_uuid(Manager *m);
256c75fd 76
c995fa02
YW
77bool address_is_filtered(int family, const union in_addr_union *address, uint8_t prefixlen, Set *allow_list, Set *deny_list);
78static inline bool in4_address_is_filtered(const struct in_addr *address, Set *allow_list, Set *deny_list) {
79 return address_is_filtered(AF_INET, &(union in_addr_union) { .in = *address }, 32, allow_list, deny_list);
80}
81static inline bool in6_prefix_is_filtered(const struct in6_addr *prefix, uint8_t prefixlen, Set *allow_list, Set *deny_list) {
82 return address_is_filtered(AF_INET6, &(union in_addr_union) { .in6 = *prefix }, prefixlen, allow_list, deny_list);
83}
84
ca5ad760
YW
85const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
86DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
87
2e5580a8
YW
88const char *dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_;
89DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_;
90
ca5ad760 91CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
967e6a64 92CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_metric);
4f7331a8 93CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
ca5ad760 94CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
4f7331a8 95CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
ca5ad760 96CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
e47bcb7d 97CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table);
6fda02e1 98CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
0e96961d 99CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
35f6a5cb 100CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
cde74a65 101CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
4e26a5ba
YW
102CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_type);
103CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_type);
cde74a65 104CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
4e26a5ba
YW
105CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_rawdata);
106CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_rawdata);
2cba2146 107CONFIG_PARSER_PROTOTYPE(config_parse_uplink);