Blame bootstrap_ver/iptables/nft.h

Packit Service 1ec7f4
#ifndef _NFT_H_
Packit Service 1ec7f4
#define _NFT_H_
Packit Service 1ec7f4
Packit Service 1ec7f4
#include "xshared.h"
Packit Service 1ec7f4
#include "nft-shared.h"
Packit Service 1ec7f4
#include <libiptc/linux_list.h>
Packit Service 1ec7f4
Packit Service 1ec7f4
enum nft_table_type {
Packit Service 1ec7f4
	NFT_TABLE_FILTER	= 0,
Packit Service 1ec7f4
	NFT_TABLE_MANGLE,
Packit Service 1ec7f4
	NFT_TABLE_RAW,
Packit Service 1ec7f4
	NFT_TABLE_SECURITY,
Packit Service 1ec7f4
	NFT_TABLE_NAT,
Packit Service 1ec7f4
};
Packit Service 1ec7f4
#define NFT_TABLE_MAX	(NFT_TABLE_NAT + 1)
Packit Service 1ec7f4
Packit Service 1ec7f4
struct builtin_chain {
Packit Service 1ec7f4
	const char *name;
Packit Service 1ec7f4
	const char *type;
Packit Service 1ec7f4
	uint32_t prio;
Packit Service 1ec7f4
	uint32_t hook;
Packit Service 1ec7f4
};
Packit Service 1ec7f4
Packit Service 1ec7f4
struct builtin_table {
Packit Service 1ec7f4
	const char *name;
Packit Service 1ec7f4
	struct builtin_chain chains[NF_INET_NUMHOOKS];
Packit Service 1ec7f4
	bool initialized;
Packit Service 1ec7f4
};
Packit Service 1ec7f4
Packit Service 1ec7f4
struct nft_handle {
Packit Service 1ec7f4
	int			family;
Packit Service 1ec7f4
	struct mnl_socket	*nl;
Packit Service 1ec7f4
	uint32_t		portid;
Packit Service 1ec7f4
	uint32_t		seq;
Packit Service 1ec7f4
	struct list_head	obj_list;
Packit Service 1ec7f4
	int			obj_list_num;
Packit Service 1ec7f4
	struct nftnl_batch	*batch;
Packit Service 1ec7f4
	struct list_head	err_list;
Packit Service 1ec7f4
	struct nft_family_ops	*ops;
Packit Service 1ec7f4
	struct builtin_table	*tables;
Packit Service 1ec7f4
	struct nftnl_chain_list	*chain_cache;
Packit Service 1ec7f4
	struct nftnl_rule_list	*rule_cache;
Packit Service 1ec7f4
	bool			restore;
Packit Service 1ec7f4
	int8_t			config_done;
Packit Service 1ec7f4
Packit Service 1ec7f4
	/* meta data, for error reporting */
Packit Service 1ec7f4
	struct {
Packit Service 1ec7f4
		unsigned int	lineno;
Packit Service 1ec7f4
	} error;
Packit Service 1ec7f4
};
Packit Service 1ec7f4
Packit Service 1ec7f4
extern struct builtin_table xtables_ipv4[NFT_TABLE_MAX];
Packit Service 1ec7f4
extern struct builtin_table xtables_arp[NFT_TABLE_MAX];
Packit Service 1ec7f4
extern struct builtin_table xtables_bridge[NFT_TABLE_MAX];
Packit Service 1ec7f4
Packit Service 1ec7f4
int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
Packit Service 1ec7f4
	     int (*cb)(const struct nlmsghdr *nlh, void *data),
Packit Service 1ec7f4
	     void *data);
