Repository navigation
feat: refactor ipwatchd plugin to use service group framework - #44
Conversation
| @@ -0,0 +1,78 @@ | |||
| // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | |||
|
|
||
|
|
||
| #include "ipwatchd.h" | ||
| #include "../hooks/ipwatchd_hooks.h" |
4155645 to
eadd6a8
Compare
Refactored ipwatchd plugin to use deepin-service-group@deepin-daemon.service framework for resident startup instead of standalone systemd service. This change simplifies service management and integrates better with the deepin daemon ecosystem. Key changes: 1. Removed standalone systemd service files (deepin-service-plugin@*.service and org.deepin.dde.IPWatchD1.service) 2. Added systemd drop-in override configuration for deepin-service-group to grant necessary network capabilities (CAP_NET_RAW, CAP_NET_ADMIN) 3. Reorganized code structure with upstream/, hooks/, and plugin/ directories to maintain clear separation between upstream code and plugin implementation 4. Implemented hook mechanism using GCC weak symbols for minimal upstream modifications 5. Changed all debug logs to IPWD_MSG_TYPE_DEBUG level for cleaner production output while maintaining debugging capability 6. add upstream ipwatchd license: GPL-2.0-or-later The plugin now starts automatically with the deepin-daemon service group and inherits the necessary capabilities through the override configuration file. Influence: 1. Test plugin startup with deepin-service-group@deepin-daemon.service 2. Verify network capabilities are properly granted (CAP_NET_RAW, CAP_NET_ADMIN) 3. Test IP conflict detection and D-Bus signal emission 4. Verify debug logs only appear when debug_flag is enabled 5. Test dpkg build and installation of override configuration feat: 重构 ipwatchd 插件以使用服务组框架 重构 ipwatchd 插件以使用 deepin-service-group@deepin-daemon.service 框架 进行常驻启动,而不是独立的 systemd 服务。此更改简化了服务管理,并更好地 集成到 deepin 守护进程生态系统中。 主要变更: 1. 移除独立的 systemd 服务文件(deepin-service-plugin@*.service 和 org.deepin.dde.IPWatchD1.service) 2. 为 deepin-service-group 添加 systemd drop-in override 配置,授予必要的 网络能力(CAP_NET_RAW、CAP_NET_ADMIN) 3. 重新组织代码结构,使用 upstream/、hooks/ 和 plugin/ 目录,在上游代码和 插件实现之间保持清晰的分离 4. 使用 GCC 弱符号实现钩子机制,最小化对上游代码的修改 5. 将所有调试日志改为 IPWD_MSG_TYPE_DEBUG 级别,在生产环境保持简洁的同时 保留调试能力 6. 添加上游代码ipwatchd许可证协议GPL-2.0-or-later.txt 插件现在随 deepin-daemon 服务组自动启动,并通过 override 配置文件继承必要 的能力。 Influence: 1. 测试插件随 deepin-service-group@deepin-daemon.service 启动 2. 验证网络能力正确授予(CAP_NET_RAW、CAP_NET_ADMIN) 3. 测试 IP 冲突检测和 D-Bus 信号发送 4. 验证调试日志仅在启用 debug_flag 时出现 5. 测试 dpkg 构建和 override 配置的安装
eadd6a8 to
7317724
Compare
deepin pr auto review这是一个关于 IPwatchD 插件的代码审查。我将从语法逻辑、代码质量、性能和安全几个方面进行分析。 1. 语法逻辑代码整体结构清晰,使用了钩子机制来扩展 ipwatchd 的功能。主要的改进建议:
// plugin_adapter.c
if (ipwd_plugin_init("/var/lib/ipwatchd/ipwatchd.conf") != 0) {
return -1; // 建议添加错误日志
}建议改为: if (ipwd_plugin_init("/var/lib/ipwatchd/ipwatchd.conf") != 0) {
ipwd_message(IPWD_MSG_TYPE_ERROR, "Failed to initialize plugin");
return -1;
}
// plugin_adapter.c
pthread_mutex_lock(&mutex);
// ... critical section ...
pthread_mutex_unlock(&mutex);建议使用 RAII 风格的锁管理,确保在异常情况下也能正确释放锁。 2. 代码质量优点:
改进建议:
// plugin_adapter.c
check_context.conflic_mac = strdup(rcv_smac);建议添加 NULL 检查: check_context.conflic_mac = strdup(rcv_smac);
if (!check_context.conflic_mac) {
ipwd_message(IPWD_MSG_TYPE_ERROR, "Memory allocation failed");
return -1;
}
// plugin_adapter.c
#define PCAP_MAX_TIMES 5建议移到头文件中,并添加注释说明用途。 3. 性能优化
// plugin_adapter.c
usleep(20000); /* 20ms - give main loop time to process */建议根据网络状况动态调整间隔时间。
// plugin_adapter.c
for (int i = 0; i < PCAP_MAX_TIMES; i++) {
// ...
usleep(20000);
}建议使用指数退避算法来优化探测频率。 4. 安全性
// plugin_adapter.c
if (getuid() != 0) {
ipwd_message(IPWD_MSG_TYPE_INFO, "Running as non-root user (uid=%d)", getuid());
}建议添加更严格的权限检查,确保必要的 capabilities。
// plugin_adapter.c
if (inet_aton(check_context.ip, &sip) == 0 || sip.s_addr == 0) {
ipwd_message(IPWD_MSG_TYPE_ERROR, "Invalid IP address: %s", check_context.ip);
return -1;
}建议添加更多的输入验证,如 MAC 地址格式检查。
// plugin_adapter.c
strncpy(newinfo->ip, devices.dev[i].ip, IPWD_MAX_DEVICE_ADDRESS_LEN - 1);建议使用更安全的字符串操作函数,如 strlcpy。 5. 其他建议
// message.c
if ((type == IPWD_MSG_TYPE_DEBUG) && (!debug_flag)) {
return;
}建议添加运行时日志级别控制,而不仅仅是调试开关。
// plugin_adapter.c
ipwd_plugin_init("/var/lib/ipwatchd/ipwatchd.conf")建议支持配置文件路径作为参数传入,提高灵活性。
// plugin_adapter.c
pthread_mutex_destroy(&mutex);建议使用 atexit 注册清理函数,确保程序异常退出时也能正确清理资源。 总的来说,代码质量良好,但在错误处理、资源管理和安全性方面还有改进空间。建议重点关注:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Refactored ipwatchd plugin to use deepin-service-group@deepin-daemon.service framework for resident startup instead of standalone systemd service. This change simplifies service management and integrates better with the deepin daemon ecosystem.
Key changes:
The plugin now starts automatically with the deepin-daemon service group and inherits the necessary capabilities through the override configuration file.
Influence:
feat: 重构 ipwatchd 插件以使用服务组框架
重构 ipwatchd 插件以使用 deepin-service-group@deepin-daemon.service 框架 进行常驻启动,而不是独立的 systemd 服务。此更改简化了服务管理,并更好地
集成到 deepin 守护进程生态系统中。
主要变更:
插件现在随 deepin-daemon 服务组自动启动,并通过 override 配置文件继承必要
的能力。
Influence: