[PATCH] tun-mtu and fragment support for openvpn



Hello all,

Here is my attempt at adding support for tun-mtu and fragment to
NetworkManager-openvpn.  "it works for me"

The diff is against SVN HOL this afternoon.  I'm not subscribed
to the list, so if there are any questions please CC me.

-- 
James R. Leu
jleu mindspring com
diff -uNr --exclude=.svn --exclude=po network-manager-openvpn/properties/auth-helpers.c NetworkManager-openvpn-0.7.0.99/properties/auth-helpers.c
--- network-manager-openvpn/properties/auth-helpers.c	2009-05-01 14:19:21.000000000 -0500
+++ NetworkManager-openvpn-0.7.0.99/properties/auth-helpers.c	2009-05-01 13:53:47.000000000 -0500
@@ -802,6 +765,26 @@
 	gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
 }
 
+static void
+mtu_toggled_cb (GtkWidget *check, gpointer user_data)
+{
+	GladeXML *xml = (GladeXML *) user_data;
+	GtkWidget *widget;
+
+	widget = glade_xml_get_widget (xml, "mtu_spinbutton");
+	gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+}
+
+static void
+frag_toggled_cb (GtkWidget *check, gpointer user_data)
+{
+	GladeXML *xml = (GladeXML *) user_data;
+	GtkWidget *widget;
+
+	widget = glade_xml_get_widget (xml, "frag_spinbutton");
+	gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+}
+
 static const char *
 nm_find_openvpn (void)
 {
@@ -1036,6 +1019,56 @@
 		gtk_widget_set_sensitive (widget, FALSE);
 	}
 
+	widget = glade_xml_get_widget (xml, "mtu_checkbutton");
+	g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (mtu_toggled_cb), xml);
+
+	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_MTU);
+	if (value && strlen (value)) {
+		long int tmp;
+
+		errno = 0;
+		tmp = strtol (value, NULL, 10);
+		if (errno == 0 && tmp > 0 && tmp < 65536 && tmp != 1500) {
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+			widget = glade_xml_get_widget (xml, "mtu_spinbutton");
+			gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget),
+			                           (gdouble) tmp);
+		}
+		gtk_widget_set_sensitive (widget, TRUE);
+	} else {
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+
+		widget = glade_xml_get_widget (xml, "mtu_spinbutton");
+		gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 1500.0);
+		gtk_widget_set_sensitive (widget, FALSE);
+	}
+
+	widget = glade_xml_get_widget (xml, "frag_checkbutton");
+	g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (frag_toggled_cb), xml);
+
+	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_FRAG);
+	if (value && strlen (value)) {
+		long int tmp;
+
+		errno = 0;
+		tmp = strtol (value, NULL, 10);
+		if (errno == 0 && tmp > 0 && tmp < 65536 && tmp != 1430) {
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+			widget = glade_xml_get_widget (xml, "frag_spinbutton");
+			gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget),
+			                           (gdouble) tmp);
+		}
+		gtk_widget_set_sensitive (widget, TRUE);
+	} else {
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+
+		widget = glade_xml_get_widget (xml, "frag_spinbutton");
+		gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 1430.0);
+		gtk_widget_set_sensitive (widget, FALSE);
+	}
+
 	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_COMP_LZO);
 	if (value && !strcmp (value, "yes")) {
 		widget = glade_xml_get_widget (xml, "lzo_checkbutton");
@@ -1145,6 +1178,24 @@
 		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PORT), g_strdup_printf ("%d", port));
 	}
 
+	widget = glade_xml_get_widget (xml, "mtu_checkbutton");
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+		int mtu;
+
+		widget = glade_xml_get_widget (xml, "mtu_spinbutton");
+		mtu = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_MTU), g_strdup_printf ("%d", mtu));
+	}
+
+	widget = glade_xml_get_widget (xml, "frag_checkbutton");
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+		int frag;
+
+		widget = glade_xml_get_widget (xml, "frag_spinbutton");
+		frag = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_FRAG), g_strdup_printf ("%d", frag));
+	}
+
 	widget = glade_xml_get_widget (xml, "lzo_checkbutton");
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
 		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_COMP_LZO), g_strdup ("yes"));
diff -uNr --exclude=.svn --exclude=po network-manager-openvpn/properties/nm-openvpn-dialog.glade NetworkManager-openvpn-0.7.0.99/properties/nm-openvpn-dialog.glade
--- network-manager-openvpn/properties/nm-openvpn-dialog.glade	2009-05-01 14:19:21.000000000 -0500
+++ NetworkManager-openvpn-0.7.0.99/properties/nm-openvpn-dialog.glade	2009-05-01 13:27:33.000000000 -0500
@@ -928,6 +894,78 @@
                   </packing>
                 </child>
                 <child>
