hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/linux/ptp_classify.h
....@@ -1,23 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * PTP 1588 support
34 *
45 * This file implements a BPF that recognizes PTP event messages.
56 *
67 * Copyright (C) 2010 OMICRON electronics GmbH
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
218 */
229
2310 #ifndef _PTP_CLASSIFY_H_
....@@ -49,13 +36,36 @@
4936
5037 #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */
5138 #define OFF_PTP_SEQUENCE_ID 30
52
-#define OFF_PTP_CONTROL 32 /* PTPv1 only */
5339
5440 /* Below defines should actually be removed at some point in time. */
5541 #define IP6_HLEN 40
5642 #define UDP_HLEN 8
5743 #define OFF_IHL 14
5844 #define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
45
+
46
+struct clock_identity {
47
+ u8 id[8];
48
+} __packed;
49
+
50
+struct port_identity {
51
+ struct clock_identity clock_identity;
52
+ __be16 port_number;
53
+} __packed;
54
+
55
+struct ptp_header {
56
+ u8 tsmt; /* transportSpecific | messageType */
57
+ u8 ver; /* reserved | versionPTP */
58
+ __be16 message_length;
59
+ u8 domain_number;
60
+ u8 reserved1;
61
+ u8 flag_field[2];
62
+ __be64 correction;
63
+ __be32 reserved2;
64
+ struct port_identity source_port_identity;
65
+ __be16 sequence_id;
66
+ u8 control;
67
+ u8 log_message_interval;
68
+} __packed;
5969
6070 #if defined(CONFIG_NET_PTP_CLASSIFY)
6171 /**
....@@ -70,6 +80,46 @@
7080 */
7181 unsigned int ptp_classify_raw(const struct sk_buff *skb);
7282
83
+/**
84
+ * ptp_parse_header - Get pointer to the PTP v2 header
85
+ * @skb: packet buffer
86
+ * @type: type of the packet (see ptp_classify_raw())
87
+ *
88
+ * This function takes care of the VLAN, UDP, IPv4 and IPv6 headers. The length
89
+ * is checked.
90
+ *
91
+ * Note, internally skb_mac_header() is used. Make sure that the @skb is
92
+ * initialized accordingly.
93
+ *
94
+ * Return: Pointer to the ptp v2 header or NULL if not found
95
+ */
96
+struct ptp_header *ptp_parse_header(struct sk_buff *skb, unsigned int type);
97
+
98
+/**
99
+ * ptp_get_msgtype - Extract ptp message type from given header
100
+ * @hdr: ptp header
101
+ * @type: type of the packet (see ptp_classify_raw())
102
+ *
103
+ * This function returns the message type for a given ptp header. It takes care
104
+ * of the different ptp header versions (v1 or v2).
105
+ *
106
+ * Return: The message type
107
+ */
108
+static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
109
+ unsigned int type)
110
+{
111
+ u8 msgtype;
112
+
113
+ if (unlikely(type & PTP_CLASS_V1)) {
114
+ /* msg type is located at the control field for ptp v1 */
115
+ msgtype = hdr->control;
116
+ } else {
117
+ msgtype = hdr->tsmt & 0x0f;
118
+ }
119
+
120
+ return msgtype;
121
+}
122
+
73123 void __init ptp_classifier_init(void);
74124 #else
75125 static inline void ptp_classifier_init(void)
....@@ -79,5 +129,18 @@
79129 {
80130 return PTP_CLASS_NONE;
81131 }
132
+static inline struct ptp_header *ptp_parse_header(struct sk_buff *skb,
133
+ unsigned int type)
134
+{
135
+ return NULL;
136
+}
137
+static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
138
+ unsigned int type)
139
+{
140
+ /* The return is meaningless. The stub function would not be
141
+ * executed since no available header from ptp_parse_header.
142
+ */
143
+ return 0;
144
+}
82145 #endif
83146 #endif /* _PTP_CLASSIFY_H_ */