使用marsio API获取dev_endpoint的MAC address

This commit is contained in:
luwenpeng
2023-02-24 15:32:37 +08:00
parent 7dd877cea8
commit b06c0b77e1
2 changed files with 33 additions and 17 deletions

View File

@@ -29,8 +29,12 @@ rx_burst_max=128
app_symbol=sce
dev_endpoint=eth_sf_endpoint
dev_nf_interface=eth_nf_interface
default_src_ip=192.168.100.1
default_src_mac=aa:aa:aa:aa:aa:aa
dev_endpoint_src_ip=192.168.100.1
# If the configuration file does not set src mac, get src mac through marsio_get_device_ether_addr();
# If the configuration file has src mac set, use the src mac in the file
# dev_endpoint_src_mac=aa:aa:aa:aa:aa:aa
# only used for bypass_all_traffic=2
default_dst_ip=192.168.100.2
default_dst_mac=bb:bb:bb:bb:bb:bb

View File

@@ -43,9 +43,9 @@ struct config
char dev_endpoint[256];
char dev_nf_interface[256];
char default_src_ip[16];
char dev_endpoint_src_ip[16];
char dev_endpoint_src_mac[32];
char default_dst_ip[16];
char default_src_mac[32];
char default_dst_mac[32];
};
@@ -232,6 +232,12 @@ struct packet_io *packet_io_create(const char *profile, int thread_num)
goto error_out;
}
if (strlen(handle->config.dev_endpoint_src_mac) == 0)
{
marsio_get_device_ether_addr(handle->dev_endpoint.mr_dev, handle->config.dev_endpoint_src_mac, sizeof(handle->config.dev_endpoint_src_mac));
LOG_DEBUG("%s: PACKET_IO->dev_endpoint_src_mac : %s (get from marsio api)", LOG_TAG_PKTIO, handle->config.dev_endpoint_src_mac);
}
return handle;
error_out:
@@ -363,9 +369,11 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi
{
case RAW_PKT_ERR_BYPASS:
throughput_metrics_inc(&g_metrics->dev_nf_interface_err_bypass, 1, action_bytes);
throughput_metrics_inc(&g_metrics->dev_nf_interface_tx, 1, raw_len);
break;
case RAW_PKT_HIT_BYPASS:
throughput_metrics_inc(&g_metrics->hit_bypass_policy, 1, action_bytes);
throughput_metrics_inc(&g_metrics->dev_nf_interface_tx, 1, raw_len);
break;
case RAW_PKT_HIT_BLOCK:
throughput_metrics_inc(&g_metrics->hit_block_policy, 1, action_bytes);
@@ -467,9 +475,9 @@ static int packet_io_config(const char *profile, struct config *config)
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", "default_src_ip", config->default_src_ip, sizeof(config->default_src_ip));
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", "default_src_mac", config->default_src_mac, sizeof(config->default_src_mac));
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)
@@ -496,15 +504,19 @@ static int packet_io_config(const char *profile, struct config *config)
return -1;
}
LOG_DEBUG("%s: PACKET_IO->bypass_all_traffic : %d", LOG_TAG_PKTIO, config->bypass_all_traffic);
LOG_DEBUG("%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
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->default_src_ip : %s", LOG_TAG_PKTIO, config->default_src_ip);
LOG_DEBUG("%s: PACKET_IO->default_dst_ip : %s", LOG_TAG_PKTIO, config->default_dst_ip);
LOG_DEBUG("%s: PACKET_IO->default_src_mac : %s", LOG_TAG_PKTIO, config->default_src_mac);
LOG_DEBUG("%s: PACKET_IO->default_dst_mac : %s", LOG_TAG_PKTIO, config->default_dst_mac);
LOG_DEBUG("%s: PACKET_IO->bypass_all_traffic : %d", LOG_TAG_PKTIO, config->bypass_all_traffic);
LOG_DEBUG("%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
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);
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;
}
@@ -1001,8 +1013,8 @@ static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff
g_vxlan_set_sf_index(g_vxlan_hdr, sf->sf_index);
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, 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_ether_header(eth_hdr, ETH_P_IP, handle->config.dev_endpoint_src_mac, sf->sf_dst_mac);
build_ip_header(ip_hdr, IPPROTO_UDP, handle->config.dev_endpoint_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);
int raw_len = marsio_buff_datalen(rx_buff);