From 2ed01e2e34f8f71da74b36bdb9bb772ca0fe8456 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Feb 2019 15:22:26 +0100 Subject: [PATCH] platform: add change-flags argument to platform's link_wireguard_change() We will need more flags. WireGuard internal tools solve this by embedding the change flags inside the structure that corresponds to NMPlatformLnkWireGuard. We don't do that, NMPlatformLnkWireGuard is only for containing the information about the link. --- src/platform/nm-linux-platform.c | 13 ++++++++----- src/platform/nm-platform.c | 8 +++++--- src/platform/nm-platform.h | 9 +++++++-- src/platform/tests/test-link.c | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index ce96c18426..9da61aa868 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2372,7 +2372,7 @@ _wireguard_create_change_nlmsgs (NMPlatform *platform, const NMPlatformLnkWireGuard *lnk_wireguard, const NMPWireGuardPeer *peers, guint peers_len, - gboolean replace_peers, + NMPlatformWireGuardChangeFlags change_flags, GPtrArray **out_msgs) { gs_unref_ptrarray GPtrArray *msgs = NULL; @@ -2422,8 +2422,11 @@ again: 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, - replace_peers ? WGDEVICE_F_REPLACE_PEERS : ((guint32) 0u)); + 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)); } if (peers_len == 0) @@ -2554,7 +2557,7 @@ link_wireguard_change (NMPlatform *platform, const NMPlatformLnkWireGuard *lnk_wireguard, const NMPWireGuardPeer *peers, guint peers_len, - gboolean replace_peers) + NMPlatformWireGuardChangeFlags change_flags) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); gs_unref_ptrarray GPtrArray *msgs = NULL; @@ -2572,7 +2575,7 @@ link_wireguard_change (NMPlatform *platform, lnk_wireguard, peers, peers_len, - replace_peers, + change_flags, &msgs); if (r < 0) { _LOGW ("wireguard: set-device, cannot construct netlink message: %s", nm_strerror (r)); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 021b45d73e..a915f97ed2 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1996,7 +1996,7 @@ nm_platform_link_wireguard_change (NMPlatform *self, const NMPlatformLnkWireGuard *lnk_wireguard, const NMPWireGuardPeer *peers, guint peers_len, - gboolean replace_peers) + NMPlatformWireGuardChangeFlags change_flags) { _CHECK_SELF (self, klass, -NME_BUG); @@ -2027,7 +2027,9 @@ nm_platform_link_wireguard_change (NMPlatform *self, nm_platform_lnk_wireguard_to_string (lnk_wireguard, buf_lnk, sizeof (buf_lnk)), peers_len, buf_peers, - replace_peers ? " (replace-peers)" : " (update-peers)"); + NM_FLAGS_HAS (change_flags, NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS) + ? " (replace-peers)" + : " (update-peers)"); } return klass->link_wireguard_change (self, @@ -2035,7 +2037,7 @@ nm_platform_link_wireguard_change (NMPlatform *self, lnk_wireguard, peers, peers_len, - replace_peers); + change_flags); } /*****************************************************************************/ diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 568b1f4b46..2fa9329ba3 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -753,6 +753,11 @@ typedef enum { NM_PLATFORM_KERNEL_SUPPORT_RTA_PREF = (1LL << 2), } NMPlatformKernelSupportFlags; +typedef enum { + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_NONE = 0, + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS = (1LL << 0), +} NMPlatformWireGuardChangeFlags; + /*****************************************************************************/ struct _NMPlatformPrivate; @@ -831,7 +836,7 @@ typedef struct { const NMPlatformLnkWireGuard *lnk_wireguard, const struct _NMPWireGuardPeer *peers, guint peers_len, - gboolean replace_peers); + NMPlatformWireGuardChangeFlags change_flags); gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link); gboolean (*link_vlan_change) (NMPlatform *self, @@ -1394,7 +1399,7 @@ int nm_platform_link_wireguard_change (NMPlatform *self, const NMPlatformLnkWireGuard *lnk_wireguard, const struct _NMPWireGuardPeer *peers, guint peers_len, - gboolean replace_peers); + NMPlatformWireGuardChangeFlags change_flags); const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index e11858d634..65291bc323 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -913,7 +913,7 @@ _test_wireguard_change (NMPlatform *platform, &lnk_wireguard, (const NMPWireGuardPeer *) peers->data, peers->len, - TRUE); + NM_PLATFORM_WIREGUARD_CHANGE_FLAG_REPLACE_PEERS); g_assert (NMTST_NM_ERR_SUCCESS (r)); }