]>
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 YW |
15 | #include "list.h" |
16 | #include "log-link.h" | |
a9aff361 | 17 | #include "macro.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 | |
f12ed3bf PF |
94 | int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code, |
95 | size_t optlen, const void *optval); | |
e0a18b74 | 96 | int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia); |
73b49d43 | 97 | int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix); |
8006aa32 | 98 | int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn); |
5a99444e | 99 | int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class); |
019951ec | 100 | int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class); |
99ccb8ff | 101 | int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedHashmap *vendor_options); |
f12ed3bf PF |
102 | int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode, |
103 | size_t *optlen, uint8_t **optvalue); | |
84452783 | 104 | int dhcp6_option_parse_status(DHCP6Option *option, size_t len); |
35388783 | 105 | int dhcp6_option_parse_ia(sd_dhcp6_client *client, DHCP6Option *iaoption, DHCP6IA *ia, uint16_t *ret_status_code); |
b553817c PF |
106 | int dhcp6_option_parse_ip6addrs(uint8_t *optval, uint16_t optlen, |
107 | struct in6_addr **addrs, size_t count, | |
108 | size_t *allocated); | |
c43eea9f BG |
109 | int dhcp6_option_parse_domainname_list(const uint8_t *optval, uint16_t optlen, |
110 | char ***str_arr); | |
111 | int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char **str); | |
34e8c5a2 | 112 | |
1a6c9136 | 113 | int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address); |
34e8c5a2 PF |
114 | int dhcp6_network_send_udp_socket(int s, struct in6_addr *address, |
115 | const void *packet, size_t len); | |
a9aff361 PF |
116 | |
117 | const char *dhcp6_message_type_to_string(int s) _const_; | |
118 | int dhcp6_message_type_from_string(const char *s) _pure_; | |
631bbe71 PF |
119 | const char *dhcp6_message_status_to_string(int s) _const_; |
120 | int dhcp6_message_status_from_string(const char *s) _pure_; | |
35388783 YW |
121 | |
122 | #define log_dhcp6_client_errno(client, error, fmt, ...) \ | |
123 | ({ \ | |
124 | int _e = (error); \ | |
125 | if (DEBUG_LOGGING) \ | |
126 | log_interface_full_errno( \ | |
127 | sd_dhcp6_client_get_ifname(client), \ | |
128 | LOG_DEBUG, _e, "DHCPv6 client: " fmt, \ | |
129 | ##__VA_ARGS__); \ | |
130 | -ERRNO_VALUE(_e); \ | |
131 | }) | |
132 | #define log_dhcp6_client(client, fmt, ...) \ | |
133 | log_dhcp6_client_errno(client, 0, fmt, ##__VA_ARGS__) |