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