Compare commits

...

15 Commits

Author SHA1 Message Date
Lennart Poettering 527653f827
Merge pull request #19857 from yuwata/tmpfile-fix
tmpfiles: fix an issue found by Coverity
2021-06-10 09:30:57 +02:00
Lennart Poettering bb25f236d4
Merge pull request #19863 from keszybz/coverity-drop-unitialized-workarounds
Drop some -Wmaybe-unitialized workarounds to help coverity
2021-06-10 09:29:59 +02:00
Lennart Poettering 0629adf7c3
Merge pull request #19867 from yuwata/ether-addr-util
ether-addr-util: introduce hw_addr_equal() and friends
2021-06-10 09:29:36 +02:00
Anita Zhang c48bc311a5 man: add note about operation without swap in systemd-oomd 2021-06-10 07:24:18 +02:00
nerdopolis 3c3335c714 Clarify help information for --global 2021-06-10 07:23:05 +02:00
Yu Watanabe c68cafbabe tmpfile: always get file descriptor of root or current directory
Fixes CID#1457467.
2021-06-10 05:42:03 +09:00
Zbigniew Jędrzejewski-Szmek 67e9c83bad cryptsetup: remove unitialized workaround
Doesn't seem needed anymore.
2021-06-09 22:01:13 +02:00
Zbigniew Jędrzejewski-Szmek 21996f81b2 test-capability: drop work-around initialization
Since those workarounds have been added, work has been done to tighten
up log_*() return values. Seems we get no warning with
gcc-11.1.1-1.fc34.x86_64 and -O0/-O2.
2021-06-09 22:01:13 +02:00
Zbigniew Jędrzejewski-Szmek 59ca71a93d networkd: drop one workaround initialization
As for the other ones in src/network/, if they are removed, gcc warns when they
are removed.

Should fix Coverity CID#1457466.
2021-06-09 22:00:28 +02:00
Yu Watanabe 4b574fd813 ether-addr-util, network: introduce ETHER_ADDR_TO_STR() macro and use it 2021-06-10 00:37:50 +09:00
Yu Watanabe f929f18c59 network: use hw_addr_equal() or friends 2021-06-10 00:29:59 +09:00
Yu Watanabe 30b977251c ether-addr-util: introduce hw_addr_compare(), hw_addr_equal(), and hw_addr_is_null() 2021-06-10 00:24:43 +09:00
Yu Watanabe ca2b7cd813 ether-addr-util: drop redundant "addr" from struct hw_addr_data
Also, this makes always specifiy "struct" for hw_addr_data.
2021-06-10 00:19:50 +09:00
Zbigniew Jędrzejewski-Szmek 6923020ec1 networkd: reorder conditional to handle errors first
This also avoid the implicit assumption that if r is not -ENOENT, 0, or 1,
it must be negative. The compiler cannot know this.
2021-06-09 12:48:52 +02:00
Yu Watanabe 21e43a7c51 tmpfile: several minor coding style fixes
This makes the followings:
- reduces scope of variables,
- drop unnecessary 'else'
- use CLOSE_AND_REPLACE() macro
- use strnull() for possible NULL string
2021-06-09 13:30:19 +09:00
26 changed files with 121 additions and 109 deletions

View File

@ -60,7 +60,9 @@
Without swap, the system enters a livelocked state much more quickly and may prevent <command>systemd-oomd</command> Without swap, the system enters a livelocked state much more quickly and may prevent <command>systemd-oomd</command>
from responding in a reasonable amount of time. See from responding in a reasonable amount of time. See
<ulink url="https://chrisdown.name/2018/01/02/in-defence-of-swap.html">"In defence of swap: common misconceptions"</ulink> <ulink url="https://chrisdown.name/2018/01/02/in-defence-of-swap.html">"In defence of swap: common misconceptions"</ulink>
for more details on swap.</para> for more details on swap. Any swap-based actions on systems without swap will be ignored. While
<command>systemd-oomd</command> can perform pressure-based actions on a system without swap, the pressure increases
will be more abrupt and may require more tuning to get the desired thresholds and behavior.</para>
<para>Be aware that if you intend to enable monitoring and actions on <filename>user.slice</filename>, <para>Be aware that if you intend to enable monitoring and actions on <filename>user.slice</filename>,
<filename>user-$UID.slice</filename>, or their ancestor cgroups, it is highly recommended that your programs be <filename>user-$UID.slice</filename>, or their ancestor cgroups, it is highly recommended that your programs be

View File

