hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/net/core/ptp_classifier.c
....@@ -1,13 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* PTP classifier
2
- *
3
- * This program is free software; you can redistribute it and/or
4
- * modify it under the terms of version 2 of the GNU General Public
5
- * License as published by the Free Software Foundation.
6
- *
7
- * This program is distributed in the hope that it will be useful, but
8
- * WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- * General Public License for more details.
113 */
124
135 /* The below program is the bpf_asm (tools/net/) representation of
....@@ -115,6 +107,36 @@
115107 }
116108 EXPORT_SYMBOL_GPL(ptp_classify_raw);
117109
110
+struct ptp_header *ptp_parse_header(struct sk_buff *skb, unsigned int type)
111
+{
112
+ u8 *ptr = skb_mac_header(skb);
113
+
114
+ if (type & PTP_CLASS_VLAN)
115
+ ptr += VLAN_HLEN;
116
+
117
+ switch (type & PTP_CLASS_PMASK) {
118
+ case PTP_CLASS_IPV4:
119
+ ptr += IPV4_HLEN(ptr) + UDP_HLEN;
120
+ break;
121
+ case PTP_CLASS_IPV6:
122
+ ptr += IP6_HLEN + UDP_HLEN;
123
+ break;
124
+ case PTP_CLASS_L2:
125
+ break;
126
+ default:
127
+ return NULL;
128
+ }
129
+
130
+ ptr += ETH_HLEN;
131
+
132
+ /* Ensure that the entire header is present in this packet. */
133
+ if (ptr + sizeof(struct ptp_header) > skb->data + skb->len)
134
+ return NULL;
135
+
136
+ return (struct ptp_header *)ptr;
137
+}
138
+EXPORT_SYMBOL_GPL(ptp_parse_header);
139
+
118140 void __init ptp_classifier_init(void)
119141 {
120142 static struct sock_filter ptp_filter[] __initdata = {
....@@ -185,9 +207,10 @@
185207 { 0x16, 0, 0, 0x00000000 },
186208 { 0x06, 0, 0, 0x00000000 },
187209 };
188
- struct sock_fprog_kern ptp_prog = {
189
- .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
190
- };
210
+ struct sock_fprog_kern ptp_prog;
211
+
212
+ ptp_prog.len = ARRAY_SIZE(ptp_filter);
213
+ ptp_prog.filter = ptp_filter;
191214
192215 BUG_ON(bpf_prog_create(&ptp_insns, &ptp_prog));
193216 }