bfd健康检查的dst ip与g_vxlan封装报文的dst ip保持一致, 并删除debug的代码

This commit is contained in:
luwenpeng
2023-03-02 11:06:23 +08:00
parent cc397f4f08
commit 8b265517bb
6 changed files with 3 additions and 258 deletions

View File

@@ -46,8 +46,6 @@ struct config
char dev_endpoint_src_ip[16];
char dev_endpoint_src_mac[32];
char default_dst_ip[16];
char default_dst_mac[32];
};
struct device
@@ -148,12 +146,6 @@ static int mirror_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff,
// return + : send n bytes
// return -1 : error
static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, struct metadata *meta, int thread_seq, void *ct);
// return + : send n bytes
// return -1 : error bypass
static int forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff, struct selected_sf *sf, int thread_seq, void *ctx);
// return + : send n bytes
// return -1 : error drop
static int forward_all_sf_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx);
// return 0 : success
// return -1 : error
@@ -323,32 +315,6 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, rx_buffs, nr_recv);
return nr_recv;
}
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);
// return + : send n bytes
// return -1 : error bypass
int nsend = forward_all_nf_packet_to_sf(handle, rx_buff, &sf, thread_seq, ctx);
if (nsend > 0)
{
throughput_metrics_inc(&g_metrics->dev_endpoint_tx, 1, nsend);
}
else
{
throughput_metrics_inc(&g_metrics->dev_nf_interface_err_bypass, 1, raw_len);
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
}
}
return nr_recv;
}
for (int j = 0; j < nr_recv; j++)
{
@@ -425,27 +391,6 @@ int packet_io_polling_endpoint(struct packet_io *handle, int thread_seq, void *c
marsio_send_burst(handle->dev_endpoint.mr_path, thread_seq, rx_buffs, nr_recv);
return nr_recv;
}
else if (handle->config.bypass_all_traffic == 2)
{
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_endpoint_rx, 1, raw_len);
// return + : send n bytes
// return -1 : error drop
int nsend = forward_all_sf_packet_to_nf(handle, rx_buff, thread_seq, ctx);
if (nsend > 0)
{
throughput_metrics_inc(&g_metrics->dev_nf_interface_tx, 1, nsend);
}
else
{
throughput_metrics_inc(&g_metrics->dev_endpoint_err_drop, 1, raw_len);
}
}
return nr_recv;
}
for (int j = 0; j < nr_recv; j++)
{
@@ -501,9 +446,7 @@ static int packet_io_config(const char *profile, struct config *config)
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, sizeof(config->dev_endpoint_src_ip));
MESA_load_profile_string_nodef(profile, "PACKET_IO", "default_dst_ip", config->default_dst_ip, sizeof(config->default_dst_ip));
MESA_load_profile_string_nodef(profile, "PACKET_IO", "dev_endpoint_src_mac", config->dev_endpoint_src_mac, sizeof(config->dev_endpoint_src_mac));
MESA_load_profile_string_nodef(profile, "PACKET_IO", "default_dst_mac", config->default_dst_mac, sizeof(config->default_dst_mac));
if (config->rx_burst_max > RX_BURST_MAX)
{
@@ -535,14 +478,11 @@ static int packet_io_config(const char *profile, struct config *config)
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);
LOG_DEBUG("%s: PACKET_IO->default_dst_ip : %s", LOG_TAG_PKTIO, config->default_dst_ip);
if (strlen(config->dev_endpoint_src_mac))
{
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_src_mac : %s (get from configuration file)", LOG_TAG_PKTIO, config->dev_endpoint_src_mac);
}
LOG_DEBUG("%s: PACKET_IO->default_dst_mac : %s", LOG_TAG_PKTIO, config->default_dst_mac);
return 0;
}
@@ -1173,167 +1113,6 @@ static int forward_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff
return raw_len;
}
// return + : send n bytes
// return -1 : error drop
static int 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;
struct metadata meta;
struct raw_pkt_parser raw_parser;
struct addr_tuple4 inner_tuple4;
struct session_ctx *s_ctx = NULL;
struct session_node *node = NULL;
const void *payload = NULL;
// get metadata
if (packet_io_get_metadata(rx_buff, &meta) == -1)
{
LOG_ERROR("%s: unexpected raw packet, unable to get metadata, bypass !!!", LOG_TAG_PKTIO);
packet_io_dump_metadata(rx_buff, &meta);
return -1;
}
// search session id
node = session_table_search_by_id(thread->session_table, meta.session_id);
if (node)
{
goto forward;
}
// add to session table
raw_packet_parser_init(&raw_parser, meta.session_id, LAYER_TYPE_ALL, 8);
payload = raw_packet_parser_parse(&raw_parser, (const void *)meta.raw_data, meta.raw_len);
if ((char *)payload - (char *)&meta.raw_data != meta.l7_offset)
{
LOG_ERROR("%s: incorrect dataoffset in the control zone of session %lu", LOG_TAG_PKTIO, meta.session_id);
}
s_ctx = session_ctx_new();
s_ctx->ref_thread_ctx = thread;
s_ctx->session_id = meta.session_id;
s_ctx->first_ctrl_pkt.dir_is_e2i = meta.dir_is_e2i;
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_tuple4);
s_ctx->first_ctrl_pkt.addr_string = addr_tuple4_to_str(&inner_tuple4);
if (meta.dir_is_e2i)
{
sids_write_once(&(s_ctx->raw_pkt_e2i_sids), &(meta.sids));
if (!strlen(s_ctx->raw_pkt_e2i_route_ctx))
{
memcpy(s_ctx->raw_pkt_e2i_route_ctx, meta.route_ctx, sizeof(s_ctx->raw_pkt_e2i_route_ctx));
}
}
else
{
sids_write_once(&(s_ctx->raw_pkt_i2e_sids), &(meta.sids));
if (!strlen(s_ctx->raw_pkt_i2e_route_ctx))
{
memcpy(s_ctx->raw_pkt_i2e_route_ctx, meta.route_ctx, sizeof(s_ctx->raw_pkt_i2e_route_ctx));
}
}
LOG_INFO("%s: session %lu %s opening", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
// TODO only add session
__atomic_fetch_add(&g_metrics->session_nums, 1, __ATOMIC_RELAXED);
session_table_insert(thread->session_table, s_ctx->session_id, &inner_tuple4, s_ctx, session_value_free_cb);
// forward data
forward:
// rx_buff : not include g_vxlan header
// return + : send n bytes
// return -1 : error
int nsend = forward_packet_to_sf(handle, rx_buff, &meta, sf, thread_seq, ctx);
if (nsend > 0)
{
return nsend;
}
else
{
LOG_ERROR("%s: processing raw packet, session %lu %s forwarding packet to service function failed, bypass !!!", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->first_ctrl_pkt.addr_string);
return -1;
}
}
// return + : send n bytes
// return -1 : error drop
static int forward_all_sf_packet_to_nf(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx)
{
struct thread_ctx *thread = (struct thread_ctx *)ctx;
// struct global_metrics *g_metrics = thread->ref_metrics;
// vxlan decode
struct g_vxlan *g_vxlan_hdr = NULL;
int raw_len = marsio_buff_datalen(rx_buff);
char *raw_data = marsio_buff_mtod(rx_buff);
if (g_vxlan_decode(&g_vxlan_hdr, raw_data, raw_len) == -1)
{
// LOG_ERROR("%s: unexpected inject packet, not a vxlan-encapsulated packet, drop !!!", LOG_TAG_PKTIO);
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
return -1;
}
struct metadata meta;
memset(&meta, 0, sizeof(struct metadata));
meta.raw_data = (char *)g_vxlan_hdr + sizeof(struct g_vxlan);
meta.raw_len = raw_len - sizeof(struct ethhdr) - sizeof(struct ip) - sizeof(struct udp_hdr) - sizeof(struct g_vxlan);
meta.dir_is_e2i = g_vxlan_get_packet_dir(g_vxlan_hdr);
meta.traffic_is_decrypted = g_vxlan_get_traffic_type(g_vxlan_hdr);
meta.is_ctrl_pkt = 0;
meta.l7_offset = 0;
// get inner tuple4
struct addr_tuple4 inner_addr;
struct raw_pkt_parser raw_parser;
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 *)meta.raw_data, meta.raw_len);
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr);
// search session table
struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr);
if (node == NULL)
{
char *addr_string = addr_tuple4_to_str(&inner_addr);
LOG_ERROR("%s: unexpected inject packet, unable to find session %s from session table, drop !!!", LOG_TAG_PKTIO, addr_string);
free(addr_string);
marsio_buff_free(handle->instance, &rx_buff, 1, 0, thread_seq);
return -1;
}
// add meta data
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
meta.session_id = s_ctx->session_id;
if (meta.dir_is_e2i)
{
sids_copy(&meta.sids, &s_ctx->raw_pkt_e2i_sids);
memcpy(meta.route_ctx, s_ctx->raw_pkt_e2i_route_ctx, sizeof(s_ctx->raw_pkt_e2i_route_ctx));
}
else
{
sids_copy(&meta.sids, &s_ctx->raw_pkt_i2e_sids);
memcpy(meta.route_ctx, s_ctx->raw_pkt_i2e_route_ctx, sizeof(s_ctx->raw_pkt_i2e_route_ctx));
}
// rx_buff : include g_vxlan header
// return + : send n bytes
// return -1 : error
int nsend = forward_packet_to_nf(handle, rx_buff, &meta, thread_seq, ctx);
if (nsend > 0)
{
return nsend;
}
else
{
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);
return -1;
}
}
// return 0 : success
// return -1 : error
static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser *parser, int thread_seq, void *ctx)