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