summaryrefslogtreecommitdiffstats
path: root/include/netlink.h
blob: 22ef489c9f744dcaa74b58aca07d418d82d0b505 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef NFTABLES_NETLINK_H
#define NFTABLES_NETLINK_H

#include <netlink/netfilter/netfilter.h>
#include <netlink/netfilter/nft_table.h>
#include <netlink/netfilter/nft_chain.h>
#include <netlink/netfilter/nft_rule.h>
#include <netlink/netfilter/nft_expr.h>
#include <netlink/netfilter/nft_data.h>
#include <netlink/object.h>

#include <rule.h>

/** 
 * struct netlink_ctx
 *
 * @msgs:	message queue
 * @list:	list of parsed rules/chains/tables
 * @set:	current set
 */
struct netlink_ctx {
	struct list_head	*msgs;
	struct list_head	list;
	struct set		*set;
};

extern void netlink_dump_object(struct nl_object *obj);

extern struct nfnl_nft_table *alloc_nft_table(const struct handle *h);
extern struct nfnl_nft_chain *alloc_nft_chain(const struct handle *h);
extern struct nfnl_nft_rule *alloc_nft_rule(const struct handle *h);
extern struct nfnl_nft_expr *alloc_nft_expr(int (*init)(struct nfnl_nft_expr *));
extern struct nfnl_nft_set *alloc_nft_set(const struct handle *h);
extern struct nfnl_nft_data *alloc_nft_data(const void *data, unsigned int len);

extern struct nfnl_nft_data *netlink_gen_data(const struct expr *expr);
extern struct nfnl_nft_data *netlink_gen_raw_data(const mpz_t value,
						  enum byteorder byteorder,
						  unsigned int len);

extern struct expr *netlink_alloc_value(const struct location *loc,
				        const struct nfnl_nft_data *nld);
extern struct expr *netlink_alloc_data(const struct location *loc,
				       const struct nfnl_nft_data *nld,
				       enum nft_registers dreg);

extern int netlink_linearize_rule(struct netlink_ctx *ctx,
				  struct nfnl_nft_rule *nlr,
				  const struct rule *rule);
extern struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
					     const struct nl_object *obj);

extern int netlink_add_rule(struct netlink_ctx *ctx, const struct handle *h,
			    const struct rule *rule);
extern int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h);

extern int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h,
			     const struct chain *chain);
extern int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_chain(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_flush_chain(struct netlink_ctx *ctx, const struct handle *h);

extern int netlink_add_table(struct netlink_ctx *ctx, const struct handle *h,
			     const struct table *table);
extern int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h);

extern int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
			   struct set *set);
extern int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h);

extern int netlink_add_setelems(struct netlink_ctx *ctx, const struct handle *h,
				const struct expr *expr);
extern int netlink_delete_setelems(struct netlink_ctx *ctx, const struct handle *h,
				   const struct expr *expr);
extern int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
				struct set *set);

#endif /* NFTABLES_NETLINK_H */