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

ptp: Add generic PTP is_sync() function

PHY drivers such as micrel or dp83640 need to analyze whether a given
skb is a PTP sync message for one step functionality.

In order to avoid code duplication introduce a generic function and
move it to ptp classify.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kurt Kanzenbach and committed by
David S. Miller
f72de02e 669b258a

+27
+15
include/linux/ptp_classify.h
··· 126 126 return msgtype; 127 127 } 128 128 129 + /** 130 + * ptp_msg_is_sync - Evaluates whether the given skb is a PTP Sync message 131 + * @skb: packet buffer 132 + * @type: type of the packet (see ptp_classify_raw()) 133 + * 134 + * This function evaluates whether the given skb is a PTP Sync message. 135 + * 136 + * Return: true if sync message, false otherwise 137 + */ 138 + bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type); 139 + 129 140 void __init ptp_classifier_init(void); 130 141 #else 131 142 static inline void ptp_classifier_init(void) ··· 158 147 * executed since no available header from ptp_parse_header. 159 148 */ 160 149 return PTP_MSGTYPE_SYNC; 150 + } 151 + static inline bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type) 152 + { 153 + return false; 161 154 } 162 155 #endif 163 156 #endif /* _PTP_CLASSIFY_H_ */
+12
net/core/ptp_classifier.c
··· 137 137 } 138 138 EXPORT_SYMBOL_GPL(ptp_parse_header); 139 139 140 + bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type) 141 + { 142 + struct ptp_header *hdr; 143 + 144 + hdr = ptp_parse_header(skb, type); 145 + if (!hdr) 146 + return false; 147 + 148 + return ptp_get_msgtype(hdr, type) == PTP_MSGTYPE_SYNC; 149 + } 150 + EXPORT_SYMBOL_GPL(ptp_msg_is_sync); 151 + 140 152 void __init ptp_classifier_init(void) 141 153 { 142 154 static struct sock_filter ptp_filter[] __initdata = {