nftnl_rule_get_str(o->rule, NFTNL_RULE_CHAIN));
#if 0
{
- struct iptables_command_state cs = {};
- nft_rule_to_iptables_command_state(o->rule, &cs);
- nft_rule_print_save(&cs, o->rule, NFT_RULE_APPEND, FMT_NOCOUNTS);
+ nft_rule_print_save(o->rule, NFT_RULE_APPEND, FMT_NOCOUNTS);
}
#endif
break;
}
void
-nft_rule_print_save(const void *data,
- struct nftnl_rule *r, enum nft_rule_print type,
+nft_rule_print_save(const struct nftnl_rule *r, enum nft_rule_print type,
unsigned int format)
{
const char *chain = nftnl_rule_get_str(r, NFTNL_RULE_CHAIN);
int family = nftnl_rule_get_u32(r, NFTNL_RULE_FAMILY);
+ struct iptables_command_state cs = {};
struct nft_family_ops *ops;
ops = nft_family_ops_lookup(family);
+ ops->rule_to_cs(r, &cs);
if (!(format & FMT_NOCOUNTS) && ops->save_counters)
- ops->save_counters(data);
+ ops->save_counters(&cs);
/* print chain name */
switch(type) {
}
if (ops->save_firewall)
- ops->save_firewall(data, format);
+ ops->save_firewall(&cs, format);
+ if (ops->clear_cs)
+ ops->clear_cs(&cs);
}
static int nftnl_chain_list_cb(const struct nlmsghdr *nlh, void *data)
while (r != NULL) {
const char *rule_table =
nftnl_rule_get_str(r, NFTNL_RULE_TABLE);
- struct iptables_command_state cs = {};
if (strcmp(table, rule_table) != 0)
goto next;
- nft_rule_to_iptables_command_state(r, &cs);
-
- nft_rule_print_save(&cs, r, NFT_RULE_APPEND,
+ nft_rule_print_save(r, NFT_RULE_APPEND,
counters ? 0 : FMT_NOCOUNTS);
next:
static void
list_save(struct nftnl_rule *r, unsigned int num, unsigned int format)
{
- struct iptables_command_state cs = {};
-
- nft_rule_to_iptables_command_state(r, &cs);
-
- nft_rule_print_save(&cs, r, NFT_RULE_APPEND, !(format & FMT_NOCOUNTS));
+ nft_rule_print_save(r, NFT_RULE_APPEND, !(format & FMT_NOCOUNTS));
}
static int
static int rule_cb(const struct nlmsghdr *nlh, void *data)
{
- struct iptables_command_state cs = {};
uint32_t type = nlh->nlmsg_type & 0xFF;
const struct cb_arg *arg = data;
struct nftnl_rule *r;
case AF_INET:
case AF_INET6:
printf("-%c ", family == AF_INET ? '4' : '6');
- nft_rule_to_iptables_command_state(r, &cs);
break;
case NFPROTO_ARP:
printf("-0 ");
- nft_rule_to_arptables_command_state(r, &cs);
break;
default:
goto err_free;
}
printf("-t %s ", nftnl_rule_get_str(r, NFTNL_RULE_TABLE));
- nft_rule_print_save(&cs, r,
- type == NFT_MSG_NEWRULE ? NFT_RULE_APPEND :
+ nft_rule_print_save(r, type == NFT_MSG_NEWRULE ? NFT_RULE_APPEND :
NFT_RULE_DEL,
counters ? 0 : FMT_NOCOUNTS);
err_free: