1/*
2Copyright (C) 2020 Derry <destan19@126.com>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22#ifndef __FILTER_USER_H__
23#define __FILTER_USER_H__
24#define MAX_IP_LEN 32
25#define MAX_MAC_LEN 32
26#define MAX_VISIT_HASH_SIZE 64
27#define MAX_DEV_NODE_HASH_SIZE 64
28#define MAX_HOSTNAME_SIZE 64
29#define MAX_SUPPORT_USER_NUM 64
30#define OAF_VISIT_LIST_FILE "/tmp/visit_list"
31#define OAF_DEV_LIST_FILE "/tmp/dev_list"
32#define MIN_VISIT_TIME 5 // default 5s
33#define MAX_APP_STAT_NUM 8
34#define MAX_VISITLIST_DUMP_NUM 16
35#define MAX_APP_TYPE 16
36#define MAX_APP_ID_NUM 128
37#define MAX_SUPPORT_DEV_NUM 64
38#define SECONDS_PER_DAY (24 * 3600)
39
40//extern dev_node_t *dev_hash_table[MAX_DEV_NODE_HASH_SIZE];
41
42/*
43{
44"mac":	"10:bf:48:37:0c:94",
45"ip":	"192.168.100.244",
46"app_num":	0,
47"visit_info":	[{
48"appid":	8002,
49"latest_action":	1,
50"latest_time":	1602604293,
51"total_num":	4,
52"drop_num":	4,
53"history_info":	[]
54}]
55}
56*/
57/* ������������������������ */
58typedef struct visit_info
59{
60    int appid;
61    int first_time;
62    int latest_time;
63    int action;
64    int expire; /*������������������������*/
65    struct visit_info *next;
66} visit_info_t;
67
68/* ������������������app��������������������� */
69typedef struct visit_stat
70{
71    unsigned long long total_time;
72    unsigned long long total_down_bytes;
73    unsigned long long total_up_bytes;
74} visit_stat_t;
75
76typedef struct dev_node
77{
78    char mac[MAX_MAC_LEN];
79    char ip[MAX_IP_LEN];
80    char hostname[MAX_HOSTNAME_SIZE];
81    int online;
82    int expire;
83    int offline_time;
84    int online_time;
85    visit_info_t *visit_htable[MAX_VISIT_HASH_SIZE];
86    visit_stat_t stat[MAX_APP_TYPE][MAX_APP_ID_NUM];
87    struct dev_node *next;
88} dev_node_t;
89
90struct app_visit_info
91{
92    int app_id;
93    char app_name[32];
94    int total_time;
95};
96
97struct app_visit_stat_info
98{
99    int num;
100    struct app_visit_info visit_list[MAX_APP_STAT_NUM];
101};
102typedef void (*iter_func)(void *arg, dev_node_t *dev);
103//todo:dev for each
104extern dev_node_t *dev_hash_table[MAX_DEV_NODE_HASH_SIZE];
105
106dev_node_t *add_dev_node(char *mac);
107void init_dev_node_htable();
108void dump_dev_list(void);
109void dump_dev_visit_list(void);
110dev_node_t *find_dev_node(char *mac);
111void dev_foreach(void *arg, iter_func iter);
112void add_visit_info_node(visit_info_t **head, visit_info_t *node);
113void check_dev_visit_info_expire(void);
114void flush_expire_visit_info();
115int check_dev_expire(void);
116void flush_dev_expire_node(void);
117void flush_expire_visit_info(void);
118#endif
119