Skip to content

Commit 24c61cf

Browse files
smagnani96pchaigno
authored andcommitted
monitor:overlay: fix cache with old eth state
Similar as in the previous commit, while printing connection info, the info concerning the eth layer are retrieved from the cache and not the connection structure previously created. This means that we must be aware whether referring `cache.eth` or `cache.overlay.eth`. This commits adjusts this. Let's test this by first decodin an ACK native packet (also when L3 packet), then a SYN VXLAN, then an ACK GENEVE, and finally a native SYN. Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
1 parent 89b9baa commit 24c61cf

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

pkg/monitor/dissect.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ func getTCPInfo(isOverlay bool) string {
135135
return info
136136
}
137137

138+
func getEthInfo(isOverlay bool) string {
139+
target := cache.eth
140+
if isOverlay {
141+
target = cache.overlay.eth
142+
}
143+
144+
return fmt.Sprintf("%s -> %s %s", target.SrcMAC, target.DstMAC, target.EthernetType.String())
145+
}
146+
138147
// ConnectionInfo contains tuple information and icmp code for a connection
139148
type ConnectionInfo struct {
140149
SrcIP net.IP
@@ -309,7 +318,7 @@ func GetConnectionSummary(data []byte, opts *decodeOpts) string {
309318
case hasIP:
310319
str += fmt.Sprintf("%s -> %s", c.SrcIP, c.DstIP)
311320
case hasEth:
312-
str += fmt.Sprintf("%s -> %s %s", cache.eth.SrcMAC, cache.eth.DstMAC, cache.eth.EthernetType.String())
321+
str += getEthInfo(c.isOverlay())
313322
default:
314323
str += "[unknown]"
315324
}

pkg/monitor/dissect_test.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

105118
func TestConnectionSummaryIcmp(t *testing.T) {

0 commit comments

Comments
 (0)