msg: Use the TLV list on transmit.

Now that the list is in place and is used on all transmit paths, simply
iterate through the list when converting to network byte order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2018-02-23 23:20:26 -08:00
parent e0005dac94
commit a061256bbd
1 changed files with 6 additions and 17 deletions

23
msg.c
View File

@ -221,18 +221,14 @@ static int suffix_post_recv(struct ptp_message *msg, uint8_t *ptr, int len)
return 0; return 0;
} }
static void suffix_pre_send(uint8_t *ptr, int cnt, struct tlv_extra *last) static void suffix_pre_send(struct ptp_message *msg)
{ {
int i; struct tlv_extra *extra;
struct TLV *tlv; struct TLV *tlv;
if (!ptr) TAILQ_FOREACH(extra, &msg->tlv_list, list) {
return; tlv = extra->tlv;
tlv_pre_send(tlv, extra);
for (i = 0; i < cnt; i++) {
tlv = (struct TLV *) ptr;
tlv_pre_send(tlv, i == cnt - 1 ? last : NULL);
ptr += sizeof(struct TLV) + tlv->length;
tlv->type = htons(tlv->type); tlv->type = htons(tlv->type);
tlv->length = htons(tlv->length); tlv->length = htons(tlv->length);
} }
@ -406,7 +402,6 @@ int msg_post_recv(struct ptp_message *m, int cnt)
int msg_pre_send(struct ptp_message *m) int msg_pre_send(struct ptp_message *m)
{ {
int type; int type;
uint8_t *suffix = NULL;
if (hdr_pre_send(&m->header)) if (hdr_pre_send(&m->header))
return -1; return -1;
@ -426,34 +421,28 @@ int msg_pre_send(struct ptp_message *m)
break; break;
case FOLLOW_UP: case FOLLOW_UP:
timestamp_pre_send(&m->follow_up.preciseOriginTimestamp); timestamp_pre_send(&m->follow_up.preciseOriginTimestamp);
suffix = m->follow_up.suffix;
break; break;
case DELAY_RESP: case DELAY_RESP:
timestamp_pre_send(&m->delay_resp.receiveTimestamp); timestamp_pre_send(&m->delay_resp.receiveTimestamp);
m->delay_resp.requestingPortIdentity.portNumber = m->delay_resp.requestingPortIdentity.portNumber =
htons(m->delay_resp.requestingPortIdentity.portNumber); htons(m->delay_resp.requestingPortIdentity.portNumber);
suffix = m->delay_resp.suffix;
break; break;
case PDELAY_RESP_FOLLOW_UP: case PDELAY_RESP_FOLLOW_UP:
timestamp_pre_send(&m->pdelay_resp_fup.responseOriginTimestamp); timestamp_pre_send(&m->pdelay_resp_fup.responseOriginTimestamp);
port_id_pre_send(&m->pdelay_resp_fup.requestingPortIdentity); port_id_pre_send(&m->pdelay_resp_fup.requestingPortIdentity);
suffix = m->pdelay_resp_fup.suffix;
break; break;
case ANNOUNCE: case ANNOUNCE:
announce_pre_send(&m->announce); announce_pre_send(&m->announce);
suffix = m->announce.suffix;
break; break;
case SIGNALING: case SIGNALING:
suffix = m->signaling.suffix;
break; break;
case MANAGEMENT: case MANAGEMENT:
port_id_pre_send(&m->management.targetPortIdentity); port_id_pre_send(&m->management.targetPortIdentity);
suffix = m->management.suffix;
break; break;
default: default:
return -1; return -1;
} }
suffix_pre_send(suffix, m->tlv_count, m->last_tlv); suffix_pre_send(m);
return 0; return 0;
} }