Skip to content

Commit 89b9baa

Browse files
smagnani96pchaigno
authored andcommitted
monitor:overlay: fix cache with old tcp state
When decoding an overlay packet, we correctly decode the packet and create a connection info struct with all the needed bits. However, outer functions such as getTCPInfo() are not aware whether the packet was native or overlay. Inside, they refer `cache.tcp`, but in case of an overlay packet they should use `cache.overlay.tcp`, which is the correct layer referring to the inner packet. Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
1 parent 68c511c commit 89b9baa

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

pkg/monitor/dissect.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ func initParser() {
102102
}
103103
}
104104

105-
func getTCPInfo() string {
105+
func getTCPInfo(isOverlay bool) string {
106+
target := cache.tcp
107+
if isOverlay {
108+
target = cache.overlay.tcp
109+
}
110+
106111
info := ""
107112
addTCPFlag := func(flag, new string) string {
108113
if flag == "" {
@@ -111,19 +116,19 @@ func getTCPInfo() string {
111116
return flag + ", " + new
112117
}
113118

114-
if cache.tcp.SYN {
119+
if target.SYN {
115120
info = addTCPFlag(info, "SYN")
116121
}
117122

118-
if cache.tcp.ACK {
123+
if target.ACK {
119124
info = addTCPFlag(info, "ACK")
120125
}
121126

122-
if cache.tcp.RST {
127+
if target.RST {
123128
info = addTCPFlag(info, "RST")
124129
}
125130

126-
if cache.tcp.FIN {
131+
if target.FIN {
127132
info = addTCPFlag(info, "FIN")
128133
}
129134

@@ -141,6 +146,10 @@ type ConnectionInfo struct {
141146
Tunnel *ConnectionInfo
142147
}
143148

149+
func (c *ConnectionInfo) isOverlay() bool {
150+
return c.Tunnel != nil
151+
}
152+
144153
// getConnectionInfoFromCache assume dissectLock is obtained at the caller and data is already
145154
// parsed to cache.decoded
146155
func getConnectionInfoFromCache() (c *ConnectionInfo, hasIP, hasEth bool) {
@@ -295,7 +304,7 @@ func GetConnectionSummary(data []byte, opts *decodeOpts) string {
295304
c.Proto)
296305

297306
if c.Proto == "tcp" {
298-
str += " " + getTCPInfo()
307+
str += " " + getTCPInfo(c.isOverlay())
299308
}
300309
case hasIP:
301310
str += fmt.Sprintf("%s -> %s", c.SrcIP, c.DstIP)
@@ -306,7 +315,7 @@ func GetConnectionSummary(data []byte, opts *decodeOpts) string {
306315
}
307316

308317
// In case of an overlay packet, dump also the tunnel.
309-
if c.Tunnel != nil {
318+
if c.isOverlay() {
310319
str += fmt.Sprintf(" [tunnel %s -> %s %s]",
311320
net.JoinHostPort(c.Tunnel.SrcIP.String(), strconv.Itoa(int(c.Tunnel.SrcPort))),
312321
net.JoinHostPort(c.Tunnel.DstIP.String(), strconv.Itoa(int(c.Tunnel.DstPort))),

0 commit comments

Comments
 (0)