diff options
Diffstat (limited to 'include/MESA/stream_inc/stream_rawpkt.h')
| -rw-r--r-- | include/MESA/stream_inc/stream_rawpkt.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/include/MESA/stream_inc/stream_rawpkt.h b/include/MESA/stream_inc/stream_rawpkt.h new file mode 100644 index 0000000..df39545 --- /dev/null +++ b/include/MESA/stream_inc/stream_rawpkt.h @@ -0,0 +1,112 @@ +#ifndef _APP_STREAM_RAWPKT_H_ +#define _APP_STREAM_RAWPKT_H_ + +#define STREAM_RAWPKT_H_VERSION (20201104) + +#include "stream_base.h" + +enum{ + RAW_PKT_GET_DATA = 1, //return value is 0: out_value should be void **; return value is 1: out_value type is raw_ipfrag_list_t **; + RAW_PKT_GET_RAW_PKT_TYPE, //value type: enum addr_type_t in stream_base.h, out_value should be enum addr_type_t* + RAW_PKT_GET_TOT_LEN, //value type: int , out_value should be int * + RAW_PKT_GET_TIMESTAMP, //value type: struct timeval , out_value should be struct timeval * + RAW_PKT_GET_THIS_LAYER_HDR, //value type: void *, out_value should be void ** + RAW_PKT_GET_THIS_LAYER_REMAIN_LEN, //value type: int , out_value should be int * + RAW_PKT_GET_GDEV_IP, // network-order, value type is int, out_value should be int * + RAW_PKT_GET_VXLAN_ID, // network-order, LINK_ID, not VPN_ID, value type is int, out_value should be int * + RAW_PKT_GET_VXLAN_SPORT, // network-order, value type is short, out_value should be short * + RAW_PKT_GET_VXLAN_ENCAP_TYPE, //value type is char, + RAW_PKT_GET_VXLAN_LINK_DIR, //value type is char, + RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC, //value type is char[6], + RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC, //value type is char[6], + 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 +extern "C" { +#endif + +/* + get option from raw packet. + +for example: + CHN : ��ȡԭʼ������, (���ݲ������͵IJ�ͬ, ���ܴ�MAC��ʼ, Ҳ���ܴ�IPͷ����ʼ, ��Ҫʹ��RAW_PKT_GET_RAW_PKT_TYPE��ȡ); + ENG : get raw packet header, header's type depend on raw pacekt type, you should use RAW_PKT_GET_RAW_PKT_TYPE first; + + void *raw_pkt_data; + ret = get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_DATA, &raw_pkt_data); + if(0 == ret){ + (struct mesa_ethernet_hdr *)raw_pkt_data; + }else if(1 == ret){ + (raw_ipfrag_list_t *)raw_pkt_data; + }else{ + error! + } + + CHN : ��ȡԭʼ���ܳ���; + ENG : get raw packet size; + int tot_len; + get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TOT_LEN, &tot_len); + + CHN : ��ȡ�����ͷ��ʼ��ַ: + ENG : get this layer header; + void *this_layer_hdr; + get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_THIS_LAYER_HDR, &this_layer_hdr); + + CHN : ��ȡԭʼ��ʱ���, ���������ײ㲶���ⲻ֧��ʱ�������, ֵΪȫ0: + ENG : get raw packet timestamp, maybe zero if network card or library not support. + struct timeval pkt_stamp; + get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TIMESTAMP, &pkt_stamp); + + return value: + 1:only for RAW_PKT_GET_DATA type, value is raw_ipfrag_list_t; + 0:success; + -1:error, or not support. +*/ +int get_opt_from_rawpkt(const void *rawpkt, int type, void *out_value); + +/* + CHN: ����ͬ��, ���������ͬ. + ENG: Function ibid, except args pstream. +*/ +int get_rawpkt_opt_from_streaminfo(const struct streaminfo *pstream, int type, void *out_value); + +/* + ��ȡ��������ԭʼ���ж�Ӧ��ͷ����ַ, + ע��: �������������ΪTCP��UDP, ���ô˺�����, �õ�ԭʼ���ж�Ӧ�ij��ر��㴫����IPͷ����ַ. +*/ +const void *get_this_layer_header(const struct streaminfo *pstream); + +/* + CHN : ���ݰ�ͷ��ƫ�ƺ���. + ENG : + + ����: + raw_data: ��ǰ���ͷ��ָ��; + raw_layer_type: ��ǰ��ĵ�ַ����, ���: enum addr_type_t ; + expect_layer_type: ������ת���ĵ�ַ����, ���: enum addr_type_t ; + + ����ֵ: + NULL: �˵�ַ; + NON-NULL: ��Ӧ���ͷ����ַ. + + + ����: + ���赱ǰ��ΪEthernet, ��ʼ��ͷ��ַΪthis_layer_hdr, ����ת��IPv6��ͷ��: + struct ip6_hdr *ip6_header; + ip6_header = MESA_jump_layer(this_layer_hdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6); +*/ +const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type); + +#ifdef __cplusplus +} +#endif + +#endif + |
