From cac5c951f20640fa89e23adb55dec8d5ac66a5cc Mon Sep 17 00:00:00 2001 From: lijie Date: Mon, 10 Dec 2018 10:25:03 +0800 Subject: 修改部分配置文件选项;修改日志输出形式;修改nominee_key,从uint32_t修改为char * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/conf/mrl.conf | 22 ++-- include/mrl_main.h | 20 +-- include/mrl_redis.h | 11 +- include/mrl_utils.h | 5 +- src/Makefile | 8 +- src/mrl_main.c | 357 +++++++++------------------------------------------- src/mrl_packet.c | 81 ++++++------ src/mrl_redis.c | 108 +++++++++------- src/mrl_utils.c | 35 ++++++ 9 files changed, 234 insertions(+), 413 deletions(-) diff --git a/bin/conf/mrl.conf b/bin/conf/mrl.conf index 071e4ce..5c16f3f 100644 --- a/bin/conf/mrl.conf +++ b/bin/conf/mrl.conf @@ -9,7 +9,7 @@ local_port=20182 mrl_port=23456 mgw_port=33456 mgw_ip=192.168.11.137 -mrl_ip=192.168.11.242 +mrl_netcard=enp131s0f2 [MAAT_INFO] Maat_table_path=./mrl_conf/table_info.conf Maat_max_threads=1 @@ -18,21 +18,23 @@ Maat_redis_port=6800 Maat_stat_path=./log/Maat_stat.log Maat_redis_index=5 [HTABLE_INFO] -ht_slots=10000 -ht_max_element_num=40000 +ht_slot_size=1048576 +ht_max_element_num=0 ht_mutex_num=5 [VXLAN_INFO] -vxlan_gdev_num=1 -vxlan_link_id_num=1 vxlan_local_mac=e4:95:6e:20:0d:0a -vxlan_gdev_mac=00:1e:73:6c:fa:43 vxlan_local_ip=192.168.1.10 -vxlan_gdev_ip=10.1.1.1 vxlan_local_port=50710 -vxlan_gdev_port=4789 -vxlan_encap_type=0 -vxlan_link_id=1 + vxlan_link_dir=1 vxlan_vpn_id=112 + +vxlan_gdev_num=1 +vxlan_gdev_mac=00:1e:73:6c:fa:43 +vxlan_gdev_ip=10.1.1.1 +vxlan_gdev_port=4789;4788 + +vxlan_link_id_num=1 +vxlan_link_id=1 vxlan_inner_smac=7c:2a:31:a3:44:9a vxlan_inner_dmac=e8:61:1f:13:70:7a \ No newline at end of file diff --git a/include/mrl_main.h b/include/mrl_main.h index 67530b1..721e9b6 100644 --- a/include/mrl_main.h +++ b/include/mrl_main.h @@ -40,24 +40,26 @@ struct mrl_global_cfg int redis_index; //htable info - unsigned int ht_slots; + unsigned int ht_slot_size; unsigned int ht_max_element_num; unsigned int ht_mutex_num; /*vxlan info*/ - unsigned int vxlan_gdev_num; - char **vxlan_outer_gdev_mac; char vxlan_outer_local_mac[MRL_STR_MAC_LEN]; - char **vxlan_outer_gdev_ip; char vxlan_outer_local_ip[MRL_STR_IP_LEN]; - char **vxlan_outer_gdev_port; char xvlan_outer_local_port[MRL_STR_PORT_LEN]; + + int vxlan_vpn_id; + int vxlan_link_dir; + + unsigned int vxlan_gdev_num; + char vxlan_outer_gdev_mac[MRL_STR_MAC_LEN]; + char **vxlan_outer_gdev_ip; + char **vxlan_outer_gdev_port; + + unsigned int vxlan_link_id_num;//豸· - int **vxlan_vpn_id; - int **vxlan_encap_type; - int **vxlan_link_dir; int **vxlan_link_id; - char ***vxlan_inner_smac; char ***vxlan_inner_dmac; }; diff --git a/include/mrl_redis.h b/include/mrl_redis.h index 252e133..8d56601 100644 --- a/include/mrl_redis.h +++ b/include/mrl_redis.h @@ -8,10 +8,10 @@ #define IR_DNAT_POLICY_TABLE_NAME "IR_DNAT_POLICY" struct mrl_ht_nominee_key{ -uint32_t sip;//network order -uint32_t dip;//network order -uint16_t sport;//network order -uint16_t dport;//network order +char sip[MRL_STR_IP_LEN]; +char dip[MRL_STR_IP_LEN]; +uint16_t sport;//host order +uint16_t dport;//host order }; struct mrl_nominee_item{ @@ -58,8 +58,7 @@ void ht_nominee_free_cb(void * data); void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candidate_item); Maat_feather_t mrl_Maat_feather_init(); void nominee_update_cb(int table_id,const char* table_line,void* u_para); -bool mrl_identify_nominee(struct streaminfo *mystream,void *rawpkt); -//bool mrl_identify_nominee(struct streaminfo *mystream); +bool mrl_identify_nominee(struct streaminfo *mystream); #endif diff --git a/include/mrl_utils.h b/include/mrl_utils.h index d65f543..5d3f132 100644 --- a/include/mrl_utils.h +++ b/include/mrl_utils.h @@ -11,7 +11,7 @@ #define MRL_STR_VPN_ID_LEN 5 #define MRL_STR_PROT_LEN 4 #define MRL_STR_EFFEC_RANGE_LEN 20 - +#define MRL_STR_NETCARD_LEN 20 #define MRL_DATE_LEN 50 #define MRL_MAX_PATH 50 @@ -38,6 +38,9 @@ unsigned int mrl_split_str(char *str, const char *delim, char **dest); int mrl_mac_pton(const char *str, int delim, uint8_t *mac); void get_cur_time(char *time); unsigned short mrl_get_checksum(unsigned short * buffer, size_t len); +unsigned int mrl_get_ip_by_eth_name(const char *ifname); +int mrl_inet_ntoa(uint32_t ip, char *dest); + void mrl_mmdb_init(const char *path); int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const char *mycountry); diff --git a/src/Makefile b/src/Makefile index 5637f24..2806a58 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,7 +38,7 @@ clean: rm -rf *.o install: - cp $(TARGET) /home/lijie/sapp/plug/business/mrl - cp ../bin/conf/mrl.inf /home/lijie/sapp/plug/business/mrl - cp ../bin/conf/*.conf /home/lijie/sapp/mrl_conf/ - cp ../bin/conf/all_ip_only_coun_v4.mmdb /home/lijie/sapp/mrl_conf + cp $(TARGET) /home/mesasoft/mrl_run/plug/business/mrl + cp ../bin/conf/mrl.inf /home/mesasoft/mrl_run/plug/business/mrl + cp ../bin/conf/*.conf /home/mesasoft/mrl_run/mrl_conf/ + cp ../bin/conf/all_ip_only_coun_v4.mmdb /home/mesasoft/mrl_run/mrl_conf diff --git a/src/mrl_main.c b/src/mrl_main.c index ed40fd2..8b67066 100644 --- a/src/mrl_main.c +++ b/src/mrl_main.c @@ -13,25 +13,15 @@ struct mrl_global_instance mrl_instance; extern struct global_stat_t global_stat; void mrl_cfg_init(const char *profile) { - char *temp_mac_str; char *temp_port_str; char *temp_ip_str; - char *temp_encap_type_str; - char *temp_vpn_id_str; char *temp_link_id_str; - char *temp_link_dir_str; char *temp_inner_mac_str; char **_link_id_str; - char **_encap_type_str; - char **_vpn_id_str; - char **_link_dir_str; char **_inner_mac_str; - char **encap_type_str; - char **vpn_id_str; char **link_id_str; - char **link_dir_str; char **gdev_inner_mac_str; unsigned int split_num = 0; @@ -45,27 +35,34 @@ void mrl_cfg_init(const char *profile) /********** load detect info **********/ MESA_load_profile_string_def(profile, "DETECT_INFO", "dest_ip", mrl_instance.mrl_cfg.dest_ip, MRL_STR_IP_LEN, "0.0.0.0"); - MESA_load_profile_int_def(profile, "DETECT_INFO", "dest_port",&(temp_port),8888); assert(temp_port > 0 && temp_port <= 65535); mrl_instance.mrl_cfg.dest_port = temp_port; - MESA_load_profile_int_def(profile, "DETECT_INFO", "local_port",&(temp_port),8888); assert(temp_port > 0 && temp_port <= 65535); mrl_instance.mrl_cfg.local_port = temp_port; /********** load sock info **********/ - MESA_load_profile_int_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888); - assert(temp_port > 0 && temp_port <= 65535); - mrl_instance.mrl_cfg.mrl_port = temp_port; - - + MESA_load_profile_string_def(profile, "SOCK_INFO", "mgw_ip", mrl_instance.mrl_cfg.mgw_ip, MRL_STR_IP_LEN, "0.0.0.0"); MESA_load_profile_int_def(profile, "SOCK_INFO", "mgw_port",&(temp_port),8888); assert(temp_port > 0 && temp_port <= 65535); mrl_instance.mrl_cfg.mgw_port = temp_port; - MESA_load_profile_string_def(profile, "SOCK_INFO", "mgw_ip", mrl_instance.mrl_cfg.mgw_ip, MRL_STR_IP_LEN, "0.0.0.0"); - MESA_load_profile_string_def(profile, "SOCK_INFO", "mrl_ip",mrl_instance.mrl_cfg.mrl_ip, MRL_STR_IP_LEN, "0.0.0.0"); + char mrl_netcard[MRL_STR_NETCARD_LEN]; + memset(mrl_netcard,0,MRL_STR_NETCARD_LEN); + MESA_load_profile_string_def(profile, "SOCK_INFO", "mrl_netcard", mrl_netcard, MRL_STR_NETCARD_LEN, "eth0"); + printf("mrl netcard is %s\n",mrl_netcard); + uint32_t temp_mrl_ip = mrl_get_ip_by_eth_name(mrl_netcard); + if(temp_mrl_ip < 0) + { + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_cfg_init","get ip from eth name error,eth name is %s",mrl_netcard); + assert(0); + } + inet_ntop(AF_INET,(void *)&temp_mrl_ip, mrl_instance.mrl_cfg.mrl_ip,MRL_STR_IP_LEN); + printf("mrl ip is %s\n",mrl_instance.mrl_cfg.mrl_ip); + MESA_load_profile_int_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888); + assert(temp_port > 0 && temp_port <= 65535); + mrl_instance.mrl_cfg.mrl_port = temp_port; /********** load maat info **********/ @@ -80,38 +77,29 @@ void mrl_cfg_init(const char *profile) /********** load htable info *********/ - MESA_load_profile_uint_def(profile, "HTABLE_INFO", "ht_slots", &(mrl_instance.mrl_cfg.ht_slots), 1048576); + MESA_load_profile_uint_def(profile, "HTABLE_INFO", "ht_slot_size", &(mrl_instance.mrl_cfg.ht_slot_size), 1048576); MESA_load_profile_uint_def(profile, "HTABLE_INFO", "ht_max_element_num", &(mrl_instance.mrl_cfg.ht_max_element_num), 0); MESA_load_profile_uint_def(profile, "HTABLE_INFO", "ht_mutex_num", &(mrl_instance.mrl_cfg.ht_mutex_num), 1); /********** load gdev info **********/ - MESA_load_profile_uint_def(profile, "VXLAN_INFO", "vxlan_gdev_num", &(mrl_instance.mrl_cfg.vxlan_gdev_num), 1); - - temp_mac_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_MAC_LEN,sizeof(char)); - global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_MAC_LEN; - temp_ip_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN,sizeof(char)); - global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN; - - temp_port_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN, sizeof(char)); - global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN; + MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_mac", mrl_instance.mrl_cfg.vxlan_outer_local_mac, MRL_STR_MAC_LEN, "00:00:00:00:00:00"); + MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_ip", mrl_instance.mrl_cfg.vxlan_outer_local_ip, MRL_STR_IP_LEN, "127.0.0.1"); + MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_port", mrl_instance.mrl_cfg.xvlan_outer_local_port,MRL_STR_PORT_LEN, "8888"); - MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_gdev_mac",temp_mac_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_MAC_LEN, "00:00:00:00:00:00"); - mrl_instance.mrl_cfg.vxlan_outer_gdev_mac = (char **)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num, sizeof(char *)); - global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *); - for(i=0;ivxlan_outer_local_mac, ':', temp_mac); - //printf("SAPP_SEND_OPT_GDEV_SMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_SMAC: %02x-%02x-%02x-%02x-%02x-%02x", + temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC; option[option_num].length = MRL_MAC_LEN; memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN); @@ -142,14 +139,15 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const memset(temp_mac, 0, MRL_MAC_LEN); mrl_mac_pton(vxlan_info->vxlan_outer_gdev_mac, ':', temp_mac); - //printf("SAPP_SEND_OPT_GDEV_DMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_DMAC: %02x-%02x-%02x-%02x-%02x-%02x", + temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC; option[option_num].length = MRL_MAC_LEN; memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN); option_num++;/////// inet_pton(AF_INET, vxlan_info->vxlan_outer_local_ip, &temp_ip); - //printf("SAPP_SEND_OPT_GDEV_SIP is:%u\n",temp_ip); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_SIP: %s",vxlan_info->vxlan_outer_local_ip); option[option_num].type = SAPP_SEND_OPT_GDEV_SIP; option[option_num].length = 4; option[option_num].int_value = temp_ip; @@ -157,7 +155,7 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const inet_pton(AF_INET, vxlan_info->vxlan_outer_gdev_ip, &temp_ip); - //printf("SAPP_SEND_OPT_GDEV_DIP is:%u\n",temp_ip); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_DIP: %s",vxlan_info->vxlan_outer_gdev_ip); option[option_num].type = SAPP_SEND_OPT_GDEV_DIP; option[option_num].length = 4; option[option_num].int_value = temp_ip; @@ -166,7 +164,7 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const temp_port = atoi(vxlan_info->vxlan_outer_local_port); assert(temp_port >0 && temp_port <= 65535); - //printf("SAPP_SEND_OPT_GDEV_UDP_SPORT is:%hu\n",temp_port); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_UDP_SPORT: %hu",temp_port); option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT; option[option_num].length = 2; option[option_num].short_value = htons(temp_port); @@ -175,39 +173,38 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const temp_port = atoi(vxlan_info->vxlan_outer_gdev_port); assert(temp_port >0 && temp_port <= 65535); - //printf("SAPP_SEND_OPT_GDEV_UDP_DPORT is:%hu\n",temp_port); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_GDEV_UDP_DPORT: %hu",temp_port); option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT; option[option_num].length = 2; option[option_num].short_value = htons(temp_port); - //printf("cur option gdev_udp_dport value is %hu\n",ntohs(option[option_num].short_value)); option_num++;/////// option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID; - //printf("SAPP_SEND_OPT_VXLAN_VPN_ID is %d\n",vxlan_info->vxlan_vpn_id); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_VXLAN_VPN_ID: %d",vxlan_info->vxlan_vpn_id); option[option_num].length = 4; option[option_num].int_value = vxlan_info->vxlan_vpn_id; option_num++;/////// - //printf("SAPP_SEND_OPT_VXLAN_LINK_ID is:%d\n",vxlan_info->vxlan_link_id); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_VXLAN_LINK_ID: %d",vxlan_info->vxlan_link_id); option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID; option[option_num].length = 4; option[option_num].int_value = vxlan_info->vxlan_link_id; option_num++;/////// - //printf("SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE is:%d\n",vxlan_info->vxlan_encap_type); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE: %d",TUNNAT_TUNNEL_TYPE_ETHER); option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE; option[option_num].length = 1; option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER; option_num++;/////// - //printf("SAPP_SEND_OPT_VXLAN_LINK_DIR is:%d\n",vxlan_info->vxlan_link_dir); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_VXLAN_LINK_DIR: %d",vxlan_info->vxlan_link_dir); option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR; option[option_num].length = 1; option[option_num].char_value = vxlan_info->vxlan_link_dir; option_num++;/////// - //printf("SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE is:%d\n",vxlan_info->vxlan_encap_type); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE: %d",TUNNAT_TUNNEL_TYPE_ETHER); option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE; option[option_num].length = 1; option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER; @@ -216,7 +213,8 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const memset(temp_mac, 0, MRL_MAC_LEN); mrl_mac_pton(vxlan_info->vxlan_inner_smac, ':', temp_mac); - //printf("SAPP_SEND_OPT_INNER_SMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_INNER_SMAC: %02x-%02x-%02x-%02x-%02x-%02x", + temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); option[option_num].type = SAPP_SEND_OPT_INNER_SMAC; option[option_num].length = MRL_MAC_LEN; memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN); @@ -225,11 +223,13 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const memset(temp_mac, 0, MRL_MAC_LEN); mrl_mac_pton(vxlan_info->vxlan_inner_dmac, ':', temp_mac); - //printf("SAPP_SEND_OPT_INNER_DMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_gdev","SAPP_SEND_OPT_INNER_DMAC: %02x-%02x-%02x-%02x-%02x-%02x", + temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]); option[option_num].type = SAPP_SEND_OPT_INNER_DMAC; option[option_num].length = MRL_MAC_LEN; memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN); option_num++;/////// + int ret = 0; ret = MESA_sendpacket_iplayer_options(thread_seq, payload, @@ -238,7 +238,6 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const option, option_num); assert(ret >=0); - //printf("send to gdev ret is %d\n",ret); } @@ -246,6 +245,8 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const bool mrl_pkt_signature_identify(struct streaminfo *mystream) { uint8_t type = 0; + char debug_sip[MRL_STR_IP_LEN]; + char debug_dip[MRL_STR_IP_LEN]; uint16_t sport = 0, dport = 0, temp_port = 0; uint32_t hash_sport = 0, hash_dport =0; uint32_t sip = 0, dip = 0; @@ -268,9 +269,12 @@ bool mrl_pkt_signature_identify(struct streaminfo *mystream) hash_dport = sport ^ sip ^ dip ^type; hash_dport = hash_dport & 0xff; temp_port = dport & 0xff; - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","cur stream[sip:%u,sport:%hu, dip:%u,dport:%hu]" - "hash info is:[hash_dport:%hu, dest_port:%u,protocol is %d", - sip,sport,dip,dport,hash_dport,temp_port,type); + + mrl_inet_ntoa(sip,debug_sip); + mrl_inet_ntoa(dip,debug_dip); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","cur stream[sip:%s,sport:%hu, dip:%s,dport:%hu]" + "hash info is:[hash_dport:%hu, ir_port:%u,protocol is %d", + debug_sip,sport,debug_dip,dport,hash_dport,temp_port,type); if(hash_dport == temp_port) { return true; @@ -280,9 +284,9 @@ bool mrl_pkt_signature_identify(struct streaminfo *mystream) hash_sport = dport ^ sip ^ dip ^type; hash_sport = hash_sport & 0xff; temp_port = sport & 0xff; - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","cur stream[sip:%u,sport:%hu, dip:%u,dport:%hu]" - "hash info is:[hash_sport:%hu, dest_port:%u,protocol is %d", - sip,sport,dip,dport,hash_dport,temp_port,type); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","cur stream[sip:%s,sport:%hu, dip:%s,dport:%hu]" + "hash info is:[hash_sport:%hu, ir_port:%u,protocol is %d", + debug_sip,sport,debug_dip,dport,hash_dport,temp_port,type); if(hash_sport == temp_port) { return true; @@ -380,26 +384,28 @@ size_t mrl_build_udp_payload(char *payload) void mrl_construct_vxlan_info(struct mrl_vxlan_info *vxlan_info, int gdev_index, int link_id_index) { - - memcpy(vxlan_info->vxlan_outer_local_port, mrl_instance.mrl_cfg.xvlan_outer_local_port,strlen(mrl_instance.mrl_cfg.xvlan_outer_local_port)); - memcpy(vxlan_info->vxlan_outer_gdev_port , mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index])); + memcpy(vxlan_info->vxlan_outer_local_mac, mrl_instance.mrl_cfg.vxlan_outer_local_mac,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_mac)); memcpy(vxlan_info->vxlan_outer_local_ip, mrl_instance.mrl_cfg.vxlan_outer_local_ip,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_ip)); + memcpy(vxlan_info->vxlan_outer_local_port, mrl_instance.mrl_cfg.xvlan_outer_local_port,strlen(mrl_instance.mrl_cfg.xvlan_outer_local_port)); + + memcpy(vxlan_info->vxlan_outer_gdev_mac, mrl_instance.mrl_cfg.vxlan_outer_gdev_mac,strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac)); memcpy(vxlan_info->vxlan_outer_gdev_ip, mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index])); - memcpy(vxlan_info->vxlan_outer_local_mac, mrl_instance.mrl_cfg.vxlan_outer_local_mac,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_mac)); - memcpy(vxlan_info->vxlan_outer_gdev_mac, mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[gdev_index])); + memcpy(vxlan_info->vxlan_outer_gdev_port , mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index])); + + vxlan_info->vxlan_encap_type = 0; + vxlan_info->vxlan_vpn_id= mrl_instance.mrl_cfg.vxlan_vpn_id; + vxlan_info->vxlan_link_dir = mrl_instance.mrl_cfg.vxlan_link_dir; + vxlan_info->vxlan_link_id = mrl_instance.mrl_cfg.vxlan_link_id[gdev_index][link_id_index]; - vxlan_info->vxlan_encap_type = mrl_instance.mrl_cfg.vxlan_encap_type[gdev_index][link_id_index]; - vxlan_info->vxlan_vpn_id= mrl_instance.mrl_cfg.vxlan_vpn_id[gdev_index][link_id_index]; - vxlan_info->vxlan_link_dir = mrl_instance.mrl_cfg.vxlan_link_dir[gdev_index][link_id_index]; memcpy(vxlan_info->vxlan_inner_smac, mrl_instance.mrl_cfg.vxlan_inner_smac[gdev_index][link_id_index],strlen(mrl_instance.mrl_cfg.vxlan_inner_smac[gdev_index][link_id_index])); memcpy(vxlan_info->vxlan_inner_dmac, mrl_instance.mrl_cfg.vxlan_inner_dmac[gdev_index][link_id_index], strlen(mrl_instance.mrl_cfg.vxlan_inner_dmac[gdev_index][link_id_index])); } void mrl_detect_action(uint32_t src_ip) { - char temp_ip[MRL_STR_IP_LEN]; - memset(temp_ip,0,MRL_STR_IP_LEN); - inet_ntop(AF_INET, &src_ip,temp_ip, MRL_STR_IP_LEN); - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_detect_action","detect ip is %s",temp_ip); + char debug_ip[MRL_STR_IP_LEN]; + memset(debug_ip,0,MRL_STR_IP_LEN); + inet_ntop(AF_INET, &src_ip,debug_ip, MRL_STR_IP_LEN); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_detect_action","detect ip is %s",debug_ip); unsigned int i = 0, j =0; int thread_seq = 0; int temp_len = 0; @@ -441,7 +447,6 @@ void *mrl_detect_ip_action(void *arg) break; } ret = MESA_lqueue_get_head(mrl_instance.mrl_queue,&detect_ip,&ip_len); - printf("queue head ip is %u\n",detect_ip); if(ret != 0) { MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_ip_action","MESA_lqueue_get_head func error! ret is %d",ret); diff --git a/src/mrl_redis.c b/src/mrl_redis.c index 0facf17..0d59c51 100644 --- a/src/mrl_redis.c +++ b/src/mrl_redis.c @@ -53,10 +53,10 @@ MESA_htable_handle mrl_htable_init(void * fn_data_free_cb) opt_int = 0; MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, &opt_int, sizeof(int)); - opt_int = mrl_instance.mrl_cfg.ht_slots; + opt_int = mrl_instance.mrl_cfg.ht_slot_size; MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, &opt_int, sizeof(int)); - opt_int = mrl_instance.mrl_cfg.ht_max_element_num + 1; + opt_int = mrl_instance.mrl_cfg.ht_max_element_num; MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, &opt_int, sizeof(int)); opt_int = mrl_instance.mrl_cfg.ht_mutex_num; @@ -115,21 +115,22 @@ int Maat_plugin_table(Maat_feather_t feather,const char* table_name, Maat_start_ void nominee_update_cb(int table_id,const char *table_line,void *u_para) { int ret = 0; + uint32_t queue_ip = 0; struct mrl_nominee_item *nominee_item = (struct mrl_nominee_item *)calloc(1, sizeof(struct mrl_nominee_item)); global_stat.malloc_memory += sizeof(struct mrl_nominee_item); sscanf(table_line,"%d\t%d\t%d\t%s\t%d\t%s\t%s", &(nominee_item->config_id), &(nominee_item->addr_pool_id), &(nominee_item->addr_type), nominee_item->ip_addr, &(nominee_item->is_valid), nominee_item->effective_range, nominee_item->op_time); MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","get nominee item:" - "config_id:%d,group_id:%d,addr_type:%d,ip_addr:%s,is_valid:%d,effective_range:%s,op_time:%s", + "config_id:%d,addr_pool_id:%d,addr_type:%d,ip_addr:%s,is_valid:%d,effective_range:%s,op_time:%s", nominee_item->config_id, nominee_item->addr_pool_id,nominee_item->addr_type, nominee_item->ip_addr, nominee_item->is_valid,nominee_item->effective_range,nominee_item->op_time); struct mrl_ht_nominee_key nominee_key; memset(&nominee_key,0,sizeof(struct mrl_ht_nominee_key)); - inet_pton(AF_INET,nominee_item->ip_addr,&(nominee_key.sip)); - inet_pton(AF_INET,mrl_instance.mrl_cfg.dest_ip,&(nominee_key.dip)); - nominee_key.sport=htons(mrl_instance.mrl_cfg.local_port); - nominee_key.dport=htons(mrl_instance.mrl_cfg.dest_port); + memcpy(nominee_key.sip,nominee_item->ip_addr,strlen(nominee_item->ip_addr)); + memcpy(nominee_key.dip,mrl_instance.mrl_cfg.dest_ip,strlen(mrl_instance.mrl_cfg.dest_ip)); + nominee_key.sport=mrl_instance.mrl_cfg.local_port; + nominee_key.dport=mrl_instance.mrl_cfg.dest_port; switch(nominee_item->is_valid) { case 0: @@ -141,11 +142,11 @@ void nominee_update_cb(int table_id,const char *table_line,void *u_para) MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_htable_del func error! ret is %d",ret); assert(0); } - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%u, dip:%u, sport:%hu, dport:%hu] is deleted.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%s, dip:%s, sport:%hu, dport:%hu] is deleted.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); } else { - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%u, dip:%u, sport:%hu, dport:%hu] is not exsit in nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%s, dip:%s, sport:%hu, dport:%hu] is not exsit in nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); } break; case 1: @@ -154,29 +155,33 @@ void nominee_update_cb(int table_id,const char *table_line,void *u_para) ret = MESA_htable_add(mrl_instance.ht_nominee, (const unsigned char *)&nominee_key, sizeof(nominee_key), nominee_item); if(ret < 0) { - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_htable_add func error! ret is %d",ret); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","insert the nominee key[sip:%s, dip:%s, sport:%hu, dport:%hu] fail! ret is %d",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport,ret); + assert(0); + } + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","insert the nominee key[sip:%s, dip:%s, sport:%hu, dport:%hu] into nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); + inet_pton(AF_INET,nominee_key.sip,&queue_ip); + ret = MESA_lqueue_join_tail(mrl_instance.mrl_queue,&(queue_ip),sizeof(queue_ip)); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","insert queue ip is %s",nominee_key.sip); + if(ret != 0) + { + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","the ip insert into lqueue fail!ret is %d",nominee_key.sip,ret); assert(0); } - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","insert the nominee key[sip:%u, dip:%u, sport:%hu, dport:%hu] into nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); - //ret = MESA_lqueue_join_tail(mrl_instance.mrl_queue,&(nominee_key.sip),sizeof(nominee_key.sip)); - //MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","insert queue ip is %u",nominee_key.sip); - //if(ret != 0) - //{ - // MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_lqueue_join_tail func error! ret is %d",ret); - // assert(0); - //} } else { - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%u, dip:%u, sport:%hu, dport:%hu] is duplicated in nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee key[sip:%s, dip:%s, sport:%hu, dport:%hu] is duplicated in nominee htable.",nominee_key.sip,nominee_key.dip,nominee_key.sport,nominee_key.dport); } - ret = MESA_lqueue_join_tail(mrl_instance.mrl_queue,&(nominee_key.sip),sizeof(nominee_key.sip)); - printf("nominee ip %u insert into queue\n",nominee_key.sip); + /* + inet_pton(AF_INET,nominee_key.sip,&queue_ip); + printf("insert ip %s into lqueue\n",nominee_key.sip); + ret = MESA_lqueue_join_tail(mrl_instance.mrl_queue,&(queue_ip),sizeof(queue_ip)); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","insert queue ip is %s",nominee_key.sip); if(ret != 0) { - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_lqueue_join_tail func error! ret is %d",ret); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","the ip insert into lqueue fail!ret is %d",nominee_key.sip,ret); assert(0); - } + }*/ break; default: assert(0); @@ -270,30 +275,40 @@ int mrl_get_link_id_index(int gdev_index, int link_id) void mrl_get_vxlan_info(struct streaminfo *mystream, struct mrl_vxlan_info *vxlan_info, unsigned int gdev_index) { int link_id = 0; - memcpy(vxlan_info->vxlan_outer_local_port, mrl_instance.mrl_cfg.xvlan_outer_local_port,strlen(mrl_instance.mrl_cfg.xvlan_outer_local_port)); - memcpy(vxlan_info->vxlan_outer_gdev_port , mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index])); - memcpy(vxlan_info->vxlan_outer_local_ip, mrl_instance.mrl_cfg.vxlan_outer_local_ip,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_ip)); - memcpy(vxlan_info->vxlan_outer_gdev_ip, mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index])); - memcpy(vxlan_info->vxlan_outer_local_mac, mrl_instance.mrl_cfg.vxlan_outer_local_mac,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_mac)); - memcpy(vxlan_info->vxlan_outer_gdev_mac, mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[gdev_index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[gdev_index])); + memcpy(vxlan_info->vxlan_outer_local_mac, mrl_instance.mrl_cfg.vxlan_outer_local_mac, strlen(mrl_instance.mrl_cfg.vxlan_outer_local_mac)); + memcpy(vxlan_info->vxlan_outer_local_ip, mrl_instance.mrl_cfg.vxlan_outer_local_ip, strlen(mrl_instance.mrl_cfg.vxlan_outer_local_ip)); + memcpy(vxlan_info->vxlan_outer_local_port, mrl_instance.mrl_cfg.xvlan_outer_local_port, strlen(mrl_instance.mrl_cfg.xvlan_outer_local_port)); + + memcpy(vxlan_info->vxlan_outer_gdev_mac, mrl_instance.mrl_cfg.vxlan_outer_gdev_mac, strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac)); + memcpy(vxlan_info->vxlan_outer_gdev_ip, mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index], strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[gdev_index])); + memcpy(vxlan_info->vxlan_outer_gdev_port, mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index], strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_port[gdev_index])); + get_rawpkt_opt_from_streaminfo(mystream, RAW_PKT_GET_VXLAN_ID, &link_id); vxlan_info->vxlan_link_id = ntohl(link_id); - printf("cur stream[sip:%u,sport:%hu,dip:%u,dport:%hu] link id is %d\n",mystream->addr.tuple4_v4->saddr,mystream->addr.tuple4_v4->source,mystream->addr.tuple4_v4->daddr,mystream->addr.tuple4_v4->dest,vxlan_info->vxlan_link_id); + printf("cur link id is %d\n",vxlan_info->vxlan_link_id); int position = mrl_get_link_id_index(gdev_index, vxlan_info->vxlan_link_id); if(position <0) { - printf("cur stream[sip:%u,sport:%hu,dip:%u,dport:%hu]\n",mystream->addr.tuple4_v4->saddr,mystream->addr.tuple4_v4->source,mystream->addr.tuple4_v4->daddr,mystream->addr.tuple4_v4->dest); + char debug_sip[MRL_STR_IP_LEN]; + char debug_dip[MRL_STR_IP_LEN]; + uint16_t debug_sport; + uint16_t debug_dport; + mrl_inet_ntoa(mystream->addr.tuple4_v4->saddr,debug_sip); + mrl_inet_ntoa(mystream->addr.tuple4_v4->daddr,debug_dip); + debug_sport = ntohs(mystream->addr.tuple4_v4->source); + debug_dport = ntohs(mystream->addr.tuple4_v4->dest); + printf("cur stream[sip:%s,sport:%hu,dip:%s,dport:%hu] link id is %d\n",debug_sip,debug_sport,debug_dip,debug_dport,vxlan_info->vxlan_link_id); MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_get_vxlan_info","cur stream[sip:%u,sport:%hu,dip:%u,dport:%hu]" "get link id error,link id is %d,gdev index is %d,position is %d", - mystream->addr.tuple4_v4->saddr,mystream->addr.tuple4_v4->source,mystream->addr.tuple4_v4->daddr,mystream->addr.tuple4_v4->dest, + debug_sip,debug_sport,debug_dip,debug_dport, vxlan_info->vxlan_link_id,gdev_index,position); - //assert(0); - position = 0; + assert(0); } - vxlan_info->vxlan_encap_type = mrl_instance.mrl_cfg.vxlan_encap_type[gdev_index][position]; - vxlan_info->vxlan_vpn_id= mrl_instance.mrl_cfg.vxlan_vpn_id[gdev_index][position]; - vxlan_info->vxlan_link_dir = mrl_instance.mrl_cfg.vxlan_link_dir[gdev_index][position]; + vxlan_info->vxlan_encap_type = 0; + vxlan_info->vxlan_vpn_id= mrl_instance.mrl_cfg.vxlan_vpn_id; + vxlan_info->vxlan_link_dir = mrl_instance.mrl_cfg.vxlan_link_dir; + memcpy(vxlan_info->vxlan_inner_smac, mrl_instance.mrl_cfg.vxlan_inner_smac[gdev_index][position],strlen(mrl_instance.mrl_cfg.vxlan_inner_smac[gdev_index][position])); memcpy(vxlan_info->vxlan_inner_dmac, mrl_instance.mrl_cfg.vxlan_inner_dmac[gdev_index][position], strlen(mrl_instance.mrl_cfg.vxlan_inner_dmac[gdev_index][position])); } @@ -329,7 +344,7 @@ void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candid MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"Maat_set_cmd_line","Maat_cmd_set_lines func error! ret is %d",ret); } MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"Maat_set_cmd_line","maat set candidate item:" - "config_id:%d,group_id:%d,addr_type:%d,ip_addr:%s,location:%d,mrl_ip:%s,link_id:%d,encap_type:%d," + "config_id:%d,addr_pool_id:%d,addr_type:%d,ip_addr:%s,location:%d,mrl_ip:%s,link_id:%d,encap_type:%d," "link_dir:%d,vpn_id:%d,local_port:%s,gdev_port:%s, local_ip:%s,gdev_ip:%s,local_mac:%s, gdev_mac:%s," "inner_smac:%s, inner_dmac:%s,is_valid:%d,effective_range:%s,op_time:%s", candidate_item->config_id, candidate_item->addr_pool_id,candidate_item->addr_type, candidate_item->ip_addr, @@ -360,8 +375,8 @@ unsigned int get_gdev_ip_index(UINT32 gdev_ip) return index; } -bool mrl_identify_nominee(struct streaminfo *mystream,void *rawpkt) -//bool mrl_identify_nominee(struct streaminfo *mystream) + +bool mrl_identify_nominee(struct streaminfo *mystream) { char ip_addr[MRL_STR_IP_LEN]; memset(ip_addr,0,MRL_STR_IP_LEN); @@ -373,17 +388,14 @@ bool mrl_identify_nominee(struct streaminfo *mystream,void *rawpkt) inet_ntop(AF_INET, &(mystream->addr.tuple4_v4->saddr), ip_addr, MRL_STR_IP_LEN); struct mrl_ht_nominee_key nominee_key; memset(&nominee_key,0,sizeof(nominee_key)); - nominee_key.sip = mystream->addr.tuple4_v4->saddr; - nominee_key.dip= mystream->addr.tuple4_v4->daddr; - nominee_key.sport= mystream->addr.tuple4_v4->source; - nominee_key.dport= mystream->addr.tuple4_v4->dest; - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","cur stream nominee key is [sip:%u, dip:%u, sport:%hu, dport:%hu].",nominee_key.sip, nominee_key.dip, nominee_key.sport, nominee_key.dport); + inet_ntop(AF_INET,(void*)&(mystream->addr.tuple4_v4->saddr),nominee_key.sip,MRL_STR_IP_LEN); + inet_ntop(AF_INET,(void*)&(mystream->addr.tuple4_v4->daddr),nominee_key.dip,MRL_STR_IP_LEN); + nominee_key.sport= ntohs(mystream->addr.tuple4_v4->source); + nominee_key.dport= ntohs(mystream->addr.tuple4_v4->dest); + MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","cur stream nominee key is [sip:%s, dip:%s, sport:%hu, dport:%hu]",nominee_key.sip, nominee_key.dip, nominee_key.sport, nominee_key.dport); if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)&nominee_key, sizeof(nominee_key),ht_search_cb,(void *)&candidate_item,&ret) != NULL) { global_stat.recv_detect_pkts ++; - struct iphdr *ip_hdr = (struct iphdr *)rawpkt; - printf("cur identify nominee pkt sip is %u,dip is %u\n",ip_hdr->saddr,ip_hdr->daddr); - MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","cur detected packet key is [sip:%u, dip:%u, sport:%hu, dport:%hu].",nominee_key.sip, nominee_key.dip, nominee_key.sport, nominee_key.dport); get_rawpkt_opt_from_streaminfo(mystream, RAW_PKT_GET_GDEV_IP, &(gdev_ip)); index = get_gdev_ip_index(gdev_ip); assert(index < mrl_instance.mrl_cfg.vxlan_gdev_num);//ھ˵ݰGDEV̽GDEVУ diff --git a/src/mrl_utils.c b/src/mrl_utils.c index 95d6eb2..6356a00 100644 --- a/src/mrl_utils.c +++ b/src/mrl_utils.c @@ -4,11 +4,46 @@ #include #include #include +#include +#include +#include #include "mrl_utils.h" #include "mrl_main.h" extern struct mrl_global_instance mrl_instance; +int mrl_inet_ntoa(uint32_t ip, char *dest) +{ + const char *_ip = inet_ntoa(*(struct in_addr *)&ip); + strncpy(dest, _ip, MRL_STR_IP_LEN); + return 0; +} + +unsigned int mrl_get_ip_by_eth_name(const char *ifname) +{ + int sockfd; + struct ifreq ifr; + unsigned int ip; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (-1 == sockfd) { + goto error; + } + + strcpy(ifr.ifr_name,ifname); + if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) { + goto error; + } + + ip = ((struct sockaddr_in*)&(ifr.ifr_addr))->sin_addr.s_addr; + close(sockfd); + return ip; + +error: + close(sockfd); + return -1; +} + /* asciiַת16 */ char mrl_ascii_to_hex(char ascii) { -- cgit v1.2.3