-
Notifications
You must be signed in to change notification settings - Fork 81
/
classifier.hh
108 lines (96 loc) · 3.67 KB
/
classifier.hh
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
#ifndef CLICK_CLASSIFIER_HH
#define CLICK_CLASSIFIER_HH
#include <click/element.hh>
#include <click/batchelement.hh>
#include "classification.hh"
CLICK_DECLS
/*
* =c
* Classifier(pattern1, ..., patternN)
* =s classification
* classifies packets by contents
* =d
* Classifies packets. The Classifier has N outputs, each associated with the
* corresponding pattern from the configuration string.
* A pattern is a set of clauses, where each clause is either "offset/value"
* or "offset/value%mask". A pattern matches if the packet has the indicated
* value at each offset.
*
* The clauses in each pattern are separated
* by spaces. A clause consists of the offset, "/", the value, and (optionally)
* "%" and a mask. The offset is in decimal. The value and mask are in hex.
* The length of the value is implied by the number of hex digits, which must
* be even. "?" is also allowed as a "hex digit"; it means "don't care about
* the value of this nibble".
*
* If present, the mask must have the same number of hex digits as the value.
* The matcher will only check bits that are 1 in the mask.
*
* A clause may be preceded by "!", in which case the clause must NOT match
* the packet.
*
* As a special case, a pattern consisting of "-" matches every packet.
*
* The patterns are scanned in order, and the packet is sent to the output
* corresponding to the first matching pattern. Thus more specific patterns
* should come before less specific ones. You will get a warning if no packet
* could ever match a pattern. Usually, this is because an earlier pattern is
* more general, or because your pattern is contradictory (`12/0806 12/0800').
*
* =n
*
* The IPClassifier and IPFilter elements have a friendlier syntax if you are
* classifying IP packets.
*
* =e
* For example,
*
* Classifier(12/0806 20/0001,
* 12/0806 20/0002,
* 12/0800,
* -);
*
* creates an element with four outputs intended to process
* Ethernet packets.
* ARP requests are sent to output 0, ARP replies are sent to
* output 1, IP packets to output 2, and all others to output 3.
*
* =h program read-only
* Returns a human-readable definition of the program the Classifier element
* is using to classify packets. At each step in the program, four bytes
* of packet data are ANDed with a mask and compared against four bytes of
* classifier pattern.
*
* The Classifier patterns above compile into the following program:
*
* 0 12/08060000%ffff0000 yes->step 1 no->step 3
* 1 20/00010000%ffff0000 yes->[0] no->step 2
* 2 20/00020000%ffff0000 yes->[1] no->[3]
* 3 12/08000000%ffff0000 yes->[2] no->[3]
* safe length 22
* alignment offset 0
*
* =a IPClassifier, IPFilter */
class Classifier : public BatchElement { public:
Classifier() CLICK_COLD;
const char *class_name() const override { return "Classifier"; }
const char *port_count() const override { return "1/-"; }
const char *processing() const override { return PUSH; }
// this element needs AlignmentInfo, so supply the "A" flag
const char *flags() const { return "A"; }
bool can_live_reconfigure() const { return true; }
int configure(Vector<String> &conf, ErrorHandler *errh) CLICK_COLD;
void add_handlers() CLICK_COLD;
#if HAVE_BATCH
void push_batch(int, PacketBatch *);
#endif
void push(int, Packet *);
Classification::Wordwise::Program empty_program(ErrorHandler *errh) const;
static void parse_program(Classification::Wordwise::Program &prog,
Vector<String> &conf, ErrorHandler *errh);
protected:
Classification::Wordwise::Program _prog;
static String program_string(Element *, void *);
};
CLICK_ENDDECLS
#endif