forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_filter.h
152 lines (113 loc) · 5.78 KB
/
class_filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "packetchain.h"
#include "packet.h"
#include "trackedcomponent.h"
#include "eventbus.h"
// Common class-based filter mechanism which can be used in multiple locations;
// implements basic default behavior and REST endpoints.
//
// Filters act on 'true' results: Default behavior of 'true' defaults to BLOCKING
// the action, behavior of 'false' defaults to PASSING actions.
class class_filter : public tracker_component {
public:
class_filter(const std::string& in_id, const std::string& in_description,
const std::string& in_type);
virtual ~class_filter() {
local_locker l(&mutex);
}
__ProxyGet(filter_id, std::string, std::string, filter_id);
__ProxyGet(filter_description, std::string, std::string, filter_description);
__ProxyGet(filter_type, std::string, std::string, filter_type);
__Proxy(filter_default, uint8_t, bool, bool, filter_default);
// Filtering actions are custom per subclass
protected:
bool filterstring_to_bool(const std::string& str);
__ProxySet(filter_id, std::string, std::string, filter_id);
__ProxySet(filter_description, std::string, std::string, filter_description);
__ProxySet(filter_type, std::string, std::string, filter_type);
virtual void register_fields() override {
tracker_component::register_fields();
register_field("kismet.classfilter.id", "Filter ID/Endpoint", &filter_id);
register_field("kismet.classfilter.description", "Filter description", &filter_description);
register_field("kismet.classfilter.type", "Filter mechanism", &filter_type);
register_field("kismet.classfilter.default", "Default filter (pass/reject)", &filter_default);
}
kis_recursive_timed_mutex mutex;
std::string base_uri;
std::shared_ptr<tracker_element_string> filter_id;
std::shared_ptr<tracker_element_string> filter_description;
std::shared_ptr<tracker_element_string> filter_type;
std::shared_ptr<tracker_element_uint8> filter_default;
// Default endpoint
std::shared_ptr<kis_net_httpd_simple_post_endpoint> default_endp;
int default_set_endp_handler(std::ostream& stream, shared_structured post_structured);
// Default display endpoint
std::shared_ptr<kis_net_httpd_simple_tracked_endpoint> self_endp;
// Build the return object; subfilters must implement this to bypass class hierarchy & call
// build_self_content
virtual std::shared_ptr<tracker_element_map> self_endp_handler() = 0;
// Cascading build
virtual void build_self_content(std::shared_ptr<tracker_element_map> content);
};
// MAC based filter
class class_filter_mac_addr : public class_filter {
public:
class_filter_mac_addr(const std::string& in_id, const std::string& in_descripton);
virtual ~class_filter_mac_addr();
virtual bool filter(mac_addr in_mac, unsigned int in_phy);
virtual void set_filter(mac_addr in_mac, const std::string& in_phy, bool value);
virtual void remove_filter(mac_addr in_mac, const std::string& in_phy);
protected:
std::shared_ptr<device_tracker> devicetracker;
std::shared_ptr<event_bus> eventbus;
unsigned long eb_id;
void update_phy_map(std::shared_ptr<eventbus_event> evt);
// Filters are stored in integer-indexed local form, but also a constructed tiered
// map for presentation out the rest interface:
// map[string, phy] -> map[mac, boolean].
virtual void register_fields() override {
class_filter::register_fields();
// Phy-based map
register_field("kismet.classfilter.macaddr.address_by_phy",
"MAC address filters", &filter_phy_block);
// Mac based map filter_sub_mac_id =
register_field("kismet.classfilter.macaddr.filter_block",
tracker_element_factory<tracker_element_mac_map>(),
"MAC address filters");
// Filter value
filter_sub_value_id =
register_field("kismet.classfilter.macaddr.value",
tracker_element_factory<tracker_element_uint8>(),
"Filter value");
}
std::shared_ptr<tracker_element_string_map> filter_phy_block;
// Nested phy types
int filter_sub_mac_id, filter_sub_value_id;
// Internal fast lookup tables per-phy we use for actual filtering
std::map<int, std::map<mac_addr, bool>> phy_mac_filter_map;
// Internal unknown phy map for filters registered before we had a phy ID
std::map<std::string, std::map<mac_addr, bool>> unknown_phy_mac_filter_map;
// Address management endpoint keyed on path
std::shared_ptr<kis_net_httpd_path_post_endpoint> macaddr_edit_endp;
unsigned int edit_endp_handler(std::ostream& stream, const std::vector<std::string>& path,
shared_structured structured);
std::shared_ptr<kis_net_httpd_path_post_endpoint> macaddr_remove_endp;
unsigned int remove_endp_handler(std::ostream& stream, const std::vector<std::string> &path,
shared_structured structured);
virtual std::shared_ptr<tracker_element_map> self_endp_handler() override;
virtual void build_self_content(std::shared_ptr<tracker_element_map> content) override;
};