]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp6-internal.h
9ce6dcd02c3b5611febadfaba091208cd6557f60
[thirdparty/systemd.git] / src / libsystemd-network / dhcp6-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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
13 #include "list.h"
14 #include "hashmap.h"
15 #include "macro.h"
16 #include "sparse-endian.h"
17
18 typedef struct sd_dhcp6_option {
19 unsigned n_ref;
20
21 uint32_t enterprise_identifier;
22 uint16_t option;
23 void *data;
24 size_t length;
25 } sd_dhcp6_option;
26
27 extern const struct hash_ops dhcp6_option_hash_ops;
28
29 /* Common option header */
30 typedef struct DHCP6Option {
31 be16_t code;
32 be16_t len;
33 uint8_t data[];
34 } _packed_ DHCP6Option;
35
36 /* Address option */
37 struct iaaddr {
38 struct in6_addr address;
39 be32_t lifetime_preferred;
40 be32_t lifetime_valid;
41 } _packed_;
42
43 /* Prefix Delegation Prefix option */
44 struct iapdprefix {
45 be32_t lifetime_preferred;
46 be32_t lifetime_valid;
47 uint8_t prefixlen;
48 struct in6_addr address;
49 } _packed_;
50
51 typedef struct DHCP6Address DHCP6Address;
52
53 struct DHCP6Address {
54 LIST_FIELDS(DHCP6Address, addresses);
55
56 union {
57 struct iaaddr iaaddr;
58 struct iapdprefix iapdprefix;
59 };
60 };
61
62 /* Non-temporary Address option */
63 struct ia_na {
64 be32_t id;
65 be32_t lifetime_t1;
66 be32_t lifetime_t2;
67 } _packed_;
68
69 /* Prefix Delegation option */
70 struct ia_pd {
71 be32_t id;
72 be32_t lifetime_t1;
73 be32_t lifetime_t2;
74 } _packed_;
75
76 /* Temporary Address option */
77 struct ia_ta {
78 be32_t id;
79 } _packed_;
80
81 struct DHCP6IA {
82 uint16_t type;
83 union {
84 struct ia_na ia_na;
85 struct ia_pd ia_pd;
86 struct ia_ta ia_ta;
87 };
88
89 LIST_HEAD(DHCP6Address, addresses);
90 };
91
92 typedef struct DHCP6IA DHCP6IA;
93
94 #define log_dhcp6_client_errno(p, error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "DHCPv6 CLIENT: " fmt, ##__VA_ARGS__)
95 #define log_dhcp6_client(p, fmt, ...) log_dhcp6_client_errno(p, 0, fmt, ##__VA_ARGS__)
96
97 int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
98 size_t optlen, const void *optval);
99 int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia);
100 int dhcp6_option_append_pd(uint8_t *buf, size_t len, const DHCP6IA *pd, DHCP6Address *hint_pd_prefix);
101 int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
102 int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char **user_class);
103 int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char **user_class);
104 int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedHashmap *vendor_options);
105 int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
106 size_t *optlen, uint8_t **optvalue);
107 int dhcp6_option_parse_status(DHCP6Option *option, size_t len);
108 int dhcp6_option_parse_ia(DHCP6Option *iaoption, DHCP6IA *ia, uint16_t *ret_status_code);
109 int dhcp6_option_parse_ip6addrs(uint8_t *optval, uint16_t optlen,
110 struct in6_addr **addrs, size_t count,
111 size_t *allocated);
112 int dhcp6_option_parse_domainname_list(const uint8_t *optval, uint16_t optlen,
113 char ***str_arr);
114 int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char **str);
115
116 int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address);
117 int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
118 const void *packet, size_t len);
119
120 const char *dhcp6_message_type_to_string(int s) _const_;
121 int dhcp6_message_type_from_string(const char *s) _pure_;
122 const char *dhcp6_message_status_to_string(int s) _const_;
123 int dhcp6_message_status_from_string(const char *s) _pure_;