(ctx context.Context, logger *zap.Logger, packet mysql.Packet, clientConn net.Conn, lastOp byte, decodeCtx *DecodeContext)
| 127 | } |
| 128 | |
| 129 | func decodePacket(ctx context.Context, logger *zap.Logger, packet mysql.Packet, clientConn net.Conn, lastOp byte, decodeCtx *DecodeContext) (*mysql.PacketBundle, error) { |
| 130 | //Get the Header & payload of the packet |
| 131 | header := packet.Header |
| 132 | payload := packet.Payload |
| 133 | |
| 134 | parsedPacket := &mysql.PacketBundle{ |
| 135 | Header: &mysql.PacketInfo{ |
| 136 | Header: &header, |
| 137 | }, |
| 138 | } |
| 139 | |
| 140 | payloadType := payload[0] |
| 141 | |
| 142 | var sg *mysql.HandshakeV10Packet |
| 143 | var ok bool |
| 144 | // No need to find the server greetings in the map if the payload is HandshakeV10 because it is the first packet and going to be stored in the map |
| 145 | if payloadType != mysql.HandshakeV10 { |
| 146 | sg, ok = decodeCtx.ServerGreetings.Load(clientConn) |
| 147 | if !ok { |
| 148 | return parsedPacket, fmt.Errorf("server Greetings not found") |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | logger.Debug("payload info", zap.Any("last operation", lastOp), zap.Any("payload type", payloadType)) |
| 153 | |
| 154 | // Handle handshakeResponse41 separately, because its status is not defined and can be changed with the client capabilities. |
| 155 | if lastOp == mysql.HandshakeV10 { |
| 156 | logger.Debug("HandshakeResponse41/SSL Request packet", zap.Any("Type", payloadType)) |
| 157 | pkt, err := connection.DecodeHandshakeResponse(ctx, logger, payload) |
| 158 | if err != nil { |
| 159 | return parsedPacket, fmt.Errorf("failed to decode HandshakeResponse41 packet: %w", err) |
| 160 | } |
| 161 | |
| 162 | var pktType string |
| 163 | switch pkt := pkt.(type) { |
| 164 | case *mysql.HandshakeResponse41Packet: |
| 165 | // Store the client capabilities to use it later |
| 166 | decodeCtx.ClientCapabilities = pkt.CapabilityFlags |
| 167 | |
| 168 | pktType = mysql.HandshakeResponse41 |
| 169 | lastOp = payloadType |
| 170 | case *mysql.SSLRequestPacket: |
| 171 | // Store the client capabilities to use it later |
| 172 | decodeCtx.ClientCapabilities = pkt.CapabilityFlags |
| 173 | |
| 174 | pktType = mysql.SSLRequest |
| 175 | decodeCtx.UseSSL = true |
| 176 | logger.Debug("SSL Request packet detected") |
| 177 | // Don't change the last operation if the packet is an SSL Request |
| 178 | } |
| 179 | |
| 180 | setPacketInfo(ctx, parsedPacket, pkt, pktType, clientConn, lastOp, decodeCtx) |
| 181 | |
| 182 | logger.Debug("HandshakeResponse41/SSL Request decoded", zap.Any("parsed packet", parsedPacket)) |
| 183 | |
| 184 | return parsedPacket, nil |
| 185 | } |
| 186 |
no test coverage detected