TSG-13684 tsg-service-chaining-engine使用VLAN封装Packet并执行Traffic Mirroring
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include "g_vxlan.h"
|
||||
#include "packet_io.h"
|
||||
#include "sf_metrics.h"
|
||||
#include "ctrl_packet.h"
|
||||
#include "control_packet.h"
|
||||
#include "global_metrics.h"
|
||||
|
||||
#define RX_BURST_MAX 128
|
||||
@@ -30,13 +30,20 @@ struct config
|
||||
int rx_burst_max;
|
||||
int min_timeout_ms;
|
||||
char app_symbol[256];
|
||||
char dev_endpoint[256];
|
||||
char dev_nf_interface[256];
|
||||
char dev_endpoint_src_ip_str[16];
|
||||
char dev_endpoint_src_mac_str[32];
|
||||
|
||||
in_addr_t dev_endpoint_src_ip;
|
||||
u_char dev_endpoint_src_mac[ETH_ALEN];
|
||||
// dev_nf
|
||||
char dev_nf_name[256];
|
||||
|
||||
// dev_endpoint_l3
|
||||
char dev_endpoint_l3_name[256];
|
||||
char dev_endpoint_l3_ip_str[16];
|
||||
char dev_endpoint_l3_mac_str[32];
|
||||
in_addr_t dev_endpoint_l3_ip;
|
||||
u_char dev_endpoint_l3_mac[ETH_ALEN];
|
||||
|
||||
// dev_endpoint_l2
|
||||
char dev_endpoint_l2_name[256];
|
||||
int vlan_encapsulate_replace_orig_vlan_header;
|
||||
};
|
||||
|
||||
struct device
|
||||
@@ -49,8 +56,9 @@ struct packet_io
|
||||
{
|
||||
int thread_num;
|
||||
struct mr_instance *instance;
|
||||
struct device dev_nf_interface;
|
||||
struct device dev_endpoint;
|
||||
struct device dev_nf;
|
||||
struct device dev_endpoint_l3;
|
||||
struct device dev_endpoint_l2;
|
||||
struct config config;
|
||||
};
|
||||
|
||||
@@ -337,19 +345,18 @@ static int is_uplink_keepalive_packet(marsio_buff_t *rx_buff)
|
||||
|
||||
// return !NULL
|
||||
// return NULL
|
||||
static struct session_ctx *raw_packet_search_session(struct session_table *table, const char *raw_data, int raw_len, uint64_t session_id)
|
||||
static struct session_ctx *data_packet_search_session(struct session_table *table, const char *raw_data, int raw_len, uint64_t session_id)
|
||||
{
|
||||
struct addr_tuple4 inner_addr;
|
||||
struct addr_tuple4 reverse_addr;
|
||||
struct raw_pkt_parser raw_parser;
|
||||
struct data_packet data_pkt;
|
||||
|
||||
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
||||
memset(&reverse_addr, 0, sizeof(struct addr_tuple4));
|
||||
|
||||
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
||||
raw_packet_parser_parse(&raw_parser, (const void *)raw_data, raw_len);
|
||||
data_packet_parse(&data_pkt, (const void *)raw_data, raw_len, 0);
|
||||
|
||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr);
|
||||
data_packet_get_innermost_tuple4(&data_pkt, &inner_addr);
|
||||
addr_tuple4_reverse(&inner_addr, &reverse_addr);
|
||||
|
||||
struct session_node *node = session_table_search_by_id(table, session_id);
|
||||
@@ -375,14 +382,13 @@ static struct session_ctx *raw_packet_search_session(struct session_table *table
|
||||
static struct session_ctx *inject_packet_search_session(struct session_table *table, const char *raw_data, int raw_len)
|
||||
{
|
||||
struct addr_tuple4 inner_addr;
|
||||
struct raw_pkt_parser raw_parser;
|
||||
struct data_packet data_pkt;
|
||||
|
||||
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
||||
|
||||
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
||||
raw_packet_parser_parse(&raw_parser, (const void *)raw_data, raw_len);
|
||||
data_packet_parse(&data_pkt, (const void *)raw_data, raw_len, 0);
|
||||
|
||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr);
|
||||
data_packet_get_innermost_tuple4(&data_pkt, &inner_addr);
|
||||
|
||||
struct session_node *node = session_table_search_by_addr(table, &inner_addr);
|
||||
if (node == NULL)
|
||||
@@ -400,13 +406,12 @@ static struct session_ctx *inject_packet_search_session(struct session_table *ta
|
||||
* action bypass/block/forward
|
||||
******************************************************************************/
|
||||
|
||||
static void vxlan_encapsulate(char *buffer,
|
||||
static void vxlan_encapsulate(marsio_buff_t *mbuff,
|
||||
const u_char src_mac[], const u_char dst_mac[],
|
||||
const in_addr_t src_ip, const in_addr_t dst_ip,
|
||||
int payload_len, int is_e2i, int is_decrypted, int sf_index,
|
||||
uint64_t session_id, uint16_t ipid)
|
||||
const in_addr_t src_ip, const in_addr_t dst_ip, uint16_t ipid,
|
||||
uint16_t src_port, int payload_len, int is_e2i, int is_decrypted, int sf_index)
|
||||
{
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)buffer;
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_prepend(mbuff, sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan));
|
||||
struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr));
|
||||
struct udp_hdr *udp_hdr = (struct udp_hdr *)((char *)ip_hdr + sizeof(struct ip));
|
||||
struct g_vxlan *g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udp_hdr));
|
||||
@@ -418,42 +423,121 @@ static void vxlan_encapsulate(char *buffer,
|
||||
|
||||
build_ether_header(eth_hdr, ETH_P_IP, src_mac, dst_mac);
|
||||
build_ip_header(ip_hdr, IPPROTO_UDP, ipid, src_ip, dst_ip, sizeof(struct udp_hdr) + sizeof(struct g_vxlan) + payload_len);
|
||||
build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, session_id % (65535 - 49152) + 49152, 4789, sizeof(struct g_vxlan) + payload_len);
|
||||
build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, src_port, 4789, sizeof(struct g_vxlan) + payload_len);
|
||||
}
|
||||
|
||||
static int send_packet_to_sf(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
struct vlan_hdr
|
||||
{
|
||||
uint16_t vlan_cfi;
|
||||
uint16_t protocol;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
static void build_vlan_header(struct vlan_hdr *vlan_hdr, uint16_t vlan_id, uint16_t protocol)
|
||||
{
|
||||
vlan_hdr->vlan_cfi = 0;
|
||||
vlan_hdr->vlan_cfi = htons(vlan_id & 0xFFF);
|
||||
vlan_hdr->protocol = htons(protocol);
|
||||
}
|
||||
|
||||
static void overwrite_vlan_id(struct vlan_hdr *vlan_hdr, uint16_t vlan_id)
|
||||
{
|
||||
vlan_hdr->vlan_cfi = 0;
|
||||
vlan_hdr->vlan_cfi = htons(vlan_id & 0xFFF);
|
||||
}
|
||||
|
||||
void vlan_encapsulate(marsio_buff_t *mbuff, int vlan_id, int replace_orig_vlan_header)
|
||||
{
|
||||
if (replace_orig_vlan_header == 0)
|
||||
{
|
||||
append:
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_prepend(mbuff, sizeof(struct vlan_hdr));
|
||||
struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)((char *)eth_hdr + sizeof(struct ethhdr));
|
||||
|
||||
memmove(eth_hdr, (char *)eth_hdr + sizeof(struct vlan_hdr), sizeof(struct ethhdr));
|
||||
build_vlan_header(vlan_hdr, vlan_id, ntohs(eth_hdr->h_proto));
|
||||
eth_hdr->h_proto = htons(ETH_P_8021Q);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_mtod(mbuff);
|
||||
int next_proto = eth_hdr->h_proto;
|
||||
char *start_layer = (char *)eth_hdr + sizeof(struct ethhdr);
|
||||
char *next_layer = start_layer;
|
||||
|
||||
while (next_proto == htons(ETH_P_8021Q) || next_proto == htons(ETH_P_8021AD))
|
||||
{
|
||||
struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)next_layer;
|
||||
next_proto = vlan_hdr->protocol;
|
||||
next_layer += sizeof(struct vlan_hdr);
|
||||
}
|
||||
|
||||
// No vlan header found
|
||||
uint64_t offset = next_layer - start_layer;
|
||||
if (offset == 0)
|
||||
{
|
||||
goto append;
|
||||
}
|
||||
|
||||
// Find a layer of vlan header
|
||||
if (offset == sizeof(struct vlan_hdr))
|
||||
{
|
||||
struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)start_layer;
|
||||
overwrite_vlan_id(vlan_hdr, vlan_id);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the multi-layer vlan header
|
||||
if (offset > sizeof(struct vlan_hdr))
|
||||
{
|
||||
struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(next_layer - sizeof(struct vlan_hdr));
|
||||
struct ethhdr *new_eth_hdr = (struct ethhdr *)((char *)vlan_hdr - sizeof(struct ethhdr));
|
||||
|
||||
overwrite_vlan_id(vlan_hdr, vlan_id);
|
||||
memmove(new_eth_hdr, (char *)eth_hdr, sizeof(struct ethhdr));
|
||||
new_eth_hdr->h_proto = htons(ETH_P_8021Q);
|
||||
|
||||
marsio_buff_adj(mbuff, offset - sizeof(struct vlan_hdr));
|
||||
return;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
static int send_packet_to_sf(marsio_buff_t *mbuff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
thread_ctx->tx_packets_to_sf++;
|
||||
int nsend = 0;
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int payload_len = meta->raw_len;
|
||||
int is_e2i = meta->is_e2i_dir;
|
||||
int is_decrypted = meta->is_decrypted;
|
||||
int sf_index = sf->sf_index;
|
||||
int prepend_len = 0;
|
||||
char *buffer = NULL;
|
||||
|
||||
marsio_buff_ctrlzone_reset(rx_buff);
|
||||
marsio_buff_ctrlzone_reset(mbuff);
|
||||
switch (sf->sf_connectivity.method)
|
||||
{
|
||||
case PACKAGE_METHOD_VXLAN_G:
|
||||
prepend_len = sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan);
|
||||
buffer = marsio_buff_prepend(rx_buff, prepend_len);
|
||||
vxlan_encapsulate(buffer, packet_io->config.dev_endpoint_src_mac, sf->sf_dst_mac, packet_io->config.dev_endpoint_src_ip, sf->sf_dst_ip, payload_len, is_e2i, is_decrypted, sf_index, meta->session_id, thread_ctx->tx_packets_to_sf % 65535);
|
||||
case ENCAPSULATE_METHOD_VXLAN_G:
|
||||
vxlan_encapsulate(mbuff, packet_io->config.dev_endpoint_l3_mac, sf->sf_dst_mac,
|
||||
packet_io->config.dev_endpoint_l3_ip, sf->sf_dst_ip, thread_ctx->tx_packets_to_sf % 65535,
|
||||
meta->session_id % (65535 - 49152) + 49152, meta->raw_len, meta->is_e2i_dir, meta->is_decrypted, sf->sf_index);
|
||||
nsend = marsio_buff_datalen(mbuff);
|
||||
marsio_send_burst_with_options(packet_io->dev_endpoint_l3.mr_path, thread_ctx->thread_index, &mbuff, 1, MARSIO_SEND_OPT_REHASH);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_tx), 1, nsend);
|
||||
break;
|
||||
case PACKAGE_METHOD_LAYER2_SWITCH:
|
||||
// TODO
|
||||
case ENCAPSULATE_METHOD_LAYER2_SWITCH:
|
||||
vlan_encapsulate(mbuff,
|
||||
meta->is_e2i_dir ? sf->sf_connectivity.ext_vlan_tag : sf->sf_connectivity.int_vlan_tag,
|
||||
packet_io->config.vlan_encapsulate_replace_orig_vlan_header);
|
||||
nsend = marsio_buff_datalen(mbuff);
|
||||
marsio_send_burst_with_options(packet_io->dev_endpoint_l2.mr_path, thread_ctx->thread_index, &mbuff, 1, MARSIO_SEND_OPT_REHASH);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_tx), 1, nsend);
|
||||
break;
|
||||
case PACKAGE_METHOD_LAYER3_SWITCH:
|
||||
case ENCAPSULATE_METHOD_LAYER3_SWITCH:
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int nsend = marsio_buff_datalen(rx_buff);
|
||||
marsio_send_burst_with_options(packet_io->dev_endpoint.mr_path, thread_index, &rx_buff, 1, MARSIO_SEND_OPT_REHASH);
|
||||
return nsend;
|
||||
}
|
||||
|
||||
@@ -466,7 +550,7 @@ static void action_err_bypass(marsio_buff_t *rx_buff, struct metadata *meta, str
|
||||
int nsend = action_nf_inject(rx_buff, meta, sf, thread_ctx);
|
||||
if (nsend > 0)
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.error_bypass), 1, nsend);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.error_bypass), 1, nsend);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +561,7 @@ static void action_err_block(marsio_buff_t *rx_buff, struct metadata *meta, stru
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.error_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.error_block), 1, raw_len);
|
||||
marsio_buff_free(packet_io->instance, &rx_buff, 1, 0, thread_index);
|
||||
}
|
||||
|
||||
@@ -496,7 +580,7 @@ static int action_nf_inject(marsio_buff_t *rx_buff, struct metadata *meta, struc
|
||||
}
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread_index, &rx_buff, 1);
|
||||
marsio_send_burst(packet_io->dev_nf.mr_path, thread_index, &rx_buff, 1);
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, raw_len);
|
||||
return raw_len;
|
||||
}
|
||||
@@ -506,7 +590,7 @@ static void action_mirr_bypass(marsio_buff_t *rx_buff, struct metadata *meta, st
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.mirr_bypass), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_bypass), 1, raw_len);
|
||||
}
|
||||
|
||||
static void action_mirr_block(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
@@ -514,7 +598,7 @@ static void action_mirr_block(marsio_buff_t *rx_buff, struct metadata *meta, str
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.mirr_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_block), 1, raw_len);
|
||||
}
|
||||
|
||||
static void action_mirr_forward(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
@@ -537,8 +621,7 @@ static void action_mirr_forward(marsio_buff_t *rx_buff, struct metadata *meta, s
|
||||
memcpy(copy_ptr, raw_data, raw_len);
|
||||
|
||||
int nsend = send_packet_to_sf(new_buff, meta, sf, thread_ctx);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_tx), 1, nsend);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.mirr_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&sf->tx, 1, nsend);
|
||||
sf_metrics_inc(thread_ctx->sf_metrics, sf->rule_vsys_id, sf->rule_id, sf->sff_profile_id, sf->sf_profile_id, 0, 0, 1, nsend);
|
||||
}
|
||||
@@ -548,7 +631,7 @@ static void action_stee_bypass(marsio_buff_t *rx_buff, struct metadata *meta, st
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.stee_bypass), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_bypass), 1, raw_len);
|
||||
}
|
||||
|
||||
static void action_stee_block(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
@@ -558,7 +641,7 @@ static void action_stee_block(marsio_buff_t *rx_buff, struct metadata *meta, str
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.stee_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_block), 1, raw_len);
|
||||
marsio_buff_free(packet_io->instance, &rx_buff, 1, 0, thread_index);
|
||||
}
|
||||
|
||||
@@ -568,8 +651,7 @@ static void action_stee_forward(marsio_buff_t *rx_buff, struct metadata *meta, s
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
int nsend = send_packet_to_sf(rx_buff, meta, sf, thread_ctx);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_tx), 1, nsend);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.stee_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&sf->tx, 1, nsend);
|
||||
sf_metrics_inc(thread_ctx->sf_metrics, sf->rule_vsys_id, sf->rule_id, sf->sff_profile_id, sf->sf_profile_id, 0, 0, 1, nsend);
|
||||
}
|
||||
@@ -617,7 +699,7 @@ static void action_sf_chaining(struct thread_ctx *thread_ctx, struct session_ctx
|
||||
}
|
||||
|
||||
case SESSION_ACTION_FORWARD:
|
||||
if (sf->sf_connectivity.method != PACKAGE_METHOD_VXLAN_G)
|
||||
if (sf->sf_connectivity.method != ENCAPSULATE_METHOD_VXLAN_G && sf->sf_connectivity.method != ENCAPSULATE_METHOD_LAYER2_SWITCH)
|
||||
{
|
||||
LOG_ERROR("%s: processing packets, session %lu %s requires encapsulation format not supported, bypass !!!",
|
||||
LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr);
|
||||
@@ -723,23 +805,23 @@ static int send_ctrl_packet(struct session_ctx *session_ctx, struct selected_cha
|
||||
LOG_INFO("%s: session %lu %s send event log %ld bytes", LOG_TAG_METRICS, session_ctx->session_id, session_ctx->session_addr, size);
|
||||
|
||||
marsio_buff_t *tx_buffs[1];
|
||||
char *raw_packet_header_data = session_ctx->ctrl_meta->raw_data;
|
||||
int raw_packet_header_len = session_ctx->ctrl_meta->l7offset;
|
||||
char *packet_header_data = session_ctx->ctrl_meta->raw_data;
|
||||
int packet_header_len = session_ctx->ctrl_meta->l7offset;
|
||||
marsio_buff_malloc_global(packet_io->instance, tx_buffs, 1, 0, thread_index);
|
||||
char *dst = marsio_buff_append(tx_buffs[0], raw_packet_header_len + size);
|
||||
memcpy(dst, raw_packet_header_data, raw_packet_header_len);
|
||||
memcpy(dst + raw_packet_header_len, data, size);
|
||||
char *dst = marsio_buff_append(tx_buffs[0], packet_header_len + size);
|
||||
memcpy(dst, packet_header_data, packet_header_len);
|
||||
memcpy(dst + packet_header_len, data, size);
|
||||
|
||||
struct metadata meta = {0};
|
||||
meta.session_id = session_ctx->session_id;
|
||||
meta.l7offset = raw_packet_header_len;
|
||||
meta.l7offset = packet_header_len;
|
||||
meta.is_ctrl_pkt = 1;
|
||||
meta.sids.num = 1;
|
||||
meta.sids.elems[0] = sce_ctx->firewall_sids;
|
||||
route_ctx_copy(&meta.route_ctx, &session_ctx->ctrl_meta->route_ctx);
|
||||
mbuff_set_metadata(tx_buffs[0], &meta);
|
||||
int nsend = marsio_buff_datalen(tx_buffs[0]);
|
||||
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread_index, tx_buffs, 1);
|
||||
marsio_send_burst(packet_io->dev_nf.mr_path, thread_index, tx_buffs, 1);
|
||||
free(data);
|
||||
|
||||
return nsend;
|
||||
@@ -797,28 +879,28 @@ static void session_value_free_cb(void *ctx)
|
||||
session_ctx_free(s_ctx);
|
||||
}
|
||||
|
||||
static void handle_policy_mutil_hits(struct policy_enforcer *enforcer, struct session_ctx *session_ctx, struct ctrl_pkt_parser *ctrl_parser, raw_pkt_parser *raw_parser, int is_e2i_dir)
|
||||
static void handle_policy_mutil_hits(struct policy_enforcer *enforcer, struct session_ctx *session_ctx, struct control_packet *ctrl_pkt, data_packet *data_pkt, int is_e2i_dir)
|
||||
{
|
||||
for (int i = 0; i < ctrl_parser->rule_id_num; i++)
|
||||
for (int i = 0; i < ctrl_pkt->rule_id_num; i++)
|
||||
{
|
||||
uint64_t rule_id = ctrl_parser->rule_ids[i];
|
||||
if (fixed_num_array_exist_elem(&session_ctx->rule_ids, rule_id))
|
||||
uint64_t rule_id = ctrl_pkt->rule_ids[i];
|
||||
if (mutable_array_exist_elem(&session_ctx->rule_ids, rule_id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
policy_enforce_select_chainings(enforcer, &session_ctx->chainings, session_ctx, raw_parser, rule_id, is_e2i_dir);
|
||||
policy_enforce_select_chainings(enforcer, &session_ctx->chainings, session_ctx, data_pkt, rule_id, is_e2i_dir);
|
||||
|
||||
selected_chaining_bref(session_ctx->chainings.chaining_raw);
|
||||
selected_chaining_bref(session_ctx->chainings.chaining_decrypted);
|
||||
|
||||
fixed_num_array_add_elem(&session_ctx->rule_ids, rule_id);
|
||||
mutable_array_add_elem(&session_ctx->rule_ids, rule_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser *ctrl_parser, struct thread_ctx *thread_ctx)
|
||||
static void handle_session_opening(struct metadata *meta, struct control_packet *ctrl_pkt, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
struct policy_enforcer *enforcer = thread_ctx->ref_enforcer;
|
||||
@@ -832,11 +914,10 @@ static void handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
||||
}
|
||||
#endif
|
||||
|
||||
struct raw_pkt_parser raw_parser;
|
||||
struct data_packet data_pkt;
|
||||
struct addr_tuple4 inner_tuple4;
|
||||
raw_packet_parser_init(&raw_parser, meta->session_id, LAYER_TYPE_ALL, 8);
|
||||
const void *payload = raw_packet_parser_parse(&raw_parser, (const void *)meta->raw_data, meta->raw_len);
|
||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_tuple4);
|
||||
const void *payload = data_packet_parse(&data_pkt, (const void *)meta->raw_data, meta->raw_len, meta->session_id);
|
||||
data_packet_get_innermost_tuple4(&data_pkt, &inner_tuple4);
|
||||
uint16_t real_offset = (char *)payload - meta->raw_data;
|
||||
if (real_offset != meta->l7offset)
|
||||
{
|
||||
@@ -855,14 +936,14 @@ static void handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
||||
session_ctx->ref_thread_ctx = thread_ctx;
|
||||
|
||||
LOG_INFO("%s: session %lu %s active first", LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr);
|
||||
handle_policy_mutil_hits(enforcer, session_ctx, ctrl_parser, &raw_parser, meta->is_e2i_dir);
|
||||
handle_policy_mutil_hits(enforcer, session_ctx, ctrl_pkt, &data_pkt, meta->is_e2i_dir);
|
||||
send_event_log(session_ctx, thread_ctx);
|
||||
|
||||
session_table_insert(session_table, session_ctx->session_id, &session_ctx->inner_tuple4, session_ctx, session_value_free_cb);
|
||||
ATOMIC_INC(&(thread_metrics->sf_session.num));
|
||||
}
|
||||
|
||||
static void handle_session_closing(struct metadata *meta, struct ctrl_pkt_parser *ctrl_parser, struct thread_ctx *thread_ctx)
|
||||
static void handle_session_closing(struct metadata *meta, struct control_packet *ctrl_pkt, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
@@ -884,7 +965,7 @@ static void handle_session_closing(struct metadata *meta, struct ctrl_pkt_parser
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_session_active(struct metadata *meta, struct ctrl_pkt_parser *ctrl_parser, struct thread_ctx *thread_ctx)
|
||||
static void handle_session_active(struct metadata *meta, struct control_packet *ctrl_pkt, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
struct policy_enforcer *enforcer = thread_ctx->ref_enforcer;
|
||||
@@ -894,9 +975,8 @@ static void handle_session_active(struct metadata *meta, struct ctrl_pkt_parser
|
||||
{
|
||||
struct session_ctx *session_ctx = (struct session_ctx *)node->value;
|
||||
|
||||
struct raw_pkt_parser raw_parser;
|
||||
raw_packet_parser_init(&raw_parser, meta->session_id, LAYER_TYPE_ALL, 8);
|
||||
const void *payload = raw_packet_parser_parse(&raw_parser, (const void *)meta->raw_data, meta->raw_len);
|
||||
struct data_packet data_pkt;
|
||||
const void *payload = data_packet_parse(&data_pkt, (const void *)meta->raw_data, meta->raw_len, meta->session_id);
|
||||
uint16_t real_offset = (char *)payload - meta->raw_data;
|
||||
if (real_offset != meta->l7offset)
|
||||
{
|
||||
@@ -904,16 +984,16 @@ static void handle_session_active(struct metadata *meta, struct ctrl_pkt_parser
|
||||
}
|
||||
|
||||
LOG_INFO("%s: session %lu %s active again", LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr);
|
||||
handle_policy_mutil_hits(enforcer, session_ctx, ctrl_parser, &raw_parser, meta->is_e2i_dir);
|
||||
handle_policy_mutil_hits(enforcer, session_ctx, ctrl_pkt, &data_pkt, meta->is_e2i_dir);
|
||||
send_event_log(session_ctx, thread_ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle_session_opening(meta, ctrl_parser, thread_ctx);
|
||||
handle_session_opening(meta, ctrl_pkt, thread_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_session_resetall(struct metadata *meta, struct ctrl_pkt_parser *ctrl_parser, struct thread_ctx *thread_ctx)
|
||||
static void handle_session_resetall(struct metadata *meta, struct control_packet *ctrl_pkt, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx;
|
||||
@@ -935,7 +1015,7 @@ static void handle_control_packet(marsio_buff_t *rx_buff, struct thread_ctx *thr
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
struct metadata meta;
|
||||
struct ctrl_pkt_parser ctrl_parser;
|
||||
struct control_packet ctrl_pkt;
|
||||
|
||||
if (mbuff_get_metadata(rx_buff, &meta) == -1)
|
||||
{
|
||||
@@ -943,37 +1023,36 @@ static void handle_control_packet(marsio_buff_t *rx_buff, struct thread_ctx *thr
|
||||
goto error_ctrl_pkt;
|
||||
}
|
||||
|
||||
ctrl_packet_parser_init(&ctrl_parser);
|
||||
if (ctrl_packet_parser_parse(&ctrl_parser, meta.raw_data + meta.l7offset, meta.raw_len - meta.l7offset) == -1)
|
||||
if (control_packet_parse(&ctrl_pkt, meta.raw_data + meta.l7offset, meta.raw_len - meta.l7offset) == -1)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet, unable to parse data", LOG_TAG_PKTIO);
|
||||
goto error_ctrl_pkt;
|
||||
}
|
||||
|
||||
if (ctrl_parser.session_id != meta.session_id)
|
||||
if (ctrl_pkt.session_id != meta.session_id)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet, metadata's session %lu != control packet's session %lu", LOG_TAG_PKTIO, meta.session_id, ctrl_parser.session_id);
|
||||
LOG_ERROR("%s: unexpected control packet, metadata's session %lu != control packet's session %lu", LOG_TAG_PKTIO, meta.session_id, ctrl_pkt.session_id);
|
||||
goto error_ctrl_pkt;
|
||||
}
|
||||
|
||||
switch (ctrl_parser.state)
|
||||
switch (ctrl_pkt.state)
|
||||
{
|
||||
case SESSION_STATE_OPENING:
|
||||
ATOMIC_INC(&(thread_metrics->ctrl_pkt.opening));
|
||||
// when session opening, firewall not send policy id
|
||||
// return handle_session_opening(&meta, &ctrl_parser, ctx);
|
||||
// return handle_session_opening(&meta, &ctrl_pkt, ctx);
|
||||
break;
|
||||
case SESSION_STATE_CLOSING:
|
||||
ATOMIC_INC(&(thread_metrics->ctrl_pkt.closing));
|
||||
handle_session_closing(&meta, &ctrl_parser, thread_ctx);
|
||||
handle_session_closing(&meta, &ctrl_pkt, thread_ctx);
|
||||
break;
|
||||
case SESSION_STATE_ACTIVE:
|
||||
ATOMIC_INC(&(thread_metrics->ctrl_pkt.active));
|
||||
handle_session_active(&meta, &ctrl_parser, thread_ctx);
|
||||
handle_session_active(&meta, &ctrl_pkt, thread_ctx);
|
||||
break;
|
||||
case SESSION_STATE_RESETALL:
|
||||
ATOMIC_INC(&(thread_metrics->ctrl_pkt.resetall));
|
||||
handle_session_resetall(&meta, &ctrl_parser, thread_ctx);
|
||||
handle_session_resetall(&meta, &ctrl_pkt, thread_ctx);
|
||||
break;
|
||||
default:
|
||||
goto error_ctrl_pkt;
|
||||
@@ -985,7 +1064,7 @@ error_ctrl_pkt:
|
||||
return;
|
||||
}
|
||||
|
||||
static void handle_raw_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
static void handle_data_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
@@ -1016,10 +1095,10 @@ static void handle_raw_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_
|
||||
goto error_bypass;
|
||||
}
|
||||
|
||||
session_ctx = raw_packet_search_session(session_table, meta.raw_data, meta.raw_len, meta.session_id);
|
||||
session_ctx = data_packet_search_session(session_table, meta.raw_data, meta.raw_len, meta.session_id);
|
||||
if (session_ctx == NULL)
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.miss_sess), 1, meta.raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.miss_sess), 1, meta.raw_len);
|
||||
goto error_bypass;
|
||||
}
|
||||
|
||||
@@ -1046,7 +1125,7 @@ error_bypass:
|
||||
action_err_bypass(rx_buff, &meta, NULL, thread_ctx);
|
||||
}
|
||||
|
||||
static void handle_inject_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
@@ -1062,7 +1141,7 @@ static void handle_inject_packet(marsio_buff_t *rx_buff, struct thread_ctx *thre
|
||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (g_vxlan_decode(&g_vxlan_hdr, raw_data, raw_len) == -1)
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_drop), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_drop), 1, raw_len);
|
||||
action_err_block(rx_buff, &meta, NULL, thread_ctx);
|
||||
return;
|
||||
}
|
||||
@@ -1103,14 +1182,14 @@ static void handle_inject_packet(marsio_buff_t *rx_buff, struct thread_ctx *thre
|
||||
{
|
||||
LOG_DEBUG("%s: unexpected inject packet, session %lu %s with sf_profile_id %d executes mirror and does not require reflow, drop !!!",
|
||||
LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr, chaining->chaining[sf_index].sf_profile_id);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.mirr_rx_drop), 1, meta.raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_rx_drop), 1, meta.raw_len);
|
||||
goto error_block;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct selected_sf *sf = &(chaining->chaining[sf_index]);
|
||||
throughput_metrics_inc(&sf->rx, 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->raw_pkt.stee_rx), 1, meta.raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_rx), 1, meta.raw_len);
|
||||
sf_metrics_inc(thread_ctx->sf_metrics, sf->rule_vsys_id, sf->rule_id, sf->sff_profile_id, sf->sf_profile_id, 1, raw_len, 0, 0);
|
||||
}
|
||||
|
||||
@@ -1119,7 +1198,7 @@ static void handle_inject_packet(marsio_buff_t *rx_buff, struct thread_ctx *thre
|
||||
return;
|
||||
|
||||
error_block:
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_drop), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_drop), 1, raw_len);
|
||||
marsio_buff_adj(rx_buff, raw_len - meta.raw_len);
|
||||
action_err_block(rx_buff, &meta, NULL, thread_ctx);
|
||||
}
|
||||
@@ -1140,11 +1219,15 @@ static int packet_io_config(const char *profile, struct config *config)
|
||||
MESA_load_profile_int_def(profile, "PACKET_IO", "rx_burst_max", (int *)&(config->rx_burst_max), 1);
|
||||
MESA_load_profile_int_def(profile, "PACKET_IO", "min_timeout_ms", (int *)&(config->min_timeout_ms), 900);
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "app_symbol", config->app_symbol, sizeof(config->app_symbol));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint", config->dev_endpoint, sizeof(config->dev_endpoint));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_nf_interface", config->dev_nf_interface, sizeof(config->dev_nf_interface));
|
||||
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_src_ip", config->dev_endpoint_src_ip_str, sizeof(config->dev_endpoint_src_ip_str));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_src_mac", config->dev_endpoint_src_mac_str, sizeof(config->dev_endpoint_src_mac_str));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_nf_name", config->dev_nf_name, sizeof(config->dev_nf_name));
|
||||
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_l3_name", config->dev_endpoint_l3_name, sizeof(config->dev_endpoint_l3_name));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_l3_ip", config->dev_endpoint_l3_ip_str, sizeof(config->dev_endpoint_l3_ip_str));
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_l3_mac", config->dev_endpoint_l3_mac_str, sizeof(config->dev_endpoint_l3_mac_str));
|
||||
|
||||
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_l2_name", config->dev_endpoint_l2_name, sizeof(config->dev_endpoint_l2_name));
|
||||
MESA_load_profile_int_def(profile, "PACKET_IO", "vlan_encapsulate_replace_orig_vlan_header", (int *)&(config->vlan_encapsulate_replace_orig_vlan_header), 0);
|
||||
|
||||
if (config->rx_burst_max > RX_BURST_MAX)
|
||||
{
|
||||
@@ -1158,28 +1241,37 @@ static int packet_io_config(const char *profile, struct config *config)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(config->dev_endpoint) == 0)
|
||||
if (strlen(config->dev_nf_name) == 0)
|
||||
{
|
||||
LOG_ERROR("%s: invalid dev_endpoint in %s", LOG_TAG_PKTIO, profile);
|
||||
LOG_ERROR("%s: invalid dev_nf_name in %s", LOG_TAG_PKTIO, profile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(config->dev_nf_interface) == 0)
|
||||
if (strlen(config->dev_endpoint_l3_name) == 0)
|
||||
{
|
||||
LOG_ERROR("%s: invalid dev_nf_interface in %s", LOG_TAG_PKTIO, profile);
|
||||
LOG_ERROR("%s: invalid dev_endpoint_l3_name in %s", LOG_TAG_PKTIO, profile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_DEBUG("%s: PACKET_IO->bypass_traffic : %d", LOG_TAG_PKTIO, config->bypass_traffic);
|
||||
LOG_DEBUG("%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
|
||||
LOG_DEBUG("%s: PACKET_IO->min_timeout_ms : %d", LOG_TAG_PKTIO, config->min_timeout_ms);
|
||||
LOG_DEBUG("%s: PACKET_IO->app_symbol : %s", LOG_TAG_PKTIO, config->app_symbol);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint : %s", LOG_TAG_PKTIO, config->dev_endpoint);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_nf_interface : %s", LOG_TAG_PKTIO, config->dev_nf_interface);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_src_ip : %s", LOG_TAG_PKTIO, config->dev_endpoint_src_ip_str);
|
||||
if (strlen(config->dev_endpoint_src_mac_str))
|
||||
if (strlen(config->dev_endpoint_l2_name) == 0)
|
||||
{
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_src_mac : %s (get from configuration file)", LOG_TAG_PKTIO, config->dev_endpoint_src_mac_str);
|
||||
LOG_ERROR("%s: invalid dev_endpoint_l2_name in %s", LOG_TAG_PKTIO, profile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_DEBUG("%s: PACKET_IO->bypass_traffic : %d", LOG_TAG_PKTIO, config->bypass_traffic);
|
||||
LOG_DEBUG("%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
|
||||
LOG_DEBUG("%s: PACKET_IO->min_timeout_ms : %d", LOG_TAG_PKTIO, config->min_timeout_ms);
|
||||
LOG_DEBUG("%s: PACKET_IO->app_symbol : %s", LOG_TAG_PKTIO, config->app_symbol);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_nf_name : %s", LOG_TAG_PKTIO, config->dev_nf_name);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_l3_name : %s", LOG_TAG_PKTIO, config->dev_endpoint_l3_name);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_l3_ip : %s", LOG_TAG_PKTIO, config->dev_endpoint_l3_ip_str);
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_l2_name : %s", LOG_TAG_PKTIO, config->dev_endpoint_l2_name);
|
||||
LOG_DEBUG("%s: PACKET_IO->vlan_encapsulate_replace_orig_vlan_header : %d", LOG_TAG_PKTIO, config->vlan_encapsulate_replace_orig_vlan_header);
|
||||
|
||||
if (strlen(config->dev_endpoint_l3_mac_str))
|
||||
{
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_l3_mac : %s (get from configuration file)", LOG_TAG_PKTIO, config->dev_endpoint_l3_mac_str);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1222,41 +1314,55 @@ struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
handle->dev_nf_interface.mr_dev = marsio_open_device(handle->instance, handle->config.dev_nf_interface, handle->thread_num, handle->thread_num);
|
||||
if (handle->dev_nf_interface.mr_dev == NULL)
|
||||
handle->dev_nf.mr_dev = marsio_open_device(handle->instance, handle->config.dev_nf_name, handle->thread_num, handle->thread_num);
|
||||
if (handle->dev_nf.mr_dev == NULL)
|
||||
{
|
||||
LOG_ERROR("%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
||||
LOG_ERROR("%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_nf_name);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
handle->dev_nf_interface.mr_path = marsio_sendpath_create_by_vdev(handle->dev_nf_interface.mr_dev);
|
||||
if (handle->dev_nf_interface.mr_path == NULL)
|
||||
handle->dev_nf.mr_path = marsio_sendpath_create_by_vdev(handle->dev_nf.mr_dev);
|
||||
if (handle->dev_nf.mr_path == NULL)
|
||||
{
|
||||
LOG_ERROR("%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
||||
LOG_ERROR("%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_nf_name);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
handle->dev_endpoint.mr_dev = marsio_open_device(handle->instance, handle->config.dev_endpoint, handle->thread_num, handle->thread_num);
|
||||
if (handle->dev_endpoint.mr_dev == NULL)
|
||||
handle->dev_endpoint_l3.mr_dev = marsio_open_device(handle->instance, handle->config.dev_endpoint_l3_name, handle->thread_num, handle->thread_num);
|
||||
if (handle->dev_endpoint_l3.mr_dev == NULL)
|
||||
{
|
||||
LOG_ERROR("%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint);
|
||||
LOG_ERROR("%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint_l3_name);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
handle->dev_endpoint.mr_path = marsio_sendpath_create_by_vdev(handle->dev_endpoint.mr_dev);
|
||||
if (handle->dev_endpoint.mr_path == NULL)
|
||||
handle->dev_endpoint_l3.mr_path = marsio_sendpath_create_by_vdev(handle->dev_endpoint_l3.mr_dev);
|
||||
if (handle->dev_endpoint_l3.mr_path == NULL)
|
||||
{
|
||||
LOG_ERROR("%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint);
|
||||
LOG_ERROR("%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint_l3_name);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
if (strlen(handle->config.dev_endpoint_src_mac_str) == 0)
|
||||
handle->dev_endpoint_l2.mr_dev = marsio_open_device(handle->instance, handle->config.dev_endpoint_l2_name, handle->thread_num, handle->thread_num);
|
||||
if (handle->dev_endpoint_l2.mr_dev == NULL)
|
||||
{
|
||||
marsio_get_device_ether_addr(handle->dev_endpoint.mr_dev, handle->config.dev_endpoint_src_mac_str, sizeof(handle->config.dev_endpoint_src_mac_str));
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_src_mac : %s (get from marsio api)", LOG_TAG_PKTIO, handle->config.dev_endpoint_src_mac_str);
|
||||
LOG_ERROR("%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint_l2_name);
|
||||
goto error_out;
|
||||
}
|
||||
str_to_mac(handle->config.dev_endpoint_src_mac_str, handle->config.dev_endpoint_src_mac);
|
||||
handle->config.dev_endpoint_src_ip = inet_addr(handle->config.dev_endpoint_src_ip_str);
|
||||
|
||||
handle->dev_endpoint_l2.mr_path = marsio_sendpath_create_by_vdev(handle->dev_endpoint_l2.mr_dev);
|
||||
if (handle->dev_endpoint_l2.mr_path == NULL)
|
||||
{
|
||||
LOG_ERROR("%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_endpoint_l2_name);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
if (strlen(handle->config.dev_endpoint_l3_mac_str) == 0)
|
||||
{
|
||||
marsio_get_device_ether_addr(handle->dev_endpoint_l3.mr_dev, handle->config.dev_endpoint_l3_mac_str, sizeof(handle->config.dev_endpoint_l3_mac_str));
|
||||
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_l3_mac : %s (get from marsio api)", LOG_TAG_PKTIO, handle->config.dev_endpoint_l3_mac_str);
|
||||
}
|
||||
str_to_mac(handle->config.dev_endpoint_l3_mac_str, handle->config.dev_endpoint_l3_mac);
|
||||
handle->config.dev_endpoint_l3_ip = inet_addr(handle->config.dev_endpoint_l3_ip_str);
|
||||
|
||||
return handle;
|
||||
|
||||
@@ -1269,28 +1375,40 @@ void packet_io_destory(struct packet_io *handle)
|
||||
{
|
||||
if (handle)
|
||||
{
|
||||
if (handle->dev_nf_interface.mr_path)
|
||||
if (handle->dev_nf.mr_path)
|
||||
{
|
||||
marsio_sendpath_destory(handle->dev_nf_interface.mr_path);
|
||||
handle->dev_nf_interface.mr_path = NULL;
|
||||
marsio_sendpath_destory(handle->dev_nf.mr_path);
|
||||
handle->dev_nf.mr_path = NULL;
|
||||
}
|
||||
|
||||
if (handle->dev_nf_interface.mr_dev)
|
||||
if (handle->dev_nf.mr_dev)
|
||||
{
|
||||
marsio_close_device(handle->dev_nf_interface.mr_dev);
|
||||
handle->dev_nf_interface.mr_dev = NULL;
|
||||
marsio_close_device(handle->dev_nf.mr_dev);
|
||||
handle->dev_nf.mr_dev = NULL;
|
||||
}
|
||||
|
||||
if (handle->dev_endpoint.mr_path)
|
||||
if (handle->dev_endpoint_l3.mr_path)
|
||||
{
|
||||
marsio_sendpath_destory(handle->dev_endpoint.mr_path);
|
||||
handle->dev_endpoint.mr_path = NULL;
|
||||
marsio_sendpath_destory(handle->dev_endpoint_l3.mr_path);
|
||||
handle->dev_endpoint_l3.mr_path = NULL;
|
||||
}
|
||||
|
||||
if (handle->dev_endpoint.mr_dev)
|
||||
if (handle->dev_endpoint_l3.mr_dev)
|
||||
{
|
||||
marsio_close_device(handle->dev_endpoint.mr_dev);
|
||||
handle->dev_endpoint.mr_dev = NULL;
|
||||
marsio_close_device(handle->dev_endpoint_l3.mr_dev);
|
||||
handle->dev_endpoint_l3.mr_dev = NULL;
|
||||
}
|
||||
|
||||
if (handle->dev_endpoint_l2.mr_path)
|
||||
{
|
||||
marsio_sendpath_destory(handle->dev_endpoint_l2.mr_path);
|
||||
handle->dev_endpoint_l2.mr_path = NULL;
|
||||
}
|
||||
|
||||
if (handle->dev_endpoint_l2.mr_dev)
|
||||
{
|
||||
marsio_close_device(handle->dev_endpoint_l2.mr_dev);
|
||||
handle->dev_endpoint_l2.mr_dev = NULL;
|
||||
}
|
||||
|
||||
if (handle->instance)
|
||||
@@ -1318,13 +1436,15 @@ int packet_io_thread_init(struct packet_io *handle, struct thread_ctx *thread_ct
|
||||
void packet_io_thread_wait(struct packet_io *handle, struct thread_ctx *thread_ctx, int timeout_ms)
|
||||
{
|
||||
static __thread struct mr_vdev *vdevs[] = {
|
||||
handle->dev_nf_interface.mr_dev,
|
||||
handle->dev_endpoint.mr_dev};
|
||||
handle->dev_nf.mr_dev,
|
||||
handle->dev_endpoint_l3.mr_dev,
|
||||
handle->dev_endpoint_l2.mr_dev,
|
||||
};
|
||||
|
||||
int min_timeout_ms = MIN(handle->config.min_timeout_ms, timeout_ms);
|
||||
if (min_timeout_ms > 0)
|
||||
{
|
||||
marsio_poll_wait(handle->instance, vdevs, 2, thread_ctx->thread_index, min_timeout_ms);
|
||||
marsio_poll_wait(handle->instance, vdevs, 3, thread_ctx->thread_index, min_timeout_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1338,7 +1458,7 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
static __thread marsio_buff_t *rx_buffs[RX_BURST_MAX];
|
||||
int nr_recv = marsio_recv_burst(handle->dev_nf_interface.mr_dev, thread_index, rx_buffs, handle->config.rx_burst_max);
|
||||
int nr_recv = marsio_recv_burst(handle->dev_nf.mr_dev, thread_index, rx_buffs, handle->config.rx_burst_max);
|
||||
if (nr_recv <= 0)
|
||||
{
|
||||
return 0;
|
||||
@@ -1354,7 +1474,7 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, raw_len);
|
||||
}
|
||||
|
||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_index, rx_buffs, nr_recv);
|
||||
marsio_send_burst(handle->dev_nf.mr_path, thread_index, rx_buffs, nr_recv);
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
@@ -1371,7 +1491,7 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
throughput_metrics_inc(&(thread_metrics->kee_pkt.downlink_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->kee_pkt.downlink_tx), 1, raw_len);
|
||||
|
||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_index, &rx_buff, 1);
|
||||
marsio_send_burst(handle->dev_nf.mr_path, thread_index, &rx_buff, 1);
|
||||
}
|
||||
else if (marsio_buff_is_ctrlbuf(rx_buff))
|
||||
{
|
||||
@@ -1382,26 +1502,26 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
throughput_metrics_inc(&(thread_metrics->ctrl_pkt.tx), 1, raw_len);
|
||||
|
||||
handle_control_packet(rx_buff, thread_ctx);
|
||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_index, &rx_buff, 1);
|
||||
marsio_send_burst(handle->dev_nf.mr_path, thread_index, &rx_buff, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_rx), 1, raw_len);
|
||||
|
||||
handle_raw_packet(rx_buff, thread_ctx);
|
||||
handle_data_packet(rx_buff, thread_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
int packet_io_thread_polling_endpoint(struct packet_io *handle, struct thread_ctx *thread_ctx)
|
||||
int packet_io_thread_polling_endpoint_l3(struct packet_io *handle, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
static __thread marsio_buff_t *rx_buffs[RX_BURST_MAX];
|
||||
int nr_recv = marsio_recv_burst(handle->dev_endpoint.mr_dev, thread_index, rx_buffs, handle->config.rx_burst_max);
|
||||
int nr_recv = marsio_recv_burst(handle->dev_endpoint_l3.mr_dev, thread_index, rx_buffs, handle->config.rx_burst_max);
|
||||
if (nr_recv <= 0)
|
||||
{
|
||||
return 0;
|
||||
@@ -1413,11 +1533,11 @@ int packet_io_thread_polling_endpoint(struct packet_io *handle, struct thread_ct
|
||||
{
|
||||
int raw_len = marsio_buff_datalen(rx_buffs[j]);
|
||||
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_tx), 1, raw_len);
|
||||
}
|
||||
|
||||
marsio_send_burst(handle->dev_endpoint.mr_path, thread_index, rx_buffs, nr_recv);
|
||||
marsio_send_burst(handle->dev_endpoint_l3.mr_path, thread_index, rx_buffs, nr_recv);
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
@@ -1428,7 +1548,7 @@ int packet_io_thread_polling_endpoint(struct packet_io *handle, struct thread_ct
|
||||
|
||||
if (is_uplink_keepalive_packet(rx_buff))
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->kee_pkt.uplink_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->kee_pkt.uplink_tx_drop), 1, raw_len);
|
||||
|
||||
@@ -1436,15 +1556,55 @@ int packet_io_thread_polling_endpoint(struct packet_io *handle, struct thread_ct
|
||||
}
|
||||
else
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_rx), 1, raw_len);
|
||||
|
||||
handle_inject_packet(rx_buff, thread_ctx);
|
||||
handle_inject_vxlan_packet(rx_buff, thread_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
int packet_io_thread_polling_endpoint_l2(struct packet_io *handle, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
static __thread marsio_buff_t *rx_buffs[RX_BURST_MAX];
|
||||
int nr_recv = marsio_recv_burst(handle->dev_endpoint_l2.mr_dev, thread_index, rx_buffs, handle->config.rx_burst_max);
|
||||
if (nr_recv <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (handle->config.bypass_traffic == 1)
|
||||
{
|
||||
for (int j = 0; j < nr_recv; j++)
|
||||
{
|
||||
int raw_len = marsio_buff_datalen(rx_buffs[j]);
|
||||
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_tx), 1, raw_len);
|
||||
}
|
||||
|
||||
marsio_send_burst(handle->dev_endpoint_l2.mr_path, thread_index, rx_buffs, nr_recv);
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
for (int j = 0; j < nr_recv; j++)
|
||||
{
|
||||
marsio_buff_t *rx_buff = rx_buffs[j];
|
||||
int raw_len = marsio_buff_datalen(rx_buffs[j]);
|
||||
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_drop), 1, raw_len);
|
||||
|
||||
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_index);
|
||||
}
|
||||
|
||||
return nr_recv;
|
||||
}
|
||||
|
||||
struct mr_instance *packet_io_get_mr_instance(struct packet_io *handle)
|
||||
{
|
||||
if (handle)
|
||||
|
||||
Reference in New Issue
Block a user