gbproxy: Add gprs_gb_message_name function

This function tries to get an accurate name for the message even if
the parsing has been aborted due to message errors.

The patch also moves the settings of the BSSGP related fields in
parse_ctx from behind to the front of bssgp_tlv_parse, to get more
information in the case of failure. This is now consistent with the
handling of the llc and g48_hdr fields.

Id addition, gprs_gb_log_parse_context now uses the new function to
derive a more accurate message name.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2014-10-09 12:04:56 +02:00 committed by Holger Hans Peter Freyther
parent cc8856f9d3
commit 9b07135b92
2 changed files with 29 additions and 4 deletions

View File

@ -51,5 +51,8 @@ int gprs_gb_parse_llc(uint8_t *llc, size_t llc_len,
int gprs_gb_parse_bssgp(uint8_t *bssgp, size_t bssgp_len,
struct gprs_gb_parse_context *parse_ctx);
const char *gprs_gb_message_name(const struct gprs_gb_parse_context *parse_ctx,
const char *default_msg_name);
void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
const char *default_msg_name);

View File

@ -564,15 +564,15 @@ int gprs_gb_parse_bssgp(uint8_t *bssgp, size_t bssgp_len,
data_len = bssgp_len - sizeof(*bgph);
}
if (bssgp_tlv_parse(tp, data, data_len) < 0)
return 0;
parse_ctx->pdu_type = pdu_type;
parse_ctx->bud_hdr = budh;
parse_ctx->bgp_hdr = bgph;
parse_ctx->bssgp_data = data;
parse_ctx->bssgp_data_len = data_len;
if (bssgp_tlv_parse(tp, data, data_len) < 0)
return 0;
if (budh)
parse_ctx->tlli_enc = (uint8_t *)&budh->tlli;
@ -626,7 +626,7 @@ int gprs_gb_parse_bssgp(uint8_t *bssgp, size_t bssgp_len,
void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
const char *default_msg_name)
{
const char *msg_name = default_msg_name;
const char *msg_name;
const char *sep = "";
if (!parse_ctx->tlli_enc &&
@ -635,6 +635,8 @@ void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
!parse_ctx->imsi)
return;
msg_name = gprs_gb_message_name(parse_ctx, default_msg_name);
if (parse_ctx->llc_msg_name)
msg_name = parse_ctx->llc_msg_name;
@ -713,3 +715,23 @@ void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
LOGPC(DGPRS, LOGL_DEBUG, "\n");
}
const char *gprs_gb_message_name(const struct gprs_gb_parse_context *parse_ctx,
const char *default_msg_name)
{
if (parse_ctx->llc_msg_name)
return parse_ctx->llc_msg_name;
if (parse_ctx->g48_hdr)
return "GMM";
if (parse_ctx->llc)
return "LLC";
if (parse_ctx->bud_hdr)
return "BSSGP-UNITDATA";
if (parse_ctx->bgp_hdr)
return "BSSGP";
return "unknown";
}