]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
e3169126 PF |
2 | #pragma once |
3 | ||
4 | /*** | |
810adae9 | 5 | Copyright © 2014-2015 Intel Corporation. All rights reserved. |
e3169126 PF |
6 | ***/ |
7 | ||
8 | #include <net/ethernet.h> | |
f12abb48 PF |
9 | #include <netinet/in.h> |
10 | ||
f12abb48 | 11 | #include "sd-event.h" |
35388783 | 12 | #include "sd-dhcp6-client.h" |
07630cea | 13 | |
99ccb8ff | 14 | #include "hashmap.h" |
35388783 | 15 | #include "list.h" |
a9aff361 | 16 | #include "macro.h" |
5977b71f | 17 | #include "network-common.h" |
07630cea | 18 | #include "sparse-endian.h" |
f12abb48 | 19 | |
e7d5fe17 AD |
20 | typedef struct sd_dhcp6_option { |
21 | unsigned n_ref; | |
22 | ||
99ccb8ff | 23 | uint32_t enterprise_identifier; |
e7d5fe17 AD |
24 | uint16_t option; |
25 | void *data; | |
26 | size_t length; | |
27 | } sd_dhcp6_option; | |
28 | ||
29 | extern const struct hash_ops dhcp6_option_hash_ops; | |
30 | ||
3bc424a3 PF |
31 | /* Common option header */ |
32 | typedef struct DHCP6Option { | |
33 | be16_t code; | |
34 | be16_t len; | |
35 | uint8_t data[]; | |
36 | } _packed_ DHCP6Option; | |
37 | ||
0dfe2a4b PF |
38 | /* Address option */ |
39 | struct iaaddr { | |
40 | struct in6_addr address; | |
41 | be32_t lifetime_preferred; | |
42 | be32_t lifetime_valid; | |
43 | } _packed_; | |
44 | ||
f8ad4dd4 PF |
45 | /* Prefix Delegation Prefix option */ |
46 | struct iapdprefix { | |
47 | be32_t lifetime_preferred; | |
48 | be32_t lifetime_valid; | |
49 | uint8_t prefixlen; | |
50 | struct in6_addr address; | |
51 | } _packed_; | |
52 | ||
f12abb48 PF |
53 | typedef struct DHCP6Address DHCP6Address; |
54 | ||
55 | struct DHCP6Address { | |
56 | LIST_FIELDS(DHCP6Address, addresses); | |
57 | ||
f8ad4dd4 PF |
58 | union { |
59 | struct iaaddr iaaddr; | |
60 | struct iapdprefix iapdprefix; | |
61 | }; | |
f12abb48 PF |
62 | }; |
63 | ||
e0026dcb PF |
64 | /* Non-temporary Address option */ |
65 | struct ia_na { | |
66 | be32_t id; | |
67 | be32_t lifetime_t1; | |
68 | be32_t lifetime_t2; | |
69 | } _packed_; | |
70 | ||
f8ad4dd4 PF |
71 | /* Prefix Delegation option */ |
72 | struct ia_pd { | |
73 | be32_t id; | |
74 | be32_t lifetime_t1; | |
75 | be32_t lifetime_t2; | |
76 | } _packed_; | |
77 | ||
e0026dcb PF |
78 | /* Temporary Address option */ |
79 | struct ia_ta { | |
80 | be32_t id; | |
81 | } _packed_; | |
82 | ||
35388783 | 83 | typedef struct DHCP6IA { |
f12abb48 | 84 | uint16_t type; |
e0026dcb PF |
85 | union { |
86 | struct ia_na ia_na; | |
f8ad4dd4 | 87 | struct ia_pd ia_pd; |
e0026dcb PF |
88 | struct ia_ta ia_ta; |
89 | }; | |
f12abb48 PF |
90 | |
91 | LIST_HEAD(DHCP6Address, addresses); | |
35388783 | 92 | } DHCP6IA; |
e3169126 | 93 | |
8d71f2b3 YW |
94 | typedef struct sd_dhcp6_client sd_dhcp6_client; |
95 | ||
fea8c180 | 96 | bool dhcp6_option_can_request(uint16_t option); |
f12ed3bf PF |
97 | int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code, |
98 | size_t optlen, const void *optval); | |
e0a18b74 | 99 | int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia); |
73b49d43 | 100 | int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix); |
8006aa32 | 101 | int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn); |
5a99444e | 102 | int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class); |
019951ec | 103 | int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class); |
99ccb8ff | 104 | int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedHashmap *vendor_options); |
b89a3758 YW |
105 | |
106 | int dhcp6_option_parse( | |
107 | const uint8_t *buf, | |
108 | size_t buflen, | |
109 | size_t *offset, | |
110 | uint16_t *ret_option_code, | |
111 | size_t *ret_option_data_len, | |
112 | const uint8_t **ret_option_data); | |
4af39cb8 | 113 | int dhcp6_option_parse_status(const uint8_t *data, size_t data_len, char **ret_status_message); |
8a895550 YW |
114 | int dhcp6_option_parse_ia( |
115 | sd_dhcp6_client *client, | |
116 | be32_t iaid, | |
117 | uint16_t option_code, | |
118 | size_t option_data_len, | |
119 | const uint8_t *option_data, | |
120 | DHCP6IA *ret); | |
ad3c8420 YW |
121 | int dhcp6_option_parse_addresses( |
122 | const uint8_t *optval, | |
123 | size_t optlen, | |
124 | struct in6_addr **addrs, | |
125 | size_t *count); | |
b27dcf08 YW |
126 | int dhcp6_option_parse_domainname_list(const uint8_t *optval, size_t optlen, char ***ret); |
127 | int dhcp6_option_parse_domainname(const uint8_t *optval, size_t optlen, char **ret); | |
34e8c5a2 | 128 | |
1a6c9136 | 129 | int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address); |
34e8c5a2 PF |
130 | int dhcp6_network_send_udp_socket(int s, struct in6_addr *address, |
131 | const void *packet, size_t len); | |
a9aff361 PF |
132 | |
133 | const char *dhcp6_message_type_to_string(int s) _const_; | |
134 | int dhcp6_message_type_from_string(const char *s) _pure_; | |
631bbe71 PF |
135 | const char *dhcp6_message_status_to_string(int s) _const_; |
136 | int dhcp6_message_status_from_string(const char *s) _pure_; | |
35388783 | 137 | |
8d71f2b3 YW |
138 | void dhcp6_client_set_test_mode(sd_dhcp6_client *client, bool test_mode); |
139 | ||
a0c2541b | 140 | #define log_dhcp6_client_errno(client, error, fmt, ...) \ |
00dd6d77 | 141 | log_interface_prefix_full_errno( \ |
a0c2541b | 142 | "DHCPv6 client: ", \ |
5977b71f | 143 | sd_dhcp6_client, client, \ |
a0c2541b ZJS |
144 | error, fmt, ##__VA_ARGS__) |
145 | #define log_dhcp6_client(client, fmt, ...) \ | |
00dd6d77 ZJS |
146 | log_interface_prefix_full_errno_zerook( \ |
147 | "DHCPv6 client: ", \ | |
5977b71f | 148 | sd_dhcp6_client, client, \ |
00dd6d77 | 149 | 0, fmt, ##__VA_ARGS__) |