Skip to content

Commit 29ef115

Browse files
authored
Adding Access Log Service E2E Test (#127)
1 parent 446fa2e commit 29ef115

26 files changed

+857
-95
lines changed

.github/workflows/rover.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ jobs:
149149
base: test/e2e/cases/process/istio
150150
config: e2e.yaml
151151
env: ISTIO_VERSION=1.13.1
152+
153+
- name: Access Log
154+
base: test/e2e/cases/access_log
155+
config: e2e.yaml
152156
steps:
153157
- uses: actions/checkout@v3
154158
with:

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Release Notes.
88
* Upgrade LLVM to `18`.
99

1010
#### Bug Fixes
11+
* Fixed the issue where `conntrack` could not find the Reply IP in the access log module.
1112

1213
#### Documentation
1314

pkg/accesslog/collector/connect.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package collector
1919

2020
import (
2121
"encoding/binary"
22+
"net"
2223

2324
"github.com/sirupsen/logrus"
2425

@@ -99,6 +100,26 @@ func (c *ConnectCollector) Start(_ *module.Manager, context *common.AccessLogCon
99100
func (c *ConnectCollector) Stop() {
100101
}
101102

103+
func (c *ConnectCollector) fixSocketFamilyIfNeed(event *events.SocketConnectEvent, result *ip.SocketPair) {
104+
if result == nil {
105+
return
106+
}
107+
if parseIP := net.ParseIP(result.SrcIP); parseIP != nil {
108+
var actual uint32
109+
if parseIP.To4() != nil {
110+
actual = unix.AF_INET
111+
} else {
112+
actual = unix.AF_INET6
113+
}
114+
115+
if result.Family != actual {
116+
connectLogger.Debugf("fix the socket family from %d to %d, connection ID: %d, randomID: %d",
117+
result.Family, actual, event.ConID, event.RandomID)
118+
result.Family = actual
119+
}
120+
}
121+
}
122+
102123
func (c *ConnectCollector) buildSocketFromConnectEvent(event *events.SocketConnectEvent) *ip.SocketPair {
103124
if event.SocketFamily != unix.AF_INET && event.SocketFamily != unix.AF_INET6 && event.SocketFamily != enums.SocketFamilyUnknown {
104125
// if not ipv4, ipv6 or unknown, ignore
@@ -122,6 +143,7 @@ func (c *ConnectCollector) buildSocketFromConnectEvent(event *events.SocketConne
122143
connectLogger.Debugf("found the connection from the socket, connection ID: %d, randomID: %d",
123144
event.ConID, event.RandomID)
124145
pair.Role = enums.ConnectionRole(event.Role)
146+
c.fixSocketFamilyIfNeed(event, pair)
125147
c.tryToUpdateSocketFromConntrack(event, pair)
126148
return pair
127149
}
@@ -193,12 +215,14 @@ func (c *ConnectCollector) buildSocketPair(event *events.SocketConnectEvent) *ip
193215
return result
194216
}
195217

218+
c.fixSocketFamilyIfNeed(event, result)
196219
c.tryToUpdateSocketFromConntrack(event, result)
197220
return result
198221
}
199222

200223
func (c *ConnectCollector) tryToUpdateSocketFromConntrack(event *events.SocketConnectEvent, socket *ip.SocketPair) {
201-
if socket != nil && socket.IsValid() && c.connTracker != nil && !tools.IsLocalHostAddress(socket.DestIP) {
224+
if socket != nil && socket.IsValid() && c.connTracker != nil && !tools.IsLocalHostAddress(socket.DestIP) &&
225+
event.FuncName != enums.SocketFunctionNameAccept { // accept event don't need to update the remote address
202226
// if no contract and socket data is valid, then trying to get the remote address from the socket
203227
// to encase the remote address is not the real remote address
204228
originalIP := socket.DestIP

pkg/accesslog/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ func (r *Runner) buildAccessLogMessage(firstLog, firstConnection bool, conn *com
241241
rpcCon = conn.RPCConnection
242242
if log.Enable(logrus.DebugLevel) {
243243
log.Debugf("ready to sending access log with connection, connection ID: %d, random ID: %d, "+
244-
"local: %s, remote: %s, role: %s",
245-
conn.ConnectionID, conn.RandomID, rpcCon.Local, rpcCon.Remote, rpcCon.Role)
244+
"local: %s, remote: %s, role: %s, kernel logs count: %d, contains protocol log: %t",
245+
conn.ConnectionID, conn.RandomID, rpcCon.Local, rpcCon.Remote, rpcCon.Role,
246+
len(kernelLogs), protocolLog != nil)
246247
}
247248
}
248249
return &v3.EBPFAccessLogMessage{

pkg/tools/ip/conntrack.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ import (
3030

3131
var log = logger.GetLogger("tools", "ip")
3232

33-
var numberStrategies = map[string]uint8{"tcp": syscall.IPPROTO_TCP, "udp": syscall.IPPROTO_UDP}
33+
var numberStrategies = []struct {
34+
name string
35+
proto uint8
36+
}{{
37+
name: "tcp",
38+
proto: syscall.IPPROTO_TCP,
39+
}, {
40+
name: "udp",
41+
proto: syscall.IPPROTO_UDP,
42+
}}
3443

3544
type ConnTrack struct {
3645
tracker *conntrack.Nfct
@@ -51,13 +60,15 @@ func (c *ConnTrack) UpdateRealPeerAddress(addr *SocketPair) bool {
5160
}
5261

5362
tuple := c.parseSocketToTuple(addr)
54-
for name, strategy := range numberStrategies {
55-
tuple.Proto.Number = &strategy
63+
for _, info := range numberStrategies {
64+
tuple.Proto.Number = &(info.proto)
5665

66+
// using get to query protocol
5767
session, e := c.tracker.Get(conntrack.Conntrack, family, conntrack.Con{Origin: tuple})
5868
if e != nil {
59-
// try to get the reply session, if the strategy not exists or from accept events, have error is normal
60-
log.Debugf("cannot get the conntrack session, strategy: %s, error: %v", name, e)
69+
// try to get the reply session, if the info not exists or from accept events, have error is normal
70+
log.Debugf("cannot get the conntrack session, type: %s, family: %d, origin src: %s:%d, origin dest: %s:%d, error: %v", info.name,
71+
family, tuple.Src, *tuple.Proto.SrcPort, tuple.Dst, *tuple.Proto.DstPort, e)
6172
continue
6273
}
6374

@@ -67,6 +78,16 @@ func (c *ConnTrack) UpdateRealPeerAddress(addr *SocketPair) bool {
6778
}
6879
}
6980

81+
// using dump to query protocol
82+
dump, e := c.tracker.Dump(conntrack.Conntrack, family)
83+
if e != nil {
84+
log.Debug("cannot dump the conntrack session, error: ", e)
85+
return false
86+
}
87+
if res := c.filterValidateReply(dump, tuple); res != nil {
88+
addr.DestIP = res.Src.String()
89+
return true
90+
}
7091
return false
7192
}
7293

test/e2e/base/env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
SW_CTL_COMMIT=6b2eb0011e38b630db6af7203db215806bd141ed
17-
SW_OAP_COMMIT=9ba0ad299139eeb4bb4e274c500cec1deaf84f79
16+
SW_CTL_COMMIT=ee371a210afe2dc6e65c2229b6a0519f8a4a2752
17+
SW_OAP_COMMIT=7a8bbacd20381bc780c48abf5706fd6e529c9872
1818
SW_KUBERNETES_COMMIT_SHA=a14f386063fffc61ed9b396e1328b76d33239aba
1919

2020
SW_AGENT_GO_COMMIT=216f122d942cb683f48578d3014cc5ea83637582

0 commit comments

Comments
 (0)