diff options
author | Thomas Haller <thaller@redhat.com> | 2019-02-11 10:57:35 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-14 08:00:29 +0100 |
commit | 1e1b03c08943b847c4b70830258aba1d597fdc07 (patch) | |
tree | de0b93afb80fe73181bcbe815ecd519e6a950ff9 | |
parent | 2ed01e2e34f8f71da74b36bdb9bb772ca0fe8456 (diff) | |
download | NetworkManager-1e1b03c08943b847c4b70830258aba1d597fdc07.tar.gz |
platform: add flags for setting individual WireGuard options of link
-rw-r--r-- | src/platform/nm-linux-platform.c | 22 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 17 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 3 | ||||
-rw-r--r-- | src/platform/tests/test-link.c | 5 |
4 files changed, 32 insertions, 15 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 9da61aa868..72b7cf985b 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2418,15 +2418,19 @@ again: NLA_PUT_U32 (msg, WGDEVICE_A_IFINDEX, (guint32) ifindex); if (idx_peer_curr == IDX_NIL) { - NLA_PUT (msg, WGDEVICE_A_PRIVATE_KEY, sizeof (lnk_wireguard->private_key), lnk_wireguard->private_key); - NLA_PUT_U16 (msg, WGDEVICE_A_LISTEN_PORT, lnk_wireguard->listen_port); - NLA_PUT_U32 (msg, WGDEVICE_A_FWMARK, lnk_wireguard->fwmark); - - NLA_PUT_U32 (msg, - WGDEVICE_A_FLAGS, - NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS) - ? WGDEVICE_F_REPLACE_PEERS - : ((guint32) 0u)); + guint32 flags; + + if (NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_PRIVATE_KEY)) + NLA_PUT (msg, WGDEVICE_A_PRIVATE_KEY, sizeof (lnk_wireguard->private_key), lnk_wireguard->private_key); + if (NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_LISTEN_PORT)) + NLA_PUT_U16 (msg, WGDEVICE_A_LISTEN_PORT, lnk_wireguard->listen_port); + if (NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_FWMARK)) + NLA_PUT_U32 (msg, WGDEVICE_A_FWMARK, lnk_wireguard->fwmark); + + flags = 0; + if (NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS)) + flags |= WGDEVICE_F_REPLACE_PEERS; + NLA_PUT_U32 (msg, WGDEVICE_A_FLAGS, flags); } if (peers_len == 0) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index a915f97ed2..efa30599da 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1982,6 +1982,14 @@ nm_platform_link_get_lnk_wireguard (NMPlatform *self, int ifindex, const NMPlatf /*****************************************************************************/ +NM_UTILS_FLAGS2STR_DEFINE_STATIC (_wireguard_change_flags_to_string, NMPlatformWireGuardChangeFlags, + NM_UTILS_FLAGS2STR (NM_PLATFORM_WIREGUARD_CHANGE_FLAG_NONE, "none"), + NM_UTILS_FLAGS2STR (NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS, "replace-peers"), + NM_UTILS_FLAGS2STR (NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_PRIVATE_KEY, "has-private-key"), + NM_UTILS_FLAGS2STR (NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_LISTEN_PORT, "has-listen-port"), + NM_UTILS_FLAGS2STR (NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_FWMARK, "has-fwmark"), +); + int nm_platform_link_wireguard_add (NMPlatform *self, const char *name, @@ -2005,6 +2013,7 @@ nm_platform_link_wireguard_change (NMPlatform *self, if (_LOGD_ENABLED ()) { char buf_lnk[256]; char buf_peers[512]; + char buf_change_flags[100]; buf_peers[0] = '\0'; if (peers_len > 0) { @@ -2022,14 +2031,12 @@ nm_platform_link_wireguard_change (NMPlatform *self, nm_utils_strbuf_append_str (&b, &len, "}"); } - _LOG3D ("link: change wireguard ifindex %d, %s, %u peers%s%s", + _LOG3D ("link: change wireguard ifindex %d, %s, (%s), %u peers%s", ifindex, nm_platform_lnk_wireguard_to_string (lnk_wireguard, buf_lnk, sizeof (buf_lnk)), + _wireguard_change_flags_to_string (change_flags, buf_change_flags, sizeof (buf_change_flags)), peers_len, - buf_peers, - NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS) - ? " (replace-peers)" - : " (update-peers)"); + buf_peers); } return klass->link_wireguard_change (self, diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 2fa9329ba3..69f656215b 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -756,6 +756,9 @@ typedef enum { typedef enum { NM_PLATFORM_WIREGUARD_CHANGE_FLAG_NONE = 0, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS = (1LL << 0), + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_PRIVATE_KEY = (1LL << 1), + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_LISTEN_PORT = (1LL << 2), + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_FWMARK = (1LL << 3), } NMPlatformWireGuardChangeFlags; /*****************************************************************************/ diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 65291bc323..45156f9864 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -913,7 +913,10 @@ _test_wireguard_change (NMPlatform *platform, &lnk_wireguard, (const NMPWireGuardPeer *) peers->data, peers->len, - NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS); + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_PRIVATE_KEY + | NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_LISTEN_PORT + | NM_PLATFORM_WIREGUARD_CHANGE_FLAG_HAS_FWMARK + | NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS); g_assert (NMTST_NM_ERR_SUCCESS (r)); } |