]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-dhcp-common.h
network: use ltype to distinguish DHCPv4 and DHCPv6
[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
12#define DHCP_ROUTE_METRIC 1024
13
67c311ab 14typedef struct Link Link;
256c75fd 15typedef struct Manager Manager;
22d37e5d 16typedef struct Network Network;
67c311ab 17
ca5ad760
YW
18typedef enum DHCPUseDomains {
19 DHCP_USE_DOMAINS_NO,
20 DHCP_USE_DOMAINS_YES,
21 DHCP_USE_DOMAINS_ROUTE,
22 _DHCP_USE_DOMAINS_MAX,
2d93c20e 23 _DHCP_USE_DOMAINS_INVALID = -EINVAL,
ca5ad760
YW
24} DHCPUseDomains;
25
2e5580a8
YW
26typedef enum DHCPOptionDataType {
27 DHCP_OPTION_DATA_UINT8,
28 DHCP_OPTION_DATA_UINT16,
29 DHCP_OPTION_DATA_UINT32,
30 DHCP_OPTION_DATA_STRING,
31 DHCP_OPTION_DATA_IPV4ADDRESS,
e7d5fe17 32 DHCP_OPTION_DATA_IPV6ADDRESS,
2e5580a8
YW
33 _DHCP_OPTION_DATA_MAX,
34 _DHCP_OPTION_DATA_INVALID,
35} DHCPOptionDataType;
36
ca5ad760
YW
37typedef struct DUID {
38 /* Value of Type in [DHCP] section */
39 DUIDType type;
40
41 uint8_t raw_data_len;
42 uint8_t raw_data[MAX_DUID_LEN];
43 usec_t llt_time;
4e26a5ba 44 bool set;
ca5ad760
YW
45} DUID;
46
67c311ab
YW
47bool link_dhcp_enabled(Link *link, int family);
48static inline bool link_dhcp4_enabled(Link *link) {
49 return link_dhcp_enabled(link, AF_INET);
50}
51static inline bool link_dhcp6_enabled(Link *link) {
52 return link_dhcp_enabled(link, AF_INET6);
53}
54
22d37e5d
YW
55void network_adjust_dhcp(Network *network);
56
28f9667d
YW
57const DUID *link_get_duid(Link *link, int family);
58static inline const DUID *link_get_dhcp4_duid(Link *link) {
4e26a5ba
YW
59 return link_get_duid(link, AF_INET);
60}
28f9667d 61static inline const DUID *link_get_dhcp6_duid(Link *link) {
4e26a5ba
YW
62 return link_get_duid(link, AF_INET6);
63}
64
28f9667d 65int dhcp_configure_duid(Link *link, const DUID *duid);
4e26a5ba 66int manager_request_product_uuid(Manager *m);
256c75fd 67
c995fa02
YW
68bool address_is_filtered(int family, const union in_addr_union *address, uint8_t prefixlen, Set *allow_list, Set *deny_list);
69static inline bool in4_address_is_filtered(const struct in_addr *address, Set *allow_list, Set *deny_list) {
70 return address_is_filtered(AF_INET, &(union in_addr_union) { .in = *address }, 32, allow_list, deny_list);
71}
72static inline bool in6_prefix_is_filtered(const struct in6_addr *prefix, uint8_t prefixlen, Set *allow_list, Set *deny_list) {
73 return address_is_filtered(AF_INET6, &(union in_addr_union) { .in6 = *prefix }, prefixlen, allow_list, deny_list);
74}
75
ca5ad760
YW
76const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
77DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
78
2e5580a8
YW
79const char *dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_;
80DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_;
81
ca5ad760 82CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
967e6a64 83CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_metric);
4f7331a8 84CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
ca5ad760 85CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
4f7331a8 86CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
ca5ad760
YW
87CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
88CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
6fda02e1 89CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
0e96961d 90CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
35f6a5cb 91CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
cde74a65 92CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
4e26a5ba
YW
93CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_type);
94CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_type);
cde74a65 95CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
4e26a5ba
YW
96CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_rawdata);
97CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_rawdata);
c995fa02 98CONFIG_PARSER_PROTOTYPE(config_parse_address_filter);