summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-12-16 15:08:58 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2015-12-16 15:14:54 +0100
commit904d4b21a5e78fc2fedf3c2ec535a5ee561c5ac6 (patch)
treec0cf0f1a8ad2829ca857ab01da545e7162bf5a4e
parentc4b6e34ddfa8b7404e8aeca91d48df5594d75917 (diff)
downloadNetworkManager-bg/sw-devices-mtu-bgo759549.tar.gz
tun: add support for MTU and cloned-mac-address propertiesbg/sw-devices-mtu-bgo759549
Make it possible to change ethernet.mtu and ethernet.cloned-mac-address properties of tun/tap devices (cloned-mac-address is meaningful only for taps).
-rw-r--r--clients/cli/connections.c1
-rw-r--r--src/devices/nm-device-tun.c60
2 files changed, 61 insertions, 0 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index e8db2bbab5..6715924b46 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -2818,6 +2818,7 @@ static const NameItem nmc_bridge_slave_settings [] = {
static const NameItem nmc_tun_settings [] = {
{ NM_SETTING_CONNECTION_SETTING_NAME, NULL, NULL, TRUE },
{ NM_SETTING_TUN_SETTING_NAME, NULL, NULL, TRUE },
+ { NM_SETTING_WIRED_SETTING_NAME, "ethernet", NULL, FALSE },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME, NULL, NULL, FALSE },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME, NULL, NULL, FALSE },
{ NULL, NULL, NULL, FALSE }
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index 3501ddb466..e1ec520363 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -25,8 +25,10 @@
#include <sys/types.h>
#include "nm-default.h"
+#include "nm-activation-request.h"
#include "nm-device-tun.h"
#include "nm-device-private.h"
+#include "nm-ip4-config.h"
#include "nm-platform.h"
#include "nm-device-factory.h"
#include "nm-setting-tun.h"
@@ -285,6 +287,62 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return TRUE;
}
+static NMActStageReturn
+act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
+{
+ NMDeviceTun *self = NM_DEVICE_TUN (device);
+ NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self);
+ NMActRequest *req;
+ NMConnection *connection;
+ NMSettingWired *s_wired;
+ const char *cloned_mac;
+ NMActStageReturn ret;
+
+ g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+ ret = NM_DEVICE_CLASS (nm_device_tun_parent_class)->act_stage1_prepare (device, reason);
+ if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
+ return ret;
+
+ /* Nothing to do for TUN devices */
+ if (g_strcmp0 (priv->mode, "tap"))
+ return NM_ACT_STAGE_RETURN_SUCCESS;
+
+ req = nm_device_get_act_request (device);
+ g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+ connection = nm_act_request_get_applied_connection (req);
+ g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+ s_wired = nm_connection_get_setting_wired (connection);
+ if (s_wired) {
+ /* Set device MAC address if the connection wants to change it */
+ cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
+ if (cloned_mac)
+ nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
+ }
+
+ return NM_ACT_STAGE_RETURN_SUCCESS;
+}
+
+static void
+ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
+{
+ NMConnection *connection;
+ NMSettingWired *s_wired;
+ guint32 mtu;
+
+ connection = nm_device_get_applied_connection (device);
+ g_assert (connection);
+
+ s_wired = nm_connection_get_setting_wired (connection);
+ if (s_wired) {
+ mtu = nm_setting_wired_get_mtu (s_wired);
+ if (mtu)
+ nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
+ }
+}
+
static void
unrealize (NMDevice *device, gboolean remove_resources)
{
@@ -392,6 +450,8 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
device_class->setup_start = setup_start;
device_class->unrealize = unrealize;
device_class->update_connection = update_connection;
+ device_class->act_stage1_prepare = act_stage1_prepare;
+ device_class->ip4_config_pre_commit = ip4_config_pre_commit;
/* properties */
g_object_class_install_property