|
Packit |
c5a612 |
#ifndef NFTABLES_NFTABLES_H
|
|
Packit |
c5a612 |
#define NFTABLES_NFTABLES_H
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
#include <stdbool.h>
|
|
Packit |
c5a612 |
#include <stdarg.h>
|
|
Packit |
c5a612 |
#include <limits.h>
|
|
Packit |
c5a612 |
#include <utils.h>
|
|
Packit |
c5a612 |
#include <nftables/libnftables.h>
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct cookie {
|
|
Packit |
c5a612 |
FILE *fp;
|
|
Packit |
c5a612 |
FILE *orig_fp;
|
|
Packit |
c5a612 |
char *buf;
|
|
Packit |
c5a612 |
size_t buflen;
|
|
Packit |
c5a612 |
size_t pos;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct symbol_tables {
|
|
Packit |
c5a612 |
const struct symbol_table *mark;
|
|
Packit |
c5a612 |
const struct symbol_table *devgroup;
|
|
Packit |
c5a612 |
const struct symbol_table *ct_label;
|
|
Packit |
c5a612 |
const struct symbol_table *realm;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct output_ctx {
|
|
Packit |
c5a612 |
unsigned int flags;
|
|
Packit |
c5a612 |
union {
|
|
Packit |
c5a612 |
FILE *output_fp;
|
|
Packit |
c5a612 |
struct cookie output_cookie;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
union {
|
|
Packit |
c5a612 |
FILE *error_fp;
|
|
Packit |
c5a612 |
struct cookie error_cookie;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
struct symbol_tables tbl;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_reversedns(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_REVERSEDNS;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_service(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_SERVICE;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_stateless(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_STATELESS;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_handle(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_HANDLE;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_json(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_JSON;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_echo(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_ECHO;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_guid(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_GUID;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_seconds(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_NUMERIC_TIME;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_numeric_proto(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_NUMERIC_PROTO;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_numeric_prio(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_NUMERIC_PRIO;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_numeric_symbol(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_NUMERIC_SYMBOL;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
static inline bool nft_output_terse(const struct output_ctx *octx)
|
|
Packit |
c5a612 |
{
|
|
Packit |
c5a612 |
return octx->flags & NFT_CTX_OUTPUT_TERSE;
|
|
Packit |
c5a612 |
}
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct nft_cache {
|
|
Packit |
c5a612 |
uint32_t genid;
|
|
Packit |
c5a612 |
struct list_head list;
|
|
Packit |
c5a612 |
uint32_t seqnum;
|
|
Packit |
c5a612 |
uint32_t flags;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct mnl_socket;
|
|
Packit |
c5a612 |
struct parser_state;
|
|
Packit |
c5a612 |
struct scope;
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
#define MAX_INCLUDE_DEPTH 16
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct nft_ctx {
|
|
Packit |
c5a612 |
struct mnl_socket *nf_sock;
|
|
Packit |
c5a612 |
char **include_paths;
|
|
Packit |
c5a612 |
unsigned int num_include_paths;
|
|
Packit |
c5a612 |
unsigned int parser_max_errors;
|
|
Packit |
c5a612 |
unsigned int debug_mask;
|
|
Packit |
c5a612 |
struct output_ctx output;
|
|
Packit |
c5a612 |
bool check;
|
|
Packit |
c5a612 |
struct nft_cache cache;
|
|
Packit |
c5a612 |
uint32_t flags;
|
|
Packit |
c5a612 |
struct parser_state *state;
|
|
Packit |
c5a612 |
void *scanner;
|
|
Packit |
c5a612 |
struct scope *top_scope;
|
|
Packit |
c5a612 |
void *json_root;
|
|
Packit |
c5a612 |
FILE *f[MAX_INCLUDE_DEPTH];
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
enum nftables_exit_codes {
|
|
Packit |
c5a612 |
NFT_EXIT_SUCCESS = 0,
|
|
Packit |
c5a612 |
NFT_EXIT_FAILURE = 1,
|
|
Packit |
c5a612 |
NFT_EXIT_NOMEM = 2,
|
|
Packit |
c5a612 |
NFT_EXIT_NONL = 3,
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
struct input_descriptor;
|
|
Packit |
c5a612 |
struct location {
|
|
Packit |
c5a612 |
const struct input_descriptor *indesc;
|
|
Packit |
c5a612 |
union {
|
|
Packit |
c5a612 |
struct {
|
|
Packit |
c5a612 |
off_t token_offset;
|
|
Packit |
c5a612 |
off_t line_offset;
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
unsigned int first_line;
|
|
Packit |
c5a612 |
unsigned int last_line;
|
|
Packit |
c5a612 |
unsigned int first_column;
|
|
Packit |
c5a612 |
unsigned int last_column;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
struct {
|
|
Packit |
c5a612 |
const void *nle;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
extern const struct location internal_location;
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
/**
|
|
Packit |
c5a612 |
* enum input_descriptor_types
|
|
Packit |
c5a612 |
*
|
|
Packit |
c5a612 |
* @INDESC_INVALID: invalid
|
|
Packit |
c5a612 |
* @INDESC_INTERNAL: dummy type for internally generated messages
|
|
Packit |
c5a612 |
* @INDESC_BUFFER: buffer (command line arguments)
|
|
Packit |
c5a612 |
* @INDESC_FILE: file
|
|
Packit |
c5a612 |
* @INDESC_CLI: command line interface
|
|
Packit |
c5a612 |
* @INDESC_NETLINK: received from netlink
|
|
Packit |
c5a612 |
*/
|
|
Packit |
c5a612 |
enum input_descriptor_types {
|
|
Packit |
c5a612 |
INDESC_INVALID,
|
|
Packit |
c5a612 |
INDESC_INTERNAL,
|
|
Packit |
c5a612 |
INDESC_BUFFER,
|
|
Packit |
c5a612 |
INDESC_FILE,
|
|
Packit |
c5a612 |
INDESC_CLI,
|
|
Packit |
c5a612 |
INDESC_NETLINK,
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
/**
|
|
Packit |
c5a612 |
* struct input_descriptor
|
|
Packit |
c5a612 |
*
|
|
Packit |
c5a612 |
* @location: location, used for include statements
|
|
Packit |
c5a612 |
* @type: input descriptor type
|
|
Packit |
c5a612 |
* @name: name describing the input
|
|
Packit |
c5a612 |
* @union: buffer or file descriptor, depending on type
|
|
Packit |
c5a612 |
* @lineno: current line number in the input
|
|
Packit |
c5a612 |
* @column: current column in the input
|
|
Packit |
c5a612 |
* @token_offset: offset of the current token to the beginning
|
|
Packit |
c5a612 |
* @line_offset: offset of the current line to the beginning
|
|
Packit |
c5a612 |
*/
|
|
Packit |
c5a612 |
struct input_descriptor {
|
|
Packit |
c5a612 |
struct list_head list;
|
|
Packit |
c5a612 |
struct location location;
|
|
Packit |
c5a612 |
enum input_descriptor_types type;
|
|
Packit |
c5a612 |
const char *name;
|
|
Packit |
c5a612 |
const char *data;
|
|
Packit |
c5a612 |
unsigned int lineno;
|
|
Packit |
c5a612 |
unsigned int column;
|
|
Packit |
c5a612 |
off_t token_offset;
|
|
Packit |
c5a612 |
off_t line_offset;
|
|
Packit |
c5a612 |
};
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
void ct_label_table_init(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void mark_table_init(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void gmp_init(void);
|
|
Packit |
c5a612 |
void realm_table_rt_init(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void devgroup_table_init(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void xt_init(void);
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
void ct_label_table_exit(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void mark_table_exit(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void devgroup_table_exit(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
void realm_table_rt_exit(struct nft_ctx *ctx);
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
int nft_print(struct output_ctx *octx, const char *fmt, ...)
|
|
Packit |
c5a612 |
__attribute__((format(printf, 2, 3)));
|
|
Packit |
c5a612 |
int nft_gmp_print(struct output_ctx *octx, const char *fmt, ...)
|
|
Packit |
c5a612 |
__attribute__((format(printf, 2, 0)));
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
#define __NFT_OUTPUT_NOTSUPP UINT_MAX
|
|
Packit |
c5a612 |
|
|
Packit |
c5a612 |
#endif /* NFTABLES_NFTABLES_H */
|