device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-util / nm-connection.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  * Copyright 2007 - 2013 Red Hat, Inc.
20  * Copyright 2007 - 2008 Novell, Inc.
21  */
22
23 #ifndef NM_CONNECTION_H
24 #define NM_CONNECTION_H
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <nm-setting.h>
29
30 #include <nm-setting-8021x.h>
31 #include <nm-setting-bluetooth.h>
32 #include <nm-setting-bond.h>
33 #include <nm-setting-team.h>
34 #include <nm-setting-team-port.h>
35 #include <nm-setting-bridge.h>
36 #include <nm-setting-bridge-port.h>
37 #include <nm-setting-cdma.h>
38 #include <nm-setting-connection.h>
39 #include <nm-setting-dcb.h>
40 #include <nm-setting-generic.h>
41 #include <nm-setting-gsm.h>
42 #include <nm-setting-infiniband.h>
43 #include <nm-setting-ip4-config.h>
44 #include <nm-setting-ip6-config.h>
45 #include <nm-setting-olpc-mesh.h>
46 #include <nm-setting-ppp.h>
47 #include <nm-setting-pppoe.h>
48 #include <nm-setting-serial.h>
49 #include <nm-setting-vpn.h>
50 #include <nm-setting-wimax.h>
51 #include <nm-setting-wired.h>
52 #include <nm-setting-adsl.h>
53 #include <nm-setting-wireless.h>
54 #include <nm-setting-wireless-security.h>
55 #include <nm-setting-vlan.h>
56
57 G_BEGIN_DECLS
58
59 #define NM_TYPE_CONNECTION            (nm_connection_get_type ())
60 #define NM_CONNECTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION, NMConnection))
61 #define NM_CONNECTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONNECTION, NMConnectionClass))
62 #define NM_IS_CONNECTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION))
63 #define NM_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CONNECTION))
64 #define NM_CONNECTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONNECTION, NMConnectionClass))
65
66 /* Signals */
67 #define NM_CONNECTION_SECRETS_UPDATED "secrets-updated"
68 #define NM_CONNECTION_SECRETS_CLEARED "secrets-cleared"
69 #define NM_CONNECTION_CHANGED         "changed"
70
71 /* Properties */
72 #define NM_CONNECTION_PATH "path"
73
74 /**
75  * NMConnectionError:
76  * @NM_CONNECTION_ERROR_UNKNOWN: unknown or unclassified error
77  * @NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND: the #NMConnection object
78  *   did not contain the required #NMSettingConnection object, which must be
79  *   present for all connections
80  * @NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID: the 'type' property of the
81  *   'connection' setting did not point to a valid connection base type; ie
82  *   it was not a hardware-related setting like #NMSettingWired or
83  *   #NMSettingWireless.
84  * @NM_CONNECTION_ERROR_SETTING_NOT_FOUND: the #NMConnection object
85  *   did not contain the specified #NMSetting object
86  *@NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains
87  *   a conflicting setting object
88  *
89  * Describes errors that may result from operations involving a #NMConnection.
90  *
91  **/
92 typedef enum
93 {
94         NM_CONNECTION_ERROR_UNKNOWN = 0,                  /*< nick=UnknownError >*/
95         NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND, /*< nick=ConnectionSettingNotFound >*/
96         NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID,      /*< nick=ConnectionTypeInvalid >*/
97         NM_CONNECTION_ERROR_SETTING_NOT_FOUND,            /*< nick=SettingNotFound >*/
98         NM_CONNECTION_ERROR_INVALID_SETTING,              /*< nick=InvalidSetting >*/
99 } NMConnectionError;
100
101 /*
102  * NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD: overwrite the ip6 method
103  * when normalizing ip6 configuration. If omited, this defaults to
104  * @NM_SETTING_IP6_CONFIG_METHOD_AUTO.
105  */
106 #define NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD "ip6-config-method"
107
108 #define NM_CONNECTION_ERROR nm_connection_error_quark ()
109 GQuark nm_connection_error_quark (void);
110
111 /**
112  * NMConnection:
113  *
114  * The NMConnection struct contains only private data.
115  * It should only be accessed through the functions described below.
116  */
117 typedef struct {
118         GObject parent;
119 } NMConnection;
120
121 typedef struct {
122         GObjectClass parent;
123
124         /* Signals */
125         void (*secrets_updated) (NMConnection *connection, const char * setting);
126 } NMConnectionClass;
127
128 GType nm_connection_get_type (void);
129
130 NMConnection *nm_connection_new           (void);
131
132 NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error);
133
134 NMConnection *nm_connection_duplicate     (NMConnection *connection);
135
136 NMSetting    *nm_connection_create_setting (const char *name);
137
138 void          nm_connection_add_setting   (NMConnection *connection,
139                                            NMSetting    *setting);
140
141 void          nm_connection_remove_setting (NMConnection *connection,
142                                             GType         setting_type);
143
144 NMSetting    *nm_connection_get_setting   (NMConnection *connection,
145                                            GType         setting_type);
146
147 NMSetting    *nm_connection_get_setting_by_name (NMConnection *connection,
148                                                  const char   *name);
149
150 gboolean      nm_connection_replace_settings (NMConnection *connection,
151                                               GHashTable *new_settings,
152                                               GError **error);
153
154 NM_AVAILABLE_IN_0_9_10
155 gboolean      nm_connection_replace_settings_from_connection (NMConnection *connection,
156                                                               NMConnection *new_connection,
157                                                               GError **error);
158
159 gboolean      nm_connection_compare       (NMConnection *a,
160                                            NMConnection *b,
161                                            NMSettingCompareFlags flags);
162
163 gboolean      nm_connection_diff          (NMConnection *a,
164                                            NMConnection *b,
165                                            NMSettingCompareFlags flags,
166                                            GHashTable **out_settings);
167
168 gboolean      nm_connection_verify        (NMConnection *connection, GError **error);
169 NM_AVAILABLE_IN_1_0
170 gboolean      nm_connection_normalize     (NMConnection *connection,
171                                            GHashTable *parameters,
172                                            gboolean *modified,
173                                            GError **error);
174
175 const char *  nm_connection_need_secrets  (NMConnection *connection,
176                                            GPtrArray **hints);
177
178 void          nm_connection_clear_secrets (NMConnection *connection);
179
180 void          nm_connection_clear_secrets_with_flags (NMConnection *connection,
181                                                       NMSettingClearSecretsWithFlagsFn func,
182                                                       gpointer user_data);
183
184 gboolean      nm_connection_update_secrets (NMConnection *connection,
185                                             const char *setting_name,
186                                             GHashTable *secrets,
187                                             GError **error);
188
189 void          nm_connection_set_path      (NMConnection *connection,
190                                            const char *path);
191
192 const char *  nm_connection_get_path      (NMConnection *connection);
193
194 const char *  nm_connection_get_virtual_iface_name (NMConnection *connection);
195
196 NM_AVAILABLE_IN_1_0
197 const char *  nm_connection_get_interface_name (NMConnection *connection);
198
199 gboolean      nm_connection_is_type (NMConnection *connection, const char *type);
200
201 void          nm_connection_for_each_setting_value (NMConnection *connection,
202                                                     NMSettingValueIterFn func,
203                                                     gpointer user_data);
204
205 GHashTable   *nm_connection_to_hash       (NMConnection *connection,
206                                            NMSettingHashFlags flags);
207
208 void          nm_connection_dump          (NMConnection *connection);
209
210 GType         nm_connection_lookup_setting_type (const char *name);
211
212 GType         nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
213
214 /* Helpers */
215 const char *  nm_connection_get_uuid            (NMConnection *connection);
216 const char *  nm_connection_get_id              (NMConnection *connection);
217 NM_AVAILABLE_IN_0_9_10
218 const char *  nm_connection_get_connection_type (NMConnection *connection);
219
220 NM_AVAILABLE_IN_0_9_10
221 char *        nm_connection_get_virtual_device_description (NMConnection *connection);
222
223 NMSetting8021x *           nm_connection_get_setting_802_1x            (NMConnection *connection);
224 NMSettingBluetooth *       nm_connection_get_setting_bluetooth         (NMConnection *connection);
225 NMSettingBond *            nm_connection_get_setting_bond              (NMConnection *connection);
226 NM_AVAILABLE_IN_0_9_10
227 NMSettingTeam *            nm_connection_get_setting_team              (NMConnection *connection);
228 NM_AVAILABLE_IN_0_9_10
229 NMSettingTeamPort *        nm_connection_get_setting_team_port         (NMConnection *connection);
230 NMSettingBridge *          nm_connection_get_setting_bridge            (NMConnection *connection);
231 NMSettingBridgePort *      nm_connection_get_setting_bridge_port       (NMConnection *connection);
232 NMSettingCdma *            nm_connection_get_setting_cdma              (NMConnection *connection);
233 NMSettingConnection *      nm_connection_get_setting_connection        (NMConnection *connection);
234 NM_AVAILABLE_IN_0_9_10
235 NMSettingDcb *             nm_connection_get_setting_dcb               (NMConnection *connection);
236 NM_AVAILABLE_IN_0_9_10
237 NMSettingGeneric *         nm_connection_get_setting_generic           (NMConnection *connection);
238 NMSettingGsm *             nm_connection_get_setting_gsm               (NMConnection *connection);
239 NMSettingInfiniband *      nm_connection_get_setting_infiniband        (NMConnection *connection);
240 NMSettingIP4Config *       nm_connection_get_setting_ip4_config        (NMConnection *connection);
241 NMSettingIP6Config *       nm_connection_get_setting_ip6_config        (NMConnection *connection);
242 NMSettingOlpcMesh *        nm_connection_get_setting_olpc_mesh         (NMConnection *connection);
243 NMSettingPPP *             nm_connection_get_setting_ppp               (NMConnection *connection);
244 NMSettingPPPOE *           nm_connection_get_setting_pppoe             (NMConnection *connection);
245 NMSettingSerial *          nm_connection_get_setting_serial            (NMConnection *connection);
246 NMSettingVPN *             nm_connection_get_setting_vpn               (NMConnection *connection);
247 NMSettingWimax *           nm_connection_get_setting_wimax             (NMConnection *connection);
248 NMSettingAdsl *            nm_connection_get_setting_adsl              (NMConnection *connection);
249 NMSettingWired *           nm_connection_get_setting_wired             (NMConnection *connection);
250 NMSettingWireless *        nm_connection_get_setting_wireless          (NMConnection *connection);
251 NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnection *connection);
252 NMSettingVlan *            nm_connection_get_setting_vlan              (NMConnection *connection);
253
254 G_END_DECLS
255
256 #endif /* NM_CONNECTION_H */