summaryrefslogtreecommitdiffstats
path: root/include/obj.h
blob: edbf023f5cdd39d8af08199c896caf584985261f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _OBJ_OPS_H_
#define _OBJ_OPS_H_

#include <stdint.h>
#include "internal.h"

struct nlattr;
struct nlmsghdr;
struct nftnl_obj;

struct nftnl_obj {
	struct list_head	head;
	struct obj_ops		*ops;

	const char		*table;
	const char		*name;

	uint32_t		family;
	uint32_t		use;

	uint32_t		flags;

	union {
		struct nftnl_obj_counter {
			uint64_t	pkts;
			uint64_t	bytes;
		} counter;
		struct nftnl_obj_quota {
			uint64_t        bytes;
			uint64_t	consumed;
			uint32_t        flags;
		} quota;
	} data;
};

struct obj_ops {
	const char *name;
	uint32_t type;
	size_t	alloc_len;
	int	max_attr;
	int	(*set)(struct nftnl_obj *e, uint16_t type, const void *data, uint32_t data_len);
	const void *(*get)(const struct nftnl_obj *e, uint16_t type, uint32_t *data_len);
	int	(*parse)(struct nftnl_obj *e, struct nlattr *attr);
	void	(*build)(struct nlmsghdr *nlh, const struct nftnl_obj *e);
	int	(*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_obj *e);
	int	(*json_parse)(struct nftnl_obj *e, json_t *data,
			      struct nftnl_parse_err *err);
};

extern struct obj_ops obj_ops_counter;
extern struct obj_ops obj_ops_quota;

#define nftnl_obj_data(obj) (void *)&obj->data

#endif