msg: Drop msg->tlv_count.
The field is redundant with the length tlv_list. Replace it with a function msg_tlv_count() instead. This iterates over the tlv_list. The computational overhead should be small, because the lists are very short and the tlv_count is only used in management paths (yet). Signed-off-by: Michael Walle <michael@walle.cc>master
parent
427f1b3981
commit
8f484e8312
2
clock.c
2
clock.c
|
@ -1319,7 +1319,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
|
||||||
if (!cid_eq(tcid, &wildcard) && !cid_eq(tcid, &c->dds.clockIdentity)) {
|
if (!cid_eq(tcid, &wildcard) && !cid_eq(tcid, &c->dds.clockIdentity)) {
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
if (msg->tlv_count != 1) {
|
if (msg_tlv_count(msg) != 1) {
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
mgt = (struct management_tlv *) msg->management.suffix;
|
mgt = (struct management_tlv *) msg->management.suffix;
|
||||||
|
|
15
msg.c
15
msg.c
|
@ -318,7 +318,6 @@ struct ptp_message *msg_duplicate(struct ptp_message *msg, int cnt)
|
||||||
memcpy(dup, msg, sizeof(*dup));
|
memcpy(dup, msg, sizeof(*dup));
|
||||||
dup->refcnt = 1;
|
dup->refcnt = 1;
|
||||||
TAILQ_INIT(&dup->tlv_list);
|
TAILQ_INIT(&dup->tlv_list);
|
||||||
dup->tlv_count = 0;
|
|
||||||
|
|
||||||
err = msg_post_recv(dup, cnt);
|
err = msg_post_recv(dup, cnt);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -506,7 +505,19 @@ struct tlv_extra *msg_tlv_append(struct ptp_message *msg, int length)
|
||||||
void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra)
|
void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra)
|
||||||
{
|
{
|
||||||
TAILQ_INSERT_TAIL(&msg->tlv_list, extra, list);
|
TAILQ_INSERT_TAIL(&msg->tlv_list, extra, list);
|
||||||
msg->tlv_count++;
|
}
|
||||||
|
|
||||||
|
int msg_tlv_count(struct ptp_message *msg)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
struct tlv_extra *extra;
|
||||||
|
|
||||||
|
for (extra = TAILQ_FIRST(&msg->tlv_list);
|
||||||
|
extra != NULL;
|
||||||
|
extra = TAILQ_NEXT(extra, list))
|
||||||
|
count++;
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *msg_type_string(int type)
|
const char *msg_type_string(int type)
|
||||||
|
|
11
msg.h
11
msg.h
|
@ -227,10 +227,6 @@ struct ptp_message {
|
||||||
* pointers to the appended TLVs.
|
* pointers to the appended TLVs.
|
||||||
*/
|
*/
|
||||||
TAILQ_HEAD(tlv_list, tlv_extra) tlv_list;
|
TAILQ_HEAD(tlv_list, tlv_extra) tlv_list;
|
||||||
/**
|
|
||||||
* Contains the number of TLVs in the suffix.
|
|
||||||
*/
|
|
||||||
int tlv_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,6 +275,13 @@ struct tlv_extra *msg_tlv_append(struct ptp_message *msg, int length);
|
||||||
*/
|
*/
|
||||||
void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra);
|
void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the number of TLVs attached to a message.
|
||||||
|
* @param msg A message obtained using @ref msg_allocate().
|
||||||
|
* @return The number of attached TLVs.
|
||||||
|
*/
|
||||||
|
int msg_tlv_count(struct ptp_message *msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the transportSpecific field from a message.
|
* Obtain the transportSpecific field from a message.
|
||||||
* @param m Message to test.
|
* @param m Message to test.
|
||||||
|
|
|
@ -819,7 +819,7 @@ static int is_msg_mgt(struct ptp_message *msg)
|
||||||
return 0;
|
return 0;
|
||||||
if (management_action(msg) != RESPONSE)
|
if (management_action(msg) != RESPONSE)
|
||||||
return 0;
|
return 0;
|
||||||
if (msg->tlv_count != 1)
|
if (msg_tlv_count(msg) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
tlv = (struct TLV *) msg->management.suffix;
|
tlv = (struct TLV *) msg->management.suffix;
|
||||||
if (tlv->type == TLV_MANAGEMENT)
|
if (tlv->type == TLV_MANAGEMENT)
|
||||||
|
|
2
pmc.c
2
pmc.c
|
@ -80,7 +80,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
|
||||||
fprintf(fp, "\t%s seq %hu %s ",
|
fprintf(fp, "\t%s seq %hu %s ",
|
||||||
pid2str(&msg->header.sourcePortIdentity),
|
pid2str(&msg->header.sourcePortIdentity),
|
||||||
msg->header.sequenceId, pmc_action_string(action));
|
msg->header.sequenceId, pmc_action_string(action));
|
||||||
if (msg->tlv_count != 1) {
|
if (msg_tlv_count(msg) != 1) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
extra = TAILQ_FIRST(&msg->tlv_list);
|
extra = TAILQ_FIRST(&msg->tlv_list);
|
||||||
|
|
Loading…
Reference in New Issue