]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/m_ematch.h
dcb: Add a subtool for the DCB APP object
[mirror_iproute2.git] / tc / m_ematch.h
CommitLineData
6054c1eb 1/* SPDX-License-Identifier: GPL-2.0 */
6a805a65
SH
2#ifndef __TC_EMATCH_H_
3#define __TC_EMATCH_H_
4
5#include <ctype.h>
737f15f6
SH
6#include <stdlib.h>
7#include <string.h>
5bd9dd49 8#include <limits.h>
6a805a65
SH
9
10#include "utils.h"
11#include "tc_util.h"
12
13#define EMATCHKINDSIZ 16
14
a8e9f4ae 15struct bstr {
f332d169 16 char *data;
6a805a65
SH
17 unsigned int len;
18 int quoted;
19 struct bstr *next;
20};
21
a8e9f4ae 22struct bstr *bstr_alloc(const char *text);
6a805a65 23
a8e9f4ae 24static inline struct bstr *bstr_new(char *data, unsigned int len)
6a805a65
SH
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
a8e9f4ae 37static inline int bstrcmp(const struct bstr *b, const char *text)
6a805a65
SH
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
48static inline struct bstr *bstr_next(struct bstr *b)
49{
50 return b->next;
51}
52
a8e9f4ae 53unsigned long bstrtoul(const struct bstr *b);
b6da1afc 54
a8e9f4ae 55struct ematch {
6a805a65
SH
56 struct bstr *args;
57 int index;
58 int inverted;
59 int relation;
60 int child_ref;
61 struct ematch *child;
62 struct ematch *next;
63};
64
a8e9f4ae 65static inline struct ematch *new_ematch(struct bstr *args, int inverted)
6a805a65
SH
66{
67 struct ematch *e = calloc(1, sizeof(*e));
68
69 if (e == NULL)
70 return NULL;
71
72 e->args = args;
73 e->inverted = inverted;
74
75 return e;
76}
77
a8e9f4ae 78void print_ematch_tree(const struct ematch *tree);
b6da1afc 79
a8e9f4ae 80struct ematch_util {
6a805a65
SH
81 char kind[EMATCHKINDSIZ];
82 int kind_num;
a8e9f4ae 83 int (*parse_eopt)(struct nlmsghdr *, struct tcf_ematch_hdr *,
6a805a65 84 struct bstr *);
52686203
EB
85 int (*parse_eopt_argv)(struct nlmsghdr *, struct tcf_ematch_hdr *,
86 int, char **);
6a805a65
SH
87 int (*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int);
88 void (*print_usage)(FILE *);
89 struct ematch_util *next;
90};
91
a8e9f4ae 92static inline int parse_layer(const struct bstr *b)
6a805a65
SH
93{
94 if (*((char *) b->data) == 'l')
95 return TCF_LAYER_LINK;
96 else if (*((char *) b->data) == 'n')
97 return TCF_LAYER_NETWORK;
98 else if (*((char *) b->data) == 't')
99 return TCF_LAYER_TRANSPORT;
100 else
101 return INT_MAX;
102}
103
5d5586b0 104__attribute__((format(printf, 5, 6)))
a8e9f4ae 105int em_parse_error(int err, struct bstr *args, struct bstr *carg,
6a805a65 106 struct ematch_util *, char *fmt, ...);
a8e9f4ae
SH
107int print_ematch(FILE *, const struct rtattr *);
108int parse_ematch(int *, char ***, int, struct nlmsghdr *);
6a805a65
SH
109
110#endif