@ -485,7 +485,7 @@ _arguments -s \
'--system[Connect to system manager]' \ '--system[Connect to system manager]' \
'--user[Connect to user service manager]' \ '--user[Connect to user service manager]' \
"--no-wall[Don't send wall message before halt/power-off/reboot]" \ "--no-wall[Don't send wall message before halt/power-off/reboot]" \
'--global[Enable/disable/mask unit files globally]' \ '--global[Enable/disable/mask default user unit files globally]' \
"--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \ "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
'--no-ask-password[Do not ask for system passwords]' \ '--no-ask-password[Do not ask for system passwords]' \
'--kill-who=[Who to send signal to]:killwho:(main control all)' \ '--kill-who=[Who to send signal to]:killwho:(main control all)' \

View File

@ -10,13 +10,13 @@
#include "macro.h" #include "macro.h"
#include "string-util.h" #include "string-util.h"
char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]) { char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]) {
assert(addr); assert(addr);
assert(buffer); assert(buffer);
assert(addr->length <= HW_ADDR_MAX_SIZE); assert(addr->length <= HW_ADDR_MAX_SIZE);
for (size_t i = 0; i < addr->length; i++) { for (size_t i = 0; i < addr->length; i++) {
sprintf(&buffer[3*i], "%02"PRIx8, addr->addr.bytes[i]); sprintf(&buffer[3*i], "%02"PRIx8, addr->bytes[i]);
if (i < addr->length - 1) if (i < addr->length - 1)
buffer[3*i + 2] = ':'; buffer[3*i + 2] = ':';
} }
@ -24,6 +24,19 @@ char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_
return buffer; return buffer;
} }
int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b) {
int r;
assert(a);
assert(b);
r = CMP(a->length, b->length);
if (r != 0)
return r;
return memcmp(a->bytes, b->bytes, a->length);
}
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) { char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) {
assert(addr); assert(addr);
assert(buffer); assert(buffer);

View File

@ -11,24 +11,30 @@
* defines a macro of the same name with a much lower size. */ * defines a macro of the same name with a much lower size. */
#define HW_ADDR_MAX_SIZE 32 #define HW_ADDR_MAX_SIZE 32
union hw_addr_union { struct hw_addr_data {
struct ether_addr ether; size_t length;
uint8_t infiniband[INFINIBAND_ALEN]; union {
uint8_t bytes[HW_ADDR_MAX_SIZE]; struct ether_addr ether;
uint8_t infiniband[INFINIBAND_ALEN];
uint8_t bytes[HW_ADDR_MAX_SIZE];
};
}; };
typedef struct hw_addr_data {
union hw_addr_union addr;
size_t length;
} hw_addr_data;
#define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE) #define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE)
char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]); char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]);
/* Use only as function argument, never stand-alone! */ /* Use only as function argument, never stand-alone! */
#define HW_ADDR_TO_STR(hw_addr) hw_addr_to_string((hw_addr), (char[HW_ADDR_TO_STRING_MAX]){}) #define HW_ADDR_TO_STR(hw_addr) hw_addr_to_string((hw_addr), (char[HW_ADDR_TO_STRING_MAX]){})
#define HW_ADDR_NULL ((const hw_addr_data){}) #define HW_ADDR_NULL ((const struct hw_addr_data){})
int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b);
static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_addr_data *b) {
return hw_addr_compare(a, b) == 0;
}
static inline bool hw_addr_is_null(const struct hw_addr_data *addr) {
return hw_addr_equal(addr, &HW_ADDR_NULL);
}
#define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X" #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X"
#define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5] #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]
@ -36,6 +42,8 @@ char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_
#define ETHER_ADDR_TO_STRING_MAX (3*6) #define ETHER_ADDR_TO_STRING_MAX (3*6)
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]); char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]);
int ether_addr_to_string_alloc(const struct ether_addr *addr, char **ret); int ether_addr_to_string_alloc(const struct ether_addr *addr, char **ret);
/* Use only as function argument, never stand-alone! */
#define ETHER_ADDR_TO_STR(addr) ether_addr_to_string((addr), (char[ETHER_ADDR_TO_STRING_MAX]){})
int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b); int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b);
static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) { static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) {

View File

@ -1056,7 +1056,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
_cleanup_(sd_event_unrefp) sd_event *event = NULL; _cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_free_ char *friendly = NULL; _cleanup_free_ char *friendly = NULL;
int keyslot = arg_key_slot, r; int keyslot = arg_key_slot, r;
size_t decrypted_key_size = 0; /* avoid false maybe-uninitialized warning */ size_t decrypted_key_size;
assert(cd); assert(cd);
assert(name); assert(name);

View File

@ -494,7 +494,7 @@ int sd_netlink_message_append_ether_addr(sd_netlink_message *m, unsigned short t
return 0; return 0;
} }
int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const hw_addr_data *data) { int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const struct hw_addr_data *data) {
int r; int r;
assert_return(m, -EINVAL); assert_return(m, -EINVAL);
@ -506,7 +506,7 @@ int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, c
if (r < 0) if (r < 0)
return r; return r;
r = add_rtattr(m, type, data->addr.bytes, data->length); r = add_rtattr(m, type, data->bytes, data->length);
if (r < 0) if (r < 0)
return r; return r;
@ -886,7 +886,7 @@ int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short typ
return 0; return 0;
} }
int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, hw_addr_data *data) { int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, struct hw_addr_data *data) {
int r; int r;
void *attr_data; void *attr_data;
@ -899,11 +899,11 @@ int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, hw_
r = netlink_message_read_internal(m, type, &attr_data, NULL); r = netlink_message_read_internal(m, type, &attr_data, NULL);
if (r < 0) if (r < 0)
return r; return r;
else if ((size_t) r > sizeof(union hw_addr_union)) else if (r > HW_ADDR_MAX_SIZE)
return -EIO; return -EIO;
if (data) { if (data) {
memcpy(data->addr.bytes, attr_data, r); memcpy(data->bytes, attr_data, r);
data->length = r; data->length = r;
} }

View File

@ -117,11 +117,11 @@ int rtnl_log_create_error(int r);
userdata, description); \ userdata, description); \
}) })
int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const hw_addr_data *data); int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const struct hw_addr_data *data);
int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data); int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data);
int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data); int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data);
int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, hw_addr_data *data); int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, struct hw_addr_data *data);
int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short type, int family, union in_addr_union *data); int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short type, int family, union in_addr_union *data);
void rtattr_append_attribute_internal(struct rtattr *rta, unsigned short type, const void *data, size_t data_length); void rtattr_append_attribute_internal(struct rtattr *rta, unsigned short type, const void *data, size_t data_length);

