Skip to contentSkip to conversation

ppp option cleanups

PATCH New Kristen Carlson Accardi 1 participant 4 messages Apr 12, 2010

lore
Share & tools
lore
#0 lore raw

cover ppp option cleanups

Remove all references to magic number, as we will not be supporting loopback detection (resend)

Remove all references to pfc and acfc, we will not be implementing this.

Nak a config option request for any other authentication protocol except CHAP/MD5

Kristen Carlson Accardi (3):
ppp: remove references to magic number
ppp: remove pfc and acfc
ppp: nak unknown auth protocol

 gatchat/gatppp.c   |   26 --------------------------
 gatchat/ppp.h      |   14 ++++++++++----
 gatchat/ppp_auth.c |    2 --
 gatchat/ppp_cp.c   |    8 +++++++-
 gatchat/ppp_lcp.c  |   35 ++++++++++++++++++++++++-----------
 5 files changed, 41 insertions(+), 44 deletions(-)
#1 lore raw

PATCH 1/3 ppp: remove references to magic number

We will not support loopback detection.

---
 gatchat/ppp_cp.c  |    8 +++++++-
 gatchat/ppp_lcp.c |    6 +-----
 2 files changed, 8 insertions(+), 6 deletions(-)
gatchat/ppp_cp.c +7 -1
index 5ac0196..83f5052 100644
@@ -574,7 +574,7 @@ static void pppcp_send_echo_reply(struct pppcp_data *data,
 	 */
 	packet->identifier = header->identifier;
 
-	/* magic number? */
+	/* magic number will always be zero */
 	ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
 			ntohs(packet->length));
 
@@ -855,6 +855,12 @@ static guint8 pppcp_process_protocol_reject(struct pppcp_data *data,
 	return RXJ_MINUS;
 }
 
