networkd: fix attribute length for wireguard (#10380)

This is actually a u16, not a u32, so the kernel complains:

kernel: netlink: 'systemd-network': attribute type 5 has an invalid length

This is due to:

if (nla_attr_len[pt->type] && attrlen != nla_attr_len[pt->type]) {
        pr_warn_ratelimited("netlink: '%s': attribute type %d has an invalid length.\n",
                            current->comm, type);
}

Presumably this has been working fine in functionality on little-endian
systems, but nobody bothered to try on big-endian systems.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-10-13 10:28:49 +02:00 committed by Yu Watanabe
parent b75f0c69b3
commit 7d0b26a027
2 changed files with 2 additions and 2 deletions

View File

@ -685,7 +685,7 @@ static const NLType genl_wireguard_peer_types[] = {
[WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN },
[WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 },
[WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN },
[WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U32 },
[WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 },
[WGPEER_A_ENDPOINT] = { /* either size of sockaddr_in or sockaddr_in6 depending on address family */ },
[WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system },
};

View File

@ -107,7 +107,7 @@ static int set_wireguard_interface(NetDev *netdev) {
if (r < 0)
break;
r = sd_netlink_message_append_u32(message, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, peer->persistent_keepalive_interval);
r = sd_netlink_message_append_u16(message, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, peer->persistent_keepalive_interval);
if (r < 0)
break;