View File

@ -1040,7 +1040,6 @@ static int route_dump(Route *route, FILE *f) {
} }
void network_dump(Network *network, FILE *f) { void network_dump(Network *network, FILE *f) {
char mac[ETHER_ADDR_TO_STRING_MAX];
Address *address; Address *address;
Route *route; Route *route;
const char *dhcp; const char *dhcp;
@ -1057,7 +1056,7 @@ void network_dump(Network *network, FILE *f) {
fputs("\n[Link]\n", f); fputs("\n[Link]\n", f);
if (!ether_addr_is_null(&network->mac)) if (!ether_addr_is_null(&network->mac))
fprintf(f, "MACAddress=%s\n", ether_addr_to_string(&network->mac, mac)); fprintf(f, "MACAddress=%s\n", ETHER_ADDR_TO_STR(&network->mac));
if (network->mtu > 0) if (network->mtu > 0)
fprintf(f, "MTUBytes=%" PRIu32 "\n", network->mtu); fprintf(f, "MTUBytes=%" PRIu32 "\n", network->mtu);
@ -1111,15 +1110,13 @@ void netdev_dump(NetDev *netdev, FILE *f) {
} }
void link_dump(Link *link, FILE *f) { void link_dump(Link *link, FILE *f) {
char mac[ETHER_ADDR_TO_STRING_MAX];
assert(link); assert(link);
assert(f); assert(f);
fputs("[Match]\n", f); fputs("[Match]\n", f);
if (!ether_addr_is_null(&link->mac)) if (!ether_addr_is_null(&link->mac))
fprintf(f, "MACAddress=%s\n", ether_addr_to_string(&link->mac, mac)); fprintf(f, "MACAddress=%s\n", ETHER_ADDR_TO_STR(&link->mac));
fprintf(f, fprintf(f,
"\n[Link]\n" "\n[Link]\n"

View File

@ -272,7 +272,7 @@ typedef struct LinkInfo {
sd_device *sd_device; sd_device *sd_device;
int ifindex; int ifindex;
unsigned short iftype; unsigned short iftype;
hw_addr_data hw_address; struct hw_addr_data hw_address;
struct ether_addr permanent_mac_address; struct ether_addr permanent_mac_address;
uint32_t master; uint32_t master;
uint32_t mtu; uint32_t mtu;
@ -554,13 +554,13 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns, b
info->has_mac_address = info->has_mac_address =
netlink_message_read_hw_addr(m, IFLA_ADDRESS, &info->hw_address) >= 0 && netlink_message_read_hw_addr(m, IFLA_ADDRESS, &info->hw_address) >= 0 &&
memcmp(&info->hw_address, &HW_ADDR_NULL, sizeof(hw_addr_data)) != 0; !hw_addr_is_null(&info->hw_address);
info->has_permanent_mac_address = info->has_permanent_mac_address =
ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 && ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 &&
memcmp(&info->permanent_mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0 && !ether_addr_is_null(&info->permanent_mac_address) &&
(info->hw_address.length != sizeof(struct ether_addr) || (info->hw_address.length != sizeof(struct ether_addr) ||
memcmp(&info->permanent_mac_address, info->hw_address.addr.bytes, sizeof(struct ether_addr)) != 0); memcmp(&info->permanent_mac_address, info->hw_address.bytes, sizeof(struct ether_addr)) != 0);
(void) sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu); (void) sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu);
(void) sd_netlink_message_read_u32(m, IFLA_MIN_MTU, &info->min_mtu); (void) sd_netlink_message_read_u32(m, IFLA_MIN_MTU, &info->min_mtu);
@ -1684,7 +1684,7 @@ static int link_status_one(
_cleanup_free_ char *description = NULL; _cleanup_free_ char *description = NULL;
if (info->hw_address.length == ETH_ALEN) if (info->hw_address.length == ETH_ALEN)
(void) ieee_oui(hwdb, &info->hw_address.addr.ether, &description); (void) ieee_oui(hwdb, &info->hw_address.ether, &description);
r = table_add_many(table, r = table_add_many(table,
TABLE_EMPTY, TABLE_EMPTY,
@ -1702,7 +1702,6 @@ static int link_status_one(
if (info->has_permanent_mac_address) { if (info->has_permanent_mac_address) {
_cleanup_free_ char *description = NULL; _cleanup_free_ char *description = NULL;
char ea[ETHER_ADDR_TO_STRING_MAX];
(void) ieee_oui(hwdb, &info->permanent_mac_address, &description); (void) ieee_oui(hwdb, &info->permanent_mac_address, &description);
@ -1712,7 +1711,7 @@ static int link_status_one(
if (r < 0) if (r < 0)
return table_log_add_error(r); return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s%s%s", r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
ether_addr_to_string(&info->permanent_mac_address, ea), ETHER_ADDR_TO_STR(&info->permanent_mac_address),
description ? " (" : "", description ? " (" : "",
strempty(description), strempty(description),
description ? ")" : ""); description ? ")" : "");
@ -2107,7 +2106,6 @@ static int link_status_one(
if (info->has_wlan_link_info) { if (info->has_wlan_link_info) {
_cleanup_free_ char *esc = NULL; _cleanup_free_ char *esc = NULL;
char buf[ETHER_ADDR_TO_STRING_MAX];
r = table_add_many(table, r = table_add_many(table,
TABLE_EMPTY, TABLE_EMPTY,
@ -2120,7 +2118,7 @@ static int link_status_one(
r = table_add_cell_stringf(table, NULL, "%s (%s)", r = table_add_cell_stringf(table, NULL, "%s (%s)",
strnull(esc), strnull(esc),
ether_addr_to_string(&info->bssid, buf)); ETHER_ADDR_TO_STR(&info->bssid));
if (r < 0) if (r < 0)
return table_log_add_error(r); return table_log_add_error(r);
} }

View File

@ -59,22 +59,22 @@ int generate_ipv6_eui_64_address(const Link *link, struct in6_addr *ret) {
if (link->iftype == ARPHRD_INFINIBAND) { if (link->iftype == ARPHRD_INFINIBAND) {
/* see RFC4391 section 8 */ /* see RFC4391 section 8 */
memcpy(&ret->s6_addr[8], &link->hw_addr.addr.infiniband[12], 8); memcpy(&ret->s6_addr[8], &link->hw_addr.infiniband[12], 8);
ret->s6_addr[8] ^= 1 << 1; ret->s6_addr[8] ^= 1 << 1;
return 0; return 0;
} }
/* see RFC4291 section 2.5.1 */ /* see RFC4291 section 2.5.1 */
ret->s6_addr[8] = link->hw_addr.addr.ether.ether_addr_octet[0]; ret->s6_addr[8] = link->hw_addr.ether.ether_addr_octet[0];
ret->s6_addr[8] ^= 1 << 1; ret->s6_addr[8] ^= 1 << 1;
ret->s6_addr[9] = link->hw_addr.addr.ether.ether_addr_octet[1]; ret->s6_addr[9] = link->hw_addr.ether.ether_addr_octet[1];
ret->s6_addr[10] = link->hw_addr.addr.ether.ether_addr_octet[2]; ret->s6_addr[10] = link->hw_addr.ether.ether_addr_octet[2];
ret->s6_addr[11] = 0xff; ret->s6_addr[11] = 0xff;
ret->s6_addr[12] = 0xfe; ret->s6_addr[12] = 0xfe;
ret->s6_addr[13] = link->hw_addr.addr.ether.ether_addr_octet[3]; ret->s6_addr[13] = link->hw_addr.ether.ether_addr_octet[3];
ret->s6_addr[14] = link->hw_addr.addr.ether.ether_addr_octet[4]; ret->s6_addr[14] = link->hw_addr.ether.ether_addr_octet[4];
ret->s6_addr[15] = link->hw_addr.addr.ether.ether_addr_octet[5]; ret->s6_addr[15] = link->hw_addr.ether.ether_addr_octet[5];
return 0; return 0;
} }
@ -1531,7 +1531,7 @@ static int ipv4_dad_configure(Address *address) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.addr.ether); r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;
@ -1561,7 +1561,7 @@ static int ipv4_dad_update_mac_one(Address *address) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.addr.ether); r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -852,7 +852,7 @@ static int dhcp4_configure_dad(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.addr.ether); r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;
@ -874,7 +874,7 @@ static int dhcp4_dad_update_mac(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.addr.ether); r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;
@ -1437,7 +1437,7 @@ static int dhcp4_set_client_identifier(Link *link) {
break; break;
} }
case DHCP_CLIENT_ID_MAC: { case DHCP_CLIENT_ID_MAC: {
const uint8_t *hw_addr = link->hw_addr.addr.bytes; const uint8_t *hw_addr = link->hw_addr.bytes;
size_t hw_addr_len = link->hw_addr.length; size_t hw_addr_len = link->hw_addr.length;
if (link->iftype == ARPHRD_INFINIBAND && hw_addr_len == INFINIBAND_ALEN) { if (link->iftype == ARPHRD_INFINIBAND && hw_addr_len == INFINIBAND_ALEN) {
@ -1546,8 +1546,8 @@ int dhcp4_configure(Link *link) {
return log_link_warning_errno(link, r, "DHCP4 CLIENT: Failed to attach event to DHCP4 client: %m"); return log_link_warning_errno(link, r, "DHCP4 CLIENT: Failed to attach event to DHCP4 client: %m");
r = sd_dhcp_client_set_mac(link->dhcp_client, r = sd_dhcp_client_set_mac(link->dhcp_client,
link->hw_addr.addr.bytes, link->hw_addr.bytes,
link->bcast_addr.length > 0 ? link->bcast_addr.addr.bytes : NULL, link->bcast_addr.length > 0 ? link->bcast_addr.bytes : NULL,
link->hw_addr.length, link->iftype); link->hw_addr.length, link->iftype);
if (r < 0) if (r < 0)
return log_link_warning_errno(link, r, "DHCP4 CLIENT: Failed to set MAC address: %m"); return log_link_warning_errno(link, r, "DHCP4 CLIENT: Failed to set MAC address: %m");
@ -1702,8 +1702,8 @@ int dhcp4_update_mac(Link *link) {
if (!link->dhcp_client) if (!link->dhcp_client)
return 0; return 0;
r = sd_dhcp_client_set_mac(link->dhcp_client, link->hw_addr.addr.bytes, r = sd_dhcp_client_set_mac(link->dhcp_client, link->hw_addr.bytes,
link->bcast_addr.length > 0 ? link->bcast_addr.addr.bytes : NULL, link->bcast_addr.length > 0 ? link->bcast_addr.bytes : NULL,
link->hw_addr.length, link->iftype); link->hw_addr.length, link->iftype);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -1569,7 +1569,7 @@ static int dhcp6_set_identifier(Link *link, sd_dhcp6_client *client) {
assert(link->network); assert(link->network);
assert(client); assert(client);
r = sd_dhcp6_client_set_mac(client, link->hw_addr.addr.bytes, link->hw_addr.length, link->iftype); r = sd_dhcp6_client_set_mac(client, link->hw_addr.bytes, link->hw_addr.length, link->iftype);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -166,7 +166,7 @@ int ipv4ll_configure(Link *link) {
return r; return r;
} }
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.addr.ether); r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;
@ -196,7 +196,7 @@ int ipv4ll_update_mac(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.addr.ether); r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -1157,7 +1157,7 @@ static int link_get_network(Link *link, Network **ret) {
r = net_match_config( r = net_match_config(
&network->match, &network->match,
link->sd_device, link->sd_device,
&link->hw_addr.addr.ether, &link->hw_addr.ether,
&link->permanent_mac, &link->permanent_mac,
link->driver, link->driver,
link->iftype, link->iftype,
@ -1968,7 +1968,7 @@ static int link_update_master(Link *link, sd_netlink_message *message) {
} }
static int link_update_hardware_address(Link *link, sd_netlink_message *message) { static int link_update_hardware_address(Link *link, sd_netlink_message *message) {
hw_addr_data hw_addr; struct hw_addr_data hw_addr;
int r; int r;
assert(link); assert(link);
@ -1984,8 +1984,7 @@ static int link_update_hardware_address(Link *link, sd_netlink_message *message)
if (r < 0) if (r < 0)
return log_link_warning_errno(link, r, "rtnl: failed to read hardware address: %m"); return log_link_warning_errno(link, r, "rtnl: failed to read hardware address: %m");
if (link->hw_addr.length == hw_addr.length && if (hw_addr_equal(&link->hw_addr, &hw_addr))
memcmp(link->hw_addr.addr.bytes, hw_addr.addr.bytes, hw_addr.length) == 0)
return 0; return 0;
link->hw_addr = hw_addr; link->hw_addr = hw_addr;
@ -2009,13 +2008,13 @@ static int link_update_hardware_address(Link *link, sd_netlink_message *message)
return log_link_debug_errno(link, r, "Could not update MAC address for Router Advertisement: %m"); return log_link_debug_errno(link, r, "Could not update MAC address for Router Advertisement: %m");
if (link->ndisc) { if (link->ndisc) {
r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.addr.ether); r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return log_link_debug_errno(link, r, "Could not update MAC for NDisc: %m"); return log_link_debug_errno(link, r, "Could not update MAC for NDisc: %m");
} }
if (link->lldp) { if (link->lldp) {
r = sd_lldp_set_filter_address(link->lldp, &link->hw_addr.addr.ether); r = sd_lldp_set_filter_address(link->lldp, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return log_link_debug_errno(link, r, "Could not update MAC address for LLDP: %m"); return log_link_debug_errno(link, r, "Could not update MAC address for LLDP: %m");
} }

View File

@ -53,8 +53,8 @@ typedef struct Link {
char *kind; char *kind;
unsigned short iftype; unsigned short iftype;
char *state_file; char *state_file;
hw_addr_data hw_addr; struct hw_addr_data hw_addr;
hw_addr_data bcast_addr; struct hw_addr_data bcast_addr;
struct ether_addr permanent_mac; struct ether_addr permanent_mac;
struct in6_addr ipv6ll_address; struct in6_addr ipv6ll_address;
uint32_t mtu; uint32_t mtu;

View File

@ -95,7 +95,7 @@ int link_lldp_rx_configure(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_lldp_set_filter_address(link->lldp, &link->hw_addr.addr.ether); r = sd_lldp_set_filter_address(link->lldp, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -314,7 +314,7 @@ static int link_send_lldp(Link *link) {
SD_LLDP_SYSTEM_CAPABILITIES_STATION; SD_LLDP_SYSTEM_CAPABILITIES_STATION;
r = lldp_make_packet(link->network->lldp_emit, r = lldp_make_packet(link->network->lldp_emit,
&link->hw_addr.addr.ether, &link->hw_addr.ether,
sd_id128_to_string(machine_id, machine_id_string), sd_id128_to_string(machine_id, machine_id_string),
link->ifname, link->ifname,
(uint16_t) ttl, (uint16_t) ttl,

View File

@ -657,9 +657,9 @@ static int make_stableprivate_address(Link *link, const struct in6_addr *prefix,
siphash24_compress_string(link->ifname, &state); siphash24_compress_string(link->ifname, &state);
/* Only last 8 bytes of IB MAC are stable */ /* Only last 8 bytes of IB MAC are stable */
if (link->iftype == ARPHRD_INFINIBAND) if (link->iftype == ARPHRD_INFINIBAND)
siphash24_compress(&link->hw_addr.addr.infiniband[12], 8, &state); siphash24_compress(&link->hw_addr.infiniband[12], 8, &state);
else else
siphash24_compress(link->hw_addr.addr.bytes, link->hw_addr.length, &state); siphash24_compress(link->hw_addr.bytes, link->hw_addr.length, &state);
siphash24_compress(&dad_counter, sizeof(uint8_t), &state); siphash24_compress(&dad_counter, sizeof(uint8_t), &state);
rid = htole64(siphash24_finalize(&state)); rid = htole64(siphash24_finalize(&state));
@ -1370,7 +1370,7 @@ int ndisc_configure(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.addr.ether); r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -16,7 +16,6 @@ static int property_get_ether_addrs(
void *userdata, void *userdata,
sd_bus_error *error) { sd_bus_error *error) {
char buf[ETHER_ADDR_TO_STRING_MAX];
const struct ether_addr *p; const struct ether_addr *p;
Set *s; Set *s;
int r; int r;
@ -32,7 +31,7 @@ static int property_get_ether_addrs(
return r; return r;
SET_FOREACH(p, s) { SET_FOREACH(p, s) {
r = sd_bus_message_append(reply, "s", ether_addr_to_string(p, buf)); r = sd_bus_message_append(reply, "s", ETHER_ADDR_TO_STR(p));
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -694,7 +694,7 @@ int radv_configure(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_radv_set_mac(link->radv, &link->hw_addr.addr.ether); r = sd_radv_set_mac(link->radv, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;
@ -766,7 +766,7 @@ int radv_update_mac(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
r = sd_radv_set_mac(link->radv, &link->hw_addr.addr.ether); r = sd_radv_set_mac(link->radv, &link->hw_addr.ether);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -338,7 +338,9 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout
rule->manager = m; rule->manager = m;
existing = TAKE_PTR(rule); existing = TAKE_PTR(rule);
} else if (r == 0) { } else if (r < 0)
return r;
else if (r == 0) {
/* Take over a foreign rule. */ /* Take over a foreign rule. */
r = set_ensure_put(&m->rules, &routing_policy_rule_hash_ops, existing); r = set_ensure_put(&m->rules, &routing_policy_rule_hash_ops, existing);
if (r < 0) if (r < 0)
@ -346,11 +348,7 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout
assert(r > 0); assert(r > 0);
set_remove(m->rules_foreign, existing); set_remove(m->rules_foreign, existing);
} else if (r == 1) { } /* else r > 0: already exists, do nothing. */
/* Already exists, do nothing. */
;
} else
return r;
if (ret) if (ret)
*ret = existing; *ret = existing;

View File

@ -692,7 +692,7 @@ int link_request_to_set_master(Link *link) {
} }
int link_request_to_set_mtu(Link *link, uint32_t mtu) { int link_request_to_set_mtu(Link *link, uint32_t mtu) {
Request *req = NULL; /* avoid false maybe-uninitialized warning */ Request *req;
const char *origin; const char *origin;
uint32_t min_mtu; uint32_t min_mtu;
int r; int r;

View File

@ -55,11 +55,9 @@ int wifi_get_info(Link *link) {
} }
if (r > 0 || s > 0) { if (r > 0 || s > 0) {
char buf[ETHER_ADDR_TO_STRING_MAX];
if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid) if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
log_link_info(link, "Connected WiFi access point: %s (%s)", log_link_info(link, "Connected WiFi access point: %s (%s)",
link->ssid, ether_addr_to_string(&link->bssid, buf)); link->ssid, ETHER_ADDR_TO_STR(&link->bssid));
return 1; /* Some information is updated. */ return 1; /* Some information is updated. */
} }

View File

@ -277,7 +277,7 @@ static int systemctl_help(void) {
" --legend=BOOL Enable/disable the legend (column headers and hints)\n" " --legend=BOOL Enable/disable the legend (column headers and hints)\n"
" --no-pager Do not pipe output into a pager\n" " --no-pager Do not pipe output into a pager\n"
" --no-ask-password Do not ask for system passwords\n" " --no-ask-password Do not ask for system passwords\n"
" --global Enable/disable/mask unit files globally\n" " --global Enable/disable/mask default user unit files globally\n"
" --runtime Enable/disable/mask unit files temporarily until next\n" " --runtime Enable/disable/mask unit files temporarily until next\n"
" reboot\n" " reboot\n"
" -f --force When enabling unit files, override existing symlinks\n" " -f --force When enabling unit files, override existing symlinks\n"

View File

@ -248,7 +248,7 @@ static void test_ensure_cap_64bit(void) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool run_ambient = false; /* avoid false maybe-uninitialized warning */ bool run_ambient;
test_setup_logging(LOG_INFO); test_setup_logging(LOG_INFO);

View File

@ -2033,7 +2033,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
static int rm_if_wrong_type_safe( static int rm_if_wrong_type_safe(
mode_t mode, mode_t mode,
int parent_fd, int parent_fd,
const struct stat *parent_st /* Only used if follow is true. */, const struct stat *parent_st, /* Only used if follow_links below is true. */
const char *name, const char *name,
int flags) { int flags) {
_cleanup_free_ char *parent_name = NULL; _cleanup_free_ char *parent_name = NULL;
@ -2110,12 +2110,10 @@ static int rm_if_wrong_type_safe(
/* If child_mode is non-zero, rm_if_wrong_type_safe will be executed for the last path component. */ /* If child_mode is non-zero, rm_if_wrong_type_safe will be executed for the last path component. */
static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) { static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
_cleanup_close_ int parent_fd = -1, next_fd = -1; _cleanup_close_ int parent_fd = -1;
_cleanup_free_ char *parent_name = NULL;
struct stat parent_st; struct stat parent_st;
const char *s, *e;
int r;
size_t path_len; size_t path_len;
int r;
assert(path); assert(path);
assert((child_mode & ~S_IFMT) == 0); assert((child_mode & ~S_IFMT) == 0);
@ -2131,19 +2129,18 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
"Trailing path separators are only allowed if child_mode is not set; got \"%s\"", path); "Trailing path separators are only allowed if child_mode is not set; got \"%s\"", path);
/* Get the parent_fd and stat. */ /* Get the parent_fd and stat. */
parent_fd = AT_FDCWD; parent_fd = openat(AT_FDCWD, path_is_absolute(path) ? "/" : ".", O_NOCTTY | O_CLOEXEC | O_DIRECTORY);
if (path_is_absolute(path)) { if (parent_fd < 0)
parent_fd = open("/", O_NOCTTY | O_CLOEXEC | O_DIRECTORY); return log_error_errno(errno, "Failed to open root: %m");
if (parent_fd < 0)
return log_error_errno(errno, "Failed to open root: %m");
}
if (fstat(parent_fd, &parent_st) < 0) if (fstat(parent_fd, &parent_st) < 0)
return log_error_errno(errno, "Failed to stat root: %m"); return log_error_errno(errno, "Failed to stat root: %m");
/* Check every parent directory in the path, except the last component */ /* Check every parent directory in the path, except the last component */
e = path; for (const char *e = path;;) {
for (;;) { _cleanup_close_ int next_fd = -1;
char t[path_len + 1]; char t[path_len + 1];
const char *s;
/* Find the start of the next path component. */ /* Find the start of the next path component. */
s = e + strspn(e, "/"); s = e + strspn(e, "/");
@ -2156,19 +2153,19 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
/* Is this the last component? If so, then check the type */ /* Is this the last component? If so, then check the type */
if (*e == 0) if (*e == 0)
return child_mode != 0 ? rm_if_wrong_type_safe(child_mode, parent_fd, &parent_st, t, AT_SYMLINK_NOFOLLOW) : 0; return child_mode != 0 ? rm_if_wrong_type_safe(child_mode, parent_fd, &parent_st, t, AT_SYMLINK_NOFOLLOW) : 0;
else {
r = rm_if_wrong_type_safe(S_IFDIR, parent_fd, &parent_st, t, 0);
/* Remove dangling symlinks. */
if (r == -ENOENT)
r = rm_if_wrong_type_safe(S_IFDIR, parent_fd, &parent_st, t, AT_SYMLINK_NOFOLLOW);
}
r = rm_if_wrong_type_safe(S_IFDIR, parent_fd, &parent_st, t, 0);
/* Remove dangling symlinks. */
if (r == -ENOENT)
r = rm_if_wrong_type_safe(S_IFDIR, parent_fd, &parent_st, t, AT_SYMLINK_NOFOLLOW);
if (r == -ENOENT) { if (r == -ENOENT) {
RUN_WITH_UMASK(0000) RUN_WITH_UMASK(0000)
r = mkdirat_label(parent_fd, t, 0755); r = mkdirat_label(parent_fd, t, 0755);
if (r < 0) { if (r < 0) {
_cleanup_free_ char *parent_name = NULL;
(void) fd_get_path(parent_fd, &parent_name); (void) fd_get_path(parent_fd, &parent_name);
return log_error_errno(r, "Failed to mkdir \"%s\" at \"%s\": %m", t, parent_name); return log_error_errno(r, "Failed to mkdir \"%s\" at \"%s\": %m", t, strnull(parent_name));
} }
} else if (r < 0) } else if (r < 0)
/* rm_if_wrong_type_safe already logs errors. */ /* rm_if_wrong_type_safe already logs errors. */
@ -2176,18 +2173,21 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
next_fd = openat(parent_fd, t, O_NOCTTY | O_CLOEXEC | O_DIRECTORY); next_fd = openat(parent_fd, t, O_NOCTTY | O_CLOEXEC | O_DIRECTORY);
if (next_fd < 0) { if (next_fd < 0) {
_cleanup_free_ char *parent_name = NULL;
r = -errno; r = -errno;
(void) fd_get_path(parent_fd, &parent_name); (void) fd_get_path(parent_fd, &parent_name);
return log_error_errno(r, "Failed to open \"%s\" at \"%s\": %m", t, parent_name); return log_error_errno(r, "Failed to open \"%s\" at \"%s\": %m", t, strnull(parent_name));
} }
if (fstat(next_fd, &parent_st) < 0) { if (fstat(next_fd, &parent_st) < 0) {
_cleanup_free_ char *parent_name = NULL;
r = -errno; r = -errno;
(void) fd_get_path(parent_fd, &parent_name); (void) fd_get_path(parent_fd, &parent_name);
return log_error_errno(r, "Failed to stat \"%s\" at \"%s\": %m", t, parent_name); return log_error_errno(r, "Failed to stat \"%s\" at \"%s\": %m", t, strnull(parent_name));
} }
safe_close(parent_fd); CLOSE_AND_REPLACE(parent_fd, next_fd);
parent_fd = TAKE_FD(next_fd);
} }
} }