port: Simplify management response logic.
The code uses a local variable for program flow control in a silly way. This patch simplifies the logic by using the common switch/case/default pattern instead. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
0a726b4390
commit
2d25209993
25
port.c
25
port.c
|
@ -705,7 +705,6 @@ static const Octet profile_id_p2p[] = {0x00, 0x1B, 0x19, 0x00, 0x02, 0x00};
|
|||
static int port_management_fill_response(struct port *target,
|
||||
struct ptp_message *rsp, int id)
|
||||
{
|
||||
int datalen = 0, respond = 0;
|
||||
struct mgmt_clock_description *cd;
|
||||
struct management_tlv_datum *mtd;
|
||||
struct clock_description *desc;
|
||||
|
@ -713,8 +712,9 @@ static int port_management_fill_response(struct port *target,
|
|||
struct management_tlv *tlv;
|
||||
struct port_ds_np *pdsnp;
|
||||
struct portDS *pds;
|
||||
uint8_t *buf;
|
||||
uint16_t u16;
|
||||
uint8_t *buf;
|
||||
int datalen;
|
||||
|
||||
tlv = (struct management_tlv *) rsp->management.suffix;
|
||||
tlv->type = TLV_MANAGEMENT;
|
||||
|
@ -723,7 +723,6 @@ static int port_management_fill_response(struct port *target,
|
|||
switch (id) {
|
||||
case TLV_NULL_MANAGEMENT:
|
||||
datalen = 0;
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_CLOCK_DESCRIPTION:
|
||||
cd = &rsp->last_tlv.cd;
|
||||
|
@ -784,7 +783,6 @@ static int port_management_fill_response(struct port *target,
|
|||
}
|
||||
buf += PROFILE_ID_LEN;
|
||||
datalen = buf - tlv->data;
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_PORT_DATA_SET:
|
||||
pds = (struct portDS *) tlv->data;
|
||||
|
@ -807,31 +805,26 @@ static int port_management_fill_response(struct port *target,
|
|||
pds->logMinPdelayReqInterval = target->logMinPdelayReqInterval;
|
||||
pds->versionNumber = target->versionNumber;
|
||||
datalen = sizeof(*pds);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_LOG_ANNOUNCE_INTERVAL:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
mtd->val = target->logAnnounceInterval;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_ANNOUNCE_RECEIPT_TIMEOUT:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
mtd->val = target->announceReceiptTimeout;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_LOG_SYNC_INTERVAL:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
mtd->val = target->logSyncInterval;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_VERSION_NUMBER:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
mtd->val = target->versionNumber;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_DELAY_MECHANISM:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
|
@ -840,20 +833,17 @@ static int port_management_fill_response(struct port *target,
|
|||
else
|
||||
mtd->val = DM_E2E;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_LOG_MIN_PDELAY_REQ_INTERVAL:
|
||||
mtd = (struct management_tlv_datum *) tlv->data;
|
||||
mtd->val = target->logMinPdelayReqInterval;
|
||||
datalen = sizeof(*mtd);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_PORT_DATA_SET_NP:
|
||||
pdsnp = (struct port_ds_np *) tlv->data;
|
||||
pdsnp->neighborPropDelayThresh = target->neighborPropDelayThresh;
|
||||
pdsnp->asCapable = target->asCapable;
|
||||
datalen = sizeof(*pdsnp);
|
||||
respond = 1;
|
||||
break;
|
||||
case TLV_PORT_PROPERTIES_NP:
|
||||
ppn = (struct port_properties_np *)tlv->data;
|
||||
|
@ -865,10 +855,12 @@ static int port_management_fill_response(struct port *target,
|
|||
ppn->timestamping = target->timestamping;
|
||||
ptp_text_set(&ppn->interface, target->iface->ts_label);
|
||||
datalen = sizeof(*ppn) + ppn->interface.length;
|
||||
respond = 1;
|
||||
break;
|
||||
default:
|
||||
/* The caller should *not* respond to this message. */
|
||||
return 0;
|
||||
}
|
||||
if (respond) {
|
||||
|
||||
if (datalen % 2) {
|
||||
tlv->data[datalen] = 0;
|
||||
datalen++;
|
||||
|
@ -876,8 +868,9 @@ static int port_management_fill_response(struct port *target,
|
|||
tlv->length = sizeof(tlv->id) + datalen;
|
||||
rsp->header.messageLength += sizeof(*tlv) + datalen;
|
||||
rsp->tlv_count = 1;
|
||||
}
|
||||
return respond;
|
||||
|
||||
/* The caller can respond to this message. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int port_management_get_response(struct port *target,
|
||||
|
|
Loading…
Reference in New Issue