]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp6-internal.h
Merge pull request #18886 from anitazha/shutdownconsole
[thirdparty/systemd.git] / src / libsystemd-network / dhcp6-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /***
5 Copyright © 2014-2015 Intel Corporation. All rights reserved.
6 ***/
7
8 #include <net/ethernet.h>
9 #include <netinet/in.h>
10
11 #include "sd-event.h"
12 #include "sd-dhcp6-client.h"
13
14 #include "hashmap.h"
15 #include "list.h"
16 #include "log-link.h"
17 #include "macro.h"
18 #include "sparse-endian.h"
19
20 typedef struct sd_dhcp6_option {
21 unsigned n_ref;
22
23 uint32_t enterprise_identifier;
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
31 /* Common option header */
32 typedef struct DHCP6Option {
33 be16_t code;
34 be16_t len;
35 uint8_t data[];
36 } _packed_ DHCP6Option;
37
38 /* Address option */
39 struct iaaddr {
40 struct in6_addr address;
41 be32_t lifetime_preferred;
42 be32_t lifetime_valid;
43 } _packed_;
44
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
53 typedef struct DHCP6Address DHCP6Address;
54
55 struct DHCP6Address {
56 LIST_FIELDS(DHCP6Address, addresses);
57
58 union {
59 struct iaaddr iaaddr;
60 struct iapdprefix iapdprefix;
61 };
62 };
63
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
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
78 /* Temporary Address option */
79 struct ia_ta {
80 be32_t id;
81 } _packed_;
82
83 typedef struct DHCP6IA {
84 uint16_t type;
85 union {
86 struct ia_na ia_na;
87 struct ia_pd ia_pd;
88 struct ia_ta ia_ta;
89 };
90
91 LIST_HEAD(DHCP6Address, addresses);
92 } DHCP6IA;
93
94 int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
95 size_t optlen, const void *optval);
96 int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia);
97 int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix);
98 int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
99 int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class);
100 int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class);
101 int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedHashmap *vendor_options);
102 int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
103 size_t *optlen, uint8_t **optvalue);
104 int dhcp6_option_parse_status(DHCP6Option *option, size_t len);
105 int dhcp6_option_parse_ia(sd_dhcp6_client *client, DHCP6Option *iaoption, DHCP6IA *ia, uint16_t *ret_status_code);
106 int dhcp6_option_parse_ip6addrs(uint8_t *optval, uint16_t optlen,
107 struct in6_addr **addrs, size_t count,
108 size_t *allocated);
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);
112
113 int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address);
114 int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
115 const void *packet, size_t len);
116
117 const char *dhcp6_message_type_to_string(int s) _const_;
118 int dhcp6_message_type_from_string(const char *s) _pure_;
119 const char *dhcp6_message_status_to_string(int s) _const_;
120 int dhcp6_message_status_from_string(const char *s) _pure_;
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__)