]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp6-internal.h
tree-wide: make format_ifname() or friends return negative errno on failure
[thirdparty/systemd.git] / src / libsystemd-network / dhcp6-internal.h
CommitLineData
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
20typedef 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
29extern const struct hash_ops dhcp6_option_hash_ops;
30
3bc424a3
PF
31/* Common option header */
32typedef struct DHCP6Option {
33 be16_t code;
34 be16_t len;
35 uint8_t data[];
36} _packed_ DHCP6Option;
37
0dfe2a4b
PF
38/* Address option */
39struct 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 */
46struct 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
53typedef struct DHCP6Address DHCP6Address;
54
55struct 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 */
65struct 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 */
72struct 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 */
79struct ia_ta {
80 be32_t id;
81} _packed_;
82
35388783 83typedef 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
94typedef struct sd_dhcp6_client sd_dhcp6_client;
95
f12ed3bf
PF
96int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
97 size_t optlen, const void *optval);
e0a18b74 98int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia);
73b49d43 99int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix);
8006aa32 100int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
5a99444e 101int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class);
019951ec 102int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class);
99ccb8ff 103int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedHashmap *vendor_options);
f12ed3bf
PF
104int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
105 size_t *optlen, uint8_t **optvalue);
84452783 106int dhcp6_option_parse_status(DHCP6Option *option, size_t len);
469fd57f 107int dhcp6_option_parse_ia(sd_dhcp6_client *client, DHCP6Option *iaoption, be32_t iaid, DHCP6IA *ia, uint16_t *ret_status_code);
b553817c 108int dhcp6_option_parse_ip6addrs(uint8_t *optval, uint16_t optlen,
319a4f4b 109 struct in6_addr **addrs, size_t count);
c43eea9f
BG
110int dhcp6_option_parse_domainname_list(const uint8_t *optval, uint16_t optlen,
111 char ***str_arr);
112int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char **str);
34e8c5a2 113
1a6c9136 114int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address);
34e8c5a2
PF
115int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
116 const void *packet, size_t len);
a9aff361
PF
117
118const char *dhcp6_message_type_to_string(int s) _const_;
119int dhcp6_message_type_from_string(const char *s) _pure_;
631bbe71
PF
120const char *dhcp6_message_status_to_string(int s) _const_;
121int dhcp6_message_status_from_string(const char *s) _pure_;
35388783 122
8d71f2b3
YW
123void dhcp6_client_set_test_mode(sd_dhcp6_client *client, bool test_mode);
124
a0c2541b 125#define log_dhcp6_client_errno(client, error, fmt, ...) \
00dd6d77 126 log_interface_prefix_full_errno( \
a0c2541b
ZJS
127 "DHCPv6 client: ", \
128 sd_dhcp6_client_get_ifname(client), \
129 error, fmt, ##__VA_ARGS__)
130#define log_dhcp6_client(client, fmt, ...) \
00dd6d77
ZJS
131 log_interface_prefix_full_errno_zerook( \
132 "DHCPv6 client: ", \
133 sd_dhcp6_client_get_ifname(client), \
134 0, fmt, ##__VA_ARGS__)