60ee6d4d7c23262cd391afeb288cb76e0443ca99
[NetworkManager.git] / libnm-core / nm-core-internal.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /*
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301 USA.
18  *
19  * (C) Copyright 2014 Red Hat, Inc.
20  */
21
22 #ifndef NM_CORE_NM_INTERNAL_H
23 #define NM_CORE_NM_INTERNAL_H
24
25 /* This header file contain functions that are provided as private API
26  * by libnm-core. It will contain functions to give privileged access to
27  * libnm-core. This can be useful for NetworkManager and libnm.so
28  * which both are special users of libnm-core.
29  * It also exposes some utility functions for reuse.
30  *
31  * These functions are not exported and are only available to components that link
32  * statically against libnm-core. This basically means libnm-core, libnm, NetworkManager
33  * and some test programs.
34  **/
35
36
37 #include "nm-default.h"
38 #include "nm-connection.h"
39 #include "nm-core-enum-types.h"
40 #include "nm-setting-8021x.h"
41 #include "nm-setting-adsl.h"
42 #include "nm-setting-bluetooth.h"
43 #include "nm-setting-bond.h"
44 #include "nm-setting-bridge-port.h"
45 #include "nm-setting-bridge.h"
46 #include "nm-setting-cdma.h"
47 #include "nm-setting-connection.h"
48 #include "nm-setting-dcb.h"
49 #include "nm-setting-generic.h"
50 #include "nm-setting-gsm.h"
51 #include "nm-setting-infiniband.h"
52 #include "nm-setting-ip-tunnel.h"
53 #include "nm-setting-ip4-config.h"
54 #include "nm-setting-ip6-config.h"
55 #include "nm-setting-macvlan.h"
56 #include "nm-setting-olpc-mesh.h"
57 #include "nm-setting-ppp.h"
58 #include "nm-setting-pppoe.h"
59 #include "nm-setting-serial.h"
60 #include "nm-setting-team-port.h"
61 #include "nm-setting-team.h"
62 #include "nm-setting-tun.h"
63 #include "nm-setting-vlan.h"
64 #include "nm-setting-vpn.h"
65 #include "nm-setting-vxlan.h"
66 #include "nm-setting-wimax.h"
67 #include "nm-setting-wired.h"
68 #include "nm-setting-wireless-security.h"
69 #include "nm-setting-wireless.h"
70 #include "nm-setting.h"
71 #include "nm-simple-connection.h"
72 #include "nm-utils.h"
73 #include "nm-vpn-dbus-interface.h"
74 #include "nm-core-types-internal.h"
75
76 /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
77  * connection can be replaced by a already-defined connection. This flag only
78  * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
79  * flag.
80  */
81 #define NM_SETTING_COMPARE_FLAG_INFERRABLE ((NMSettingCompareFlags) 0x80000000)
82
83 /* NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY: this flag is used for properties
84  * that automatically get re-applied on an active connection when the settings
85  * connection is modified. For most properties, the applied-connection is distinct
86  * from the setting-connection and changes don't propagate. Exceptions are the
87  * firewall-zone and the metered property.
88  */
89 #define NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY ((NMSettingCompareFlags) 0x40000000)
90
91 /* NM_SETTING_COMPARE_FLAG_NONE: for convenience, define a special flag NONE -- which
92  * equals to numeric zero (NM_SETTING_COMPARE_FLAG_EXACT).
93  */
94 #define NM_SETTING_COMPARE_FLAG_NONE ((NMSettingCompareFlags) 0)
95
96
97 #define NM_SETTING_SECRET_FLAGS_ALL \
98         (NM_SETTING_SECRET_FLAG_NONE | \
99          NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
100          NM_SETTING_SECRET_FLAG_NOT_SAVED | \
101          NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
102
103 typedef enum { /*< skip >*/
104         NM_SETTING_PARSE_FLAGS_NONE                     = 0,
105         NM_SETTING_PARSE_FLAGS_STRICT                   = 1LL << 0,
106         NM_SETTING_PARSE_FLAGS_BEST_EFFORT              = 1LL << 1,
107         NM_SETTING_PARSE_FLAGS_NORMALIZE                = 1LL << 2,
108
109         _NM_SETTING_PARSE_FLAGS_LAST,
110         NM_SETTING_PARSE_FLAGS_ALL                      = ((_NM_SETTING_PARSE_FLAGS_LAST - 1) << 1) - 1,
111 } NMSettingParseFlags;
112
113 gboolean _nm_connection_replace_settings (NMConnection *connection,
114                                           GVariant *new_settings,
115                                           NMSettingParseFlags parse_flags,
116                                           GError **error);
117
118 NMConnection *_nm_simple_connection_new_from_dbus (GVariant      *dict,
119                                                    NMSettingParseFlags parse_flags,
120                                                    GError       **error);
121
122 guint32 _nm_setting_get_setting_priority (NMSetting *setting);
123
124 gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
125
126 GSList *    _nm_utils_hash_values_to_slist (GHashTable *hash);
127
128 GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);
129
130 typedef gpointer (*NMUtilsCopyFunc) (gpointer);
131
132 GPtrArray *_nm_utils_copy_slist_to_array (const GSList *list,
133                                           NMUtilsCopyFunc copy_func,
134                                           GDestroyNotify unref_func);
135 GSList    *_nm_utils_copy_array_to_slist (const GPtrArray *array,
136                                           NMUtilsCopyFunc copy_func);
137
138 GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
139                                  NMUtilsCopyFunc copy_func,
140                                  GDestroyNotify free_func);
141 GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
142
143 gssize _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle);
144
145 gssize _nm_utils_ptrarray_find_binary_search (gpointer *list, gsize len, gpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
146
147 gboolean    _nm_utils_string_in_list   (const char *str,
148                                         const char **valid_strings);
149
150 gssize      _nm_utils_strv_find_first (char **list, gssize len, const char *needle);
151
152 char **_nm_utils_strv_cleanup (char **strv,
153                                gboolean strip_whitespace,
154                                gboolean skip_empty,
155                                gboolean skip_repeated);
156
157 char **     _nm_utils_strsplit_set (const char *str,
158                                     const char *delimiters,
159                                     int max_tokens);
160
161 GSList *    _nm_utils_strv_to_slist (char **strv, gboolean deep_copy);
162 char **     _nm_utils_slist_to_strv (GSList *slist, gboolean deep_copy);
163
164 GPtrArray * _nm_utils_strv_to_ptrarray (char **strv);
165 char **     _nm_utils_ptrarray_to_strv (GPtrArray *ptrarray);
166 gboolean    _nm_utils_strv_equal (char **strv1, char **strv2);
167
168 gboolean _nm_utils_check_file (const char *filename,
169                                gint64 check_owner,
170                                NMUtilsCheckFilePredicate check_file,
171                                gpointer user_data,
172                                struct stat *out_st,
173                                GError **error);
174
175 gboolean _nm_utils_check_module_file (const char *name,
176                                       int check_owner,
177                                       NMUtilsCheckFilePredicate check_file,
178                                       gpointer user_data,
179                                       GError **error);
180
181 #define NM_UTILS_UUID_TYPE_LEGACY            0
182 #define NM_UTILS_UUID_TYPE_VARIANT3          1
183
184 char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_type, gpointer type_args);
185
186 /* arbitrarily choosen namespace UUID for _nm_utils_uuid_generate_from_strings() */
187 #define NM_UTILS_UUID_NS "b425e9fb-7598-44b4-9e3b-5a2e3aaa4905"
188
189 char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED;
190
191 void _nm_dbus_errors_init (void);
192
193 extern gboolean _nm_utils_is_manager_process;
194
195 GByteArray *nm_utils_rsa_key_encrypt (const guint8 *data,
196                                       gsize len,
197                                       const char *in_password,
198                                       char **out_password,
199                                       GError **error);
200
201 gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
202                                      const char *signal_name,
203                                      const GVariantType *signature,
204                                      GCallback c_handler,
205                                      gpointer data,
206                                      GClosureNotify destroy_data,
207                                      GConnectFlags connect_flags);
208 #define _nm_dbus_signal_connect(proxy, name, signature, handler, data) \
209         _nm_dbus_signal_connect_data (proxy, name, signature, handler, data, NULL, (GConnectFlags) 0)
210
211 GVariant *_nm_dbus_proxy_call_finish (GDBusProxy           *proxy,
212                                       GAsyncResult         *res,
213                                       const GVariantType   *reply_type,
214                                       GError              **error);
215
216 GVariant *_nm_dbus_proxy_call_sync   (GDBusProxy           *proxy,
217                                       const gchar          *method_name,
218                                       GVariant             *parameters,
219                                       const GVariantType   *reply_type,
220                                       GDBusCallFlags        flags,
221                                       gint                  timeout_msec,
222                                       GCancellable         *cancellable,
223                                       GError              **error);
224
225 gboolean _nm_dbus_error_has_name (GError     *error,
226                                   const char *dbus_error_name);
227
228 /***********************************************************/
229
230 gboolean _nm_vpn_plugin_info_check_file (const char *filename,
231                                          gboolean check_absolute,
232                                          gboolean do_validate_filename,
233                                          gint64 check_owner,
234                                          NMUtilsCheckFilePredicate check_file,
235                                          gpointer user_data,
236                                          GError **error);
237
238 const char *_nm_vpn_plugin_info_get_default_dir_etc (void);
239 const char *_nm_vpn_plugin_info_get_default_dir_lib (void);
240 const char *_nm_vpn_plugin_info_get_default_dir_user (void);
241
242 GSList *_nm_vpn_plugin_info_list_load_dir (const char *dirname,
243                                            gboolean do_validate_filename,
244                                            gint64 check_owner,
245                                            NMUtilsCheckFilePredicate check_file,
246                                            gpointer user_data);
247
248 /***********************************************************/
249
250 typedef struct {
251         const char *name;
252         gboolean numeric;
253         gboolean ipv6_only;
254 } NMUtilsDNSOptionDesc;
255
256 extern const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[];
257
258 gboolean    _nm_utils_dns_option_validate (const char *option, char **out_name,
259                                            long *out_value, gboolean ipv6,
260                                            const NMUtilsDNSOptionDesc *option_descs);
261 int         _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option);
262
263 /***********************************************************/
264
265 typedef struct _NMUtilsStrStrDictKey NMUtilsStrStrDictKey;
266 guint                 _nm_utils_strstrdictkey_hash   (gconstpointer a);
267 gboolean              _nm_utils_strstrdictkey_equal  (gconstpointer a, gconstpointer b);
268 NMUtilsStrStrDictKey *_nm_utils_strstrdictkey_create (const char *v1, const char *v2);
269
270 #define _nm_utils_strstrdictkey_static(v1, v2) \
271     ( (NMUtilsStrStrDictKey *) ("\03" v1 "\0" v2 "") )
272
273 /***********************************************************/
274
275 gboolean _nm_setting_vlan_set_priorities (NMSettingVlan *setting,
276                                           NMVlanPriorityMap map,
277                                           const NMVlanQosMapping *qos_map,
278                                           guint n_qos_map);
279 void     _nm_setting_vlan_get_priorities (NMSettingVlan *setting,
280                                           NMVlanPriorityMap map,
281                                           NMVlanQosMapping **out_qos_map,
282                                           guint *out_n_qos_map);
283
284 /***********************************************************/
285
286 typedef enum {
287         NM_BOND_OPTION_TYPE_INT,
288         NM_BOND_OPTION_TYPE_STRING,
289         NM_BOND_OPTION_TYPE_BOTH,
290         NM_BOND_OPTION_TYPE_IP,
291         NM_BOND_OPTION_TYPE_IFNAME,
292 } NMBondOptionType;
293
294 NMBondOptionType
295 _nm_setting_bond_get_option_type (NMSettingBond *setting, const char *name);
296
297 #endif