summaryrefslogtreecommitdiffstats
path: root/include/nftables/nftables.h
blob: 449f9e4ee879c61bc53c73ce1ce704474426a884 (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
/*
 * Copyright (c) 2017 Eric Leblond <eric@regit.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */
#ifndef LIB_NFTABLES_H
#define LIB_NFTABLES_H

#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>

struct nft_ctx;

enum nft_debug_level {
	NFT_DEBUG_SCANNER		= 0x1,
	NFT_DEBUG_PARSER		= 0x2,
	NFT_DEBUG_EVALUATION		= 0x4,
	NFT_DEBUG_NETLINK		= 0x8,
	NFT_DEBUG_MNL			= 0x10,
	NFT_DEBUG_PROTO_CTX		= 0x20,
	NFT_DEBUG_SEGTREE		= 0x40,
};

enum nft_numeric_level {
	NFT_NUMERIC_NONE,
	NFT_NUMERIC_ADDR,
	NFT_NUMERIC_PORT,
	NFT_NUMERIC_ALL,
};

/**
 * Possible flags to pass to nft_ctx_new()
 */
#define NFT_CTX_DEFAULT		0

/**
 * Exit codes returned by nft_run_cmd_from_*()
 */
enum nftables_exit_codes {
	NFT_EXIT_SUCCESS	= 0,
	NFT_EXIT_FAILURE	= 1,
	NFT_EXIT_NOMEM		= 2,
	NFT_EXIT_NONL		= 3,
};

struct nft_ctx *nft_ctx_new(uint32_t flags);
void nft_ctx_free(struct nft_ctx *ctx);

bool nft_ctx_get_dry_run(struct nft_ctx *ctx);
void nft_ctx_set_dry_run(struct nft_ctx *ctx, bool dry);
enum nft_numeric_level nft_ctx_output_get_numeric(struct nft_ctx *ctx);
void nft_ctx_output_set_numeric(struct nft_ctx *ctx, enum nft_numeric_level level);
bool nft_ctx_output_get_stateless(struct nft_ctx *ctx);
void nft_ctx_output_set_stateless(struct nft_ctx *ctx, bool val);
bool nft_ctx_output_get_ip2name(struct nft_ctx *ctx);
void nft_ctx_output_set_ip2name(struct nft_ctx *ctx, bool val);
unsigned int nft_ctx_output_get_debug(struct nft_ctx *ctx);
void nft_ctx_output_set_debug(struct nft_ctx *ctx, unsigned int mask);
bool nft_ctx_output_get_handle(struct nft_ctx *ctx);
void nft_ctx_output_set_handle(struct nft_ctx *ctx, bool val);
bool nft_ctx_output_get_echo(struct nft_ctx *ctx);
void nft_ctx_output_set_echo(struct nft_ctx *ctx, bool val);

FILE *nft_ctx_set_output(struct nft_ctx *ctx, FILE *fp);
int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path);
void nft_ctx_clear_include_paths(struct nft_ctx *ctx);

void nft_ctx_flush_cache(struct nft_ctx *ctx);

int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen);
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename);

#endif /* LIB_NFTABLES_H */