diff options
| author | 陆秋文 <[email protected]> | 2023-02-17 10:40:50 +0000 |
|---|---|---|
| committer | 陆秋文 <[email protected]> | 2023-02-17 10:40:50 +0000 |
| commit | 973807f41582137b1cda8649cf46108cc3000ce9 (patch) | |
| tree | 529ac355a3e90c58924c0eb080d9adfb5c525751 /app/src/marsio.c | |
| parent | 0a7c43e32f43cef36cea93dee4c3d5dc5873c58b (diff) | |
TSG-13385 增加service, app侧kernel representor的实现以实现向内核协议栈注入控制报文的功能。
Diffstat (limited to 'app/src/marsio.c')
| -rw-r--r-- | app/src/marsio.c | 121 |
1 files changed, 13 insertions, 108 deletions
diff --git a/app/src/marsio.c b/app/src/marsio.c index 5a10097..c84ff7e 100644 --- a/app/src/marsio.c +++ b/app/src/marsio.c @@ -13,6 +13,7 @@ #include <arpa/inet.h> #include <ctrlmsg.h> #include <ctrlmsg_define.h> +#include <tap.h> #include <MESA_prof_load.h> #include <unistd.h> #include <signal.h> @@ -82,7 +83,7 @@ void __mrapp_mem_protect_unlock_mempool_cb(struct rte_mempool * mp, void *arg) #if 0 /* 基于ASAN的内存保护模式 * 该保护模式开启后,共享大页内存将标记为不可达,对共享内存的访问将被ASAN探测并记录 */ -static void mrapp_mem_protect_with_asan_init(struct mr_instance * instance) +static void mrapp_mem_protect_with_asan_init(struct ref_mr_instance * instance) { MESA_load_profile_uint_def(instance->app_cfgfile_path, "protect", "enable", &instance->memory_protect_with_asan, 0); @@ -278,52 +279,6 @@ static int mrapp_distributer_init(struct mr_instance * instance) return RT_SUCCESS; } -static int mrapp_bpf_dumper_init(struct mr_instance * instance, struct mr_vdev * vdev) -{ - const char * str_devsym = vdev->devsym; - const char * str_cfgfile = instance->app_cfgfile_path; - - /* 从应用配置文件中读取Dumper的配置。Dumper系调试使用,由用户通过配置文件指定, - 读不到相关选项,则不启用Dumper。 */ - - char str_section[MR_SYMBOL_MAX] = { 0 }; - snprintf(str_section, sizeof(str_section), "bpfdump:%s", str_devsym); - - unsigned int __opt_enable = 0; - MESA_load_profile_uint_def(str_cfgfile, str_section, "enable", &__opt_enable, 0); - - /* 是否启用 */ - if (!__opt_enable) return RT_SUCCESS; - - char __opt_str_bpf_expr[MR_STRING_MAX] = { 0 }; - char __opt_str_dumpfile[MR_STRING_MAX] = { 0 }; - - unsigned int __opt_direction = 0; - unsigned int __opt_backend = 0; - unsigned int __opt_offset = 0; - - MESA_load_profile_string_def(str_cfgfile, str_section, "bpf_expr", __opt_str_bpf_expr, - sizeof(__opt_str_bpf_expr), NULL); - MESA_load_profile_string_def(str_cfgfile, str_section, "dumpfile", __opt_str_dumpfile, - sizeof(__opt_str_dumpfile), NULL); - - MESA_load_profile_uint_def(str_cfgfile, str_section, "bpf_offset", &__opt_offset, 0); - MESA_load_profile_uint_def(str_cfgfile, str_section, "direction", &__opt_direction, 0); - MESA_load_profile_uint_def(str_cfgfile, str_section, "backend", &__opt_backend, 0); - - vdev->bpf_dumper = bpf_dumper_create(instance->appsym, __opt_backend, - str_devsym, __opt_str_dumpfile, __opt_str_bpf_expr); - - if (unlikely(vdev->bpf_dumper == NULL)) - { - MR_ERROR("In application %s, BPF dumper for device %s create failed.", - instance->appsym, str_devsym); return RT_ERR; - } - - return RT_SUCCESS; -} - - static unsigned __table_strip(char *str, unsigned len) { int newlen = len; @@ -541,49 +496,6 @@ err: return RT_ERR; } -/* 邻居子系统,延迟初始化 - 设备初始化时初始化该部分 -*/ -static int mrapp_neigh_device_init(struct mr_instance * instance, struct mr_vdev * vdev) -{ - /* 读静态邻居表项 */ - struct mr_static_neigh_entry * __neigh_entry_iter; - TAILQ_FOREACH(__neigh_entry_iter, &instance->static_neigh_list, next) - { - if (strncmp(vdev->devsym, __neigh_entry_iter->devsym, sizeof(vdev->devsym)) != 0) - continue; - - int ret = neigh_create_or_update(instance->neigh, __neigh_entry_iter->in_addr, - &__neigh_entry_iter->ether_addr, vdev->vdi, 1); - - if (ret < 0) - { - MR_WARNING("Static neighbour %s->%s on device %s failed, Ignore.", - __neigh_entry_iter->str_in_addr, - __neigh_entry_iter->str_ether_addr, - __neigh_entry_iter->devsym); - - continue; - } - - MR_INFO("Static neighbour: %s->%s, device: %s.", __neigh_entry_iter->str_in_addr, - __neigh_entry_iter->str_ether_addr, __neigh_entry_iter->devsym); - } - - /* 设备开启了发送队列后,且启用了ARP功能,发免费ARP报文 */ - if (vdev->nr_txstream == 0 || vdev->en_arp == 0) - { - return RT_SUCCESS; - } - - for (int i = 0; i < instance->nr_gratuitous_arp_send; i++) - { - arp_request_send(vdev->vdi, 0, vdev->vdi->vdev->in_addr); - } - - return RT_SUCCESS; -} - /* 注册应用 */ static int mrapp_app_register(struct mr_instance * instance) { @@ -737,14 +649,6 @@ static int __open_device_response_handler(struct ctrlmsg_handler * ct_hand, __open_device_unposion(mr_vdev->vdi); } - /* 启用了IP地址,处理ARP请求和ICMP请求 */ - struct vdev * vdev = mr_vdev->vdi->vdev; - if (vdev->in_addr.s_addr != 0 && vdev->in_mask.s_addr != 0) - { - mr_vdev->en_arp = 1; - mr_vdev->en_icmp = 1; - } - instance->nr_vdevs++; wake_up: @@ -781,15 +685,14 @@ struct mr_vdev * marsio_open_device(struct mr_instance * instance, { /* 构造虚设备打开请求 */ struct ctrl_msg_vdev_open_request req_msg; - ctrl_msg_header_construct(&req_msg.msg_header, sizeof(req_msg), - CTRL_MSG_TYPE_REQUEST, CTRLMSG_TOPIC_VDEV_OPEN); + ctrl_msg_header_construct(&req_msg.msg_header, sizeof(req_msg), CTRL_MSG_TYPE_REQUEST, CTRLMSG_TOPIC_VDEV_OPEN); snprintf((char *)req_msg.devsym, sizeof(req_msg.devsym), "%s", devsym); req_msg.nr_rxstream = nr_rxstream; req_msg.nr_txstream = nr_txstream; /* 发送请求 */ - ctrlmsg_msg_send(instance->ctrlmsg_handler, NULL, (struct ctrl_msg_header*)&req_msg); + ctrlmsg_msg_send(instance->ctrlmsg_handler, NULL, (struct ctrl_msg_header *)&req_msg); /* 等待应答 */ /* TODO: 抽象出单独的函数 */ @@ -804,19 +707,21 @@ struct mr_vdev * marsio_open_device(struct mr_instance * instance, /* 查询打开结果 */ struct mr_vdev * vdev = marsio_device_lookup(instance, devsym); - if (vdev == NULL) return NULL; + if (vdev == NULL) + { + return NULL; + } MR_INFO(" "); MR_INFO("Application %s, Device %s:", instance->appsym, vdev->devsym); MR_INFO(" Rx Queue Count : %d", vdev->nr_rxstream); MR_INFO(" Tx Queue Count : %d", vdev->nr_txstream); - MR_INFO(" ARP protocol handler : %s", vdev->en_arp ? "Enable" : "Disable"); - MR_INFO(" ICMP protocol handler : %s", vdev->en_arp ? "Enable" : "Disable"); - /* 调试捕包 */ - mrapp_bpf_dumper_init(instance, vdev); - /* 静态邻居表 */ - mrapp_neigh_device_init(instance, vdev); + if (vdev->vdi->vdev->representor_config.enable > 0) + { + tap_representor_init(instance, vdev); + } + return vdev; } |
