From 9aa64aabb2e4f16b402bc1e91c7d5da03f9b8420 Mon Sep 17 00:00:00 2001 From: songyanchao Date: Mon, 27 Feb 2023 02:06:19 +0000 Subject: ✨ feat: Add ‘get ether addr ’ api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ‘get ether addr ’ api --- app/src/marsio.c | 283 +++++++++++++++++++++++++--------------------- app/src/version.map | 1 + include/external/marsio.h | 2 + 3 files changed, 157 insertions(+), 129 deletions(-) diff --git a/app/src/marsio.c b/app/src/marsio.c index c84ff7e..448f094 100644 --- a/app/src/marsio.c +++ b/app/src/marsio.c @@ -1,29 +1,29 @@ -#include -#include #include #include #include #include -#include -#include #include +#include +#include +#include +#include -#include -#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include +#include +#include #include +#include +#include +#include +#include -#define MR_LIB_MAX_EAL_ARGC 128 +#define MR_LIB_MAX_EAL_ARGC 128 unsigned int g_logger_to_stdout = 1; unsigned int g_logger_level = LOG_DEBUG; @@ -35,30 +35,29 @@ __thread struct mr_thread_info thread_info; struct mr_instance * _current_instance = NULL; -#define MRAPP_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.app.%s" -#define MRAPP_SERVICE_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.daemon" -#define MRAPP_GLOBAL_CONF_FILE_PATH "/opt/mrzcpd/etc/mrglobal.conf" -#define MRAPP_STATIC_NEIGH_FILE_PATH "/opt/mrzcpd/etc/mrneigh.table" +#define MRAPP_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.app.%s" +#define MRAPP_SERVICE_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.daemon" +#define MRAPP_GLOBAL_CONF_FILE_PATH "/opt/mrzcpd/etc/mrglobal.conf" +#define MRAPP_STATIC_NEIGH_FILE_PATH "/opt/mrzcpd/etc/mrneigh.table" #ifndef MRAPP_DEFAULT_NEIGH_TABLE_MAX_ENTRIES -#define MRAPP_DEFAULT_NEIGH_TABLE_MAX_ENTRIES 4096 +#define MRAPP_DEFAULT_NEIGH_TABLE_MAX_ENTRIES 4096 #endif #ifndef MRAPP_DEFAULT_NEIGH_TABLE_TIMEOUT -#define MRAPP_DEFAULT_NEIGH_TABLE_TIMEOUT 0 +#define MRAPP_DEFAULT_NEIGH_TABLE_TIMEOUT 0 #endif #ifndef MRAPP_DEFAULT_NEIGH_ARP_SEND_INTERVAL -#define MRAPP_DEFAULT_NEIGH_ARP_SEND_INTERVAL 1 +#define MRAPP_DEFAULT_NEIGH_ARP_SEND_INTERVAL 1 #endif #ifndef MRAPP_DEFAULT_NEIGH_GRATUITOUS_ARP_SEND -#define MRAPP_DEFAULT_NEIGH_GRATUITOUS_ARP_SEND 3 +#define MRAPP_DEFAULT_NEIGH_GRATUITOUS_ARP_SEND 3 #endif /* 写入Command参数 */ -static void __write_arg(char * eal_argv[], unsigned int * eal_argc, - unsigned int max_argc, const char * value) +static void __write_arg(char * eal_argv[], unsigned int * eal_argc, unsigned int max_argc, const char * value) { assert(max_argc >= *eal_argc); char * mem = (char *)malloc(MR_STRING_MAX * sizeof(char)); @@ -69,12 +68,13 @@ static void __write_arg(char * eal_argv[], unsigned int * eal_argc, return; } -#define WRITE_ARG(x) \ - do {__write_arg(eal_argv, &eal_argc, MR_LIB_MAX_EAL_ARGC, x);} \ - while(0) +#define WRITE_ARG(x) \ + do \ + { \ + __write_arg(eal_argv, &eal_argc, MR_LIB_MAX_EAL_ARGC, x); \ + } while (0) - -void __mrapp_mem_protect_unlock_mempool_cb(struct rte_mempool * mp, void *arg) +void __mrapp_mem_protect_unlock_mempool_cb(struct rte_mempool * mp, void * arg) { PROTECT_rte_mempool_unpoison(mp); MR_INFO("Unlock MEMPOOL %s: %p, local cache is %p", mp->name, mp, mp->local_cache); @@ -123,7 +123,8 @@ static void mrapp_eal_init(struct mr_instance * instance) char * eal_argv[MR_LIB_MAX_EAL_ARGC]; unsigned int eal_argc = 0; - if (g_eal_inited > 0) return; + if (g_eal_inited > 0) + return; WRITE_ARG(instance->appsym); WRITE_ARG("-c"); @@ -131,8 +132,8 @@ static void mrapp_eal_init(struct mr_instance * instance) WRITE_ARG("--proc-type=secondary"); char str_virtaddr[MR_STRING_MAX]; - int ret = MESA_load_profile_string_nodef(instance->g_cfgfile_path, "eal", - "virtaddr", str_virtaddr, sizeof(str_virtaddr)); + int ret = + MESA_load_profile_string_nodef(instance->g_cfgfile_path, "eal", "virtaddr", str_virtaddr, sizeof(str_virtaddr)); if (ret >= 0) { @@ -150,17 +151,17 @@ static void mrapp_eal_init(struct mr_instance * instance) // DPDK和SYSTEMD的日志级别差1 unsigned int loglevel = g_logger_level + 1; - MESA_load_profile_uint_def(instance->g_cfgfile_path, "eal", "loglevel", - &loglevel, loglevel); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "eal", "loglevel", &loglevel, loglevel); /* 检查日志选项,必须在1~8之间 */ if (!(loglevel >= RTE_LOG_EMERG && loglevel <= RTE_LOG_DEBUG)) { MR_CFGERR_INVALID_VALUE(instance->g_cfgfile_path, "eal", "loglevel", - "Must between LOG_DEBUG(8) and LOG_EMERG(1)"); exit(EXIT_FAILURE); + "Must between LOG_DEBUG(8) and LOG_EMERG(1)"); + exit(EXIT_FAILURE); } -#if RTE_VERSION >= RTE_VERSION_NUM(17,5,0,0) +#if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0) rte_log_set_global_level(loglevel); #else rte_set_log_level(loglevel); @@ -180,7 +181,7 @@ static void mrapp_eal_init(struct mr_instance * instance) for (int i = 0; i < eal_argc; i++) { curser_str_eal_cmdline += snprintf(str_eal_cmdline + curser_str_eal_cmdline, - sizeof(str_eal_cmdline) - curser_str_eal_cmdline, "%s ", eal_argv[i]); + sizeof(str_eal_cmdline) - curser_str_eal_cmdline, "%s ", eal_argv[i]); } MR_INFO("EAL Parameters: %s", str_eal_cmdline); @@ -206,12 +207,12 @@ static void mrapp_eal_init(struct mr_instance * instance) static int mrapp_ctrlmsg_init(struct mr_instance * instance) { - char str_ctrlmsg_addr[MR_STRING_MAX] = { 0 }; + char str_ctrlmsg_addr[MR_STRING_MAX] = {0}; unsigned int ctrlmsg_port = 0; /* 读控制面监听线程的监听地址、端口号 */ - //MESA_load_profile_string_def(instance->g_cfgfile_path, "ctrlmsg", "listen_addr", - // str_ctrlmsg_addr, sizeof(str_ctrlmsg_addr), CTRLMSG_DEFAULT_ADDR); + // MESA_load_profile_string_def(instance->g_cfgfile_path, "ctrlmsg", "listen_addr", + // str_ctrlmsg_addr, sizeof(str_ctrlmsg_addr), CTRLMSG_DEFAULT_ADDR); const char * env_ctrlmsg_addr = getenv("MRZCPD_CTRLMSG_LISTEN_ADDR"); if (env_ctrlmsg_addr != NULL) @@ -225,15 +226,15 @@ static int mrapp_ctrlmsg_init(struct mr_instance * instance) strncpy(str_ctrlmsg_addr, "127.0.0.1", sizeof(str_ctrlmsg_addr)); } - MESA_load_profile_uint_def(instance->g_cfgfile_path, "ctrlmsg", "listen_port", - &ctrlmsg_port, CTRLMSG_DEFAULT_PORT); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "ctrlmsg", "listen_port", &ctrlmsg_port, CTRLMSG_DEFAULT_PORT); /* 地址转换 */ struct sockaddr_in sockaddr_in; if (inet_pton(AF_INET, str_ctrlmsg_addr, &sockaddr_in.sin_addr) <= 0) { - //MR_CFGERR_INVALID_FORMAT(instance->g_cfgfile_path, "ctrlmsg", "listen_addr"); - MR_ERROR("Mrapp ctrlmsg init error,The environment variable 'MRZCPD_CTRLMSG_LISTEN_ADDR=%s' is invalid.",str_ctrlmsg_addr); + // MR_CFGERR_INVALID_FORMAT(instance->g_cfgfile_path, "ctrlmsg", "listen_addr"); + MR_ERROR("Mrapp ctrlmsg init error,The environment variable 'MRZCPD_CTRLMSG_LISTEN_ADDR=%s' is invalid.", + str_ctrlmsg_addr); return RT_ERR; } @@ -243,7 +244,8 @@ static int mrapp_ctrlmsg_init(struct mr_instance * instance) /* 创建消息处理框架句柄 */ instance->ctrlmsg_handler = ctrlmsg_handler_create(CTRLMSG_HANDLER_MODE_CLIENT, sockaddr_in, NULL, -1); - if (instance->ctrlmsg_handler == NULL) return RT_ERR; + if (instance->ctrlmsg_handler == NULL) + return RT_ERR; return RT_SUCCESS; } @@ -252,10 +254,8 @@ static int mrapp_distributer_init(struct mr_instance * instance) unsigned int distmode = LDBC_DIST_OUTER_TUPLE2; unsigned int hashmode = LDBC_HASH_SYM_CRC; - MESA_load_profile_uint_def(instance->g_cfgfile_path, "service", "distmode", - &distmode, LDBC_DIST_OUTER_TUPLE2); - MESA_load_profile_uint_def(instance->g_cfgfile_path, "service", "hashmode", - &hashmode, LDBC_HASH_SYM_CRC); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "service", "distmode", &distmode, LDBC_DIST_OUTER_TUPLE2); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "service", "hashmode", &hashmode, LDBC_HASH_SYM_CRC); if (distmode < 0 || distmode >= LDBC_DIST_MAX) { @@ -279,7 +279,7 @@ static int mrapp_distributer_init(struct mr_instance * instance) return RT_SUCCESS; } -static unsigned __table_strip(char *str, unsigned len) +static unsigned __table_strip(char * str, unsigned len) { int newlen = len; if (len == 0) @@ -297,8 +297,7 @@ static unsigned __table_strip(char *str, unsigned len) /* strip leading whitespace */ int i, start = 1; while (isspace(str[start]) && start < newlen) - start++ - ; /* do nothing */ + start++; /* do nothing */ newlen -= start; for (i = 0; i < newlen; i++) str[i] = str[i + start]; @@ -308,12 +307,12 @@ static unsigned __table_strip(char *str, unsigned len) return newlen; } -static const char * __table_readline(FILE * fp, char * buffer, - size_t sz_buffer, size_t * buffer_len, unsigned int * line_no) +static const char * __table_readline(FILE * fp, char * buffer, size_t sz_buffer, size_t * buffer_len, + unsigned int * line_no) { while (fgets(buffer, sz_buffer, fp) != NULL) { - char *pos = NULL; + char * pos = NULL; size_t len = strnlen(buffer, sz_buffer); (*line_no)++; @@ -351,8 +350,10 @@ static int __table_split_line(const char * buffer, char str_tokens[MR_TOKENS_MAX while ((token_ptr = strsep(&__buffer, " \t")) != NULL) { - if (strlen(token_ptr) == 0) continue; - if (total_nr_tokens == MR_TOKENS_MAX) break; + if (strlen(token_ptr) == 0) + continue; + if (total_nr_tokens == MR_TOKENS_MAX) + break; strncpy(str_tokens[total_nr_tokens], token_ptr, MR_STRING_MAX); @@ -381,18 +382,18 @@ static int mrapp_neigh_init(struct mr_instance * instance) */ TAILQ_INIT(&instance->static_neigh_list); - MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "neigh_table_max_entries", - &neigh_max_entries, MRAPP_DEFAULT_NEIGH_TABLE_MAX_ENTRIES); - MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "neigh_table_timeout", - &neigh_timeout, MRAPP_DEFAULT_NEIGH_TABLE_TIMEOUT); - MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "arp_send_interval", - &arp_send_interval, MRAPP_DEFAULT_NEIGH_ARP_SEND_INTERVAL); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "neigh_table_max_entries", &neigh_max_entries, + MRAPP_DEFAULT_NEIGH_TABLE_MAX_ENTRIES); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "neigh_table_timeout", &neigh_timeout, + MRAPP_DEFAULT_NEIGH_TABLE_TIMEOUT); + MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "arp_send_interval", &arp_send_interval, + MRAPP_DEFAULT_NEIGH_ARP_SEND_INTERVAL); MESA_load_profile_uint_def(instance->g_cfgfile_path, "neigh", "gratuitous_arp_send", - &instance->nr_gratuitous_arp_send, MRAPP_DEFAULT_NEIGH_GRATUITOUS_ARP_SEND); + &instance->nr_gratuitous_arp_send, MRAPP_DEFAULT_NEIGH_GRATUITOUS_ARP_SEND); /* 邻居子系统初始化 */ - if (neighbour_mamanger_init(instance->neigh, instance->appsym, - neigh_max_entries, neigh_timeout, arp_send_interval) != RT_SUCCESS) + if (neighbour_mamanger_init(instance->neigh, instance->appsym, neigh_max_entries, neigh_timeout, + arp_send_interval) != RT_SUCCESS) { goto err; } @@ -401,8 +402,8 @@ static int mrapp_neigh_init(struct mr_instance * instance) FILE * fp_static_neigh_table = fopen(MRAPP_STATIC_NEIGH_FILE_PATH, "r"); if (fp_static_neigh_table == NULL) { - MR_DEBUG("Skip reading static neighbour table from file %s.", - MRAPP_STATIC_NEIGH_FILE_PATH); goto success; + MR_DEBUG("Skip reading static neighbour table from file %s.", MRAPP_STATIC_NEIGH_FILE_PATH); + goto success; } /* 按行读 */ @@ -410,8 +411,8 @@ static int mrapp_neigh_init(struct mr_instance * instance) size_t __tb_buffer_len = 0; unsigned int __tb_line_no = 0; - while (__table_readline(fp_static_neigh_table, - __tb_line_buffer, sizeof(__tb_line_buffer), &__tb_buffer_len, &__tb_line_no) != NULL) + while (__table_readline(fp_static_neigh_table, __tb_line_buffer, sizeof(__tb_line_buffer), &__tb_buffer_len, + &__tb_line_no) != NULL) { /* 拆分,第一列为IP地址,第二列为MAC地址 */ char __split_str[MR_TOKENS_MAX][MR_STRING_MAX]; @@ -421,7 +422,8 @@ static int mrapp_neigh_init(struct mr_instance * instance) if (nr_tokens != 3) { MR_WARNING("Table: %s, line: %u: Invalid line format, must have 3 column, ignore.", - MRAPP_STATIC_NEIGH_FILE_PATH, __tb_line_no); continue; + MRAPP_STATIC_NEIGH_FILE_PATH, __tb_line_no); + continue; } /* 读IP地址、MAC地址 */ @@ -436,19 +438,20 @@ static int mrapp_neigh_init(struct mr_instance * instance) int ret = inet_pton(AF_INET, str_in_addr, &in_addr); if (ret < 0) { - MR_WARNING("Table: %s, line: %u: Invaild IP address format, ignore. ", - MRAPP_STATIC_NEIGH_FILE_PATH, __tb_line_no); continue; + MR_WARNING("Table: %s, line: %u: Invaild IP address format, ignore. ", MRAPP_STATIC_NEIGH_FILE_PATH, + __tb_line_no); + continue; } - ret = sscanf(str_ether_addr, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - ðer_addr.addr_bytes[0], ðer_addr.addr_bytes[1], - ðer_addr.addr_bytes[2], ðer_addr.addr_bytes[3], - ðer_addr.addr_bytes[4], ðer_addr.addr_bytes[5]); + ret = sscanf(str_ether_addr, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", ðer_addr.addr_bytes[0], + ðer_addr.addr_bytes[1], ðer_addr.addr_bytes[2], ðer_addr.addr_bytes[3], + ðer_addr.addr_bytes[4], ðer_addr.addr_bytes[5]); if (ret != 6) { - MR_WARNING("Table: %s, line: %u: Invaild MAC address format, ignore. ", - MRAPP_STATIC_NEIGH_FILE_PATH, __tb_line_no); continue; + MR_WARNING("Table: %s, line: %u: Invaild MAC address format, ignore. ", MRAPP_STATIC_NEIGH_FILE_PATH, + __tb_line_no); + continue; } /* 检查重复的表项 */ @@ -457,16 +460,19 @@ static int mrapp_neigh_init(struct mr_instance * instance) TAILQ_FOREACH(__neigh_entry_iter, &instance->static_neigh_list, next) { - if (__neigh_entry_iter->in_addr.s_addr != in_addr.s_addr) continue; + if (__neigh_entry_iter->in_addr.s_addr != in_addr.s_addr) + continue; /* 重复表项,告警 */ - MR_WARNING("table: %s, line: %u: Duplicate entry, %s->%s, ignore.", - MRAPP_STATIC_NEIGH_FILE_PATH, __tb_line_no, str_in_addr, str_ether_addr); - is_dup_entry = 1; break; + MR_WARNING("table: %s, line: %u: Duplicate entry, %s->%s, ignore.", MRAPP_STATIC_NEIGH_FILE_PATH, + __tb_line_no, str_in_addr, str_ether_addr); + is_dup_entry = 1; + break; } /* 重复表项跳过 */ - if (is_dup_entry) continue; + if (is_dup_entry) + continue; /* 插入临时的静态邻居表 */ struct mr_static_neigh_entry * __neigh_entry = malloc(sizeof(struct mr_static_neigh_entry)); @@ -502,10 +508,7 @@ static int mrapp_app_register(struct mr_instance * instance) struct ctrl_msg_app_reg_request reg_cmd; memset(®_cmd, 0, sizeof(reg_cmd)); - ctrl_msg_header_construct(®_cmd.msg_header, - sizeof(reg_cmd), - CTRL_MSG_TYPE_REQUEST, - CTRLMSG_TOPIC_APP_REGISTER); + ctrl_msg_header_construct(®_cmd.msg_header, sizeof(reg_cmd), CTRL_MSG_TYPE_REQUEST, CTRLMSG_TOPIC_APP_REGISTER); /* 应用标识符 */ strncpy((char *)reg_cmd.symbol, instance->appsym, sizeof(reg_cmd.symbol)); @@ -532,18 +535,19 @@ static int mrapp_app_register(struct mr_instance * instance) static int mrapp_gconf_init(struct mr_instance * instance) { /* 读JSON文件 */ - FILE *f = fopen(MRAPP_SERVICE_MONIT_FILE_PATH, "rb"); + FILE * f = fopen(MRAPP_SERVICE_MONIT_FILE_PATH, "rb"); if (f == NULL) { MR_ERROR("Cannot open mrzcpd monit file %s, perhaps mrzcpd program is not running : %s", - MRAPP_SERVICE_MONIT_FILE_PATH, strerror(errno)); return RT_ERR; + MRAPP_SERVICE_MONIT_FILE_PATH, strerror(errno)); + return RT_ERR; } fseek(f, 0, SEEK_END); long fsize = ftell(f); - fseek(f, 0, SEEK_SET); //same as rewind(f); + fseek(f, 0, SEEK_SET); // same as rewind(f); - char *string = malloc(fsize + 1); + char * string = malloc(fsize + 1); MR_VERIFY_MALLOC(string); /* 读文件 */ @@ -553,23 +557,26 @@ static int mrapp_gconf_init(struct mr_instance * instance) string[fsize] = 0; cJSON * j_global_monit = cJSON_Parse(string); - if (j_global_monit == NULL) goto j_parse_error; + if (j_global_monit == NULL) + goto j_parse_error; cJSON * j_genernal = cJSON_GetObjectItem(j_global_monit, "general"); - if (j_genernal == NULL) goto j_parse_error; + if (j_genernal == NULL) + goto j_parse_error; char * g_cfg_file = cJSON_GetObjectItem(j_genernal, "g_cfgfile")->valuestring; - if (g_cfg_file == NULL) goto j_parse_error; + if (g_cfg_file == NULL) + goto j_parse_error; /* 全局配置文件路径 */ strncpy(instance->g_cfgfile_path, g_cfg_file, sizeof(instance->g_cfgfile_path)); /* 本地配置文件路径 */ - char __str_cfgfile[MR_STRING_MAX] = { 0 }; + char __str_cfgfile[MR_STRING_MAX] = {0}; strncpy(__str_cfgfile, instance->g_cfgfile_path, sizeof(__str_cfgfile)); - snprintf(instance->app_cfgfile_path, sizeof(instance->app_cfgfile_path), - "%s/mrapp.%s.conf", dirname(__str_cfgfile), instance->appsym); + snprintf(instance->app_cfgfile_path, sizeof(instance->app_cfgfile_path), "%s/mrapp.%s.conf", dirname(__str_cfgfile), + instance->appsym); return RT_SUCCESS; @@ -596,15 +603,15 @@ struct mr_vdev * marsio_device_lookup(struct mr_instance * instance, const char { for (int i = 0; i < instance->nr_vdevs; i++) { - if (strncmp(devsym, instance->vdevs[i].devsym, - sizeof(instance->vdevs[i].devsym)) == 0) return &instance->vdevs[i]; + if (strncmp(devsym, instance->vdevs[i].devsym, sizeof(instance->vdevs[i].devsym)) == 0) + return &instance->vdevs[i]; } return NULL; } -static int __ctrlplane_conn_close_handler(struct ctrlmsg_handler * ct_hand, - struct ctrlmsg_conn * ct_conn, struct ctrl_msg_header * msg, void * arg) +static int __ctrlplane_conn_close_handler(struct ctrlmsg_handler * ct_hand, struct ctrlmsg_conn * ct_conn, + struct ctrl_msg_header * msg, void * arg) { MR_INFO("Ctrlplane connection is terminated, Exit. "); exit(EXIT_FAILURE); @@ -621,8 +628,8 @@ static void __open_device_unposion(struct vdev_instance * vdi) vnode_mirror_unpoison_prod(vdi->vnode_ltx_prod); } -static int __open_device_response_handler(struct ctrlmsg_handler * ct_hand, - struct ctrlmsg_conn * ct_conn, struct ctrl_msg_header * msg, void * arg) +static int __open_device_response_handler(struct ctrlmsg_handler * ct_hand, struct ctrlmsg_conn * ct_conn, + struct ctrl_msg_header * msg, void * arg) { struct ctrl_msg_vdev_open_response * rep_msg = (struct ctrl_msg_vdev_open_response *)msg; struct mr_instance * instance = (struct mr_instance *)arg; @@ -644,7 +651,7 @@ static int __open_device_response_handler(struct ctrlmsg_handler * ct_hand, strncpy(mr_vdev->devsym, (char *)rep_msg->devsym, MR_SYMBOL_MAX); /* VDI使用了大页面共享内存,在保护模式下撤除对它的保护 */ - if(instance->memory_protect_with_asan) + if (instance->memory_protect_with_asan) { __open_device_unposion(mr_vdev->vdi); } @@ -659,8 +666,8 @@ wake_up: return 0; } -static int __app_register_response_handler(struct ctrlmsg_handler * ct_hand, - struct ctrlmsg_conn * ct_conn, struct ctrl_msg_header * msg, void * arg) +static int __app_register_response_handler(struct ctrlmsg_handler * ct_hand, struct ctrlmsg_conn * ct_conn, + struct ctrl_msg_header * msg, void * arg) { struct ctrl_msg_app_reg_response * rep_msg = (struct ctrl_msg_app_reg_response *)msg; struct mr_instance * instance = (struct mr_instance *)arg; @@ -680,8 +687,8 @@ static int __app_register_response_handler(struct ctrlmsg_handler * ct_hand, return 0; } -struct mr_vdev * marsio_open_device(struct mr_instance * instance, - const char * devsym, unsigned int nr_rxstream, unsigned int nr_txstream) +struct mr_vdev * marsio_open_device(struct mr_instance * instance, const char * devsym, unsigned int nr_rxstream, + unsigned int nr_txstream) { /* 构造虚设备打开请求 */ struct ctrl_msg_vdev_open_request req_msg; @@ -730,20 +737,32 @@ void marsio_close_device(struct mr_vdev * vdev) return; } +void marsio_get_device_ether_addr(struct mr_vdev * vdev, void * str_ether_addr, uint8_t size) +{ + rte_ether_format_addr(str_ether_addr, size, &vdev->vdi->vdev->ether_addr); + return; +} + static void mask_to_cpuset(uint64_t mask, cpu_set_t * cpusetp) { for (unsigned long bit_iter = 0; bit_iter < sizeof(mask) * 8; bit_iter++) { - if ((mask & (1ULL << bit_iter))) CPU_SET(bit_iter, cpusetp); + if ((mask & (1ULL << bit_iter))) + CPU_SET(bit_iter, cpusetp); } } int marsio_option_set(struct mr_instance * instance, marsio_opt_type_t opt_type, void * opt, size_t sz_opt) { -#define __CHECK_USER_PARAM(expect_type) do { \ - if(sz_opt < sizeof(expect_type)) { return -EINVAL; } \ -} while(0) +#define __CHECK_USER_PARAM(expect_type) \ + do \ + { \ + if (sz_opt < sizeof(expect_type)) \ + { \ + return -EINVAL; \ + } \ + } while (0) int ret = 0; @@ -752,23 +771,27 @@ int marsio_option_set(struct mr_instance * instance, marsio_opt_type_t opt_type, case MARSIO_OPT_THREAD_NUM: __CHECK_USER_PARAM(unsigned int); instance->nr_dataplane_thread = *(unsigned int *)opt; - ret = 0; break; + ret = 0; + break; case MARSIO_OPT_THREAD_MASK: __CHECK_USER_PARAM(uint64_t); uint64_t mask = *(uint64_t *)opt; mask_to_cpuset(mask, &instance->cpu_set); - ret = 0; break; + ret = 0; + break; case MARSIO_OPT_THREAD_MASK_IN_CPUSET: __CHECK_USER_PARAM(cpu_set_t); instance->cpu_set = *(cpu_set_t *)opt; - ret = 0; break; + ret = 0; + break; case MARSIO_OPT_EXIT_WHEN_ERR: __CHECK_USER_PARAM(unsigned int); instance->is_exit_when_err_raise = *(unsigned int *)opt; - ret = 0; break; + ret = 0; + break; default: ret = -EINVAL; @@ -805,8 +828,7 @@ int marsio_init(struct mr_instance * instance, const char * appsym) snprintf(instance->appsym, sizeof(instance->appsym), "%s", appsym); /* 状态监测路径 */ - snprintf(instance->monit_file_path, sizeof(instance->monit_file_path), - MRAPP_MONIT_FILE_PATH, instance->appsym); + snprintf(instance->monit_file_path, sizeof(instance->monit_file_path), MRAPP_MONIT_FILE_PATH, instance->appsym); pthread_mutex_init(&instance->lock_ctrlmsg_wait, NULL); pthread_cond_init(&instance->cond_ctrlmsg_wait, NULL); @@ -837,16 +859,15 @@ int marsio_init(struct mr_instance * instance, const char * appsym) mrapp_eal_init(instance); /* 注册处理应用注册结果的回调函数 */ - ctrlmsg_msg_reciver_register(instance->ctrlmsg_handler, CTRLMSG_TOPIC_APP_REGISTER, - CTRL_MSG_TYPE_RESPONSE, __app_register_response_handler, instance); + ctrlmsg_msg_reciver_register(instance->ctrlmsg_handler, CTRLMSG_TOPIC_APP_REGISTER, CTRL_MSG_TYPE_RESPONSE, + __app_register_response_handler, instance); /* 注册设备打开的回调函数 */ - ctrlmsg_msg_reciver_register(instance->ctrlmsg_handler, CTRLMSG_TOPIC_VDEV_OPEN, - CTRL_MSG_TYPE_RESPONSE, __open_device_response_handler, instance); + ctrlmsg_msg_reciver_register(instance->ctrlmsg_handler, CTRLMSG_TOPIC_VDEV_OPEN, CTRL_MSG_TYPE_RESPONSE, + __open_device_response_handler, instance); /* 控制链接中断处理函数 */ - ctrlmsg_event_conn_close_register(instance->ctrlmsg_handler, - __ctrlplane_conn_close_handler, instance); + ctrlmsg_event_conn_close_register(instance->ctrlmsg_handler, __ctrlplane_conn_close_handler, instance); if (ctrlmsg_thread_launch(instance->ctrlmsg_handler) != RT_SUCCESS) { @@ -892,7 +913,8 @@ int marsio_init(struct mr_instance * instance, const char * appsym) return RT_SUCCESS; err: - if (instance->is_exit_when_err_raise) exit(EXIT_FAILURE); + if (instance->is_exit_when_err_raise) + exit(EXIT_FAILURE); return RT_ERR; } @@ -918,7 +940,8 @@ int marsio_thread_init(struct mr_instance * instance) if (cpu_id < 0) { MR_ERROR("Too many threads call thread init, supposed tid is %d", instance->to_suppose_tid); - ret = RT_ERR; goto out; + ret = RT_ERR; + goto out; } cpu_set_t _cpu_set; @@ -930,7 +953,8 @@ int marsio_thread_init(struct mr_instance * instance) if (ret < 0) { MR_ERROR("Set thread affinity failed : %s. ", strerror(errno)); - ret = RT_ERR; goto out; + ret = RT_ERR; + goto out; } thread_info.instance = instance; @@ -946,7 +970,8 @@ int marsio_thread_init(struct mr_instance * instance) out: pthread_mutex_unlock(&instance->lock_thread_init); - if (ret < 0 && instance->is_exit_when_err_raise) exit(EXIT_FAILURE); + if (ret < 0 && instance->is_exit_when_err_raise) + exit(EXIT_FAILURE); return ret; } diff --git a/app/src/version.map b/app/src/version.map index fc48a3f..6943d9b 100644 --- a/app/src/version.map +++ b/app/src/version.map @@ -9,6 +9,7 @@ global: marsio_option_get; marsio_open_device; marsio_close_device; + marsio_get_device_ether_addr; marsio_recv_burst; marsio_recv_all_burst; marsio_send_burst; diff --git a/include/external/marsio.h b/include/external/marsio.h index ec58114..983b48a 100644 --- a/include/external/marsio.h +++ b/include/external/marsio.h @@ -158,6 +158,8 @@ struct mr_vdev * marsio_open_device(struct mr_instance * instance, const char * void marsio_close_device(struct mr_vdev * vdev); +void marsio_get_device_ether_addr(struct mr_vdev * vdev, void * str_ether_addr, uint8_t size); + struct mr_vdev * marsio_device_lookup(struct mr_instance * instance, const char * devsym); int marsio_recv_burst(struct mr_vdev * vdev, queue_id_t qid, marsio_buff_t * mbufs[], int nr_mbufs); -- cgit v1.2.3