This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/plugin/business/traffic-mirror/include/traffic_mirror.h
2019-06-18 09:43:49 +08:00

123 lines
3.3 KiB
C

#pragma once
#include <marsio.h>
#include <tfe_stream.h>
#include <netinet/ether.h>
#include <MESA/Maat_rule.h>
#include <pcap/pcap.h>
enum traffic_mirror_ethdev_type
{
TRAFFIC_MIRROR_ETHDEV_AF_PACKET,
TRAFFIC_MIRROR_ETHDEV_MARSIO
};
enum traffic_mirror_target_addr_type
{
TRAFFIC_MIRROR_TARGET_BY_VLAN_ID,
TRAFFIC_MIRROR_TARGET_BY_ETHER_ADDR,
};
struct traffic_mirror_instance
{
void * logger;
unsigned int nr_threads;
Maat_feather_t maat_feather;
int policy_table_id;
int profile_table_id;
/* DEFAULT MAC ADDRESS, IN VLAN MODE */
char default_ether_addr_src;
char default_ether_addr_dst;
struct traffic_mirror_ethdev * ethdev;
};
struct policy_table_ex_data
{
unsigned int atomic_refcnt;
unsigned int enable;
unsigned int profile_id;
};
struct profile_table_ex_data
{
unsigned int atomic_refcnt;
unsigned int nr_targets;
/* Target VLANS */
unsigned int * vlans;
struct ether_addr * ether_addrs;
};
struct traffic_mirror_ethdev_pcap
{
pcap_t * pcap_device_handle;
char * sendbuf[TFE_THREAD_MAX];
};
struct traffic_mirror_ethdev_mr4
{
/* DEVICE INSTANCES */
struct mr_instance * instance;
struct mr_vdev * device;
struct mr_sendpath * sendpath;
/* THREAD SENDBUF */
unsigned int nr_tx_threads;
marsio_buff_t * sendbuf[TFE_THREAD_MAX];
};
struct traffic_mirror_ethdev
{
/* PUBLIC */
char str_device[TFE_SYMBOL_MAX];
unsigned int mtu;
unsigned int en_offload_vlan;
unsigned int en_offload_ip_cksum;
unsigned int en_offload_tcp_cksum;
/* PRIVATE, FOR PCAP */
pcap_t * pcap_device_handle;
char local_ether_addr[6];
enum traffic_mirror_ethdev_type type;
union
{
struct traffic_mirror_ethdev_pcap * detail_pcap;
struct traffic_mirror_ethdev_mr4 * detail_mr4;
};
/* FUNCTIONS */
char * (*fn_send_prepare)(struct traffic_mirror_ethdev *, unsigned int tid);
int (*fn_send_finish)(struct traffic_mirror_ethdev * ethdev, unsigned int, unsigned int);
void (*fn_send_abort)(struct traffic_mirror_ethdev * ethdev, unsigned int tid);
void (*fn_destroy)(struct traffic_mirror_ethdev * ethdev);
};
struct traffic_mirror_rebuild_target
{
struct ether_addr ether_addr;
unsigned int vlan_tci;
};
struct traffic_mirror_ethdev * traffic_mirror_ethdev_pcap_create(const char * str_ethdev, void * logger);
struct traffic_mirror_ethdev * traffic_mirror_ethdev_mr4_create(const char * str_ethdev,
unsigned int nr_threads, void * logger);
void traffic_mirror_ethdev_destroy(struct traffic_mirror_ethdev * ethdev);
int traffic_mirror_ethdev_finish(struct traffic_mirror_ethdev * ethdev, unsigned int tid, unsigned int pktlen);
struct traffic_mirror_rebuild * traffic_mirror_rebuild_create(struct tfe_stream_addr * addr,
struct traffic_mirror_rebuild_target * target, struct traffic_mirror_ethdev * ethdev);
void traffic_mirror_rebuild_destroy(struct traffic_mirror_rebuild * instance);
void traffic_mirror_rebuild_handshake(struct traffic_mirror_rebuild * instance, unsigned int tid);
void traffic_mirror_rebuild_data(struct traffic_mirror_rebuild * instance, unsigned int tid, const char * data,
unsigned int datalen, enum tfe_conn_dir dir);
void traffic_mirror_rebuild_farewell(struct traffic_mirror_rebuild * instance, unsigned int tid);