Bug Summary

File:build-scan/../src/libsystemd-network/sd-dhcp6-lease.c
Warning:line 56, column 17
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name sd-dhcp6-lease.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I src/libsystemd-network/libsystemd-network.a.p -I src/libsystemd-network -I ../src/libsystemd-network -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I . -I .. -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/libsystemd-network/sd-dhcp6-lease.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2/***
3 Copyright © 2014-2015 Intel Corporation. All rights reserved.
4***/
5
6#include <errno(*__errno_location ()).h>
7
8#include "alloc-util.h"
9#include "dhcp6-lease-internal.h"
10#include "dhcp6-protocol.h"
11#include "strv.h"
12#include "util.h"
13
14int dhcp6_lease_clear_timers(DHCP6IA *ia) {
15 assert_return(ia, -EINVAL)do { if (!(((__builtin_expect(!!(ia),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("ia"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 15, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
16
17 ia->timeout_t1 = sd_event_source_unref(ia->timeout_t1);
18 ia->timeout_t2 = sd_event_source_unref(ia->timeout_t2);
19
20 return 0;
21}
22
23int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire) {
24 DHCP6Address *addr;
25 uint32_t valid = 0, t;
26
27 assert_return(ia, -EINVAL)do { if (!(((__builtin_expect(!!(ia),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("ia"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 27, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
28 assert_return(expire, -EINVAL)do { if (!(((__builtin_expect(!!(expire),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("expire"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 28, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
29
30 LIST_FOREACH(addresses, addr, ia->addresses)for ((addr) = (ia->addresses); (addr); (addr) = (addr)->
addresses_next)
{
31 t = be32toh(addr->iaaddr.lifetime_valid);
32 if (valid < t)
33 valid = t;
34 }
35
36 t = be32toh(ia->ia_na.lifetime_t2);
37 if (t > valid)
38 return -EINVAL22;
39
40 *expire = valid - t;
41
42 return 0;
43}
44
45DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia) {
46 DHCP6Address *address;
47
48 if (!ia
8.1
'ia' is non-null
)
9
Taking false branch
49 return NULL((void*)0);
50
51 dhcp6_lease_clear_timers(ia);
52
53 while (ia->addresses) {
10
Loop condition is true. Entering loop body
19
Loop condition is true. Entering loop body
54 address = ia->addresses;
55
56 LIST_REMOVE(addresses, ia->addresses, address)do { typeof(*(ia->addresses)) **_head = &(ia->addresses
), *_item = (address); do { if ((__builtin_expect(!!(!(_item)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_item"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 56, __PRETTY_FUNCTION__); } while (0); if (_item->addresses_next
) _item->addresses_next->addresses_prev = _item->addresses_prev
; if (_item->addresses_prev) _item->addresses_prev->
addresses_next = _item->addresses_next; else { do { if ((__builtin_expect
(!!(!(*_head == _item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("*_head == _item"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 56, __PRETTY_FUNCTION__); } while (0); *_head = _item->addresses_next
; } _item->addresses_next = _item->addresses_prev = ((void
*)0); } while (0)
;
11
Taking false branch
12
Loop condition is false. Exiting loop
13
Assuming field 'addresses_next' is null
14
Taking false branch
15
Assuming field 'addresses_prev' is non-null
16
Taking true branch
17
Loop condition is false. Exiting loop
20
Taking false branch
21
Loop condition is false. Exiting loop
22
Use of memory after it is freed
57
58 free(address);
18
Memory is released
59 }
60
61 return NULL((void*)0);
62}
63
64int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
65 size_t len) {
66 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 66, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
67 assert_return(id, -EINVAL)do { if (!(((__builtin_expect(!!(id),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("id"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 67, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
68
69 free(lease->serverid);
70
71 lease->serverid = memdup(id, len);
72 if (!lease->serverid)
73 return -EINVAL22;
74
75 lease->serverid_len = len;
76
77 return 0;
78}
79
80int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) {
81 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 81, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
82
83 if (!lease->serverid)
84 return -ENOMSG42;
85
86 if (id)
87 *id = lease->serverid;
88 if (len)
89 *len = lease->serverid_len;
90
91 return 0;
92}
93
94int dhcp6_lease_set_preference(sd_dhcp6_lease *lease, uint8_t preference) {
95 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 95, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
96
97 lease->preference = preference;
98
99 return 0;
100}
101
102int dhcp6_lease_get_preference(sd_dhcp6_lease *lease, uint8_t *preference) {
103 assert_return(preference, -EINVAL)do { if (!(((__builtin_expect(!!(preference),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("preference"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 103, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
104
105 if (!lease)
106 return -EINVAL22;
107
108 *preference = lease->preference;
109
110 return 0;
111}
112
113int dhcp6_lease_set_rapid_commit(sd_dhcp6_lease *lease) {
114 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 114, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
115
116 lease->rapid_commit = true1;
117
118 return 0;
119}
120
121int dhcp6_lease_get_rapid_commit(sd_dhcp6_lease *lease, bool_Bool *rapid_commit) {
122 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 122, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
123 assert_return(rapid_commit, -EINVAL)do { if (!(((__builtin_expect(!!(rapid_commit),1))) ? (1) : (
log_assert_failed_return_realm(LOG_REALM_SYSTEMD, ("rapid_commit"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 123, __PRETTY_FUNCTION__
), 0))) return (-22); } while (0)
;
124
125 *rapid_commit = lease->rapid_commit;
126
127 return 0;
128}
129
130int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid) {
131 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 131, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
132 assert_return(iaid, -EINVAL)do { if (!(((__builtin_expect(!!(iaid),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("iaid"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 132, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
133
134 *iaid = lease->ia.ia_na.id;
135
136 return 0;
137}
138
139int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease, struct in6_addr *addr,
140 uint32_t *lifetime_preferred,
141 uint32_t *lifetime_valid) {
142 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 142, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
143 assert_return(addr, -EINVAL)do { if (!(((__builtin_expect(!!(addr),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("addr"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 143, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
144 assert_return(lifetime_preferred, -EINVAL)do { if (!(((__builtin_expect(!!(lifetime_preferred),1))) ? (
1) : (log_assert_failed_return_realm(LOG_REALM_SYSTEMD, ("lifetime_preferred"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 144, __PRETTY_FUNCTION__
), 0))) return (-22); } while (0)
;
145 assert_return(lifetime_valid, -EINVAL)do { if (!(((__builtin_expect(!!(lifetime_valid),1))) ? (1) :
(log_assert_failed_return_realm(LOG_REALM_SYSTEMD, ("lifetime_valid"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 145, __PRETTY_FUNCTION__
), 0))) return (-22); } while (0)
;
146
147 if (!lease->addr_iter)
148 return -ENOMSG42;
149
150 memcpy(addr, &lease->addr_iter->iaaddr.address,
151 sizeof(struct in6_addr));
152 *lifetime_preferred =
153 be32toh(lease->addr_iter->iaaddr.lifetime_preferred);
154 *lifetime_valid = be32toh(lease->addr_iter->iaaddr.lifetime_valid);
155
156 lease->addr_iter = lease->addr_iter->addresses_next;
157
158 return 0;
159}
160
161void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease) {
162 if (lease)
163 lease->addr_iter = lease->ia.addresses;
164}
165
166int sd_dhcp6_lease_get_pd(sd_dhcp6_lease *lease, struct in6_addr *prefix,
167 uint8_t *prefix_len,
168 uint32_t *lifetime_preferred,
169 uint32_t *lifetime_valid) {
170 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 170, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
171 assert_return(prefix, -EINVAL)do { if (!(((__builtin_expect(!!(prefix),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("prefix"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 171, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
172 assert_return(prefix_len, -EINVAL)do { if (!(((__builtin_expect(!!(prefix_len),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("prefix_len"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 172, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
173 assert_return(lifetime_preferred, -EINVAL)do { if (!(((__builtin_expect(!!(lifetime_preferred),1))) ? (
1) : (log_assert_failed_return_realm(LOG_REALM_SYSTEMD, ("lifetime_preferred"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 173, __PRETTY_FUNCTION__
), 0))) return (-22); } while (0)
;
174 assert_return(lifetime_valid, -EINVAL)do { if (!(((__builtin_expect(!!(lifetime_valid),1))) ? (1) :
(log_assert_failed_return_realm(LOG_REALM_SYSTEMD, ("lifetime_valid"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 174, __PRETTY_FUNCTION__
), 0))) return (-22); } while (0)
;
175
176 if (!lease->prefix_iter)
177 return -ENOMSG42;
178
179 memcpy(prefix, &lease->prefix_iter->iapdprefix.address,
180 sizeof(struct in6_addr));
181 *prefix_len = lease->prefix_iter->iapdprefix.prefixlen;
182 *lifetime_preferred =
183 be32toh(lease->prefix_iter->iapdprefix.lifetime_preferred);
184 *lifetime_valid =
185 be32toh(lease->prefix_iter->iapdprefix.lifetime_valid);
186
187 lease->prefix_iter = lease->prefix_iter->addresses_next;
188
189 return 0;
190}
191
192void sd_dhcp6_lease_reset_pd_prefix_iter(sd_dhcp6_lease *lease) {
193 if (lease)
194 lease->prefix_iter = lease->pd.addresses;
195}
196
197int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
198 int r;
199
200 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 200, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
201 assert_return(optval, -EINVAL)do { if (!(((__builtin_expect(!!(optval),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("optval"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 201, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
202
203 if (!optlen)
204 return 0;
205
206 r = dhcp6_option_parse_ip6addrs(optval, optlen, &lease->dns,
207 lease->dns_count,
208 &lease->dns_allocated);
209 if (r < 0) {
210 log_dhcp6_client(client, "Invalid DNS server option: %s",log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 211, __func__
, "DHCPv6 CLIENT: " "Invalid DNS server option: %s", strerror
(-r))
211 strerror(-r))log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 211, __func__
, "DHCPv6 CLIENT: " "Invalid DNS server option: %s", strerror
(-r))
;
212
213 return r;
214 }
215
216 lease->dns_count = r;
217
218 return 0;
219}
220
221int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, struct in6_addr **addrs) {
222 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 222, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
223 assert_return(addrs, -EINVAL)do { if (!(((__builtin_expect(!!(addrs),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("addrs"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 223, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
224
225 if (lease->dns_count) {
226 *addrs = lease->dns;
227 return lease->dns_count;
228 }
229
230 return -ENOENT2;
231}
232
233int dhcp6_lease_set_domains(sd_dhcp6_lease *lease, uint8_t *optval,
234 size_t optlen) {
235 int r;
236 char **domains;
237
238 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 238, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
239 assert_return(optval, -EINVAL)do { if (!(((__builtin_expect(!!(optval),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("optval"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 239, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
240
241 if (!optlen)
242 return 0;
243
244 r = dhcp6_option_parse_domainname(optval, optlen, &domains);
245 if (r < 0)
246 return 0;
247
248 strv_free_and_replace(lease->domains, domains)({ strv_free(lease->domains); (lease->domains) = (domains
); (domains) = ((void*)0); 0; })
;
249 lease->domains_count = r;
250
251 return r;
252}
253
254int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***domains) {
255 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 255, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
256 assert_return(domains, -EINVAL)do { if (!(((__builtin_expect(!!(domains),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("domains"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 256, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
257
258 if (lease->domains_count) {
259 *domains = lease->domains;
260 return lease->domains_count;
261 }
262
263 return -ENOENT2;
264}
265
266int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
267 int r;
268 uint16_t subopt;
269 size_t sublen;
270 uint8_t *subval;
271
272 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 272, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
273 assert_return(optval, -EINVAL)do { if (!(((__builtin_expect(!!(optval),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("optval"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 273, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
274
275 lease->ntp = mfree(lease->ntp);
276 lease->ntp_count = 0;
277 lease->ntp_allocated = 0;
278
279 while ((r = dhcp6_option_parse(&optval, &optlen, &subopt, &sublen,
280 &subval)) >= 0) {
281 int s;
282 char **servers;
283
284 switch(subopt) {
285 case DHCP6_NTP_SUBOPTION_SRV_ADDR:
286 case DHCP6_NTP_SUBOPTION_MC_ADDR:
287 if (sublen != 16)
288 return 0;
289
290 s = dhcp6_option_parse_ip6addrs(subval, sublen,
291 &lease->ntp,
292 lease->ntp_count,
293 &lease->ntp_allocated);
294 if (s < 0)
295 return s;
296
297 lease->ntp_count = s;
298
299 break;
300
301 case DHCP6_NTP_SUBOPTION_SRV_FQDN:
302 r = dhcp6_option_parse_domainname(subval, sublen,
303 &servers);
304 if (r < 0)
305 return 0;
306
307 strv_free_and_replace(lease->ntp_fqdn, servers)({ strv_free(lease->ntp_fqdn); (lease->ntp_fqdn) = (servers
); (servers) = ((void*)0); 0; })
;
308 lease->ntp_fqdn_count = r;
309
310 break;
311 }
312 }
313
314 if (r != -ENOMSG42)
315 return r;
316
317 return 0;
318}
319
320int dhcp6_lease_set_sntp(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
321 int r;
322
323 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 323, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
324 assert_return(optval, -EINVAL)do { if (!(((__builtin_expect(!!(optval),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("optval"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 324, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
325
326 if (!optlen)
327 return 0;
328
329 if (lease->ntp || lease->ntp_fqdn) {
330 log_dhcp6_client(client, "NTP information already provided")log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 330, __func__
, "DHCPv6 CLIENT: " "NTP information already provided")
;
331
332 return 0;
333 }
334
335 log_dhcp6_client(client, "Using deprecated SNTP information")log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 335, __func__
, "DHCPv6 CLIENT: " "Using deprecated SNTP information")
;
336
337 r = dhcp6_option_parse_ip6addrs(optval, optlen, &lease->ntp,
338 lease->ntp_count,
339 &lease->ntp_allocated);
340 if (r < 0) {
341 log_dhcp6_client(client, "Invalid SNTP server option: %s",log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 342, __func__
, "DHCPv6 CLIENT: " "Invalid SNTP server option: %s", strerror
(-r))
342 strerror(-r))log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))),
0, "../src/libsystemd-network/sd-dhcp6-lease.c", 342, __func__
, "DHCPv6 CLIENT: " "Invalid SNTP server option: %s", strerror
(-r))
;
343
344 return r;
345 }
346
347 lease->ntp_count = r;
348
349 return 0;
350}
351
352int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease,
353 struct in6_addr **addrs) {
354 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 354, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
355 assert_return(addrs, -EINVAL)do { if (!(((__builtin_expect(!!(addrs),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("addrs"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 355, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
356
357 if (lease->ntp_count) {
358 *addrs = lease->ntp;
359 return lease->ntp_count;
360 }
361
362 return -ENOENT2;
363}
364
365int sd_dhcp6_lease_get_ntp_fqdn(sd_dhcp6_lease *lease, char ***ntp_fqdn) {
366 assert_return(lease, -EINVAL)do { if (!(((__builtin_expect(!!(lease),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("lease"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 366, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
367 assert_return(ntp_fqdn, -EINVAL)do { if (!(((__builtin_expect(!!(ntp_fqdn),1))) ? (1) : (log_assert_failed_return_realm
(LOG_REALM_SYSTEMD, ("ntp_fqdn"), "../src/libsystemd-network/sd-dhcp6-lease.c"
, 367, __PRETTY_FUNCTION__), 0))) return (-22); } while (0)
;
368
369 if (lease->ntp_fqdn_count) {
370 *ntp_fqdn = lease->ntp_fqdn;
371 return lease->ntp_fqdn_count;
372 }
373
374 return -ENOENT2;
375}
376
377sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease) {
378
379 if (!lease)
380 return NULL((void*)0);
381
382 assert(lease->n_ref >= 1)do { if ((__builtin_expect(!!(!(lease->n_ref >= 1)),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lease->n_ref >= 1"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 382, __PRETTY_FUNCTION__
); } while (0)
;
383 lease->n_ref++;
384
385 return lease;
386}
387
388sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease) {
389
390 if (!lease)
1
Assuming 'lease' is non-null
2
Taking false branch
391 return NULL((void*)0);
392
393 assert(lease->n_ref >= 1)do { if ((__builtin_expect(!!(!(lease->n_ref >= 1)),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lease->n_ref >= 1"
), "../src/libsystemd-network/sd-dhcp6-lease.c", 393, __PRETTY_FUNCTION__
); } while (0)
;
3
Assuming field 'n_ref' is >= 1
4
Taking false branch
5
Loop condition is false. Exiting loop
394 lease->n_ref--;
395
396 if (lease->n_ref > 0)
6
Assuming field 'n_ref' is <= 0
7
Taking false branch
397 return NULL((void*)0);
398
399 free(lease->serverid);
400 dhcp6_lease_free_ia(&lease->ia);
8
Calling 'dhcp6_lease_free_ia'
401 dhcp6_lease_free_ia(&lease->pd);
402
403 free(lease->dns);
404
405 lease->domains = strv_free(lease->domains);
406
407 free(lease->ntp);
408
409 lease->ntp_fqdn = strv_free(lease->ntp_fqdn);
410 return mfree(lease);
411}
412
413int dhcp6_lease_new(sd_dhcp6_lease **ret) {
414 sd_dhcp6_lease *lease;
415
416 lease = new0(sd_dhcp6_lease, 1)((sd_dhcp6_lease*) calloc((1), sizeof(sd_dhcp6_lease)));
417 if (!lease)
418 return -ENOMEM12;
419
420 lease->n_ref = 1;
421
422 LIST_HEAD_INIT(lease->ia.addresses)do { (lease->ia.addresses) = ((void*)0); } while (0);
423
424 *ret = lease;
425 return 0;
426}