]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/m_ematch.h
tc: Remove pointless assignments in batch()
[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 char *data;
17 unsigned int len;
18 int quoted;
19 struct bstr *next;
20 };
21
22 struct bstr *bstr_alloc(const char *text);
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(const struct bstr *b, const char *text)
38 {
39 int len = strlen(text);
40 int d = b->len - len;
41
42 if (d == 0)
43 return strncmp(b->data, text, len);
44
45 return d;
46 }
47
48 static inline struct bstr *bstr_next(struct bstr *b)
49 {
50 return b->next;
51 }
52
53 unsigned long bstrtoul(const struct bstr *b);
54 void bstr_print(FILE *fd, const struct bstr *b, int ascii);
55
56 struct ematch {
57 struct bstr *args;
58 int index;
59 int inverted;
60 int relation;
61 int child_ref;
62 struct ematch *child;
63 struct ematch *next;
64 };
65
66 static inline struct ematch *new_ematch(struct bstr *args, int inverted)
67 {
68 struct ematch *e = calloc(1, sizeof(*e));
69
70 if (e == NULL)
71 return NULL;
72
73 e->args = args;
74 e->inverted = inverted;
75
76 return e;
77 }
78
79 void print_ematch_tree(const struct ematch *tree);
80
81 struct ematch_util {
82 char kind[EMATCHKINDSIZ];
83 int kind_num;
84 int (*parse_eopt)(struct nlmsghdr *, struct tcf_ematch_hdr *,
85 struct bstr *);
86 int (*parse_eopt_argv)(struct nlmsghdr *, struct tcf_ematch_hdr *,
87 int, char **);
88 int (*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int);
89 void (*print_usage)(FILE *);
90 struct ematch_util *next;
91 };
92
93 static inline int parse_layer(const struct bstr *b)
94 {
95 if (*((char *) b->data) == 'l')
96 return TCF_LAYER_LINK;
97 else if (*((char *) b->data) == 'n')
98 return TCF_LAYER_NETWORK;
99 else if (*((char *) b->data) == 't')
100 return TCF_LAYER_TRANSPORT;
101 else
102 return INT_MAX;
103 }
104
105 __attribute__((format(printf, 5, 6)))
106 int em_parse_error(int err, struct bstr *args, struct bstr *carg,
107 struct ematch_util *, char *fmt, ...);
108 int print_ematch(FILE *, const struct rtattr *);
109 int parse_ematch(int *, char ***, int, struct nlmsghdr *);
110
111 #endif