netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nft.c File Reference
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdbool.h>
#include <errno.h>
#include <netdb.h>
#include <time.h>
#include <stdarg.h>
#include <inttypes.h>
#include <xtables.h>
#include <libiptc/libxtc.h>
#include <libiptc/xtcshared.h>
#include <stdlib.h>
#include <string.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <netinet/ip6.h>
#include <linux/netlink.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nf_tables.h>
#include <linux/netfilter/nf_tables_compat.h>
#include <libmnl/libmnl.h>
#include <libnftnl/table.h>
#include <libnftnl/chain.h>
#include <libnftnl/rule.h>
#include <libnftnl/expr.h>
#include <libnftnl/set.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "nft.h"
#include "xshared.h"
#include "nft-shared.h"
#include "xtables-config-parser.h"
#include <linux/netfilter_arp.h>
Include dependency graph for nft.c:

Data Structures

struct  batch_page
 
struct  obj_update
 

Macros

#define BATCH_PAGE_SIZE   getpagesize() * 32
 

Enumerations

enum  obj_update_type {
  NFT_COMPAT_TABLE_ADD,
  NFT_COMPAT_CHAIN_ADD,
  NFT_COMPAT_CHAIN_USER_ADD,
  NFT_COMPAT_CHAIN_USER_DEL,
  NFT_COMPAT_CHAIN_UPDATE,
  NFT_COMPAT_CHAIN_RENAME,
  NFT_COMPAT_RULE_APPEND,
  NFT_COMPAT_RULE_INSERT,
  NFT_COMPAT_RULE_REPLACE,
  NFT_COMPAT_RULE_DELETE,
  NFT_COMPAT_RULE_FLUSH
}
 
enum  obj_action {
  NFT_COMPAT_COMMIT,
  NFT_COMPAT_ABORT
}
 

Functions

int mnl_talk (struct nft_handle *h, struct nlmsghdr *nlh, int(*cb)(const struct nlmsghdr *nlh, void *data), void *data)
 
int nft_table_add (struct nft_handle *h, struct nft_table *t, uint16_t flags)
 
int nft_chain_add (struct nft_handle *h, struct nft_chain *c, uint16_t flags)
 
int nft_init (struct nft_handle *h, struct builtin_table *t)
 
void nft_fini (struct nft_handle *h)
 
int nft_chain_set (struct nft_handle *h, const char *table, const char *chain, const char *policy, const struct xt_counters *counters)
 
int add_match (struct nft_rule *r, struct xt_entry_match *m)
 
int add_target (struct nft_rule *r, struct xt_entry_target *t)
 
int add_jumpto (struct nft_rule *r, const char *name, int verdict)
 
int add_verdict (struct nft_rule *r, int verdict)
 
int add_action (struct nft_rule *r, struct iptables_command_state *cs, bool goto_set)
 
int add_counters (struct nft_rule *r, uint64_t packets, uint64_t bytes)
 
void add_compat (struct nft_rule *r, uint32_t proto, bool inv)
 
int nft_rule_append (struct nft_handle *h, const char *chain, const char *table, void *data, uint64_t handle, bool verbose)
 
void nft_rule_print_save (const void *data, struct nft_rule *r, enum nft_rule_print type, unsigned int format)
 
struct nft_chain_listnft_chain_dump (struct nft_handle *h)
 
int nft_chain_save (struct nft_handle *h, struct nft_chain_list *list, const char *table)
 
int nft_rule_save (struct nft_handle *h, const char *table, bool counters)
 
int nft_rule_flush (struct nft_handle *h, const char *chain, const char *table)
 
int nft_chain_user_add (struct nft_handle *h, const char *chain, const char *table)
 
int nft_chain_user_del (struct nft_handle *h, const char *chain, const char *table)
 
struct nft_chainnft_chain_list_find (struct nft_chain_list *list, const char *table, const char *chain)
 
int nft_chain_user_rename (struct nft_handle *h, const char *chain, const char *table, const char *newname)
 
bool nft_table_find (struct nft_handle *h, const char *tablename)
 
int nft_for_each_table (struct nft_handle *h, int(*func)(struct nft_handle *h, const char *tablename, bool counters), bool counters)
 
int nft_table_purge_chains (struct nft_handle *h, const char *this_table, struct nft_chain_list *chain_list)
 
struct nft_rule_listnft_rule_list_create (struct nft_handle *h)
 
void nft_rule_list_destroy (struct nft_rule_list *list)
 
int nft_rule_check (struct nft_handle *h, const char *chain, const char *table, void *data, bool verbose)
 
int nft_rule_delete (struct nft_handle *h, const char *chain, const char *table, void *data, bool verbose)
 
int nft_rule_insert (struct nft_handle *h, const char *chain, const char *table, void *data, int rulenum, bool verbose)
 
int nft_rule_delete_num (struct nft_handle *h, const char *chain, const char *table, int rulenum, bool verbose)
 
int nft_rule_replace (struct nft_handle *h, const char *chain, const char *table, void *data, int rulenum, bool verbose)
 