Packit Service 1ec7f4
int nft_init(struct nft_handle *h, struct builtin_table *t);
Packit Service 1ec7f4
void nft_fini(struct nft_handle *h);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Operations with tables.
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
struct nftnl_table;
Packit Service 1ec7f4
struct nftnl_chain_list;
Packit Service 1ec7f4
Packit Service 1ec7f4
int nft_for_each_table(struct nft_handle *h, int (*func)(struct nft_handle *h, const char *tablename, bool counters), bool counters);
Packit Service 1ec7f4
bool nft_table_find(struct nft_handle *h, const char *tablename);
Packit Service 1ec7f4
int nft_table_purge_chains(struct nft_handle *h, const char *table, struct nftnl_chain_list *list);
Packit Service 1ec7f4
int nft_table_flush(struct nft_handle *h, const char *table);
Packit Service 1ec7f4
void nft_table_new(struct nft_handle *h, const char *table);
Packit Service 1ec7f4
struct builtin_table *nft_table_builtin_find(struct nft_handle *h, const char *table);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Operations with chains.
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
struct nftnl_chain;
Packit Service 1ec7f4
Packit Service 1ec7f4
int nft_chain_set(struct nft_handle *h, const char *table, const char *chain, const char *policy, const struct xt_counters *counters);
Packit Service 1ec7f4
struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h);
Packit Service 1ec7f4
struct nftnl_chain *nft_chain_list_find(struct nftnl_chain_list *list, const char *table, const char *chain);
Packit Service 1ec7f4
int nft_chain_save(struct nft_handle *h, struct nftnl_chain_list *list, const char *table);
Packit Service 1ec7f4
int nft_chain_user_add(struct nft_handle *h, const char *chain, const char *table);
Packit Service 1ec7f4
int nft_chain_user_del(struct nft_handle *h, const char *chain, const char *table, bool verbose);
Packit Service 1ec7f4
int nft_chain_user_flush(struct nft_handle *h, struct nftnl_chain_list *list,
Packit Service 1ec7f4
			 const char *chain, const char *table);
Packit Service 1ec7f4
int nft_chain_user_rename(struct nft_handle *h, const char *chain, const char *table, const char *newname);
Packit Service 1ec7f4
int nft_chain_zero_counters(struct nft_handle *h, const char *chain, const char *table, bool verbose);
Packit Service 1ec7f4
struct builtin_chain *nft_chain_builtin_find(struct builtin_table *t, const char *chain);
Packit Service 1ec7f4
bool nft_chain_exists(struct nft_handle *h, const char *table, const char *chain);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Operations with rule-set.
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
struct nftnl_rule;
Packit Service 1ec7f4
Packit Service 1ec7f4
int nft_rule_append(struct nft_handle *h, const char *chain, const char *table, void *data, uint64_t handle, bool verbose);
Packit Service 1ec7f4
int nft_rule_insert(struct nft_handle *h, const char *chain, const char *table, void *data, int rulenum, bool verbose);
Packit Service 1ec7f4
int nft_rule_check(struct nft_handle *h, const char *chain, const char *table, void *data, bool verbose);
Packit Service 1ec7f4
int nft_rule_delete(struct nft_handle *h, const char *chain, const char *table, void *data, bool verbose);
Packit Service 1ec7f4
int nft_rule_delete_num(struct nft_handle *h, const char *chain, const char *table, int rulenum, bool verbose);
Packit Service 1ec7f4
int nft_rule_replace(struct nft_handle *h, const char *chain, const char *table, void *data, int rulenum, bool verbose);
Packit Service 1ec7f4
int nft_rule_list(struct nft_handle *h, const char *chain, const char *table, int rulenum, unsigned int format);
Packit Service 1ec7f4
int nft_rule_list_save(struct nft_handle *h, const char *chain, const char *table, int rulenum, int counters);
Packit Service 1ec7f4
int nft_rule_save(struct nft_handle *h, const char *table, unsigned int format);
Packit Service 1ec7f4
int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table, bool verbose);
Packit Service 1ec7f4
int nft_rule_zero_counters(struct nft_handle *h, const char *chain, const char *table, int rulenum);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Operations used in userspace tools
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
int add_counters(struct nftnl_rule *r, uint64_t packets, uint64_t bytes);
Packit Service 1ec7f4
int add_verdict(struct nftnl_rule *r, int verdict);
Packit Service 1ec7f4
int add_match(struct nftnl_rule *r, struct xt_entry_match *m);
Packit Service 1ec7f4
int add_target(struct nftnl_rule *r, struct xt_entry_target *t);
Packit Service 1ec7f4
int add_jumpto(struct nftnl_rule *r, const char *name, int verdict);
Packit Service 1ec7f4
int add_action(struct nftnl_rule *r, struct iptables_command_state *cs, bool goto_set);
Packit Service 1ec7f4
int add_comment(struct nftnl_rule *r, const char *comment);
Packit Service 1ec7f4
char *get_comment(const void *data, uint32_t data_len);
Packit Service 1ec7f4
Packit Service 1ec7f4
enum nft_rule_print {
Packit Service 1ec7f4
	NFT_RULE_APPEND,
Packit Service 1ec7f4
	NFT_RULE_DEL,
Packit Service 1ec7f4
};
Packit Service 1ec7f4
Packit Service 1ec7f4
void nft_rule_print_save(const struct nftnl_rule *r, enum nft_rule_print type,
Packit Service 1ec7f4
			 unsigned int format);
