]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/m_ematch.h
man: tc-csum.8: Fix inconsistency in example description
[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
15struct bstr
16{
f332d169 17 char *data;
6a805a65
SH
18 unsigned int len;
19 int quoted;
20 struct bstr *next;
21};
22
b6da1afc 23extern struct bstr * bstr_alloc(const char *text);
6a805a65
SH
24
25static 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
38static 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)
f332d169 44 return strncmp(b->data, text, len);
6a805a65
SH
45
46 return d;
47}
48
6a805a65
SH
49static inline struct bstr *bstr_next(struct bstr *b)
50{
51 return b->next;
52}
53
b6da1afc
SH
54extern unsigned long bstrtoul(const struct bstr *b);
55extern void bstr_print(FILE *fd, const struct bstr *b, int ascii);
56
57
6a805a65
SH
58struct 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
69static 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
b6da1afc
SH
82extern void print_ematch_tree(const struct ematch *tree);
83
6a805a65
SH
84
85struct 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 (*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int);
92 void (*print_usage)(FILE *);
93 struct ematch_util *next;
94};
95
96static inline int parse_layer(struct bstr *b)
97{
98 if (*((char *) b->data) == 'l')
99 return TCF_LAYER_LINK;
100 else if (*((char *) b->data) == 'n')
101 return TCF_LAYER_NETWORK;
102 else if (*((char *) b->data) == 't')
103 return TCF_LAYER_TRANSPORT;
104 else
105 return INT_MAX;
106}
107
108extern int em_parse_error(int err, struct bstr *args, struct bstr *carg,
109 struct ematch_util *, char *fmt, ...);
110extern int print_ematch(FILE *, const struct rtattr *);
111extern int parse_ematch(int *, char ***, int, struct nlmsghdr *);
112
113#endif