From 29b93602fc02774e2fd739389c9098cfc95cdb58 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 16 Dec 2015 15:08:58 +0100 Subject: tun: add support for MTU and cloned-mac-address properties 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). --- clients/cli/connections.c | 1 + src/devices/nm-device-tun.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 0b6513a37d..9ab926a021 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -2820,6 +2820,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 #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 -- cgit v1.2.1