struct list_head head;
enum obj_update_type type:8;
uint8_t skip:1;
+ uint8_t implicit:1;
unsigned int seq;
union {
struct nftnl_table *table;
return batch_add(h, type, c) ? 0 : -1;
}
-static int batch_rule_add(struct nft_handle *h, enum obj_update_type type,
+static struct obj_update *
+batch_rule_add(struct nft_handle *h, enum obj_update_type type,
struct nftnl_rule *r)
{
- return batch_add(h, type, r) ? 0 : -1;
+ return batch_add(h, type, r);
}
const struct builtin_table xtables_ipv4[NFT_TABLE_MAX] = {
} else
type = NFT_COMPAT_RULE_APPEND;
- if (batch_rule_add(h, type, r) < 0) {
+ if (batch_rule_add(h, type, r) == NULL) {
nftnl_rule_free(r);
return 0;
}
}
nftnl_chain_set_u32(c, NFTNL_CHAIN_POLICY, verdict);
- if (batch_rule_add(h, NFT_COMPAT_RULE_DELETE, last) < 0)
+ if (batch_rule_add(h, NFT_COMPAT_RULE_DELETE, last) == NULL)
fprintf(stderr, "Failed to delete old policy rule\n");
nftnl_chain_rule_del(last);
out_iter:
static void
__nft_rule_flush(struct nft_handle *h, const char *table,
- const char *chain, bool verbose)
+ const char *chain, bool verbose, bool implicit)
{
+ struct obj_update *obj;
struct nftnl_rule *r;
if (verbose)
nftnl_rule_set(r, NFTNL_RULE_TABLE, (char *)table);
nftnl_rule_set(r, NFTNL_RULE_CHAIN, (char *)chain);
- if (batch_rule_add(h, NFT_COMPAT_RULE_FLUSH, r) < 0)
+ obj = batch_rule_add(h, NFT_COMPAT_RULE_FLUSH, r);
+ if (!obj) {
nftnl_rule_free(r);
+ return;
+ }
+
+ obj->implicit = 1;
}
int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
if (!c)
return 0;
- __nft_rule_flush(h, table, chain, verbose);
+ __nft_rule_flush(h, table, chain, verbose, false);
flush_rule_cache(c);
return 1;
}
const char *chain_name =
nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
- __nft_rule_flush(h, table, chain_name, verbose);
+ __nft_rule_flush(h, table, chain_name, verbose, false);
flush_rule_cache(c);
c = nftnl_chain_list_iter_next(iter);
}
* chains that are redefined.
*/
if (h->noflush)
- __nft_rule_flush(h, table, chain, false);
+ __nft_rule_flush(h, table, chain, false, true);
} else {
c = nftnl_chain_alloc();
if (!c)
static int __nft_rule_del(struct nft_handle *h, struct nftnl_rule *r)
{
- int ret;
+ struct obj_update *obj;
nftnl_rule_list_del(r);
- ret = batch_rule_add(h, NFT_COMPAT_RULE_DELETE, r);
- if (ret < 0) {
+ obj = batch_rule_add(h, NFT_COMPAT_RULE_DELETE, r);
+ if (!obj) {
nftnl_rule_free(r);
return -1;
}
}
}
- if (batch_rule_add(h, NFT_COMPAT_RULE_INSERT, r) < 0) {
+ if (!batch_rule_add(h, NFT_COMPAT_RULE_INSERT, r)) {
nftnl_rule_free(r);
return NULL;
}
nftnl_udata_buf_len(udata));
nftnl_udata_buf_free(udata);
- if (batch_rule_add(h, NFT_COMPAT_RULE_APPEND, r) < 0) {
+ if (!batch_rule_add(h, NFT_COMPAT_RULE_APPEND, r)) {
nftnl_rule_free(r);
return -1;
}
struct nft_handle *h = d->handle;
struct nftnl_rule_iter *iter;
struct nftnl_rule *r;
- int ret = 0;
if (d->verbose)
fprintf(stdout, "Zeroing chain `%s'\n",
nftnl_chain_set_u64(c, NFTNL_CHAIN_PACKETS, 0);
nftnl_chain_set_u64(c, NFTNL_CHAIN_BYTES, 0);
nftnl_chain_unset(c, NFTNL_CHAIN_HANDLE);
- ret = batch_chain_add(h, NFT_COMPAT_CHAIN_ZERO, c);
- if (ret)
+ if (batch_chain_add(h, NFT_COMPAT_CHAIN_ZERO, c))
return -1;
}
* rule based on its handle only.
*/
nftnl_rule_unset(r, NFTNL_RULE_POSITION);
- ret = batch_rule_add(h, NFT_COMPAT_RULE_REPLACE, r);
- if (ret)
+ if (!batch_rule_add(h, NFT_COMPAT_RULE_REPLACE, r))
return -1;
}
r = nftnl_rule_iter_next(iter);