Skip to content

Commit

Permalink
msg: add authentication tlv in management handling
Browse files Browse the repository at this point in the history
existing code assumed only one tlv was attached to management messages:
a management tlv that started at management.suffix. If an authentication
tlv is attached, these checks fail as there are now two tlvs.

add case for this scenario when counting tlvs

Signed-off-by: Clay Kaiser <Clay.Kaiser@ibm.com>
Reviewed-by: Erez Geva <ErezGeva2@gmail.com>
Reviewed-by: Miroslav Lichvar <mlichvar@redhat.com>
  • Loading branch information
Clay Kaiser (via linuxptp-devel Mailing List) authored and richardcochran committed Jun 4, 2024
1 parent 7192046 commit 0aef576
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
11 changes: 10 additions & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
{
int changed = 0, res, answers;
struct port *piter;
struct tlv_extra *extra;
struct management_tlv *mgt;
struct ClockIdentity *tcid, wildcard = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
Expand All @@ -1628,7 +1629,15 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
if (!cid_eq(tcid, &wildcard) && !cid_eq(tcid, &c->dds.clockIdentity)) {
return changed;
}
if (msg_tlv_count(msg) != 1) {
switch (msg_tlv_count(msg)) {
case 1:
break;
case 2:
extra = TAILQ_LAST(&msg->tlv_list, tlv_list);
if (extra->tlv->type == TLV_AUTHENTICATION) {
break;
}
default:
return changed;
}
mgt = (struct management_tlv *) msg->management.suffix;
Expand Down
10 changes: 9 additions & 1 deletion pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
fprintf(fp, "\t%s seq %hu %s ",
pid2str(&msg->header.sourcePortIdentity),
msg->header.sequenceId, pmc_action_string(action));
if (msg_tlv_count(msg) != 1) {
switch (msg_tlv_count(msg)) {
case 1:
break;
case 2:
extra = TAILQ_LAST(&msg->tlv_list, tlv_list);
if (extra->tlv->type == TLV_AUTHENTICATION) {
break;
}
default:
goto out;
}
extra = TAILQ_FIRST(&msg->tlv_list);
Expand Down
12 changes: 11 additions & 1 deletion pmc_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,24 @@ static int check_clock_identity(struct pmc_agent *node, struct ptp_message *msg)

static int is_msg_mgt(struct ptp_message *msg)
{
struct tlv_extra *extra;
struct TLV *tlv;

if (msg_type(msg) != MANAGEMENT)
return 0;
if (management_action(msg) != RESPONSE)
return 0;
if (msg_tlv_count(msg) != 1)
switch (msg_tlv_count(msg)) {
case 1:
break;
case 2:
extra = TAILQ_LAST(&msg->tlv_list, tlv_list);
if (extra->tlv->type == TLV_AUTHENTICATION) {
break;
}
default:
return 0;
}
tlv = (struct TLV *) msg->management.suffix;
if (tlv->type == TLV_MANAGEMENT)
return 1;
Expand Down

0 comments on commit 0aef576

Please sign in to comment.