运行

p1905_managerd -r1 -f /etc/map/1905d.cfg -F /etc/map/wts_bss_info_config

calltree

精简一下

main()
    debug(DEBUG_OFF, "Current Version %s\n", VERSION_1905);	// 打印版本
    memset()	// 清空 struct p1905_managerd_ctx ctx
    openlog()	// syslog -- openlog
    getopt()	// 处理命令行参数
    	-r 0:controller, 1:agent	// -r1 set 1905 role agent
		-f map cfg file				// -f /etc/map/1905d.cfg
    	-F wts bss cfg file			// -F /etc/map/wts_bss_info_config
    init_global_var_by_role()	// 根据角色初始化全局变量
		IEEE802_3_GROUP
        map_read_config_file()	// 读取map配置文件,-f 传入的
            map_config_get_line()
            /*
            	map_agent_alid = 00:0c:43:26:60:30
            	br_inf = br-lan
            	ctx->map_version = 2
            	bss_config_priority: ra0;apcli0;rai0;rai1;rai2;rai3;apclii0
            	lan = eth0.1
            	set discovery_cnt to defaut value(11)
            */
        get_wireless_interfaces()	// 读取无线接口信息
            /*
            	interface[2] = ra0
				interface[3] = apcli0
				interface[4] = rai0
				interface[5] = rai1
				interface[6] = rai2
				interface[7] = rai3
				interface[8] = apclii0
            */
        set_bss_config_priority_by_str()	// set the bss config priority
            /*
				bss intf(ra0) priority=1
				bss intf(apcli0) priority=2
				bss intf(rai0) priority=3
				bss intf(rai1) priority=4
				bss intf(rai2) priority=5
				bss intf(rai3) priority=6
				bss intf(apclii0) priority=7
            */
    p1905_managerd_init()	// Initialize manager daemon

