0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _PTP_CLASSIFY_H_
0011 #define _PTP_CLASSIFY_H_
0012
0013 #include <linux/ip.h>
0014 #include <linux/skbuff.h>
0015
0016 #define PTP_CLASS_NONE 0x00
0017 #define PTP_CLASS_V1 0x01
0018 #define PTP_CLASS_V2 0x02
0019 #define PTP_CLASS_VMASK 0x0f
0020 #define PTP_CLASS_IPV4 0x10
0021 #define PTP_CLASS_IPV6 0x20
0022 #define PTP_CLASS_L2 0x40
0023 #define PTP_CLASS_PMASK 0x70
0024 #define PTP_CLASS_VLAN 0x80
0025
0026 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
0027 #define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6)
0028 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
0029 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
0030 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
0031 #define PTP_CLASS_V2_VLAN (PTP_CLASS_V2 | PTP_CLASS_VLAN)
0032 #define PTP_CLASS_L4 (PTP_CLASS_IPV4 | PTP_CLASS_IPV6)
0033
0034 #define PTP_MSGTYPE_SYNC 0x0
0035 #define PTP_MSGTYPE_DELAY_REQ 0x1
0036 #define PTP_MSGTYPE_PDELAY_REQ 0x2
0037 #define PTP_MSGTYPE_PDELAY_RESP 0x3
0038
0039 #define PTP_EV_PORT 319
0040 #define PTP_GEN_PORT 320
0041 #define PTP_GEN_BIT 0x08
0042
0043 #define OFF_PTP_SOURCE_UUID 22
0044 #define OFF_PTP_SEQUENCE_ID 30
0045
0046
0047 #define PTP_FLAG_TWOSTEP BIT(1)
0048
0049
0050 #define IP6_HLEN 40
0051 #define UDP_HLEN 8
0052 #define OFF_IHL 14
0053 #define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
0054
0055 struct clock_identity {
0056 u8 id[8];
0057 } __packed;
0058
0059 struct port_identity {
0060 struct clock_identity clock_identity;
0061 __be16 port_number;
0062 } __packed;
0063
0064 struct ptp_header {
0065 u8 tsmt;
0066 u8 ver;
0067 __be16 message_length;
0068 u8 domain_number;
0069 u8 reserved1;
0070 u8 flag_field[2];
0071 __be64 correction;
0072 __be32 reserved2;
0073 struct port_identity source_port_identity;
0074 __be16 sequence_id;
0075 u8 control;
0076 u8 log_message_interval;
0077 } __packed;
0078
0079 #if defined(CONFIG_NET_PTP_CLASSIFY)
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 unsigned int ptp_classify_raw(const struct sk_buff *skb);
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 struct ptp_header *ptp_parse_header(struct sk_buff *skb, unsigned int type);
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
0118 unsigned int type)
0119 {
0120 u8 msgtype;
0121
0122 if (unlikely(type & PTP_CLASS_V1)) {
0123
0124 msgtype = hdr->control;
0125 } else {
0126 msgtype = hdr->tsmt & 0x0f;
0127 }
0128
0129 return msgtype;
0130 }
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type);
0142
0143 void __init ptp_classifier_init(void);
0144 #else
0145 static inline void ptp_classifier_init(void)
0146 {
0147 }
0148 static inline unsigned int ptp_classify_raw(struct sk_buff *skb)
0149 {
0150 return PTP_CLASS_NONE;
0151 }
0152 static inline struct ptp_header *ptp_parse_header(struct sk_buff *skb,
0153 unsigned int type)
0154 {
0155 return NULL;
0156 }
0157 static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
0158 unsigned int type)
0159 {
0160
0161
0162
0163 return PTP_MSGTYPE_SYNC;
0164 }
0165 static inline bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type)
0166 {
0167 return false;
0168 }
0169 #endif
0170 #endif