int nft_rule_list (struct nft_handle *h, const char *chain, const char *table, int rulenum, unsigned int format)
 
int nft_rule_list_save (struct nft_handle *h, const char *chain, const char *table, int rulenum, int counters)
 
int nft_rule_zero_counters (struct nft_handle *h, const char *chain, const char *table, int rulenum)
 
int nft_commit (struct nft_handle *h)
 
int nft_abort (struct nft_handle *h)
 
int nft_compatible_revision (const char *name, uint8_t rev, int opt)
 
const char * nft_strerror (int err)
 
int nft_xtables_config_load (struct nft_handle *h, const char *filename, uint32_t flags)
 
int nft_chain_zero_counters (struct nft_handle *h, const char *chain, const char *table)
 
uint32_t nft_invflags2cmp (uint32_t invflags, uint32_t flag)
 

Variables

struct builtin_table xtables_ipv4 [TABLES_MAX]
 
struct builtin_table xtables_arp [TABLES_MAX]
 

Macro Definition Documentation

#define BATCH_PAGE_SIZE   getpagesize() * 32

Enumeration Type Documentation

enum obj_action
Enumerator
NFT_COMPAT_COMMIT 
NFT_COMPAT_ABORT 
Enumerator
NFT_COMPAT_TABLE_ADD 
NFT_COMPAT_CHAIN_ADD 
NFT_COMPAT_CHAIN_USER_ADD 
NFT_COMPAT_CHAIN_USER_DEL 
NFT_COMPAT_CHAIN_UPDATE 
NFT_COMPAT_CHAIN_RENAME 
NFT_COMPAT_RULE_APPEND 
NFT_COMPAT_RULE_INSERT 
NFT_COMPAT_RULE_REPLACE 
NFT_COMPAT_RULE_DELETE 
NFT_COMPAT_RULE_FLUSH 

Function Documentation

void add_compat ( struct nft_rule r,
uint32_t  proto,
bool  inv 
)

References NFT_RULE_ATTR_COMPAT_FLAGS, NFT_RULE_ATTR_COMPAT_PROTO, nft_rule_attr_set_u32(), and NFT_RULE_COMPAT_F_INV.

Here is the call graph for this function:

int add_counters ( struct nft_rule r,
uint64_t  packets,
uint64_t  bytes 
)

References NFT_EXPR_CTR_BYTES, NFT_EXPR_CTR_PACKETS, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set_u64(), and NULL.

Here is the call graph for this function:

int add_jumpto ( struct nft_rule r,
const char *  name,
int  verdict 
)

References NFT_EXPR_IMM_CHAIN, NFT_EXPR_IMM_DREG, NFT_EXPR_IMM_VERDICT, NFT_REG_VERDICT, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set_str(), nft_rule_expr_set_u32(), and NULL.

Referenced by add_action().

Here is the call graph for this function:

Here is the caller graph for this function:

int add_match ( struct nft_rule r,
struct xt_entry_match m 
)

References nft_rule_add_expr(), nft_rule_expr_alloc(), and NULL.

Here is the call graph for this function:

int add_target ( struct nft_rule r,
struct xt_entry_target t 
)

References nft_rule_add_expr(), nft_rule_expr_alloc(), and NULL.

Referenced by add_action().

Here is the call graph for this function:

Here is the caller graph for this function:

int add_verdict ( struct nft_rule r,
int  verdict 
)

References NFT_EXPR_IMM_DREG, NFT_EXPR_IMM_VERDICT, NFT_REG_VERDICT, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set_u32(), and NULL.

Referenced by add_action().

Here is the call graph for this function:

Here is the caller graph for this function:

