wifidog
wifidog开源模块,通过iptable对报文进行重定向到端口2060接口,对报文进行拦截,利用iptable实现用户上网行为管理功能,目前市面上的无线多采用此模块进行portale认真。 本文章对wifidog的源码进行了分析,希望有所帮助。
1 main
1.1 config_init();初始化全局变量,设置默认值
1.2 parse_commandline(argc,
argv);读取命令行参数
(1). -h 打印命令参数信息;
(2). -c 指定使用的wifidog配置文件;
(3). -f wifidog前台运行;
(4). -d 设置调试等级;
(5). -s 将日志信息输入到log日志;
(6). -w 与Wdctl通信域socket路径;
(7). -v 打印wifidog版本信息;
(8). -x 父进程id;
(9). -i Internal socket path used when re-starting self.;
(10). -a Path to /proc/net/arp replacement - mainly useful for debugging.;
(11) -p Save pid to file;
1.3 config_read(config->configfile);读取wifidog.conf文件,并将其内容保存到全局变量
1.4 config_validate();检验是否配置gatewayinterface和authserver
1.5client_list_init();初始化client链表
1.6 init_signals();初始化信号
1.7 append_x_restartargv(),保存传入参数和进程id。
1.8 执行main_loop循环
2 main_loop循环
2.1 设置wifidog启动时间started_time
2.2 存放进程id到指定文件save_pid_file(config->pidfile);
2.3 获取gateway的ip地址config->gw_address
2.4 获取gateway id即mac地址config->gw_id
2.5 调用函数httpdCreate()创建web server(建立tcp,socket监听默认端口2060)
2.6 函数register_fd_cleanup_on_fork(webserver->serverSock);初始化socket表
2.7 web server注册调用函数
httpdAddCContent(webserver, "/", "wifidog", 0, NULL, http_callback_wifidog);
httpdAddCContent(webserver, "/wifidog", "", 0, NULL, http_callback_wifidog);
httpdAddCContent(webserver, "/wifidog", "about", 0, NULL, http_callback_about);
httpdAddCContent(webserver, "/wifidog", "status", 0, NULL, http_callback_status);
httpdAddCContent(webserver, "/wifidog", "auth", 0, NULL, http_callback_auth);
httpdAddCContent(webserver, "/wifidog", "disconnect", 0, NULL, http_callback_disconnect);
<