netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nft-shared.h File Reference
#include <stdbool.h>
#include <libnftnl/rule.h>
#include <libnftnl/expr.h>
#include <linux/netfilter_arp/arp_tables.h>
#include "xshared.h"
Include dependency graph for nft-shared.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  nft_xt_ctx
 
struct  nft_family_ops
 
struct  addr_mask
 
struct  xtables_args
 

Macros

#define DEBUGP(x, args...)
 
#define FMT_NUMERIC   0x0001
 
#define FMT_NOCOUNTS   0x0002
 
#define FMT_KILOMEGAGIGA   0x0004
 
#define FMT_OPTIONS   0x0008
 
#define FMT_NOTABLE   0x0010
 
#define FMT_NOTARGET   0x0020
 
#define FMT_VIA   0x0040
 
#define FMT_NONEWLINE   0x0080
 
#define FMT_LINENUMBERS   0x0100
 
#define FMT_PRINT_RULE
 
#define FMT(tab, notab)   ((format) & FMT_NOTABLE ? (notab) : (tab))
 
#define CMD_NONE   0x0000U
 
#define CMD_INSERT   0x0001U
 
#define CMD_DELETE   0x0002U
 
#define CMD_DELETE_NUM   0x0004U
 
#define CMD_REPLACE   0x0008U
 
#define CMD_APPEND   0x0010U
 
#define CMD_LIST   0x0020U
 
#define CMD_FLUSH   0x0040U
 
#define CMD_ZERO   0x0080U
 
#define CMD_NEW_CHAIN   0x0100U
 
#define CMD_DELETE_CHAIN   0x0200U
 
#define CMD_SET_POLICY   0x0400U
 
#define CMD_RENAME_CHAIN   0x0800U
 
#define CMD_LIST_RULES   0x1000U
 
#define CMD_ZERO_NUM   0x2000U
 
#define CMD_CHECK   0x4000U
 

Enumerations

enum  {
  NFT_XT_CTX_PAYLOAD = (1 << 0),
  NFT_XT_CTX_META = (1 << 1),
  NFT_XT_CTX_BITWISE = (1 << 2)
}
 

Functions

void add_meta (struct nft_rule *r, uint32_t key)
 
void add_payload (struct nft_rule *r, int offset, int len)
 
void add_bitwise_u16 (struct nft_rule *r, int mask, int xor)
 
void add_cmp_ptr (struct nft_rule *r, uint32_t op, void *data, size_t len)
 
void add_cmp_u8 (struct nft_rule *r, uint8_t val, uint32_t op)
 
void add_cmp_u16 (struct nft_rule *r, uint16_t val, uint32_t op)
 
void add_cmp_u32 (struct nft_rule *r, uint32_t val, uint32_t op)
 
void add_iniface (struct nft_rule *r, char *iface, uint32_t op)
 
void add_outiface (struct nft_rule *r, char *iface, uint32_t op)
 
void add_addr (struct nft_rule *r, int offset, void *data, void *mask, size_t len, uint32_t op)
 
void add_proto (struct nft_rule *r, int offset, size_t len, uint8_t proto, uint32_t op)
 
void add_compat (struct nft_rule *r, uint32_t proto, bool inv)
 
bool is_same_interfaces (const char *a_iniface, const char *a_outiface, unsigned const char *a_iniface_mask, unsigned const char *a_outiface_mask, const char *b_iniface, const char *b_outiface, unsigned const char *b_iniface_mask, unsigned const char *b_outiface_mask)
 
void parse_meta (struct nft_rule_expr *e, uint8_t key, char *iniface, unsigned char *iniface_mask, char *outiface, unsigned char *outiface_mask, uint8_t *invflags)
 
void print_proto (uint16_t proto, int invert)
 
void get_cmp_data (struct nft_rule_expr *e, void *data, size_t dlen, bool *inv)
 
