@@ -55,8 +55,8 @@ func TestConnectionSummaryTcp(t *testing.T) {
5555 IsL3Device bool
5656 }{{"L3Device" , true }, {"L2Device" , false }} {
5757 t .Run (c .Name , func (t * testing.T ) {
58- // Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443)
59- data := []byte {2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 2 , 32 , 0 , 125 , 196 , 0 , 0 }
58+ // Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443,flags="A" )
59+ data := []byte {2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 16 , 32 , 0 , 125 , 182 , 0 , 0 }
6060 if c .IsL3Device {
6161 // Remove ethernet layer.
6262 data = data [14 :]
@@ -66,7 +66,7 @@ func TestConnectionSummaryTcp(t *testing.T) {
6666 expect := fmt .Sprintf ("%s -> %s %s" ,
6767 net .JoinHostPort (srcIP , sport ),
6868 net .JoinHostPort (dstIP , dport ),
69- "tcp SYN " )
69+ "tcp ACK " )
7070 require .Equal (t , expect , summary )
7171 })
7272 }
@@ -79,27 +79,40 @@ func TestConnectionSummaryTcp(t *testing.T) {
7979
8080 for _ , c := range []struct {
8181 Name string
82+ Flag string
8283 Data []byte
8384 }{
84- // Ether(src="01:02:03:04:05:06", dst="11:12:13:14:15:16")/IP(src="1.1.1.1",dst="2.2.2.2")/UDP(sport=8472,dport=9999)/VXLAN(vni=2)/Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443)
85- {"VXLAN" , []byte {17 , 18 , 19 , 20 , 21 , 22 , 1 , 2 , 3 , 4 , 5 , 6 , 8 , 0 , 69 , 0 , 0 , 90 , 0 , 1 , 0 , 0 , 64 , 17 , 116 , 141 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 33 , 24 , 39 , 15 , 0 , 70 , 9 , 229 , 12 , 0 , 0 , 3 , 0 , 0 , 2 , 0 , 2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 2 , 32 , 0 , 125 , 196 , 0 , 0 }},
86- // Ether(src="01:02:03:04:05:06", dst="11:12:13:14:15:16")/IP(src="1.1.1.1",dst="2.2.2.2")/UDP(sport=8472,dport=9999)/GENEVE(vni=2,proto=0x6558)/Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443)
87- {"Geneve" , []byte {17 , 18 , 19 , 20 , 21 , 22 , 1 , 2 , 3 , 4 , 5 , 6 , 8 , 0 , 69 , 0 , 0 , 90 , 0 , 1 , 0 , 0 , 64 , 17 , 116 , 141 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 33 , 24 , 39 , 15 , 0 , 70 , 176 , 143 , 0 , 0 , 101 , 88 , 0 , 0 , 2 , 0 , 2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 2 , 32 , 0 , 125 , 196 , 0 , 0 }},
85+ // Ether(src="01:02:03:04:05:06", dst="11:12:13:14:15:16")/IP(src="1.1.1.1",dst="2.2.2.2")/UDP(sport=8472,dport=9999)/VXLAN(vni=2)/Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443,flags="S" )
86+ {"VXLAN" , "SYN" , []byte {17 , 18 , 19 , 20 , 21 , 22 , 1 , 2 , 3 , 4 , 5 , 6 , 8 , 0 , 69 , 0 , 0 , 90 , 0 , 1 , 0 , 0 , 64 , 17 , 116 , 141 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 33 , 24 , 39 , 15 , 0 , 70 , 9 , 229 , 12 , 0 , 0 , 3 , 0 , 0 , 2 , 0 , 2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 2 , 32 , 0 , 125 , 196 , 0 , 0 }},
87+ // Ether(src="01:02:03:04:05:06", dst="11:12:13:14:15:16")/IP(src="1.1.1.1",dst="2.2.2.2")/UDP(sport=8472,dport=9999)/GENEVE(vni=2,proto=0x6558)/Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443,flags="A" )
88+ {"Geneve" , "ACK" , []byte {17 , 18 , 19 , 20 , 21 , 22 , 1 , 2 , 3 , 4 , 5 , 6 , 8 , 0 , 69 , 0 , 0 , 90 , 0 , 1 , 0 , 0 , 64 , 17 , 116 , 141 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 33 , 24 , 39 , 15 , 0 , 70 , 176 , 143 , 0 , 0 , 101 , 88 , 0 , 0 , 2 , 0 , 2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 16 , 32 , 0 , 125 , 182 , 0 , 0 }},
8889 } {
8990 t .Run (c .Name , func (t * testing.T ) {
9091 summary := GetConnectionSummary (c .Data , & decodeOpts {IsVXLAN : c .Name == "VXLAN" , IsGeneve : c .Name == "Geneve" })
9192
9293 expect := fmt .Sprintf ("%s -> %s %s [tunnel %s -> %s %s]" ,
9394 net .JoinHostPort (srcIP , sport ),
9495 net .JoinHostPort (dstIP , dport ),
95- "tcp SYN" ,
96+ "tcp " + c . Flag ,
9697 net .JoinHostPort (srcIPOuter , sportOuter ),
9798 net .JoinHostPort (dstIPOuter , dportOuter ),
9899 strings .ToLower (c .Name ))
99100
100101 require .Equal (t , expect , summary )
101102 })
102103 }
104+
105+ t .Run ("PostOverlay" , func (t * testing.T ) {
106+ // Ether(src="01:23:45:67:89:ab", dst="02:33:45:67:89:ab")/IP(src="1.2.3.4",dst="5.6.7.8")/TCP(sport=80,dport=443,flags="S")
107+ data := []byte {2 , 51 , 69 , 103 , 137 , 171 , 1 , 35 , 69 , 103 , 137 , 171 , 8 , 0 , 69 , 0 , 0 , 40 , 0 , 1 , 0 , 0 , 64 , 6 , 106 , 188 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 80 , 1 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 2 , 32 , 0 , 125 , 196 , 0 , 0 }
108+ summary := GetConnectionSummary (data , nil )
109+
110+ expect := fmt .Sprintf ("%s -> %s %s" ,
111+ net .JoinHostPort (srcIP , sport ),
112+ net .JoinHostPort (dstIP , dport ),
113+ "tcp SYN" )
114+ require .Equal (t , expect , summary )
115+ })
103116}
104117
105118func TestConnectionSummaryIcmp (t * testing.T ) {
0 commit comments