05c32ae6d0fbad2aef79787b246a88fba0569d85
[project/usteer.git] / node.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #ifndef __APMGR_NODE_H
21 #define __APMGR_NODE_H
22
23 #include "usteer.h"
24
25 enum local_req_state {
26 REQ_IDLE,
27 REQ_CLIENTS,
28 REQ_RRM_SET_LIST,
29 REQ_RRM_GET_OWN,
30 __REQ_MAX
31 };
32
33 struct usteer_local_node {
34 struct usteer_node node;
35
36 struct ubus_subscriber ev;
37 struct uloop_timeout update;
38
39 const char *iface;
40 int ifindex;
41 int wiphy;
42
43 struct ubus_request req;
44 struct uloop_timeout req_timer;
45 int req_state;
46
47 uint32_t obj_id;
48
49 float load_ewma;
50 int load_thr_count;
51
52 uint64_t time, time_busy;
53
54 struct kvlist node_info;
55
56 struct uloop_timeout bss_tm_queries_timeout;
57 struct list_head bss_tm_queries;
58
59 struct {
60 bool present;
61 struct uloop_timeout update;
62 } nl80211;
63 struct {
64 struct ubus_request req;
65 bool req_pending;
66 bool status_complete;
67 } netifd;
68 };
69
70 struct interface;
71
72 struct usteer_remote_host {
73 struct avl_node avl;
74
75 struct list_head nodes;
76 struct blob_attr *host_info;
77 char *addr;
78 };
79
80 struct usteer_remote_node {
81 struct list_head list;
82 struct list_head host_list;
83 const char *name;
84
85 struct usteer_remote_host *host;
86 struct usteer_node node;
87
88 int check;
89 };
90
91 extern struct avl_tree local_nodes;
92 extern struct list_head remote_nodes;
93 extern struct avl_tree remote_hosts;
94
95 #define for_each_local_node(node) \
96 avl_for_each_element(&local_nodes, node, avl) \
97 if (!node->disabled)
98
99 #define for_each_remote_node(rn) \
100 list_for_each_entry(rn, &remote_nodes, list)
101
102 #endif