void nft_parse_bitwise (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_parse_cmp (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_parse_target (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_parse_meta (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_parse_payload (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_parse_counter (struct nft_rule_expr *e, struct xt_counters *counters)
 
void nft_parse_immediate (struct nft_xt_ctx *ctx, struct nft_rule_expr *e)
 
void nft_rule_to_iptables_command_state (struct nft_rule *r, struct iptables_command_state *cs)
 
void print_header (unsigned int format, const char *chain, const char *pol, const struct xt_counters *counters, bool basechain, uint32_t refs)
 
void print_firewall_details (const struct iptables_command_state *cs, const char *targname, uint8_t flags, uint8_t invflags, uint8_t proto, unsigned int num, unsigned int format)
 
void print_ifaces (const char *iniface, const char *outiface, uint8_t invflags, unsigned int format)
 
void print_matches_and_target (struct iptables_command_state *cs, unsigned int format)
 
void save_firewall_details (const struct iptables_command_state *cs, uint8_t invflags, uint16_t proto, const char *iniface, unsigned const char *iniface_mask, const char *outiface, unsigned const char *outiface_mask)
 
void save_counters (uint64_t pcnt, uint64_t bcnt)
 
void save_matches_and_target (struct xtables_rule_match *m, struct xtables_target *target, const char *jumpto, uint8_t flags, const void *fw)
 
struct nft_family_opsnft_family_ops_lookup (int family)
 
bool nft_ipv46_rule_find (struct nft_family_ops *ops, struct nft_rule *r, struct iptables_command_state *cs)
 
bool compare_targets (struct xtables_target *tg1, struct xtables_target *tg2)
 

Macro Definition Documentation

#define CMD_APPEND   0x0010U
#define CMD_CHECK   0x4000U
#define CMD_DELETE   0x0002U
#define CMD_DELETE_CHAIN   0x0200U
#define CMD_DELETE_NUM   0x0004U
#define CMD_FLUSH   0x0040U
#define CMD_INSERT   0x0001U
#define CMD_LIST   0x0020U
#define CMD_LIST_RULES   0x1000U
#define CMD_NEW_CHAIN   0x0100U
#define CMD_NONE   0x0000U
#define CMD_RENAME_CHAIN   0x0800U
#define CMD_REPLACE   0x0008U
#define CMD_SET_POLICY   0x0400U
#define CMD_ZERO   0x0080U
#define CMD_ZERO_NUM   0x2000U
#define DEBUGP (   x,
  args... 
)
#define FMT (   tab,
  notab 
)    ((format) & FMT_NOTABLE ? (notab) : (tab))
#define FMT_KILOMEGAGIGA   0x0004
#define FMT_LINENUMBERS   0x0100
#define FMT_NOCOUNTS   0x0002
#define FMT_NONEWLINE   0x0080
#define FMT_NOTABLE   0x0010
#define FMT_NOTARGET   0x0020
#define FMT_NUMERIC   0x0001
#define FMT_OPTIONS   0x0008
#define FMT_PRINT_RULE
Value:
#define FMT_OPTIONS
Definition: nft-shared.h:28
#define FMT_NOCOUNTS
Definition: nft-shared.h:26
#define FMT_NUMERIC
Definition: nft-shared.h:25
#define FMT_NOTABLE
Definition: nft-shared.h:29
#define FMT_VIA
Definition: nft-shared.h:31
#define FMT_VIA   0x0040

Enumeration Type Documentation

anonymous enum
Enumerator
NFT_XT_CTX_PAYLOAD 
NFT_XT_CTX_META 
NFT_XT_CTX_BITWISE 

Function Documentation

void add_addr ( struct nft_rule r,
int  offset,
void *  data,
void *  mask,
size_t  len,
uint32_t  op 
)

References add_cmp_ptr(), and add_payload().

Here is the call graph for this function:

void add_cmp_ptr ( struct nft_rule r,
uint32_t  op,
void *  data,
size_t  len 
)

References NFT_EXPR_CMP_DATA, NFT_EXPR_CMP_OP, NFT_EXPR_CMP_SREG, NFT_REG_1, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set(), nft_rule_expr_set_u32(), and NULL.

Referenced by add_addr(), add_cmp_u16(), add_cmp_u32(), add_cmp_u8(), add_iniface(), and add_outiface().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_cmp_u16 ( struct nft_rule r,
uint16_t  val,
uint32_t  op 
)

References add_cmp_ptr().

Here is the call graph for this function:

void add_cmp_u32 ( struct nft_rule r,
uint32_t  val,
uint32_t  op 
)

References add_cmp_ptr().

Here is the call graph for this function:

void add_cmp_u8 ( struct nft_rule r,
uint8_t  val,
uint32_t  op 
)

References add_cmp_ptr().

Referenced by add_proto().

Here is the call graph for this function:

Here is the caller graph for this function:

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:

void add_iniface ( struct nft_rule r,
char *  iface,
uint32_t  op 
)

References add_cmp_ptr(), add_meta(), and NFT_META_IIFNAME.

Here is the call graph for this function:

void add_meta ( struct nft_rule r,
uint32_t  key 
)

References NFT_EXPR_META_DREG, NFT_EXPR_META_KEY, NFT_REG_1, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set_u32(), and NULL.

Referenced by add_iniface(), and add_outiface().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_outiface ( struct nft_rule r,
char *  iface,
uint32_t  op 
)

References add_cmp_ptr(), add_meta(), and NFT_META_OIFNAME.

Here is the call graph for this function:

void add_payload ( struct nft_rule r,
int  offset,
int  len 
)

References NFT_EXPR_PAYLOAD_BASE, NFT_EXPR_PAYLOAD_DREG, NFT_EXPR_PAYLOAD_LEN, NFT_EXPR_PAYLOAD_OFFSET, NFT_PAYLOAD_NETWORK_HEADER, NFT_REG_1, nft_rule_add_expr(), nft_rule_expr_alloc(), nft_rule_expr_set_u32(), and NULL.

Referenced by add_addr(), and add_proto().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_proto ( struct nft_rule r,
int  offset,
size_t  len,
uint8_t  proto,
uint32_t  op 
)

References add_cmp_u8(), and add_payload().

Here is the call graph for this function:

bool compare_targets ( struct xtables_target tg1,
struct xtables_target tg2 
)

References xt_entry_target::data, NULL, xtables_target::t, xt_entry_target::u, xt_entry_target::user, and xtables_target::userspacesize.

Referenced by nft_ipv46_rule_find().

Here is the caller graph for this function:

void get_cmp_data ( struct nft_rule_expr e,
void *  data,
size_t  dlen,
bool *  inv 
)

References len, NFT_CMP_NEQ, NFT_EXPR_CMP_DATA, NFT_EXPR_CMP_OP, nft_rule_expr_get(), and nft_rule_expr_get_u32().

Here is the call graph for this function:

bool is_same_interfaces ( const char *  a_iniface,
const char *  a_outiface,
unsigned const char *  a_iniface_mask,
unsigned const char *  a_outiface_mask,
const char *  b_iniface,
const char *  b_outiface,
unsigned const char *  b_iniface_mask,
unsigned const char *  b_outiface_mask 
)

References DEBUGP, and IFNAMSIZ.

struct nft_family_ops* nft_family_ops_lookup ( int  family)
void nft_parse_counter ( struct nft_rule_expr e,
struct xt_counters counters 
)

References xt_counters::bcnt, NFT_EXPR_CTR_BYTES, NFT_EXPR_CTR_PACKETS, nft_rule_expr_get_u64(), and xt_counters::pcnt.

Referenced by nft_rule_to_arptables_command_state(), and nft_rule_to_iptables_command_state().

Here is the call graph for this function:

Here is the caller graph for this function:

void nft_parse_meta ( struct nft_xt_ctx ctx,
struct nft_rule_expr e 
)

References nft_xt_ctx::flags, nft_xt_ctx::key, nft_xt_ctx::meta, NFT_EXPR_META_DREG, NFT_EXPR_META_KEY, nft_rule_expr_get_u32(), NFT_XT_CTX_META, and nft_xt_ctx::reg.

Referenced by nft_rule_to_arptables_command_state(), and nft_rule_to_iptables_command_state().

Here is the call graph for this function:

Here is the caller graph for this function:

void nft_parse_payload ( struct nft_xt_ctx ctx,
struct nft_rule_expr e 
)
void parse_meta ( struct nft_rule_expr e,
uint8_t  key,
char *  iniface,
unsigned char *  iniface_mask,
char *  outiface,
unsigned char *  outiface_mask,
uint8_t *  invflags 
)
void print_firewall_details ( const struct iptables_command_state cs,
const char *  targname,
uint8_t  flags,
uint8_t  invflags,
uint8_t  proto,
unsigned int  num,
unsigned int  format 
)
void print_header ( unsigned int  format,
const char *  chain,
const char *  pol,
const struct xt_counters counters,
bool  basechain,
uint32_t  refs 
)
void print_ifaces ( const char *  iniface,
const char *  outiface,
uint8_t  invflags,
unsigned int  format 
)
void print_proto ( uint16_t  proto,
int  invert 
)
void save_counters ( uint64_t  pcnt,
uint64_t  bcnt 
)
void save_firewall_details ( const struct iptables_command_state cs,
uint8_t  invflags,
uint16_t  proto,
const char *  iniface,
unsigned const char *  iniface_mask,
const char *  outiface,
unsigned const char *  outiface_mask 
)