Go to the documentation of this file.
23 #ifndef _PTP_CLASSIFY_H_
24 #define _PTP_CLASSIFY_H_
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
29 #include <linux/filter.h>
33 #include <netinet/in.h>
36 #define PTP_CLASS_NONE 0x00
37 #define PTP_CLASS_V1 0x01
38 #define PTP_CLASS_V2 0x02
39 #define PTP_CLASS_VMASK 0x0f
40 #define PTP_CLASS_IPV4 0x10
41 #define PTP_CLASS_IPV6 0x20
42 #define PTP_CLASS_L2 0x30
43 #define PTP_CLASS_VLAN 0x40
44 #define PTP_CLASS_PMASK 0xf0
46 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
47 #define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6)
48 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
49 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
50 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
51 #define PTP_CLASS_V2_VLAN (PTP_CLASS_V2 | PTP_CLASS_VLAN)
53 #define PTP_EV_PORT 319
54 #define PTP_GEN_BIT 0x08
63 #define OFF_PTP_SOURCE_UUID 22
64 #define OFF_PTP_SEQUENCE_ID 30
65 #define OFF_PTP_CONTROL 32
67 #define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
72 #define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST)
73 #define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST)
74 #define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN)
76 #define OP_AND (BPF_ALU | BPF_AND | BPF_K)
77 #define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K)
78 #define OP_JSET (BPF_JMP | BPF_JSET | BPF_K)
79 #define OP_LDB (BPF_LD | BPF_B | BPF_ABS)
80 #define OP_LDH (BPF_LD | BPF_H | BPF_ABS)
81 #define OP_LDHI (BPF_LD | BPF_H | BPF_IND)
82 #define OP_LDX (BPF_LDX | BPF_B | BPF_MSH)
83 #define OP_OR (BPF_ALU | BPF_OR | BPF_K)
84 #define OP_RETA (BPF_RET | BPF_A)
85 #define OP_RETK (BPF_RET | BPF_K)
87 static inline int ptp_filter_init(
struct sock_filter *
f,
int len)
96 {OP_LDH, 0, 0, OFF_ETYPE }, \
97 {OP_JEQ, 0, 12, ETH_P_IP }, \
98 {OP_LDB, 0, 0, OFF_PROTO4 }, \
99 {OP_JEQ, 0, 9, IPPROTO_UDP }, \
100 {OP_LDH, 0, 0, OFF_FRAG }, \
101 {OP_JSET, 7, 0, 0x1fff }, \
102 {OP_LDX, 0, 0, OFF_IHL }, \
103 {OP_LDHI, 0, 0, RELOFF_DST4 }, \
104 {OP_JEQ, 0, 4, PTP_EV_PORT }, \
105 {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, \
106 {OP_AND, 0, 0, PTP_CLASS_VMASK }, \
107 {OP_OR, 0, 0, PTP_CLASS_IPV4 }, \
108 {OP_RETA, 0, 0, 0 }, \
109 {OP_RETK, 0, 0, PTP_CLASS_NONE }, \
110 {OP_JEQ, 0, 9, ETH_P_IPV6 }, \
111 {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, \
112 {OP_JEQ, 0, 6, IPPROTO_UDP }, \
113 {OP_LDH, 0, 0, OFF_DST6 }, \
114 {OP_JEQ, 0, 4, PTP_EV_PORT }, \
115 {OP_LDH, 0, 0, OFF_PTP6 }, \
116 {OP_AND, 0, 0, PTP_CLASS_VMASK }, \
117 {OP_OR, 0, 0, PTP_CLASS_IPV6 }, \
118 {OP_RETA, 0, 0, 0 }, \
119 {OP_RETK, 0, 0, PTP_CLASS_NONE }, \
120 {OP_JEQ, 0, 9, ETH_P_8021Q }, \
121 {OP_LDH, 0, 0, OFF_ETYPE + 4 }, \
122 {OP_JEQ, 0, 15, ETH_P_1588 }, \
123 {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, \
124 {OP_AND, 0, 0, PTP_GEN_BIT }, \
125 {OP_JEQ, 0, 12, 0 }, \
126 {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, \
127 {OP_AND, 0, 0, PTP_CLASS_VMASK }, \
128 {OP_OR, 0, 0, PTP_CLASS_VLAN }, \
129 {OP_RETA, 0, 0, 0 }, \
130 {OP_JEQ, 0, 7, ETH_P_1588 }, \
131 {OP_LDB, 0, 0, ETH_HLEN }, \
132 {OP_AND, 0, 0, PTP_GEN_BIT }, \
133 {OP_JEQ, 0, 4, 0 }, \
134 {OP_LDH, 0, 0, ETH_HLEN }, \
135 {OP_AND, 0, 0, PTP_CLASS_VMASK }, \
136 {OP_OR, 0, 0, PTP_CLASS_L2 }, \
137 {OP_RETA, 0, 0, 0 }, \
138 {OP_RETK, 0, 0, PTP_CLASS_NONE },