summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/rule.c b/src/rule.c
index 0bb1c2a..e16e2c1 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -115,21 +115,11 @@ int nftnl_rule_set_data(struct nftnl_rule *r, uint16_t attr,
switch(attr) {
case NFTNL_RULE_TABLE:
- if (r->flags & (1 << NFTNL_RULE_TABLE))
- xfree(r->table);
-
- r->table = strdup(data);
- if (!r->table)
- return -1;
- break;
+ return nftnl_set_str_attr(&r->table, &r->flags,
+ attr, data, data_len);
case NFTNL_RULE_CHAIN:
- if (r->flags & (1 << NFTNL_RULE_CHAIN))
- xfree(r->chain);
-
- r->chain = strdup(data);
- if (!r->chain)
- return -1;
- break;
+ return nftnl_set_str_attr(&r->chain, &r->flags,
+ attr, data, data_len);
case NFTNL_RULE_HANDLE:
memcpy(&r->handle, data, sizeof(r->handle));
break;
@@ -622,12 +612,13 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
for (i = 0; i < r->user.len; i++) {
char *c = r->user.data;
- ret = snprintf(buf + offset, remain, "%c",
- isalnum(c[i]) ? c[i] : 0);
+ ret = snprintf(buf + offset, remain,
+ isprint(c[i]) ? "%c" : "\\x%02hhx",
+ c[i]);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
- ret = snprintf(buf + offset, remain, " }\n");
+ ret = snprintf(buf + offset, remain, " }");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}