Compare commits

...

8 Commits

Author SHA1 Message Date
Lennart Poettering ecb040643d
Merge pull request #14376 from poettering/sd-event-no-stack
sd-event: don't use stack for event queue array
2019-12-18 17:18:07 +01:00
Yu Watanabe de697db05b network: introduce AddPrefixRoute= and deprecate PrefixRoute=
PrefixRoute= was added by e63be0847c,
but unfortunately, the meaning of PrefixRoute= is inverted; when true
IFA_F_NOPREFIXROUTE flag is added. This introduces AddPrefixRoute=
setting.
2019-12-18 16:32:31 +01:00
Lennart Poettering 0c8e33b6e9
Merge pull request #14377 from keszybz/fixups
Fixups
2019-12-18 16:21:20 +01:00
Zbigniew Jędrzejewski-Szmek b012a1f455 Make openssl dependency optional again 2019-12-18 11:24:44 +01:00
Lennart Poettering 27b4b3cc92 update TODO 2019-12-18 11:02:21 +01:00
Lennart Poettering 5cddd924aa sd-event: don't allocate event queue array on stack
We might have quite a number of event sources, hence allocate this in a
buffer we can reuse on the heap, rather than on the stack.
2019-12-18 10:59:27 +01:00
Zbigniew Jędrzejewski-Szmek 4023637a8a Restore silent handling of BUS_ERROR_SPEED_METER_INACTIVE
This only matters for the case where new networkctl is running against older
networkd. We should still handle the old error to avoid unnecessary warning
about speedmeeter being disabled.

This partially reverts commit e813de549b.
2019-12-18 08:48:33 +01:00
Zbigniew Jędrzejewski-Szmek 1b49e3e3c4 shared/loop-util: rename function
As suggested in https://github.com/systemd/systemd/pull/14261#pullrequestreview-332398625.
2019-12-18 08:48:33 +01:00
14 changed files with 51 additions and 42 deletions

2
TODO
View File

@ -37,8 +37,6 @@ Features:
waitid() only on the children with the highest priority until one is waitable waitid() only on the children with the highest priority until one is waitable
and ignore all lower-prio ones from that point on and ignore all lower-prio ones from that point on
* sd-event: drop stack allocated epoll_event buffer in sd_event_wait()
* maybe introduce xattrs that can be set on the root dir of the root fs * maybe introduce xattrs that can be set on the root dir of the root fs
partition that declare the volatility mode to use the image in. Previously I partition that declare the volatility mode to use the image in. Previously I
thought marking this via GPT partition flags but that's not ideal since thought marking this via GPT partition flags but that's not ideal since

View File

@ -1007,12 +1007,10 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>PrefixRoute=</varname></term> <term><varname>AddPrefixRoute=</varname></term>
<listitem> <listitem>
<para>Takes a boolean. When adding or modifying an IPv6 address, the userspace <para>Takes a boolean. When true, the prefix route for the address is automatically added.
application needs a way to suppress adding a prefix route. This is for example relevant Defaults to true.</para>
together with IFA_F_MANAGERTEMPADDR, where userspace creates autoconf generated addresses,
but depending on on-link, no route for the prefix should be added. Defaults to false.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -102,6 +102,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
SD_BUS_ERROR_MAP(BUS_ERROR_NO_PRODUCT_UUID, EOPNOTSUPP), SD_BUS_ERROR_MAP(BUS_ERROR_NO_PRODUCT_UUID, EOPNOTSUPP),
SD_BUS_ERROR_MAP(BUS_ERROR_SPEED_METER_INACTIVE, EOPNOTSUPP),
SD_BUS_ERROR_MAP(BUS_ERROR_UNMANAGED_INTERFACE, EOPNOTSUPP), SD_BUS_ERROR_MAP(BUS_ERROR_UNMANAGED_INTERFACE, EOPNOTSUPP),
SD_BUS_ERROR_MAP_END SD_BUS_ERROR_MAP_END

View File

@ -81,6 +81,7 @@
#define BUS_ERROR_NO_PRODUCT_UUID "org.freedesktop.hostname1.NoProductUUID" #define BUS_ERROR_NO_PRODUCT_UUID "org.freedesktop.hostname1.NoProductUUID"
#define BUS_ERROR_SPEED_METER_INACTIVE "org.freedesktop.network1.SpeedMeterInactive"
#define BUS_ERROR_UNMANAGED_INTERFACE "org.freedesktop.network1.UnmanagedInterface" #define BUS_ERROR_UNMANAGED_INTERFACE "org.freedesktop.network1.UnmanagedInterface"
BUS_ERROR_MAP_ELF_USE(bus_common_errors); BUS_ERROR_MAP_ELF_USE(bus_common_errors);

