The comment does not belong to the handle, it belongs to the rule.
Signed-off-by: Patrick McHardy <kaber@trash.net>
* @handle: rule handle (rules only)
* @position: rule position (rules only)
* @set_id: set ID (sets only)
- * @comment: human-readable comment (rules only)
*/
struct handle {
uint32_t family;
uint64_t handle;
uint64_t position;
uint32_t set_id;
- const char *comment;
};
extern void handle_merge(struct handle *dst, const struct handle *src);
* @location: location the rule was defined at
* @stmt: list of statements
* @num_stmts: number of statements in stmts list
+ * @comment: comment
*/
struct rule {
struct list_head list;
struct location location;
struct list_head stmts;
unsigned int num_stmts;
+ const char *comment;
};
extern struct rule *rule_alloc(const struct location *loc,
nftnl_rule_set_u64(nlr, NFTNL_RULE_HANDLE, h->handle);
if (h->position)
nftnl_rule_set_u64(nlr, NFTNL_RULE_POSITION, h->position);
- if (h->comment)
- nftnl_rule_set_data(nlr, NFTNL_RULE_USERDATA,
- h->comment, strlen(h->comment) + 1);
return nlr;
}
if (nftnl_rule_is_set(nlr, NFTNL_RULE_POSITION))
h.position = nftnl_rule_get_u64(nlr, NFTNL_RULE_POSITION);
+ pctx->rule = rule_alloc(&netlink_location, &h);
+ pctx->table = table_lookup(&h);
+ assert(pctx->table != NULL);
+
if (nftnl_rule_is_set(nlr, NFTNL_RULE_USERDATA)) {
- uint32_t len;
const void *data;
+ uint32_t len;
- data = nftnl_rule_get_data(nlr, NFTNL_RULE_USERDATA,
- &len);
- h.comment = xmalloc(len);
- memcpy((char *)h.comment, data, len);
+ data = nftnl_rule_get_data(nlr, NFTNL_RULE_USERDATA, &len);
+ pctx->rule->comment = xmalloc(len);
+ memcpy((char *)pctx->rule->comment, data, len);
}
- pctx->rule = rule_alloc(&netlink_location, &h);
- pctx->table = table_lookup(&h);
- assert(pctx->table != NULL);
nftnl_expr_foreach((struct nftnl_rule *)nlr, netlink_parse_expr, pctx);
rule_parse_postprocess(pctx, pctx->rule);
list_for_each_entry(stmt, &rule->stmts, list)
netlink_gen_stmt(&lctx, stmt);
+ if (rule->comment)
+ nftnl_rule_set_data(nlr, NFTNL_RULE_USERDATA,
+ rule->comment, strlen(rule->comment) + 1);
+
netlink_dump_rule(nlr);
}
struct stmt *i;
$$ = rule_alloc(&@$, NULL);
- $$->handle.comment = $2;
+ $$->comment = $2;
list_for_each_entry(i, $1, list)
$$->num_stmts++;
list_splice_tail($1, &$$->stmts);
xfree(h->table);
xfree(h->chain);
xfree(h->set);
- xfree(h->comment);
}
void handle_merge(struct handle *dst, const struct handle *src)
dst->handle = src->handle;
if (dst->position == 0)
dst->position = src->position;
- if (dst->comment == NULL && src->comment != NULL)
- dst->comment = xstrdup(src->comment);
}
static LIST_HEAD(table_list);
{
stmt_list_free(&rule->stmts);
handle_free(&rule->handle);
+ xfree(rule->comment);
xfree(rule);
}
printf(" ");
}
- if (rule->handle.comment)
- printf("comment \"%s\" ", rule->handle.comment);
+ if (rule->comment)
+ printf("comment \"%s\" ", rule->comment);
if (handle_output > 0)
printf("# handle %" PRIu64, rule->handle.handle);