Blame tc/m_ematch.h

Packit Service 3880ab
/* SPDX-License-Identifier: GPL-2.0 */
Packit Service 3880ab
#ifndef __TC_EMATCH_H_
Packit Service 3880ab
#define __TC_EMATCH_H_
Packit Service 3880ab
Packit Service 3880ab
#include <ctype.h>
Packit Service 3880ab
#include <stdlib.h>
Packit Service 3880ab
#include <string.h>
Packit Service 3880ab
#include <limits.h>
Packit Service 3880ab
Packit Service 3880ab
#include "utils.h"
Packit Service 3880ab
#include "tc_util.h"
Packit Service 3880ab
Packit Service 3880ab
#define EMATCHKINDSIZ 16
Packit Service 3880ab
Packit Service 3880ab
struct bstr {
Packit Service 3880ab
	char	*data;
Packit Service 3880ab
	unsigned int	len;
Packit Service 3880ab
	int		quoted;
Packit Service 3880ab
	struct bstr	*next;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
struct bstr *bstr_alloc(const char *text);
Packit Service 3880ab
Packit Service 3880ab
static inline struct bstr *bstr_new(char *data, unsigned int len)
Packit Service 3880ab
{
Packit Service 3880ab
	struct bstr *b = calloc(1, sizeof(*b));
Packit Service 3880ab
Packit Service 3880ab
	if (b == NULL)
Packit Service 3880ab
		return NULL;
Packit Service 3880ab
Packit Service 3880ab
	b->data = data;
Packit Service 3880ab
	b->len = len;
Packit Service 3880ab
Packit Service 3880ab
	return b;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
static inline int bstrcmp(const struct bstr *b, const char *text)
Packit Service 3880ab
{
Packit Service 3880ab
	int len = strlen(text);
Packit Service 3880ab
	int d = b->len - len;
Packit Service 3880ab
Packit Service 3880ab
	if (d == 0)
Packit Service 3880ab
		return strncmp(b->data, text, len);
Packit Service 3880ab
Packit Service 3880ab
	return d;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
static inline struct bstr *bstr_next(struct bstr *b)
Packit Service 3880ab
{
Packit Service 3880ab
	return b->next;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
unsigned long bstrtoul(const struct bstr *b);
Packit Service 3880ab
Packit Service 3880ab
struct ematch {
Packit Service 3880ab
	struct bstr	*args;
Packit Service 3880ab
	int		index;
Packit Service 3880ab
	int		inverted;
Packit Service 3880ab
	int		relation;
Packit Service 3880ab
	int		child_ref;
Packit Service 3880ab
	struct ematch	*child;
Packit Service 3880ab
	struct ematch	*next;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
static inline struct ematch *new_ematch(struct bstr *args, int inverted)
Packit Service 3880ab
{
Packit Service 3880ab
	struct ematch *e = calloc(1, sizeof(*e));
Packit Service 3880ab
Packit Service 3880ab
	if (e == NULL)
Packit Service 3880ab
		return NULL;
Packit Service 3880ab
Packit Service 3880ab
	e->args = args;
Packit Service 3880ab
	e->inverted = inverted;
Packit Service 3880ab
Packit Service 3880ab
	return e;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
void print_ematch_tree(const struct ematch *tree);
Packit Service 3880ab
Packit Service 3880ab
struct ematch_util {
Packit Service 3880ab
	char			kind[EMATCHKINDSIZ];
Packit Service 3880ab
	int			kind_num;
Packit Service 3880ab
	int	(*parse_eopt)(struct nlmsghdr *, struct tcf_ematch_hdr *,
Packit Service 3880ab
			      struct bstr *);
Packit Service 3880ab
	int	(*parse_eopt_argv)(struct nlmsghdr *, struct tcf_ematch_hdr *,
Packit Service 3880ab
				   int, char **);
Packit Service 3880ab
	int	(*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int);
Packit Service 3880ab
	void	(*print_usage)(FILE *);
Packit Service 3880ab
	struct ematch_util	*next;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
static inline int parse_layer(const struct bstr *b)
Packit Service 3880ab
{
Packit Service 3880ab
	if (*((char *) b->data) == 'l')
Packit Service 3880ab
		return TCF_LAYER_LINK;
Packit Service 3880ab
	else if (*((char *) b->data) == 'n')
Packit Service 3880ab
		return TCF_LAYER_NETWORK;
Packit Service 3880ab
	else if (*((char *) b->data) == 't')
Packit Service 3880ab
		return TCF_LAYER_TRANSPORT;
Packit Service 3880ab
	else
Packit Service 3880ab
		return INT_MAX;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
__attribute__((format(printf, 5, 6)))
Packit Service 3880ab
int em_parse_error(int err, struct bstr *args, struct bstr *carg,
Packit Service 3880ab
		   struct ematch_util *, char *fmt, ...);
Packit Service 3880ab
int print_ematch(FILE *, const struct rtattr *);
Packit Service 3880ab
int parse_ematch(int *, char ***, int, struct nlmsghdr *);
Packit Service 3880ab
Packit Service 3880ab
#endif