/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2013 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
#include <net/if.h>
#include "set.h"
#include "socket-util.h"
#include "string-util.h"
+#include "strv.h"
#include "utf8.h"
#include "util.h"
#define STATIC_ADDRESSES_PER_NETWORK_MAX 1024U
int address_new(Address **ret) {
- _cleanup_address_free_ Address *address = NULL;
+ _cleanup_(address_freep) Address *address = NULL;
address = new0(Address, 1);
if (!address)
address->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME;
address->cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME;
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
int address_new_static(Network *network, const char *filename, unsigned section_line, Address **ret) {
- _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL;
- _cleanup_address_free_ Address *address = NULL;
+ _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+ _cleanup_(address_freep) Address *address = NULL;
int r;
assert(network);
address = hashmap_get(network->addresses_by_section, n);
if (address) {
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
return r;
if (filename) {
- address->section = n;
- n = NULL;
+ address->section = TAKE_PTR(n);
r = hashmap_put(network->addresses_by_section, address->section, address);
if (r < 0)
LIST_APPEND(addresses, network->static_addresses, address);
network->n_static_addresses++;
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
static int address_compare_func(const void *c1, const void *c2) {
const Address *a1 = c1, *a2 = c2;
+ int r;
- if (a1->family < a2->family)
- return -1;
- if (a1->family > a2->family)
- return 1;
+ r = CMP(a1->family, a2->family);
+ if (r != 0)
+ return r;
switch (a1->family) {
/* use the same notion of equality as the kernel does */
case AF_INET:
- if (a1->prefixlen < a2->prefixlen)
- return -1;
- if (a1->prefixlen > a2->prefixlen)
- return 1;
+ r = CMP(a1->prefixlen, a2->prefixlen);
+ if (r != 0)
+ return r;
/* compare the peer prefixes */
if (a1->prefixlen != 0) {
else
b2 = be32toh(a2->in_addr.in.s_addr) >> (32 - a1->prefixlen);
- if (b1 < b2)
- return -1;
- if (b1 > b2)
- return 1;
+ r = CMP(b1, b2);
+ if (r != 0)
+ return r;
}
_fallthrough_;
const union in_addr_union *in_addr,
unsigned char prefixlen,
Address **ret) {
- _cleanup_address_free_ Address *address = NULL;
+ _cleanup_(address_freep) Address *address = NULL;
int r;
assert(link);
if (r < 0)
return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
- r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
+ r = sd_netlink_call_async(link->manager->rtnl, req, callback,
+ link_netlink_destroy_callback, link, 0, NULL);
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
static int address_acquire(Link *link, Address *original, Address **ret) {
union in_addr_union in_addr = {};
struct in_addr broadcast = {};
- _cleanup_address_free_ Address *na = NULL;
+ _cleanup_(address_freep) Address *na = NULL;
int r;
assert(link);
LIST_PREPEND(addresses, link->pool_addresses, na);
- *ret = na;
- na = NULL;
+ *ret = TAKE_PTR(na);
return 0;
}
if (r < 0)
return r;
- r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
+ r = sd_netlink_call_async(link->manager->rtnl, req, callback,
+ link_netlink_destroy_callback, link, 0, NULL);
if (r < 0) {
address_release(address);
return log_error_errno(r, "Could not send rtnetlink message: %m");
void *userdata) {
Network *network = userdata;
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
int r;
assert(filename);
void *userdata) {
Network *network = userdata;
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
const char *address, *e;
union in_addr_union buffer;
int r, f;
void *data,
void *userdata) {
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
Network *network = userdata;
int r;
void *data,
void *userdata) {
Network *network = userdata;
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
unsigned k;
int r;
void *data,
void *userdata) {
Network *network = userdata;
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
int r;
assert(filename);
void *data,
void *userdata) {
Network *network = userdata;
- _cleanup_address_free_ Address *n = NULL;
+ _cleanup_(address_freep) Address *n = NULL;
int r;
assert(filename);