1
0
mirror of https://github.com/systemd/systemd synced 2025-12-25 10:24:45 +01:00

Compare commits

..

10 Commits

Author SHA1 Message Date
Lennart Poettering
34d16bad2d update TODO 2020-05-18 18:41:14 +02:00
Zbigniew Jędrzejewski-Szmek
b3d15d90c0
Merge pull request #15804 from poettering/hostnamed-instant-part1
four likely safe commits split out of #15624
2020-05-18 15:26:24 +02:00
Zbigniew Jędrzejewski-Szmek
d7d892e694
Merge pull request #15494 from ssahani/dhcpv6-request-options
DHCPv6: Allow to add arbitrary request option
2020-05-18 13:14:36 +02:00
Susant Sahani
28a060688f dhcpv6 tests: Update since we allow arbitrary options to be set 2020-05-17 11:18:46 +02:00
Susant Sahani
35f6a5cb44 network: DHCPv6 - Add support set arbitary request options 2020-05-17 11:18:29 +02:00
Susant Sahani
2b20ca653c sd-dhcp6: Allow to add arbitary request option 2020-05-17 10:54:43 +02:00
Lennart Poettering
0271e9b10c man: complete vtable flag documentation 2020-05-13 16:57:44 +02:00
Lennart Poettering
491ce16103 sd-bus: introduce new SD_BUS_VTABLE_ABSOLUTE_OFFSET vtable flag
When set, the offset specified for the vtable entry is passed to the
handler as-is, and is not added to the userdata pointer. This is useful
in case methods/properties are mixed on the same vtable, that expect to
operate relative to some object in memory and that expect pointers to
absolute memory, or that just want a number passed.
2020-05-13 16:57:44 +02:00
Lennart Poettering
61c12865f5 resolved: port to stat_inode_unmodified() 2020-05-13 16:57:44 +02:00
Lennart Poettering
fee5c52ac2 stat-util: add stat_inode_unmodified() helper that checks if an inode was modified 2020-05-13 16:57:44 +02:00
20 changed files with 165 additions and 88 deletions

4
TODO
View File

@ -22,6 +22,10 @@ Janitorial Clean-ups:
Features:
* add "throttling" to sd-event event sources: optionally, when we wake up too
often for one, let's turn it off entirely for a while. Use that for the
/proc/self/mountinfo logic.
* move our systemd-user PAM snippet to /usr/, which PAM appears to support
these days

View File

@ -544,6 +544,25 @@
This corresponds to the <constant>org.freedesktop.systemd1.Explicit</constant> annotation
in introspection data.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>SD_BUS_VTABLE_SENSITIVE</constant></term>
<listitem><para>Mark this vtable method entry as processing sensitive data. When set,
incoming method call messages and their outgoing reply messages are marked as sensitive using
<citerefentry><refentrytitle>sd_bus_message_sensitive</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
so that they are erased from memory when freed.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>SD_BUS_VTABLE_ABSOLUTE_OFFSET</constant></term>
<listitem><para>Mark this vtable method or property entry so that the user data pointer passed to
its associated handler functions is determined slightly differently: instead of adding the offset
parameter of the entry to the user data pointer specified during vtable registration, the offset is
passed directly, converted to a pointer, without taking the user data pointer specified during
vtable registration into account.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>

View File

@ -1652,7 +1652,8 @@
<varlistentry>
<term><varname>RequestOptions=</varname></term>
<listitem>
<para>A whitespace-separated list of integers in the range 1254.</para>
<para>When configured, allows to set arbitrary request options in the DHCPv4 request options list and will be
sent to the DHCPV4 server. A whitespace-separated list of integers in the range 1..254. Defaults to unset.</para>
</listitem>
</varlistentry>
@ -1725,6 +1726,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><varname>RequestOptions=</varname></term>
<listitem>
<para>When configured, allows to set arbitrary request options in the DHCPv6 request options list and will
sent to the DHCPV6 server. A whitespace-separated list of integers in the range 1..254. Defaults to unset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>ForceDHCPv6PDOtherInformation=</varname></term>
<listitem>
@ -1746,7 +1755,7 @@
<listitem>
<para>Takes an IPv6 address with prefix length as <varname>Address=</varname> in
the "[Network]" section. Specifies the DHCPv6 client for the requesting router to include
a prefix-hint in the DHCPv6 solicitation. Prefix ranges 1-128. Defaults to unset.</para>
a prefix-hint in the DHCPv6 solicitation. Prefix ranges 1..128. Defaults to unset.</para>
</listitem>
</varlistentry>

