@@ -3,7 +3,7 @@ package bpfwrapper
3
3
import (
4
4
"bytes"
5
5
"encoding/binary"
6
- "log"
6
+ "log/slog "
7
7
"unsafe"
8
8
9
9
"github.com/akto-api-security/mirroring-api-logging/ebpf/connections"
@@ -28,11 +28,16 @@ func SocketOpenEventCallback(inputChan chan []byte, connectionFactory *connectio
28
28
29
29
var event structs.SocketOpenEvent
30
30
if err := binary .Read (bytes .NewReader (data ), bcc .GetHostByteOrder (), & event ); err != nil {
31
- log . Printf ("Failed to decode received data on socket open: %+v " , err )
31
+ slog . Error ("Failed to decode received data on socket open" , "error " , err )
32
32
continue
33
33
}
34
34
connId := event .ConnId
35
- utils .LogIngest ("Received open fd: %v id: %v ts: %v ip: %v port: %v\n " , connId .Fd , connId .Id , connId .Conn_start_ns , connId .Ip , connId .Port )
35
+ slog .Debug ("Received socket open event" ,
36
+ "fd" , connId .Fd ,
37
+ "id" , connId .Id ,
38
+ "timestamp" , connId .Conn_start_ns ,
39
+ "ip" , connId .Ip ,
40
+ "port" , connId .Port )
36
41
connectionFactory .CreateIfNotExists (connId )
37
42
connectionFactory .SendEvent (connId , & event )
38
43
}
@@ -45,12 +50,17 @@ func SocketCloseEventCallback(inputChan chan []byte, connectionFactory *connecti
45
50
}
46
51
var event structs.SocketCloseEvent
47
52
if err := binary .Read (bytes .NewReader (data ), bcc .GetHostByteOrder (), & event ); err != nil {
48
- log . Printf ("Failed to decode received data on socket close: %+v " , err )
53
+ slog . Error ("Failed to decode received data on socket close" , "error " , err )
49
54
continue
50
55
}
51
56
52
57
connId := event .ConnId
53
- utils .LogIngest ("Received close on: fd: %v id: %v ts: %v ip: %v port: %v\n " , connId .Fd , connId .Id , connId .Conn_start_ns , connId .Ip , connId .Port )
58
+ slog .Debug ("Received close on" ,
59
+ "fd" , connId .Fd ,
60
+ "id" , connId .Id ,
61
+ "timestamp" , connId .Conn_start_ns ,
62
+ "ip" , connId .Ip ,
63
+ "port" , connId .Port )
54
64
connectionFactory .SendEvent (connId , & event )
55
65
}
56
66
}
@@ -90,7 +100,7 @@ func SocketDataEventCallback(inputChan chan []byte, connectionFactory *connectio
90
100
}
91
101
92
102
if ! (connectionFactory .CanBeFilled () && connections .BufferCheck ()) {
93
- utils . LogIngest ("Connections filled" )
103
+ slog . Debug ("Connections filled" )
94
104
continue
95
105
}
96
106
@@ -100,10 +110,10 @@ func SocketDataEventCallback(inputChan chan []byte, connectionFactory *connectio
100
110
// Since the Msg field might be mostly empty, binary.read fails.
101
111
// So we split the loading into the fixed size attribute parts, and copying the message separately.
102
112
103
- // fmt.Printf ("data: %v\n ", data)
113
+ // slog.Debug ("data", "data ", data)
104
114
105
115
if err := binary .Read (bytes .NewReader (data [:eventAttributesSize ]), bcc .GetHostByteOrder (), & event .Attr ); err != nil {
106
- utils . LogIngest ("Failed to decode received data: %+v " , err )
116
+ slog . Error ("Failed to decode received data" , "error " , err )
107
117
continue
108
118
}
109
119
@@ -120,7 +130,12 @@ func SocketDataEventCallback(inputChan chan []byte, connectionFactory *connectio
120
130
121
131
_ , ok := ignorePortsMap [connId .Port ]
122
132
if ignorePorts && ok {
123
- utils .LogIngest ("Ignoring data for ignore port fd: %v id: %v ts: %v rc: %v wc: %v\n " , connId .Fd , connId .Id , connId .Conn_start_ns , event .Attr .ReadEventsCount , event .Attr .WriteEventsCount )
133
+ slog .Debug ("Ignoring data for ignore port" ,
134
+ "fd" , connId .Fd ,
135
+ "id" , connId .Id ,
136
+ "timestamp" , connId .Conn_start_ns ,
137
+ "rc" , event .Attr .ReadEventsCount ,
138
+ "wc" , event .Attr .WriteEventsCount )
124
139
continue
125
140
}
126
141
@@ -134,6 +149,15 @@ func SocketDataEventCallback(inputChan chan []byte, connectionFactory *connectio
134
149
connectionFactory .SendEvent (connId , & event )
135
150
connections .UpdateBufferSize (uint64 (utils .Abs (bytesSent )))
136
151
137
- utils .LogIngest ("Got data fd: %v id: %v ts: %v ip: %v port: %v data: %v rc: %v wc: %v ssl: %v\n " , connId .Fd , connId .Id , connId .Conn_start_ns , connId .Ip , connId .Port , dataStr , event .Attr .ReadEventsCount , event .Attr .WriteEventsCount , event .Attr .Ssl )
152
+ slog .Debug ("Got data" ,
153
+ "fd" , connId .Fd ,
154
+ "id" , connId .Id ,
155
+ "timestamp" , connId .Conn_start_ns ,
156
+ "ip" , connId .Ip ,
157
+ "port" , connId .Port ,
158
+ "data" , dataStr ,
159
+ "rc" , event .Attr .ReadEventsCount ,
160
+ "wc" , event .Attr .WriteEventsCount ,
161
+ "ssl" , event .Attr .Ssl )
138
162
}
139
163
}
0 commit comments