连接管理器 (connman) 是一个连接管理守护程序 (connmand),用于管理运行 linux 操作系统的设备内的互联网连接。它提供低内存消耗,对不断变化的网络条件做出快速、一致、同步的反应。
connman具有各种插件,是一个完全模块化的系统,可以扩展以支持各种有线或无线技术。插件方法允许针对各种用例轻松进行调整和修改。dhcp 和域名解析等配置方法是使用插件实现的。
所有应用程序都应使用 d-bus 与康曼通信。它与嵌入式yocto构建系统一起使用,是genivi车载信息娱乐规范的一部分。
康文在 gpl v2.0 许可证下分发。英特尔是康曼项目的主要贡献者。
康曼建筑 康曼内部基础设施 功能和特性 连接管理器中内置了以下功能:
通用插件基础架构 设备和网络抽象(具有基本存储支持) ipv4、ipv4-ll(链路本地)和 dhcp - ipv6、dhcpv6 和 6to4 隧道 高级路由和 dns 配置 内置 dns 代理和智能缓存 内置 wispr 热点登录和门户检测 时间和时区配置(手动和自动使用 ntp) 代理处理(手动和自动使用 wpad) 网络共享支持(usb、蓝牙和无线网络接入点模式) 详细的统计信息处理(家庭和漫游) 可以为网络支持启用各种插件:
以太网插件 具有 wep40/wep128 和 wpa/wpa2(个人和企业)的无线插件 蓝牙插件(使用蓝牙z) 2g/3g/4g 插件(使用网络) 还具有附加功能的普金斯:
环回接口设置 pacrunner 代理处理 策略工具包授权支持 康曼 d-总线接口 d 总线接口 应用程序应使用 d-bus 与康曼通信。 主入口点通过管理器对象。 管理器对象包含对服务对象的引用(接口)。 其他接口包括 vpn、时钟、任务、技术、会话、通知、对等、代理和计数器。 管理器 d 总线接口 应用程序入口点是管理器对象 解释了所有方法和属性 管理器属性 检索所有全局属性的简单方法如下所示:
总线 = 数字总线。系统总线() 管理器 = 总线。interface(bus.get_object(“net.connman”, “/”), “net.connman.manager”) 属性 = 管理器。获取属性() 更改全局属性也非常简单。例如,启用所谓的脱机模式(aka 飞行模式)就足以设置该属性:管理器。setproperty(“offlinemode”, dbus.布尔值(1))。
服务接口 高级界面使用户界面可以轻松访问网络详细信息和用户选择的首选项。这是服务列表和接口。connman 维护着一个包含所有可用服务的平面和排序列表。
服务订单 service states 每个服务的基本状态都是“空闲”。这意味着此服务目前根本没有在使用中。它也没有尝试连接或执行任何其他操作。 “关联”状态表示此服务尝试建立与网络的低级连接 - 例如,与wifi接入点关联/连接。 在“配置”状态下,服务指示它正在尝试检索/配置 ip 设置。 “就绪”状态表示设备已成功连接。这并不意味着它具有默认路由,但基本 ip 操作将成功。 在“断开连接”状态下,服务指示它将终止当前连接,并将返回到“空闲”状态。 此外,“失败”状态表示错误行为。它类似于“空闲”状态,因为服务未连接。 服务 d 总线接口 下面介绍如何获取服务对象:
-properties = manager.getproperties() -for path in properties[services]: service = dbus.interface(bus.get_object(net.connman, path), net.connman.service)
它还包含连接或断开特定服务的方法。connman 还可以根据他的策略或通过外部事件(如插入以太网电缆)自动连接服务。手动连接(或断开)特定服务就像告诉它一样简单。
connect: service.connect() or service.disconnect()
服务属性 技术接口 基本的设备配置任务由技术接口完成。例如,打开和关闭设备(例如通过rfkill)应通过技术接口完成。
技术特性 用户可以通过管理器脱机模式属性激活脱机(飞行)模式。在离线模式下,包括以太网在内的所有技术都已关闭电源。在脱机模式下,用户可以通过使用 rfkill 命令或某些便携式计算机中的 fn-fx 组合键,通过“技术支持”属性临时激活单个技术。
康曼内部 启动连接 选项:
-c, --config=file load the specified configuration file instead of /usr/local/etc/connman/main.conf -d, --debug=debug specify debug options to enable -i, --device=dev specify networking device or interface -i, --nodevice=dev specify networking interface to ignore -p, --plugin=name,... specify plugins to load -p, --noplugin=name,... specify plugins not to load -w, --wifi=name specify driver for wifi/supplicant -n, --nodaemon don't fork daemon to background -r, --nodnsproxy don't enable dns proxy --nobacktrace don't print out backtrace information
用法示例:
# connman_supplicant_debug=1 connmand -n -d &> connman.log #connmand -i wlan0 -i eth0 --nodnsproxy --nodaemon >& connman.log
主配置文件 主要.conf inputrequesttimeout = 120 (default)---------> input request ( ex. passphrase) timeout browserlaunchtimeout = 300 ( default) -----> the request for launching a browser for portal pages backgroundscanning = true --------------------> option for background scanning fallbacktimeservers = --------------------------> list of fallback timeservers ( used by ntp sync) separated by , fallbacknameservers = -------------------------> list of fallback nameservers defaultautoconnecttechnologies = -----------> list of technologies that are marked autoconnectable by default. preferredtechnologies = ------------------------> list of preferred technologies from - most preferred one to least preferred networkinterfaceblacklist = vmnet,vboxnet,virbr,ifb,ve-,vb- ---> list of blacklisted network interfaces allowhostnameupdates = true -----------------> allow connman to change the system hostname ( ex. dhcp hostname option) singleconnectedtechnology = false -----------> keep only a single connected technology at any time tetheringtechnologies = wifi,bluetooth,gadget persistenttetheringmode = false --------------> restore earlier tethering status when returning from offline mode enable6to4 = false ------------------------------> automatically enable anycast 6to4 if possible (not recommended. see rfc6343 ) enableonlinecheck = false --------------------> enable use of http get as on online status check alwaysconnectedtechnologies = -------------> list of technologies with autoconnect = true which are always connected regardless of preferredtechnologies setting
康曼配置文件 康曼使用配置文件来配置现有服务。康曼将在 /var/lib/康曼/ 中寻找其配置文件。配置文件名不得包含字母或数字以外的其他字符,并且必须具有 .config 后缀。
ex. #cat /var/lib/connman/example.config [global] name = example description = example network configuration [service_home_ethernet] type = ethernet ipv4 = 192.168.1.42/255.255.255.0/192.168.1.1 ipv6 = 2001:db8::42/64/2001:db8::1 mac = 01:02:03:04:05:06 nameservers = 10.2.3.4,192.168.1.99 searchdomains = my.home,isp.net timeservers = 10.172.2.1,ntp.my.isp.net domain = my.home [service_home_wifi] type = wifi name = my_home_wifi passphrase = secret ipv4 = 192.168.2.2/255.255.255.0/192.168.2.1 mac = 06:05:04:03:02:01
设置 为用户经常连接到的网络自动创建设置和配置文件。
# cat /var/lib/connman/settings [global] offlinemode=false [wifi] enable=true tethering=false [bluetooth] enable=false tethering=false
配置文件设置按其服务名称存储在 /var/lib/connman/ 下的目录中。vpn设置可以在 /var/lib/康曼-vpn/ 中找到。
编写插件 基本插件包含通过connman_plugin_define的插件描述,以及通过该描述定义的初始化/退出回调。
#include static int example_init(void) { return 0; } static void example_exit(void) { } connman_plugin_define(example, example plugin, connman_version, example_init, example_exit)
插件使用技术、网络和设备以及其他基础结构与 connman 的核心功能进行交互。以下是技术基础架构:
ex. bluetooth plugin static struct connman_technology_driver tech_driver = { .name = bluetooth, .type = connman_service_type_bluetooth, .probe = bluetooth_tech_probe, .remove = bluetooth_tech_remove, .set_tethering = bluetooth_tech_set_tethering, };
若要使连接管理器了解新的技术插件,我们需要通过调用connman_technology_driver_register()来注册其驱动程序。
connman_technology_driver_register(&tech_driver);
设备基础结构 设备表示给定技术的真实设备。每种技术可能有许多设备。
static struct connman_device_driver device_driver = { .name = bluetooth, .type = connman_device_type_bluetooth, .probe = bluetooth_device_probe, .remove = bluetooth_device_remove, .enable = bluetooth_device_enable, .disable = bluetooth_device_disable, };
要注册驱动程序:
connman_device_driver_register(&device_driver);
此外,需要为每个插件编写代码来处理新设备的检测;蓝牙插件通过为 bluez d-bus 接口注册观察程序来实现此目的。一旦出现新的蓝牙设备,插件需要通过调用connman_device_create()来通知connman核心。对于蓝牙插件,调用将是:
struct connman_device *device; device = connman_device_create(bluetooth, connman_device_type_bluetooth)
网络基础设施 连接管理器为插件提供了一种方法来处理为每种类型的技术建立/处理连接的细节。对于蓝牙插件,需要注册一个connman_network_driver:
static struct connman_network_driver network_driver = { .name = bluetooth, .type = connman_network_type_bluetooth_pan, .probe = bluetooth_pan_probe, .remove = bluetooth_pan_remove, .connect = bluetooth_pan_connect, .disconnect = bluetooth_pan_disconnect, };
然后,调用寄存器函数:
connman_network_driver_register(&network_driver);
康曼源文件/基础架构 初始化函数将在运行主循环之前在 src/main.c 中被调用。
src/util.c - /dev/urandom support src/inotify.c - used by the core (config.c) and the session policy plugin src/technology.c – used for technology interface src/notifier.c – basic notifier infrastructure src/agent.c – agent interface src/service.c – used for service interface src/peer_service.c – p2p peer service api src/peer.c – p2p peer object’s core logic src/provider.c – provider infrastructure src/network.c – network infrastructure used by plug-ins src/config.c – framework for configuration files src/device.c – device infrastructure used by plug-ins src/iptables.c – iptables support (netfilter chains and rules) src/firewall-iptables.c, nftables.c (older firewall.c) – firewall infrastructure. src/nat.c – used for nat src/tethering.c – tethering infrastructure src/manager.c – manager interface src/stats.c – used for storing service stats ( mmaped into memory) src/ipconfig.c – ip configuration framework src/rtnl.c – netlink support src/session.c – allows 3rd party applications to request a network session src/resolver.c – resolver framework src/dhcp.c, dhcpv6.c – dhcp framework src/rfkill.c – rfkill interface support src/machine.c - basic systemd-hostnamed ( machine-type- “chassis”) support
康曼克特 康曼有一个标准的命令行客户端康曼克特。它可以在2模式下运行:
在命令模式下,命令作为连接命令的参数输入,就像系统命令一样。 交互模式是通过键入不带参数的 connmanctl 来启动的。提示将更改为 connmanctl>以指示它正在等待用户命令,就像 python 交互模式一样。 康曼克特示例 示例 1.启用和禁用无线网络 $ connmanctl technologies - check for the line that says powered: true/false. $ connmanctl enable wifi - to power the wifi on. $ connmanctl disable wifi – to power off the wifi.
启用无线网络的其他方法可能包括 - ip链接设置。康曼将自动处理有线连接。
示例 2.连接到开放接入点 本节中的命令演示如何在命令模式下运行 connmanctl。要扫描网络,康曼克特尔接受称为技术的简单名称。要扫描附近的 wifi 网络:
$ connmanctl scan wifi to list the available networks found after a scan run (example output): $ connmanctl services *ao mynetwork wifi_dc85de828967_68756773616d_managed_psk othernet wifi_dc85de828967_38303944616e69656c73_managed_psk anotherone wifi_dc85de828967_3257495245363836_managed_wep fourthnetwork wifi_dc85de828967_4d7572706879_managed_wep ano6pennetwork wifi_dc85de828967_4d6568657272696e_managed_none $ connmanctl connect wifi_dc85de828967_4d6568657272696e_managed_none
您现在应该已连接到网络。使用 ip 地址或连接状态进行检查。
示例 3.连接到受保护的接入点 对于受保护的接入点,请向 connman 守护程序提供一些信息,至少提供密码或密码。
$ connmanctl connmanctl> scan wifi ----- to list services: connmanctl> services connmanctl> agent on --- register the agent to handle user requests. connmanctl> connect wifi_dc85de828967_38303944616e69656c73_managed_psk
代理会要求您提供更多信息,具体取决于您要连接到的网络类型。代理还将打印有关所需信息的其他数据,如以下示例所示。
agent requestinput wifi_dc85de828967_38303944616e69656c73_managed_psk passphrase = [ type=psk, requirement=mandatory ] passphrase?
提供请求的信息,在此示例中为密码,然后键入:
connmanctl> quit
如果您提供的信息正确无误,您现在应该已连接到受保护的接入点。
其他康曼克特用法: 技术 各种硬件接口被康文称为技术。要列出可用技术,请运行:
$ connmanctl technologies
可以通过以下方式打开/关闭技术:
$ connmanctl enable technology_type $ connmanctl disable technology_type
例如,要关闭无线网络:
$ connmanctl disable wifi
康曼测试脚本 康曼还提供了基本的python脚本(例如测试康曼,列表服务等)。通过这些脚本支持连接,断开连接,自动连接,服务,扫描,启用,禁用,脱机模式,状态等基本操作。
康曼调试 激活调试 我们可以使用 -d 命令行选项在 connman 中激活调试打印。
-d activate all normal debug prints -d src/service.c this prints debugging info from src/service.c file only -d src/network.c:src/ipconfig.c this activates debug prints in src/network.c and src/ipconfig.c files. -d 'src/n*.c' this would activate debug print from all the c source files starting with letter 'n' in src directory. note the quotation marks around option, that is to prevent shell expansion. -d '*/n*.c:*/i*.c' activate debug prints for all c source files starting with letters 'n' or 'i' in any sub-directory.
子组件调试 connman 的某些组件具有激活的环境变量调试打印。如果设置了环境变量,则相应的组件将打印一些额外的调试信息。
可以使用以下环境变量:
connman_dhcp_debug:与 dhcpv4 相关的调试信息 connman_dhcpv6_debug:dhcpv6 相关的调试信息 connman_iptables_debug:使用表时的额外信息 connman_resolv_debug:名称解析程序调试打印。当 connman 解析主机名供自己使用时,将使用这些调试打印。请注意,dns 代理调试打印不使用此环境变量。为此,可以使用“-d src/dns代理.c”命令行选项。 connman_supplicant_debug:调试打印以进行连接和wpa_supplicant进程之间的通信。 v connman_web_debug:在 wispr 和 6to4 组件中执行互联网连接检查时,调试信息。 例:
connman_supplicant_debug=1 src/connmand -n
示例:获取connman_iptables_debug日志 确保在内核中启用了 iptables 支持:
#zcat /proc/config.gz | grep config_ip_nf_iptables
必须在内核中启用 iptable:
config_ip_nf_iptables=m or config_ip_nf_iptables=y
清除所有可测试的过滤器:
# iptables –f
设置以下可测试规则以过滤 icmp 数据包(输入、输出和转发数据包):
# iptables -t filter -a input -p icmp --icmp-type echo-request -j log --log-prefix=filter input: # iptables -t filter -a input -p icmp --icmp-type echo-reply -j log --log-prefix=filter input:“ # iptables -t filter -a output -p icmp --icmp-type echo-request -j log --log-prefix=filter output:“ # iptables -t filter -a output -p icmp --icmp-type echo-reply -j log --log-prefix=filter output:“ # iptables -t filter -a forward -p icmp --icmp-type echo-request -j log --log-prefix=filter forward:“ # iptables -t filter -a forward -p icmp --icmp-type echo-reply -j log --log-prefix=filter forward:
导出以下环境变量以启用康曼的 iptables 调试:
# export connman_iptables_debug=1
在启用调试选项的情况下启动 connmand 连接管理器:
# /usr/sbin/connmand -d -n -i eth0
每当涉及 icmp 数据包时,都应显示康文守护程序消息日志。
易控组态软件在变频节能系统的应用
可调电感器改变电感量的方法
OPPOR11怎么样?OPPOR11值得购买吗?OPPOR11外观、配置、拍照、性能升级较大,颜值给力
物联网依赖的三个关键技术是什么?
大功率集成功率放大器
使用康文管理Linux设备上的互联网连接
集成电路的多种实现方式
替换亚成微ic驱动电源管理芯片SM7075P升级版电路方案
家庭无线网络问题甚堪忧(不容乐观)
探针台测试,垂直和端面耦合的灵活硅光测量方案
超级模拟芯片问世 比现有电脑快9000倍
荣耀FlyPods 3真无线降噪耳机将于今晚发布 支持双重主动降噪及快速充电技术
世界上最快的无线射频芯片 极速数据收发
饿了么口碑打造智慧餐厅 萌萌机器人为顾客送餐
钛合电子携手森友会共探物联网之路,促进产业物联网升级
泰克DPO7354C数字荧光示波器简介
Facebook再次对苹果起抨击,希望欧盟能为该公司设定界限
国内5G水平领先全球_运营商还需加倍努力
华为正与联发科、紫光展锐就采购更多芯片事宜开始磋商
一文让你成为射频功率测量专家