diff options
| author | 李佳 <[email protected]> | 2020-11-04 20:46:08 +0800 |
|---|---|---|
| committer | 李佳 <[email protected]> | 2020-11-04 20:46:08 +0800 |
| commit | f51e78467a0a50b1b89bd2ab77e6f660d5357c13 (patch) | |
| tree | 762bb16981cc9fa4dc493ac3e7995b6d76e4ed12 | |
| parent | 0d0363d0747f6e06ab8e9748a6cf9efe14256c74 (diff) | |
增加在任意模式下获取最外层原始mac地址接口.v4.1.15
Conflicts:
src/config/config_parse.cpp
| -rw-r--r-- | include/public/stream_inc/stream_rawpkt.h | 6 | ||||
| -rw-r--r-- | src/dealpkt/plug_support.c | 48 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 22 |
3 files changed, 72 insertions, 4 deletions
diff --git a/include/public/stream_inc/stream_rawpkt.h b/include/public/stream_inc/stream_rawpkt.h index f0630e8..ebaf421 100644 --- a/include/public/stream_inc/stream_rawpkt.h +++ b/include/public/stream_inc/stream_rawpkt.h @@ -1,7 +1,7 @@ #ifndef _APP_STREAM_RAWPKT_H_
#define _APP_STREAM_RAWPKT_H_
-#define STREAM_RAWPKT_H_VERSION (20190817)
+#define STREAM_RAWPKT_H_VERSION (20201104)
#include "stream_base.h"
@@ -22,8 +22,10 @@ enum{ RAW_PKT_GET_VIRTUAL_LINK_ID, //value type is uint64 *, out_value should be uint64 *
RAW_PKT_GET_REHASH_INDEX, // value type is uint64 *, out_value should be uint64 *
RAW_PKT_GET_VXLAN_VPNID, // network-order, VPN_ID, value type is int, out_value should be int *
-
RAW_PKT_GET_VXLAN_LOCAL_IP, // network-order, VXLAN Local IP, value type is int, out_value should be int *
+
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC, /* value type is char[6],��ʵԭʼ��������smac��ַ,mirrorģʽ��, ��ͬ��RAW_PKT_GET_DATA, ����ʹ��stream->pfather����ƫ��; inline + vxlan + mrtunnatģʽ��, ��ͬ��RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC; */
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC, /* value type is char[6],��ʵԭʼ��������dmac��ַ,mirrorģʽ��, ��ͬ��RAW_PKT_GET_DATA, ����ʹ��stream->pfather����ƫ��; inline + vxlan + mrtunnatģʽ��, ��ͬ��RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC; */
};
#ifdef __cplusplus
diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index 34cf556..d4b62c5 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -262,6 +262,54 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value) break; #endif + /* ���ڲ����ȡ��ײ���ʵmac��ַ, ����ʲôģʽ, ��û��mrtunnat, ������һ���ӿ� */ + case RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC: + { + const struct mesa_ethernet_hdr *lowest_ehdr; + + if(DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin){ + if(CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode){ + const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)ptr_marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */ + if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */ + ret = -1; + }else{ + memcpy(void_value, mr_ctrlzone->g_device_mac, ETH_ALEN); + } + }else{ + sapp_runtime_log(RLOG_LV_FATAL, "can't support option 'RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC' in no marsio inline mode!"); + ret = -1; + } + }else{ + lowest_ehdr = (struct mesa_ethernet_hdr *)rawpkt->raw_pkt_data; + memcpy(void_value, lowest_ehdr->ether_shost, ETH_ALEN); + } + } + break; + + /* ���ڲ����ȡ��ײ���ʵmac��ַ, ����ʲôģʽ, ��û��mrtunnat, ������һ���ӿ� */ + case RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC: + { + const struct mesa_ethernet_hdr *lowest_ehdr; + + if(DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin){ + if(CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode){ + const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)ptr_marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */ + if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */ + ret = -1; + }else{ + memcpy(void_value, mr_ctrlzone->l_device_mac, ETH_ALEN); + } + }else{ + sapp_runtime_log(RLOG_LV_FATAL, "can't support option 'RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC' in no marsio inline mode!"); + ret = -1; + } + }else{ + lowest_ehdr = (struct mesa_ethernet_hdr *)rawpkt->raw_pkt_data; + memcpy(void_value, lowest_ehdr->ether_dhost, ETH_ALEN); + } + } + break; + default: ret = -1; break; diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 7a66245..6af32b2 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -2250,6 +2250,10 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch int tot_len = -1, this_layer_remain_len = -1; int ret; + if((OP_STATE_DATA != f_stream->opstate) && (OP_STATE_DATA != f_stream->pktstate)){ /* ��ͬʱ���ص�tcp,tcpall */ + return APP_STATE_GIVEME; + } + ret = get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_DATA, &raw_pkt_hdr); if(ret == 1){ raw_ipfrag_list_t *tlist = (raw_ipfrag_list_t *)raw_pkt_hdr; @@ -2269,7 +2273,7 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_GDEV_IP, &gdev_ip); inet_ntop(AF_INET, &gdev_ip, gdev_ip_str, 32); - int link_id; + int link_id = 0; get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_VXLAN_ID, &link_id); unsigned short vxlan_sport = 0; @@ -2278,7 +2282,11 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch unsigned char link_dir = 0; get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_VXLAN_LINK_DIR, &link_dir); - char gdev_mac[6], local_mac[6]; + unsigned char gdev_mac[6], local_mac[6]; + + memset(gdev_mac, 0, 6); + memset(local_mac, 0, 6); + get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC, gdev_mac); get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC, local_mac); @@ -2287,6 +2295,16 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch gdev_mac[0], gdev_mac[1], gdev_mac[2], gdev_mac[3], gdev_mac[4], gdev_mac[5], local_mac[0], local_mac[1], local_mac[2], local_mac[3], local_mac[4], local_mac[5]); + memset(gdev_mac, 0, 6); + memset(local_mac, 0, 6); + + get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC, gdev_mac); + get_rawpkt_opt_from_streaminfo(f_stream, RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC, local_mac); + printf("get vxlan opt from RAW_PKT_GET_ORIGINAL_LOWEST_ETH_, smac:%02x-%02x-%02x-%02x-%02x-%02x, dmac:%02x-%02x-%02x-%02x-%02x-%02x \n", + gdev_mac[0], gdev_mac[1], gdev_mac[2], gdev_mac[3], gdev_mac[4], gdev_mac[5], + local_mac[0], local_mac[1], local_mac[2], local_mac[3], local_mac[4], local_mac[5]); + + printf("\n-----------------------\n"); return APP_STATE_GIVEME; } |
