11 #define EMATCHKINDSIZ 16
21 static inline struct bstr
* bstr_alloc(const char *text
)
23 struct bstr
*b
= calloc(1, sizeof(*b
));
28 b
->data
= strdup(text
);
29 if (b
->data
== NULL
) {
34 b
->len
= strlen(text
);
39 static inline struct bstr
* bstr_new(char *data
, unsigned int len
)
41 struct bstr
*b
= calloc(1, sizeof(*b
));
52 static inline int bstrcmp(struct bstr
*b
, const char *text
)
54 int len
= strlen(text
);
58 return strncmp(b
->data
, text
, len
);
63 static inline unsigned long bstrtoul(struct bstr
*b
)
69 memcpy(buf
, b
->data
, b
->len
);
72 l
= strtol(buf
, &inv
, 0);
73 if (l
== ULONG_MAX
|| inv
== buf
)
79 static inline void bstr_print(FILE *fd
, struct bstr
*b
, int ascii
)
85 for (i
= 0; i
< b
->len
; i
++)
86 fprintf(fd
, "%c", isprint(s
[i
]) ? s
[i
] : '.');
88 for (i
= 0; i
< b
->len
; i
++)
89 fprintf(fd
, "%02x", s
[i
]);
91 for (i
= 0; i
< b
->len
; i
++)
92 fprintf(fd
, "%c", isprint(s
[i
]) ? s
[i
] : '.');
97 static inline struct bstr
*bstr_next(struct bstr
*b
)
109 struct ematch
*child
;
113 static inline struct ematch
* new_ematch(struct bstr
*args
, int inverted
)
115 struct ematch
*e
= calloc(1, sizeof(*e
));
121 e
->inverted
= inverted
;
126 static inline void print_ematch_tree(struct ematch
*tree
)
130 for (t
= tree
; t
; t
= t
->next
) {
136 print_ematch_tree(t
->child
);
140 for (b
= t
->args
; b
; b
= b
->next
)
141 printf("%s%s", b
->data
, b
->next
? " " : "");
144 if (t
->relation
== TCF_EM_REL_AND
)
146 else if (t
->relation
== TCF_EM_REL_OR
)
153 char kind
[EMATCHKINDSIZ
];
155 int (*parse_eopt
)(struct nlmsghdr
*,struct tcf_ematch_hdr
*,
157 int (*print_eopt
)(FILE *, struct tcf_ematch_hdr
*, void *, int);
158 void (*print_usage
)(FILE *);
159 struct ematch_util
*next
;
162 static inline int parse_layer(struct bstr
*b
)
164 if (*((char *) b
->data
) == 'l')
165 return TCF_LAYER_LINK
;
166 else if (*((char *) b
->data
) == 'n')
167 return TCF_LAYER_NETWORK
;
168 else if (*((char *) b
->data
) == 't')
169 return TCF_LAYER_TRANSPORT
;
174 extern int em_parse_error(int err
, struct bstr
*args
, struct bstr
*carg
,
175 struct ematch_util
*, char *fmt
, ...);
176 extern int print_ematch(FILE *, const struct rtattr
*);
177 extern int parse_ematch(int *, char ***, int, struct nlmsghdr
*);