更新隧道跳层功能时, 需要同时更新sapp和tcpdump_mesa, 以后可能还有其他模块也引用此文件,

移除net_common.c, 使用公共库libMESA_jump_layer, 统一实现隧道跳层功能.
This commit is contained in:
lijia
2021-09-14 17:47:16 +08:00
parent da3eeea4e6
commit 45789bc03e
6 changed files with 17 additions and 1379 deletions

View File

@@ -3,6 +3,7 @@ variables:
GIT_STRATEGY: "clone" GIT_STRATEGY: "clone"
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/ BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
INSTALL_PREFIX: "/opt/MESA/" INSTALL_PREFIX: "/opt/MESA/"
INSTALL_DEPENDENCY_LIBRARY: libMESA_jump_layer
stages: stages:
- build - build

View File

@@ -71,7 +71,7 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
@rm -f $@ @rm -f $@
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c $(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
CSRC = setsignal.c tcpdump.c util.c net_common.c CSRC = setsignal.c tcpdump.c util.c
LIBNETDISSECT_SRC=\ LIBNETDISSECT_SRC=\
addrtoname.c \ addrtoname.c \

1
src/configure vendored
View File

@@ -8196,6 +8196,7 @@ if test "$missing_includes" = "yes"; then
fi fi
LIBS="-L/opt/MESA/lib -lMESA_jump_layer $LIBS"

View File

@@ -805,8 +805,8 @@ unsigned char net_layer_to_ipv6_protocol(int addr_type);
unsigned short net_layer_to_ethernet_protocol(int addr_type); unsigned short net_layer_to_ethernet_protocol(int addr_type);
int net_common_build_send_mac(unsigned char *buf, const struct mesa_ethernet_hdr *raw_eth_hdr, int addr_type, int dir_reverse, int net_topology_mode); int net_common_build_send_mac(unsigned char *buf, const struct mesa_ethernet_hdr *raw_eth_hdr, int addr_type, int dir_reverse, int net_topology_mode);
int net_common_adjust_forward_mac(struct mesa_ethernet_hdr *raw_eth_hdr,int net_topology_mode); int net_common_adjust_forward_mac(struct mesa_ethernet_hdr *raw_eth_hdr,int net_topology_mode);
const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, int expect_layer_type); const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type); const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type);
char MESA_ascii_to_hex(char ascii); char MESA_ascii_to_hex(char ascii);
#ifdef __cplusplus #ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@@ -54,7 +54,6 @@ static int greedy_seek_flag = 0; /* 偏移到最内层IP, 便于隧道模式下
static int dump_to_file_flag = 0; /* 是否有-w 参数, 原有标准的WFileName变量是main()的局部变量, 不方便使用, 使用此变量表示是否写文件 */ static int dump_to_file_flag = 0; /* 是否有-w 参数, 原有标准的WFileName变量是main()的局部变量, 不方便使用, 使用此变量表示是否写文件 */
static int has_device_flag = 0; /* 是否有-i, -r参数, 原有标准的device变量是main()的局部变量, 不方便使用, 使用此变量表示是否从某个网卡捕包 */ static int has_device_flag = 0; /* 是否有-i, -r参数, 原有标准的device变量是main()的局部变量, 不方便使用, 使用此变量表示是否从某个网卡捕包 */
static int has_bpf_filter_flag = 0; /* 是否有正确的BPF过滤条件 */ static int has_bpf_filter_flag = 0; /* 是否有正确的BPF过滤条件 */
extern int treat_vlan_as_mac_in_mac_sw;
static short pkt_classify_flag = 0; static short pkt_classify_flag = 0;
static char pkt_classify_watermark_sw = 0; static char pkt_classify_watermark_sw = 0;
int tcpdump_r_offline_mode = 0; /* 从pcap文件里读包, 而不是来源于sapp, 主要是应对有-o参数时处理模式不一样 */ int tcpdump_r_offline_mode = 0; /* 从pcap文件里读包, 而不是来源于sapp, 主要是应对有-o参数时处理模式不一样 */
@@ -533,7 +532,7 @@ show_devices_and_exit (void)
#define OPTION_IMMEDIATE_MODE 130 #define OPTION_IMMEDIATE_MODE 130
#if MESA_DUMP #if MESA_DUMP
#define OPTION_VLAN_AS_MAC_IN_MAC 131 /* 短参数不够用了, 增加长参数 */ //#define OPTION_VLAN_AS_MAC_IN_MAC 131 /* 短参数不够用了, 增加长参数 */
#define OPTION_PKT_CLASSIFY 132 /* 增加长参数包类型定义见PKT_DUMP_OPT_CLASSIFY */ #define OPTION_PKT_CLASSIFY 132 /* 增加长参数包类型定义见PKT_DUMP_OPT_CLASSIFY */
#define OPTION_PKT_CLASSIFY_WATERMARK 133 /* PKT_DUMP_OPT_CLASSIFY_WATERMARK */ #define OPTION_PKT_CLASSIFY_WATERMARK 133 /* PKT_DUMP_OPT_CLASSIFY_WATERMARK */
#endif #endif
@@ -578,7 +577,7 @@ static const struct option longopts[] = {
{ "number", no_argument, NULL, '#' }, { "number", no_argument, NULL, '#' },
{ "version", no_argument, NULL, OPTION_VERSION }, { "version", no_argument, NULL, OPTION_VERSION },
#if MESA_DUMP #if MESA_DUMP
{ "vlan-as-mac-in-mac", no_argument, NULL, OPTION_VLAN_AS_MAC_IN_MAC }, //{ "vlan-as-mac-in-mac", no_argument, NULL, OPTION_VLAN_AS_MAC_IN_MAC },
{ "classify", required_argument, NULL, OPTION_PKT_CLASSIFY }, { "classify", required_argument, NULL, OPTION_PKT_CLASSIFY },
{ "enable_classify_watermark", no_argument, NULL, OPTION_PKT_CLASSIFY_WATERMARK }, { "enable_classify_watermark", no_argument, NULL, OPTION_PKT_CLASSIFY_WATERMARK },
#endif #endif
@@ -833,7 +832,7 @@ static int MESA_dump_seek_to_inner(char *pkt_buf, int pktlen)
first_ip_layer = NULL; first_ip_layer = NULL;
} }
ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_net_jump_to_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4); ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_jump_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
if(ip4hdr_greedy){ if(ip4hdr_greedy){
if((char *)ip4hdr_greedy == first_ip_layer){ if((char *)ip4hdr_greedy == first_ip_layer){
bpf_match_pkt_len = pktlen; /* 最内层和第一层IP一样, 说明是非常标准的ethernet->IPv4包, 且无隧道, 无需memmove操作 */ bpf_match_pkt_len = pktlen; /* 最内层和第一层IP一样, 说明是非常标准的ethernet->IPv4包, 且无隧道, 无需memmove操作 */
@@ -861,7 +860,7 @@ static int MESA_dump_seek_to_inner(char *pkt_buf, int pktlen)
bpf_match_ipv4 = 0; bpf_match_ipv4 = 0;
} }
ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_net_jump_to_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6); ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_jump_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
if(ip6hdr_greedy){ if(ip6hdr_greedy){
if((char *)ip6hdr_greedy == first_ip_layer){ if((char *)ip6hdr_greedy == first_ip_layer){
bpf_match_pkt_len = pktlen; /* 最内层和第一层IP一样, 说明是非常标准的ethernet->IPv6包, 且无隧道, 无需memmove操作 */ bpf_match_pkt_len = pktlen; /* 最内层和第一层IP一样, 说明是非常标准的ethernet->IPv6包, 且无隧道, 无需memmove操作 */
@@ -1929,9 +1928,9 @@ main(int argc, char **argv)
#endif #endif
#if MESA_DUMP #if MESA_DUMP
case OPTION_VLAN_AS_MAC_IN_MAC: //case OPTION_VLAN_AS_MAC_IN_MAC:
treat_vlan_as_mac_in_mac_sw = 1; //treat_vlan_as_mac_in_mac_sw = 1;
break; //break;
case OPTION_PKT_CLASSIFY: case OPTION_PKT_CLASSIFY:
pkt_classify_flag = get_pkt_classify_optarg(optarg); pkt_classify_flag = get_pkt_classify_optarg(optarg);
if(pkt_classify_flag == 0) if(pkt_classify_flag == 0)
@@ -3092,7 +3091,7 @@ MESA_dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *raw_pk
struct mesa_ip4_hdr *ip4hdr_greedy; struct mesa_ip4_hdr *ip4hdr_greedy;
struct mesa_ip6_hdr *ip6hdr_greedy; struct mesa_ip6_hdr *ip6hdr_greedy;
const unsigned char *inner_iphdr = NULL; const unsigned char *inner_iphdr = NULL;
ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_net_jump_to_layer_greedy(raw_pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4); ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_jump_layer_greedy(raw_pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
if(ip4hdr_greedy) if(ip4hdr_greedy)
{ {
inner_iphdr = (const unsigned char *)ip4hdr_greedy; inner_iphdr = (const unsigned char *)ip4hdr_greedy;
@@ -3100,7 +3099,7 @@ MESA_dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *raw_pk
} }
else else
{ {
ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_net_jump_to_layer_greedy(raw_pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6); ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_jump_layer_greedy(raw_pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
if(ip6hdr_greedy) if(ip6hdr_greedy)
{ {
inner_iphdr = (const unsigned char *)ip6hdr_greedy; inner_iphdr = (const unsigned char *)ip6hdr_greedy;
@@ -3187,7 +3186,7 @@ MESA_dump_print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *
struct mesa_ip4_hdr *ip4hdr_greedy; struct mesa_ip4_hdr *ip4hdr_greedy;
struct mesa_ip6_hdr *ip6hdr_greedy; struct mesa_ip6_hdr *ip6hdr_greedy;
const unsigned char *inner_iphdr = NULL; const unsigned char *inner_iphdr = NULL;
ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_net_jump_to_layer_greedy(pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4); ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_jump_layer_greedy(pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
if(ip4hdr_greedy) if(ip4hdr_greedy)
{ {
inner_iphdr = (const unsigned char *)ip4hdr_greedy; inner_iphdr = (const unsigned char *)ip4hdr_greedy;
@@ -3195,7 +3194,7 @@ MESA_dump_print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *
} }
else else
{ {
ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_net_jump_to_layer_greedy(pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6); ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_jump_layer_greedy(pkt, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
if(ip6hdr_greedy) if(ip6hdr_greedy)
{ {
inner_iphdr = (const unsigned char *)ip6hdr_greedy; inner_iphdr = (const unsigned char *)ip6hdr_greedy;
@@ -3365,8 +3364,7 @@ print_usage(void)
"\t\t[ -o offset ] to assign offset from MAC, for skip some low layer data, for example: jump vxlan using -o 50, jump mac_in_mac using -o 14.\n"); "\t\t[ -o offset ] to assign offset from MAC, for skip some low layer data, for example: jump vxlan using -o 50, jump mac_in_mac using -o 14.\n");
(void)fprintf(stderr, (void)fprintf(stderr,
"\t\t[ -P port ] to assign sapp recv command port.\n"); "\t\t[ -P port ] to assign sapp recv command port.\n");
(void)fprintf(stderr, //(void)fprintf(stderr, "\t\t[ --vlan-as-mac-in-mac ] force VLAN to be analysed as MAC-IN-MAC format.\n");
"\t\t[ --vlan-as-mac-in-mac ] force VLAN to be analysed as MAC-IN-MAC format.\n");
(void)fprintf(stderr, (void)fprintf(stderr,
"\t\t[ --classify in|forward|inject|drop|error|repeat|bypass ]. specify packet capture classifier by direction and operation\n"); "\t\t[ --classify in|forward|inject|drop|error|repeat|bypass ]. specify packet capture classifier by direction and operation\n");
(void)fprintf(stderr, (void)fprintf(stderr,