1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2015 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-ip-tunnel.h"
29 #include "nm-device-ip-tunnel.h"
30 #include "nm-device-private.h"
31 #include "nm-object-private.h"
32 #include "nm-core-internal.h"
34 G_DEFINE_TYPE (NMDeviceIPTunnel, nm_device_ip_tunnel, NM_TYPE_DEVICE)
36 #define NM_DEVICE_IP_TUNNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_IP_TUNNEL, NMDeviceIPTunnelPrivate))
45 gboolean path_mtu_discovery;
50 } NMDeviceIPTunnelPrivate;
60 PROP_PATH_MTU_DISCOVERY,
63 PROP_ENCAPSULATION_LIMIT,
70 * nm_device_ip_tunnel_get_mode:
71 * @device: a #NMDeviceIPTunnel
73 * Returns: the tunneling mode
78 nm_device_ip_tunnel_get_mode (NMDeviceIPTunnel *device)
80 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
82 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->mode;
86 * nm_device_ip_tunnel_get_parent:
87 * @device: a #NMDeviceIPTunnel
89 * Returns: (transfer none): the device's parent device
94 nm_device_ip_tunnel_get_parent (NMDeviceIPTunnel *device)
96 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
98 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->parent;
102 * nm_device_ip_tunnel_get_local:
103 * @device: a #NMDeviceIPTunnel
105 * Returns: the local endpoint of the tunnel
110 nm_device_ip_tunnel_get_local (NMDeviceIPTunnel *device)
112 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
114 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->local;
118 * nm_device_ip_tunnel_get_remote:
119 * @device: a #NMDeviceIPTunnel
121 * Returns: the remote endpoint of the tunnel
126 nm_device_ip_tunnel_get_remote (NMDeviceIPTunnel *device)
128 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
130 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->remote;
134 * nm_device_ip_tunnel_get_ttl:
135 * @device: a #NMDeviceIPTunnel
137 * Returns: the TTL assigned to tunneled packets
142 nm_device_ip_tunnel_get_ttl (NMDeviceIPTunnel *device)
144 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
146 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->ttl;
150 * nm_device_ip_tunnel_get_tos:
151 * @device: a #NMDeviceIPTunnel
153 * Returns: type of service (IPv4) or traffic class (IPv6) assigned
154 * to tunneled packets.
159 nm_device_ip_tunnel_get_tos (NMDeviceIPTunnel *device)
161 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
163 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->tos;
167 * nm_device_ip_tunnel_get_path_mtu_discovery:
168 * @device: a #NMDeviceIPTunnel
170 * Returns: whether path MTU discovery is enabled
175 nm_device_ip_tunnel_get_path_mtu_discovery (NMDeviceIPTunnel *device)
177 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), TRUE);
179 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->path_mtu_discovery;
183 * nm_device_ip_tunnel_get_input_key:
184 * @device: a #NMDeviceIPTunnel
186 * Returns: the key used for incoming packets
191 nm_device_ip_tunnel_get_input_key (NMDeviceIPTunnel *device)
193 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
195 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->input_key;
199 * nm_device_ip_tunnel_get_output_key:
200 * @device: a #NMDeviceIPTunnel
202 * Returns: the key used for outgoing packets
207 nm_device_ip_tunnel_get_output_key (NMDeviceIPTunnel *device)
209 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
211 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->output_key;
215 * nm_device_ip_tunnel_get_encapsulation_limit:
216 * @device: a #NMDeviceIPTunnel
218 * Returns: the maximum permitted encapsulation level
223 nm_device_ip_tunnel_get_encapsulation_limit (NMDeviceIPTunnel *device)
225 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
227 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->encap_limit;
231 * nm_device_ip_tunnel_get_flow_label:
232 * @device: a #NMDeviceIPTunnel
234 * Returns: the flow label assigned to tunnel packets
239 nm_device_ip_tunnel_get_flow_label (NMDeviceIPTunnel *device)
241 g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
243 return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->flow_label;
247 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
249 if (!NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->connection_compatible (device, connection, error))
252 if (!nm_connection_is_type (connection, NM_SETTING_IP_TUNNEL_SETTING_NAME)) {
253 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
254 _("The connection was not an IP tunnel connection."));
262 get_setting_type (NMDevice *device)
264 return NM_TYPE_SETTING_IP_TUNNEL;
267 /***********************************************************/
270 nm_device_ip_tunnel_init (NMDeviceIPTunnel *device)
272 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_IP_TUNNEL);
276 init_dbus (NMObject *object)
278 NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (object);
279 const NMPropertiesInfo property_info[] = {
280 { NM_DEVICE_IP_TUNNEL_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
281 { NM_DEVICE_IP_TUNNEL_MODE, &priv->mode },
282 { NM_DEVICE_IP_TUNNEL_LOCAL, &priv->local },
283 { NM_DEVICE_IP_TUNNEL_REMOTE, &priv->remote },
284 { NM_DEVICE_IP_TUNNEL_TTL, &priv->ttl },
285 { NM_DEVICE_IP_TUNNEL_TOS, &priv->tos },
286 { NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, &priv->path_mtu_discovery },
287 { NM_DEVICE_IP_TUNNEL_INPUT_KEY, &priv->input_key },
288 { NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, &priv->output_key },
289 { NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, &priv->encap_limit },
290 { NM_DEVICE_IP_TUNNEL_FLOW_LABEL, &priv->flow_label },
294 NM_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->init_dbus (object);
296 _nm_object_register_properties (object,
297 NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL,
302 finalize (GObject *object)
304 NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (object);
306 g_free (priv->local);
307 g_free (priv->remote);
308 g_free (priv->input_key);
309 g_free (priv->output_key);
310 g_clear_object (&priv->parent);
312 G_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->finalize (object);
316 get_property (GObject *object,
321 NMDeviceIPTunnel *device = NM_DEVICE_IP_TUNNEL (object);
325 g_value_set_object (value, nm_device_ip_tunnel_get_parent (device));
328 g_value_set_uint (value, nm_device_ip_tunnel_get_mode (device));
331 g_value_set_string (value, nm_device_ip_tunnel_get_local (device));
334 g_value_set_string (value, nm_device_ip_tunnel_get_remote (device));
337 g_value_set_uint (value, nm_device_ip_tunnel_get_ttl (device));
340 g_value_set_uint (value, nm_device_ip_tunnel_get_tos (device));
342 case PROP_PATH_MTU_DISCOVERY:
343 g_value_set_boolean (value, nm_device_ip_tunnel_get_path_mtu_discovery (device));
346 g_value_set_string (value, nm_device_ip_tunnel_get_input_key (device));
348 case PROP_OUTPUT_KEY:
349 g_value_set_string (value, nm_device_ip_tunnel_get_output_key (device));
351 case PROP_ENCAPSULATION_LIMIT:
352 g_value_set_uint (value, nm_device_ip_tunnel_get_encapsulation_limit (device));
354 case PROP_FLOW_LABEL:
355 g_value_set_uint (value, nm_device_ip_tunnel_get_flow_label (device));
358 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
364 nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class)
366 GObjectClass *object_class = G_OBJECT_CLASS (bond_class);
367 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bond_class);
368 NMDeviceClass *device_class = NM_DEVICE_CLASS (bond_class);
370 g_type_class_add_private (bond_class, sizeof (NMDeviceIPTunnelPrivate));
372 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL);
374 /* virtual methods */
375 object_class->finalize = finalize;
376 object_class->get_property = get_property;
378 nm_object_class->init_dbus = init_dbus;
380 device_class->connection_compatible = connection_compatible;
381 device_class->get_setting_type = get_setting_type;
386 * NMDeviceIPTunnel:mode:
388 * The tunneling mode of the device.
392 g_object_class_install_property
393 (object_class, PROP_MODE,
394 g_param_spec_uint (NM_DEVICE_IP_TUNNEL_MODE, "", "",
397 G_PARAM_STATIC_STRINGS));
400 * NMDeviceIPTunnel:parent:
402 * The devices's parent device.
406 g_object_class_install_property
407 (object_class, PROP_PARENT,
408 g_param_spec_object (NM_DEVICE_IP_TUNNEL_PARENT, "", "",
411 G_PARAM_STATIC_STRINGS));
414 * NMDeviceIPTunnel:local:
416 * The local endpoint of the tunnel.
420 g_object_class_install_property
421 (object_class, PROP_LOCAL,
422 g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "",
425 G_PARAM_STATIC_STRINGS));
428 * NMDeviceIPTunnel:remote:
430 * The remote endpoint of the tunnel.
434 g_object_class_install_property
435 (object_class, PROP_REMOTE,
436 g_param_spec_string (NM_DEVICE_IP_TUNNEL_REMOTE, "", "",
439 G_PARAM_STATIC_STRINGS));
442 * NMDeviceIPTunnel:ttl:
444 * The TTL assigned to tunneled packets. 0 is a special value
445 * meaning that packets inherit the TTL value
449 g_object_class_install_property
450 (object_class, PROP_TTL,
451 g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TTL, "", "",
454 G_PARAM_STATIC_STRINGS));
457 * NMDeviceIPTunnel:tos:
459 * The type of service (IPv4) or traffic class (IPv6) assigned to
464 g_object_class_install_property
465 (object_class, PROP_TOS,
466 g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TOS, "", "",
469 G_PARAM_STATIC_STRINGS));
472 * NMDeviceIPTunnel:path-mtu-discovery:
474 * Whether path MTU discovery is enabled on this tunnel.
478 g_object_class_install_property
479 (object_class, PROP_PATH_MTU_DISCOVERY,
480 g_param_spec_boolean (NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, "", "",
483 G_PARAM_STATIC_STRINGS));
486 * NMDeviceIPTunnel:input-key:
488 * The key used for tunneled input packets, if applicable.
492 g_object_class_install_property
493 (object_class, PROP_INPUT_KEY,
494 g_param_spec_string (NM_DEVICE_IP_TUNNEL_INPUT_KEY, "", "",
497 G_PARAM_STATIC_STRINGS));
500 * NMDeviceIPTunnel:output-key:
502 * The key used for tunneled output packets, if applicable.
506 g_object_class_install_property
507 (object_class, PROP_OUTPUT_KEY,
508 g_param_spec_string (NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, "", "",
511 G_PARAM_STATIC_STRINGS));
514 * NMDeviceIPTunnel:encapsulation-limit:
516 * How many additional levels of encapsulation are permitted to
517 * be prepended to packets. This property applies only to IPv6
522 g_object_class_install_property
523 (object_class, PROP_ENCAPSULATION_LIMIT,
524 g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, "", "",
527 G_PARAM_STATIC_STRINGS));
530 * NMDeviceIPTunnel:flow-label:
532 * The flow label to assign to tunnel packets. This property
533 * applies only to IPv6 tunnels.
537 g_object_class_install_property
538 (object_class, PROP_FLOW_LABEL,
539 g_param_spec_uint (NM_DEVICE_IP_TUNNEL_FLOW_LABEL, "", "",
542 G_PARAM_STATIC_STRINGS));