View File

@ -388,3 +388,24 @@ int proc_mounted(void) {
return r;
}
bool stat_inode_unmodified(const struct stat *a, const struct stat *b) {
/* Returns if the specified stat structures reference the same, unmodified inode. This check tries to
* be reasonably careful when detecting changes: we check both inode and mtime, to cater for file
* systems where mtimes are fixed to 0 (think: ostree/nixos type installations). We also check file
* size, backing device, inode type and if this refers to a device not the major/minor.
*
* Note that we don't care if file attributes such as ownership or access mode change, this here is
* about contents of the file. The purpose here is to detect file contents changes, and nothing
* else. */
return a && b &&
(a->st_mode & S_IFMT) != 0 && /* We use the check for .st_mode if the structure was ever initialized */
((a->st_mode ^ b->st_mode) & S_IFMT) == 0 && /* same inode type */
a->st_mtime == b->st_mtime &&
(!S_ISREG(a->st_mode) || a->st_size == b->st_size) && /* if regular file, compare file size */
a->st_dev == b->st_dev &&
a->st_ino == b->st_ino &&
(!(S_ISCHR(a->st_mode) || S_ISBLK(a->st_mode)) || a->st_rdev == b->st_rdev); /* if device node, also compare major/minor, because we can */
}

View File

@ -89,3 +89,5 @@ int device_path_make_canonical(mode_t mode, dev_t devno, char **ret);
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devno);
int proc_mounted(void);
bool stat_inode_unmodified(const struct stat *a, const struct stat *b);

View File

@ -357,18 +357,8 @@ int sd_dhcp6_client_set_request_option(sd_dhcp6_client *client, uint16_t option)
assert_return(client, -EINVAL);
assert_return(client->state == DHCP6_STATE_STOPPED, -EBUSY);
switch(option) {
case SD_DHCP6_OPTION_DNS_SERVERS:
case SD_DHCP6_OPTION_DOMAIN_LIST:
case SD_DHCP6_OPTION_SNTP_SERVERS:
case SD_DHCP6_OPTION_NTP_SERVER:
case SD_DHCP6_OPTION_RAPID_COMMIT:
break;
default:
if (option <= 0 || option >= 255)
return -EINVAL;
}
for (t = 0; t < client->req_opts_len; t++)
if (client->req_opts[t] == htobe16(option))

View File

@ -61,12 +61,12 @@ static int test_client_basic(sd_event *e) {
assert_se(sd_dhcp6_client_set_fqdn(client, "~host") == -EINVAL);
assert_se(sd_dhcp6_client_set_fqdn(client, "~host.domain") == -EINVAL);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_CLIENTID) == -EINVAL);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_CLIENTID) == 0);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DNS_SERVERS) == -EEXIST);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_NTP_SERVER) == -EEXIST);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_SNTP_SERVERS) == -EEXIST);
assert_se(sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DOMAIN_LIST) == -EEXIST);
assert_se(sd_dhcp6_client_set_request_option(client, 10) == -EINVAL);
assert_se(sd_dhcp6_client_set_request_option(client, 10) == 0);
assert_se(sd_dhcp6_client_set_information_request(client, 1) >= 0);
v = 0;

View File

