phc2sys: read PHC with each PPS sample.

In the PPS loop, instead of setting the system clock from the PHC only
once on start, read PHC with each PPS sample and use the time stamp to
get the whole number of seconds in the offset. This will prevent phc2sys
from losing track of the system clock.

Also, check if the PPS is synchronized to the PHC.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
phc2sys: allow PPS loop only with system clock.

The PPS time stamps are always made by the system clock, don't allow
running the PPS loop with other clocks.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Add missing documentation for msg_post_recv.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Check that TLV length is correct when receiving TLVs.

The function, tlv_post_recv, and the functions it calls don't check
the length of the tlv before flipping the byte order of fields. An
attacker (or a really buggy client) can craft a message causing the
byte order of data outside the received message to be flipped.

None of the supported tlvs are large enough to flip bytes outside the
ptp_message struct, which could corrupt the heap. However, it's easy
to mess up the message's refcnt field, leading to memory leaks.

The fix is to check that the tlv length is what is expected when
receiving, and tlv_post_recv needs to return an int to signal when a
tlv is invalid.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>