[PATCH] Disconnect after N idle seconds
- From: Raul Gutierrez Segales <rgs rieder net py>
- To: Dan Williams <dcbw redhat com>
- Cc: networkmanager-list <networkmanager-list gnome org>
- Subject: [PATCH] Disconnect after N idle seconds
- Date: Mon, 08 Jun 2009 01:02:27 -0400
Dan,
I am attaching 2 patches that add the "disconnect after N idle seconds"
option to the group of PPP settings.
One adds the option to the nm-applet and the other one does the back-end
magic (dealing with the setting and building the cmd line for pppd).
I did this because I only have so many bytes to transfer over my 3G
connection and this feature is useful when you want to rationalize what
goes through the link (and prefer the connection to go down if you are
away for a while). Hope it's useful for someone else.
Regards,
Raúl
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index f7354a6..620567a 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -157,6 +157,7 @@ global:
nm_setting_ppp_get_mtu;
nm_setting_ppp_get_lcp_echo_failure;
nm_setting_ppp_get_lcp_echo_interval;
+ nm_setting_ppp_get_idle_seconds;
nm_setting_pppoe_error_get_type;
nm_setting_pppoe_error_quark;
nm_setting_pppoe_get_type;
diff --git a/libnm-util/nm-setting-ppp.c b/libnm-util/nm-setting-ppp.c
index 2b39a54..ee06241 100644
--- a/libnm-util/nm-setting-ppp.c
+++ b/libnm-util/nm-setting-ppp.c
@@ -84,6 +84,7 @@ typedef struct {
guint32 mtu;
guint32 lcp_echo_failure;
guint32 lcp_echo_interval;
+ char *idle_seconds;
} NMSettingPPPPrivate;
enum {
@@ -106,6 +107,7 @@ enum {
PROP_MTU,
PROP_LCP_ECHO_FAILURE,
PROP_LCP_ECHO_INTERVAL,
+ PROP_IDLE_SECONDS,
LAST_PROP
};
@@ -260,6 +262,15 @@ nm_setting_ppp_get_lcp_echo_interval (NMSettingPPP *setting)
return NM_SETTING_PPP_GET_PRIVATE (setting)->lcp_echo_interval;
}
+const char *
+nm_setting_ppp_get_idle_seconds (NMSettingPPP *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_PPP (setting), NULL);
+
+ return NM_SETTING_PPP_GET_PRIVATE (setting)->idle_seconds;
+}
+
+
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
@@ -334,6 +345,10 @@ set_property (GObject *object, guint prop_id,
case PROP_LCP_ECHO_INTERVAL:
priv->lcp_echo_interval = g_value_get_uint (value);
break;
+ case PROP_IDLE_SECONDS:
+ g_free (priv->idle_seconds);
+ priv->idle_seconds = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -401,6 +416,9 @@ get_property (GObject *object, guint prop_id,
case PROP_LCP_ECHO_INTERVAL:
g_value_set_uint (value, nm_setting_ppp_get_lcp_echo_interval (setting));
break;
+ case PROP_IDLE_SECONDS:
+ g_value_set_string (value, nm_setting_ppp_get_idle_seconds (setting));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -564,4 +582,13 @@ nm_setting_ppp_class_init (NMSettingPPPClass *setting_class)
"LCP echo interval",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
+
+ g_object_class_install_property
+ (object_class, PROP_IDLE_SECONDS,
+ g_param_spec_string (NM_SETTING_PPP_IDLE_SECONDS,
+ "Idle Seconds before disconnect",
+ "Idle Seconds before disconnect",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
}
diff --git a/libnm-util/nm-setting-ppp.h b/libnm-util/nm-setting-ppp.h
index d768e65..2ebe511 100644
--- a/libnm-util/nm-setting-ppp.h
+++ b/libnm-util/nm-setting-ppp.h
@@ -71,6 +71,7 @@ GQuark nm_setting_ppp_error_quark (void);
#define NM_SETTING_PPP_MTU "mtu"
#define NM_SETTING_PPP_LCP_ECHO_FAILURE "lcp-echo-failure"
#define NM_SETTING_PPP_LCP_ECHO_INTERVAL "lcp-echo-interval"
+#define NM_SETTING_PPP_IDLE_SECONDS "idle-seconds"
typedef struct {
NMSetting parent;
@@ -101,6 +102,7 @@ guint32 nm_setting_ppp_get_mru (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_mtu (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_lcp_echo_failure (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_lcp_echo_interval (NMSettingPPP *setting);
+const char * nm_setting_ppp_get_idle_seconds (NMSettingPPP *setting);
G_END_DECLS
diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c
index 73fd1ed..8b945dc 100644
--- a/src/ppp-manager/nm-ppp-manager.c
+++ b/src/ppp-manager/nm-ppp-manager.c
@@ -723,6 +723,7 @@ create_pppd_cmd_line (NMPPPManager *self,
const char *ppp_binary;
NMCmdLine *cmd;
const char *ppp_debug;
+ int idle_secs;
ppp_binary = nm_find_pppd ();
if (!ppp_binary) {
@@ -831,6 +832,12 @@ create_pppd_cmd_line (NMPPPManager *self,
nm_cmd_line_add_string (cmd, "plugin");
nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN);
+ idle_secs = nm_setting_ppp_get_idle_seconds (setting) ? atoi (nm_setting_ppp_get_idle_seconds (setting)) : 0;
+ if (idle_secs > 0) {
+ nm_cmd_line_add_string (cmd, "idle");
+ nm_cmd_line_add_int (cmd, idle_secs);
+ }
+
return cmd;
}
diff --git a/src/connection-editor/ce-page-ppp.glade b/src/connection-editor/ce-page-ppp.glade
index 6b4c5b9..be38ec8 100644
--- a/src/connection-editor/ce-page-ppp.glade
+++ b/src/connection-editor/ce-page-ppp.glade
@@ -298,9 +298,103 @@
<property name="position">2</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkVBox" id="vbox10">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkLabel" id="label32">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Misc</b></property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkLabel" id="label33">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Number of idle seconds before disconect</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkEntry" id="ppp_idle_seconds_before_disconnect">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="visibility">True</property>
+ <property name="max_length">6</property>
+ <property name="text" translatable="yes">0</property>
+ <property name="has_frame">True</property>
+ <property name="invisible_char">●</property>
+ <property name="activates_default">False</property>
+ <property name="width_chars">6</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+
</widget>
</child>
</widget>
+
<widget class="GtkDialog" id="auth_methods_dialog">
<property name="extension_events">all</property>
<property name="border_width">5</property>
diff --git a/src/connection-editor/page-ppp.c b/src/connection-editor/page-ppp.c
index 0e3567a..c4fd82c 100644
--- a/src/connection-editor/page-ppp.c
+++ b/src/connection-editor/page-ppp.c
@@ -67,6 +67,8 @@ typedef struct {
GtkToggleButton *send_ppp_echo;
+ GtkEntry *idle_seconds_before_disconnect;
+
GtkWindowGroup *window_group;
gboolean window_added;
char *connection_id;
@@ -92,6 +94,7 @@ ppp_private_init (CEPagePpp *self)
priv->allow_deflate = GTK_TOGGLE_BUTTON (glade_xml_get_widget (xml, "ppp_allow_deflate"));
priv->use_vj_comp = GTK_TOGGLE_BUTTON (glade_xml_get_widget (xml, "ppp_usevj"));
priv->send_ppp_echo = GTK_TOGGLE_BUTTON (glade_xml_get_widget (xml, "ppp_send_echo_packets"));
+ priv->idle_seconds_before_disconnect = GTK_ENTRY (glade_xml_get_widget (xml, "ppp_idle_seconds_before_disconnect"));
}
static void
@@ -213,6 +216,7 @@ populate_ui (CEPagePpp *self, NMConnection *connection)
NMSettingPPP *setting = priv->setting;
gboolean require_mppe, require_mppe_128, mppe_stateful, nobsdcomp, nodeflate, no_vj_comp;
guint32 lcp_echo_interval;
+ const char *str;
g_object_get (setting,
NM_SETTING_PPP_REFUSE_PAP, &priv->refuse_pap,
@@ -252,6 +256,10 @@ populate_ui (CEPagePpp *self, NMConnection *connection)
gtk_toggle_button_set_active (priv->send_ppp_echo, (lcp_echo_interval > 0) ? TRUE : FALSE);
g_signal_connect_swapped (priv->send_ppp_echo, "toggled", G_CALLBACK (ce_page_changed), self);
+
+ str = nm_setting_ppp_get_idle_seconds(setting);
+ gtk_entry_set_text (priv->idle_seconds_before_disconnect, str ? str : "0");
+
}
static void
@@ -328,6 +336,7 @@ ui_to_setting (CEPagePpp *self)
gboolean no_vj_comp;
guint32 lcp_echo_failure;
guint32 lcp_echo_interval;
+ const char *idle_seconds_before_disconnect;
require_mppe = gtk_toggle_button_get_active (priv->use_mppe);
require_mppe_128 = gtk_toggle_button_get_active (priv->mppe_require_128);
@@ -345,6 +354,10 @@ ui_to_setting (CEPagePpp *self)
lcp_echo_interval = 0;
}
+ idle_seconds_before_disconnect = gtk_entry_get_text (priv->idle_seconds_before_disconnect);
+ if (atoi(idle_seconds_before_disconnect) < 0)
+ idle_seconds_before_disconnect = "0";
+
g_object_set (priv->setting,
NM_SETTING_PPP_REFUSE_EAP, priv->refuse_eap,
NM_SETTING_PPP_REFUSE_PAP, priv->refuse_pap,
@@ -359,6 +372,7 @@ ui_to_setting (CEPagePpp *self)
NM_SETTING_PPP_MPPE_STATEFUL, mppe_stateful,
NM_SETTING_PPP_LCP_ECHO_FAILURE, lcp_echo_failure,
NM_SETTING_PPP_LCP_ECHO_INTERVAL, lcp_echo_interval,
+ NM_SETTING_PPP_IDLE_SECONDS, idle_seconds_before_disconnect,
NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]