|
Packit Service |
d1fe03 |
#ifndef _NFT_SHARED_H_
|
|
Packit Service |
d1fe03 |
#define _NFT_SHARED_H_
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#include <stdbool.h>
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#include <libnftnl/rule.h>
|
|
Packit Service |
d1fe03 |
#include <libnftnl/expr.h>
|
|
Packit Service |
d1fe03 |
#include <libnftnl/chain.h>
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#include <linux/netfilter_arp/arp_tables.h>
|
|
Packit Service |
7b1493 |
#include <linux/netfilter/nf_tables.h>
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#include "xshared.h"
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#ifdef DEBUG
|
|
Packit Service |
d1fe03 |
#define NLDEBUG
|
|
Packit Service |
d1fe03 |
#define DEBUG_DEL
|
|
Packit Service |
d1fe03 |
#endif
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
/*
|
|
Packit Service |
d1fe03 |
* iptables print output emulation
|
|
Packit Service |
d1fe03 |
*/
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#define FMT_NUMERIC 0x0001
|
|
Packit Service |
d1fe03 |
#define FMT_NOCOUNTS 0x0002
|
|
Packit Service |
d1fe03 |
#define FMT_KILOMEGAGIGA 0x0004
|
|
Packit Service |
d1fe03 |
#define FMT_OPTIONS 0x0008
|
|
Packit Service |
d1fe03 |
#define FMT_NOTABLE 0x0010
|
|
Packit Service |
d1fe03 |
#define FMT_NOTARGET 0x0020
|
|
Packit Service |
d1fe03 |
#define FMT_VIA 0x0040
|
|
Packit Service |
d1fe03 |
#define FMT_NONEWLINE 0x0080
|
|
Packit Service |
d1fe03 |
#define FMT_LINENUMBERS 0x0100
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \
|
|
Packit Service |
d1fe03 |
| FMT_NUMERIC | FMT_NOTABLE)
|
|
Packit Service |
d1fe03 |
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct xtables_args;
|
|
Packit Service |
d1fe03 |
struct nft_handle;
|
|
Packit Service |
d1fe03 |
struct xt_xlate;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
enum {
|
|
Packit Service |
d1fe03 |
NFT_XT_CTX_PAYLOAD = (1 << 0),
|
|
Packit Service |
d1fe03 |
NFT_XT_CTX_META = (1 << 1),
|
|
Packit Service |
d1fe03 |
NFT_XT_CTX_BITWISE = (1 << 2),
|
|
Packit Service |
d1fe03 |
NFT_XT_CTX_IMMEDIATE = (1 << 3),
|
|
Packit Service |
d1fe03 |
NFT_XT_CTX_PREV_PAYLOAD = (1 << 4),
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_xt_ctx {
|
|
Packit Service |
d1fe03 |
struct iptables_command_state *cs;
|
|
Packit Service |
d1fe03 |
struct nftnl_expr_iter *iter;
|
|
Packit Service |
d1fe03 |
struct nft_handle *h;
|
|
Packit Service |
d1fe03 |
uint32_t flags;
|
|
Packit Service |
d1fe03 |
const char *table;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
uint32_t reg;
|
|
Packit Service |
d1fe03 |
struct {
|
|
Packit Service |
d1fe03 |
uint32_t base;
|
|
Packit Service |
d1fe03 |
uint32_t offset;
|
|
Packit Service |
d1fe03 |
uint32_t len;
|
|
Packit Service |
d1fe03 |
} payload, prev_payload;
|
|
Packit Service |
d1fe03 |
struct {
|
|
Packit Service |
d1fe03 |
uint32_t key;
|
|
Packit Service |
d1fe03 |
} meta;
|
|
Packit Service |
d1fe03 |
struct {
|
|
Packit Service |
d1fe03 |
uint32_t data[4];
|
|
Packit Service |
d1fe03 |
uint32_t len, reg;
|
|
Packit Service |
d1fe03 |
} immediate;
|
|
Packit Service |
d1fe03 |
struct {
|
|
Packit Service |
d1fe03 |
uint32_t mask[4];
|
|
Packit Service |
d1fe03 |
uint32_t xor[4];
|
|
Packit Service |
d1fe03 |
} bitwise;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_family_ops {
|
|
Packit Service |
d1fe03 |
int (*add)(struct nft_handle *h, struct nftnl_rule *r, void *data);
|
|
Packit Service |
d1fe03 |
bool (*is_same)(const void *data_a,
|
|
Packit Service |
d1fe03 |
const void *data_b);
|
|
Packit Service |
d1fe03 |
void (*print_payload)(struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
struct nftnl_expr_iter *iter);
|
|
Packit Service |
d1fe03 |
void (*parse_meta)(struct nft_xt_ctx *ctx, struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_payload)(struct nft_xt_ctx *ctx, struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_bitwise)(struct nft_xt_ctx *ctx, struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_cmp)(struct nft_xt_ctx *ctx, struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_lookup)(struct nft_xt_ctx *ctx, struct nftnl_expr *e,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_immediate)(const char *jumpto, bool nft_goto, void *data);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void (*print_table_header)(const char *tablename);
|
|
Packit Service |
d1fe03 |
void (*print_header)(unsigned int format, const char *chain,
|
|
Packit Service |
d1fe03 |
const char *pol,
|
|
Packit Service |
d1fe03 |
const struct xt_counters *counters, bool basechain,
|
|
Packit Service |
d1fe03 |
uint32_t refs, uint32_t entries);
|
|
Packit Service |
d1fe03 |
void (*print_rule)(struct nft_handle *h, struct nftnl_rule *r,
|
|
Packit Service |
d1fe03 |
unsigned int num, unsigned int format);
|
|
Packit Service |
d1fe03 |
void (*save_rule)(const void *data, unsigned int format);
|
|
Packit Service |
d1fe03 |
void (*save_counters)(const void *data);
|
|
Packit Service |
d1fe03 |
void (*save_chain)(const struct nftnl_chain *c, const char *policy);
|
|
Packit Service |
d1fe03 |
void (*proto_parse)(struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
struct xtables_args *args);
|
|
Packit Service |
d1fe03 |
void (*post_parse)(int command, struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
struct xtables_args *args);
|
|
Packit Service |
d1fe03 |
void (*parse_match)(struct xtables_match *m, void *data);
|
|
Packit Service |
d1fe03 |
void (*parse_target)(struct xtables_target *t, void *data);
|
|
Packit Service |
d1fe03 |
void (*rule_to_cs)(struct nft_handle *h, const struct nftnl_rule *r,
|
|
Packit Service |
d1fe03 |
struct iptables_command_state *cs);
|
|
Packit Service |
d1fe03 |
void (*clear_cs)(struct iptables_command_state *cs);
|
|
Packit Service |
d1fe03 |
bool (*rule_find)(struct nft_handle *h, struct nftnl_rule *r,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
int (*xlate)(const void *data, struct xt_xlate *xl);
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void add_meta(struct nftnl_rule *r, uint32_t key);
|
|
Packit Service |
d1fe03 |
void add_payload(struct nftnl_rule *r, int offset, int len, uint32_t base);
|
|
Packit Service |
d1fe03 |
void add_bitwise(struct nftnl_rule *r, uint8_t *mask, size_t len);
|
|
Packit Service |
d1fe03 |
void add_bitwise_u16(struct nftnl_rule *r, uint16_t mask, uint16_t xor);
|
|
Packit Service |
d1fe03 |
void add_cmp_ptr(struct nftnl_rule *r, uint32_t op, void *data, size_t len);
|
|
Packit Service |
d1fe03 |
void add_cmp_u8(struct nftnl_rule *r, uint8_t val, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_cmp_u16(struct nftnl_rule *r, uint16_t val, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_cmp_u32(struct nftnl_rule *r, uint32_t val, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_iniface(struct nftnl_rule *r, char *iface, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_outiface(struct nftnl_rule *r, char *iface, uint32_t op);
|
|
Packit Service |
7b1493 |
void add_addr(struct nftnl_rule *r, enum nft_payload_bases base, int offset,
|
|
Packit Service |
d1fe03 |
void *data, void *mask, size_t len, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_proto(struct nftnl_rule *r, int offset, size_t len,
|
|
Packit Service |
d1fe03 |
uint8_t proto, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_l4proto(struct nftnl_rule *r, uint8_t proto, uint32_t op);
|
|
Packit Service |
d1fe03 |
void add_compat(struct nftnl_rule *r, uint32_t proto, bool inv);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
bool is_same_interfaces(const char *a_iniface, const char *a_outiface,
|
|
Packit Service |
d1fe03 |
unsigned const char *a_iniface_mask,
|
|
Packit Service |
d1fe03 |
unsigned const char *a_outiface_mask,
|
|
Packit Service |
d1fe03 |
const char *b_iniface, const char *b_outiface,
|
|
Packit Service |
d1fe03 |
unsigned const char *b_iniface_mask,
|
|
Packit Service |
d1fe03 |
unsigned const char *b_outiface_mask);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
int parse_meta(struct nftnl_expr *e, uint8_t key, char *iniface,
|
|
Packit Service |
d1fe03 |
unsigned char *iniface_mask, char *outiface,
|
|
Packit Service |
d1fe03 |
unsigned char *outiface_mask, uint8_t *invflags);
|
|
Packit Service |
d1fe03 |
void print_proto(uint16_t proto, int invert);
|
|
Packit Service |
d1fe03 |
void get_cmp_data(struct nftnl_expr *e, void *data, size_t dlen, bool *inv);
|
|
Packit Service |
d1fe03 |
void nft_rule_to_iptables_command_state(struct nft_handle *h,
|
|
Packit Service |
d1fe03 |
const struct nftnl_rule *r,
|
|
Packit Service |
d1fe03 |
struct iptables_command_state *cs);
|
|
Packit Service |
d1fe03 |
void nft_clear_iptables_command_state(struct iptables_command_state *cs);
|
|
Packit Service |
d1fe03 |
void print_header(unsigned int format, const char *chain, const char *pol,
|
|
Packit Service |
d1fe03 |
const struct xt_counters *counters, bool basechain,
|
|
Packit Service |
d1fe03 |
uint32_t refs, uint32_t entries);
|
|
Packit Service |
d1fe03 |
void print_rule_details(const struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
const char *targname, uint8_t flags,
|
|
Packit Service |
d1fe03 |
uint8_t invflags, uint8_t proto,
|
|
Packit Service |
d1fe03 |
unsigned int num, unsigned int format);
|
|
Packit Service |
d1fe03 |
void print_matches_and_target(struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
unsigned int format);
|
|
Packit Service |
d1fe03 |
void save_rule_details(const struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
uint8_t invflags, uint16_t proto,
|
|
Packit Service |
d1fe03 |
const char *iniface,
|
|
Packit Service |
d1fe03 |
unsigned const char *iniface_mask,
|
|
Packit Service |
d1fe03 |
const char *outiface,
|
|
Packit Service |
d1fe03 |
unsigned const char *outiface_mask);
|
|
Packit Service |
d1fe03 |
void save_counters(const void *data);
|
|
Packit Service |
d1fe03 |
void nft_ipv46_save_chain(const struct nftnl_chain *c, const char *policy);
|
|
Packit Service |
d1fe03 |
void save_matches_and_target(const struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
bool goto_flag, const void *fw,
|
|
Packit Service |
d1fe03 |
unsigned int format);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_family_ops *nft_family_ops_lookup(int family);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void nft_ipv46_parse_target(struct xtables_target *t, void *data);
|
|
Packit Service |
d1fe03 |
bool nft_ipv46_rule_find(struct nft_handle *h, struct nftnl_rule *r,
|
|
Packit Service |
d1fe03 |
void *data);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
bool compare_matches(struct xtables_rule_match *mt1, struct xtables_rule_match *mt2);
|
|
Packit Service |
d1fe03 |
bool compare_targets(struct xtables_target *tg1, struct xtables_target *tg2);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct addr_mask {
|
|
Packit Service |
d1fe03 |
union {
|
|
Packit Service |
d1fe03 |
struct in_addr *v4;
|
|
Packit Service |
d1fe03 |
struct in6_addr *v6;
|
|
Packit Service |
d1fe03 |
} addr;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
unsigned int naddrs;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
union {
|
|
Packit Service |
d1fe03 |
struct in_addr *v4;
|
|
Packit Service |
d1fe03 |
struct in6_addr *v6;
|
|
Packit Service |
d1fe03 |
} mask;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct xtables_args {
|
|
Packit Service |
d1fe03 |
int family;
|
|
Packit Service |
d1fe03 |
uint16_t proto;
|
|
Packit Service |
d1fe03 |
uint8_t flags;
|
|
Packit Service |
d1fe03 |
uint8_t invflags;
|
|
Packit Service |
d1fe03 |
char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
|
|
Packit Service |
d1fe03 |
unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
|
|
Packit Service |
d1fe03 |
bool goto_set;
|
|
Packit Service |
d1fe03 |
const char *shostnetworkmask, *dhostnetworkmask;
|
|
Packit Service |
d1fe03 |
const char *pcnt, *bcnt;
|
|
Packit Service |
d1fe03 |
struct addr_mask s, d;
|
|
Packit Service |
d1fe03 |
unsigned long long pcnt_cnt, bcnt_cnt;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_xt_cmd_parse {
|
|
Packit Service |
d1fe03 |
unsigned int command;
|
|
Packit Service |
d1fe03 |
unsigned int rulenum;
|
|
Packit Service |
d1fe03 |
char *table;
|
|
Packit Service |
d1fe03 |
const char *chain;
|
|
Packit Service |
d1fe03 |
const char *newname;
|
|
Packit Service |
d1fe03 |
const char *policy;
|
|
Packit Service |
d1fe03 |
bool restore;
|
|
Packit Service |
d1fe03 |
int verbose;
|
|
Packit Service |
d1fe03 |
bool xlate;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void do_parse(struct nft_handle *h, int argc, char *argv[],
|
|
Packit Service |
d1fe03 |
struct nft_xt_cmd_parse *p, struct iptables_command_state *cs,
|
|
Packit Service |
d1fe03 |
struct xtables_args *args);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nftnl_chain_list;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_xt_restore_cb {
|
|
Packit Service |
d1fe03 |
void (*table_new)(struct nft_handle *h, const char *table);
|
|
Packit Service |
d1fe03 |
int (*chain_set)(struct nft_handle *h, const char *table,
|
|
Packit Service |
d1fe03 |
const char *chain, const char *policy,
|
|
Packit Service |
d1fe03 |
const struct xt_counters *counters);
|
|
Packit Service |
d1fe03 |
int (*chain_restore)(struct nft_handle *h, const char *chain,
|
|
Packit Service |
d1fe03 |
const char *table);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
int (*table_flush)(struct nft_handle *h, const char *table);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
int (*do_command)(struct nft_handle *h, int argc, char *argv[],
|
|
Packit Service |
d1fe03 |
char **table, bool restore);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
int (*commit)(struct nft_handle *h);
|
|
Packit Service |
d1fe03 |
int (*abort)(struct nft_handle *h);
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct nft_xt_restore_parse {
|
|
Packit Service |
d1fe03 |
FILE *in;
|
|
Packit Service |
d1fe03 |
int testing;
|
|
Packit Service |
d1fe03 |
const char *tablename;
|
|
Packit Service |
d1fe03 |
bool commit;
|
|
Packit Service |
d1fe03 |
const struct nft_xt_restore_cb *cb;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void xtables_restore_parse(struct nft_handle *h,
|
|
Packit Service |
d1fe03 |
const struct nft_xt_restore_parse *p);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void nft_check_xt_legacy(int family, bool is_ipt_save);
|
|
Packit Service |
d6b995 |
|
|
Packit Service |
d6b995 |
#define min(x, y) ((x) < (y) ? (x) : (y))
|
|
Packit Service |
d6b995 |
#define max(x, y) ((x) > (y) ? (x) : (y))
|
|
Packit Service |
d6b995 |
|
|
Packit Service |
d1fe03 |
#endif
|