connmand 架构介绍
总体架构图
文件结构
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
结构体关系
connman_xxx(technology,network,device)分别描述了特征, 并单向关联了对应的driver行为, connmnad_xxx_driver 描述了具体行为接口,大致如下,具体接口定义在各个插件中实现, 通过 connman_xxx(technology,network,device)从而统一底层不同网络类型与connmand 和上层与connmand 的交互
const char *name;
enum connman_device_type type;
int priority;
int (*probe) (struct connman_device *device);
void (*remove) (struct connman_device *device);
int (*enable) (struct connman_device *device);
int (*disable) (struct connman_device *device);
int (*scan)(struct connman_device *device,
struct connman_device_scan_params *params);
void (*stop_scan) (enum connman_service_type type,
struct connman_device *device);
int (*set_regdom) (struct connman_device *device,
const char *alpha2);
connman_technology
struct connman_technology {
int refcount;
enum connman_service_type type;
char *path;
GSList *device_list;
...
//单向关联connman_technology_driver, 可以同时存在多种technology的行为定义
GSList *driver_list;
....
};
connman_technology_driver
struct connman_technology_driver {
const char *name;
enum connman_service_type type;
int priority;
int (*probe) (struct connman_technology *technology);
void (*remove) (struct connman_technology *technology);
void (*add_interface) (struct connman_technology *technology,
int index, const char *name,
const char *ident);
void (*remove_interface) (struct connman_technology *technology,
int index);
int (*set_tethering) (struct connman_technology *technology,
const char *identifier, const char *passphrase,
const char *bridge, bool enabled);
int (*set_regdom) (struct connman_technology *technology,
const char *alpha2);
};
connman_device
每个插件编写处理新设备检测的代码;但插件发现有新设备, 插件需要通过调用 connman_device_create() 通知 ConnMand。
struct connman_device {
...
struct connman_device_driver *driver; // 具体网络类型的行为
...
struct connman_network *network;
GHashTable *networks; //存储底层上报的network哈希表
};
connman_device_driver
描述各个网络设备插件的行为, 主要为扫描, 上下电等接口
struct connman_device_driver {
const char *name;
enum connman_device_type type;
int priority;
int (*probe) (struct connman_device *device);
void (*remove) (struct connman_device *device);
int (*enable) (struct connman_device *device);
int (*disable) (struct connman_device *device);
int (*scan)(struct connman_device *device,
struct connman_device_scan_params *params);
void (*stop_scan) (enum connman_service_type type,
struct connman_device *device);
int (*set_regdom) (struct connman_device *device,
const char *alpha2);
};
connman_network
struct connman_network {
...
//关联网络的行为,如关联和去关联等
struct connman_network_driver *driver;
...
struct connman_device *device;
};
network_driver
描述每种类型的技术建立/处理连接的细节.
struct connman_network_driver {
const char *name;
enum connman_network_type type;
int priority;
int (*probe) (struct connman_network *network);
void (*remove) (struct connman_network *network);
int (*connect) (struct connman_network *network);
int (*disconnect) (struct connman_network *network);
int (*set_autoconnect) (struct connman_network *network,
bool autoconnect);
};