00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_FILTER_ANONYMIZER_HH_
00023 # define WIFI_FRAME_FILTER_ANONYMIZER_HH_
00024
00025 extern "C"
00026 {
00027 # include <stdint.h>
00028 }
00029
00030 # include <set>
00031
00032 # include <wipal/tool/iterable.hh>
00033 # include <wipal/tool/valued_iterator.hh>
00034 # include <wipal/pcap/frame_descriptor.hh>
00035 # include <wipal/wifi/addr.hh>
00036 # include <wipal/wifi/frame/dissector/default_hooks.hh>
00037 # include <wipal/wifi/essid.hh>
00038 # include <wipal/wifi/frame/filter/anon_policies.hh>
00039
00040
00041
00042
00043
00044 namespace wifi
00045 {
00046 namespace frame
00047 {
00048 namespace filter
00049 {
00050
00051 template <class, class, class, class>
00052 struct anonymizer;
00053
00054 namespace internals
00055 {
00056
00057 template <class, class, class, class, class>
00058 struct anonymizer_iterator;
00059
00060 }
00061
00062 }
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071 namespace tool
00072 {
00073
00074 template <class I, class P, class A, class B>
00075 struct types< wifi::frame::filter::anonymizer<I, P, A, B> >
00076 {
00077 typedef wifi::frame::filter::internals::
00078 anonymizer_iterator<I, P, A, B, tool::bottom> iterator;
00079 };
00080
00081 template <class I, class P, class A, class B1, class B2>
00082 struct types< wifi::frame::filter::internals::
00083 anonymizer_iterator<I, P, A, B1, B2> >
00084 {
00085 typedef wifi::frame::filter::anonymizer<I, P, A, B1> iterable_type;
00086 typedef typename pcapxx::frame_descriptor<> value_type;
00087 };
00088
00089 }
00090
00091
00092
00093
00094
00095
00096 namespace wifi
00097 {
00098 namespace frame
00099 {
00100
00102 namespace anon
00103 {
00104
00105 struct dummy_mac_policy
00106 {
00107 addr operator [] (const addr& mac_addr) const;
00108 };
00109
00110 struct dummy_essid_policy
00111 {
00112 essid operator [] (const essid& essid) const;
00113 };
00114
00115 template <class MACAnonPolicy, class ESSIDAnonPolicy>
00116 struct generic_policy: private MACAnonPolicy, private ESSIDAnonPolicy
00117 {
00118 generic_policy(const MACAnonPolicy& macp = MACAnonPolicy (),
00119 const ESSIDAnonPolicy& essidp = ESSIDAnonPolicy ());
00120
00121 addr operator [] (const addr& mac_addr);
00122 essid operator [] (const essid& essid);
00123 };
00124
00125 typedef generic_policy<dummy_mac_policy, dummy_essid_policy>
00126 dummy_policy;
00127
00128 typedef generic_policy<prefix_preserving_mac_policy,
00129 prefix_preserving_essid_policy>
00130 prefix_preserving_policy;
00131
00132 typedef prefix_preserving_policy
00133 default_policy;
00134
00135 }
00136
00137
00138 namespace filter
00139 {
00140
00141 namespace internals
00142 {
00143
00150 template <class I, class P, class A, class B,
00151 class Bottom = tool::bottom>
00152 struct anonymizer_iterator: WP_INHERIT(public tool::valued_iterator,
00153 anonymizer_iterator<I, P, A, B,
00154 Bottom>),
00155 private A
00156 {
00157 typedef WP_GET_EXACT(Bottom, anonymizer_iterator<I, P, A, B, Bottom>)
00158 exact_type;
00159 typedef WP_TYPE(value_type, exact_type) value_type;
00160 typedef WP_TYPE(iterable_type, exact_type) iterable_type;
00161
00162 anonymizer_iterator(const iterable_type& iterable, bool end);
00163
00164 bool equal(const anonymizer_iterator& rhs) const;
00165 void increment();
00166
00167 private:
00168 void anonymize_addrs(const uint8_t* const phy,
00169 const std::set<const addr*>& addrs,
00170 uint8_t* const anon_bytes,
00171 const size_t anon_caplen);
00172
00173 size_t
00174 anonymize_ssid(const typename I::value_type& frm,
00175 const ssid_elt* const ssid,
00176 uint8_t* const anon_bytes,
00177 const size_t anon_caplen);
00178
00179 struct hooks: public dissector_default_hooks
00180 {
00181 hooks();
00182
00183 void
00184 addr_hook(const void*, size_t, unsigned, const addr&);
00185
00186 void
00187 end_of_frame_headers_hook(const void*, size_t, const void*);
00188
00189 type::frame_type ty;
00190 const uint8_t* end;
00191 std::set<const addr*> addrs;
00192 const ssid_elt* ssid;
00193 };
00194
00195 I next_;
00196 I last_;
00197 };
00198
00199 }
00200
00201
00202 template <class InputIterator,
00203 class Phy,
00204 class AnonPolicy = anon::default_policy,
00205 class Bottom = tool::bottom>
00206 struct anonymizer: WP_INHERIT(public tool::iterable,
00207 anonymizer<InputIterator, Phy, AnonPolicy,
00208 Bottom>),
00209 private AnonPolicy
00210 {
00211 anonymizer(const InputIterator& first, const InputIterator& last,
00212 const AnonPolicy& anon_policy = AnonPolicy ());
00213
00214 private:
00215 InputIterator first_;
00216 InputIterator last_;
00217
00218 friend struct internals::anonymizer_iterator<InputIterator,
00219 Phy,
00220 AnonPolicy,
00221 Bottom, tool::bottom>;
00222 };
00223
00224 }
00225 }
00226 }
00227
00228 # include "anonymizer.hxx"
00229
00230 #endif