int mnl_talk ( struct nft_handle h,
struct nlmsghdr nlh,
int(*)(const struct nlmsghdr *nlh, void *data cb,
void *  data 
)
int nft_abort ( struct nft_handle h)

References NFT_COMPAT_ABORT.

int nft_chain_add ( struct nft_handle h,
struct nft_chain c,
uint16_t  flags 
)
struct nft_chain_list* nft_chain_dump ( struct nft_handle h)

Referenced by nft_rule_list(), and nft_rule_list_save().

Here is the caller graph for this function:

struct nft_chain* nft_chain_list_find ( struct nft_chain_list list,
const char *  table,
const char *  chain 
)
int nft_chain_save ( struct nft_handle h,
struct nft_chain_list list,
const char *  table 
)
int nft_chain_set ( struct nft_handle h,
const char *  table,
const char *  chain,
const char *  policy,
const struct xt_counters counters 
)

References nft_handle::batch_support, NF_ACCEPT, NF_DROP, nft_chain_add(), nft_chain_set(), NFT_COMPAT_CHAIN_UPDATE, and NULL.

Referenced by do_commandarp(), do_commandx(), nft_chain_set(), and nft_strerror().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_chain_user_del ( struct nft_handle h,
const char *  chain,
const char *  table 
)
int nft_commit ( struct nft_handle h)

References NFT_COMPAT_COMMIT.

Referenced by nft_rule_list(), and xtables_arp_main().

Here is the caller graph for this function:

void nft_fini ( struct nft_handle h)

References nft_handle::batch, mnl_nlmsg_batch_head(), mnl_nlmsg_batch_stop(), mnl_socket_close(), and nft_handle::nl.

Referenced by xtables_arp_main().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_for_each_table ( struct nft_handle h,
int(*)(struct nft_handle *h, const char *tablename, bool counters)  func,
bool  counters 
)
uint32_t nft_invflags2cmp ( uint32_t  invflags,
uint32_t  flag 
)

References NFT_CMP_EQ, and NFT_CMP_NEQ.

int nft_rule_append ( struct nft_handle h,
const char *  chain,
const char *  table,
void *  data,
uint64_t  handle,
bool  verbose 
)
int nft_rule_check ( struct nft_handle h,
const char *  chain,
const char *  table,
void *  data,
bool  verbose 
)

References nft_rule_list::list, nft_rule_check(), nft_rule_list_create(), nft_rule_list_destroy(), and NULL.

Referenced by nft_rule_check(), and nft_strerror().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_rule_delete ( struct nft_handle h,
const char *  chain,
const char *  table,
void *  data,
bool  verbose 
)

References nft_rule_list::list, nft_rule_delete(), nft_rule_list_create(), nft_rule_list_destroy(), and NULL.

Referenced by nft_rule_delete(), nft_rule_zero_counters(), and nft_strerror().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_rule_delete_num ( struct nft_handle h,
const char *  chain,
const char *  table,
int  rulenum,
bool  verbose 
)

References DEBUGP, nft_rule_list::list, nft_rule_delete_num(), nft_rule_list_create(), nft_rule_list_destroy(), and NULL.

Referenced by do_commandarp(), do_commandx(), nft_rule_delete_num(), and nft_strerror().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_rule_flush ( struct nft_handle h,
const char *  chain,
const char *  table 
)
int nft_rule_insert ( struct nft_handle h,
const char *  chain,
const char *  table,
void *  data,
int  rulenum,
bool  verbose 
)

References DEBUGP, nft_rule_list::list, nft_rule_attr_get_u64(), NFT_RULE_ATTR_HANDLE, nft_rule_insert(), nft_rule_list_create(), nft_rule_list_destroy(), nft_xtables_config_load(), NULL, and XTABLES_CONFIG_DEFAULT.

Referenced by nft_rule_insert().

Here is the call graph for this function:

Here is the caller graph for this function:

struct nft_rule_list* nft_rule_list_create ( struct nft_handle h)
void nft_rule_list_destroy ( struct nft_rule_list list)

References nft_rule_list_free().

Referenced by nft_rule_check(), nft_rule_delete(), nft_rule_delete_num(), nft_rule_insert(), nft_rule_replace(), and nft_rule_zero_counters().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_rule_list_save ( struct nft_handle h,
const char *  chain,
const char *  table,
int  rulenum,
int  counters 
)
void nft_rule_print_save ( const void *  data,
struct nft_rule r,
enum nft_rule_print  type,
unsigned int  format 
)
int nft_rule_replace ( struct nft_handle h,
const char *  chain,
const char *  table,
void *  data,
int  rulenum,
bool  verbose 
)

References DEBUGP, nft_rule_list::list, nft_rule_append(), nft_rule_attr_get_u64(), NFT_RULE_ATTR_HANDLE, nft_rule_list_create(), nft_rule_list_destroy(), nft_rule_replace(), and NULL.

Referenced by nft_rule_replace(), and nft_strerror().

Here is the call graph for this function:

Here is the caller graph for this function:

int nft_rule_zero_counters ( struct nft_handle h,
const char *  chain,
const char *  table,
int  rulenum 
)
const char* nft_strerror ( int  err)

References nft_chain_set(), nft_chain_user_add(), nft_chain_user_del(), nft_rule_check(), nft_rule_delete(), nft_rule_delete_num(), nft_rule_replace(), and NULL.

Referenced by xtables_arp_main().

Here is the call graph for this function:

Here is the caller graph for this function:

bool nft_table_find ( struct nft_handle h,
const char *  tablename 
)
int nft_table_purge_chains ( struct nft_handle h,
const char *  this_table,
struct nft_chain_list chain_list 
)

Variable Documentation

Initial value:
= {
[FILTER] = {
.name = "filter",
.chains = {
{
.name = "INPUT",
.type = "filter",
.hook = NF_ARP_IN,
},
{
.name = "FORWARD",
.type = "filter",
.hook = NF_ARP_FORWARD,
},
{
.name = "OUTPUT",
.type = "filter",
.hook = NF_ARP_OUT,
},
},
},
}
#define NF_ARP_IN
Definition: netfilter_arp.h:14
#define FILTER
Definition: nft.h:8
Definition: netfilter_ipv4.h:60
#define NF_ARP_FORWARD
Definition: netfilter_arp.h:16
#define NF_ARP_OUT
Definition: netfilter_arp.h:15

Referenced by do_commandarp().

Referenced by xtables_config_main().