forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
filtercore.cc
761 lines (666 loc) · 21.4 KB
/
filtercore.cc
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/*
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 <sstream>
#include "util.h"
#include "filtercore.h"
FilterCore::FilterCore() {
fprintf(stderr, "FATAL OOPS: FilterCore() called w/ no globalreg\n");
exit(1);
}
FilterCore::FilterCore(GlobalRegistry *in_globalreg) {
globalreg = in_globalreg;
bssid_invert = -1;
source_invert = -1;
dest_invert = -1;
bssid_hit = 0;
source_hit = 0;
dest_hit = 0;
#ifdef HAVE_LIBPCRE
pcre_invert = -1;
pcre_hit = 0;
#endif
}
#define _filter_stacker_none 0
#define _filter_stacker_mac 1
#define _filter_stacker_pcre 2
#define _filter_type_none -1
#define _filter_type_bssid 0
#define _filter_type_source 1
#define _filter_type_dest 2
#define _filter_type_any 3
#define _filter_type_pcre 4
int FilterCore::AddFilterLine(std::string filter_str) {
_kis_lex_rec ltop;
int type = _filter_stacker_none;
int mtype = _filter_type_none;
int negate = -1;
std::string errstr;
// Local copies to add so we can error out cleanly... This is a cheap
// hack but it lets us avoid a bunch of if's
std::map<int, std::vector<mac_addr> > local_maps;
std::map<int, int> local_inverts;
#ifdef HAVE_LIBPCRE
std::vector<pcre_filter *> local_pcre;
#endif
std::vector<mac_addr> macvec;
local_inverts[_filter_type_bssid] = -1;
local_inverts[_filter_type_source] = -1;
local_inverts[_filter_type_dest] = -1;
local_inverts[_filter_type_any] = -1;
local_inverts[_filter_type_pcre] = -1;
std::list<_kis_lex_rec> precs = LexString(filter_str, errstr);
if (precs.size() == 0) {
_MSG(errstr, MSGFLAG_ERROR);
return -1;
}
while (precs.size() > 0) {
// Grab the top of the stack, pop the lexer
ltop = precs.front();
precs.pop_front();
// Ignore 'none'
if (ltop.type == _kis_lex_none) {
continue;
}
// If we don't have anything in the stack...
if (type == _filter_stacker_none) {
// Ignore delimiters, they just break up mac addresses
if (ltop.type == _kis_lex_delim)
continue;
if (ltop.type != _kis_lex_string) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected an "
"unquoted string", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
std::string uqstr = StrLower(ltop.data);
if (uqstr == "bssid") {
type = _filter_stacker_mac;
mtype = _filter_type_bssid;
} else if (uqstr == "source") {
type = _filter_stacker_mac;
mtype = _filter_type_source;
} else if (uqstr == "dest") {
type = _filter_stacker_mac;
mtype = _filter_type_dest;
} else if (uqstr == "any") {
type = _filter_stacker_mac;
mtype = _filter_type_any;
} else if (uqstr == "pcre") {
type = _filter_stacker_pcre;
} else {
_MSG("Couldn't parse filter line '" + filter_str + "', expected one "
"of BSSID, SOURCE, DEST, ANY, PCRE", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
// check for a '('
if (precs.size() <= 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected (",
MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
ltop = precs.front();
precs.pop_front();
if (ltop.type != _kis_lex_popen) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected (",
MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
// Peek for a negation
if (precs.size() <= 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected "
"contents", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
continue;
}
if (type == _filter_stacker_mac) {
int addr_loc_negate = 0;
if (ltop.type == _kis_lex_negate) {
if (negate == 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', cannot "
"mix negated and non-negated MAC addresses on the same "
"filter", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
}
// Double-hop on negates
negate = 1;
addr_loc_negate = 1;
ltop = precs.front();
precs.pop_front();
}
// Look for an address as a string
if (ltop.type != _kis_lex_string) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected "
"MAC address", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
if (negate == 1 && addr_loc_negate != 1) {
_MSG("Couldn't parse filter line '" + filter_str + "', cannot "
"mix inverted and non-inverted MAC addresses on the same "
"filter", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
mac_addr mymac = ltop.data.c_str();
if (mymac.error) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected "
"MAC address and could not interpret '" + ltop.data + "'",
MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
// Add it to the local map for this type
(local_maps[mtype]).push_back(mymac);
// Peek at the next item
if (precs.size() <= 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected ',' "
"or ')'", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
ltop = precs.front();
precs.pop_front();
// If it's a delimiter, skip over it and continue
if (ltop.type == _kis_lex_delim)
continue;
// if it's a close paren, close down and save/errorcheck the negation
if (ltop.type == _kis_lex_pclose) {
if (local_inverts[mtype] != -1 && local_inverts[mtype] != negate) {
_MSG("Couldn't parse filter line '" + filter_str + "', filter "
"has an illegal mix of normal and inverted addresses. "
"A filter type must be either all inverted addresses or all "
"standard addresses.", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
if (negate < 0)
negate = 0;
local_inverts[mtype] = negate;
type = _filter_stacker_none;
mtype = _filter_type_none;
negate = 0;
continue;
}
// Fall through and hit errors about anything else
_MSG("Couldn't parse filter line '" + filter_str + "', expected ',' "
"or ')'", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
if (type == _filter_stacker_pcre) {
#ifndef HAVE_LIBPCRE
// Catch libpcre not being here
_MSG("Couldn't parse filter line '" + filter_str + "', filter "
"uses PCRE regular expressions and this instance of Kismet "
"was not compiled with libpcre support.", MSGFLAG_ERROR);
return -1;
#else
// Look for a quoted string
if (ltop.type != _kis_lex_quotestring) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected "
"quoted string", MSGFLAG_ERROR);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
}
// local_pcre.push_back(ltop.data);
// Try to parse and study the PCRE
pcre_filter *filt = new pcre_filter;
const char *error, *study_err;
int erroffset;
std::ostringstream osstr;
filt->re =
pcre_compile(ltop.data.c_str(), 0, &error, &erroffset, NULL);
if (filt->re == NULL) {
osstr << "Couldn't parse filter line '" << filter_str << "', PCRE "
"compilation failure '" << error << "' at offset " << erroffset;
_MSG(osstr.str(), MSGFLAG_ERROR);
delete(filt);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
}
filt->study = pcre_study(filt->re, 0, &study_err);
if (filt->study == NULL) {
osstr << "Couldn't parse filter line '" << filter_str << "', PCRE "
"study/optimization failure '" << study_err << "'";
_MSG(osstr.str(), MSGFLAG_ERROR);
pcre_free(filt->re);
delete(filt);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
}
filt->filter = ltop.data;
local_pcre.push_back(filt);
// Peek at the next item
if (precs.size() <= 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', expected ',' "
"or ')'", MSGFLAG_ERROR);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
}
ltop = precs.front();
precs.pop_front();
// If it's a delimiter, skip over it and continue
if (ltop.type == _kis_lex_delim) {
continue;
}
// If it's a close paren, close down
if (ltop.type == _kis_lex_pclose) {
if (local_inverts[_filter_type_pcre] != -1 &&
local_inverts[_filter_type_pcre] != negate) {
_MSG("Couldn't parse filter line '" + filter_str + "', filter "
"has an illegal mix of normal and inverted PCRE filters. "
"A filter type must be either all inverted addresses or all "
"standard addresses.", MSGFLAG_ERROR);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
}
local_inverts[_filter_type_pcre] = negate;
type = _filter_stacker_none;
mtype = _filter_type_none;
negate = 0;
continue;
}
// Fall through and hit errors about anything else
_MSG("Couldn't parse filter line '" + filter_str + "', expected ',' "
"or ')'", MSGFLAG_ERROR);
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
return -1;
#endif
}
}
// Check all the negate joins before we edit anything
int negfail = 0;
negate = local_inverts[_filter_type_bssid];
if (negate != -1) {
macvec = local_maps[_filter_type_bssid];
if (bssid_invert != -1 && negate != bssid_invert) {
negfail = 1;
}
}
negate = local_inverts[_filter_type_source];
if (negate != -1) {
macvec = local_maps[_filter_type_source];
if (source_invert != -1 && negate != source_invert) {
negfail = 1;
}
}
negate = local_inverts[_filter_type_dest];
if (negate != -1) {
macvec = local_maps[_filter_type_dest];
if (dest_invert != -1 && negate != dest_invert) {
negfail = 1;
}
}
negate = local_inverts[_filter_type_any];
if (negate != -1) {
macvec = local_maps[_filter_type_any];
if ((dest_invert != 1 && negate != dest_invert) ||
(source_invert != 1 && negate != source_invert) ||
(bssid_invert != 1 && negate != bssid_invert)) {
_MSG("Couldn't parse filter line '" + filter_str + "', filter uses the "
"ANY filter term. The ANY filter can only be used on inverted "
"matches to discard any packets not matching the specified address, "
"and the DEST, SOURCE, and BSSID filter terms must contain only "
"inverted matches.", MSGFLAG_ERROR);
negfail = 1;
}
}
#ifdef HAVE_LIBPCRE
negate = local_inverts[_filter_type_pcre];
if (negate != -1) {
macvec = local_maps[_filter_type_pcre];
if (pcre_invert != -1 && negate != pcre_invert) {
negfail = 1;
}
}
#endif
if (negfail != 0) {
_MSG("Couldn't parse filter line '" + filter_str + "', filter "
"has an illegal mix of normal and inverted addresses. "
"A filter type must be either all inverted addresses or all "
"standard addresses.", MSGFLAG_ERROR);
#ifdef HAVE_LIBPCRE
for (unsigned zed = 0; zed < local_pcre.size(); zed++) {
pcre_free(local_pcre[zed]->re);
pcre_free(local_pcre[zed]->study);
delete(local_pcre[zed]);
}
#endif
return -1;
}
// Join all the maps back up with the real filters
negate = local_inverts[_filter_type_bssid];
if (negate != -1) {
macvec = local_maps[_filter_type_bssid];
bssid_invert = negate;
for (unsigned int x = 0; x < macvec.size(); x++) {
bssid_map.insert(macvec[x], 1);
}
}
negate = local_inverts[_filter_type_source];
if (negate != -1) {
macvec = local_maps[_filter_type_source];
source_invert = negate;
for (unsigned int x = 0; x < macvec.size(); x++) {
source_map.insert(macvec[x], 1);
}
}
negate = local_inverts[_filter_type_dest];
if (negate != -1) {
macvec = local_maps[_filter_type_dest];
dest_invert = negate;
for (unsigned int x = 0; x < macvec.size(); x++) {
dest_map.insert(macvec[x], 1);
}
}
negate = local_inverts[_filter_type_any];
if (negate != -1) {
macvec = local_maps[_filter_type_any];
for (unsigned int x = 0; x < macvec.size(); x++) {
dest_map.insert(macvec[x], 1);
source_map.insert(macvec[x], 1);
bssid_map.insert(macvec[x], 1);
}
}
#ifdef HAVE_LIBPCRE
negate = local_inverts[_filter_type_pcre];
if (negate != -1) {
pcre_invert = negate;
for (unsigned int x = 0; x < local_pcre.size(); x++) {
pcre_vec.push_back(local_pcre[x]);
}
}
#endif
return 1;
#if 0
// Break it into filter terms
size_t parse_pos = 0;
size_t parse_error = 0;
while (parse_pos < filter_str.length()) {
size_t addr_term_end;
size_t address_target = 0; // 1=bssid 2=source 4=dest 7=any
if (filter_str[parse_pos] == ',' || filter_str[parse_pos] == ' ') {
parse_pos++;
continue;
}
if ((addr_term_end = filter_str.find('(', parse_pos + 1)) == string::npos) {
_MSG("Couldn't parse filter line '" + filter_str + "' no '(' found",
MSGFLAG_ERROR);
parse_error = 1;
break;
}
string addr_term = StrLower(filter_str.substr(parse_pos,
addr_term_end - parse_pos));
parse_pos = addr_term_end + 1;
if (addr_term.length() == 0) {
_MSG("Couldn't parse filter line '" + filter_str + "' no address type "
"given.", MSGFLAG_ERROR);
parse_error = 1;
break;
}
if (addr_term == "any") {
address_target = 7;
} else if (addr_term == "bssid") {
address_target = 1;
} else if (addr_term == "source") {
address_target = 2;
} else if (addr_term == "dest") {
address_target = 4;
} else {
_MSG("Couldn't parse filter line '" + filter_str + "' unknown address "
"type '" + addr_term + "' (expected 'any', 'bssid', 'source', "
"'dest'", MSGFLAG_ERROR);
parse_error = 1;
break;
}
if ((addr_term_end = filter_str.find(')', parse_pos + 1)) == string::npos) {
_MSG("Couldn't parse filter line '" + filter_str + "', no ')' found",
MSGFLAG_ERROR);
parse_error = 1;
break;
}
string term_contents = filter_str.substr(parse_pos,
addr_term_end - parse_pos);
parse_pos = addr_term_end + 1;
if (term_contents.length() == 0) {
_MSG("Couldn't parse filter line '" + filter_str + "' no addresses "
"listed after address type", MSGFLAG_ERROR);
parse_error = 1;
break;
}
size_t term_parse_pos = 0;
while (term_parse_pos < term_contents.length()) {
size_t term_end;
int invert = 0;
if (term_contents[term_parse_pos] == ' ' ||
term_contents[term_parse_pos] == ',') {
term_parse_pos++;
continue;
}
if (term_contents[term_parse_pos] == '!') {
invert = 1;
term_parse_pos++;
}
if ((term_end = term_contents.find(',',
term_parse_pos + 1)) == string::npos)
term_end = term_contents.length();
string single_addr = term_contents.substr(term_parse_pos,
term_end - term_parse_pos);
mac_addr mac = single_addr.c_str();
if (mac.error != 0) {
_MSG("Couldn't parse filter string '" + filter_str + "' MAC "
"address '" + single_addr + "'", MSGFLAG_ERROR);
parse_error = 1;
break;
}
// Catch non-inverted 'ANY'
if (address_target == 7 && invert == 0) {
_MSG("Filtering address type 'ANY' will discard all packets. The "
"'ANY' address type can only be used on inverted matches to "
"discard any packets not matching the specified.",
MSGFLAG_ERROR);
parse_error = 1;
break;
}
// Do an insert check for mismatched inversion flags, set it,
// and set the inversion for future address types
if (address_target & 0x01) {
if (bssid_invert != -1 && invert != bssid_invert) {
_MSG("BSSID filter '" + filter_str + "' has an illegal mix of "
"normal and inverted addresses. A filter must be either "
"all inverted addresses or all standard addresses.",
MSGFLAG_ERROR);
return -1;
}
bssid_map.insert(mac, invert);
bssid_invert = invert;
} if (address_target & 0x02) {
if (source_invert != -1 && invert != source_invert) {
_MSG("SOURCE filter '" + filter_str + "' has an illegal mix of "
"normal and inverted addresses. A filter must be either "
"all inverted addresses or all standard addresses.",
MSGFLAG_ERROR);
return -1;
}
source_map.insert(mac, invert);
source_invert = invert;
} if (address_target & 0x04) {
if (dest_invert != -1 && invert != dest_invert) {
_MSG("DEST filter '" + filter_str + "' has an illegal mix of "
"normal and inverted addresses. A filter must be either "
"all inverted addresses or all standard addresses.",
MSGFLAG_ERROR);
return -1;
}
dest_map.insert(mac, invert);
dest_invert = invert;
}
term_parse_pos = term_end + 1;
}
}
if (parse_error == 1)
return -1;
return 1;
#endif
}
int FilterCore::RunFilter(mac_addr bssidmac, mac_addr sourcemac,
mac_addr destmac) {
int hit = 0;
// Clumsy artifact of how iters are defined for macmap currently, must
// be defined as an assign
macmap<int>::iterator fitr = bssid_map.find(bssidmac);
if ((fitr != bssid_map.end() && bssid_invert == 1) ||
(fitr == bssid_map.end() && bssid_invert == 0)) {
bssid_hit++;
hit = 1;
}
fitr = source_map.find(sourcemac);
if ((fitr != source_map.end() && source_invert == 1) ||
(fitr == source_map.end() && source_invert == 0)) {
source_hit++;
hit = 1;
}
fitr = dest_map.find(destmac);
if ((fitr != dest_map.end() && dest_invert == 1) ||
(fitr == dest_map.end() && dest_invert == 0)) {
dest_hit++;
hit = 1;
}
return hit;
}
int FilterCore::FetchPCREHits() {
#ifndef HAVE_LIBPCRE
return 0;
#else
return pcre_hit;
#endif
}
int FilterCore::RunPcreFilter(std::string in_text) {
#ifndef HAVE_LIBPCRE
return 0;
#else
int ovector[128];
int rc;
for (unsigned int x = 0; x < pcre_vec.size(); x++) {
rc = pcre_exec(pcre_vec[x]->re, pcre_vec[x]->study, in_text.c_str(),
in_text.length(), 0, 0, ovector, 128);
if ((rc >= 0 && pcre_invert == 0) || (rc < 0 && pcre_invert == 1))
return 1;
}
#endif
return 0;
}