diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-04 09:49:37 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-04 09:49:37 +0200 |
commit | 917cd3eb0388d872119667f119b90f3927844d50 (patch) | |
tree | b38f6e0c016094fe6aff975544b6492738a996dd /src/systemd | |
parent | 9598adac60b08d627aec324e63addacfe5e0ebd7 (diff) | |
parent | b6032223988616c7d5c6c5715521aff1c5a81e40 (diff) | |
download | NetworkManager-917cd3eb0388d872119667f119b90f3927844d50.tar.gz |
systemd: merge branch systemd into master
Diffstat (limited to 'src/systemd')
16 files changed, 73 insertions, 92 deletions
diff --git a/src/systemd/sd-adapt-core/stat-util.h b/src/systemd/sd-adapt-core/udev-util.h index 637892c2d6..637892c2d6 100644 --- a/src/systemd/sd-adapt-core/stat-util.h +++ b/src/systemd/sd-adapt-core/udev-util.h diff --git a/src/systemd/src/libsystemd-network/dhcp-identifier.c b/src/systemd/src/libsystemd-network/dhcp-identifier.c index 7fc8248a71..e3af362d2f 100644 --- a/src/systemd/src/libsystemd-network/dhcp-identifier.c +++ b/src/systemd/src/libsystemd-network/dhcp-identifier.c @@ -14,6 +14,7 @@ #include "siphash24.h" #include "sparse-endian.h" #include "stdio-util.h" +#include "udev-util.h" #include "virt.h" #define SYSTEMD_PEN 43793 @@ -189,6 +190,13 @@ int dhcp_identifier_set_iaid( /* not yet ready */ return -EBUSY; + r = device_is_renaming(device); + if (r < 0) + return r; + if (r > 0) + /* device is under renaming */ + return -EBUSY; + name = net_get_name(device); } } diff --git a/src/systemd/src/libsystemd-network/dhcp-network.c b/src/systemd/src/libsystemd-network/dhcp-network.c index 810a26339a..45d2ed8928 100644 --- a/src/systemd/src/libsystemd-network/dhcp-network.c +++ b/src/systemd/src/libsystemd-network/dhcp-network.c @@ -154,7 +154,6 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port) { .in.sin_addr.s_addr = address, }; _cleanup_close_ int s = -1; - char ifname[IF_NAMESIZE] = ""; int r; s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); @@ -170,12 +169,9 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port) { return r; if (ifindex > 0) { - if (if_indextoname(ifindex, ifname) == 0) - return -errno; - - r = setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname)); + r = socket_bind_to_ifindex(s, ifindex); if (r < 0) - return -errno; + return r; } if (address == INADDR_ANY) { diff --git a/src/systemd/src/libsystemd-network/dhcp-option.c b/src/systemd/src/libsystemd-network/dhcp-option.c index c5fbe749de..eaf044bf3f 100644 --- a/src/systemd/src/libsystemd-network/dhcp-option.c +++ b/src/systemd/src/libsystemd-network/dhcp-option.c @@ -10,10 +10,10 @@ #include <string.h> #include "alloc-util.h" -#include "utf8.h" -#include "strv.h" - #include "dhcp-internal.h" +#include "memory-util.h" +#include "strv.h" +#include "utf8.h" static int option_append(uint8_t options[], size_t size, size_t *offset, uint8_t code, size_t optlen, const void *optval) { diff --git a/src/systemd/src/libsystemd-network/dhcp6-option.c b/src/systemd/src/libsystemd-network/dhcp6-option.c index 3d5abe64af..6172c368e6 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-option.c +++ b/src/systemd/src/libsystemd-network/dhcp6-option.c @@ -15,10 +15,10 @@ #include "dhcp6-lease-internal.h" #include "dhcp6-protocol.h" #include "dns-domain.h" +#include "memory-util.h" #include "sparse-endian.h" #include "strv.h" #include "unaligned.h" -#include "util.h" typedef struct DHCP6StatusOption { struct DHCP6Option option; diff --git a/src/systemd/src/libsystemd-network/lldp-neighbor.c b/src/systemd/src/libsystemd-network/lldp-neighbor.c index bbe7bf9d00..530af0347d 100644 --- a/src/systemd/src/libsystemd-network/lldp-neighbor.c +++ b/src/systemd/src/libsystemd-network/lldp-neighbor.c @@ -9,9 +9,9 @@ #include "in-addr-util.h" #include "lldp-internal.h" #include "lldp-neighbor.h" +#include "memory-util.h" #include "missing.h" #include "unaligned.h" -#include "util.h" static void lldp_neighbor_id_hash_func(const LLDPNeighborID *id, struct siphash *state) { siphash24_compress(id->chassis_id, id->chassis_id_size, state); diff --git a/src/systemd/src/libsystemd-network/network-internal.c b/src/systemd/src/libsystemd-network/network-internal.c index f85db47b1f..de219a6d03 100644 --- a/src/systemd/src/libsystemd-network/network-internal.c +++ b/src/systemd/src/libsystemd-network/network-internal.c @@ -103,32 +103,12 @@ bool net_match_config(Set *match_mac, char * const *match_drivers, char * const *match_types, char * const *match_names, - Condition *match_host, - Condition *match_virt, - Condition *match_kernel_cmdline, - Condition *match_kernel_version, - Condition *match_arch, const struct ether_addr *dev_mac, const char *dev_path, const char *dev_driver, const char *dev_type, const char *dev_name) { - if (match_host && condition_test(match_host) <= 0) - return false; - - if (match_virt && condition_test(match_virt) <= 0) - return false; - - if (match_kernel_cmdline && condition_test(match_kernel_cmdline) <= 0) - return false; - - if (match_kernel_version && condition_test(match_kernel_version) <= 0) - return false; - - if (match_arch && condition_test(match_arch) <= 0) - return false; - if (match_mac && (!dev_mac || !set_contains(match_mac, dev_mac))) return false; @@ -159,32 +139,31 @@ int config_parse_net_condition(const char *unit, void *userdata) { ConditionType cond = ltype; - Condition **ret = data; + Condition **list = data, *c; bool negate; - Condition *c; - _cleanup_free_ char *s = NULL; assert(filename); assert(lvalue); assert(rvalue); assert(data); + if (isempty(rvalue)) { + *list = condition_free_list_type(*list, cond); + return 0; + } + negate = rvalue[0] == '!'; if (negate) rvalue++; - s = strdup(rvalue); - if (!s) - return log_oom(); - - c = condition_new(cond, s, false, negate); + c = condition_new(cond, rvalue, false, negate); if (!c) return log_oom(); - if (*ret) - condition_free(*ret); + /* Drop previous assignment. */ + *list = condition_free_list_type(*list, cond); - *ret = c; + LIST_PREPEND(conditions, *list, c); return 0; } diff --git a/src/systemd/src/libsystemd-network/network-internal.h b/src/systemd/src/libsystemd-network/network-internal.h index 9119d9a4ce..d895103b5a 100644 --- a/src/systemd/src/libsystemd-network/network-internal.h +++ b/src/systemd/src/libsystemd-network/network-internal.h @@ -6,7 +6,6 @@ #include "sd-device.h" #include "sd-dhcp-lease.h" -#include "condition.h" #include "conf-parser.h" #include "def.h" #include "set.h" @@ -20,11 +19,6 @@ bool net_match_config(Set *match_mac, char * const *match_driver, char * const *match_type, char * const *match_name, - Condition *match_host, - Condition *match_virt, - Condition *match_kernel_cmdline, - Condition *match_kernel_version, - Condition *match_arch, const struct ether_addr *dev_mac, const char *dev_path, const char *dev_driver, diff --git a/src/systemd/src/libsystemd-network/sd-dhcp-client.c b/src/systemd/src/libsystemd-network/sd-dhcp-client.c index 27f7963890..cadcc8a884 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp-client.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp-client.c @@ -25,10 +25,10 @@ #include "event-util.h" #include "hostname-util.h" #include "io-util.h" +#include "memory-util.h" #include "random-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" #define MAX_CLIENT_ID_LEN (sizeof(uint32_t) + MAX_DUID_LEN) /* Arbitrary limit */ #define MAX_MAC_ADDR_LEN CONST_MAX(INFINIBAND_ALEN, ETH_ALEN) diff --git a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c index 39d2a6d082..6c7aecc8a1 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c @@ -10,6 +10,9 @@ #include <stdio_ext.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include "sd-dhcp-lease.h" diff --git a/src/systemd/src/libsystemd-network/sd-ipv4acd.c b/src/systemd/src/libsystemd-network/sd-ipv4acd.c index 6de4adb535..53ce8929d7 100644 --- a/src/systemd/src/libsystemd-network/sd-ipv4acd.c +++ b/src/systemd/src/libsystemd-network/sd-ipv4acd.c @@ -22,7 +22,7 @@ #include "random-util.h" #include "siphash24.h" #include "string-util.h" -#include "util.h" +#include "time-util.h" /* Constants from the RFC */ #define PROBE_WAIT_USEC (1U * USEC_PER_SEC) diff --git a/src/systemd/src/libsystemd-network/sd-ipv4ll.c b/src/systemd/src/libsystemd-network/sd-ipv4ll.c index 8b1e966589..4f186762e4 100644 --- a/src/systemd/src/libsystemd-network/sd-ipv4ll.c +++ b/src/systemd/src/libsystemd-network/sd-ipv4ll.c @@ -219,28 +219,21 @@ static int ipv4ll_pick_address(sd_ipv4ll *ll) { return sd_ipv4ll_set_address(ll, &(struct in_addr) { addr }); } -int sd_ipv4ll_restart(sd_ipv4ll *ll) { - ll->address = 0; - - return sd_ipv4ll_start(ll); -} - #define MAC_HASH_KEY SD_ID128_MAKE(df,04,22,98,3f,ad,14,52,f9,87,2e,d1,9c,70,e2,f2) -int sd_ipv4ll_start(sd_ipv4ll *ll) { +static int ipv4ll_start_internal(sd_ipv4ll *ll, bool reset_generation) { int r; bool picked_address = false; assert_return(ll, -EINVAL); assert_return(!ether_addr_is_null(&ll->mac), -EINVAL); - assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY); /* If no random seed is set, generate some from the MAC address */ if (!ll->seed_set) ll->seed.value = htole64(siphash24(ll->mac.ether_addr_octet, ETH_ALEN, MAC_HASH_KEY.bytes)); - /* Restart the generation counter. */ - ll->seed.generation = 0; + if (reset_generation) + ll->seed.generation = 0; if (ll->address == 0) { r = ipv4ll_pick_address(ll); @@ -264,6 +257,19 @@ int sd_ipv4ll_start(sd_ipv4ll *ll) { return 0; } +int sd_ipv4ll_start(sd_ipv4ll *ll) { + assert_return(ll, -EINVAL); + assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY); + + return ipv4ll_start_internal(ll, true); +} + +int sd_ipv4ll_restart(sd_ipv4ll *ll) { + ll->address = 0; + + return ipv4ll_start_internal(ll, false); +} + static void ipv4ll_client_notify(sd_ipv4ll *ll, int event) { assert(ll); @@ -299,11 +305,7 @@ void ipv4ll_on_acd(sd_ipv4acd *acd, int event, void *userdata) { ll->claimed_address = 0; } else { - r = ipv4ll_pick_address(ll); - if (r < 0) - goto error; - - r = sd_ipv4acd_start(ll->acd); + r = sd_ipv4ll_restart(ll); if (r < 0) goto error; } diff --git a/src/systemd/src/libsystemd-network/sd-lldp.c b/src/systemd/src/libsystemd-network/sd-lldp.c index 741128e1d0..bdf58dacd3 100644 --- a/src/systemd/src/libsystemd-network/sd-lldp.c +++ b/src/systemd/src/libsystemd-network/sd-lldp.c @@ -15,7 +15,9 @@ #include "lldp-internal.h" #include "lldp-neighbor.h" #include "lldp-network.h" +#include "memory-util.h" #include "socket-util.h" +#include "sort-util.h" #include "string-table.h" #define LLDP_DEFAULT_NEIGHBORS_MAX 128U diff --git a/src/systemd/src/libsystemd/sd-event/sd-event.c b/src/systemd/src/libsystemd/sd-event/sd-event.c index 6f77421b0e..dad0801b71 100644 --- a/src/systemd/src/libsystemd/sd-event/sd-event.c +++ b/src/systemd/src/libsystemd/sd-event/sd-event.c @@ -17,6 +17,7 @@ #include "hashmap.h" #include "list.h" #include "macro.h" +#include "memory-util.h" #include "missing.h" #include "prioq.h" #include "process-util.h" @@ -25,7 +26,6 @@ #include "string-table.h" #include "string-util.h" #include "time-util.h" -#include "util.h" #define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC) @@ -3120,7 +3120,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) { timeout = 0; m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max, - timeout == (uint64_t) -1 ? -1 : (int) ((timeout + USEC_PER_MSEC - 1) / USEC_PER_MSEC)); + timeout == (uint64_t) -1 ? -1 : (int) DIV_ROUND_UP(timeout, USEC_PER_MSEC)); if (m < 0) { if (errno == EINTR) { e->state = SD_EVENT_PENDING; diff --git a/src/systemd/src/libsystemd/sd-id128/sd-id128.c b/src/systemd/src/libsystemd/sd-id128/sd-id128.c index 13a2829112..d0cae981df 100644 --- a/src/systemd/src/libsystemd/sd-id128/sd-id128.c +++ b/src/systemd/src/libsystemd/sd-id128/sd-id128.c @@ -121,7 +121,6 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { #if 0 /* NM_IGNORED */ static int get_invocation_from_keyring(sd_id128_t *ret) { - _cleanup_free_ char *description = NULL; char *d, *p, *g, *u, *e; unsigned long perms; @@ -140,7 +139,7 @@ static int get_invocation_from_keyring(sd_id128_t *ret) { if (key == -1) { /* Keyring support not available? No invocation key stored? */ if (IN_SET(errno, ENOSYS, ENOKEY)) - return 0; + return -ENXIO; return -errno; } @@ -216,7 +215,19 @@ static int get_invocation_from_keyring(sd_id128_t *ret) { if (c != sizeof(sd_id128_t)) return -EIO; - return 1; + return 0; +} + +static int get_invocation_from_environment(sd_id128_t *ret) { + const char *e; + + assert(ret); + + e = secure_getenv("INVOCATION_ID"); + if (!e) + return -ENXIO; + + return sd_id128_from_string(e, ret); } _public_ int sd_id128_get_invocation(sd_id128_t *ret) { @@ -226,31 +237,17 @@ _public_ int sd_id128_get_invocation(sd_id128_t *ret) { assert_return(ret, -EINVAL); if (sd_id128_is_null(saved_invocation_id)) { + /* We first check the environment. The environment variable is primarily relevant for user + * services, and sufficiently safe as long as no privilege boundary is involved. */ + r = get_invocation_from_environment(&saved_invocation_id); + if (r < 0 && r != -ENXIO) + return r; - /* We first try to read the invocation ID from the kernel keyring. This has the benefit that it is not - * fakeable by unprivileged code. If the information is not available in the keyring, we use - * $INVOCATION_ID but ignore the data if our process was called by less privileged code - * (i.e. secure_getenv() instead of getenv()). - * - * The kernel keyring is only relevant for system services (as for user services we don't store the - * invocation ID in the keyring, as there'd be no trust benefit in that). The environment variable is - * primarily relevant for user services, and sufficiently safe as no privilege boundary is involved. */ - + /* The kernel keyring is relevant for system services (as for user services we don't store + * the invocation ID in the keyring, as there'd be no trust benefit in that). */ r = get_invocation_from_keyring(&saved_invocation_id); if (r < 0) return r; - - if (r == 0) { - const char *e; - - e = secure_getenv("INVOCATION_ID"); - if (!e) - return -ENXIO; - - r = sd_id128_from_string(e, &saved_invocation_id); - if (r < 0) - return r; - } } *ret = saved_invocation_id; diff --git a/src/systemd/src/systemd/sd-event.h b/src/systemd/src/systemd/sd-event.h index 787a12f241..7bb8609376 100644 --- a/src/systemd/src/systemd/sd-event.h +++ b/src/systemd/src/systemd/sd-event.h @@ -71,7 +71,7 @@ typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata); typedef int (*sd_event_io_handler_t)(sd_event_source *s, int fd, uint32_t revents, void *userdata); typedef int (*sd_event_time_handler_t)(sd_event_source *s, uint64_t usec, void *userdata); typedef int (*sd_event_signal_handler_t)(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata); -#if defined _GNU_SOURCE || _POSIX_C_SOURCE >= 199309L +#if defined _GNU_SOURCE || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 199309L) typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si, void *userdata); #else typedef void* sd_event_child_handler_t; |