@ -56,7 +56,7 @@ static int node_vtable_get_userdata(
static void *vtable_method_convert_userdata(const sd_bus_vtable *p, void *u) {
assert(p);
if (!u)
if (!u || FLAGS_SET(p->flags, SD_BUS_VTABLE_ABSOLUTE_OFFSET))
return SIZE_TO_PTR(p->x.method.offset); /* don't add offset on NULL, to make ubsan happy */
return (uint8_t*) u + p->x.method.offset;
@ -65,7 +65,7 @@ static void *vtable_method_convert_userdata(const sd_bus_vtable *p, void *u) {
static void *vtable_property_convert_userdata(const sd_bus_vtable *p, void *u) {
assert(p);
if (!u)
if (!u || FLAGS_SET(p->flags, SD_BUS_VTABLE_ABSOLUTE_OFFSET))
return SIZE_TO_PTR(p->x.property.offset); /* as above */
return (uint8_t*) u + p->x.property.offset;

View File

@ -519,6 +519,82 @@ int config_parse_dhcp_send_option(
return 0;
}
int config_parse_dhcp_request_options(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Network *network = data;
const char *p;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(rvalue)) {
if (ltype == AF_INET)
network->dhcp_request_options = set_free(network->dhcp_request_options);
else
network->dhcp6_request_options = set_free(network->dhcp6_request_options);
return 0;
}
for (p = rvalue;;) {
_cleanup_free_ char *n = NULL;
uint32_t i;
r = extract_first_word(&p, &n, NULL, 0);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse DHCP request option, ignoring assignment: %s",
rvalue);
return 0;
}
if (r == 0)
return 0;
r = safe_atou32(n, &i);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"DHCP request option is invalid, ignoring assignment: %s", n);
continue;
}
if (i < 1 || i >= 255) {
log_syntax(unit, LOG_ERR, filename, line, r,
"DHCP request option is invalid, valid range is 1-254, ignoring assignment: %s", n);
continue;
}
if (ltype == AF_INET)
r = set_ensure_allocated(&network->dhcp_request_options, NULL);
else
r = set_ensure_allocated(&network->dhcp6_request_options, NULL);
if (r < 0)
return log_oom();
if (ltype == AF_INET)
r = set_put(network->dhcp_request_options, UINT32_TO_PTR(i));
else
r = set_put(network->dhcp6_request_options, UINT32_TO_PTR(i));
if (r < 0)
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to store DHCP request option '%s', ignoring assignment: %m", n);
}
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains,
"Failed to parse DHCP use domains setting");

View File

@ -51,3 +51,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);

View File

@ -1659,72 +1659,6 @@ int config_parse_dhcp_user_class(
return 0;
}
int config_parse_dhcp_request_options(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Network *network = data;
const char *p;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(rvalue)) {
network->dhcp_request_options = set_free(network->dhcp_request_options);
return 0;
}
for (p = rvalue;;) {
_cleanup_free_ char *n = NULL;
uint32_t i;
r = extract_first_word(&p, &n, NULL, 0);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse DHCP request option, ignoring assignment: %s",
rvalue);
return 0;
}
if (r == 0)
return 0;
r = safe_atou32(n, &i);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"DHCP request option is invalid, ignoring assignment: %s", n);
continue;
}
if (i < 1 || i >= 255) {
log_syntax(unit, LOG_ERR, filename, line, r,
"DHCP request option is invalid, valid range is 1-254, ignoring assignment: %s", n);
continue;
}
r = set_ensure_allocated(&network->dhcp_request_options, NULL);
if (r < 0)
return log_oom();
r = set_put(network->dhcp_request_options, UINT32_TO_PTR(i));
if (r < 0)
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to store DHCP request option '%s', ignoring assignment: %m", n);
}
return 0;
}
int config_parse_dhcp_ip_service_type(
const char *unit,
const char *filename,

View File

@ -26,6 +26,5 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_ip_service_type);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_mud_url);

View File

@ -621,6 +621,7 @@ static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
int dhcp6_configure(Link *link) {
_cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
sd_dhcp6_option *send_option;
void *request_options;
const DUID *duid;
Iterator i;
int r;
@ -692,6 +693,19 @@ int dhcp6_configure(Link *link) {
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set MUD URL: %m");
}
SET_FOREACH(request_options, link->network->dhcp6_request_options, i) {
uint32_t option = PTR_TO_UINT32(request_options);
r = sd_dhcp6_client_set_request_option(client, option);
if (r == -EEXIST) {
log_link_debug(link, "DHCP6 CLIENT: Failed to set request flag for '%u' already exists, ignoring.", option);
continue;
}
if (r < 0)
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set request flag for '%u': %m", option);
}
r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link);
if (r < 0)
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set callback: %m");

View File

