From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 4/5] ppp: use common code to get options from pppcp packet data
Date: Fri, 26 Mar 2010 18:34:29 -0700 [thread overview]
Message-ID: <1269653670-31352-5-git-send-email-kristen@linux.intel.com> (raw)
In-Reply-To: <1269653670-31352-1-git-send-email-kristen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 5009 bytes --]
---
gatchat/ppp_cp.c | 71 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c
index 263fa8b..d7d70b7 100644
--- a/gatchat/ppp_cp.c
+++ b/gatchat/ppp_cp.c
@@ -1140,6 +1140,22 @@ static void remove_config_option(gpointer elem, gpointer user_data)
data->config_options = g_list_delete_link(data->config_options, list);
}
+static struct ppp_option *extract_ppp_option(guint8 *packet_data)
+{
+ struct ppp_option *option;
+ guint8 otype = packet_data[0];
+ guint8 olen = packet_data[1];
+
+ option = g_try_malloc0(olen);
+ if (option == NULL)
+ return NULL;
+
+ option->type = otype;
+ option->length = olen;
+ memcpy(option->data, &packet_data[2], olen-2);
+ return option;
+}
+
static guint8 pppcp_process_configure_request(struct pppcp_data *data,
struct pppcp_packet *packet)
{
@@ -1157,14 +1173,13 @@ static guint8 pppcp_process_configure_request(struct pppcp_data *data,
* check the options.
*/
while (i < len) {
- guint8 otype = packet->data[i];
- guint8 olen = packet->data[i+1];
- option = g_try_malloc0(olen);
+ option = extract_ppp_option(&packet->data[i]);
if (option == NULL)
break;
- option->type = otype;
- option->length = olen;
- memcpy(option->data, &packet->data[i+2], olen-2);
+
+ /* skip ahead to the next option */
+ i += option->length;
+
if (action->option_scan)
rval = action->option_scan(option, data);
switch (rval) {
@@ -1182,10 +1197,9 @@ static guint8 pppcp_process_configure_request(struct pppcp_data *data,
option);
break;
case OPTION_ERR:
- g_printerr("unhandled option type %d\n", otype);
+ g_printerr("unhandled option type %d\n", option->type);
+ g_free(option);
}
- /* skip ahead to the next option */
- i += olen;
}
/* make sure all required config options were included */
@@ -1242,16 +1256,12 @@ static guint8 pppcp_process_configure_ack(struct pppcp_data *data,
* and apply them.
*/
while (i < len) {
- guint8 otype = packet->data[i];
- guint8 olen = packet->data[i + 1];
- acked_option = g_try_malloc0(olen);
+ acked_option = extract_ppp_option(&packet->data[i]);
if (acked_option == NULL)
break;
- acked_option->type = otype;
- acked_option->length = olen;
- memcpy(acked_option->data, &packet->data[i + 2], olen - 2);
list = g_list_find_custom(data->config_options,
- GUINT_TO_POINTER((guint) otype), is_option);
+ GUINT_TO_POINTER((guint) acked_option->type),
+ is_option);
if (list) {
/*
* once we've applied the option, delete it from
@@ -1266,10 +1276,11 @@ static guint8 pppcp_process_configure_ack(struct pppcp_data *data,
g_list_delete_link(data->config_options, list);
} else
g_printerr("oops -- found acked option %d we didn't request\n", acked_option->type);
- g_free(acked_option);
/* skip ahead to the next option */
- i += olen;
+ i += acked_option->length;
+
+ g_free(acked_option);
}
return RCA;
}
@@ -1300,14 +1311,13 @@ static guint8 pppcp_process_configure_nak(struct pppcp_data *data,
* modify a value there, or add a new option.
*/
while (i < len) {
- guint8 otype = packet->data[i];
- guint8 olen = packet->data[i+1];
- naked_option = g_try_malloc0(olen);
+ naked_option = extract_ppp_option(&packet->data[i]);
if (naked_option == NULL)
break;
- naked_option->type = otype;
- naked_option->length = olen;
- memcpy(naked_option->data, &packet->data[i + 2], olen - 2);
+
+ /* skip ahead to the next option */
+ i += naked_option->length;
+
if (action->option_scan)
rval = action->option_scan(naked_option, data);
if (rval == OPTION_ACCEPT) {
@@ -1316,7 +1326,8 @@ static guint8 pppcp_process_configure_nak(struct pppcp_data *data,
* match.
*/
list = g_list_find_custom(data->config_options,
- GUINT_TO_POINTER((guint) otype), is_option);
+ GUINT_TO_POINTER((guint) naked_option->type),
+ is_option);
if (list) {
/* modify current option value to match */
config_option = list->data;
@@ -1326,10 +1337,11 @@ static guint8 pppcp_process_configure_nak(struct pppcp_data *data,
* we need to reallocate
*/
if ((config_option->length ==
- naked_option->length) && (olen - 2)) {
+ naked_option->length) &&
+ (naked_option - 2)) {
memcpy(config_option->data,
- naked_option->data,
- olen - 2);
+ naked_option->data,
+ naked_option->length - 2);
} else {
/* XXX implement this */
g_printerr("uh oh, option value doesn't match\n");
@@ -1344,9 +1356,6 @@ static guint8 pppcp_process_configure_nak(struct pppcp_data *data,
g_printerr("oops, option wasn't acceptable\n");
g_free(naked_option);
}
-
- /* skip ahead to the next option */
- i += olen;
}
return RCN;
}
--
1.6.6.1
next prev parent reply other threads:[~2010-03-27 1:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-27 1:34 [PATCH 0/5] ppp: error path fixes Kristen Carlson Accardi
2010-03-27 1:34 ` [PATCH 1/5] ppp: fix segfault in pppcp_send_code_reject() Kristen Carlson Accardi
2010-03-27 1:34 ` [PATCH 2/5] ppp: comment fix Kristen Carlson Accardi
2010-03-27 1:34 ` [PATCH 3/5] ppp: send Protocol-Reject Kristen Carlson Accardi
2010-03-27 1:34 ` Kristen Carlson Accardi [this message]
2010-03-27 1:34 ` [PATCH 5/5] ppp: handle Config-Reject Kristen Carlson Accardi
2010-03-27 2:29 ` [PATCH 0/5] ppp: error path fixes Marcel Holtmann
2010-03-27 4:39 ` Kristen Carlson Accardi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269653670-31352-5-git-send-email-kristen@linux.intel.com \
--to=kristen@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox