Fix the problem that the switch does not take effect

This commit is contained in:
Derry 2021-04-13 01:28:45 -07:00
parent fd6fef639b
commit 10e8c00833
4 changed files with 58 additions and 26 deletions

View File

@ -113,7 +113,6 @@ void init_app_class_name_table(void){
}
while (fgets(line_buf, sizeof(line_buf), fp)){
sscanf(line_buf, "%d %s", &class_id, class_name);
printf("class id = %d, class name = %s\n", class_id, class_name);
strcpy(CLASS_NAME_TABLE[class_id - 1], class_name);
g_cur_class_num++;
}
@ -140,6 +139,7 @@ void dump_af_time(af_ctl_time_t *t){
}
printf("\n");
}
af_ctl_time_t *load_appfilter_ctl_time_config(void){
int ret = 0;
af_ctl_time_t *t = NULL;
@ -210,6 +210,32 @@ EXIT1:
return t;
}
int config_get_appfilter_enable(void){
int ret = 0;
int enable = 0;
af_ctl_time_t *t = NULL;
appfilter_config_alloc();
struct uci_section *global_sec = uci_lookup_section(uci_ctx, uci_appfilter, "global");
if (!global_sec){
printf("get time section failed\n");
return NULL;
}
char *enable_opt = uci_lookup_option_string(uci_ctx, global_sec, "enable");
if (!enable_opt){
return 0;
}
enable = atoi(enable_opt);
printf("enable str = %s, enable = %d\n", enable_opt, enable);
free(enable_opt);
appfilter_config_free();
return enable;
}
int appfilter_config_alloc(void){
char *err;
uci_appfilter = config_init_package("appfilter");

View File

@ -49,6 +49,7 @@ int appfilter_config_alloc(void);
int appfilter_config_free(void);
af_ctl_time_t *load_appfilter_ctl_time_config(void);
int config_get_appfilter_enable(void);
#endif

View File

@ -176,33 +176,35 @@ void clean_dev_online_status(void){
}
/*
Id Mac Ip
1 10:bf:48:37:0c:94 192.168.66.244
Id Mac Ip
1 10:bf:48:37:0c:94 192.168.66.244
*/
void check_dev_expire(void){
char line_buf[256] = {0};
char mac_buf[32] = {0};
char ip_buf[32] = {0};
printf("check dev expire...\n");
FILE *fp = fopen("/proc/net/af_client", "r");
if (!fp){
printf("open dev file....failed\n");
return;
}
while(fgets(line_buf, sizeof(line_buf), fp)){
if (strlen(line_buf) <= 16)
continue;
sscanf(line_buf, "%*s %s %s", mac_buf, ip_buf);
printf("mac = %s, ip = %s\n", mac_buf, ip_buf);
dev_node_t *node = find_dev_node(mac_buf);
if (!node)
continue;
node->online = 1;
printf("node is online, mac = %s\n" , node->mac);
}
fclose(fp);
char line_buf[256] = {0};
char mac_buf[32] = {0};
char ip_buf[32] = {0};
FILE *fp = fopen("/proc/net/af_client", "r");
if (!fp){
printf("open dev file....failed\n");
return;
}
fgets(line_buf, sizeof(line_buf), fp); // title
while(fgets(line_buf, sizeof(line_buf), fp)){
sscanf(line_buf, "%*s %s %s", mac_buf, ip_buf);
if (strlen(mac_buf) < 17){
printf("invalid mac:%s\n", mac_buf);
continue;
}
dev_node_t *node = find_dev_node(mac_buf);
if (!node){
node = add_dev_node(mac_buf);
if (!node)
continue;
}
node->online = 1;
}
fclose(fp);
}
void dump_dev_list(void){
int i, j;

View File

@ -35,6 +35,9 @@ void check_appfilter_enable(void){
struct tm *t;
time_t tt;
time(&tt);
enable = config_get_appfilter_enable();
if (0 == enable)
goto EXIT;
af_ctl_time_t *af_t = load_appfilter_ctl_time_config();
if (!af_t){
enable = 0;