diff options
| author | yangwei <[email protected]> | 2019-07-02 18:34:14 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2019-07-02 18:34:14 +0800 |
| commit | e4c12a10ee0e7c58e0eddc17183f7319e8a86daf (patch) | |
| tree | 4451f0440bb0163527dc633031bfeb06f7c73cff /src/ntc_http_collect.cpp | |
| parent | bbbb3f8e332e1454d19af12243045e6fc6cb6c20 (diff) | |
1、移除make,仅支持cmake
2、内置cjson,隐藏符号名编译
3、增加自动版本号脚本
Diffstat (limited to 'src/ntc_http_collect.cpp')
| -rw-r--r-- | src/ntc_http_collect.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/ntc_http_collect.cpp b/src/ntc_http_collect.cpp index 9018e40..ecec3ff 100644 --- a/src/ntc_http_collect.cpp +++ b/src/ntc_http_collect.cpp @@ -49,6 +49,26 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#ifdef __cplusplus +extern "C" +{ +#endif + +#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char * GIT_VERSION_##v = NULL +#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v) + +/* VERSION TAG */ +#ifdef GIT_VERSION +GIT_VERSION_EXPEND(GIT_VERSION); +#else +static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; +#endif +#undef GIT_VERSION_CATTER +#undef GIT_VERSION_EXPEND + +#ifdef __cplusplus +} +#endif int NTC_HTTP_COLLECT_VERSION_20180910 = 1; @@ -212,6 +232,82 @@ static int form_url_to_domain(const char *url, char *domain) return i; } +static int ntc_addStreamInfo_to_jsonObj(cJSON *json_obj, const struct streaminfo *a_stream) +{ + const char *addr_proto = NULL; + const char *null_addr = "0"; + short null_port = 0; + unsigned short tunnel_type = 0; + char nest_addr_buf[1024]; + int tunnel_type_size = sizeof(tunnel_type); + const struct layer_addr *addr = NULL; + char src_ip_str[128] = {0}, dst_ip_str[128] = {0}; + + cJSON_AddNumberToObject(json_obj, "stream_dir", a_stream->dir); + + addr = &(a_stream->addr); + switch (addr->addrtype) + { + case ADDR_TYPE_IPV4: + case __ADDR_TYPE_IP_PAIR_V4: + inet_ntop(AF_INET, &addr->ipv4->saddr, src_ip_str, sizeof(src_ip_str)); + inet_ntop(AF_INET, &addr->ipv4->daddr, dst_ip_str, sizeof(dst_ip_str)); + cJSON_AddStringToObject(json_obj, "s_ip", src_ip_str); + cJSON_AddStringToObject(json_obj, "d_ip", dst_ip_str); + cJSON_AddNumberToObject(json_obj, "s_port", ntohs(addr->ipv4->source)); + cJSON_AddNumberToObject(json_obj, "d_port", ntohs(addr->ipv4->dest)); + break; + case ADDR_TYPE_IPV6: + case __ADDR_TYPE_IP_PAIR_V6: + cJSON_AddNumberToObject(json_obj, "addr_type", addr->addrtype); + inet_ntop(AF_INET6, addr->ipv6->saddr, src_ip_str, sizeof(src_ip_str)); + inet_ntop(AF_INET6, addr->ipv6->daddr, dst_ip_str, sizeof(dst_ip_str)); + cJSON_AddStringToObject(json_obj, "s_ip", src_ip_str); + cJSON_AddStringToObject(json_obj, "d_ip", dst_ip_str); + cJSON_AddNumberToObject(json_obj, "s_port", ntohs(addr->ipv6->source)); + cJSON_AddNumberToObject(json_obj, "d_port", ntohs(addr->ipv6->dest)); + break; + case ADDR_TYPE_VLAN: + case ADDR_TYPE_GRE: + case ADDR_TYPE_MPLS: + case ADDR_TYPE_PPPOE_SES: + case ADDR_TYPE_L2TP: + case ADDR_TYPE_PPP: + cJSON_AddNumberToObject(json_obj, "addr_type", addr->addrtype); + cJSON_AddStringToObject(json_obj, "s_ip", null_addr); + cJSON_AddStringToObject(json_obj, "d_ip", null_addr); + cJSON_AddNumberToObject(json_obj, "s_port", null_port); + cJSON_AddNumberToObject(json_obj, "d_port", null_port); + break; + case ADDR_TYPE_PPTP: + cJSON_AddNumberToObject(json_obj, "addr_type", addr->addrtype); + cJSON_AddStringToObject(json_obj, "s_ip", null_addr); + cJSON_AddStringToObject(json_obj, "d_ip", null_addr); + cJSON_AddNumberToObject(json_obj, "s_port", ntohs(addr->pptp->C2S_call_id)); + cJSON_AddNumberToObject(json_obj, "d_port", ntohs(addr->pptp->S2C_call_id)); + break; + default: + break; + } + + addr_proto = layer_addr_prefix_ntop(a_stream); + cJSON_AddStringToObject(json_obj, "trans_proto", addr_proto); + + MESA_get_stream_opt(a_stream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &tunnel_type_size); + if (tunnel_type == STREAM_TUNNLE_NON) + { + layer_addr_ntop_r(a_stream, nest_addr_buf, sizeof(nest_addr_buf)); + } + else + { + stream_addr_list_ntop(a_stream, nest_addr_buf, sizeof(nest_addr_buf)); + } + + cJSON_AddStringToObject(json_obj, "addr_list", nest_addr_buf); + + return 0; +} + extern long long g_CurrentTime; static void feedback_url_to_kafka(streaminfo *a_tcp, int http_seq, store_hash_data_t *store_hash_data) { @@ -230,6 +326,7 @@ static void feedback_url_to_kafka(streaminfo *a_tcp, int http_seq, store_hash_da cJSON_AddStringToObject(feedback_node, "url", store_hash_data->url_buf); + ntc_addStreamInfo_to_jsonObj(feedback_node, a_tcp); cJSON_AddNumberToObject(feedback_node, "found_time", store_hash_data->store_time); char *domain = (char *)calloc(sizeof(char), store_hash_data->url_len+1); form_url_to_domain(store_hash_data->url_buf, domain); |
