summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2020-09-01 21:19:16 +0800
committerlijia <[email protected]>2020-09-01 21:19:16 +0800
commit3565515b06deee3fb4b702c0ec676cee4ac4759f (patch)
treeefe8c6b805837e6dce9375f7d64dfa734e5c251f
parent69e7edf06a50136d04d59978b69a12d88f8be264 (diff)
修复并联模式下, 注入数据包方式, 支持四种模式: sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gatewayv4.1.3
-rw-r--r--bin/etc/sapp.toml13
-rw-r--r--include/private/sapp_global_val.h4
-rw-r--r--include/public/stream_inc/stream_project.h2
-rw-r--r--src/config/config_parse.cpp22
-rw-r--r--src/packet_io/packet_io.c29
-rw-r--r--src/packet_io/sendpacket.c23
6 files changed, 54 insertions, 39 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index 048f6e6..a7ad6f4 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -33,14 +33,19 @@ dictator_enable=1
create_mpls_anyway=0
-### note, depolyment.mode options: [sys_route, vxlan_by_inline_device, raw_ethernet]
-### sys_route: send ip(ipv6) packet by system route table, default mode in mirror mode;
+### note, depolyment.mode options: [sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]
+### sys_route: send ip(ipv6) packet by system route table, this is default mode in mirror mode;
### vxlan_by_inline_device: encapsulation inject packet with vxlan, and then send to inline device by udp socket.
-### raw_ethernet: send layer2 ethernet packet to specific gateway in same broadcast domain.
+### raw_ethernet_single_gateway: send layer2 ethernet packet to specific gateway in same broadcast domain.
+### raw_ethernet_multi_gateway: send layer2 ethernet packet to multiple gateway in same broadcast domain.
inject_pkt_mode=sys_route
### note, this config is valid if inject_pkt_mode==vxlan_by_inline_device, means udp socket src port.
inject_mode_inline_device_sport=54789
+
+### note, this config is valid if inject_pkt_mode==raw_ethernet_single_gateway.
+ inject_mode_single_gateway_device="eth1"
+ inject_mode_single_gateway_dst_mac="00:11:22:33:44:55"
### note, depolyment.mode options: [mirror, inline, transparent]
[packet_io.depolyment]
@@ -84,7 +89,7 @@ dictator_enable=1
signature_enabled=1
signature_seed1=65535
signature_seed2=13
- remedy_kill_tcp_by_inline_device=1
+ remedy_kill_tcp_by_inline_device=0
[stream.udp]
max=10000
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index 6a4d796..fc6e84a 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -182,6 +182,10 @@ typedef struct{
char inject_pkt_mode_string[NAME_MAX];
int inject_pkt_mode; /* ��ע�뷽ʽ������ֵ, ���: enum send_fake_packet_mode */
unsigned short inject_mode_inline_device_sport; /* udp socket�󶨵ı���Դ�˿�, host order, ������ */
+ char inject_mode_single_gateway_device[NAME_MAX];
+ char inject_mode_single_gateway_dst_mac_string[20];
+ char inject_mode_single_gateway_dst_mac[6]; /* gateway��MAC */
+ char inject_mode_single_gateway_src_mac[6]; /* inject_mode_single_gateway_device������MAC */
}sapp_config_packet_io_t;
typedef struct{
diff --git a/include/public/stream_inc/stream_project.h b/include/public/stream_inc/stream_project.h
index 6f38b37..35cc685 100644
--- a/include/public/stream_inc/stream_project.h
+++ b/include/public/stream_inc/stream_project.h
@@ -119,7 +119,7 @@ int project_req_add_struct(struct streaminfo *stream, int project_req_id, const
For example:
int value = project_req_get_int(stream, req_id);
if((-1 == value) && (ERANGE == errno)){
- error_handle();
+ error_handle();
}else{
// this is not an error!!
do_something();
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index 68b0ab0..251a407 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -326,13 +326,27 @@ static int config_expression_convert(void)
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_3_LAYER;
}else if(strncasecmp("vxlan_by_inline_device", pconfig->packet_io.inject_pkt_mode_string, strlen("vxlan_by_inline_device")) == 0){
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_GDEV;
- }else if(strncasecmp("raw_ethernet", pconfig->packet_io.inject_pkt_mode_string, strlen("raw_ethernet")) == 0){
+ }else if(strncasecmp("raw_ethernet_single_gateway", pconfig->packet_io.inject_pkt_mode_string, strlen("raw_ethernet_single_gateway")) == 0){
+ pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE;
+ }else if(strncasecmp("raw_ethernet_multi_gateway", pconfig->packet_io.inject_pkt_mode_string, strlen("raw_ethernet_multi_gateway")) == 0){
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE;
}else{
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->PACKET_IO.inject_pkt_mode error, only support:%s!", "[sys_route, vxlan_by_inline_device, raw_ethernet]");
+ sapp_log(30, ~0, ~0, "[Error]sapp.toml->PACKET_IO.inject_pkt_mode error, only support:%s!", "[sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]");
return -1;
}
+ if(strncasecmp(pconfig->packet_io.inject_pkt_mode_string, "raw_ethernet_single_gateway", strlen("raw_ethernet_single_gateway")) == 0){
+ if(MESA_mac_pton(pconfig->packet_io.inject_mode_single_gateway_dst_mac_string, ':', pconfig->packet_io.inject_mode_single_gateway_dst_mac) < 0){
+ sapp_log(30, ~0, ~0, "[Error]sapp.toml->[packet_io.feature]->inject_mode_single_gateway_dst_mac error: %s", pconfig->packet_io.inject_mode_single_gateway_dst_mac_string);
+ return -1;
+ }
+
+ if(MESA_get_dev_mac(pconfig->packet_io.inject_mode_single_gateway_device, (unsigned char *)pconfig->packet_io.inject_mode_single_gateway_src_mac) < 0){
+ sapp_log(30, ~0, ~0, "[Error]can't get sapp.toml->[packet_io.feature]->inject_mode_single_gateway_device: '%s' mac address", pconfig->packet_io.inject_mode_single_gateway_device);
+ return -1;
+ }
+ }
+
tmp_str = pconfig->packet_io.external.interface.type_str;
if(strncasecmp(tmp_str, "pcap", strlen("pcap")) == 0){
pconfig->packet_io.external.interface.type_bin = CAP_MODEL_PCAP_ONLINE;
@@ -628,6 +642,10 @@ int sapp_parse_config(void)
tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"pcap_capture_direction", pconfig->packet_io.pcap_capture_direction, NAME_MAX, "in");
tomlc99_wrap_load_int_def(default_config_file, (char *)"packet_io.feature", (char *)"create_mpls_anyway", &pconfig->packet_io.create_mpls_anyway, 0);
tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"inject_pkt_mode", pconfig->packet_io.inject_pkt_mode_string, NAME_MAX, "sys_route");
+ if(strncasecmp(pconfig->packet_io.inject_pkt_mode_string, "raw_ethernet_single_gateway", strlen("raw_ethernet_single_gateway")) == 0){
+ tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"inject_mode_single_gateway_device", pconfig->packet_io.inject_mode_single_gateway_device, NAME_MAX, "lo");
+ tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"inject_mode_single_gateway_dst_mac", pconfig->packet_io.inject_mode_single_gateway_dst_mac_string, sizeof(pconfig->packet_io.inject_mode_single_gateway_dst_mac_string), "$");
+ }
tomlc99_wrap_load_int_def(default_config_file, (char *)"packet_io.feature", (char *)"inject_mode_inline_device_sport", &tmp_int, 54789);
if(tmp_int <= 0 || tmp_int > 65535){
sapp_log(30, ~0, ~0, "config parse error! invalid value of 'packet_io.feature.inject_mode_inline_device_sport %d'", tmp_int);
diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c
index 5efde37..d630f9a 100644
--- a/src/packet_io/packet_io.c
+++ b/src/packet_io/packet_io.c
@@ -35,8 +35,8 @@ int gdev_init(void);
extern int packet_io_status_init(void);
extern MESA_send_handle g_send_handle[MAX_THREAD_NUM];
char g_send_dev_name[DEV_NAME_STR_LEN]; /* ���������� */
-unsigned char g_send_dev_mac[MAC_ADDR_LEN];
-unsigned char g_send_gateway_mac[MAC_ADDR_LEN]; /* ͨ���ֹ����û��ѯ·�ɱ���ARP���õ� */
+//unsigned char g_send_dev_mac[MAC_ADDR_LEN];
+//unsigned char g_send_gateway_mac[MAC_ADDR_LEN]; /* ͨ���ֹ����û��ѯ·�ɱ���ARP���õ� */
unsigned char g_send_gateway_mac_table[64][16][18];
static int G_SND_ROUTE_INFO_NUM = 0;
@@ -260,6 +260,7 @@ int packet_io_set_capdev_serial(const char *up_dev, const char *down_dev)
return ret;
}
+#if 0
int packet_io_set_send_dev(const char *send_dev)
{
@@ -274,6 +275,7 @@ int packet_io_set_send_dev(const char *send_dev)
return ret;
}
+
int packet_io_set_gateway_mac(const char *gateway_mac)
{
if(MESA_mac_pton(gateway_mac, ':', (char *)g_send_gateway_mac) < 0){
@@ -283,6 +285,7 @@ int packet_io_set_gateway_mac(const char *gateway_mac)
return 0;
}
+#endif
int packet_io_set_capture_filter(const char *filter_rule)
{
@@ -722,15 +725,6 @@ int packet_io_init(int argc, char *argv[])
dl_io_fun_list.dl_io_register_exit_cb(packet_io_exit);
}
- if(g_send_dev_name[0] != '\0'){
- if(MESA_get_dev_mac(g_send_dev_name, g_send_dev_mac) < 0){
- printf("Warning, can't get %s mac addr!\n", g_send_dev_name);
- }
- }else{
- //printf("Warning, not assign send device!\n");
- ;
- }
-
parse_send_gdev_ip_conf("conf/send_gdev.conf");
parse_send_route_conf("conf/send_route.conf");
@@ -1004,14 +998,6 @@ static int packet_io_send_by_manual_conf(MESA_send_handle *send_handle,int datal
*/
-#if 0 /* for test, use 10.0.6.201 mac addr */
- static char mac_201_gateway[6] = {0xdc, 0xd2, 0xfc, 0x66, 0xec, 0xb2};
- static char mac_201_em2[6] = {0x74, 0x86,0x7A,0xD0,0x12,0xFD};
-
- memcpy(g_send_gateway_mac, mac_201_gateway, 6);
- memcpy(g_send_dev_mac, mac_201_em2, 6);
-
-#endif
const struct streaminfo_private *pstrem_pr = (const struct streaminfo_private *)send_handle->user_arg;
const struct streaminfo *pstream = (const struct streaminfo *)send_handle->user_arg;
const struct streaminfo *tmpstream = pstream;
@@ -1036,9 +1022,10 @@ static int packet_io_send_by_manual_conf(MESA_send_handle *send_handle,int datal
}
else
{
- p_dst_mac = g_send_gateway_mac;
+ //p_dst_mac = g_send_gateway_mac;
+ p_dst_mac = sapp_global_val->config.packet_io.inject_mode_single_gateway_dst_mac;
}
- sendpacket_build_ethernet(p_dst_mac, g_send_dev_mac, ether_type, NULL, 0, send_handle->send_buf);
+ sendpacket_build_ethernet(p_dst_mac, sapp_global_val->config.packet_io.inject_mode_single_gateway_src_mac, ether_type, NULL, 0, send_handle->send_buf);
send_again:
ret = sendto(send_handle->raw_eth_fd, send_handle->send_buf, datalen, 0,
diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c
index a31ee41..accbb23 100644
--- a/src/packet_io/sendpacket.c
+++ b/src/packet_io/sendpacket.c
@@ -58,7 +58,6 @@ static tcp_rst_finger_mark_t g_tcp_rst_finger[MAX_THREAD_NUM];
extern void *g_packet_dl_send_handle[MAX_THREAD_NUM];
extern dl_io_fun_list_t dl_io_fun_list;
-extern char g_send_dev_name[DEV_NAME_STR_LEN];
extern int g_app_send_rst_type ;
extern int calc_l2tp_hdr_len(const struct l2tp_hdr_v2 *l2tp_hdr);
extern int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_type,
@@ -3110,6 +3109,7 @@ static int send_handle_init(int tot_thread_num)
{
int i, ret;
int max_thread_num;
+ const sapp_config_packet_io_t *pcfg_io = &sapp_global_val->config.packet_io;
#if 0 /* 2018 lijia modify , ���Ӳ���������߳������������� */
for(i = 0; i < tot_thread_num; i++){
#else
@@ -3118,12 +3118,12 @@ static int send_handle_init(int tot_thread_num)
#endif
g_send_handle[i].raw_ipv4_fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
if(g_send_handle[i].raw_ipv4_fd < 0){
- printf("socket v4 error, %s\n", strerror(errno));
+ sapp_log(30, ~0, ~0, "socket v4 error, %s\n", strerror(errno));
return -1;
}
g_send_handle[i].raw_udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
if(g_send_handle[i].raw_udp_fd < 0){
- printf("socket udp error, %s\n", strerror(errno));
+ sapp_log(30, ~0, ~0, "socket udp error, %s\n", strerror(errno));
return -1;
} else
{
@@ -3134,28 +3134,29 @@ static int send_handle_init(int tot_thread_num)
listen_addr.sin_family = AF_INET;
listen_addr.sin_port = htons((unsigned short)sapp_global_val->config.packet_io.inject_mode_inline_device_sport); /* ���������ļ���дvxlanԴ�˿� */
if(bind(g_send_handle[i].raw_udp_fd, (struct sockaddr *) &listen_addr, sizeof(listen_addr)) != 0){
- printf("socket bind udp error");
+ sapp_log(30, ~0, ~0, "socket bind udp port '%u' error", sapp_global_val->config.packet_io.inject_mode_inline_device_sport);
return -1;
}
}
if(g_ipv6_send_packet_enabled){
g_send_handle[i].raw_ipv6_fd = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW);
if(g_send_handle[i].raw_ipv6_fd < 0){
- printf("socket v6 error, %s\n", strerror(errno));
- printf("Please disable IPv6 module, then try again!\n");
+ sapp_log(30, ~0, ~0, "socket v6 error, %s\n", strerror(errno));
+ sapp_log(30, ~0, ~0, "Please disable IPv6 module, then try again!\n");
return -1;
}
}
- if(g_send_dev_name[0] != '\0'){
+
+ if(pcfg_io->inject_mode_single_gateway_device[0] != '\0'){
ret = g_send_handle[i].raw_eth_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
if(g_send_handle[i].raw_eth_fd < 0){
- printf("socket raw eth error, %s\n", strerror(errno));
+ sapp_log(30, ~0, ~0, "socket raw eth error, %s\n", strerror(errno));
return -1;
}
ret = snprintf(g_send_handle[i].saddr_raw_eth.sa_data, sizeof(g_send_handle[i].saddr_raw_eth.sa_data),
- "%s", g_send_dev_name);
- if(ret >= (int)sizeof(g_send_handle[i].saddr_raw_eth.sa_data)){
- printf("send device name is too long!\n");
+ "%s", pcfg_io->inject_mode_single_gateway_device);
+ if(ret >= (int)sizeof(g_send_handle[i].saddr_raw_eth.sa_data)){
+ sapp_log(30, ~0, ~0, "send device name is too long!\n");
return -1;
}
g_send_handle[i].saddr_raw_eth.sa_family = PF_INET;