修复 client端抓包,client的 IP显示不准确的 bug
This commit is contained in:
parent
b74b4fed20
commit
87a877750f
|
@ -165,7 +165,7 @@ func (nc *networkCard) parseTCPPackage(packet gopacket.Packet, authHeader *pp.He
|
|||
}
|
||||
|
||||
// deal mysql server response
|
||||
err = readToServerPackage(clientIP, clientPort, &srcIP, srcPort, &dstIP, tcpPkt, nc.receiver)
|
||||
err = readToServerPackage(clientIP, clientPort, &dstIP, tcpPkt, nc.receiver)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ func (nc *networkCard) parseTCPPackage(packet gopacket.Packet, authHeader *pp.He
|
|||
}
|
||||
|
||||
func readFromServerPackage(
|
||||
srcIP *string, srcPort int, tcpPkt *layers.TCP) (err error) {
|
||||
clientIP *string, clientPort int, tcpPkt *layers.TCP) (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
log.Error("read Mysql package send from mysql server to client failed <-- %s", err.Error())
|
||||
|
@ -190,7 +190,7 @@ func readFromServerPackage(
|
|||
}()
|
||||
|
||||
if tcpPkt.FIN {
|
||||
sessionKey := spliceSessionKey(srcIP, srcPort)
|
||||
sessionKey := spliceSessionKey(clientIP, clientPort)
|
||||
session := sessionPool[*sessionKey]
|
||||
if session != nil {
|
||||
session.Close()
|
||||
|
@ -204,7 +204,7 @@ func readFromServerPackage(
|
|||
return
|
||||
}
|
||||
|
||||
sessionKey := spliceSessionKey(srcIP, srcPort)
|
||||
sessionKey := spliceSessionKey(clientIP, clientPort)
|
||||
session := sessionPool[*sessionKey]
|
||||
if session != nil {
|
||||
pkt := model.NewTCPPacket(tcpPayload, int64(tcpPkt.Ack), false)
|
||||
|
@ -215,7 +215,7 @@ func readFromServerPackage(
|
|||
}
|
||||
|
||||
func readToServerPackage(
|
||||
clientIP *string, clientPort int, srcIP *string, srcPort int, destIP *string, tcpPkt *layers.TCP,
|
||||
clientIP *string, clientPort int, destIP *string, tcpPkt *layers.TCP,
|
||||
receiver chan model.QueryPiece) (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
|
@ -225,7 +225,7 @@ func readToServerPackage(
|
|||
|
||||
// when client try close connection remove session from session pool
|
||||
if tcpPkt.FIN {
|
||||
sessionKey := spliceSessionKey(srcIP, srcPort)
|
||||
sessionKey := spliceSessionKey(clientIP, clientPort)
|
||||
session := sessionPool[*sessionKey]
|
||||
if session != nil {
|
||||
session.Close()
|
||||
|
@ -240,10 +240,10 @@ func readToServerPackage(
|
|||
return
|
||||
}
|
||||
|
||||
sessionKey := spliceSessionKey(srcIP, srcPort)
|
||||
sessionKey := spliceSessionKey(clientIP, clientPort)
|
||||
session := sessionPool[*sessionKey]
|
||||
if session == nil {
|
||||
session = sd.NewSession(sessionKey, clientIP, clientPort, srcIP, srcPort, destIP, snifferPort, receiver)
|
||||
session = sd.NewSession(sessionKey, clientIP, clientPort, destIP, snifferPort, receiver)
|
||||
sessionPool[*sessionKey] = session
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"github.com/zr-hebo/sniffer-agent/session-dealer/mysql"
|
||||
)
|
||||
|
||||
func NewSession(sessionKey, clientIP *string, clientPort int, srcIP *string, srcPort int, serverIP *string, serverPort int,
|
||||
func NewSession(sessionKey, clientIP *string, clientPort int, serverIP *string, serverPort int,
|
||||
receiver chan model.QueryPiece) (session ConnSession) {
|
||||
switch serviceType {
|
||||
case ServiceTypeMysql:
|
||||
session = mysql.NewMysqlSession(sessionKey, clientIP, clientPort, srcIP, srcPort, serverIP, serverPort, receiver)
|
||||
session = mysql.NewMysqlSession(sessionKey, clientIP, clientPort, serverIP, serverPort, receiver)
|
||||
default:
|
||||
session = mysql.NewMysqlSession(sessionKey, clientIP, clientPort, srcIP, srcPort, serverIP, serverPort, receiver)
|
||||
session = mysql.NewMysqlSession(sessionKey, clientIP, clientPort, serverIP, serverPort, receiver)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ type MysqlSession struct {
|
|||
visitDB *string
|
||||
clientIP *string
|
||||
clientPort int
|
||||
srcIP *string
|
||||
srcPort int
|
||||
serverIP *string
|
||||
serverPort int
|
||||
stmtBeginTimeNano int64
|
||||
|
@ -48,14 +46,12 @@ type prepareInfo struct {
|
|||
}
|
||||
|
||||
func NewMysqlSession(
|
||||
sessionKey, clientIP *string, clientPort int, srcIP *string, srcPort int, serverIP *string, serverPort int,
|
||||
sessionKey, clientIP *string, clientPort int, serverIP *string, serverPort int,
|
||||
receiver chan model.QueryPiece) (ms *MysqlSession) {
|
||||
ms = &MysqlSession{
|
||||
connectionID: sessionKey,
|
||||
clientIP: clientIP,
|
||||
clientPort: clientPort,
|
||||
srcIP: srcIP,
|
||||
srcPort: srcPort,
|
||||
serverIP: serverIP,
|
||||
serverPort: serverPort,
|
||||
stmtBeginTimeNano: time.Now().UnixNano(),
|
||||
|
@ -323,11 +319,11 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
|
|||
return mqp
|
||||
}
|
||||
|
||||
func filterQueryPieceBySQL(mqp *model.PooledMysqlQueryPiece, querySQL []byte) (*model.PooledMysqlQueryPiece) {
|
||||
func filterQueryPieceBySQL(mqp *model.PooledMysqlQueryPiece, querySQL []byte) *model.PooledMysqlQueryPiece {
|
||||
if mqp == nil || querySQL == nil {
|
||||
return nil
|
||||
|
||||
} else if (uselessSQLPattern.Match(querySQL)) {
|
||||
} else if uselessSQLPattern.Match(querySQL) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -341,10 +337,6 @@ func filterQueryPieceBySQL(mqp *model.PooledMysqlQueryPiece, querySQL []byte) (*
|
|||
func (ms *MysqlSession) composeQueryPiece() (mqp *model.PooledMysqlQueryPiece) {
|
||||
clientIP := ms.clientIP
|
||||
clientPort := ms.clientPort
|
||||
if clientIP == nil {
|
||||
clientIP = ms.srcIP
|
||||
clientPort = ms.serverPort
|
||||
}
|
||||
return model.NewPooledMysqlQueryPiece(
|
||||
ms.connectionID, clientIP, ms.visitUser, ms.visitDB, ms.serverIP,
|
||||
clientPort, ms.serverPort, communicator.GetMysqlCapturePacketRate(), ms.stmtBeginTimeNano)
|
||||
|
|
Loading…
Reference in New Issue