Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: fix L2 event message recognition

The IEEE 1588 standard defines two kinds of messages, event and general
messages. Event messages require time stamping, and general do not. When
using UDP transport, two separate ports are used for the two message
types.

The BPF designed to recognize event messages incorrectly classifies L2
general messages as event messages. This commit fixes the issue by
extending the filter to check the message type field for L2 PTP packets.
Event messages are be distinguished from general messages by testing
the "general" bit.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: <stable@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Richard Cochran and committed by
David S. Miller
f75159e9 d5767c53

+10 -3
+10 -3
include/linux/ptp_classify.h
··· 51 51 #define PTP_CLASS_V2_VLAN (PTP_CLASS_V2 | PTP_CLASS_VLAN) 52 52 53 53 #define PTP_EV_PORT 319 54 + #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type */ 54 55 55 56 #define OFF_ETYPE 12 56 57 #define OFF_IHL 14 ··· 117 116 {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \ 118 117 {OP_RETA, 0, 0, 0 }, /* */ \ 119 118 /*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \ 120 - /*L40*/ {OP_JEQ, 0, 6, ETH_P_8021Q }, /* f goto L50 */ \ 119 + /*L40*/ {OP_JEQ, 0, 9, ETH_P_8021Q }, /* f goto L50 */ \ 121 120 {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \ 122 - {OP_JEQ, 0, 9, ETH_P_1588 }, /* f goto L60 */ \ 121 + {OP_JEQ, 0, 15, ETH_P_1588 }, /* f goto L60 */ \ 122 + {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \ 123 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \ 124 + {OP_JEQ, 0, 12, 0 }, /* f goto L6x */ \ 123 125 {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \ 124 126 {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ 125 127 {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \ 126 128 {OP_RETA, 0, 0, 0 }, /* */ \ 127 - /*L50*/ {OP_JEQ, 0, 4, ETH_P_1588 }, /* f goto L61 */ \ 129 + /*L50*/ {OP_JEQ, 0, 7, ETH_P_1588 }, /* f goto L61 */ \ 130 + {OP_LDB, 0, 0, ETH_HLEN }, /* */ \ 131 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \ 132 + {OP_JEQ, 0, 4, 0 }, /* f goto L6x */ \ 128 133 {OP_LDH, 0, 0, ETH_HLEN }, /* */ \ 129 134 {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ 130 135 {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \