19
19
20
20
/*
21
21
TODO:
22
- main 函数 & 命令行参数处理
22
+
23
23
日志级别处理
24
24
FIX 5.7 EOF 问题 conn_data->num_fields = conn_data->stmt_num_params;
25
25
1. 处理 mysql 5.7 协议变更, 无 EOF packet
@@ -33,62 +33,6 @@ FIX 5.7 EOF 问题 conn_data->num_fields = conn_data->stmt_num_params;
33
33
OK: 支持多mysql端口
34
34
OK: 测试 新旧 两种协议 同时连接的场景
35
35
用简单的 strmap 处理 ResultSet 结果集?! string <=> string
36
-
37
-
38
- // 以下 打印处理
39
-
40
- decoding table: exec_flags
41
- static const value_string mysql_exec_flags_vals[] = {
42
- {MYSQL_CURSOR_TYPE_NO_CURSOR, "Defaults"},
43
- {MYSQL_CURSOR_TYPE_READ_ONLY, "Read-only cursor"},
44
- {MYSQL_CURSOR_TYPE_FOR_UPDATE, "Cursor for update"},
45
- {MYSQL_CURSOR_TYPE_SCROLLABLE, "Scrollable cursor"},
46
- {0, NULL}
47
- };
48
-
49
- decoding table: new_parameter_bound_flag
50
- static const value_string mysql_new_parameter_bound_flag_vals[] = {
51
- {0, "Subsequent call"},
52
- {1, "First call or rebound"},
53
- {0, NULL}
54
- };
55
-
56
- decoding table: exec_time_sign
57
- static const value_string mysql_exec_time_sign_vals[] = {
58
- {0, "Positive"},
59
- {1, "Negative"},
60
- {0, NULL}
61
- };
62
-
63
- allowed MYSQL_SHUTDOWN levels
64
- static const value_string mysql_shutdown_vals[] = {
65
- {0, "default"},
66
- {1, "wait for connections to finish"},
67
- {2, "wait for transactions to finish"},
68
- {8, "wait for updates to finish"},
69
- {16, "wait flush all buffers"},
70
- {17, "wait flush critical buffers"},
71
- {254, "kill running queries"},
72
- {255, "kill connections"},
73
- {0, NULL}
74
- };
75
-
76
-
77
- allowed MYSQL_SET_OPTION values
78
- static const value_string mysql_option_vals[] = {
79
- {0, "multi statements on"},
80
- {1, "multi statements off"},
81
- {0, NULL}
82
- };
83
-
84
- static const value_string mysql_session_track_type_vals[] = {
85
- {0, "SESSION_SYSVARS_TRACKER"},
86
- {1, "CURRENT_SCHEMA_TRACKER"},
87
- {2, "SESSION_STATE_CHANGE_TRACKER"},
88
- {0, NULL}
89
- };
90
-
91
-
92
36
*/
93
37
94
38
/* thanks for https://github.com/wireshark/wireshark/blob/master/epan/dissectors/packet-mysql.c */
@@ -1208,16 +1152,15 @@ mysql_dissect_request(struct buffer *buf, mysql_conn_data_t *conn_data)
1208
1152
case MYSQL_SHUTDOWN :
1209
1153
{
1210
1154
uint8_t mysql_shutdown = buf_readInt8 (buf );
1211
- UNUSED (mysql_shutdown );
1212
- LOG_INFO ("Mysql Shutdown" );
1155
+ LOG_INFO ("Mysql Shutdown %s(%d)" , mysql_get_shutdown_val (mysql_shutdown , "未知" ), mysql_shutdown );
1213
1156
}
1214
1157
mysql_set_conn_state (conn_data , RESPONSE_OK );
1215
1158
break ;
1216
1159
1217
1160
case MYSQL_SET_OPTION :
1218
1161
{
1219
1162
uint16_t mysql_option = buf_readInt16LE (buf );
1220
- LOG_INFO ("Mysql Set Option 0x%04x" , mysql_option );
1163
+ LOG_INFO ("Mysql Set Option %s( 0x%04x)" , mysql_get_option_val ( mysql_option , "未知" ) , mysql_option );
1221
1164
}
1222
1165
mysql_set_conn_state (conn_data , RESPONSE_OK );
1223
1166
break ;
@@ -1265,8 +1208,11 @@ mysql_dissect_request(struct buffer *buf, mysql_conn_data_t *conn_data)
1265
1208
uint8_t exec_flags = buf_readInt8 (buf );
1266
1209
uint32_t exec_iter = buf_readInt32LE (buf );
1267
1210
1268
- LOG_INFO ("Mysql Statement Id %u, Flags 0x%02x, Iter %u" ,
1269
- stmt_id , exec_flags , exec_iter );
1211
+ // 注意: 这里是+5.x协议, 不适用于4.x
1212
+ const char * tofree = mysql_get_exec_flags (exec_flags );
1213
+ LOG_INFO ("Mysql Statement Id %u, Flags %s(0x%02x), Iter %u" ,
1214
+ stmt_id , tofree , exec_flags , exec_iter );
1215
+ free ((void * )tofree );
1270
1216
1271
1217
khint_t k = kh_get (stmts , conn_data -> stmts , stmt_id );
1272
1218
int is_missing = (k == kh_end (conn_data -> stmts ));
@@ -1289,6 +1235,8 @@ mysql_dissect_request(struct buffer *buf, mysql_conn_data_t *conn_data)
1289
1235
buf_retrieve (buf , n );
1290
1236
1291
1237
uint8_t stmt_bound = buf_readInt8 (buf );
1238
+ LOG_INFO ("Mysql Parameter Bound: %s" , mysql_get_parameter_bound_val (stmt_bound , "未知" ));
1239
+
1292
1240
if (stmt_bound == 1 ) // First Call Or Rebound
1293
1241
{
1294
1242
int stmt_pos ;
@@ -1300,6 +1248,10 @@ mysql_dissect_request(struct buffer *buf, mysql_conn_data_t *conn_data)
1300
1248
break ;
1301
1249
}
1302
1250
}
1251
+ else
1252
+ {
1253
+ // TODO
1254
+ }
1303
1255
}
1304
1256
}
1305
1257
@@ -1680,6 +1632,7 @@ mysql_dissect_session_tracker_entry(struct buffer *buf)
1680
1632
1681
1633
/* session tracker type */
1682
1634
uint8_t data_type = buf_readInt8 (buf );
1635
+ LOG_INFO ("Mysql Session Tracker Type: %s(%d)" , mysql_get_session_track_type (data_type , "未知" ), data_type );
1683
1636
uint64_t length = buf_readFle (buf , & lenfle , NULL ); /* complete length of session tracking entry */
1684
1637
int sz = 1 + lenfle + length ;
1685
1638
@@ -1786,35 +1739,37 @@ mysql_dissect_exec_time(struct buffer *buf, uint8_t param_unsigned, int *param_i
1786
1739
uint8_t param_len = buf_readInt8 (buf );
1787
1740
* param_idx += sizeof (uint8_t );
1788
1741
1789
- uint8_t mysql_exec_field_time_sign = 0 ;
1790
- uint32_t mysql_exec_field_time_days = 0 ;
1791
- uint8_t mysql_exec_field_hour = 0 ;
1792
- uint8_t mysql_exec_field_minute = 0 ;
1793
- uint8_t mysql_exec_field_second = 0 ;
1794
- uint32_t mysql_exec_field_second_b = 0 ;
1742
+ // TODO struct
1743
+ uint8_t time_sign = 0 ;
1744
+ uint32_t time_days = 0 ;
1745
+ uint8_t hour = 0 ;
1746
+ uint8_t minute = 0 ;
1747
+ uint8_t second = 0 ;
1748
+ uint32_t second_b = 0 ;
1795
1749
1796
1750
if (param_len >= 1 )
1797
1751
{
1798
- mysql_exec_field_time_sign = buf_readInt8 (buf );
1752
+ time_sign = buf_readInt8 (buf );
1799
1753
* param_idx += sizeof (uint8_t );
1754
+ LOG_INFO ("Mysql Time Sign: %s" , mysql_get_time_sign (time_sign , "未知" ));
1800
1755
}
1801
1756
if (param_len >= 5 )
1802
1757
{
1803
- mysql_exec_field_time_days = buf_readInt32LE (buf );
1758
+ time_days = buf_readInt32LE (buf );
1804
1759
* param_idx += 3 ;
1805
1760
}
1806
1761
if (param_len >= 8 )
1807
1762
{
1808
- mysql_exec_field_hour = buf_readInt8 (buf );
1809
- mysql_exec_field_minute = buf_readInt8 (buf );
1810
- mysql_exec_field_second = buf_readInt8 (buf );
1763
+ hour = buf_readInt8 (buf );
1764
+ minute = buf_readInt8 (buf );
1765
+ second = buf_readInt8 (buf );
1811
1766
* param_idx += sizeof (uint8_t );
1812
1767
* param_idx += sizeof (uint8_t );
1813
1768
* param_idx += sizeof (uint8_t );
1814
1769
}
1815
1770
if (param_len >= 12 )
1816
1771
{
1817
- mysql_exec_field_second_b = buf_readInt32LE (buf );
1772
+ second_b = buf_readInt32LE (buf );
1818
1773
* param_idx += sizeof (uint32_t );
1819
1774
}
1820
1775
@@ -1837,38 +1792,39 @@ mysql_dissect_exec_datetime(struct buffer *buf, uint8_t param_unsigned, int *par
1837
1792
uint8_t param_len = buf_readInt8 (buf );
1838
1793
* param_idx += sizeof (uint8_t );
1839
1794
1840
- uint16_t mysql_exec_field_year = 0 ;
1841
- uint8_t mysql_exec_field_month = 0 ;
1842
- uint8_t mysql_exec_field_day = 0 ;
1843
- uint8_t mysql_exec_field_hour = 0 ;
1844
- uint8_t mysql_exec_field_minute = 0 ;
1845
- uint8_t mysql_exec_field_second = 0 ;
1846
- uint32_t mysql_exec_field_second_b = 0 ;
1795
+ // TODO struct
1796
+ uint16_t year = 0 ;
1797
+ uint8_t month = 0 ;
1798
+ uint8_t day = 0 ;
1799
+ uint8_t hour = 0 ;
1800
+ uint8_t minute = 0 ;
1801
+ uint8_t second = 0 ;
1802
+ uint32_t second_b = 0 ;
1847
1803
1848
1804
if (param_len >= 2 )
1849
1805
{
1850
- mysql_exec_field_year = buf_readInt16LE (buf );
1806
+ year = buf_readInt16LE (buf );
1851
1807
* param_idx += sizeof (uint16_t );
1852
1808
}
1853
1809
if (param_len >= 4 )
1854
1810
{
1855
- mysql_exec_field_month = buf_readInt8 (buf );
1856
- mysql_exec_field_day = buf_readInt8 (buf );
1811
+ month = buf_readInt8 (buf );
1812
+ day = buf_readInt8 (buf );
1857
1813
* param_idx += sizeof (uint8_t );
1858
1814
* param_idx += sizeof (uint8_t );
1859
1815
}
1860
1816
if (param_len >= 7 )
1861
1817
{
1862
- mysql_exec_field_hour = buf_readInt8 (buf );
1863
- mysql_exec_field_minute = buf_readInt8 (buf );
1864
- mysql_exec_field_second = buf_readInt8 (buf );
1818
+ hour = buf_readInt8 (buf );
1819
+ minute = buf_readInt8 (buf );
1820
+ second = buf_readInt8 (buf );
1865
1821
* param_idx += sizeof (uint8_t );
1866
1822
* param_idx += sizeof (uint8_t );
1867
1823
* param_idx += sizeof (uint8_t );
1868
1824
}
1869
1825
if (param_len >= 11 )
1870
1826
{
1871
- mysql_exec_field_second_b = buf_readInt32LE (buf );
1827
+ second_b = buf_readInt32LE (buf );
1872
1828
* param_idx += sizeof (uint32_t );
1873
1829
}
1874
1830
@@ -2325,14 +2281,15 @@ int main(int argc, char **argv)
2325
2281
assert (opts -> interface );
2326
2282
break ;
2327
2283
case 'p' :
2328
- // size_t needed = snprintf(NULL, 0, ,
2284
+ // size_t needed = snprintf(NULL, 0, ,
2329
2285
i += snprintf (opts -> expression + i , max_filter_sz - i - 1 , "tcp and ( port 0 " );
2330
2286
assert (i <= max_filter_sz - 1 );
2331
2287
while ((port = strsep (& optarg , "," )) != NULL )
2332
2288
{
2333
2289
if (port )
2334
2290
{
2335
- if (!atoi (port )) {
2291
+ if (!atoi (port ))
2292
+ {
2336
2293
LOG_ERROR ("端口号有误 %s" , port );
2337
2294
goto free ;
2338
2295
}
0 commit comments