systemd: update code from upstream (2019-04-04)
This is a direct dump from systemd git. ====== SYSTEMD_DIR=../systemd COMMIT=6e79d2b5a414f49c05392cf5f52072c5f081442e ( cd "$SYSTEMD_DIR" git checkout "$COMMIT" git reset --hard git clean -fdx ) git ls-files -z :/src/systemd/src/ \ :/shared/systemd/src/ \ :/shared/nm-utils/unaligned.h | \ xargs -0 rm -f nm_copy_sd_shared() { mkdir -p "./shared/systemd/$(dirname "$1")" cp "$SYSTEMD_DIR/$1" "./shared/systemd/$1" } nm_copy_sd_core() { mkdir -p "./src/systemd/$(dirname "$1")" cp "$SYSTEMD_DIR/$1" "./src/systemd/$1" } nm_copy_sd_nmutils() { mkdir -p "./shared/nm-utils/" cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}" } nm_copy_sd_core "src/libsystemd-network/arp-util.c" nm_copy_sd_core "src/libsystemd-network/arp-util.h" nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c" nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h" nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h" nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h" nm_copy_sd_core "src/libsystemd-network/dhcp-network.c" nm_copy_sd_core "src/libsystemd-network/dhcp-option.c" nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c" nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h" nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h" nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h" nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c" nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c" nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h" nm_copy_sd_core "src/libsystemd-network/lldp-internal.h" nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c" nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h" nm_copy_sd_core "src/libsystemd-network/lldp-network.c" nm_copy_sd_core "src/libsystemd-network/lldp-network.h" nm_copy_sd_core "src/libsystemd-network/network-internal.c" nm_copy_sd_core "src/libsystemd-network/network-internal.h" nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c" nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c" nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c" nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c" nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c" nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c" nm_copy_sd_core "src/libsystemd-network/sd-lldp.c" nm_copy_sd_core "src/libsystemd/sd-event/event-source.h" nm_copy_sd_core "src/libsystemd/sd-event/event-util.c" nm_copy_sd_core "src/libsystemd/sd-event/event-util.h" nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c" nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c" nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h" nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c" nm_copy_sd_core "src/shared/dns-domain.c" nm_copy_sd_core "src/shared/dns-domain.h" nm_copy_sd_core "src/systemd/_sd-common.h" nm_copy_sd_core "src/systemd/sd-dhcp-client.h" nm_copy_sd_core "src/systemd/sd-dhcp-lease.h" nm_copy_sd_core "src/systemd/sd-dhcp6-client.h" nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h" nm_copy_sd_core "src/systemd/sd-event.h" nm_copy_sd_core "src/systemd/sd-id128.h" nm_copy_sd_core "src/systemd/sd-ipv4acd.h" nm_copy_sd_core "src/systemd/sd-ipv4ll.h" nm_copy_sd_core "src/systemd/sd-lldp.h" nm_copy_sd_core "src/systemd/sd-ndisc.h" nm_copy_sd_nmutils "src/basic/unaligned.h" nm_copy_sd_shared "src/basic/alloc-util.c" nm_copy_sd_shared "src/basic/alloc-util.h" nm_copy_sd_shared "src/basic/async.h" nm_copy_sd_shared "src/basic/env-file.c" nm_copy_sd_shared "src/basic/env-file.h" nm_copy_sd_shared "src/basic/env-util.c" nm_copy_sd_shared "src/basic/env-util.h" nm_copy_sd_shared "src/basic/errno-util.h" nm_copy_sd_shared "src/basic/escape.c" nm_copy_sd_shared "src/basic/escape.h" nm_copy_sd_shared "src/basic/ether-addr-util.c" nm_copy_sd_shared "src/basic/ether-addr-util.h" nm_copy_sd_shared "src/basic/extract-word.c" nm_copy_sd_shared "src/basic/extract-word.h" nm_copy_sd_shared "src/basic/fd-util.c" nm_copy_sd_shared "src/basic/fd-util.h" nm_copy_sd_shared "src/basic/fileio.c" nm_copy_sd_shared "src/basic/fileio.h" nm_copy_sd_shared "src/basic/fs-util.c" nm_copy_sd_shared "src/basic/fs-util.h" nm_copy_sd_shared "src/basic/hash-funcs.c" nm_copy_sd_shared "src/basic/hash-funcs.h" nm_copy_sd_shared "src/basic/hashmap.c" nm_copy_sd_shared "src/basic/hashmap.h" nm_copy_sd_shared "src/basic/hexdecoct.c" nm_copy_sd_shared "src/basic/hexdecoct.h" nm_copy_sd_shared "src/basic/hostname-util.c" nm_copy_sd_shared "src/basic/hostname-util.h" nm_copy_sd_shared "src/basic/in-addr-util.c" nm_copy_sd_shared "src/basic/in-addr-util.h" nm_copy_sd_shared "src/basic/io-util.c" nm_copy_sd_shared "src/basic/io-util.h" nm_copy_sd_shared "src/basic/list.h" nm_copy_sd_shared "src/basic/log.h" nm_copy_sd_shared "src/basic/macro.h" nm_copy_sd_shared "src/basic/memory-util.c" nm_copy_sd_shared "src/basic/memory-util.h" nm_copy_sd_shared "src/basic/mempool.c" nm_copy_sd_shared "src/basic/mempool.h" nm_copy_sd_shared "src/basic/missing_fcntl.h" nm_copy_sd_shared "src/basic/missing_socket.h" nm_copy_sd_shared "src/basic/missing_stat.h" nm_copy_sd_shared "src/basic/missing_type.h" nm_copy_sd_shared "src/basic/parse-util.c" nm_copy_sd_shared "src/basic/parse-util.h" nm_copy_sd_shared "src/basic/path-util.c" nm_copy_sd_shared "src/basic/path-util.h" nm_copy_sd_shared "src/basic/prioq.c" nm_copy_sd_shared "src/basic/prioq.h" nm_copy_sd_shared "src/basic/process-util.c" nm_copy_sd_shared "src/basic/process-util.h" nm_copy_sd_shared "src/basic/random-util.c" nm_copy_sd_shared "src/basic/random-util.h" nm_copy_sd_shared "src/basic/set.h" nm_copy_sd_shared "src/basic/signal-util.h" nm_copy_sd_shared "src/basic/siphash24.h" nm_copy_sd_shared "src/basic/socket-util.c" nm_copy_sd_shared "src/basic/socket-util.h" nm_copy_sd_shared "src/basic/sort-util.h" nm_copy_sd_shared "src/basic/sparse-endian.h" nm_copy_sd_shared "src/basic/stat-util.c" nm_copy_sd_shared "src/basic/stat-util.h" nm_copy_sd_shared "src/basic/stdio-util.h" nm_copy_sd_shared "src/basic/string-table.c" nm_copy_sd_shared "src/basic/string-table.h" nm_copy_sd_shared "src/basic/string-util.c" nm_copy_sd_shared "src/basic/string-util.h" nm_copy_sd_shared "src/basic/strv.c" nm_copy_sd_shared "src/basic/strv.h" nm_copy_sd_shared "src/basic/time-util.c" nm_copy_sd_shared "src/basic/time-util.h" nm_copy_sd_shared "src/basic/tmpfile-util.c" nm_copy_sd_shared "src/basic/tmpfile-util.h" nm_copy_sd_shared "src/basic/umask-util.h" nm_copy_sd_shared "src/basic/utf8.c" nm_copy_sd_shared "src/basic/utf8.h" nm_copy_sd_shared "src/basic/util.c" nm_copy_sd_shared "src/basic/util.h"
This commit is contained in:
@@ -5,12 +5,15 @@
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "macro.h"
|
||||
#include "parse-util.h"
|
||||
#include "random-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "util.h"
|
||||
|
||||
bool in4_addr_is_null(const struct in_addr *a) {
|
||||
@@ -68,6 +71,14 @@ bool in4_addr_is_localhost(const struct in_addr *a) {
|
||||
return (be32toh(a->s_addr) & UINT32_C(0xFF000000)) == UINT32_C(127) << 24;
|
||||
}
|
||||
|
||||
bool in4_addr_is_non_local(const struct in_addr *a) {
|
||||
/* Whether the address is not null and not localhost.
|
||||
*
|
||||
* As such, it is suitable to configure as DNS/NTP server from DHCP. */
|
||||
return !in4_addr_is_null(a) &&
|
||||
!in4_addr_is_localhost(a);
|
||||
}
|
||||
|
||||
int in_addr_is_localhost(int family, const union in_addr_union *u) {
|
||||
assert(u);
|
||||
|
||||
@@ -207,8 +218,85 @@ int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen)
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
int in_addr_random_prefix(
|
||||
int family,
|
||||
union in_addr_union *u,
|
||||
unsigned prefixlen_fixed_part,
|
||||
unsigned prefixlen) {
|
||||
|
||||
assert(u);
|
||||
|
||||
/* Random network part of an address by one. */
|
||||
|
||||
if (prefixlen <= 0)
|
||||
return 0;
|
||||
|
||||
if (family == AF_INET) {
|
||||
uint32_t c, n;
|
||||
|
||||
if (prefixlen_fixed_part > 32)
|
||||
prefixlen_fixed_part = 32;
|
||||
if (prefixlen > 32)
|
||||
prefixlen = 32;
|
||||
if (prefixlen_fixed_part >= prefixlen)
|
||||
return -EINVAL;
|
||||
|
||||
c = be32toh(u->in.s_addr);
|
||||
c &= ((UINT32_C(1) << prefixlen_fixed_part) - 1) << (32 - prefixlen_fixed_part);
|
||||
|
||||
random_bytes(&n, sizeof(n));
|
||||
n &= ((UINT32_C(1) << (prefixlen - prefixlen_fixed_part)) - 1) << (32 - prefixlen);
|
||||
|
||||
u->in.s_addr = htobe32(n | c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (family == AF_INET6) {
|
||||
struct in6_addr n;
|
||||
unsigned i, j;
|
||||
|
||||
if (prefixlen_fixed_part > 128)
|
||||
prefixlen_fixed_part = 128;
|
||||
if (prefixlen > 128)
|
||||
prefixlen = 128;
|
||||
if (prefixlen_fixed_part >= prefixlen)
|
||||
return -EINVAL;
|
||||
|
||||
random_bytes(&n, sizeof(n));
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
uint8_t mask_fixed_part = 0, mask = 0;
|
||||
|
||||
if (i < (prefixlen_fixed_part + 7) / 8) {
|
||||
if (i < prefixlen_fixed_part / 8)
|
||||
mask_fixed_part = 0xffu;
|
||||
else {
|
||||
j = prefixlen_fixed_part % 8;
|
||||
mask_fixed_part = ((UINT8_C(1) << (j + 1)) - 1) << (8 - j);
|
||||
}
|
||||
}
|
||||
|
||||
if (i < (prefixlen + 7) / 8) {
|
||||
if (i < prefixlen / 8)
|
||||
mask = 0xffu ^ mask_fixed_part;
|
||||
else {
|
||||
j = prefixlen % 8;
|
||||
mask = (((UINT8_C(1) << (j + 1)) - 1) << (8 - j)) ^ mask_fixed_part;
|
||||
}
|
||||
}
|
||||
|
||||
u->in6.s6_addr[i] &= mask_fixed_part;
|
||||
u->in6.s6_addr[i] |= n.s6_addr[i] & mask;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
char *x;
|
||||
_cleanup_free_ char *x = NULL;
|
||||
size_t l;
|
||||
|
||||
assert(u);
|
||||
@@ -226,18 +314,50 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l)) {
|
||||
free(x);
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
}
|
||||
|
||||
*ret = x;
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret) {
|
||||
_cleanup_free_ char *x = NULL;
|
||||
char *p;
|
||||
size_t l;
|
||||
|
||||
assert(u);
|
||||
assert(ret);
|
||||
|
||||
if (family == AF_INET)
|
||||
l = INET_ADDRSTRLEN + 3;
|
||||
else if (family == AF_INET6)
|
||||
l = INET6_ADDRSTRLEN + 4;
|
||||
else
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
if (prefixlen > FAMILY_ADDRESS_SIZE(family) * 8)
|
||||
return -EINVAL;
|
||||
|
||||
x = new(char, l);
|
||||
if (!x)
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
|
||||
p = x + strlen(x);
|
||||
l -= strlen(x);
|
||||
(void) strpcpyf(&p, l, "/%u", prefixlen);
|
||||
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
|
||||
_cleanup_free_ char *x = NULL;
|
||||
size_t l;
|
||||
char *x;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
@@ -263,14 +383,12 @@ int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifin
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l)) {
|
||||
free(x);
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
}
|
||||
|
||||
sprintf(strchr(x, 0), "%%%i", ifindex);
|
||||
*ret = x;
|
||||
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
|
||||
fallback:
|
||||
|
Reference in New Issue
Block a user