2 This file is part of systemd.
4 Copyright (C) 2014 Tom Gundersen
5 Copyright (C) 2014 Intel Corporation. All rights reserved.
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "dhcp6-lease-internal.h"
27 int dhcp6_lease_clear_timers(DHCP6IA *ia) {
28 assert_return(ia, -EINVAL);
30 ia->timeout_t1 = sd_event_source_unref(ia->timeout_t1);
31 ia->timeout_t2 = sd_event_source_unref(ia->timeout_t2);
36 DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia) {
37 DHCP6Address *address;
42 dhcp6_lease_clear_timers(ia);
44 while (ia->addresses) {
45 address = ia->addresses;
47 LIST_REMOVE(addresses, ia->addresses, address);
55 int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
57 assert_return(lease, -EINVAL);
58 assert_return(id, -EINVAL);
60 free(lease->serverid);
62 lease->serverid = memdup(id, len);
66 lease->serverid_len = len;
71 int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) {
72 assert_return(lease, -EINVAL);
73 assert_return(id, -EINVAL);
74 assert_return(len, -EINVAL);
76 *id = lease->serverid;
77 *len = lease->serverid_len;
82 int dhcp6_lease_set_preference(sd_dhcp6_lease *lease, uint8_t preference) {
83 assert_return(lease, -EINVAL);
85 lease->preference = preference;
90 int dhcp6_lease_get_preference(sd_dhcp6_lease *lease, uint8_t *preference) {
91 assert_return(lease, -EINVAL);
92 assert_return(preference, -EINVAL);
94 *preference = lease->preference;
99 int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid) {
100 assert_return(lease, -EINVAL);
101 assert_return(iaid, -EINVAL);
103 *iaid = lease->ia.id;
108 sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease) {
110 assert_se(REFCNT_INC(lease->n_ref) >= 2);
115 sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease) {
116 if (lease && REFCNT_DEC(lease->n_ref) <= 0) {
117 free(lease->serverid);
118 dhcp6_lease_free_ia(&lease->ia);
126 int dhcp6_lease_new(sd_dhcp6_lease **ret) {
127 sd_dhcp6_lease *lease;
129 lease = new0(sd_dhcp6_lease, 1);
133 lease->n_ref = REFCNT_INIT;
135 LIST_HEAD_INIT(lease->ia.addresses);