From 9dd6254a264279cc92cb2cd5cd8a368653138e26 Mon Sep 17 00:00:00 2001 From: Andrew Elder Date: Fri, 31 May 2013 10:34:09 -0400 Subject: [PATCH] mrp: client notification string updated to always include the registrar and applicant states --- daemons/mrpd/mmrp.c | 31 ++++++++------------------ daemons/mrpd/msrp.c | 24 +++++++++++--------- daemons/mrpd/mvrp.c | 39 +++++++++++---------------------- examples/mrp_client/mrpdhelper.c | 47 +++++++++++++++++++++++++++++----------- 4 files changed, 70 insertions(+), 71 deletions(-) diff --git a/daemons/mrpd/mmrp.c b/daemons/mrpd/mmrp.c index 1259740..53ea2ee 100644 --- a/daemons/mrpd/mmrp.c +++ b/daemons/mrpd/mmrp.c @@ -1317,9 +1317,9 @@ int mmrp_txpdu(void) int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify) { char *msgbuf; - char *stage; char *variant; char *regsrc; + char mrp_state[8]; client_t *client; if (NULL == attrib) @@ -1329,13 +1329,12 @@ int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify) if (NULL == msgbuf) return -1; - stage = variant = regsrc = NULL; + variant = regsrc = NULL; - stage = (char *)malloc(128); variant = (char *)malloc(128); regsrc = (char *)malloc(128); - if ((NULL == stage) || (NULL == variant) || (NULL == regsrc)) + if ((NULL == variant) || (NULL == regsrc)) goto free_msgbuf; memset(msgbuf, 0, MAX_MRPD_CMDSZ); @@ -1358,29 +1357,19 @@ int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify) attrib->registrar.macaddr[2], attrib->registrar.macaddr[3], attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); - switch (attrib->registrar.mrp_state) { - case MRP_IN_STATE: - sprintf(stage, "MIN %s %s\n", variant, regsrc); - break; - case MRP_LV_STATE: - sprintf(stage, "MLV %s %s\n", variant, regsrc); - break; - case MRP_MT_STATE: - sprintf(stage, "MMT %s %s\n", variant, regsrc); - break; - default: - break; - } + + mrp_decode_state(&attrib->registrar, &attrib->applicant, + mrp_state, sizeof(mrp_state)); switch (notify) { case MRP_NOTIFY_NEW: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MNE %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MNE %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_JOIN: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MJO %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MJO %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_LV: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MLE %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MLE %s %s %s\n", variant, regsrc, mrp_state); break; default: goto free_msgbuf; @@ -1396,8 +1385,6 @@ int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify) free_msgbuf: if (variant) free(variant); - if (stage) - free(stage); if (regsrc) free(regsrc); free(msgbuf); diff --git a/daemons/mrpd/msrp.c b/daemons/mrpd/msrp.c index 46f088f..3405d59 100644 --- a/daemons/mrpd/msrp.c +++ b/daemons/mrpd/msrp.c @@ -1479,7 +1479,11 @@ msrp_emit_domainvectors(unsigned char *msgbuf, unsigned char *msgbuf_eof, uint8_t srclassprio_firstval; uint16_t srclassvid_firstval; int attriblistlen; - struct msrp_attribute *attrib, *vattrib; + struct msrp_attribute *attrib; +/* pending review and deletion */ +#ifdef MSRP_AGGREGATE_DOMAINS_VECTORS + struct msrp_attribute *vattrib; +#endif mrpdu_message_t *mrpdu_msg; unsigned char *mrpdu_msg_ptr = msgbuf; unsigned char *mrpdu_msg_eof = msgbuf_eof; @@ -2429,9 +2433,9 @@ int msrp_txpdu(void) int msrp_send_notifications(struct msrp_attribute *attrib, int notify) { char *msgbuf; - char *stage; char *variant; char *regsrc; + char mrp_state[8]; client_t *client; if (NULL == attrib) @@ -2441,13 +2445,12 @@ int msrp_send_notifications(struct msrp_attribute *attrib, int notify) if (NULL == msgbuf) return -1; - stage = variant = regsrc = NULL; + variant = regsrc = NULL; - stage = (char *)malloc(128); variant = (char *)malloc(128); regsrc = (char *)malloc(128); - if ((NULL == stage) || (NULL == variant) || (NULL == regsrc)) + if ((NULL == variant) || (NULL == regsrc)) goto free_msgbuf; memset(msgbuf, 0, MAX_MRPD_CMDSZ); @@ -2531,15 +2534,18 @@ int msrp_send_notifications(struct msrp_attribute *attrib, int notify) attrib->registrar.macaddr[3], attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); + mrp_decode_state(&attrib->registrar, &attrib->applicant, + mrp_state, sizeof(mrp_state)); + switch (notify) { case MRP_NOTIFY_NEW: - sprintf(msgbuf, "SNE %s %s\n", variant, regsrc); + sprintf(msgbuf, "SNE %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_JOIN: - sprintf(msgbuf, "SJO %s %s\n", variant, regsrc); + sprintf(msgbuf, "SJO %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_LV: - sprintf(msgbuf, "SLE %s %s\n", variant, regsrc); + sprintf(msgbuf, "SLE %s %s %s\n", variant, regsrc, mrp_state); break; default: goto free_msgbuf; @@ -2557,8 +2563,6 @@ int msrp_send_notifications(struct msrp_attribute *attrib, int notify) free(regsrc); if (variant) free(variant); - if (stage) - free(stage); free(msgbuf); return 0; } diff --git a/daemons/mrpd/mvrp.c b/daemons/mrpd/mvrp.c index b84f439..fdad327 100644 --- a/daemons/mrpd/mvrp.c +++ b/daemons/mrpd/mvrp.c @@ -622,7 +622,7 @@ mvrp_emit_vidvectors(unsigned char *msgbuf, unsigned char *msgbuf_eof, switch (attrib->applicant.sndmsg) { case MRP_SND_IN: /* - * If 'In' in indicated by the applicant attribute, the + * If 'In' is indicated by the applicant attribute, then * look at the registrar state to determine whether to * send an In (if registrar is also In) or an Mt if the * registrar is either Mt or Lv. @@ -639,7 +639,7 @@ mvrp_emit_vidvectors(unsigned char *msgbuf, unsigned char *msgbuf_eof, vectevt[0] = MRPDU_LV; break; case MRP_SND_JOIN: - /* IF 'Join' in indicated by the applicant, look at + /* If 'Join' in indicated by the applicant, look at * the corresponding registrar state to determine whether * to send a JoinIn (if the registar state is 'In') or * a JoinMt if the registrar state is MT or LV. @@ -681,7 +681,7 @@ mvrp_emit_vidvectors(unsigned char *msgbuf, unsigned char *msgbuf_eof, switch (vattrib->applicant.sndmsg) { case MRP_SND_IN: /* - * If 'In' in indicated by the applicant attribute, the + * If 'In' is indicated by the applicant attribute, then * look at the registrar state to determine whether to * send an In (if registrar is also In) or an Mt if the * registrar is either Mt or Lv. @@ -699,7 +699,7 @@ mvrp_emit_vidvectors(unsigned char *msgbuf, unsigned char *msgbuf_eof, vectevt[vectevt_idx] = MRPDU_LV; break; case MRP_SND_JOIN: - /* IF 'Join' in indicated by the applicant, look at + /* If 'Join' in indicated by the applicant, look at * the corresponding registrar state to determine whether * to send a JoinIn (if the registar state is 'In') or * a JoinMt if the registrar state is MT or LV. @@ -907,9 +907,9 @@ int mvrp_txpdu(void) int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify) { char *msgbuf; - char *stage; char *variant; char *regsrc; + char mrp_state[8]; client_t *client; if (NULL == attrib) @@ -919,13 +919,12 @@ int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify) if (NULL == msgbuf) return -1; - stage = variant = regsrc = NULL; + variant = regsrc = NULL; - stage = (char *)malloc(128); variant = (char *)malloc(128); regsrc = (char *)malloc(128); - if ((NULL == stage) || (NULL == variant) || (NULL == regsrc)) + if ((NULL == variant) || (NULL == regsrc)) goto free_msgbuf; memset(msgbuf, 0, MAX_MRPD_CMDSZ); @@ -939,29 +938,19 @@ int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify) attrib->registrar.macaddr[3], attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); - switch (attrib->registrar.mrp_state) { - case MRP_IN_STATE: - sprintf(stage, "VIN %s %s", variant, regsrc); - break; - case MRP_LV_STATE: - sprintf(stage, "VLV %s %s", variant, regsrc); - break; - case MRP_MT_STATE: - sprintf(stage, "VMT %s %s", variant, regsrc); - break; - default: - break; - } + mrp_decode_state(&attrib->registrar, &attrib->applicant, + mrp_state, sizeof(mrp_state)); + switch (notify) { case MRP_NOTIFY_NEW: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VNE %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VNE %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_JOIN: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VJO %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VJO %s %s %s\n", variant, regsrc, mrp_state); break; case MRP_NOTIFY_LV: - snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VLE %s\n", stage); + snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VLE %s %s %s\n", variant, regsrc, mrp_state); break; default: goto free_msgbuf; @@ -979,8 +968,6 @@ int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify) free(regsrc); if (variant) free(variant); - if (stage) - free(stage); free(msgbuf); return 0; } diff --git a/examples/mrp_client/mrpdhelper.c b/examples/mrp_client/mrpdhelper.c index 6678331..0c32774 100755 --- a/examples/mrp_client/mrpdhelper.c +++ b/examples/mrp_client/mrpdhelper.c @@ -72,6 +72,15 @@ struct app_state_to_enum { static int parse_app_state(char *sz, struct mrpdhelper_notify *n) { int i; + char *r; + + r = strstr(sz, "R="); + if (r) + r = strchr(r, ' '); + if (!r) + return -1; + + sz = r + 1; /* loop over mrp_app_state_mapping struct */ for (i=0; i < 12; i++) { @@ -88,6 +97,15 @@ static int parse_app_state(char *sz, struct mrpdhelper_notify *n) static int parse_state(char *sz, struct mrpdhelper_notify *n) { + char *r; + + r = strstr(sz, "R="); + if (r) + r = strchr(r, ' '); + if (!r) + return -1; + sz = r + 4; + if (strncmp(sz, "IN", 2) == 0) { n->state = mrpdhelper_state_in; } else if (strncmp(sz, "LV", 3) == 0) { @@ -133,7 +151,7 @@ static int parse_registrar(char *sz, struct mrpdhelper_notify *n, char **rpos) static int parse_mvrp(char *sz, size_t len, struct mrpdhelper_notify *n) { /* format - VIN VJO 1234 R=112233445566 + VJO 1234 R=112233445566 len = 28 */ if (len < 28) @@ -142,13 +160,17 @@ static int parse_mvrp(char *sz, size_t len, struct mrpdhelper_notify *n) if (parse_notification(&sz[1], n) < 0) return -1; - if (parse_state(&sz[5], n) < 0) + n->attrib = mrpdhelper_attribtype_mvrp; + if (sscanf(&sz[4], "%04x ", &n->u.v.vid) != 1) return -1; - n->attrib = mrpdhelper_attribtype_mvrp; - if (sscanf(&sz[8], "%04x ", &n->u.v.vid) != 1) + if (parse_registrar(sz, n, NULL) < 0) return -1; - return parse_registrar(sz, n, NULL); + + if (parse_app_state(sz, n) < 0) + return -1; + + return parse_state(sz, n); } static int parse_msrp_string(char *sz, size_t len, struct mrpdhelper_notify *n) @@ -209,7 +231,13 @@ static int parse_msrp(char *sz, size_t len, struct mrpdhelper_notify *n) if (parse_msrp_string(&sz[4], len - 4, n) < 0) return -1; - return parse_registrar(sz, n, NULL); + if (parse_registrar(sz, n, NULL) < 0) + return -1; + + if (parse_app_state(sz, n) < 0) + return -1; + + return parse_state(sz, n); } @@ -231,13 +259,6 @@ static int parse_msrp_query(char *sz, size_t len, struct mrpdhelper_notify *n) static int parse_mmrp(char *sz, size_t len, struct mrpdhelper_notify *n) { - /* format - MIN MJO M=112233445566 R=112233445566 - len = 38 - */ - if (len < 38) - return -1; - if (parse_notification(&sz[1], n) < 0) return -1; -- 2.7.4