Commit bbd0e2c1 authored by Davide Ciminaghi's avatar Davide Ciminaghi Committed by Alessandro Rubini

fsm: move code for filtering out packets to a dedicated function

A function should only do what it promises, so msg_unpack_header should
just unpack. This move also gets also us ready for fixing compliance
to 9.5.2.3.
parent 79f423b5
......@@ -96,6 +96,51 @@ static int leave_current_state(struct pp_instance *ppi)
return 0;
}
/*
* Checks whether a packet has to be discarded and maybe updates port status
* accordingly. Returns new packet length (0 if packet has to be discarded)
*/
static int pp_packet_prefilter(struct pp_instance *ppi)
{
MsgHeader *hdr = &ppi->received_ptp_header;
/*
* 9.5.1:
* Only PTP messages where the domainNumber field of the PTP message
* header (see 13.3.2.5) is identical to the defaultDS.domainNumber
* shall be accepted for processing by the protocol.
*/
if (hdr->domainNumber != GDSDEF(GLBS(ppi))->domainNumber) {
pp_diag(ppi, frames, 1, "Wrong domain %i: discard\n",
hdr->domainNumber);
return -1;
}
/*
* Alternate masters (17.4) not supported
* 17.4.2, NOTE:
* A slave node that does not want to use information from alternate
* masters merely ignores all messages with alternateMasterFlag TRUE.
*/
if (hdr->flagField[0] & PP_ALTERNATE_MASTER_FLAG) {
pp_diag(ppi, frames, 1, "Alternate master: discard\n");
return -1;
}
/*
* If the message is from the same port that sent it, we should
* discard it (9.5.2.2)
*/
if (!memcmp(&ppi->received_ptp_header.sourcePortIdentity,
&DSPOR(ppi)->portIdentity,
sizeof(PortIdentity))) {
pp_diag(ppi, frames, 1, "Looping frame: discard\n");
return -1;
}
return 0;
}
/*
* This is the state machine code. i.e. the extension-independent
* function that runs the machine. Errors are managed and reported
......@@ -148,6 +193,19 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
ppi->next_delay = 0;
if (ppi->is_new_state)
pp_diag_fsm(ppi, ip->name, STATE_ENTER, plen);
/*
* Possibly filter out packet and maybe update port state
*/
if (packet) {
err = pp_packet_prefilter(ppi);
if (err < 0) {
packet = NULL;
plen = 0;
}
}
if (ppi->state != ppi->next_state)
return leave_current_state(ppi);
err = ip->f1(ppi, packet, plen);
if (err)
pp_printf("fsm for %s: Error %i in %s\n",
......
......@@ -36,32 +36,6 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf, int plen)
hdr->controlField = (*(UInteger8 *) (buf + 32));
hdr->logMessageInterval = (*(Integer8 *) (buf + 33));
/*
* 9.5.1:
* Only PTP messages where the domainNumber field of the PTP message
* header (see 13.3.2.5) is identical to the defaultDS.domainNumber
* shall be accepted for processing by the protocol.
*/
if (hdr->domainNumber != GDSDEF(GLBS(ppi))->domainNumber)
return -1;
/*
* Alternate masters (17.4) not supported
* 17.4.2, NOTE:
* A slave node that does not want to use information from alternate
* masters merely ignores all messages with alternateMasterFlag TRUE.
*/
if (hdr->flagField[0] & PP_ALTERNATE_MASTER_FLAG)
return -1;
/*
* If the message is from the same port that sent it, we should
* discard it (9.5.2.2)
*/
if (!memcmp(&ppi->received_ptp_header.sourcePortIdentity,
&DSPOR(ppi)->portIdentity,
sizeof(PortIdentity)))
return -1;
/*
* This FLAG_FROM_CURRENT_PARENT must be killed. Meanwhile, say it's
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment