| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* 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. |
|---|
| 11 | 3 | */ |
|---|
| 12 | 4 | |
|---|
| 13 | 5 | /* The below program is the bpf_asm (tools/net/) representation of |
|---|
| .. | .. |
|---|
| 115 | 107 | } |
|---|
| 116 | 108 | EXPORT_SYMBOL_GPL(ptp_classify_raw); |
|---|
| 117 | 109 | |
|---|
| 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 | + |
|---|
| 118 | 140 | void __init ptp_classifier_init(void) |
|---|
| 119 | 141 | { |
|---|
| 120 | 142 | static struct sock_filter ptp_filter[] __initdata = { |
|---|
| .. | .. |
|---|
| 185 | 207 | { 0x16, 0, 0, 0x00000000 }, |
|---|
| 186 | 208 | { 0x06, 0, 0, 0x00000000 }, |
|---|
| 187 | 209 | }; |
|---|
| 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; |
|---|
| 191 | 214 | |
|---|
| 192 | 215 | BUG_ON(bpf_prog_create(&ptp_insns, &ptp_prog)); |
|---|
| 193 | 216 | } |
|---|