forked from jpirko/libteam
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiec61375-hello.bpf
218 lines (218 loc) · 3.82 KB
/
iec61375-hello.bpf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
ld [2] ; check dest. MAC and other Ethernet stuff */
jneq #0xc200000e, drop */
ldh [0]
jneq #0x0180, drop
ld vlan_avail
jneq #1, drop
ld vlan_tci
and #0x0FFF
jneq #0x01EC, drop
ldh [12]
jneq #0x88CC, drop
ld poff ; have M[0] hold the last ok header start position
tax
ld len
sub x
sub #2 ; size of the first TLV header
st M[0]
ld #0x0e ; the first TLV header starts here
ldx #0x0
st M[1] ; this snippet tests whether we'd
stx M[2] ; jump out of bounds, i.e. if
ld M[0] ; ((accumulated TLV sizes in x) -
ldx M[1] ; (packet payload size)) < 0
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0] ; test one TLV - load TLV header
and #0xFE00 ; extract type
jeq #0x0000, drop ; type 0 is EOF TLV
jneq #0xFE00, skip_tlv_1 ; skip if not HELLO
ldh [x + 0] ; reload TLV header
and #0x01FF ; extract length
jeq #0x56, okay ; must be 86
skip_tlv_1: ldh [x + 0] ; reload TLV header
and #0x01FF ; extract length
add #2 ; header length not included
add x ; previous header offset
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0] ; test next TLV... etc
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_2
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_2: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_3
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_3: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_4
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_4: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_5
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_5: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_6
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_6: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_7
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_7: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_8
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_8: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, skip_tlv_9
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
skip_tlv_9: ldh [x + 0]
and #0x01FF
add #2
add x
st M[1]
stx M[2]
ld M[0]
ldx M[1]
sub x
jset #0x80000000, drop
ld M[1]
ldx M[2]
tax
ldh [x + 0]
and #0xFE00
jeq #0x0000, drop
jneq #0xFE00, drop
ldh [x + 0]
and #0x01FF
jeq #0x56, okay
jmp drop
okay: ret #-1 ; accept entire packet
drop: ret #0 ; accept nothing