1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <netinet/in.h>
5 
6 #include "conf-parser.h"
7 #include "dhcp-identifier.h"
8 #include "in-addr-util.h"
9 #include "set.h"
10 #include "time-util.h"
11 
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 #define UPLINK_INDEX_SELF -2 /* the interface itself is uplink */
16 
17 #define DHCP_ROUTE_METRIC 1024
18 #define DHCP6PD_ROUTE_METRIC 256
19 
20 typedef struct Link Link;
21 typedef struct Manager Manager;
22 typedef struct Network Network;
23 
24 typedef enum DHCPUseDomains {
25         DHCP_USE_DOMAINS_NO,
26         DHCP_USE_DOMAINS_YES,
27         DHCP_USE_DOMAINS_ROUTE,
28         _DHCP_USE_DOMAINS_MAX,
29         _DHCP_USE_DOMAINS_INVALID = -EINVAL,
30 } DHCPUseDomains;
31 
32 typedef enum DHCPOptionDataType {
33         DHCP_OPTION_DATA_UINT8,
34         DHCP_OPTION_DATA_UINT16,
35         DHCP_OPTION_DATA_UINT32,
36         DHCP_OPTION_DATA_STRING,
37         DHCP_OPTION_DATA_IPV4ADDRESS,
38         DHCP_OPTION_DATA_IPV6ADDRESS,
39         _DHCP_OPTION_DATA_MAX,
40         _DHCP_OPTION_DATA_INVALID,
41 } DHCPOptionDataType;
42 
43 typedef struct DUID {
44         /* Value of Type in [DHCP] section */
45         DUIDType type;
46 
47         uint8_t raw_data_len;
48         uint8_t raw_data[MAX_DUID_LEN];
49         usec_t llt_time;
50         bool set;
51 } DUID;
52 
53 uint32_t link_get_dhcp4_route_table(Link *link);
54 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
55 
56 bool link_dhcp_enabled(Link *link, int family);
link_dhcp4_enabled(Link * link)57 static inline bool link_dhcp4_enabled(Link *link) {
58         return link_dhcp_enabled(link, AF_INET);
59 }
link_dhcp6_enabled(Link * link)60 static inline bool link_dhcp6_enabled(Link *link) {
61         return link_dhcp_enabled(link, AF_INET6);
62 }
63 
64 void network_adjust_dhcp(Network *network);
65 
66 const DUID *link_get_duid(Link *link, int family);
link_get_dhcp4_duid(Link * link)67 static inline const DUID *link_get_dhcp4_duid(Link *link) {
68         return link_get_duid(link, AF_INET);
69 }
link_get_dhcp6_duid(Link * link)70 static inline const DUID *link_get_dhcp6_duid(Link *link) {
71         return link_get_duid(link, AF_INET6);
72 }
73 
74 int dhcp_configure_duid(Link *link, const DUID *duid);
75 int manager_request_product_uuid(Manager *m);
76 
77 bool address_is_filtered(int family, const union in_addr_union *address, uint8_t prefixlen, Set *allow_list, Set *deny_list);
in4_address_is_filtered(const struct in_addr * address,Set * allow_list,Set * deny_list)78 static 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 }
in6_prefix_is_filtered(const struct in6_addr * prefix,uint8_t prefixlen,Set * allow_list,Set * deny_list)81 static 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 
85 const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
86 DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
87 
88 const char *dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_;
89 DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_;
90 
91 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
92 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_metric);
93 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
94 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
95 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
96 CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
97 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table);
98 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
99 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
100 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
101 CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
102 CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_type);
103 CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_type);
104 CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
105 CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_rawdata);
106 CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_rawdata);
107 CONFIG_PARSER_PROTOTYPE(config_parse_uplink);
108