Skip to content

Commit 4b6535c

Browse files
committed
erspan: handle the Type III frame type field.
Show its value and only dissect the payload as an Ethernet frame if it's type 0, for Ethernet. Add a test file for frame type 0, rename the existing file to indicate that it uses the unknown frame type 7 (which ain't Ethernet), and regenerate that file.
1 parent 36b6a5d commit 4b6535c

File tree

6 files changed

+125
-131
lines changed

6 files changed

+125
-131
lines changed

print-erspan.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,17 @@ erspan_print_i_ii(netdissect_options *ndo, uint16_t flags, const u_char *bp, u_i
169169
#define ERSPAN3_SID_SHIFT 0
170170
#define ERSPAN3_SID_MASK (0x3ffU << ERSPAN3_SID_SHIFT)
171171
#define ERSPAN3_P_SHIFT 15
172-
#define ERSPAN3_P_MASK (0x1U << ERSPAN3_P_MASK)
172+
#define ERSPAN3_P_MASK (0x1U << ERSPAN3_P_SHIFT)
173173
#define ERSPAN3_FT_SHIFT 10
174-
#define ERSPAN3_FT_MASK (0x1fU << ERSPAN3_FT_MASK)
174+
#define ERSPAN3_FT_MASK (0x1fU << ERSPAN3_FT_SHIFT)
175+
#define ERSPAN3_FT_ETHERNET 0
176+
#define ERSPAN3_FT_IP 2
175177
#define ERSPAN3_HW_ID_SHIFT 4
176-
#define ERSPAN3_HW_ID_MASK (0x3fU << ERSPAN3_HW_ID_MASK)
178+
#define ERSPAN3_HW_ID_MASK (0x3fU << ERSPAN3_HW_ID_SHIFT)
177179
#define ERSPAN3_D_SHIFT 3
178180
#define ERSPAN3_D_MASK (0x1U << ERSPAN3_D_SHIFT)
179181
#define ERSPAN3_GRA_SHIFT 1
180-
#define ERSPAN3_GRA_MASK (0x3U << ERSPAN3_GRA_MASK)
182+
#define ERSPAN3_GRA_MASK (0x3U << ERSPAN3_GRA_SHIFT)
181183
#define ERSPAN3_O_SHIFT 0
182184
#define ERSPAN3_O_MASK (0x1U << ERSPAN3_O_SHIFT)
183185

@@ -189,10 +191,16 @@ static const struct tok erspan3_bso_values[] = {
189191
{ 0, NULL }
190192
};
191193

194+
static const struct tok erspan3_ft_values[] = {
195+
{ ERSPAN3_FT_ETHERNET, "Ethernet" },
196+
{ ERSPAN3_FT_IP, "IP" },
197+
{ 0, NULL }
198+
};
199+
192200
void
193201
erspan_print_iii(netdissect_options *ndo, const u_char *bp, u_int len)
194202
{
195-
uint32_t hdr, hdr2, ver, cos, sid;
203+
uint32_t hdr, hdr2, ver, cos, sid, ft;
196204

197205
ndo->ndo_protocol = "erspan";
198206
nd_print_protocol(ndo);
@@ -250,6 +258,11 @@ erspan_print_iii(netdissect_options *ndo, const u_char *bp, u_int len)
250258
bp += 2;
251259
len -= 2;
252260

261+
ft = (hdr2 & ERSPAN3_FT_MASK) >> ERSPAN3_FT_SHIFT;
262+
ND_PRINT(" ft %s",
263+
tok2str(erspan3_ft_values, "unknown %x", ft));
264+
265+
253266
/* Do we have the platform-specific header? */
254267
if (hdr2 & ERSPAN3_O_MASK) {
255268
/* Yes. Skip it. */
@@ -259,7 +272,17 @@ erspan_print_iii(netdissect_options *ndo, const u_char *bp, u_int len)
259272
}
260273

261274
ND_PRINT(": ");
262-
ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
275+
276+
switch (ft) {
277+
278+
case ERSPAN3_FT_ETHERNET:
279+
ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
280+
break;
281+
282+
default:
283+
ND_PRINT("Frame type unknown");
284+
break;
285+
}
263286
return;
264287

265288
invalid:

tests/TESTLIST

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ erspan-type-i-4 erspan-type-i-4.pcap erspan-type-i-4.out -v
582582
erspan-type-ii-1 erspan-type-ii-1.pcap erspan-type-ii-1.out -v
583583
erspan-type-ii-2 erspan-type-ii-2.pcap erspan-type-ii-2.out -v
584584
erspan-type-ii-3 erspan-type-ii-3.pcap erspan-type-ii-3.out -v
585-
erspan-type-iii-1 erspan-type-iii-1.pcap erspan-type-iii-1.out -v
585+
erspan-type-iii-ft-0 erspan-type-iii-ft-0.pcap erspan-type-iii-ft-0.out -v
586+
erspan-type-iii-ft-7 erspan-type-iii-ft-7.pcap erspan-type-iii-ft-7.out -v
586587

587588
# bad packets from Hanno Böck
588589
# heap-overflow-1 is in non-bsd.tests

tests/erspan-type-iii-ft-0.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
1 2019-09-29 07:58:26.661437 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
2+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
3+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40210, offset 0, flags [DF], proto ICMP (1), length 84)
4+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 226, length 64
5+
2 2019-09-29 07:58:27.685531 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
6+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
7+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40434, offset 0, flags [DF], proto ICMP (1), length 84)
8+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 227, length 64
9+
3 2019-09-29 07:58:28.709480 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
10+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
11+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40562, offset 0, flags [DF], proto ICMP (1), length 84)
12+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 228, length 64
13+
4 2019-09-29 07:58:29.733534 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
14+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
15+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40634, offset 0, flags [DF], proto ICMP (1), length 84)
16+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 229, length 64
17+
5 2019-09-29 07:58:30.757572 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
18+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
19+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40761, offset 0, flags [DF], proto ICMP (1), length 84)
20+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 230, length 64
21+
6 2019-09-29 07:58:31.781502 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
22+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
23+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 40946, offset 0, flags [DF], proto ICMP (1), length 84)
24+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 231, length 64
25+
7 2019-09-29 07:58:32.805543 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
26+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
27+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 41042, offset 0, flags [DF], proto ICMP (1), length 84)
28+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 232, length 64
29+
8 2019-09-29 07:58:33.829480 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
30+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
31+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 41230, offset 0, flags [DF], proto ICMP (1), length 84)
32+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 233, length 64
33+
9 2019-09-29 07:58:34.853463 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto GRE (47), length 138)
34+
10.29.30.104 > 10.29.11.13: GREv0, Flags [none], length 118
35+
erspan type3 session 0 bso Good/unknown cos 0 ft Ethernet: IP (tos 0x0, ttl 63, id 41238, offset 0, flags [DF], proto ICMP (1), length 84)
36+
10.29.11.1 > 10.29.20.21: ICMP echo request, id 16331, seq 234, length 64

tests/erspan-type-iii-ft-0.pcap

1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)