View File

@ -115,6 +115,9 @@ struct sd_event {
unsigned n_sources; unsigned n_sources;
struct epoll_event *event_queue;
size_t event_queue_allocated;
LIST_HEAD(sd_event_source, sources); LIST_HEAD(sd_event_source, sources);
usec_t last_run, last_log; usec_t last_run, last_log;
@ -286,6 +289,8 @@ static sd_event *event_free(sd_event *e) {
hashmap_free(e->child_sources); hashmap_free(e->child_sources);
set_free(e->post_sources); set_free(e->post_sources);
free(e->event_queue);
return mfree(e); return mfree(e);
} }
@ -3477,8 +3482,7 @@ pending:
} }
_public_ int sd_event_wait(sd_event *e, uint64_t timeout) { _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
struct epoll_event *ev_queue; size_t event_queue_max;
unsigned ev_queue_max;
int r, m, i; int r, m, i;
assert_return(e, -EINVAL); assert_return(e, -EINVAL);
@ -3492,14 +3496,15 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
return 1; return 1;
} }
ev_queue_max = MAX(e->n_sources, 1u); event_queue_max = MAX(e->n_sources, 1u);
ev_queue = newa(struct epoll_event, ev_queue_max); if (!GREEDY_REALLOC(e->event_queue, e->event_queue_allocated, event_queue_max))
return -ENOMEM;
/* If we still have inotify data buffered, then query the other fds, but don't wait on it */ /* If we still have inotify data buffered, then query the other fds, but don't wait on it */
if (e->inotify_data_buffered) if (e->inotify_data_buffered)
timeout = 0; timeout = 0;
m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max, m = epoll_wait(e->epoll_fd, e->event_queue, event_queue_max,
timeout == (uint64_t) -1 ? -1 : (int) DIV_ROUND_UP(timeout, USEC_PER_MSEC)); timeout == (uint64_t) -1 ? -1 : (int) DIV_ROUND_UP(timeout, USEC_PER_MSEC));
if (m < 0) { if (m < 0) {
if (errno == EINTR) { if (errno == EINTR) {
@ -3515,26 +3520,26 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
if (ev_queue[i].data.ptr == INT_TO_PTR(SOURCE_WATCHDOG)) if (e->event_queue[i].data.ptr == INT_TO_PTR(SOURCE_WATCHDOG))
r = flush_timer(e, e->watchdog_fd, ev_queue[i].events, NULL); r = flush_timer(e, e->watchdog_fd, e->event_queue[i].events, NULL);
else { else {
WakeupType *t = ev_queue[i].data.ptr; WakeupType *t = e->event_queue[i].data.ptr;
switch (*t) { switch (*t) {
case WAKEUP_EVENT_SOURCE: { case WAKEUP_EVENT_SOURCE: {
sd_event_source *s = ev_queue[i].data.ptr; sd_event_source *s = e->event_queue[i].data.ptr;
assert(s); assert(s);
switch (s->type) { switch (s->type) {
case SOURCE_IO: case SOURCE_IO:
r = process_io(e, s, ev_queue[i].events); r = process_io(e, s, e->event_queue[i].events);
break; break;
case SOURCE_CHILD: case SOURCE_CHILD:
r = process_pidfd(e, s, ev_queue[i].events); r = process_pidfd(e, s, e->event_queue[i].events);
break; break;
default: default:
@ -3545,20 +3550,20 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
} }
case WAKEUP_CLOCK_DATA: { case WAKEUP_CLOCK_DATA: {
struct clock_data *d = ev_queue[i].data.ptr; struct clock_data *d = e->event_queue[i].data.ptr;
assert(d); assert(d);
r = flush_timer(e, d->fd, ev_queue[i].events, &d->next); r = flush_timer(e, d->fd, e->event_queue[i].events, &d->next);
break; break;
} }
case WAKEUP_SIGNAL_DATA: case WAKEUP_SIGNAL_DATA:
r = process_signal(e, ev_queue[i].data.ptr, ev_queue[i].events); r = process_signal(e, e->event_queue[i].data.ptr, e->event_queue[i].events);
break; break;
case WAKEUP_INOTIFY_DATA: case WAKEUP_INOTIFY_DATA:
r = event_inotify_data_read(e, ev_queue[i].data.ptr, ev_queue[i].events); r = event_inotify_data_read(e, e->event_queue[i].data.ptr, e->event_queue[i].events);
break; break;
default: default:

View File

@ -366,7 +366,8 @@ static int acquire_link_bitrates(sd_bus *bus, LinkInfo *link) {
"org.freedesktop.network1.Link", "org.freedesktop.network1.Link",
"BitRates"); "BitRates");
if (r < 0) { if (r < 0) {
bool quiet = sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_PROPERTY); bool quiet = sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_PROPERTY) ||
sd_bus_error_has_name(&error, BUS_ERROR_SPEED_METER_INACTIVE);
return log_full_errno(quiet ? LOG_DEBUG : LOG_WARNING, return log_full_errno(quiet ? LOG_DEBUG : LOG_WARNING,
r, "Failed to query link bit rates: %s", bus_error_message(&error, r)); r, "Failed to query link bit rates: %s", bus_error_message(&error, r));

View File

@ -33,6 +33,7 @@ int address_new(Address **ret) {
.cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME, .cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME,
.cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME, .cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME,
.duplicate_address_detection = ADDRESS_FAMILY_IPV6, .duplicate_address_detection = ADDRESS_FAMILY_IPV6,
.prefix_route = true,
}; };
*ret = TAKE_PTR(address); *ret = TAKE_PTR(address);
@ -596,7 +597,7 @@ int address_configure(
if (address->manage_temporary_address) if (address->manage_temporary_address)
address->flags |= IFA_F_MANAGETEMPADDR; address->flags |= IFA_F_MANAGETEMPADDR;
if (address->prefix_route) if (!address->prefix_route)
address->flags |= IFA_F_NOPREFIXROUTE; address->flags |= IFA_F_NOPREFIXROUTE;
if (address->autojoin) if (address->autojoin)
@ -1001,6 +1002,8 @@ int config_parse_address_flags(const char *unit,
else if (streq(lvalue, "ManageTemporaryAddress")) else if (streq(lvalue, "ManageTemporaryAddress"))
n->manage_temporary_address = r; n->manage_temporary_address = r;
else if (streq(lvalue, "PrefixRoute")) else if (streq(lvalue, "PrefixRoute"))
n->prefix_route = !r;
else if (streq(lvalue, "AddPrefixRoute"))
n->prefix_route = r; n->prefix_route = r;
else if (streq(lvalue, "AutoJoin")) else if (streq(lvalue, "AutoJoin"))
n->autojoin = r; n->autojoin = r;

View File

@ -111,10 +111,10 @@ static int route_scope_from_address(const Route *route, const struct in_addr *se
return RT_SCOPE_UNIVERSE; return RT_SCOPE_UNIVERSE;
} }
static bool link_noprefixroute(Link *link) { static bool link_prefixroute(Link *link) {
return link->network->dhcp_route_table_set && return !link->network->dhcp_route_table_set ||
link->network->dhcp_route_table != RT_TABLE_MAIN && link->network->dhcp_route_table == RT_TABLE_MAIN ||
!link->manager->dhcp4_prefix_root_cannot_set_table; link->manager->dhcp4_prefix_root_cannot_set_table;
} }
static int dhcp_route_configure(Route **route, Link *link) { static int dhcp_route_configure(Route **route, Link *link) {
@ -254,7 +254,7 @@ static int link_set_dhcp_routes(Link *link) {
if (r < 0) if (r < 0)
return log_link_warning_errno(link, r, "DHCP error: could not get address: %m"); return log_link_warning_errno(link, r, "DHCP error: could not get address: %m");
if (link_noprefixroute(link)) { if (!link_prefixroute(link)) {
_cleanup_(route_freep) Route *prefix_route = NULL; _cleanup_(route_freep) Route *prefix_route = NULL;
r = dhcp_prefix_route_from_lease(link->dhcp_lease, table, &address, &prefix_route); r = dhcp_prefix_route_from_lease(link->dhcp_lease, table, &address, &prefix_route);
@ -516,7 +516,7 @@ static int dhcp_remove_dns_routes(Link *link, sd_dhcp_lease *lease, const struct
(void) route_remove(route, link, NULL); (void) route_remove(route, link, NULL);
} }
if (link_noprefixroute(link)) { if (!link_prefixroute(link)) {
_cleanup_(route_freep) Route *prefix_route = NULL; _cleanup_(route_freep) Route *prefix_route = NULL;
r = dhcp_prefix_route_from_lease(lease, table, address, &prefix_route); r = dhcp_prefix_route_from_lease(lease, table, address, &prefix_route);
@ -719,7 +719,7 @@ static int dhcp4_update_address(Link *link,
addr->cinfo.ifa_valid = lifetime; addr->cinfo.ifa_valid = lifetime;
addr->prefixlen = prefixlen; addr->prefixlen = prefixlen;
addr->broadcast.s_addr = address->s_addr | ~netmask->s_addr; addr->broadcast.s_addr = address->s_addr | ~netmask->s_addr;
addr->prefix_route = link_noprefixroute(link); addr->prefix_route = link_prefixroute(link);
/* allow reusing an existing address and simply update its lifetime /* allow reusing an existing address and simply update its lifetime
* in case it already exists */ * in case it already exists */

View File

@ -106,7 +106,8 @@ Address.Label, config_parse_label,
Address.PreferredLifetime, config_parse_lifetime, 0, 0 Address.PreferredLifetime, config_parse_lifetime, 0, 0
Address.HomeAddress, config_parse_address_flags, 0, 0 Address.HomeAddress, config_parse_address_flags, 0, 0
Address.ManageTemporaryAddress, config_parse_address_flags, 0, 0 Address.ManageTemporaryAddress, config_parse_address_flags, 0, 0
Address.PrefixRoute, config_parse_address_flags, 0, 0 Address.PrefixRoute, config_parse_address_flags, 0, 0 /* deprecated */
Address.AddPrefixRoute, config_parse_address_flags, 0, 0
Address.AutoJoin, config_parse_address_flags, 0, 0 Address.AutoJoin, config_parse_address_flags, 0, 0
Address.DuplicateAddressDetection, config_parse_duplicate_address_detection, 0, 0 Address.DuplicateAddressDetection, config_parse_duplicate_address_detection, 0, 0
Address.Scope, config_parse_address_scope, 0, 0 Address.Scope, config_parse_address_scope, 0, 0

View File

@ -29,7 +29,7 @@ static void cleanup_clear_loop_close(int *fd) {
} }
} }
int loop_device_make_full( int loop_device_make(
int fd, int fd,
int open_flags, int open_flags,
uint64_t offset, uint64_t offset,
@ -166,7 +166,7 @@ int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_fla
if (fd < 0) if (fd < 0)
return -errno; return -errno;
return loop_device_make_full(fd, open_flags, 0, 0, loop_flags, ret); return loop_device_make(fd, open_flags, 0, 0, loop_flags, ret);
} }
LoopDevice* loop_device_unref(LoopDevice *d) { LoopDevice* loop_device_unref(LoopDevice *d) {

View File

@ -14,7 +14,7 @@ struct LoopDevice {
bool relinquished; bool relinquished;
}; };
int loop_device_make_full(int fd, int open_flags, uint64_t offset, uint64_t size, uint32_t loop_flags, LoopDevice **ret); int loop_device_make(int fd, int open_flags, uint64_t offset, uint64_t size, uint32_t loop_flags, LoopDevice **ret);
int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret); int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret);
int loop_device_open(const char *loop_path, int open_flags, LoopDevice **ret); int loop_device_open(const char *loop_path, int open_flags, LoopDevice **ret);

View File

@ -1,9 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1+ */ /* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once #pragma once
#if HAVE_OPENSSL
# include <openssl/pem.h> # include <openssl/pem.h>
DEFINE_TRIVIAL_CLEANUP_FUNC(X509*, X509_free); DEFINE_TRIVIAL_CLEANUP_FUNC(X509*, X509_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(X509_NAME*, X509_NAME_free); DEFINE_TRIVIAL_CLEANUP_FUNC(X509_NAME*, X509_NAME_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_PKEY_CTX*, EVP_PKEY_CTX_free); DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_PKEY_CTX*, EVP_PKEY_CTX_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_CIPHER_CTX*, EVP_CIPHER_CTX_free); DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_CIPHER_CTX*, EVP_CIPHER_CTX_free);
#endif

View File

@ -6,13 +6,10 @@
#if HAVE_P11KIT #if HAVE_P11KIT
# include <p11-kit/p11-kit.h> # include <p11-kit/p11-kit.h>
# include <p11-kit/uri.h> # include <p11-kit/uri.h>
#if HAVE_OPENSSL
#include <openssl/pem.h>
#endif
#endif #endif
#include "macro.h" #include "macro.h"
#include "openssl-util.h"
#include "time-util.h" #include "time-util.h"
bool pkcs11_uri_valid(const char *uri); bool pkcs11_uri_valid(const char *uri);

View File

@ -202,6 +202,7 @@ Address=
Scope= Scope=
HomeAddress= HomeAddress=
PrefixRoute= PrefixRoute=
AddPrefixRoute=
ManageTemporaryAddress= ManageTemporaryAddress=
Broadcast= Broadcast=
Peer= Peer=