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