summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2024-08-13 16:31:03 +0800
committerlijia <[email protected]>2024-08-13 16:31:03 +0800
commit28ebeda1f4d52d8784961d14171d27ced621616d (patch)
treef84da79bfcd553fabadc2a6c909e9b8eedd5eee1
parent2a1ca8defbc5b461f4a6a40a2f4b98653eea007b (diff)
add get_session_addr, tcp_segment_get_data, tcp out-of-order test case.
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/PreInstall.sh2
-rw-r--r--cmake/PreUninstall.sh2
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/http_decoder.cpp92
-rw-r--r--src/http_decoder_half.cpp111
-rw-r--r--src/http_decoder_inc.h6
-rw-r--r--src/http_decoder_tunnel.cpp18
-rw-r--r--src/http_decoder_tunnel.h6
-rw-r--r--src/http_decoder_utils.cpp221
-rw-r--r--src/http_decoder_utils.h18
-rw-r--r--test/http_pcap/http_out_of_order.pcapbin0 -> 74700 bytes
-rw-r--r--test/http_pcap/http_url_test_without_host_v6.pcapbin0 -> 1931 bytes
-rw-r--r--test/test_result_json/http_out_of_order.json43
-rw-r--r--test/test_result_json/http_url_test_without_host.json2
-rw-r--r--test/test_result_json/http_url_test_without_host_v6.json42
-rw-r--r--test_based_on_stellar/CMakeLists.txt6
-rw-r--r--test_based_on_stellar/env/stellar.toml20
-rw-r--r--test_based_on_stellar/plugin_test_main.cpp5
-rw-r--r--vendor/CMakeLists.txt17
-rw-r--r--vendor/brotli-v1.0.9.tar.gzbin0 -> 486984 bytes
22 files changed, 429 insertions, 193 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 92f6c5c..416b839 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,7 +4,7 @@ variables:
BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
INSTALL_DEPENDENCY_LIBRARY: framework_env libMESA_prof_load-devel libasan
libMESA_handle_logger-devel libfieldstat4-devel libfieldstat4
- zlib-devel brotli brotli-devel stellar-devel systemd-devel
+ zlib-devel stellar-devel systemd-devel
SYMBOL_TARGET: http_decoder
TEST_NAME: gtest_http_decoder
INSTALL_PREFIX: "/opt/tsg/"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c2c41b..627a10f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -90,9 +90,9 @@ enable_testing()
add_subdirectory(test)
add_subdirectory(test_based_on_stellar)
-set(CPACK_RPM_LIBRARIES_USER_FILELIST "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/sapp/etc/http/http_decoder.toml")
+set(CPACK_RPM_LIBRARIES_USER_FILELIST "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/stellar/etc/http/http_decoder.toml")
-install(FILES conf/http_decoder.toml DESTINATION ${CMAKE_INSTALL_PREFIX}/sapp/etc/http COMPONENT PROFILE)
+install(FILES conf/http_decoder.toml DESTINATION ${CMAKE_INSTALL_PREFIX}/stellar/etc/http COMPONENT PROFILE)
install(FILES include/http_decoder.h DESTINATION ${CMAKE_INSTALL_PREFIX}/framework/include/http_decoder COMPONENT HEADER)
SET(CPACK_RPM_LIBRARIES_PRE_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/cmake/PreInstall.sh")
diff --git a/cmake/PreInstall.sh b/cmake/PreInstall.sh
index 94f8c5f..4f4016a 100644
--- a/cmake/PreInstall.sh
+++ b/cmake/PreInstall.sh
@@ -1,4 +1,4 @@
-DST=${RPM_INSTALL_PREFIX}/sapp/
+DST=${RPM_INSTALL_PREFIX}/stellar/
mkdir -p ${DST}/plugin
touch ${DST}/plugin/spec.toml
diff --git a/cmake/PreUninstall.sh b/cmake/PreUninstall.sh
index e694083..b32759a 100644
--- a/cmake/PreUninstall.sh
+++ b/cmake/PreUninstall.sh
@@ -1,5 +1,5 @@
if [ $1 == 0 ]; then
- DST=${RPM_INSTALL_PREFIX}/sapp/plugin
+ DST=${RPM_INSTALL_PREFIX}/stellar/plugin
sed -i -n '$!N;/http_decoder.so/!P;D' ${DST}/spec.toml
sed -i '/http_decoder_init/d' ${DST}/spec.toml
sed -i '/http_decoder_exit/d' ${DST}/spec.toml
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 76d8603..99b039d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,7 +15,8 @@ set(HTTP_SRC ${DEPS_SRC} http_decoder.cpp http_decoder_utils.cpp http_decoder_ha
add_library(http_decoder SHARED ${HTTP_SRC})
set_target_properties(http_decoder PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/src/version.map")
-target_link_libraries(http_decoder z brotlidec llhttp-static fieldstat4 stellar_devel)
+target_link_libraries(http_decoder z llhttp-static fieldstat4)
+target_link_libraries(http_decoder brotli-dec-static brotli-common-static )
set_target_properties(http_decoder PROPERTIES PREFIX "")
-install(TARGETS http_decoder LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/sapp/plugin/${lib_name} COMPONENT LIBRARIES) \ No newline at end of file
+install(TARGETS http_decoder LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/plugin/${lib_name} COMPONENT LIBRARIES) \ No newline at end of file
diff --git a/src/http_decoder.cpp b/src/http_decoder.cpp
index 640217b..08caaba 100644
--- a/src/http_decoder.cpp
+++ b/src/http_decoder.cpp
@@ -92,7 +92,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
exdata->tunnel_state = HTTP_TUN_C2S_HDR_START;
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TUNNEL, 1);
}
- if (httpd_is_tunnel_session(exdata))
+ if (httpd_is_tunnel_session(httpd_env,exdata))
{
http_decoder_get_url(half_data, mempool);
}
@@ -146,7 +146,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_FREE, 1);
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S, 1);
}
- if (httpd_is_tunnel_session(exdata))
+ if (httpd_is_tunnel_session(httpd_env,exdata))
{
if (SESSION_SEEN_C2S_FLOW == flow_flag)
{
@@ -236,7 +236,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
int tot_s2c_headers = http_half_data_get_total_parsed_header_count(half_data);
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_HEADERS_S2C, tot_s2c_headers);
- if (httpd_is_tunnel_session(exdata))
+ if (httpd_is_tunnel_session(httpd_env,exdata))
{
exdata->tunnel_state = HTTP_TUN_INNER_STARTING;
http_half_pre_context_free(ev_ctx->ref_session, exdata);
@@ -567,27 +567,7 @@ extern "C"
void *httpd_session_ctx_new_cb(struct session *sess, void *plugin_env)
{
- // If not http, ignore this session
- uint16_t payload_len;
- struct http_decoder_env *httpd_env = (struct http_decoder_env *)plugin_env;
- const char *payload = session_get0_current_payload(sess, &payload_len);
- if (payload != NULL && payload_len > 0)
- {
- size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN ? HTTP_IDENTIFY_LEN : payload_len;
- int ret = http_protocol_identify(payload, http_identify_len);
- if (ret < 0)
- {
- stellar_session_plugin_dettach_current_session(sess);
- return (void *)HTTP_CTX_NOT_HTTP;
- }
- struct http_decoder_exdata *exdata = httpd_session_exdata_new(sess, httpd_env, 0, 0);
- exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_MSG_INDEX].sub_topic_id;
- session_exdata_set(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id, exdata);
- return (void *)HTTP_CTX_IS_HTTP;
- }
-
- stellar_session_plugin_dettach_current_session(sess);
- return (void *)HTTP_CTX_NOT_HTTP;
+ return (void *)HTTP_CTX_IS_HTTP;
}
void httpd_session_ctx_free_cb(struct session *sess, void *session_ctx, void *plugin_env)
@@ -619,18 +599,11 @@ extern "C"
}
}
- static void http_decoder_execute(struct session *sess, struct http_decoder_env *httpd_env, http_decoder_exdata *exdata)
+ static void http_decoder_execute(struct session *sess, struct http_decoder_env *httpd_env, http_decoder_exdata *exdata, const char *payload, uint16_t payload_len)
{
- uint16_t payload_len;
- const char *payload = session_get0_current_payload(sess, &payload_len);
- if (unlikely(0 == payload_len || NULL == payload))
- {
- return;
- }
-
- if (httpd_in_tunnel_transmitting(exdata))
+ if (httpd_in_tunnel_transmitting(httpd_env,exdata))
{
- http_decoder_push_tunnel_data(sess, exdata, httpd_tunnel_state_to_msg(exdata));
+ http_decoder_push_tunnel_data(sess, exdata, httpd_tunnel_state_to_msg(exdata), payload, payload_len);
httpd_tunnel_state_update(exdata);
return;
}
@@ -667,9 +640,18 @@ extern "C"
{
return;
}
+ hstring tunnel_payload;
+ http_tunnel_message_get_payload((const struct http_tunnel_message *)tmsg, &tunnel_payload);
+ uint16_t payload_len = tunnel_payload.iov_len;
+ const char *payload = (char *)tunnel_payload.iov_base;
+ if (NULL == payload || 0 == payload_len)
+ {
+ return;
+ }
struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)session_exdata_get(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_TUNNEL_INDEX].exdata_id);
enum http_tunnel_message_type tmsg_type = http_tunnel_message_type_get((const struct http_tunnel_message *)tmsg);
+
switch (tmsg_type)
{
case HTTP_TUNNEL_OPENING:
@@ -680,8 +662,6 @@ extern "C"
session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
return;
}
- uint16_t payload_len;
- const char *payload = session_get0_current_payload(sess, &payload_len);
size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN ? HTTP_IDENTIFY_LEN : payload_len;
int is_http = http_protocol_identify(payload, http_identify_len);
if (is_http)
@@ -730,7 +710,7 @@ extern "C"
}
if (exdata->in_tunnel_is_http)
{
- http_decoder_execute(sess, httpd_env, exdata);
+ http_decoder_execute(sess, httpd_env, exdata, payload, payload_len);
}
return;
}
@@ -738,21 +718,16 @@ extern "C"
void http_decoder_tcp_stream_msg_cb(struct session *sess, int topic_id, const void *msg, void *nouse_session_ctx, void *plugin_env)
{
struct http_decoder_env *httpd_env = (struct http_decoder_env *)plugin_env;
- enum session_state sess_state = session_get_current_state(sess);
struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)session_exdata_get(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id);
-
- if (NULL == exdata)
- {
- http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1);
- stellar_session_plugin_dettach_current_session(sess);
- return;
- }
+ enum session_state sess_state = session_get_current_state(sess);
+ const char *payload = NULL;
+ uint16_t payload_len = 0;
if (SESSION_STATE_CLOSED == sess_state)
{
- if (httpd_in_tunnel_transmitting(exdata))
+ if (httpd_in_tunnel_transmitting(httpd_env,exdata))
{
- http_decoder_push_tunnel_data(sess, exdata, HTTP_TUNNEL_CLOSING);
+ http_decoder_push_tunnel_data(sess, exdata, HTTP_TUNNEL_CLOSING, NULL, 0);
}
else
{
@@ -760,9 +735,28 @@ extern "C"
}
return;
}
+ assert(msg != NULL);
- http_decoder_execute(sess, httpd_env, exdata);
-
+ payload_len = tcp_segment_get_len((struct tcp_segment *)msg);
+ payload = tcp_segment_get_data((const struct tcp_segment *)msg);
+ if (unlikely(0 == payload_len || NULL == payload))
+ {
+ return;
+ }
+ if (NULL == exdata)//first packet
+ {
+ size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN ? HTTP_IDENTIFY_LEN : payload_len;
+ int ret = http_protocol_identify(payload, http_identify_len);
+ if (ret < 0)
+ {
+ stellar_session_plugin_dettach_current_session(sess);
+ return;
+ }
+ exdata = httpd_session_exdata_new(sess, httpd_env, 0, 0);
+ exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_MSG_INDEX].sub_topic_id;
+ session_exdata_set(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id, exdata);
+ }
+ http_decoder_execute(sess, httpd_env, exdata, payload, payload_len);
return;
}
diff --git a/src/http_decoder_half.cpp b/src/http_decoder_half.cpp
index a522ba6..9ed171c 100644
--- a/src/http_decoder_half.cpp
+++ b/src/http_decoder_half.cpp
@@ -44,7 +44,7 @@ struct http_decoder_half
long long trans_counter;
long long err_counter;
- long long transaction_seq; //accumulated
+ long long transaction_seq; // accumulated
const char *data;
int data_len;
@@ -66,7 +66,7 @@ static void printf_debug_info(const char *desc, const char *at, size_t length)
}
}
#else
-#define printf_debug_info(desc, at, length)
+#define printf_debug_info(desc, at, length)
#endif
static void
@@ -425,7 +425,7 @@ static int on_header_value_complete(llhttp_t *http)
}
}
- if(http->type == HTTP_REQUEST)
+ if (http->type == HTTP_REQUEST)
{
http_decoder_get_host_feed_url(half);
}
@@ -478,7 +478,7 @@ static int on_headers_complete(llhttp_t *http)
{
half->event = HTTP_EVENT_RES_HDR_END;
}
- half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx, half->httpd_env); // http_event_handler()
+ half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx, half->httpd_env); // http_event_handler()
return 0;
}
@@ -576,13 +576,13 @@ static void http_decoder_half_init(struct http_decoder_half *half, http_event_cb
half->settings.on_body = on_body;
half->error = HPE_OK;
- half->http_ev_cb = http_ev_cb; // http_event_handler()
+ half->http_ev_cb = http_ev_cb; // http_event_handler()
half->ref_data = NULL;
}
-struct http_decoder_half * http_decoder_half_new(struct http_decoder_exdata *hd_ctx, nmx_pool_t *mempool,
- http_event_cb *ev_cb, enum llhttp_type http_type,
- int decompress_switch, struct http_decoder_env *httpd_env, long long start_seq)
+struct http_decoder_half *http_decoder_half_new(struct http_decoder_exdata *hd_ctx, nmx_pool_t *mempool,
+ http_event_cb *ev_cb, enum llhttp_type http_type,
+ int decompress_switch, struct http_decoder_env *httpd_env, long long start_seq)
{
struct http_decoder_half *half = MEMPOOL_CALLOC(mempool, struct http_decoder_half, 1);
assert(half);
@@ -612,7 +612,7 @@ void http_decoder_half_free(nmx_pool_t *mempool, struct http_decoder_half *half)
MEMPOOL_FREE(mempool, half);
}
-void http_decoder_half_reinit(struct http_decoder_half *half,
+void http_decoder_half_reinit(struct http_decoder_half *half,
struct http_decoder_result_queue *queue,
nmx_pool_t *mempool, struct session *sess)
{
@@ -632,12 +632,15 @@ static void publish_message_for_parsed_header(struct http_decoder_half *half)
{
return;
}
- if (half->parser.type == HTTP_REQUEST){
+ if (half->parser.type == HTTP_REQUEST)
+ {
half->event = HTTP_EVENT_REQ_HDR;
- }else{
+ }
+ else
+ {
half->event = HTTP_EVENT_RES_HDR;
}
- half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx, half->httpd_env); // http_event_handler();
+ half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx, half->httpd_env); // http_event_handler();
return;
}
@@ -661,7 +664,8 @@ int http_decoder_half_parse(int proxy_enable, struct http_decoder_half *half, co
llhttp_resume(&half->parser);
break;
case HPE_PAUSED_UPGRADE:
- if(proxy_enable){
+ if (proxy_enable)
+ {
llhttp_resume_after_upgrade(&half->parser);
}
ret = 0;
@@ -707,9 +711,9 @@ int http_decoder_half_parse(int proxy_enable, struct http_decoder_half *half, co
{
http_decoder_table_reset_header_complete(half->ref_data->table);
}
- else
+ else
{
- //if headers are not completed with EOF \r\n\r\n, push the parsed headers so far
+ // if headers are not completed with EOF \r\n\r\n, push the parsed headers so far
publish_message_for_parsed_header(half);
}
@@ -915,28 +919,30 @@ void http_decoder_half_data_dump(struct http_decoder_half *half)
static void using_session_addr_as_host(struct session *ref_session,
struct http_header *host_result, nmx_pool_t *mempool)
{
-#if 0 //todo, in native steallar, can't get the tuple4 from the session yet!!!
- const struct session_addr *ssaddr;
- enum session_addr_type ssaddr_type;
- ssaddr = session_get0_addr(ref_session, &ssaddr_type);
- if (!ssaddr)
+#if 1 // in native steallar, can't get the tuple4 from the session yet!!!
+ struct httpd_session_addr ssaddr = {};
+ httpd_session_get_addr(ref_session, &ssaddr);
+ if (ssaddr.ipver != 4 && ssaddr.ipver != 6)
{
- assert(0);
+ host_result->val.iov_base = MEMPOOL_CALLOC(mempool, char, 1);
+ sprintf((char *)host_result->val.iov_base, "%s", "");
+ host_result->val.iov_len = strlen((char *)host_result->val.iov_base);
+ return;
}
char ip_string_buf[INET6_ADDRSTRLEN];
- if (SESSION_ADDR_TYPE_IPV4_TCP == ssaddr_type || SESSION_ADDR_TYPE_IPV4_UDP == ssaddr_type)
+ if (4 == ssaddr.ipver)
{
host_result->val.iov_base = MEMPOOL_CALLOC(mempool, char, (INET_ADDRSTRLEN + 7) /* "ip:port" max length */);
- inet_ntop(AF_INET, &ssaddr->ipv4.daddr, ip_string_buf, INET_ADDRSTRLEN);
- sprintf((char *)host_result->val.iov_base, "%s:%u", ip_string_buf, ntohs(ssaddr->ipv4.dport));
+ inet_ntop(AF_INET, &ssaddr.daddr4, ip_string_buf, INET_ADDRSTRLEN);
+ sprintf((char *)host_result->val.iov_base, "%s:%u", ip_string_buf, ntohs(ssaddr.dport));
host_result->val.iov_len = strlen((char *)host_result->val.iov_base);
}
- else if (SESSION_ADDR_TYPE_IPV6_TCP == ssaddr_type || SESSION_ADDR_TYPE_IPV6_UDP == ssaddr_type)
+ else if (6 == ssaddr.ipver)
{
host_result->val.iov_base = MEMPOOL_CALLOC(mempool, char, (INET6_ADDRSTRLEN + 7) /* "ip:port" max length */);
- inet_ntop(AF_INET6, &ssaddr->ipv6.daddr, ip_string_buf, INET6_ADDRSTRLEN);
- sprintf((char *)host_result->val.iov_base, "%s:%u", ip_string_buf, ntohs(ssaddr->ipv6.dport));
+ inet_ntop(AF_INET6, &ssaddr.daddr6, ip_string_buf, INET6_ADDRSTRLEN);
+ sprintf((char *)host_result->val.iov_base, "%s:%u", ip_string_buf, ntohs(ssaddr.dport));
host_result->val.iov_len = strlen((char *)host_result->val.iov_base);
}
else
@@ -944,7 +950,7 @@ static void using_session_addr_as_host(struct session *ref_session,
assert(0);
}
#else
- host_result->val.iov_base = MEMPOOL_CALLOC(mempool, char, 32);
+ host_result->val.iov_base = MEMPOOL_CALLOC(mempool, char, 32);
sprintf((char *)host_result->val.iov_base, "%s", "todo:get_tuple4");
host_result->val.iov_len = strlen((char *)host_result->val.iov_base);
#endif
@@ -975,10 +981,13 @@ void http_decoder_join_url(struct http_decoder_half_data *hfdata, nmx_pool_t *me
hfdata->joint_url.iov_len = url_cache_str_len;
hfdata->url_is_encoded = httpd_url_is_encoded(url_cache_str, url_cache_str_len);
- if(hfdata->url_is_encoded){
+ if (hfdata->url_is_encoded)
+ {
hfdata->decoded_url.iov_base = MEMPOOL_CALLOC(mempool, char, url_cache_str_len);
httpd_url_decode(url_cache_str, url_cache_str_len, (char *)hfdata->decoded_url.iov_base, &hfdata->decoded_url.iov_len);
- }else{
+ }
+ else
+ {
hfdata->decoded_url.iov_base = url_cache_str;
hfdata->decoded_url.iov_len = url_cache_str_len;
}
@@ -990,9 +999,9 @@ void http_decoder_get_url(struct http_decoder_half_data *hfdata, nmx_pool_t *mem
{
struct http_request_line reqline = {};
http_decoder_half_data_get_request_line(hfdata, &reqline);
- if(unlikely(strncasecmp_safe("CONNECT", (char *)reqline.method.iov_base, 7, reqline.method.iov_len) == 0))
+ if (unlikely(strncasecmp_safe("CONNECT", (char *)reqline.method.iov_base, 7, reqline.method.iov_len) == 0))
{
- hfdata->joint_url.iov_base = MEMPOOL_CALLOC(mempool, char, reqline.uri.iov_len+1);
+ hfdata->joint_url.iov_base = MEMPOOL_CALLOC(mempool, char, reqline.uri.iov_len + 1);
memcpy(hfdata->joint_url.iov_base, reqline.uri.iov_base, reqline.uri.iov_len);
hfdata->joint_url.iov_len = reqline.uri.iov_len;
hfdata->joint_url_complete = 1;
@@ -1064,12 +1073,12 @@ int http_half_data_get_transaction_seq(struct http_decoder_half_data *hf_data)
return hf_data->transaction_index;
}
-void http_half_data_update_commit_index(struct http_decoder_half_data * half_data)
+void http_half_data_update_commit_index(struct http_decoder_half_data *half_data)
{
http_decoder_table_update_commit_index(half_data->table);
}
-int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data * half_data)
+int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data *half_data)
{
return http_decoder_table_get_total_parsed_header(half_data->table);
}
@@ -1077,25 +1086,31 @@ int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data *
void http_half_pre_context_free(struct session *sess, struct http_decoder_exdata *exdata)
{
struct http_message *msg = NULL;
- struct http_decoder_half_data *res_data;
- struct http_decoder_result_queue *queue = exdata->queue;
+ struct http_decoder_half_data *res_data = NULL;
+ struct http_decoder_result_queue *queue = NULL;
- for(int i = 0; i < queue->queue_size; i++){
- struct http_decoder_half_data *req_data = queue->array[i].req_data;
- res_data = queue->array[i].res_data;
- if ((req_data != NULL) && (NULL == res_data) && (req_data->state < HTTP_EVENT_REQ_END))
+ if (exdata)
+ {
+ queue = exdata->queue;
+ for (int i = 0; i < queue->queue_size; i++)
{
- msg = http_message_new(HTTP_TRANSACTION_END, queue, i, HTTP_REQUEST);
- session_mq_publish_message(sess, exdata->pub_topic_id, msg);
+ struct http_decoder_half_data *req_data = queue->array[i].req_data;
+ res_data = queue->array[i].res_data;
+ if ((req_data != NULL) && (NULL == res_data) && (req_data->state < HTTP_EVENT_REQ_END))
+ {
+ msg = http_message_new(HTTP_TRANSACTION_END, queue, i, HTTP_REQUEST);
+ session_mq_publish_message(sess, exdata->pub_topic_id, msg);
+ }
}
- }
- for(int i = 0; i < queue->queue_size; i++){
- res_data = queue->array[i].res_data;
- if ((res_data != NULL) && (res_data->state < HTTP_EVENT_RES_END))
+ for (int i = 0; i < queue->queue_size; i++)
{
- msg = http_message_new(HTTP_TRANSACTION_END, queue, i, HTTP_RESPONSE);
- session_mq_publish_message(sess, exdata->pub_topic_id, msg);
+ res_data = queue->array[i].res_data;
+ if ((res_data != NULL) && (res_data->state < HTTP_EVENT_RES_END))
+ {
+ msg = http_message_new(HTTP_TRANSACTION_END, queue, i, HTTP_RESPONSE);
+ session_mq_publish_message(sess, exdata->pub_topic_id, msg);
+ }
}
}
}
diff --git a/src/http_decoder_inc.h b/src/http_decoder_inc.h
index 3f5247a..b78d586 100644
--- a/src/http_decoder_inc.h
+++ b/src/http_decoder_inc.h
@@ -11,6 +11,10 @@
#ifndef _HTTP_DECODER_INC_H_
#define _HTTP_DECODER_INC_H_
+#ifndef __USE_MISC
+#define __USE_MISC 1
+#endif
+
#include <cstddef>
#ifdef __cplusplus
extern "C"
@@ -18,6 +22,8 @@ extern "C"
#endif
#include <bits/types/struct_iovec.h>
#include "stellar/stellar.h"
+#include "stellar/layer.h"
+#include "stellar/packet.h"
#include "stellar/utils.h"
#include "stellar/session.h"
#include "stellar/stellar_mq.h"
diff --git a/src/http_decoder_tunnel.cpp b/src/http_decoder_tunnel.cpp
index 6f23195..42f100a 100644
--- a/src/http_decoder_tunnel.cpp
+++ b/src/http_decoder_tunnel.cpp
@@ -39,14 +39,20 @@ int httpd_tunnel_identify(struct http_decoder_env *httpd_env, int curdir, struct
return 0;
}
-int httpd_is_tunnel_session(const struct http_decoder_exdata *ex_data)
+int httpd_is_tunnel_session(const struct http_decoder_env *httpd_env, const struct http_decoder_exdata *ex_data)
{
- return (ex_data->tunnel_state != HTTP_TUN_NON);
+ if(0 == httpd_env->hd_cfg.proxy_enable){
+ return 0;
+ }
+ return (ex_data && ex_data->tunnel_state != HTTP_TUN_NON);
}
-int httpd_in_tunnel_transmitting(struct http_decoder_exdata *ex_data)
+int httpd_in_tunnel_transmitting(const struct http_decoder_env *httpd_env, struct http_decoder_exdata *ex_data)
{
- return (ex_data->tunnel_state >= HTTP_TUN_INNER_STARTING);
+ if(0 == httpd_env->hd_cfg.proxy_enable){
+ return 0;
+ }
+ return (ex_data && ex_data->tunnel_state >= HTTP_TUN_INNER_STARTING);
}
enum http_tunnel_message_type httpd_tunnel_state_to_msg(const struct http_decoder_exdata *ex_data)
@@ -67,12 +73,10 @@ void httpd_tunnel_state_update(struct http_decoder_exdata *ex_data)
}
}
-void http_decoder_push_tunnel_data(struct session *sess, const struct http_decoder_exdata *exdata, enum http_tunnel_message_type type)
+void http_decoder_push_tunnel_data(struct session *sess, const struct http_decoder_exdata *exdata, enum http_tunnel_message_type type, const char *payload, uint16_t payload_len)
{
struct http_tunnel_message *tmsg = (struct http_tunnel_message *)CALLOC(struct http_tunnel_message, 1);
tmsg->type = type;
- uint16_t payload_len;
- const char *payload = session_get0_current_payload(sess, &payload_len);
tmsg->tunnel_payload.iov_base = (char *)payload;
tmsg->tunnel_payload.iov_len = payload_len;
session_mq_publish_message(sess, exdata->pub_topic_id, tmsg);
diff --git a/src/http_decoder_tunnel.h b/src/http_decoder_tunnel.h
index f908c1b..b90e402 100644
--- a/src/http_decoder_tunnel.h
+++ b/src/http_decoder_tunnel.h
@@ -28,8 +28,8 @@ void http_tunnel_message_get_payload(const struct http_tunnel_message *tmsg, str
int httpd_tunnel_identify(struct http_decoder_env *httpd_env, int curdir, struct http_decoder_half_data *hfdata);
-int httpd_is_tunnel_session(const struct http_decoder_exdata *ex_data);
-int httpd_in_tunnel_transmitting(struct http_decoder_exdata *ex_data);
+int httpd_is_tunnel_session(const struct http_decoder_env *httpd_env, const struct http_decoder_exdata *ex_data);
+int httpd_in_tunnel_transmitting(const struct http_decoder_env *httpd_env, struct http_decoder_exdata *ex_data);
void httpd_tunnel_state_update(struct http_decoder_exdata *ex_data);
-void http_decoder_push_tunnel_data(struct session *sess, const struct http_decoder_exdata *exdata, enum http_tunnel_message_type type);
+void http_decoder_push_tunnel_data(struct session *sess, const struct http_decoder_exdata *exdata, enum http_tunnel_message_type type, const char *payload, uint16_t payload_len);
enum http_tunnel_message_type httpd_tunnel_state_to_msg(const struct http_decoder_exdata *ex_data); \ No newline at end of file
diff --git a/src/http_decoder_utils.cpp b/src/http_decoder_utils.cpp
index 55aba66..4e43c1e 100644
--- a/src/http_decoder_utils.cpp
+++ b/src/http_decoder_utils.cpp
@@ -5,7 +5,8 @@
char *safe_dup(const char *str, size_t len)
{
- if (str == NULL || len == 0) {
+ if (str == NULL || len == 0)
+ {
return NULL;
}
char *dup = CALLOC(char, len + 1);
@@ -15,10 +16,12 @@ char *safe_dup(const char *str, size_t len)
int strncasecmp_safe(const char *fix_s1, const char *dyn_s2, size_t fix_n1, size_t dyn_n2)
{
- if (fix_s1 == NULL || dyn_s2 == NULL) {
+ if (fix_s1 == NULL || dyn_s2 == NULL)
+ {
return -1;
}
- if(fix_n1 != dyn_n2){
+ if (fix_n1 != dyn_n2)
+ {
return -1;
}
return strncasecmp(fix_s1, dyn_s2, fix_n1);
@@ -41,8 +44,8 @@ const char *http_message_type_to_string(enum http_message_type type)
break;
case HTTP_MESSAGE_REQ_BODY_START:
sname = "HTTP_MESSAGE_REQ_BODY_START";
- break;
- case HTTP_MESSAGE_REQ_BODY:
+ break;
+ case HTTP_MESSAGE_REQ_BODY:
sname = "HTTP_MESSAGE_REQ_BODY";
break;
case HTTP_MESSAGE_REQ_BODY_END:
@@ -50,8 +53,8 @@ const char *http_message_type_to_string(enum http_message_type type)
break;
case HTTP_MESSAGE_RES_LINE:
sname = "HTTP_MESSAGE_RES_LINE";
- break;
- case HTTP_MESSAGE_RES_HEADER:
+ break;
+ case HTTP_MESSAGE_RES_HEADER:
sname = "HTTP_MESSAGE_RES_HEADER";
break;
case HTTP_MESSAGE_RES_HEADER_END:
@@ -59,10 +62,10 @@ const char *http_message_type_to_string(enum http_message_type type)
break;
case HTTP_MESSAGE_RES_BODY_START:
sname = "HTTP_MESSAGE_RES_BODY_START";
- break;
+ break;
case HTTP_MESSAGE_RES_BODY:
sname = "HTTP_MESSAGE_RES_BODY";
- break;
+ break;
case HTTP_MESSAGE_RES_BODY_END:
sname = "HTTP_MESSAGE_RES_BODY_END";
break;
@@ -84,40 +87,44 @@ int http_message_type_is_req(struct session *sess, enum http_message_type msg_ty
{
int is_req_msg = 0;
- switch(msg_type){
- case HTTP_MESSAGE_REQ_LINE:
- case HTTP_MESSAGE_REQ_HEADER:
- case HTTP_MESSAGE_REQ_HEADER_END:
- case HTTP_MESSAGE_REQ_BODY_START:
- case HTTP_MESSAGE_REQ_BODY:
- case HTTP_MESSAGE_REQ_BODY_END:
- is_req_msg = 1;
+ switch (msg_type)
+ {
+ case HTTP_MESSAGE_REQ_LINE:
+ case HTTP_MESSAGE_REQ_HEADER:
+ case HTTP_MESSAGE_REQ_HEADER_END:
+ case HTTP_MESSAGE_REQ_BODY_START:
+ case HTTP_MESSAGE_REQ_BODY:
+ case HTTP_MESSAGE_REQ_BODY_END:
+ is_req_msg = 1;
break;
- case HTTP_MESSAGE_RES_LINE:
- case HTTP_MESSAGE_RES_HEADER:
- case HTTP_MESSAGE_RES_HEADER_END:
- case HTTP_MESSAGE_RES_BODY_START:
- case HTTP_MESSAGE_RES_BODY:
- case HTTP_MESSAGE_RES_BODY_END:
- is_req_msg = 0;
+ case HTTP_MESSAGE_RES_LINE:
+ case HTTP_MESSAGE_RES_HEADER:
+ case HTTP_MESSAGE_RES_HEADER_END:
+ case HTTP_MESSAGE_RES_BODY_START:
+ case HTTP_MESSAGE_RES_BODY:
+ case HTTP_MESSAGE_RES_BODY_END:
+ is_req_msg = 0;
break;
- case HTTP_TRANSACTION_START:
- case HTTP_TRANSACTION_END:
+ case HTTP_TRANSACTION_START:
+ case HTTP_TRANSACTION_END:
+ {
+ enum flow_direction cur_dir = session_get_current_flow_direction(sess);
+ if (FLOW_DIRECTION_C2S == cur_dir)
{
- enum flow_direction cur_dir = session_get_current_flow_direction(sess);
- if(FLOW_DIRECTION_C2S == cur_dir){
- is_req_msg = 1;
- }else{
- is_req_msg = 0;
- }
+ is_req_msg = 1;
}
- break;
+ else
+ {
+ is_req_msg = 0;
+ }
+ }
+ break;
- default:
- assert(0);
- fprintf(stderr, "unknow message type:%d\n", (int)msg_type);
+ default:
+ assert(0);
+ fprintf(stderr, "unknow message type:%d\n", (int)msg_type);
break;
}
return is_req_msg;
@@ -125,51 +132,53 @@ int http_message_type_is_req(struct session *sess, enum http_message_type msg_ty
int http_event_is_req(enum http_event event)
{
- switch(event){
- case HTTP_EVENT_REQ_INIT:
- case HTTP_EVENT_REQ_LINE:
- case HTTP_EVENT_REQ_HDR:
- case HTTP_EVENT_REQ_HDR_END:
- case HTTP_EVENT_REQ_BODY_BEGIN:
- case HTTP_EVENT_REQ_BODY_DATA:
- case HTTP_EVENT_REQ_BODY_END:
- case HTTP_EVENT_REQ_END:
- return 1;
+ switch (event)
+ {
+ case HTTP_EVENT_REQ_INIT:
+ case HTTP_EVENT_REQ_LINE:
+ case HTTP_EVENT_REQ_HDR:
+ case HTTP_EVENT_REQ_HDR_END:
+ case HTTP_EVENT_REQ_BODY_BEGIN:
+ case HTTP_EVENT_REQ_BODY_DATA:
+ case HTTP_EVENT_REQ_BODY_END:
+ case HTTP_EVENT_REQ_END:
+ return 1;
break;
- case HTTP_EVENT_RES_INIT:
- case HTTP_EVENT_RES_LINE:
- case HTTP_EVENT_RES_HDR:
- case HTTP_EVENT_RES_HDR_END:
- case HTTP_EVENT_RES_BODY_BEGIN:
- case HTTP_EVENT_RES_BODY_DATA:
- case HTTP_EVENT_RES_BODY_END:
- case HTTP_EVENT_RES_END:
- return 0;
+ case HTTP_EVENT_RES_INIT:
+ case HTTP_EVENT_RES_LINE:
+ case HTTP_EVENT_RES_HDR:
+ case HTTP_EVENT_RES_HDR_END:
+ case HTTP_EVENT_RES_BODY_BEGIN:
+ case HTTP_EVENT_RES_BODY_DATA:
+ case HTTP_EVENT_RES_BODY_END:
+ case HTTP_EVENT_RES_END:
+ return 0;
break;
- default:
- assert(0);
- fprintf(stderr, "unknow event type:%d\n", (int)event);
+ default:
+ assert(0);
+ fprintf(stderr, "unknow event type:%d\n", (int)event);
break;
}
return -1;
}
-int stellar_session_mq_get_topic_id_reliable(struct stellar *st, const char *topic_name, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
+int stellar_session_mq_get_topic_id_reliable(struct stellar *st, const char *topic_name, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
{
int topic_id = stellar_mq_get_topic_id(st, topic_name);
- if(topic_id < 0){
+ if (topic_id < 0)
+ {
topic_id = stellar_mq_create_topic(st, topic_name, msg_free_cb, msg_free_arg);
}
return topic_id;
}
static const unsigned char __g_httpd_hextable[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */
- 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
- 0, 10, 11, 12, 13, 14, 15 /* 0x60 - 0x66 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */
+ 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
+ 0, 10, 11, 12, 13, 14, 15 /* 0x60 - 0x66 */
};
/* the input is a single hex digit */
@@ -211,10 +220,90 @@ void httpd_url_decode(const char *string, size_t length, char *ostring, size_t *
int httpd_url_is_encoded(const char *url, size_t len)
{
- for(size_t i = 0; i < len; i++){
- if(url[i] == '%'){
+ for (size_t i = 0; i < len; i++)
+ {
+ if (url[i] == '%')
+ {
return 1;
}
}
return 0;
+}
+
+static void httpd_set_tcp_addr(const struct tcphdr *tcph, struct httpd_session_addr *addr, enum flow_direction fdir)
+{
+ if (FLOW_DIRECTION_C2S == fdir)
+ {
+ addr->sport = tcph->th_sport;
+ addr->dport = tcph->th_dport;
+ }
+ else
+ {
+ addr->sport = tcph->th_dport;
+ addr->dport = tcph->th_sport;
+ }
+}
+static void httpd_set_ipv4_addr(const struct ip *ip4h, struct httpd_session_addr *addr, enum flow_direction fdir)
+{
+ addr->ipver = 4;
+ if (FLOW_DIRECTION_C2S == fdir)
+ {
+ addr->saddr4 = ip4h->ip_src.s_addr;
+ addr->daddr4 = ip4h->ip_dst.s_addr;
+ }
+ else
+ {
+ addr->saddr4 = ip4h->ip_dst.s_addr;
+ addr->daddr4 = ip4h->ip_src.s_addr;
+ }
+}
+static void httpd_set_ipv6_addr(const struct ip6_hdr *ip6h, struct httpd_session_addr *addr, enum flow_direction fdir)
+{
+ addr->ipver = 6;
+ if (FLOW_DIRECTION_C2S == fdir)
+ {
+ memcpy(&addr->saddr6, &ip6h->ip6_src, sizeof(struct in6_addr));
+ memcpy(&addr->daddr6, &ip6h->ip6_dst, sizeof(struct in6_addr));
+ }
+ else
+ {
+ memcpy(&addr->saddr6, &ip6h->ip6_dst, sizeof(struct in6_addr));
+ memcpy(&addr->daddr6, &ip6h->ip6_src, sizeof(struct in6_addr));
+ }
+}
+
+void httpd_session_get_addr(const struct session *sess, struct httpd_session_addr *addr)
+{
+ if (sess == NULL || addr == NULL)
+ {
+ return;
+ }
+ enum flow_direction fdir = session_get_current_flow_direction(sess);
+ const struct packet *raw_pkt = session_get_first_packet(sess, fdir);
+ if (NULL == raw_pkt)
+ {
+ addr->ipver = 0;
+ return;
+ }
+
+ struct layer pkt_layer = {};
+ PACKET_FOREACH_LAYER_REVERSE(raw_pkt, pkt_layer)
+ {
+ if (pkt_layer.proto == LAYER_PROTO_TCP)
+ {
+ httpd_set_tcp_addr(pkt_layer.hdr.tcp, addr, fdir);
+ }
+ else if (pkt_layer.proto == LAYER_PROTO_IPV4)
+ {
+ httpd_set_ipv4_addr(pkt_layer.hdr.ip4, addr, fdir);
+ break;
+ }
+ else if (pkt_layer.proto == LAYER_PROTO_IPV6)
+ {
+ httpd_set_ipv6_addr(pkt_layer.hdr.ip6, addr, fdir);
+ break;
+ }
+ }
+
+ return;
} \ No newline at end of file
diff --git a/src/http_decoder_utils.h b/src/http_decoder_utils.h
index e500a60..33483cf 100644
--- a/src/http_decoder_utils.h
+++ b/src/http_decoder_utils.h
@@ -60,3 +60,21 @@ enum http_decoder_log_level {
} \
}
#endif
+
+
+#include <netinet/in.h>
+
+struct httpd_session_addr
+{
+ uint8_t ipver; /* 4 or 6 */
+ uint16_t sport; /* network order */
+ uint16_t dport; /* network order */
+ union
+ {
+ uint32_t saddr4;
+ uint32_t daddr4;
+ struct in6_addr saddr6;
+ struct in6_addr daddr6;
+ };
+};
+void httpd_session_get_addr(const struct session *sess, struct httpd_session_addr *addr);
diff --git a/test/http_pcap/http_out_of_order.pcap b/test/http_pcap/http_out_of_order.pcap
new file mode 100644
index 0000000..e72edc7
--- /dev/null
+++ b/test/http_pcap/http_out_of_order.pcap
Binary files differ
diff --git a/test/http_pcap/http_url_test_without_host_v6.pcap b/test/http_pcap/http_url_test_without_host_v6.pcap
new file mode 100644
index 0000000..70937c8
--- /dev/null
+++ b/test/http_pcap/http_url_test_without_host_v6.pcap
Binary files differ
diff --git a/test/test_result_json/http_out_of_order.json b/test/test_result_json/http_out_of_order.json
new file mode 100644
index 0000000..5b77c18
--- /dev/null
+++ b/test/test_result_json/http_out_of_order.json
@@ -0,0 +1,43 @@
+[
+ {
+ "__X_HTTP_TUPLE4": "192.168.38.2:49243-202.96.17.37:80-6-0"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "request",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "method": "GET",
+ "uri": "/cn/images/globesite/airchina.jpg",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "Host": "www.airchina.com",
+ "Connection": "keep-alive",
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
+ "DNT": "1",
+ "Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
+ "Referer": "http://www.airchina.com/website/ip2.jsp?v=20230128",
+ "Accept-Encoding": "gzip, deflate",
+ "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
+ "Cookie": "_ga=GA1.2.1223391296.1710844147; _ga_CGYVD7S4G4=GS1.1.1711101500.1.1.1711101524.0.0.0; _gcl_au=1.1.45985360.1720059434; arialoadData=true; ariawapChangeViewPort=false; JSESSIONID=ZoFJbBlIeHCsA5414j6JC-vO6jvcBw7_xphcV3qerj5Q8htV6XH8!-1677015109",
+ "__X_HTTP_URL": "www.airchina.com/cn/images/globesite/airchina.jpg"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "response",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Date": "Tue, 13 Aug 2024 01:48:28 GMT",
+ "Server": "Apache",
+ "X-Frame-Options": "SAMEORIGIN",
+ "Last-Modified": "Tue, 06 Aug 2019 02:10:09 GMT",
+ "Accept-Ranges": "bytes",
+ "Content-Length": "67424",
+ "Keep-Alive": "timeout=120, max=1000",
+ "Connection": "Keep-Alive",
+ "Content-Type": "image/jpeg",
+ "__X_HTTP_PAYLOAD_MD5": "c4c9d459415e922f877a2af6afd9d316"
+ }
+] \ No newline at end of file
diff --git a/test/test_result_json/http_url_test_without_host.json b/test/test_result_json/http_url_test_without_host.json
index c9ad313..5c68075 100644
--- a/test/test_result_json/http_url_test_without_host.json
+++ b/test/test_result_json/http_url_test_without_host.json
@@ -1,6 +1,6 @@
[
{
- "__X_HTTP_TUPLE4": "192.168.244.128.44868>192.168.244.128.8080"
+ "__X_HTTP_TUPLE4": "192.168.244.128:44868-192.168.244.128:8080-6-0"
},
{
"__X_HTTP_TRANSACTION": "request",
diff --git a/test/test_result_json/http_url_test_without_host_v6.json b/test/test_result_json/http_url_test_without_host_v6.json
new file mode 100644
index 0000000..2bc3934
--- /dev/null
+++ b/test/test_result_json/http_url_test_without_host_v6.json
@@ -0,0 +1,42 @@
+[
+ {
+ "__X_HTTP_TUPLE4": "2607:5d00:2:2::38:2:54676-2408:8722:840:f8::83:80-6-0"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "request",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "method": "GET",
+ "uri": "/dist/aria.js?appid=1cea560ed256bea7ae52761bd9042164",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "_HOT": "ent.govwza.cn",
+ "Connection": "keep-alive",
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
+ "DNT": "1",
+ "Accept": "*/*",
+ "Referer": "http://www.airchina.com/",
+ "Accept-Encoding": "gzip, deflate",
+ "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
+ "If-Modified-Since": "Mon, 05 Aug 2024 00:26:26 GMT",
+ "__X_HTTP_URL": "2408:8722:840:f8::83:80/dist/aria.js?appid=1cea560ed256bea7ae52761bd9042164"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "response",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "res_version": "1.1",
+ "res_status": "Not Modified",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 304,
+ "Date": "Mon, 05 Aug 2024 07:51:04 GMT",
+ "Content-Type": "application/javascript;charset=UTF-8",
+ "Vary": "origin,access-control-request-method,access-control-request-headers,accept-encoding",
+ "Server": "SLT-MID",
+ "X-NWS-LOG-UUID": "1242198743243161630",
+ "Connection": "close",
+ "X-Cache-Lookup": "Cache Hit",
+ "Access-Control-Allow-Origin": "*",
+ "Cache-Control": "max-age=86400"
+ }
+] \ No newline at end of file
diff --git a/test_based_on_stellar/CMakeLists.txt b/test_based_on_stellar/CMakeLists.txt
index af1757c..7ae821f 100644
--- a/test_based_on_stellar/CMakeLists.txt
+++ b/test_based_on_stellar/CMakeLists.txt
@@ -72,6 +72,8 @@ add_test(NAME STELLAR_HTTP_NO_CONTENT_LENGTH_TEST COMMAND sh -c "ln -sf ${TEST_
add_test(NAME STELLAR_HTTP_POST_MULTIPART_FORM_DATA_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_post_multipart_form_data.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_post_multipart_form_data.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_HEADERS_EXCEED_MAXIMUM_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_hdrs_exceed_maximum.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_hdrs_exceed_maximum.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_GET_MALFORMED_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_get_malformed.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_get_malformed.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
+add_test(NAME STELLAR_HTTP_URL_WITHOUT_HOST_V4_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_url_test_without_host.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_url_test_without_host.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
+add_test(NAME STELLAR_HTTP_URL_WITHOUT_HOST_V6_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_url_test_without_host_v6.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_url_test_without_host_v6.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
#no SYN, steallar not support !
# add_test(NAME STELLAR_HTTP_HEADER_VALUE_EMPTY_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_hdr_value_empty.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_hdr_value_empty.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_UPGRADE_WEBSOCKET_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_upgrade_websocket.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_upgrade_websocket.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
@@ -86,6 +88,7 @@ add_test(NAME STELLAR_HTTP_FIN_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http
# -r ${TEST_PCAP_DIR}/http_tunnel_s2c_only_hdr.pcap WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_CHN_ENCODE_URL COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_chn_encode_url.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_chn_encode_url.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_ZLIB_DEADLOCK COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_zlib_deadlock.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_zlib_deadlock.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
+add_test(NAME STELLAR_HTTP_OUT_OF_DRDER COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_out_of_order.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_out_of_order.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
set_tests_properties(STELLAR_HTTP_GET_SINGLE_TRANS_TEST
STELLAR_HTTP_GET_MULTI_TRANS_TEST
@@ -103,6 +106,8 @@ set_tests_properties(STELLAR_HTTP_GET_SINGLE_TRANS_TEST
STELLAR_HTTP_POST_MULTIPART_FORM_DATA_TEST
STELLAR_HTTP_HEADERS_EXCEED_MAXIMUM_TEST
STELLAR_HTTP_GET_MALFORMED_TEST
+ STELLAR_HTTP_URL_WITHOUT_HOST_V4_TEST
+ STELLAR_HTTP_URL_WITHOUT_HOST_V6_TEST
STELLAR_HTTP_MULTI_PARSE_ERROR_TEST
STELLAR_HTTP_UPGRADE_WEBSOCKET_TEST
STELLAR_HTTP_GET_REQ_PIPELINE_TEST
@@ -110,6 +115,7 @@ set_tests_properties(STELLAR_HTTP_GET_SINGLE_TRANS_TEST
STELLAR_HTTP_FIN_TEST
STELLAR_HTTP_CHN_ENCODE_URL
STELLAR_HTTP_ZLIB_DEADLOCK
+ STELLAR_HTTP_OUT_OF_DRDER
PROPERTIES FIXTURES_REQUIRED TestFixture)
add_test(NAME UPDATE_STATE_PLUG_ENTRY COMMAND bash -c "sed -i 's/name=.*/name=\\x22http_decoder_test_state_entry\\x22/' ${TEST_RUN_DIR}/etc/http/gtest_entry.toml")
diff --git a/test_based_on_stellar/env/stellar.toml b/test_based_on_stellar/env/stellar.toml
index dbb4bd1..496324f 100644
--- a/test_based_on_stellar/env/stellar.toml
+++ b/test_based_on_stellar/env/stellar.toml
@@ -28,16 +28,16 @@ tcp_overload_evict_old_sess = 1 # 1: evict old session, 0: bypass new session
udp_overload_evict_old_sess = 1 # 1: evict old session, 0: bypass new session
# TCP timeout
-tcp_init_timeout = 5000 # range: [1, 60000] (ms)
-tcp_handshake_timeout = 5000 # range: [1, 60000] (ms)
-tcp_data_timeout = 5000 # range: [1, 15999999000] (ms)
-tcp_half_closed_timeout = 2000 # range: [1, 604800000] (ms)
-tcp_time_wait_timeout = 1000 # range: [1, 600000] (ms)
-tcp_discard_timeout = 1000 # range: [1, 15999999000] (ms)
-tcp_unverified_rst_timeout = 1000 # range: [1, 600000] (ms)
+tcp_init_timeout = 100 # range: [1, 60000] (ms)
+tcp_handshake_timeout = 100 # range: [1, 60000] (ms)
+tcp_data_timeout = 100 # range: [1, 15999999000] (ms)
+tcp_half_closed_timeout = 100 # range: [1, 604800000] (ms)
+tcp_time_wait_timeout = 100 # range: [1, 600000] (ms)
+tcp_discard_timeout = 100 # range: [1, 15999999000] (ms)
+tcp_unverified_rst_timeout = 100 # range: [1, 600000] (ms)
# UDP timeout
-udp_data_timeout = 5000 # range: [1, 15999999000] (ms)
-udp_discard_timeout = 5000 # range: [1, 15999999000] (ms)
+udp_data_timeout = 100 # range: [1, 15999999000] (ms)
+udp_discard_timeout = 100 # range: [1, 15999999000] (ms)
# duplicate packet filter
duplicated_packet_filter_enable = 0
@@ -53,5 +53,5 @@ evicted_session_filter_error_rate = 0.00001 # range: [0.0, 1.0]
# TCP reassembly (Per direction)
tcp_reassembly_enable = 1
-tcp_reassembly_max_timeout = 10000 # range: [1, 60000] (ms)
+tcp_reassembly_max_timeout = 100 # range: [1, 60000] (ms)
tcp_reassembly_max_segments = 256 # range: [2, 4096]
diff --git a/test_based_on_stellar/plugin_test_main.cpp b/test_based_on_stellar/plugin_test_main.cpp
index f13ae62..accec2d 100644
--- a/test_based_on_stellar/plugin_test_main.cpp
+++ b/test_based_on_stellar/plugin_test_main.cpp
@@ -125,6 +125,7 @@ fail:
int main(int argc, char *argv[])
{
+ int ret = 0;
if (argc < 2)
{
printf("Usage: %s <result_json_path>\n", argv[0]);
@@ -144,7 +145,7 @@ int main(int argc, char *argv[])
}
if (result_json_path != NULL)
{
- RUN_ALL_TESTS();
+ ret = RUN_ALL_TESTS();
}
- return 0;
+ return ret;
}
diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt
index 5a3c568..87ef525 100644
--- a/vendor/CMakeLists.txt
+++ b/vendor/CMakeLists.txt
@@ -54,3 +54,20 @@ add_dependencies(cjson-static cjson)
set_property(TARGET cjson-static PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/vendor/cjson/src/cjson/libcjson.a)
set_property(TARGET cjson-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${VENDOR_BUILD}/include/cjson)
+#brotli-v1.0.9
+ExternalProject_Add(libbrotli PREFIX libbrotli
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/brotli-v1.0.9.tar.gz
+ URL_MD5 c2274f0c7af8470ad514637c35bcee7d
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${VENDOR_BUILD} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
+
+file(MAKE_DIRECTORY ${VENDOR_BUILD}/include)
+
+add_library(brotli-common-static STATIC IMPORTED GLOBAL)
+add_dependencies(brotli-common-static libbrotli)
+set_property(TARGET brotli-common-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${VENDOR_BUILD}/include)
+set_property(TARGET brotli-common-static PROPERTY IMPORTED_LOCATION ${VENDOR_BUILD}/lib64/libbrotlicommon-static.a)
+
+add_library(brotli-dec-static STATIC IMPORTED GLOBAL)
+add_dependencies(brotli-dec-static libbrotli)
+set_property(TARGET brotli-dec-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${VENDOR_BUILD}/include)
+set_property(TARGET brotli-dec-static PROPERTY IMPORTED_LOCATION ${VENDOR_BUILD}/lib64/libbrotlidec-static.a)
diff --git a/vendor/brotli-v1.0.9.tar.gz b/vendor/brotli-v1.0.9.tar.gz
new file mode 100644
index 0000000..0d717bb
--- /dev/null
+++ b/vendor/brotli-v1.0.9.tar.gz
Binary files differ