ip-tunnel: add a MTU property
authorBeniamino Galvani <bgalvani@redhat.com>
Wed, 16 Dec 2015 10:31:58 +0000 (11:31 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Sat, 19 Dec 2015 11:06:33 +0000 (12:06 +0100)
Add a new ip-tunnel.mtu property which can be used to change the MTU
of the tunnel interface.

clients/cli/settings.c
libnm-core/nm-setting-ip-tunnel.c
libnm-core/nm-setting-ip-tunnel.h
libnm/libnm.ver
src/devices/nm-device-ip-tunnel.c

index c899d8f..9f95dfe 100644 (file)
@@ -732,6 +732,7 @@ NmcOutputField nmc_fields_setting_ip_tunnel[] = {
        SETTING_FIELD (NM_SETTING_IP_TUNNEL_OUTPUT_KEY),              /* 9 */
        SETTING_FIELD (NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT),     /* 10 */
        SETTING_FIELD (NM_SETTING_IP_TUNNEL_FLOW_LABEL),              /* 11 */
+       SETTING_FIELD (NM_SETTING_IP_TUNNEL_MTU),                     /* 12 */
        {NULL, NULL, 0, NULL, FALSE, FALSE, 0}
 };
 #define NMC_FIELDS_SETTING_IP_TUNNEL_ALL     "name"","\
@@ -745,7 +746,8 @@ NmcOutputField nmc_fields_setting_ip_tunnel[] = {
                                               NM_SETTING_IP_TUNNEL_INPUT_KEY","\
                                               NM_SETTING_IP_TUNNEL_OUTPUT_KEY","\
                                               NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT","\
-                                              NM_SETTING_IP_TUNNEL_FLOW_LABEL
+                                              NM_SETTING_IP_TUNNEL_FLOW_LABEL","\
+                                              NM_SETTING_IP_TUNNEL_MTU
 #define NMC_FIELDS_SETTING_IP_TUNNEL_COMMON   NMC_FIELDS_SETTING_IP_TUNNEL_ALL
 
 /* Available fields for NM_SETTING_MACVLAN_SETTING_NAME */
@@ -1407,6 +1409,7 @@ DEFINE_GETTER (nmc_property_ip_tunnel_get_input_key, NM_SETTING_IP_TUNNEL_INPUT_
 DEFINE_GETTER (nmc_property_ip_tunnel_get_output_key, NM_SETTING_IP_TUNNEL_OUTPUT_KEY);
 DEFINE_GETTER (nmc_property_ip_tunnel_get_encapsulation_limit, NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT);
 DEFINE_GETTER (nmc_property_ip_tunnel_get_flow_label, NM_SETTING_IP_TUNNEL_FLOW_LABEL);
+DEFINE_GETTER (nmc_property_ip_tunnel_get_mtu, NM_SETTING_IP_TUNNEL_MTU);
 
 static const char **
 nmc_property_ip_tunnel_allowed_mode (NMSetting *setting, const char *prop)
@@ -7385,6 +7388,13 @@ nmc_properties_init (void)
                            NULL,
                            NULL,
                            NULL);
+       nmc_add_prop_funcs (GLUE (IP_TUNNEL, MTU),
+                           nmc_property_ip_tunnel_get_mtu,
+                           nmc_property_set_uint,
+                           NULL,
+                           NULL,
+                           NULL,
+                           NULL);
 
        /* Add editable properties for NM_SETTING_MACVLAN_SETTING_NAME */
        nmc_add_prop_funcs (GLUE (MACVLAN, PARENT),
@@ -8738,6 +8748,7 @@ setting_ip_tunnel_details (NMSetting *setting, NmCli *nmc,  const char *one_prop
        set_val_str (arr, 9, nmc_property_ip_tunnel_get_output_key (setting, NMC_PROPERTY_GET_PRETTY));
        set_val_str (arr, 10, nmc_property_ip_tunnel_get_encapsulation_limit (setting, NMC_PROPERTY_GET_PRETTY));
        set_val_str (arr, 11, nmc_property_ip_tunnel_get_flow_label (setting, NMC_PROPERTY_GET_PRETTY));
+       set_val_str (arr, 12, nmc_property_ip_tunnel_get_mtu (setting, NMC_PROPERTY_GET_PRETTY));
        g_ptr_array_add (nmc->output_data, arr);
 
        print_data (nmc);  /* Print all data */
index 672a49c..cd63aa1 100644 (file)
@@ -49,6 +49,7 @@ typedef struct {
        char *output_key;
        guint encapsulation_limit;
        guint flow_label;
+       guint mtu;
 } NMSettingIPTunnelPrivate;
 
 enum {
@@ -64,6 +65,7 @@ enum {
        PROP_OUTPUT_KEY,
        PROP_ENCAPSULATION_LIMIT,
        PROP_FLOW_LABEL,
+       PROP_MTU,
 
        LAST_PROP
 };
@@ -266,6 +268,24 @@ nm_setting_ip_tunnel_get_flow_label (NMSettingIPTunnel *setting)
        return NM_SETTING_IP_TUNNEL_GET_PRIVATE (setting)->flow_label;
 }
 
+/**
+ * nm_setting_ip_tunnel_get_mtu:
+ * @setting: the #NMSettingIPTunnel
+ *
+ * Returns the #NMSettingIPTunnel:mtu property of the setting.
+ *
+ * Returns: the MTU
+ *
+ * Since: 1.2
+ **/
+guint
+nm_setting_ip_tunnel_get_mtu (NMSettingIPTunnel *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_IP_TUNNEL (setting), 0);
+
+       return NM_SETTING_IP_TUNNEL_GET_PRIVATE (setting)->mtu;
+}
+
 /*********************************************************************/
 
 static gboolean
@@ -460,6 +480,9 @@ set_property (GObject *object, guint prop_id,
        case PROP_FLOW_LABEL:
                priv->flow_label = g_value_get_uint (value);
                break;
+       case PROP_MTU:
+               priv->mtu = g_value_get_uint (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -507,6 +530,9 @@ get_property (GObject *object, guint prop_id,
        case PROP_FLOW_LABEL:
                g_value_set_uint (value, priv->flow_label);
                break;
+       case PROP_MTU:
+               g_value_set_uint (value, priv->mtu);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -721,4 +747,21 @@ nm_setting_ip_tunnel_class_init (NMSettingIPTunnelClass *setting_class)
                                    G_PARAM_CONSTRUCT |
                                    NM_SETTING_PARAM_INFERRABLE |
                                    G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingIPTunel:mtu:
+        *
+        * If non-zero, only transmit packets of the specified size or smaller,
+        * breaking larger packets up into multiple fragments.
+        *
+        * Since: 1.2
+        **/
+       g_object_class_install_property
+               (object_class, PROP_MTU,
+                g_param_spec_uint (NM_SETTING_IP_TUNNEL_MTU, "", "",
+                                   0, G_MAXUINT, 0,
+                                   G_PARAM_READWRITE |
+                                   G_PARAM_CONSTRUCT |
+                                   NM_SETTING_PARAM_FUZZY_IGNORE |
+                                   G_PARAM_STATIC_STRINGS));
 }
index a07bd50..09814f3 100644 (file)
@@ -49,6 +49,7 @@ G_BEGIN_DECLS
 #define NM_SETTING_IP_TUNNEL_OUTPUT_KEY          "output-key"
 #define NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT "encapsulation-limit"
 #define NM_SETTING_IP_TUNNEL_FLOW_LABEL          "flow-label"
+#define NM_SETTING_IP_TUNNEL_MTU                 "mtu"
 
 struct _NMSettingIPTunnel {
        NMSetting parent;
@@ -89,6 +90,8 @@ NM_AVAILABLE_IN_1_2
 guint nm_setting_ip_tunnel_get_encapsulation_limit (NMSettingIPTunnel *setting);
 NM_AVAILABLE_IN_1_2
 guint nm_setting_ip_tunnel_get_flow_label (NMSettingIPTunnel *setting);
+NM_AVAILABLE_IN_1_2
+guint nm_setting_ip_tunnel_get_mtu (NMSettingIPTunnel *setting);
 
 G_END_DECLS
 
index 8eca496..4636e9a 100644 (file)
@@ -949,6 +949,7 @@ global:
        nm_setting_ip_tunnel_get_input_key;
        nm_setting_ip_tunnel_get_local;
        nm_setting_ip_tunnel_get_mode;
+       nm_setting_ip_tunnel_get_mtu;
        nm_setting_ip_tunnel_get_output_key;
        nm_setting_ip_tunnel_get_parent;
        nm_setting_ip_tunnel_get_path_mtu_discovery;
index bcb6dbf..2fa6bee 100644 (file)
@@ -35,6 +35,7 @@
 #include "nm-core-internal.h"
 #include "nm-connection-provider.h"
 #include "nm-activation-request.h"
+#include "nm-ip4-config.h"
 
 #include "nmdbus-device-ip-tunnel.h"
 
@@ -777,6 +778,24 @@ setup_start (NMDevice *device, const NMPlatformLink *plink)
        update_properties (device);
 }
 
+static void
+ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
+{
+       NMConnection *connection;
+       NMSettingIPTunnel *s_ip_tunnel;
+       guint32 mtu;
+
+       connection = nm_device_get_applied_connection (device);
+       g_assert (connection);
+       s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);
+       g_assert (s_ip_tunnel);
+
+       /* MTU override */
+       mtu = nm_setting_ip_tunnel_get_mtu (s_ip_tunnel);
+       if (mtu)
+               nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
+}
+
 static void
 unrealize (NMDevice *device, gboolean remove_resources)
 {
@@ -865,6 +884,7 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass)
        device_class->update_connection = update_connection;
        device_class->check_connection_compatible = check_connection_compatible;
        device_class->create_and_realize = create_and_realize;
+       device_class->ip4_config_pre_commit = ip4_config_pre_commit;
        device_class->realize = realize;
        device_class->setup_start = setup_start;
        device_class->unrealize = unrealize;