Packit Service 1ec7f4
Packit Service 1ec7f4
uint32_t nft_invflags2cmp(uint32_t invflags, uint32_t flag);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * global commit and abort
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
int nft_commit(struct nft_handle *h);
Packit Service 1ec7f4
int nft_abort(struct nft_handle *h);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * revision compatibility.
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
int nft_compatible_revision(const char *name, uint8_t rev, int opt);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Error reporting.
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
const char *nft_strerror(int err);
Packit Service 1ec7f4
Packit Service 1ec7f4
/* For xtables.c */
Packit Service 1ec7f4
int do_commandx(struct nft_handle *h, int argc, char *argv[], char **table, bool restore);
Packit Service 1ec7f4
/* For xtables-arptables.c */
Packit Service 1ec7f4
int nft_init_arp(struct nft_handle *h, const char *pname);
Packit Service 1ec7f4
int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table, bool restore);
Packit Service 1ec7f4
/* For xtables-eb.c */
Packit Service 1ec7f4
int nft_init_eb(struct nft_handle *h, const char *pname);
Packit Service 1ec7f4
int ebt_get_current_chain(const char *chain);
Packit Service 1ec7f4
int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table, bool restore);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Parse config for tables and chain helper functions
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
#define XTABLES_CONFIG_DEFAULT  "/etc/xtables.conf"
Packit Service 1ec7f4
Packit Service 1ec7f4
struct nftnl_table_list;
Packit Service 1ec7f4
struct nftnl_chain_list;
Packit Service 1ec7f4
Packit Service 1ec7f4
extern int xtables_config_parse(const char *filename, struct nftnl_table_list *table_list, struct nftnl_chain_list *chain_list);
Packit Service 1ec7f4
Packit Service 1ec7f4
enum {
Packit Service 1ec7f4
	NFT_LOAD_VERBOSE = (1 << 0),
Packit Service 1ec7f4
};
Packit Service 1ec7f4
Packit Service 1ec7f4
int nft_xtables_config_load(struct nft_handle *h, const char *filename, uint32_t flags);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * Translation from iptables to nft
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
struct xt_buf;
Packit Service 1ec7f4
Packit Service 1ec7f4
bool xlate_find_match(const struct iptables_command_state *cs, const char *p_name);
Packit Service 1ec7f4
int xlate_matches(const struct iptables_command_state *cs, struct xt_xlate *xl);
Packit Service 1ec7f4
int xlate_action(const struct iptables_command_state *cs, bool goto_set,
Packit Service 1ec7f4
		 struct xt_xlate *xl);
Packit Service 1ec7f4
void xlate_ifname(struct xt_xlate *xl, const char *nftmeta, const char *ifname,
Packit Service 1ec7f4
		  bool invert);
Packit Service 1ec7f4
Packit Service 1ec7f4
/*
Packit Service 1ec7f4
 * ARP
Packit Service 1ec7f4
 */
Packit Service 1ec7f4
Packit Service 1ec7f4
struct arpt_entry;
Packit Service 1ec7f4
Packit Service 1ec7f4
int nft_arp_rule_append(struct nft_handle *h, const char *chain,
Packit Service 1ec7f4
			const char *table, struct arpt_entry *fw,
Packit Service 1ec7f4
			bool verbose);
Packit Service 1ec7f4
int nft_arp_rule_insert(struct nft_handle *h, const char *chain,
Packit Service 1ec7f4
			const char *table, struct arpt_entry *fw,
Packit Service 1ec7f4
			int rulenum, bool verbose);
Packit Service 1ec7f4
Packit Service 1ec7f4
void nft_rule_to_arpt_entry(struct nftnl_rule *r, struct arpt_entry *fw);
Packit Service 1ec7f4
Packit Service 1ec7f4
bool nft_is_table_compatible(struct nft_handle *h, const char *name);
Packit Service 1ec7f4
Packit Service 1ec7f4
#endif