]>
Commit | Line | Data |
---|---|---|
6a805a65 SH |
1 | #ifndef __TC_EMATCH_H_ |
2 | #define __TC_EMATCH_H_ | |
3 | ||
4 | #include <ctype.h> | |
737f15f6 SH |
5 | #include <stdlib.h> |
6 | #include <string.h> | |
5bd9dd49 | 7 | #include <limits.h> |
6a805a65 SH |
8 | |
9 | #include "utils.h" | |
10 | #include "tc_util.h" | |
11 | ||
12 | #define EMATCHKINDSIZ 16 | |
13 | ||
14 | struct bstr | |
15 | { | |
f332d169 | 16 | char *data; |
6a805a65 SH |
17 | unsigned int len; |
18 | int quoted; | |
19 | struct bstr *next; | |
20 | }; | |
21 | ||
b6da1afc | 22 | extern struct bstr * bstr_alloc(const char *text); |
6a805a65 SH |
23 | |
24 | static inline struct bstr * bstr_new(char *data, unsigned int len) | |
25 | { | |
26 | struct bstr *b = calloc(1, sizeof(*b)); | |
27 | ||
28 | if (b == NULL) | |
29 | return NULL; | |
30 | ||
31 | b->data = data; | |
32 | b->len = len; | |
33 | ||
34 | return b; | |
35 | } | |
36 | ||
37 | static inline int bstrcmp(struct bstr *b, const char *text) | |
38 | { | |
39 | int len = strlen(text); | |
40 | int d = b->len - len; | |
41 | ||
42 | if (d == 0) | |
f332d169 | 43 | return strncmp(b->data, text, len); |
6a805a65 SH |
44 | |
45 | return d; | |
46 | } | |
47 | ||
6a805a65 SH |
48 | static inline struct bstr *bstr_next(struct bstr *b) |
49 | { | |
50 | return b->next; | |
51 | } | |
52 | ||
b6da1afc SH |
53 | extern unsigned long bstrtoul(const struct bstr *b); |
54 | extern void bstr_print(FILE *fd, const struct bstr *b, int ascii); | |
55 | ||
56 | ||
6a805a65 SH |
57 | struct ematch |
58 | { | |
59 | struct bstr *args; | |
60 | int index; | |
61 | int inverted; | |
62 | int relation; | |
63 | int child_ref; | |
64 | struct ematch *child; | |
65 | struct ematch *next; | |
66 | }; | |
67 | ||
68 | static inline struct ematch * new_ematch(struct bstr *args, int inverted) | |
69 | { | |
70 | struct ematch *e = calloc(1, sizeof(*e)); | |
71 | ||
72 | if (e == NULL) | |
73 | return NULL; | |
74 | ||
75 | e->args = args; | |
76 | e->inverted = inverted; | |
77 | ||
78 | return e; | |
79 | } | |
80 | ||
b6da1afc SH |
81 | extern void print_ematch_tree(const struct ematch *tree); |
82 | ||
6a805a65 SH |
83 | |
84 | struct ematch_util | |
85 | { | |
86 | char kind[EMATCHKINDSIZ]; | |
87 | int kind_num; | |
88 | int (*parse_eopt)(struct nlmsghdr *,struct tcf_ematch_hdr *, | |
89 | struct bstr *); | |
90 | int (*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int); | |
91 | void (*print_usage)(FILE *); | |
92 | struct ematch_util *next; | |
93 | }; | |
94 | ||
95 | static inline int parse_layer(struct bstr *b) | |
96 | { | |
97 | if (*((char *) b->data) == 'l') | |
98 | return TCF_LAYER_LINK; | |
99 | else if (*((char *) b->data) == 'n') | |
100 | return TCF_LAYER_NETWORK; | |
101 | else if (*((char *) b->data) == 't') | |
102 | return TCF_LAYER_TRANSPORT; | |
103 | else | |
104 | return INT_MAX; | |
105 | } | |
106 | ||
107 | extern int em_parse_error(int err, struct bstr *args, struct bstr *carg, | |
108 | struct ematch_util *, char *fmt, ...); | |
109 | extern int print_ematch(FILE *, const struct rtattr *); | |
110 | extern int parse_ematch(int *, char ***, int, struct nlmsghdr *); | |
111 | ||
112 | #endif |