[PATCH 1/1] ppp: Add MAX_IPCP_FAILURE to avoid timeout quickly

Zhenhua Zhang zhenhua.zhang at intel.com
Fri Jul 9 01:40:35 PDT 2010


We use IPCP NAK response to stall the progress of acquiring the client
IP address from DHCP server. So we need to increase the max failure of
NAKs in IPCP handshaking.
---
 gatchat/ppp_cp.c   |    8 ++++++--
 gatchat/ppp_cp.h   |    2 +-
 gatchat/ppp_ipcp.c |   10 +++++++++-
 gatchat/ppp_lcp.c  |    2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c
index 647e241..e013283 100644
--- a/gatchat/ppp_cp.c
+++ b/gatchat/ppp_cp.c
@@ -997,7 +997,7 @@ void pppcp_set_local_options(struct pppcp_data *pppcp,
 }
 
 struct pppcp_data *pppcp_new(GAtPPP *ppp, const struct pppcp_proto *proto,
-				gboolean dormant)
+				gboolean dormant, int max_failure)
 {
 	struct pppcp_data *data;
 
@@ -1016,7 +1016,11 @@ struct pppcp_data *pppcp_new(GAtPPP *ppp, const struct pppcp_proto *proto,
 	data->terminate_timer_data.max_counter = MAX_TERMINATE;
 	data->config_timer_data.data = data;
 	data->terminate_timer_data.data = data;
-	data->max_failure = MAX_FAILURE;
+
+	if (max_failure)
+		data->max_failure = max_failure;
+	else
+		data->max_failure = MAX_FAILURE;
 
 	data->ppp = ppp;
 	data->driver = proto;
diff --git a/gatchat/ppp_cp.h b/gatchat/ppp_cp.h
index 56a20e0..1e69562 100644
--- a/gatchat/ppp_cp.h
+++ b/gatchat/ppp_cp.h
@@ -104,7 +104,7 @@ guint8 ppp_option_iter_get_length(struct ppp_option_iter *iter);
 const guint8 *ppp_option_iter_get_data(struct ppp_option_iter *iter);
 
 struct pppcp_data *pppcp_new(GAtPPP *ppp, const struct pppcp_proto *proto,
-				gboolean dormant);
+				gboolean dormant, int max_failure);
 void pppcp_free(struct pppcp_data *data);
 
 void pppcp_set_data(struct pppcp_data *pppcp, gpointer data);
diff --git a/gatchat/ppp_ipcp.c b/gatchat/ppp_ipcp.c
index d64bded..3aa9eec 100644
--- a/gatchat/ppp_ipcp.c
+++ b/gatchat/ppp_ipcp.c
@@ -63,6 +63,8 @@ enum ipcp_option_types {
 #define REQ_OPTION_NBNS1	0x08
 #define REQ_OPTION_NBNS2	0x10
 
+#define MAX_IPCP_FAILURE	100
+
 struct ipcp_data {
 	guint8 options[MAX_CONFIG_OPTION_SIZE];
 	guint16 options_len;
@@ -472,7 +474,13 @@ struct pppcp_data *ipcp_new(GAtPPP *ppp, gboolean is_server, guint32 ip)
 	if (!ipcp)
 		return NULL;
 
-	pppcp = pppcp_new(ppp, &ipcp_proto, FALSE);
+	/*
+	 * Some 3G modems use repeated IPCP NAKs as the way of stalling
+	 * util sending us the client IP address. So we increase the
+	 * default number of NAKs we accept before start treating them
+	 * as rejects.
+	 */
+	pppcp = pppcp_new(ppp, &ipcp_proto, FALSE, MAX_IPCP_FAILURE);
 	if (!pppcp) {
 		g_printerr("Failed to allocate PPPCP struct\n");
 		g_free(ipcp);
diff --git a/gatchat/ppp_lcp.c b/gatchat/ppp_lcp.c
index 3cfab5c..5838ebd 100644
--- a/gatchat/ppp_lcp.c
+++ b/gatchat/ppp_lcp.c
@@ -313,7 +313,7 @@ struct pppcp_data *lcp_new(GAtPPP *ppp, gboolean is_server)
 	if (!lcp)
 		return NULL;
 
-	pppcp = pppcp_new(ppp, &lcp_proto, is_server);
+	pppcp = pppcp_new(ppp, &lcp_proto, is_server, 0);
 	if (!pppcp) {
 		g_free(lcp);
 		return NULL;
-- 
1.6.3.3



More information about the ofono mailing list