@@ -73,7 +73,7 @@ func parseNextLayerFallback(data []byte) Layer {
73
73
return nil
74
74
}
75
75
for _ , layer := range Layers {
76
- next := GetNextLayer (layer )
76
+ next := GetLayer (layer )
77
77
if err := next .Parse (data ); err == nil {
78
78
return next
79
79
}
@@ -90,25 +90,25 @@ func parseNextLayerFromBytes(data []byte) Layer {
90
90
var next Layer
91
91
firstByte := buf [0 ]
92
92
if firstByte >= 0x45 && firstByte <= 0x4F {
93
- next = GetNextLayer (LayerIPv4 )
93
+ next = GetLayer (LayerIPv4 )
94
94
if err := next .Parse (buf ); err == nil {
95
95
return next
96
96
}
97
97
}
98
98
if firstByte >> 4 == 6 {
99
- next = GetNextLayer (LayerIPv6 )
99
+ next = GetLayer (LayerIPv6 )
100
100
if err := next .Parse (buf ); err == nil {
101
101
return next
102
102
}
103
103
}
104
104
if firstByte == HandshakeTLSVal {
105
- next = GetNextLayer (LayerTLS )
105
+ next = GetLayer (LayerTLS )
106
106
if err := next .Parse (buf ); err == nil {
107
107
return next
108
108
}
109
109
}
110
- if firstByte == 0x30 {
111
- next = GetNextLayer ( LayerSNMP )
110
+ if checkFTP ( buf ) {
111
+ next = GetLayer ( LayerFTP )
112
112
if err := next .Parse (buf ); err == nil {
113
113
return next
114
114
}
@@ -117,29 +117,35 @@ func parseNextLayerFromBytes(data []byte) Layer {
117
117
b1 := binary .BigEndian .Uint16 (buf [0 :2 ])
118
118
b2 := binary .BigEndian .Uint16 (buf [2 :4 ])
119
119
if b1 == 1 && (b2 == 0x0800 || b2 == 0x86dd ) {
120
- next = GetNextLayer (LayerARP )
120
+ next = GetLayer (LayerARP )
121
121
if err := next .Parse (buf ); err == nil {
122
122
return next
123
123
}
124
124
}
125
125
}
126
+ if checkSNMP (buf ) {
127
+ next = GetLayer (LayerSNMP )
128
+ if err := next .Parse (buf ); err == nil {
129
+ return next
130
+ }
131
+ }
126
132
if len (buf ) > 15 {
127
133
b1 := binary .BigEndian .Uint16 (buf [12 :14 ])
128
134
if b1 == 0x0806 || b1 == 0x0800 || b1 == 0x86dd {
129
- next = GetNextLayer (LayerETH )
135
+ next = GetLayer (LayerETH )
130
136
if err := next .Parse (buf ); err == nil {
131
137
return next
132
138
}
133
139
}
134
140
}
135
141
if bytes .Contains (buf , protohttp10 ) || bytes .Contains (buf , protohttp11 ) {
136
- next = GetNextLayer (LayerHTTP )
142
+ next = GetLayer (LayerHTTP )
137
143
if err := next .Parse (buf ); err == nil {
138
144
return next
139
145
}
140
146
}
141
147
if bytes .Contains (buf , protoSSH ) {
142
- next = GetNextLayer (LayerSSH )
148
+ next = GetLayer (LayerSSH )
143
149
if err := next .Parse (buf ); err == nil {
144
150
return next
145
151
}
@@ -170,17 +176,17 @@ func parseNextLayerFromPorts(data []byte, src, dst *uint16) Layer {
170
176
var next Layer
171
177
switch {
172
178
case addrMatch (src , dst , []uint16 {53 , 5353 , 853 , 5355 }):
173
- next = GetNextLayer (LayerDNS )
179
+ next = GetLayer (LayerDNS )
174
180
case addrMatch (src , dst , []uint16 {80 , 8080 , 8000 , 8888 , 81 , 591 , 5911 }):
175
- next = GetNextLayer (LayerHTTP )
181
+ next = GetLayer (LayerHTTP )
176
182
case addrMatch (src , dst , []uint16 {161 , 162 , 10161 , 10162 , 1161 , 2161 }):
177
- next = GetNextLayer (LayerSNMP )
183
+ next = GetLayer (LayerSNMP )
178
184
case addrMatch (src , dst , []uint16 {21 , 20 , 2121 , 8021 }):
179
- next = GetNextLayer (LayerFTP )
185
+ next = GetLayer (LayerFTP )
180
186
case addrMatch (src , dst , []uint16 {22 , 2222 , 2200 , 222 , 2022 }):
181
- next = GetNextLayer (LayerSSH )
187
+ next = GetLayer (LayerSSH )
182
188
case addrMatch (src , dst , []uint16 {443 , 465 , 993 , 995 , 8443 , 9443 , 10443 , 8444 , 5228 }):
183
- next = GetNextLayer (LayerTLS )
189
+ next = GetLayer (LayerTLS )
184
190
default :
185
191
return nil
186
192
}
@@ -206,7 +212,7 @@ func ParseNextLayer(data []byte, src, dst *uint16) Layer {
206
212
return parseNextLayerFallback (buf )
207
213
}
208
214
209
- func GetNextLayer (layer LayerName ) Layer {
215
+ func GetLayer (layer LayerName ) Layer {
210
216
switch layer {
211
217
case LayerETH :
212
218
return & EthernetFrame {}
@@ -262,3 +268,11 @@ func add16WithCarryWrapAround(x, y uint16) uint16 {
262
268
sum32 = (sum32 & 0xFFFF ) + (sum32 >> 16 )
263
269
return uint16 (sum32 )
264
270
}
271
+
272
+ func isDigit (b byte ) bool {
273
+ return b >= '0' && b <= '9'
274
+ }
275
+
276
+ func isUpper (b byte ) bool {
277
+ return b >= 'A' && b <= 'Z'
278
+ }
0 commit comments