1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 Copyright © 2014-2015 Intel Corporation. All rights reserved.
8 #include <net/ethernet.h>
9 #include <netinet/in.h>
12 #include "sd-dhcp6-client.h"
14 #include "dhcp-identifier.h"
15 #include "dhcp6-protocol.h"
16 #include "ether-addr-util.h"
20 #include "network-common.h"
21 #include "sparse-endian.h"
23 typedef struct sd_dhcp6_option
{
26 uint32_t enterprise_identifier
;
32 extern const struct hash_ops dhcp6_option_hash_ops
;
34 /* Common option header */
35 typedef struct DHCP6Option
{
39 } _packed_ DHCP6Option
;
43 struct in6_addr address
;
44 be32_t lifetime_preferred
;
45 be32_t lifetime_valid
;
48 /* Prefix Delegation Prefix option */
50 be32_t lifetime_preferred
;
51 be32_t lifetime_valid
;
53 struct in6_addr address
;
56 typedef struct DHCP6Address DHCP6Address
;
59 LIST_FIELDS(DHCP6Address
, addresses
);
63 struct iapdprefix iapdprefix
;
73 typedef struct DHCP6IA
{
75 struct ia_header header
;
77 LIST_HEAD(DHCP6Address
, addresses
);
80 /* what to request from the server, addresses (IA_NA) and/or prefixes (IA_PD) */
81 typedef enum DHCP6RequestIA
{
82 DHCP6_REQUEST_IA_NA
= 1 << 0,
83 DHCP6_REQUEST_IA_TA
= 1 << 1, /* currently not used */
84 DHCP6_REQUEST_IA_PD
= 1 << 2,
87 typedef struct sd_dhcp6_client
{
95 struct in6_addr local_address
;
96 struct hw_addr_data hw_addr
;
100 DHCP6RequestIA request_ia
;
101 be32_t transaction_id
;
102 usec_t transaction_start
;
103 struct sd_dhcp6_lease
*lease
;
105 bool information_request
;
113 sd_event_source
*receive_message
;
114 usec_t retransmit_time
;
115 uint8_t retransmit_count
;
116 sd_event_source
*timeout_resend
;
117 sd_event_source
*timeout_expire
;
118 sd_event_source
*timeout_t1
;
119 sd_event_source
*timeout_t2
;
120 sd_dhcp6_client_callback_t callback
;
124 usec_t information_request_time_usec
;
125 usec_t information_refresh_time_usec
;
126 OrderedHashmap
*extra_options
;
127 OrderedHashmap
*vendor_options
;
129 /* Ignore ifindex when generating iaid. See dhcp_identifier_set_iaid(). */
133 bool dhcp6_option_can_request(uint16_t option
);
134 int dhcp6_option_append(uint8_t **buf
, size_t *buflen
, uint16_t code
,
135 size_t optlen
, const void *optval
);
136 int dhcp6_option_append_ia(uint8_t **buf
, size_t *buflen
, const DHCP6IA
*ia
);
137 int dhcp6_option_append_fqdn(uint8_t **buf
, size_t *buflen
, const char *fqdn
);
138 int dhcp6_option_append_user_class(uint8_t **buf
, size_t *buflen
, char * const *user_class
);
139 int dhcp6_option_append_vendor_class(uint8_t **buf
, size_t *buflen
, char * const *user_class
);
140 int dhcp6_option_append_vendor_option(uint8_t **buf
, size_t *buflen
, OrderedHashmap
*vendor_options
);
142 int dhcp6_option_parse(
146 uint16_t *ret_option_code
,
147 size_t *ret_option_data_len
,
148 const uint8_t **ret_option_data
);
149 int dhcp6_option_parse_status(const uint8_t *data
, size_t data_len
, char **ret_status_message
);
150 int dhcp6_option_parse_ia(
151 sd_dhcp6_client
*client
,
153 uint16_t option_code
,
154 size_t option_data_len
,
155 const uint8_t *option_data
,
157 int dhcp6_option_parse_addresses(
158 const uint8_t *optval
,
160 struct in6_addr
**addrs
,
162 int dhcp6_option_parse_domainname_list(const uint8_t *optval
, size_t optlen
, char ***ret
);
163 int dhcp6_option_parse_domainname(const uint8_t *optval
, size_t optlen
, char **ret
);
165 int dhcp6_network_bind_udp_socket(int ifindex
, struct in6_addr
*address
);
166 int dhcp6_network_send_udp_socket(int s
, struct in6_addr
*address
,
167 const void *packet
, size_t len
);
169 const char *dhcp6_message_type_to_string(DHCP6MessageType t
) _const_
;
170 DHCP6MessageType
dhcp6_message_type_from_string(const char *s
) _pure_
;
171 const char *dhcp6_message_status_to_string(DHCP6Status s
) _const_
;
172 DHCP6Status
dhcp6_message_status_from_string(const char *s
) _pure_
;
174 void dhcp6_client_set_test_mode(sd_dhcp6_client
*client
, bool test_mode
);
176 #define log_dhcp6_client_errno(client, error, fmt, ...) \
177 log_interface_prefix_full_errno( \
179 sd_dhcp6_client, client, \
180 error, fmt, ##__VA_ARGS__)
181 #define log_dhcp6_client(client, fmt, ...) \
182 log_interface_prefix_full_errno_zerook( \
184 sd_dhcp6_client, client, \
185 0, fmt, ##__VA_ARGS__)