+                  <widget class="GtkHBox" id="hbox98">
+                    <property name="visible">True</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <widget class="GtkCheckButton" id="mtu_checkbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">Use custom M_TU:</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkSpinButton" id="mtu_spinbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="adjustment">1500 1 65535 1 10 10</property>
+                        <property name="climb_rate">1</property>
+                        <property name="numeric">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkHBox" id="hbox99">
+                    <property name="visible">True</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <widget class="GtkCheckButton" id="frag_checkbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">Use custom f_ragment:</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkSpinButton" id="frag_spinbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="adjustment">1430 1 65535 1 10 10</property>
+                        <property name="climb_rate">1</property>
+                        <property name="numeric">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                  </packing>
+                </child>
+                <child>
                   <widget class="GtkCheckButton" id="lzo_checkbutton">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
diff -uNr --exclude=.svn --exclude=po network-manager-openvpn/src/nm-openvpn-service.c NetworkManager-openvpn-0.7.0.99/src/nm-openvpn-service.c
--- network-manager-openvpn/src/nm-openvpn-service.c	2009-05-01 14:19:20.000000000 -0500
+++ NetworkManager-openvpn-0.7.0.99/src/nm-openvpn-service.c	2009-05-01 14:05:41.000000000 -0500
@@ -94,6 +94,8 @@
 	{ NM_OPENVPN_KEY_LOCAL_IP,             G_TYPE_STRING, 0, 0, TRUE },
 	{ NM_OPENVPN_KEY_PROTO_TCP,            G_TYPE_BOOLEAN, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_PORT,                 G_TYPE_INT, 1, 65535, FALSE },
+	{ NM_OPENVPN_KEY_MTU,                  G_TYPE_INT, 1, 65535, FALSE },
+	{ NM_OPENVPN_KEY_FRAG,                 G_TYPE_INT, 1, 65535, FALSE },
 	{ NM_OPENVPN_KEY_REMOTE,               G_TYPE_STRING, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_REMOTE_IP,            G_TYPE_STRING, 0, 0, TRUE },
 	{ NM_OPENVPN_KEY_STATIC_KEY,           G_TYPE_STRING, 0, 0, FALSE },
@@ -676,6 +678,36 @@
 		add_openvpn_arg (args, "1194");
 	}
 
+	/* MTU */
+	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_MTU);
+	if (tmp && strlen (tmp)) {
+		add_openvpn_arg (args, "--tun-mtu");
+		if (!add_openvpn_arg_int (args, tmp)) {
+			g_set_error (error,
+			             NM_VPN_PLUGIN_ERROR,
+			             NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+			             "Invalid MTU number '%s'.",
+			             tmp);
+			free_openvpn_args (args);
+			return FALSE;
+		}
+	}
+
+	/* Frag size */
+	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_FRAG);
+	if (tmp && strlen (tmp)) {
+		add_openvpn_arg (args, "--fragment");
+		if (!add_openvpn_arg_int (args, tmp)) {
+			g_set_error (error,
+			             NM_VPN_PLUGIN_ERROR,
+			             NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+			             "Invalid fragment size '%s'.",
+			             tmp);
+			free_openvpn_args (args);
+			return FALSE;
+		}
+	}
+
 	/* Cipher */
 	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CIPHER);
 	if (tmp && strlen (tmp)) {
diff -uNr --exclude=.svn --exclude=po network-manager-openvpn/src/nm-openvpn-service.h NetworkManager-openvpn-0.7.0.99/src/nm-openvpn-service.h
--- network-manager-openvpn/src/nm-openvpn-service.h	2009-05-01 14:19:20.000000000 -0500
+++ NetworkManager-openvpn-0.7.0.99/src/nm-openvpn-service.h	2009-05-01 13:48:03.000000000 -0500
@@ -49,6 +49,8 @@
 #define NM_OPENVPN_KEY_LOCAL_IP "local-ip"
 #define NM_OPENVPN_KEY_PROTO_TCP "proto-tcp"
 #define NM_OPENVPN_KEY_PORT "port"
+#define NM_OPENVPN_KEY_MTU "tun-mtu"
+#define NM_OPENVPN_KEY_FRAG "fragment"
 #define NM_OPENVPN_KEY_REMOTE "remote"
 #define NM_OPENVPN_KEY_REMOTE_IP "remote-ip"
 #define NM_OPENVPN_KEY_STATIC_KEY "static-key"

Attachment: pgpCN9zUTpcrz.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]