@ -166,7 +166,7 @@ DHCPv4.UseHostname, config_parse_bool,
DHCPv4.UseDomains, config_parse_dhcp_use_domains, 0, offsetof(Network, dhcp_use_domains)
DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
DHCPv4.UseGateway, config_parse_tristate, 0, offsetof(Network, dhcp_use_gateway)
DHCPv4.RequestOptions, config_parse_dhcp_request_options, 0, 0
DHCPv4.RequestOptions, config_parse_dhcp_request_options, AF_INET, 0
DHCPv4.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
DHCPv4.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_send_hostname)
DHCPv4.Hostname, config_parse_hostname, 0, offsetof(Network, dhcp_hostname)
@ -193,6 +193,7 @@ DHCPv6.UseDNS, config_parse_bool,
DHCPv6.UseNTP, config_parse_bool, 0, offsetof(Network, dhcp6_use_ntp)
DHCPv6.RapidCommit, config_parse_bool, 0, offsetof(Network, rapid_commit)
DHCPv6.MUDURL, config_parse_dhcp6_mud_url, 0, 0
DHCPv6.RequestOptions, config_parse_dhcp_request_options, AF_INET6, 0
DHCPv6.ForceDHCPv6PDOtherInformation, config_parse_bool, 0, offsetof(Network, dhcp6_force_pd_other_information)
DHCPv6.PrefixDelegationHint, config_parse_dhcp6_pd_hint, 0, 0
DHCPv6.WithoutRA, config_parse_bool, 0, offsetof(Network, dhcp6_without_ra)

View File

@ -650,6 +650,7 @@ static Network *network_free(Network *network) {
free(network->dhcp_hostname);
set_free(network->dhcp_black_listed_ip);
set_free(network->dhcp_request_options);
set_free(network->dhcp6_request_options);
free(network->mac);
free(network->dhcp6_mudurl);

View File

@ -134,6 +134,7 @@ struct Network {
char *dhcp6_mudurl;
struct in6_addr dhcp6_pd_address;
OrderedHashmap *dhcp6_client_send_options;
Set *dhcp6_request_options;
/* DHCP Server Support */
bool dhcp_server;

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <sys/stat.h>
#include "sd-event.h"
#include "sd-netlink.h"
#include "sd-network.h"
@ -71,7 +73,7 @@ struct Manager {
bool need_builtin_fallbacks:1;
bool read_resolv_conf:1;
usec_t resolv_conf_mtime;
struct stat resolv_conf_stat;
DnsTrustAnchor trust_anchor;

View File

@ -14,6 +14,7 @@
#include "resolved-conf.h"
#include "resolved-dns-server.h"
#include "resolved-resolv-conf.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "tmpfile-util-label.h"
@ -93,7 +94,7 @@ int manager_read_resolv_conf(Manager *m) {
}
/* Have we already seen the file? */
if (timespec_load(&st.st_mtim) == m->resolv_conf_mtime)
if (stat_inode_unmodified(&st, &m->resolv_conf_stat))
return 0;
if (file_is_our_own(&st))
@ -159,7 +160,7 @@ int manager_read_resolv_conf(Manager *m) {
log_syntax(NULL, LOG_DEBUG, "/etc/resolv.conf", n, 0, "Ignoring resolv.conf line: %s", l);
}
m->resolv_conf_mtime = timespec_load(&st.st_mtim);
m->resolv_conf_stat = st;
/* Flush out all servers and search domains that are still
* marked. Those are then ones that didn't appear in the new

View File

@ -44,6 +44,7 @@ enum {
SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION = 1ULL << 6,
SD_BUS_VTABLE_PROPERTY_EXPLICIT = 1ULL << 7,
SD_BUS_VTABLE_SENSITIVE = 1ULL << 8, /* covers both directions: method call + reply */
SD_BUS_VTABLE_ABSOLUTE_OFFSET = 1ULL << 9,
_SD_BUS_VTABLE_CAPABILITY_MASK = 0xFFFFULL << 40
};

View File

@ -114,6 +114,7 @@ PrefixDelegationHint=
WithoutRA=
MUDURL=
SendOption=
RequestOptions=
[Route]
Destination=
Protocol=