@@ -848,8 +848,9 @@ static int event_srv_chk_w(int fd)
848
848
849
849
/*
850
850
* This function is used only for server health-checks. It handles the server's
851
- * reply to an HTTP request or SSL HELLO. It calls set_server_check_status() to
852
- * update s->check_status, s->check_duration and s->result.
851
+ * reply to an HTTP request, SSL HELLO or MySQL client Auth. It calls
852
+ * set_server_check_status() to update s->check_status, s->check_duration
853
+ * and s->result.
853
854
854
855
* The set_server_check_status function is called with HCHK_STATUS_L7OKD if
855
856
* an HTTP server replies HTTP 2xx or 3xx (valid responses), if an SMTP server
@@ -1001,36 +1002,91 @@ static int event_srv_chk_r(int fd)
1001
1002
set_server_check_status (s , HCHK_STATUS_L7STS , desc );
1002
1003
}
1003
1004
else if (s -> proxy -> options2 & PR_O2_MYSQL_CHK ) {
1004
- /* MySQL Error packet always begin with field_count = 0xff
1005
- * contrary to OK Packet who always begin whith 0x00 */
1006
1005
if (!done && s -> check_data_len < 5 )
1007
1006
goto wait_more_data ;
1008
1007
1009
- if (* (s -> check_data + 4 ) != '\xff' ) {
1010
- /* We set the MySQL Version in description for information purpose
1011
- * FIXME : it can be cool to use MySQL Version for other purpose,
1012
- * like mark as down old MySQL server.
1013
- */
1014
- if (s -> check_data_len > 51 ) {
1015
- desc = ltrim (s -> check_data + 5 , ' ' );
1016
- set_server_check_status (s , HCHK_STATUS_L7OKD , desc );
1008
+ if (s -> proxy -> check_len == 0 ) { // old mode
1009
+ if (* (s -> check_data + 4 ) != '\xff' ) {
1010
+ /* We set the MySQL Version in description for information purpose
1011
+ * FIXME : it can be cool to use MySQL Version for other purpose,
1012
+ * like mark as down old MySQL server.
1013
+ */
1014
+ if (s -> check_data_len > 51 ) {
1015
+ desc = ltrim (s -> check_data + 5 , ' ' );
1016
+ set_server_check_status (s , HCHK_STATUS_L7OKD , desc );
1017
+ }
1018
+ else {
1019
+ if (!done )
1020
+ goto wait_more_data ;
1021
+ /* it seems we have a OK packet but without a valid length,
1022
+ * it must be a protocol error
1023
+ */
1024
+ set_server_check_status (s , HCHK_STATUS_L7RSP , s -> check_data );
1025
+ }
1026
+ }
1027
+ else {
1028
+ /* An error message is attached in the Error packet */
1029
+ desc = ltrim (s -> check_data + 7 , ' ' );
1030
+ set_server_check_status (s , HCHK_STATUS_L7STS , desc );
1031
+ }
1032
+ } else {
1033
+ unsigned int first_packet_len = ((unsigned int ) * s -> check_data ) +
1034
+ (((unsigned int ) * (s -> check_data + 1 )) << 8 ) +
1035
+ (((unsigned int ) * (s -> check_data + 2 )) << 16 );
1036
+
1037
+ if (s -> check_data_len == first_packet_len + 4 ) {
1038
+ /* MySQL Error packet always begin with field_count = 0xff */
1039
+ if (* (s -> check_data + 4 ) != '\xff' ) {
1040
+ /* We have only one MySQL packet and it is a Handshake Initialization packet
1041
+ * but we need to have a second packet to know if it is alright
1042
+ */
1043
+ if (!done && s -> check_data_len < first_packet_len + 5 )
1044
+ goto wait_more_data ;
1045
+ }
1046
+ else {
1047
+ /* We have only one packet and it is an Error packet,
1048
+ * an error message is attached, so we can display it
1049
+ */
1050
+ desc = & s -> check_data [7 ];
1051
+ //Warning("onlyoneERR: %s\n", desc);
1052
+ set_server_check_status (s , HCHK_STATUS_L7STS , desc );
1053
+ }
1054
+ } else if (s -> check_data_len > first_packet_len + 4 ) {
1055
+ unsigned int second_packet_len = ((unsigned int ) * (s -> check_data + first_packet_len + 4 )) +
1056
+ (((unsigned int ) * (s -> check_data + first_packet_len + 5 )) << 8 ) +
1057
+ (((unsigned int ) * (s -> check_data + first_packet_len + 6 )) << 16 );
1058
+
1059
+ if (s -> check_data_len == first_packet_len + 4 + second_packet_len + 4 ) {
1060
+ /* We have 2 packets and that's good */
1061
+ /* Check if the second packet is a MySQL Error packet or not */
1062
+ if (* (s -> check_data + first_packet_len + 8 ) != '\xff' ) {
1063
+ /* No error packet */
1064
+ /* We set the MySQL Version in description for information purpose */
1065
+ desc = & s -> check_data [5 ];
1066
+ //Warning("2packetOK: %s\n", desc);
1067
+ set_server_check_status (s , HCHK_STATUS_L7OKD , desc );
1068
+ }
1069
+ else {
1070
+ /* An error message is attached in the Error packet
1071
+ * so we can display it ! :)
1072
+ */
1073
+ desc = & s -> check_data [first_packet_len + 11 ];
1074
+ //Warning("2packetERR: %s\n", desc);
1075
+ set_server_check_status (s , HCHK_STATUS_L7STS , desc );
1076
+ }
1077
+ }
1017
1078
}
1018
1079
else {
1019
1080
if (!done )
1020
1081
goto wait_more_data ;
1021
- /* it seems we have a OK packet but without a valid length,
1082
+ /* it seems we have a Handshake Initialization packet but without a valid length,
1022
1083
* it must be a protocol error
1023
1084
*/
1024
- set_server_check_status (s , HCHK_STATUS_L7RSP , s -> check_data );
1085
+ desc = & s -> check_data [5 ];
1086
+ //Warning("protoerr: %s\n", desc);
1087
+ set_server_check_status (s , HCHK_STATUS_L7RSP , desc );
1025
1088
}
1026
1089
}
1027
- else {
1028
- /* An error message is attached in the Error packet,
1029
- * so we can display it ! :)
1030
- */
1031
- desc = ltrim (s -> check_data + 7 , ' ' );
1032
- set_server_check_status (s , HCHK_STATUS_L7STS , desc );
1033
- }
1034
1090
}
1035
1091
else if (s -> proxy -> options2 & PR_O2_LDAP_CHK ) {
1036
1092
if (!done && s -> check_data_len < 14 )
0 commit comments