cmdu.c	// C 文件
        cmdu_init()	// Initialize all parameters for CMDU.
                socket(AF_PACKET, SOCK_RAW, ETH_P_1905)	// 1905 socket
            	// 设置接收、发送缓冲区大小为458752
            	// cmdu_init set send buffer size 458752
				// cmdu_init set recv buffer size 458752
            	setsockopt(ctx->sock_br, SOL_SOCKET, SO_SNDBUF, (const char*)&nSndBufLen, sizeof(int);
                setsockopt(ctx->sock_br, SOL_SOCKET, SO_RCVBUF, (const char*)&nRcvBufLen, sizeof(int);
                bind()	// bind raw socket to interface

                // br mac addr 3E:AA:03:DC:9D:F5	// 通过 ioctl 获取 br mac 地址  
                         
            	/* Let bridge do not forward if dest address is local AL MAC address.
				   It is for 1905.1 unicast message usage.
                */
                set_opt_not_forward_dest()
            		socket(PF_INET, SOCK_RAW, IPPROTO_RAW)
            		setsockopt(fd, IPPROTO_IP, MAP_SO_BASE, mac, (socklen_t)size)
            		close(fd);

        _1905_interface_init()
            _1905_interface_open_sock()
                setsockopt(cli_ctrl->sock, SOL_SOCKET, SO_SNDBUF, (const char*)&nSndBufLen, sizeof(int));
                setsockopt(cli_ctrl->sock, SOL_SOCKET, SO_RCVBUF, (const char*)&nRcvBufLen, sizeof(int));
                // set send buffer size 458752
                // set recv buffer size 458752
                // 设置发送、接收缓冲区大小
        netlink_init(getpid())
            // sock < 0 // 功能正常?
        mapfilter_netlink_init()
        lldpdu_init()	// l1dpdu
        ap_autoconfig_init()	// AP 自动配置初始化

        eth_layer_init()	// 以太网层初始化
            eth_layer_port_init()
                /*
					MAX_LAN_PORT_NUM=5
					init eth_data[0]=0
					init eth_data[1]=1
					init eth_data[2]=2
					init eth_data[3]=3
					init eth_data[4]=4
                */
        traffic_separation_init()
            eloop_register_timeout(0, 0, map_r2_notify_ts_config, (void *)ctx, NULL);
                map_rm_hnat_session()
                    /*
                    	***************************
						cat /sys/kernel/debug/hnat/hnat_entry | while read line;do      line_num=$(echo $line 							| awk -F "(" '{print $2}' | awk -F ")" '{print $1}');     [ -n "$line_num" ] && 						echo "3 $line_num">/sys/kernel/debug/hnat/hnat_entry && sleep 1;done
						***************************
                    */
        eloop_register_signal_terminate()
        /* set all socket to eloop */
        eloop_register_read_sock(cmdu_process)
        eloop_register_read_sock(lldp_process)  
		eloop_register_read_sock(library_cmd_process)
        eloop_register_read_sock(ctrl_cmd_process)
        eloop_register_read_sock(netlink_event_process)
            netlink_event_recv()
            get_netlink_data()
            netlink_event_handler()
                case SWITCH_PORT_CHANGE:
                    eth_layer_port_data_update_and_notify()
                        notifier.down_handler()
                            ethernet_pull_out_handler()
                        notifier.up_handler()
                           	ethernet_plug_in_handler()
                           		// send topology discovery with vs info by interface
                           		discovery_at_boot_up()
            common_process()
        eloop_register_read_sock(worker_task_event_process)
        eloop_register_read_sock(wapp_cmd_process)
        /* 1905 one sec timer */
        eloop_register_timeout(p1905_managerd_periodic())
            /* update LLDP database, */
            update_lldp_queue_ttl()
            /* delete 1905.1 neighbor if not receiving new topology discovery */
            delete_not_exist_p1905_neighbor_device()
			/* delete 1905 topology device */
            delete_not_exist_p1905_topology_device()
            check_topology_rsp_expired()
			/* update topology tree */
            update_topology_tree()

有点多

main()
    debug(DEBUG_OFF, "Current Version %s\n", VERSION_1905);	// 打印版本
    memset()	// 清空 struct p1905_managerd_ctx ctx
    openlog()	// syslog -- openlog
    getopt()	// 处理命令行参数
    	-r 0:controller, 1:agent	// -r1 set 1905 role agent
		-f map cfg file				// -f /etc/map/1905d.cfg
    	-F wts bss cfg file			// -F /etc/map/wts_bss_info_config
    init_global_var_by_role()	// 根据角色初始化全局变量
		IEEE802_3_GROUP
        map_read_config_file()	// 读取map配置文件,-f 传入的
            map_config_get_line()
            /*
            	map_agent_alid = 00:0c:43:26:60:30
            	br_inf = br-lan
            	ctx->map_version = 2
            	bss_config_priority: ra0;apcli0;rai0;rai1;rai2;rai3;apclii0
            	lan = eth0.1
            	set discovery_cnt to defaut value(11)
            */
        get_wireless_interfaces()	// 读取无线接口信息
            /*
            	interface[2] = ra0
				interface[3] = apcli0
				interface[4] = rai0
				interface[5] = rai1
				interface[6] = rai2
				interface[7] = rai3
				interface[8] = apclii0
            */
        set_bss_config_priority_by_str()	// set the bss config priority
            /*
				bss intf(ra0) priority=1
				bss intf(apcli0) priority=2
				bss intf(rai0) priority=3
				bss intf(rai1) priority=4
				bss intf(rai2) priority=5
				bss intf(rai3) priority=6
				bss intf(apclii0) priority=7
            */
    p1905_managerd_init()	// Initialize manager daemon

cmdu.c	// C 文件
        cmdu_init()	// Initialize all parameters for CMDU.
                socket(AF_PACKET, SOCK_RAW, ETH_P_1905)	// 1905 socket
            	// 设置接收、发送缓冲区大小为458752
            	// cmdu_init set send buffer size 458752
				// cmdu_init set recv buffer size 458752
            	setsockopt(ctx->sock_br, SOL_SOCKET, SO_SNDBUF, (const char*)&nSndBufLen, sizeof(int);
                setsockopt(ctx->sock_br, SOL_SOCKET, SO_RCVBUF, (const char*)&nRcvBufLen, sizeof(int);
                bind()	// bind raw socket to interface

                // br mac addr 3E:AA:03:DC:9D:F5	// 通过 ioctl 获取 br mac 地址  
                         
            	/* Let bridge do not forward if dest address is local AL MAC address.
				   It is for 1905.1 unicast message usage.
                */
                set_opt_not_forward_dest()
            		socket(PF_INET, SOCK_RAW, IPPROTO_RAW)
            		setsockopt(fd, IPPROTO_IP, MAP_SO_BASE, mac, (socklen_t)size)
            		close(fd);
                cmdu_txq_init()	// initialize the cmdu transmit queue
                    TAILQ_INIT()
                init_fragment_queue()	// initialize the list head of rx fragment queue.
                init_retry_queue()		// initialization retry queue.
                init_message_wait_queue()	// initialization message wait queue.
        concurrent_sock_init()
                socket(AF_UNIX, SOCK_STREAM , 0)
                bind()
                listen()
        p1905_database_init()
            os_random()
            LIST_INIT()
            SLIST_INIT()	// 各种协议头
        #if 0
        wapp_usr_intf_init()
            /* wapp 的代码 */
            wapp_usr_intf_ctrl_open("1905_client_controller", "1905_client_controller");
			or
            wapp_usr_intf_ctrl_open("1905_client_agent", "1905_client_agent");
        wapp_register_unsolicited_event()
            wapp_usr_intf_send_command()
            wapp_usr_intf_ctrl_pending()
            wapp_usr_intf_ctrl_recv()	// only used for event messages
        #endif
        _1905_interface_init()
            _1905_interface_open_sock()
                setsockopt(cli_ctrl->sock, SOL_SOCKET, SO_SNDBUF, (const char*)&nSndBufLen, sizeof(int));
                setsockopt(cli_ctrl->sock, SOL_SOCKET, SO_RCVBUF, (const char*)&nRcvBufLen, sizeof(int));
                // set send buffer size 458752
                // set recv buffer size 458752
                // 设置发送、接收缓冲区大小
        netlink_init(getpid())
            // sock < 0 // 功能正常?
        mapfilter_netlink_init()
        lldpdu_init()	// l1dpdu
        ap_autoconfig_init()	// AP 自动配置初始化
        ethernet_pull_out_handler()
            delete_topo_disc_db_by_port()
            report_own_topology_rsp()
            insert_cmdu_txq()
            cmdu_reliable_send()
            debug()
            eth_layer_clear_switch_table()
            unmask_control_conn_port()
            delete_topo_response_db_by_port_interface()
            update_topology_tree()
        ethernet_plug_in_handler()
            usleep()
            debug()
            insert_cmdu_txq()
            eloop_register_timeout()
            discovery_at_boot_up()
                debug()
                insert_cmdu_txq()
                eloop_register_timeout()
                discovery_at_boot_up()
        eth_layer_init()	// 以太网层初始化
            eth_layer_port_init()
                /*
					MAX_LAN_PORT_NUM=5
					init eth_data[0]=0
					init eth_data[1]=1
					init eth_data[2]=2
					init eth_data[3]=3
					init eth_data[4]=4
                */
        worker_task_receiver_sock_init()	// 初始化 switch 口状态轮询线程
        worker_task_init()
        eloop_init()
        update_mapfilter_all_eth_interfaces()
            os_zalloc()
            os_memcpy()
            mapfilter_set_all_interface()
            os_free()
        mapfilter_ts_onoff()
        update_mapfilter_wan_tag()
            mapfilter_set_wan_tag()
            debug()
        traffic_separation_init()
            eloop_register_timeout(0, 0, map_r2_notify_ts_config, (void *)ctx, NULL);
                map_rm_hnat_session()
                    /*
                    	***************************
						cat /sys/kernel/debug/hnat/hnat_entry | while read line;do      line_num=$(echo $line 							| awk -F "(" '{print $2}' | awk -F ")" '{print $1}');     [ -n "$line_num" ] && 						echo "3 $line_num">/sys/kernel/debug/hnat/hnat_entry && sleep 1;done
						***************************
                    */
        eloop_register_signal_terminate()
        /* set all socket to eloop */
        eloop_register_read_sock(cmdu_process)
            cmdu_process()
                cmdu_parse()
                    parse_cmdu_message()
                        case TOPOLOGY_RESPONSE:
                            parse_topology_response_message()
        eloop_register_read_sock(lldp_process)  
		eloop_register_read_sock(library_cmd_process)
        eloop_register_read_sock(ctrl_cmd_process)
        eloop_register_read_sock(netlink_event_process)
        eloop_register_read_sock(worker_task_event_process)
        eloop_register_read_sock(wapp_cmd_process)
        /* 1905 one sec timer */
        eloop_register_timeout(p1905_managerd_periodic())
            /* update LLDP database, */
            update_lldp_queue_ttl()
            /* delete 1905.1 neighbor if not receiving new topology discovery */
            delete_not_exist_p1905_neighbor_device()
			/* delete 1905 topology device */
            delete_not_exist_p1905_topology_device()
            check_topology_rsp_expired()
			/* update topology tree */
            update_topology_tree()
            trace_topology_tree_cb()
            config_sync_error_handler()

            add_fragment_cnt()
            get_fragment_cnt()
            delete_fragment_queue_all()
            /* 检查是否有消息需要重传 */
            handle_retry_message_queue()
            common_process()
                process_cmdu_txq()
                debug()
                handle_message_wait_queue()
            eloop_register_timeout(p1905_managerd_periodic())

        /*周期发送拓扑发现消息 */
        eloop_register_timeout(send_discovery_periodic())

            eloop_register_timeout(send_discovery_periodic())
    /* Start manager daemon core */
    p1905_managerd_run()
        eloop_run()


    /* 去初始化,善后工作 */
    p1905_managerd_uninit()

    closelog()