+/*
+ * For Echo-Request, Echo-Reply, and Discard-Request, we will not
+ * bother checking the magic number of the packet, because we will
+ * never send an echo or discard request.  We can't reliably detect
+ * loop back anyway, since we don't negotiate a magic number.
+ */
 static guint8 pppcp_process_echo_request(struct pppcp_data *data,
 					struct pppcp_packet *packet)
 {
gatchat/ppp_lcp.c +1 -5
index a384a0d..5dfe4aa 100644
@@ -64,7 +64,6 @@ enum lcp_options {
 #define REQ_OPTION_ACCM 0x1
 
 struct lcp_data {
-	guint32 magic_number;
 	guint8 options[MAX_CONFIG_OPTION_SIZE];
 	guint16 options_len;
 	guint8 req_options;
@@ -157,7 +156,6 @@ static enum rcr_result lcp_rcr(struct pppcp_data *pppcp,
 					const struct pppcp_packet *packet,
 					guint8 **new_options, guint16 *new_len)
 {
-	struct lcp_data *lcp = pppcp_get_data(pppcp);
 	GAtPPP *ppp = pppcp_get_ppp(pppcp);
 	struct ppp_option_iter iter;
 
@@ -180,7 +178,6 @@ static enum rcr_result lcp_rcr(struct pppcp_data *pppcp,
 			if (magic == 0)
 				return RCR_REJECT;
 
-			/* TODO: Handle loopback */
 			break;
 		}
 		default:
@@ -201,8 +198,7 @@ static enum rcr_result lcp_rcr(struct pppcp_data *pppcp,
 			ppp_set_auth(ppp, ppp_option_iter_get_data(&iter));
 			break;
 		case MAGIC_NUMBER:
-			lcp->magic_number =
-				get_host_long(ppp_option_iter_get_data(&iter));
+			/* don't care */
 			break;
 		case PFC:
 			ppp_set_pfc(ppp, TRUE);
Signature · 1 line
1.6.6.1
#2 lore raw

PATCH 2/3 ppp: remove pfc and acfc

In reply to Kristen Carlson Accardi

We will not support pfc or acfc

---
 gatchat/gatppp.c  |   26 --------------------------
 gatchat/ppp.h     |    4 ----
 gatchat/ppp_lcp.c |    6 +-----
 3 files changed, 1 insertions(+), 35 deletions(-)
gatchat/gatppp.c +0 -26
index b98ab14..d9506c6 100644
@@ -69,8 +69,6 @@ struct _GAtPPP {
 	gint mru;
 	char user_name[256];
 	char passwd[256];
-	gboolean pfc;
-	gboolean acfc;
 	guint32 xmit_accm[8];
 	guint32 recv_accm;
 	GIOChannel *modem;
@@ -137,7 +135,6 @@ static void ppp_put(GAtPPP *ppp, guint8 *buf, int *pos,
 	*pos = i;
 }
 
-/* XXX implement PFC and ACFC */
 static struct frame_buffer *ppp_encode(GAtPPP *ppp, guint8 *data, int len)
 {
 	int pos = 0;
@@ -212,7 +209,6 @@ static void ppp_recv(GAtPPP *ppp, struct frame_buffer *frame)
 	};
 }
 
-/* XXX - Implement PFC and ACFC */
 static struct frame_buffer *ppp_decode(GAtPPP *ppp, guint8 *frame)
 {
 	guint8 *data;
@@ -469,26 +465,6 @@ void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm)
 	ppp->xmit_accm[0] = accm;
 }
 
-void ppp_set_pfc(GAtPPP *ppp, gboolean pfc)
-{
-	ppp->pfc = pfc;
-}
-
-gboolean ppp_get_pfc(GAtPPP *ppp)
-{
-	return ppp->pfc;
-}
-
-void ppp_set_acfc(GAtPPP *ppp, gboolean acfc)
-{
-	ppp->acfc = acfc;
-}
-
-gboolean ppp_get_acfc(GAtPPP *ppp)
-{
-	return ppp->acfc;
-}
-
 /* Administrative Open */
 void g_at_ppp_open(GAtPPP *ppp)
 {
@@ -593,8 +569,6 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem)
 	ppp->recv_accm = ~0U;
 	ppp->xmit_accm[0] = ~0U;
 	ppp->xmit_accm[3] = 0x60000000; /* 0x7d, 0x7e */
-	ppp->pfc = FALSE;
-	ppp->acfc = FALSE;
 
 	ppp->index = 0;
 
gatchat/ppp.h +0 -4
index 0354050..87541c9 100644
@@ -95,10 +95,6 @@ void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen);
 void ppp_set_auth(GAtPPP *ppp, const guint8 *auth_data);
 void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
 void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
-void ppp_set_pfc(GAtPPP *ppp, gboolean pfc);
-gboolean ppp_get_pfc(GAtPPP *ppp);
-void ppp_set_acfc(GAtPPP *ppp, gboolean acfc);
-gboolean ppp_get_acfc(GAtPPP *ppp);
 struct pppcp_data * lcp_new(GAtPPP *ppp);
 void lcp_free(struct pppcp_data *lcp);
 void lcp_open(struct pppcp_data *data);
gatchat/ppp_lcp.c +1 -5
index 5dfe4aa..429fa49 100644
@@ -198,13 +198,9 @@ static enum rcr_result lcp_rcr(struct pppcp_data *pppcp,
 			ppp_set_auth(ppp, ppp_option_iter_get_data(&iter));
 			break;
 		case MAGIC_NUMBER:
-			/* don't care */
-			break;
 		case PFC:
-			ppp_set_pfc(ppp, TRUE);
-			break;
 		case ACFC:
-			ppp_set_acfc(ppp, TRUE);
+			/* don't care */
 			break;
 		}
 	}
Signature · 1 line
1.6.6.1
#3 lore raw

PATCH 3/3 ppp: nak unknown auth protocol

In reply to Kristen Carlson Accardi

If we are sent a Config-Request with anything other than CHAP/MD5, send a NAK.

---
 gatchat/ppp.h      |   10 ++++++++++
 gatchat/ppp_auth.c |    2 --
 gatchat/ppp_lcp.c  |   25 +++++++++++++++++++++++--
 3 files changed, 33 insertions(+), 4 deletions(-)
gatchat/ppp.h +10 -0
index 87541c9..3eaf808 100644
@@ -25,6 +25,7 @@
 #define CHAP_PROTOCOL	0xc223
 #define IPCP_PROTO	0x8021
 #define PPP_IP_PROTO	0x0021
+#define MD5		5
 
 enum ppp_event {
 	PPP_UP = 1,
@@ -61,12 +62,21 @@ static inline guint16 __get_unaligned_short(const void *p)
 	return ptr->s;
 }
 
+static inline void __put_unaligned_short(void *p, guint16 val)
+{
+	struct packed_short *ptr = p;
+	ptr->s = val;
+}
+
 #define get_host_long(p) \
 	(ntohl(__get_unaligned_long(p)))
 
 #define get_host_short(p) \
 	(ntohs(__get_unaligned_short(p)))
 
+#define put_network_short(p, val) \
+	(__put_unaligned_short(p, htons(val)))
+
 #define ppp_info(packet) \
 	(packet + 4)
 
gatchat/ppp_auth.c +0 -2
index 3f69fa3..e04f708 100644
@@ -35,8 +35,6 @@
 #include "gatppp.h"
 #include "ppp.h"
 
-#define MD5	5
-
 struct chap_header {
 	guint8 code;
 	guint8 identifier;
gatchat/ppp_lcp.c +23 -2
index 429fa49..ab83d9e 100644
@@ -163,9 +163,30 @@ static enum rcr_result lcp_rcr(struct pppcp_data *pppcp,
 
 	while (ppp_option_iter_next(&iter) == TRUE) {
 		switch (ppp_option_iter_get_type(&iter)) {
-		case ACCM:
-		/* TODO check to make sure it's a proto we recognize */
 		case AUTH_PROTO:
+		{
+			const guint8 *option_data =
+				ppp_option_iter_get_data(&iter);
+			guint16 proto = get_host_short(option_data);
+			guint8 method = option_data[2];
+
+			if ((proto != CHAP_PROTOCOL) || (method != MD5)) {
+				guint8 *option = g_try_malloc0(5);
+				if (!option)
+					return RCR_REJECT;
+
+				option[0] = AUTH_PROTO;
+				option[1] = 5;
+				put_network_short(&option[2], CHAP_PROTOCOL);
+				option[4] = MD5;
+				*new_options = option;
+				*new_len = 5;
+				return RCR_NAK;
+			}
+			break;
+		}
+
+		case ACCM:
 		case PFC:
 		case ACFC:
 			break;
Signature · 1 line
1.6.6.1