deal all auth packet

This commit is contained in:
hebo 2019-11-13 13:47:56 +08:00
parent 1b0d2c8e91
commit 16722c878c
3 changed files with 7 additions and 7 deletions

View File

@ -134,10 +134,9 @@ func (nc *networkCard) listenNormal() {
// send FIN tcp packet to avoid not complete session cannot be released
tcpPkt := packet.TransportLayer().(*layers.TCP)
payLoad := tcpPkt.Payload
// deal FIN packet
// deal auth packet
if tcpPkt.FIN || (len(payLoad) >= 5 && sd.IsAuthPacket(payLoad[4])) {
if tcpPkt.FIN || sd.IsAuthPacket(tcpPkt.Payload) {
nc.parseTCPPackage(packet)
continue
}

View File

@ -25,11 +25,12 @@ func CheckParams() {
}
}
func IsAuthPacket(val byte) bool {
func IsAuthPacket(payload []byte) bool {
switch serviceType {
case ServiceTypeMysql:
return mysql.IsAuthPacket(val)
return len(payload) >= 5 && mysql.IsAuth(payload[4])
default:
return mysql.IsAuthPacket(val)
return false
}
}

View File

@ -208,7 +208,7 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
// ms.expectReceiveSize = ms.expectReceiveSize - int(contentSize)
}
func IsAuthPacket(val byte) bool {
func IsAuth(val byte) bool {
return val > 32
}
@ -231,7 +231,7 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
var mqp *model.PooledMysqlQueryPiece
var querySQLInBytes []byte
if IsAuthPacket(ms.cachedStmtBytes[0]) {
if IsAuth(ms.cachedStmtBytes[0]) {
userName, dbName, err := parseAuthInfo(ms.cachedStmtBytes)
if err != nil {
log.Errorf("parse auth info failed <-- %s", err.Error())