type = "set";
}
- root = json_pack("{s:s, s:s, s:s, s:o}",
+ root = json_pack("{s:s, s:s, s:s, s:o, s:I}",
"family", family2str(set->handle.family),
"name", set->handle.set.name,
"table", set->handle.table.name,
- "type", set_dtype_json(set->key));
- if (octx->handle)
- json_object_set_new(root, "handle",
- json_integer(set->handle.handle.id));
+ "type", set_dtype_json(set->key),
+ "handle", set->handle.handle.id);
if (datatype_ext)
json_object_set_new(root, "map", json_string(datatype_ext));
"family", family2str(rule->handle.family),
"table", rule->handle.table.name,
"chain", rule->handle.chain.name,
- "position", rule->handle.position.id);
- if (octx->handle)
- json_object_set_new(root, "handle",
- json_integer(rule->handle.handle.id));
+ "handle", rule->handle.handle.id);
if (rule->comment)
json_object_set_new(root, "comment",
json_string(rule->comment));
{
json_t *root, *tmp;
- root = json_pack("{s:s, s:s, s:s}",
+ root = json_pack("{s:s, s:s, s:s, s:I}",
"family", family2str(chain->handle.family),
"table", chain->handle.table.name,
- "name", chain->handle.chain.name);
- if (octx->handle)
- json_object_set_new(root, "handle",
- json_integer(chain->handle.handle.id));
+ "name", chain->handle.chain.name,
+ "handle", chain->handle.handle.id);
if (chain->flags & CHAIN_F_BASECHAIN) {
tmp = json_pack("{s:s, s:s, s:i, s:s}",
const char *unit;
uint64_t rate;
- root = json_pack("{s:s, s:s, s:s}",
+ root = json_pack("{s:s, s:s, s:s, s:I}",
"family", family2str(obj->handle.family),
"name", obj->handle.obj.name,
- "table", obj->handle.table.name);
- if (octx->handle)
- json_object_set_new(root, "handle",
- json_integer(obj->handle.handle.id));
+ "table", obj->handle.table.name,
+ "handle", obj->handle.handle.id);
switch (obj->type) {
case NFT_OBJECT_COUNTER:
{
json_t *root, *tmp;
- root = json_pack("{s:s, s:s}",
+ root = json_pack("{s:s, s:s, s:I}",
"family", family2str(table->handle.family),
- "name", table->handle.table.name);
- if (octx->handle)
- json_object_set_new(root, "handle",
- json_integer(table->handle.handle.id));
+ "name", table->handle.table.name,
+ "handle", table->handle.handle.id);
tmp = table_flags_json(table);
if (tmp)
"chain", &h.chain.name,
"expr", &tmp))
return NULL;
+ json_unpack(root, "{s:I}", "handle", &h.handle.id);
+ json_unpack(root, "{s:I}", "index", &h.index.id);
- if (op == CMD_REPLACE &&
- json_unpack_err(ctx, root, "{s:I}", "handle", &h.handle.id))
+ if (op == CMD_REPLACE && !h.handle.id) {
+ json_error(ctx, "Handle is required when replacing a rule.");
return NULL;
+ }
- if (op == CMD_INSERT &&
- json_unpack_err(ctx, root, "{s:i}", "pos", &h.position.id))
- return NULL;
+ if ((op == CMD_INSERT || op == CMD_ADD) && h.handle.id) {
+ h.position.id = h.handle.id;
+ h.handle.id = 0;
+ }
h.family = parse_family(family);
if (h.family < 0) {
json_output = json.loads(json_output)
for item in json_output["nftables"]:
if "rule" in item:
- if "handle" in item["rule"]:
- del(item["rule"]["handle"])
- if "position" in item["rule"]:
- del(item["rule"]["position"])
+ del(item["rule"]["handle"])
json_output = item["rule"]
break
json_input = json.dumps(json_output["expr"], sort_keys = True)
json_output = json.loads(json_output)
for item in json_output["nftables"]:
if "rule" in item:
- if "handle" in item["rule"]:
- del(item["rule"]["handle"])
- if "position" in item["rule"]:
- del(item["rule"]["position"])
+ del(item["rule"]["handle"])
json_output = item["rule"]
break
json_output = json.dumps(json_output["expr"], sort_keys = True)