|
|
|
|
@@ -131,11 +131,11 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
|
|
|
|
|
// return 0 : success
|
|
|
|
|
// return -1 : error
|
|
|
|
|
static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int chain_index, int thread_seq, void *ctx);
|
|
|
|
|
static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, int thread_seq, void *ctx);
|
|
|
|
|
// return 0 : success
|
|
|
|
|
// return -1 : error
|
|
|
|
|
static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int chain_index, int thread_seq, void *ct);
|
|
|
|
|
static void forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx);
|
|
|
|
|
static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int thread_seq, void *ct);
|
|
|
|
|
static void forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct selected_sf *sf, int thread_seq, void *ctx);
|
|
|
|
|
static void forward_all_sf_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx);
|
|
|
|
|
|
|
|
|
|
// return 0 : success
|
|
|
|
|
@@ -295,13 +295,17 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi
|
|
|
|
|
}
|
|
|
|
|
else if (handle->config.bypass_all_traffic == 2)
|
|
|
|
|
{
|
|
|
|
|
struct selected_sf sf = {0};
|
|
|
|
|
sf.sf_index = 1;
|
|
|
|
|
memcpy(sf.sf_dst_ip, handle->config.default_dst_ip, strlen(handle->config.default_dst_ip));
|
|
|
|
|
memcpy(sf.sf_dst_mac, handle->config.default_dst_mac, strlen(handle->config.default_dst_mac));
|
|
|
|
|
for (int j = 0; j < nr_recv; j++)
|
|
|
|
|
{
|
|
|
|
|
marsio_buff_t *rx_buff = rx_buffs[j];
|
|
|
|
|
int raw_len = marsio_buff_datalen(rx_buff);
|
|
|
|
|
throughput_metrics_inc(&g_metrics->dev_nf_interface_rx, 1, raw_len);
|
|
|
|
|
throughput_metrics_inc(&g_metrics->dev_endpoint_tx, 1, raw_len);
|
|
|
|
|
forward_all_nf_packet_to_sf(handle, rx_buff, thread_seq, ctx);
|
|
|
|
|
forward_all_nf_packet_to_sf(handle, rx_buff, &sf, thread_seq, ctx);
|
|
|
|
|
}
|
|
|
|
|
return nr_recv;
|
|
|
|
|
}
|
|
|
|
|
@@ -688,7 +692,7 @@ static enum raw_pkt_action handle_raw_packet(struct packet_io *handle, marsio_bu
|
|
|
|
|
return RAW_PKT_ERR_BYPASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < chaining->chaining_size; i++)
|
|
|
|
|
for (int i = 0; i < chaining->chaining_used; i++)
|
|
|
|
|
{
|
|
|
|
|
struct selected_sf *node = &(chaining->chaining[i]);
|
|
|
|
|
LOG_INFO("%s: session %lu %s execute policy: %d -> sff_profile_id %d -> sf_profile_id %d -> sf_need_skip %d sf_action_reason : %d",
|
|
|
|
|
@@ -716,7 +720,7 @@ static enum raw_pkt_action handle_raw_packet(struct packet_io *handle, marsio_bu
|
|
|
|
|
return RAW_PKT_ERR_BYPASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, i + 1, thread_seq, ctx) == 0)
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, node, thread_seq, ctx) == 0)
|
|
|
|
|
{
|
|
|
|
|
throughput_metrics_inc(&node->tx, 1, meta.raw_len);
|
|
|
|
|
return RAW_PKT_HIT_FORWARD;
|
|
|
|
|
@@ -767,7 +771,7 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
meta.l7_offset = 0;
|
|
|
|
|
// meta.session_id set later
|
|
|
|
|
// meta.sids set later
|
|
|
|
|
int chain_index = g_vxlan_get_chain_index(g_vxlan_hdr);
|
|
|
|
|
int next_sf_index = g_vxlan_get_next_sf_index(g_vxlan_hdr);
|
|
|
|
|
|
|
|
|
|
struct addr_tuple4 inner_addr;
|
|
|
|
|
struct raw_pkt_parser raw_parser;
|
|
|
|
|
@@ -800,16 +804,16 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct selected_chaining *chaining = s_ctx->chaining;
|
|
|
|
|
if (chaining == NULL || chain_index < 1 || chain_index > chaining->chaining_size)
|
|
|
|
|
if (chaining == NULL || next_sf_index < 1 || next_sf_index > chaining->chaining_used)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("%s: unexpected inject packet, session %lu %s misses chaining index, drop !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
|
|
|
|
|
return INJT_PKT_ERR_DROP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throughput_metrics_inc(&chaining->chaining[chain_index - 1].rx, 1, meta.raw_len);
|
|
|
|
|
throughput_metrics_inc(&chaining->chaining[next_sf_index - 1].rx, 1, meta.raw_len);
|
|
|
|
|
|
|
|
|
|
for (int i = chain_index; i < chaining->chaining_size; i++)
|
|
|
|
|
for (int i = next_sf_index; i < chaining->chaining_used; i++)
|
|
|
|
|
{
|
|
|
|
|
struct selected_sf *node = &(chaining->chaining[i]);
|
|
|
|
|
LOG_INFO("%s: session %lu %s execute policy: %d -> sff_profile_id %d -> sf_profile_id %d -> sf_need_skip %d sf_action_reason : %d",
|
|
|
|
|
@@ -837,7 +841,7 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
return INJT_PKT_ERR_DROP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, i + 1, thread_seq, ctx) == 0)
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, node, thread_seq, ctx) == 0)
|
|
|
|
|
{
|
|
|
|
|
throughput_metrics_inc(&node->tx, 1, meta.raw_len);
|
|
|
|
|
return INJT_PKT_HIT_FWD2SF;
|
|
|
|
|
@@ -853,14 +857,14 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chain_index != chaining->chaining_size)
|
|
|
|
|
if (next_sf_index != chaining->chaining_used)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("%s: unexpected inject packet, session %lu %s using invalid chaining index, drop !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
|
|
|
|
|
return INJT_PKT_ERR_DROP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (forward_packet_to_nf(handle, rx_buff, &meta, -1, thread_seq, ctx) == -1)
|
|
|
|
|
if (forward_packet_to_nf(handle, rx_buff, &meta, thread_seq, ctx) == -1)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("%s: processing inject packet, session %lu %s forwarding packet to network function failed, drop !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
|
|
|
|
|
@@ -874,10 +878,8 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
|
|
|
|
|
|
|
|
|
|
// return 0 : success
|
|
|
|
|
// return -1 : error
|
|
|
|
|
static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int chain_index, int thread_seq, void *ctx)
|
|
|
|
|
static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, int thread_seq, void *ctx)
|
|
|
|
|
{
|
|
|
|
|
// TODO get dst ip frome policy
|
|
|
|
|
// TODO get dst mac by dst ip
|
|
|
|
|
marsio_buff_reset(rx_buff);
|
|
|
|
|
|
|
|
|
|
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_prepend(rx_buff, sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan));
|
|
|
|
|
@@ -887,11 +889,11 @@ static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff
|
|
|
|
|
|
|
|
|
|
memset(g_vxlan_hdr, 0, sizeof(struct g_vxlan));
|
|
|
|
|
g_vxlan_set_packet_dir(g_vxlan_hdr, meta->dir_is_e2i);
|
|
|
|
|
g_vxlan_set_chain_index(g_vxlan_hdr, chain_index);
|
|
|
|
|
g_vxlan_set_next_sf_index(g_vxlan_hdr, sf->sf_index + 1);
|
|
|
|
|
g_vxlan_set_traffic_type(g_vxlan_hdr, meta->traffic_is_decrypted);
|
|
|
|
|
|
|
|
|
|
build_ether_header(eth_hdr, ETH_P_IP, handle->config.default_src_mac, handle->config.default_dst_mac);
|
|
|
|
|
build_ip_header(ip_hdr, IPPROTO_UDP, handle->config.default_src_ip, handle->config.default_dst_ip, sizeof(struct udp_hdr) + sizeof(struct g_vxlan) + meta->raw_len);
|
|
|
|
|
build_ether_header(eth_hdr, ETH_P_IP, handle->config.default_src_mac, sf->sf_dst_mac);
|
|
|
|
|
build_ip_header(ip_hdr, IPPROTO_UDP, handle->config.default_src_ip, sf->sf_dst_ip, sizeof(struct udp_hdr) + sizeof(struct g_vxlan) + meta->raw_len);
|
|
|
|
|
build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, meta->session_id % (65535 - 49152) + 49152, 4789, sizeof(struct g_vxlan) + meta->raw_len);
|
|
|
|
|
|
|
|
|
|
if (marsio_send_burst(handle->dev_endpoint.mr_path, thread_seq, &rx_buff, 1) != 0)
|
|
|
|
|
@@ -905,7 +907,7 @@ static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff
|
|
|
|
|
|
|
|
|
|
// return 0 : success
|
|
|
|
|
// return -1 : error
|
|
|
|
|
static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int chain_index, int thread_seq, void *ct)
|
|
|
|
|
static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int thread_seq, void *ct)
|
|
|
|
|
{
|
|
|
|
|
marsio_buff_adj(rx_buff, marsio_buff_datalen(rx_buff) - meta->raw_len);
|
|
|
|
|
|
|
|
|
|
@@ -924,7 +926,7 @@ static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx)
|
|
|
|
|
static void forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct selected_sf *sf, int thread_seq, void *ctx)
|
|
|
|
|
{
|
|
|
|
|
struct thread_ctx *thread = (struct thread_ctx *)ctx;
|
|
|
|
|
struct global_metrics *g_metrics = thread->ref_metrics;
|
|
|
|
|
@@ -990,7 +992,7 @@ static void forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t
|
|
|
|
|
|
|
|
|
|
// forward data
|
|
|
|
|
forward:
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, 0, thread_seq, ctx) == 0)
|
|
|
|
|
if (forward_packet_to_sf(handle, rx_buff, &meta, sf, thread_seq, ctx) == 0)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("%s: processing raw packet, session %lu %s forwarding packet to service function failed, drop !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
|
|
|
|
|
@@ -1057,7 +1059,7 @@ static void forward_all_sf_packet_to_nf(struct packet_io *handle, marsio_buff_t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sendto nf
|
|
|
|
|
if (forward_packet_to_nf(handle, rx_buff, &meta, -1, thread_seq, ctx) == -1)
|
|
|
|
|
if (forward_packet_to_nf(handle, rx_buff, &meta, thread_seq, ctx) == -1)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("%s: processing inject packet, session %lu %s forwarding packet to network function failed, drop !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
|
|
|
|
|
|