1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2008 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-dhcp-config.h"
#include "nm-dbus-interface.h"
#include "nm-utils.h"
#include "nm-dbus-object.h"
#include "nm-core-utils.h"
/*****************************************************************************/
#define NM_TYPE_DHCP4_CONFIG (nm_dhcp4_config_get_type ())
#define NM_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4Config))
#define NM_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
#define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
#define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG))
#define NM_DHCP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp4ConfigClass NMDhcp4ConfigClass;
static GType nm_dhcp4_config_get_type (void);
#define NM_TYPE_DHCP6_CONFIG (nm_dhcp6_config_get_type ())
#define NM_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6Config))
#define NM_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
#define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
#define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG))
#define NM_DHCP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
typedef struct _NMDhcp6Config NMDhcp6Config;
typedef struct _NMDhcp6ConfigClass NMDhcp6ConfigClass;
static GType nm_dhcp6_config_get_type (void);
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpConfig,
PROP_OPTIONS,
);
typedef struct {
GVariant *options;
} NMDhcpConfigPrivate;
struct _NMDhcpConfig {
NMDBusObject parent;
NMDhcpConfigPrivate _priv;
};
struct _NMDhcpConfigClass {
NMDBusObjectClass parent;
};
G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_DBUS_OBJECT)
#define NM_DHCP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDhcpConfig, NM_IS_DHCP_CONFIG)
/*****************************************************************************/
void
nm_dhcp_config_set_options (NMDhcpConfig *self,
GHashTable *options)
{
NMDhcpConfigPrivate *priv;
g_return_if_fail (NM_IS_DHCP_CONFIG (self));
g_return_if_fail (options);
priv = NM_DHCP_CONFIG_GET_PRIVATE (self);
nm_g_variant_unref (priv->options);
priv->options = g_variant_ref_sink (nm_utils_strdict_to_variant_asv (options));
_notify (self, PROP_OPTIONS);
}
const char *
nm_dhcp_config_get_option (NMDhcpConfig *self, const char *key)
{
NMDhcpConfigPrivate *priv;
const char *value;
g_return_val_if_fail (NM_IS_DHCP_CONFIG (self), NULL);
g_return_val_if_fail (key, NULL);
priv = NM_DHCP_CONFIG_GET_PRIVATE (self);
if ( priv->options
&& g_variant_lookup (priv->options, key, "&s", &value))
return value;
else
return NULL;
}
GVariant *
nm_dhcp_config_get_options (NMDhcpConfig *self)
{
g_return_val_if_fail (NM_IS_DHCP_CONFIG (self), NULL);
return NM_DHCP_CONFIG_GET_PRIVATE (self)->options;
}
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
case PROP_OPTIONS:
g_value_set_variant (value, priv->options
?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_dhcp_config_init (NMDhcpConfig *self)
{
}
NMDhcpConfig *
nm_dhcp_config_new (int addr_family)
{
nm_assert_addr_family (addr_family);
return g_object_new ( addr_family != AF_INET
? NM_TYPE_DHCP6_CONFIG
: NM_TYPE_DHCP4_CONFIG,
NULL);
}
static void
finalize (GObject *object)
{
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
nm_g_variant_unref (priv->options);
G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object);
}
static void
nm_dhcp_config_class_init (NMDhcpConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
obj_properties[PROP_OPTIONS] =
g_param_spec_variant (NM_DHCP_CONFIG_OPTIONS, "", "",
G_VARIANT_TYPE ("a{sv}"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}
/*****************************************************************************/
struct _NMDhcp4Config {
NMDhcpConfig parent;
};
struct _NMDhcp4ConfigClass {
NMDhcpConfigClass parent;
};
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG)
static void
nm_dhcp4_config_init (NMDhcp4Config *self)
{
}
static const NMDBusInterfaceInfoExtended interface_info_dhcp4_config = {
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
NM_DBUS_INTERFACE_DHCP4_CONFIG,
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
&nm_signal_info_property_changed_legacy,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP_CONFIG_OPTIONS),
),
),
.legacy_property_changed = TRUE,
};
static void
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *klass)
{
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP4Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp4_config);
dbus_object_class->export_on_construction = TRUE;
}
/*****************************************************************************/
struct _NMDhcp6Config {
NMDhcpConfig parent;
};
struct _NMDhcp6ConfigClass {
NMDhcpConfigClass parent;
};
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_DHCP_CONFIG)
static void
nm_dhcp6_config_init (NMDhcp6Config *self)
{
}
static const NMDBusInterfaceInfoExtended interface_info_dhcp6_config = {
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
NM_DBUS_INTERFACE_DHCP6_CONFIG,
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
&nm_signal_info_property_changed_legacy,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP_CONFIG_OPTIONS),
),
),
.legacy_property_changed = TRUE,
};
static void
nm_dhcp6_config_class_init (NMDhcp6ConfigClass *klass)
{
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP6Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp6_config);
dbus_object_class->export_on_construction = TRUE;
}
|