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 | |
16 | G_BEGIN_DECLS |
17 | |
18 | /*****************************************************************************/ |
19 | |
20 | #define NM_WIREGUARD_PUBLIC_KEY_LEN 32 |
21 | #define NM_WIREGUARD_SYMMETRIC_KEY_LEN 32 |
22 | |
23 | /*****************************************************************************/ |
24 | |
25 | typedef struct _NMWireGuardPeer NMWireGuardPeer; |
26 | |
27 | NM_AVAILABLE_IN_1_16 |
28 | GType nm_wireguard_peer_get_type(void); |
29 | |
30 | NM_AVAILABLE_IN_1_16 |
31 | NMWireGuardPeer *nm_wireguard_peer_new(void); |
32 | |
33 | NM_AVAILABLE_IN_1_16 |
34 | NMWireGuardPeer *nm_wireguard_peer_new_clone(const NMWireGuardPeer *self, gboolean with_secrets); |
35 | |
36 | NM_AVAILABLE_IN_1_16 |
37 | NMWireGuardPeer *nm_wireguard_peer_ref(NMWireGuardPeer *self); |
38 | NM_AVAILABLE_IN_1_16 |
39 | void nm_wireguard_peer_unref(NMWireGuardPeer *self); |
40 | |
41 | NM_AVAILABLE_IN_1_16 |
42 | void nm_wireguard_peer_seal(NMWireGuardPeer *self); |
43 | NM_AVAILABLE_IN_1_16 |
44 | gboolean nm_wireguard_peer_is_sealed(const NMWireGuardPeer *self); |
45 | |
46 | NM_AVAILABLE_IN_1_16 |
47 | const char *nm_wireguard_peer_get_public_key(const NMWireGuardPeer *self); |
48 | NM_AVAILABLE_IN_1_16 |
49 | gboolean nm_wireguard_peer_set_public_key(NMWireGuardPeer *self, |
50 | const char *public_key, |
51 | gboolean accept_invalid); |
52 | |
53 | NM_AVAILABLE_IN_1_16 |
54 | const char *nm_wireguard_peer_get_preshared_key(const NMWireGuardPeer *self); |
55 | NM_AVAILABLE_IN_1_16 |
56 | gboolean nm_wireguard_peer_set_preshared_key(NMWireGuardPeer *self, |
57 | const char *preshared_key, |
58 | gboolean accept_invalid); |
59 | |
60 | NM_AVAILABLE_IN_1_16 |
61 | NMSettingSecretFlags nm_wireguard_peer_get_preshared_key_flags(const NMWireGuardPeer *self); |
62 | NM_AVAILABLE_IN_1_16 |
63 | void nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer *self, |
64 | NMSettingSecretFlags preshared_key_flags); |
65 | |
66 | NM_AVAILABLE_IN_1_16 |
67 | guint16 nm_wireguard_peer_get_persistent_keepalive(const NMWireGuardPeer *self); |
68 | NM_AVAILABLE_IN_1_16 |
69 | void nm_wireguard_peer_set_persistent_keepalive(NMWireGuardPeer *self, |
70 | guint16 persistent_keepalive); |
71 | |
72 | NM_AVAILABLE_IN_1_16 |
73 | const char *nm_wireguard_peer_get_endpoint(const NMWireGuardPeer *self); |
74 | NM_AVAILABLE_IN_1_16 |
75 | gboolean |
76 | nm_wireguard_peer_set_endpoint(NMWireGuardPeer *self, const char *endpoint, gboolean allow_invalid); |
77 | |
78 | NM_AVAILABLE_IN_1_16 |
79 | guint nm_wireguard_peer_get_allowed_ips_len(const NMWireGuardPeer *self); |
80 | NM_AVAILABLE_IN_1_16 |
81 | const char * |
82 | nm_wireguard_peer_get_allowed_ip(const NMWireGuardPeer *self, guint idx, gboolean *out_is_valid); |
83 | NM_AVAILABLE_IN_1_16 |
84 | void nm_wireguard_peer_clear_allowed_ips(NMWireGuardPeer *self); |
85 | NM_AVAILABLE_IN_1_16 |
86 | gboolean nm_wireguard_peer_append_allowed_ip(NMWireGuardPeer *self, |
87 | const char *allowed_ip, |
88 | gboolean accept_invalid); |
89 | NM_AVAILABLE_IN_1_16 |
90 | gboolean nm_wireguard_peer_remove_allowed_ip(NMWireGuardPeer *self, guint idx); |
91 | |
92 | NM_AVAILABLE_IN_1_16 |
93 | gboolean nm_wireguard_peer_is_valid(const NMWireGuardPeer *self, |
94 | gboolean check_non_secrets, |
95 | gboolean check_secrets, |
96 | GError **error); |
97 | |
98 | NM_AVAILABLE_IN_1_16 |
99 | int 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 | |
139 | typedef struct _NMSettingWireGuardClass NMSettingWireGuardClass; |
140 | |
141 | NM_AVAILABLE_IN_1_16 |
142 | GType nm_setting_wireguard_get_type(void); |
143 | |
144 | NM_AVAILABLE_IN_1_16 |
145 | NMSetting *nm_setting_wireguard_new(void); |
146 | |
147 | /*****************************************************************************/ |
148 | |
149 | NM_AVAILABLE_IN_1_16 |
150 | const char *nm_setting_wireguard_get_private_key(NMSettingWireGuard *self); |
151 | |
152 | NM_AVAILABLE_IN_1_16 |
153 | NMSettingSecretFlags nm_setting_wireguard_get_private_key_flags(NMSettingWireGuard *self); |
154 | |
155 | NM_AVAILABLE_IN_1_16 |
156 | guint16 nm_setting_wireguard_get_listen_port(NMSettingWireGuard *self); |
157 | |
158 | NM_AVAILABLE_IN_1_16 |
159 | guint32 nm_setting_wireguard_get_fwmark(NMSettingWireGuard *self); |
160 | |
161 | /*****************************************************************************/ |
162 | |
163 | NM_AVAILABLE_IN_1_16 |
164 | guint nm_setting_wireguard_get_peers_len(NMSettingWireGuard *self); |
165 | |
166 | NM_AVAILABLE_IN_1_16 |
167 | NMWireGuardPeer *nm_setting_wireguard_get_peer(NMSettingWireGuard *self, guint idx); |
168 | |
169 | NM_AVAILABLE_IN_1_16 |
170 | NMWireGuardPeer *nm_setting_wireguard_get_peer_by_public_key(NMSettingWireGuard *self, |
171 | const char *public_key, |
172 | guint *out_idx); |
173 | |
174 | NM_AVAILABLE_IN_1_16 |
175 | void nm_setting_wireguard_set_peer(NMSettingWireGuard *self, NMWireGuardPeer *peer, guint idx); |
176 | |
177 | NM_AVAILABLE_IN_1_16 |
178 | void nm_setting_wireguard_append_peer(NMSettingWireGuard *self, NMWireGuardPeer *peer); |
179 | |
180 | NM_AVAILABLE_IN_1_16 |
181 | gboolean nm_setting_wireguard_remove_peer(NMSettingWireGuard *self, guint idx); |
182 | |
183 | NM_AVAILABLE_IN_1_16 |
184 | guint nm_setting_wireguard_clear_peers(NMSettingWireGuard *self); |
185 | |
186 | NM_AVAILABLE_IN_1_16 |
187 | gboolean nm_setting_wireguard_get_peer_routes(NMSettingWireGuard *self); |
188 | |
189 | NM_AVAILABLE_IN_1_16 |
190 | guint32 nm_setting_wireguard_get_mtu(NMSettingWireGuard *self); |
191 | |
192 | NM_AVAILABLE_IN_1_20 |
193 | NMTernary nm_setting_wireguard_get_ip4_auto_default_route(NMSettingWireGuard *self); |
194 | |
195 | NM_AVAILABLE_IN_1_20 |
196 | NMTernary nm_setting_wireguard_get_ip6_auto_default_route(NMSettingWireGuard *self); |
197 | |
198 | /*****************************************************************************/ |
199 | |
200 | G_END_DECLS |
201 | |
202 | #endif /* __NM_SETTING_WIREGUARD_H__ */ |
203 | |