1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2018 - 2019 Red Hat, Inc.
4 */
5
6#ifndef __NM_SETTING_WIREGUARD_H__
7#define __NM_SETTING_WIREGUARD_H__
8
9#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION)
10#error "Only <NetworkManager.h> can be included directly."
11#endif
12
13#include "nm-setting.h"
14#include "nm-utils.h"
15
16G_BEGIN_DECLS
17
18/*****************************************************************************/
19
20#define NM_WIREGUARD_PUBLIC_KEY_LEN 32
21#define NM_WIREGUARD_SYMMETRIC_KEY_LEN 32
22
23/*****************************************************************************/
24
25typedef struct _NMWireGuardPeer NMWireGuardPeer;
26
27NM_AVAILABLE_IN_1_16
28GType nm_wireguard_peer_get_type(void);
29
30NM_AVAILABLE_IN_1_16
31NMWireGuardPeer *nm_wireguard_peer_new(void);
32
33NM_AVAILABLE_IN_1_16
34NMWireGuardPeer *nm_wireguard_peer_new_clone(const NMWireGuardPeer *self, gboolean with_secrets);
35
36NM_AVAILABLE_IN_1_16
37NMWireGuardPeer *nm_wireguard_peer_ref(NMWireGuardPeer *self);
38NM_AVAILABLE_IN_1_16
39void nm_wireguard_peer_unref(NMWireGuardPeer *self);
40
41NM_AVAILABLE_IN_1_16
42void nm_wireguard_peer_seal(NMWireGuardPeer *self);
43NM_AVAILABLE_IN_1_16
44gboolean nm_wireguard_peer_is_sealed(const NMWireGuardPeer *self);
45
46NM_AVAILABLE_IN_1_16
47const char *nm_wireguard_peer_get_public_key(const NMWireGuardPeer *self);
48NM_AVAILABLE_IN_1_16
49gboolean nm_wireguard_peer_set_public_key(NMWireGuardPeer *self,
50 const char *public_key,
51 gboolean accept_invalid);
52
53NM_AVAILABLE_IN_1_16
54const char *nm_wireguard_peer_get_preshared_key(const NMWireGuardPeer *self);
55NM_AVAILABLE_IN_1_16
56gboolean nm_wireguard_peer_set_preshared_key(NMWireGuardPeer *self,
57 const char *preshared_key,
58 gboolean accept_invalid);
59
60NM_AVAILABLE_IN_1_16
61NMSettingSecretFlags nm_wireguard_peer_get_preshared_key_flags(const NMWireGuardPeer *self);
62NM_AVAILABLE_IN_1_16
63void nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer *self,
64 NMSettingSecretFlags preshared_key_flags);
65
66NM_AVAILABLE_IN_1_16
67guint16 nm_wireguard_peer_get_persistent_keepalive(const NMWireGuardPeer *self);
68NM_AVAILABLE_IN_1_16
69void nm_wireguard_peer_set_persistent_keepalive(NMWireGuardPeer *self,
70 guint16 persistent_keepalive);
71
72NM_AVAILABLE_IN_1_16
73const char *nm_wireguard_peer_get_endpoint(const NMWireGuardPeer *self);
74NM_AVAILABLE_IN_1_16
75gboolean
76nm_wireguard_peer_set_endpoint(NMWireGuardPeer *self, const char *endpoint, gboolean allow_invalid);
77
78NM_AVAILABLE_IN_1_16
79guint nm_wireguard_peer_get_allowed_ips_len(const NMWireGuardPeer *self);
80NM_AVAILABLE_IN_1_16
81const char *
82nm_wireguard_peer_get_allowed_ip(const NMWireGuardPeer *self, guint idx, gboolean *out_is_valid);
83NM_AVAILABLE_IN_1_16
84void nm_wireguard_peer_clear_allowed_ips(NMWireGuardPeer *self);
85NM_AVAILABLE_IN_1_16
86gboolean nm_wireguard_peer_append_allowed_ip(NMWireGuardPeer *self,
87 const char *allowed_ip,
88 gboolean accept_invalid);
89NM_AVAILABLE_IN_1_16
90gboolean nm_wireguard_peer_remove_allowed_ip(NMWireGuardPeer *self, guint idx);
91
92NM_AVAILABLE_IN_1_16
93gboolean nm_wireguard_peer_is_valid(const NMWireGuardPeer *self,
94 gboolean check_non_secrets,
95 gboolean check_secrets,
96 GError **error);
97
98NM_AVAILABLE_IN_1_16
99int nm_wireguard_peer_cmp(const NMWireGuardPeer *a,
100 const NMWireGuardPeer *b,
101 NMSettingCompareFlags compare_flags);
102
103/*****************************************************************************/
104
105#define NM_TYPE_SETTING_WIREGUARD (nm_setting_wireguard_get_type())
106#define NM_SETTING_WIREGUARD(obj) \
107 (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_SETTING_WIREGUARD, NMSettingWireGuard))
108#define NM_SETTING_WIREGUARD_CLASS(klass) \
109 (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_SETTING_WIREGUARD, NMSettingWireGuardClass))
110#define NM_IS_SETTING_WIREGUARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_SETTING_WIREGUARD))
111#define NM_IS_SETTING_WIREGUARD_CLASS(klass) \
112 (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_SETTING_WIREGUARD))
113#define NM_SETTING_WIREGUARD_GET_CLASS(obj) \
114 (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SETTING_WIREGUARD, NMSettingWireGuardClass))
115
116#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard"
117
118#define NM_SETTING_WIREGUARD_FWMARK "fwmark"
119#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port"
120#define NM_SETTING_WIREGUARD_PRIVATE_KEY "private-key"
121#define NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS "private-key-flags"
122
123#define NM_SETTING_WIREGUARD_PEERS "peers"
124
125#define NM_SETTING_WIREGUARD_MTU "mtu"
126#define NM_SETTING_WIREGUARD_PEER_ROUTES "peer-routes"
127#define NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE "ip4-auto-default-route"
128#define NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE "ip6-auto-default-route"
129
130#define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips"
131#define NM_WIREGUARD_PEER_ATTR_ENDPOINT "endpoint"
132#define NM_WIREGUARD_PEER_ATTR_PERSISTENT_KEEPALIVE "persistent-keepalive"
133#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY "preshared-key"
134#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS "preshared-key-flags"
135#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key"
136
137/*****************************************************************************/
138
139typedef struct _NMSettingWireGuardClass NMSettingWireGuardClass;
140
141NM_AVAILABLE_IN_1_16
142GType nm_setting_wireguard_get_type(void);
143
144NM_AVAILABLE_IN_1_16
145NMSetting *nm_setting_wireguard_new(void);
146
147/*****************************************************************************/
148
149NM_AVAILABLE_IN_1_16
150const char *nm_setting_wireguard_get_private_key(NMSettingWireGuard *self);
151
152NM_AVAILABLE_IN_1_16
153NMSettingSecretFlags nm_setting_wireguard_get_private_key_flags(NMSettingWireGuard *self);
154
155NM_AVAILABLE_IN_1_16
156guint16 nm_setting_wireguard_get_listen_port(NMSettingWireGuard *self);
157
158NM_AVAILABLE_IN_1_16
159guint32 nm_setting_wireguard_get_fwmark(NMSettingWireGuard *self);
160
161/*****************************************************************************/
162
163NM_AVAILABLE_IN_1_16
164guint nm_setting_wireguard_get_peers_len(NMSettingWireGuard *self);
165
166NM_AVAILABLE_IN_1_16
167NMWireGuardPeer *nm_setting_wireguard_get_peer(NMSettingWireGuard *self, guint idx);
168
169NM_AVAILABLE_IN_1_16
170NMWireGuardPeer *nm_setting_wireguard_get_peer_by_public_key(NMSettingWireGuard *self,
171 const char *public_key,
172 guint *out_idx);
173
174NM_AVAILABLE_IN_1_16
175void nm_setting_wireguard_set_peer(NMSettingWireGuard *self, NMWireGuardPeer *peer, guint idx);
176
177NM_AVAILABLE_IN_1_16
178void nm_setting_wireguard_append_peer(NMSettingWireGuard *self, NMWireGuardPeer *peer);
179
180NM_AVAILABLE_IN_1_16
181gboolean nm_setting_wireguard_remove_peer(NMSettingWireGuard *self, guint idx);
182
183NM_AVAILABLE_IN_1_16
184guint nm_setting_wireguard_clear_peers(NMSettingWireGuard *self);
185
186NM_AVAILABLE_IN_1_16
187gboolean nm_setting_wireguard_get_peer_routes(NMSettingWireGuard *self);
188
189NM_AVAILABLE_IN_1_16
190guint32 nm_setting_wireguard_get_mtu(NMSettingWireGuard *self);
191
192NM_AVAILABLE_IN_1_20
193NMTernary nm_setting_wireguard_get_ip4_auto_default_route(NMSettingWireGuard *self);
194
195NM_AVAILABLE_IN_1_20
196NMTernary nm_setting_wireguard_get_ip6_auto_default_route(NMSettingWireGuard *self);
197
198/*****************************************************************************/
199
200G_END_DECLS
201
202#endif /* __NM_SETTING_WIREGUARD_H__ */
203

source code of include/libnm/nm-setting-wireguard.h