summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/utils.h10
-rw-r--r--src/rule.c19
-rw-r--r--src/set_elem.c18
3 files changed, 18 insertions, 29 deletions
diff --git a/include/utils.h b/include/utils.h
index 1049289..5dcd287 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -91,4 +91,14 @@ char *nftnl_attr_get_ifname(const struct nlattr *attr);
int nftnl_parse_str_attr(const struct nlattr *tb, int attr,
const char **field, uint32_t *flags);
+static inline uint32_t bytesum(uint8_t *buf, size_t buflen)
+{
+ uint32_t ret = 0;
+
+ while (buflen--)
+ ret += buf[buflen];
+
+ return ret;
+}
+
#endif
diff --git a/src/rule.c b/src/rule.c
index cd3041e..f810996 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -509,8 +509,8 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
uint32_t type, uint32_t flags)
{
struct nftnl_expr *expr;
- int ret, offset = 0, i;
const char *sep = "";
+ int ret, offset = 0;
if (r->flags & (1 << NFTNL_RULE_FAMILY)) {
ret = snprintf(buf + offset, remain, "%s%s", sep,
@@ -573,21 +573,10 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
}
if (r->user.len) {
- ret = snprintf(buf + offset, remain, "\n userdata = { ");
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
- for (i = 0; i < r->user.len; i++) {
- char *c = r->user.data;
-
- ret = snprintf(buf + offset, remain,
- isprint(c[i]) ? "%c" : "\\x%02hhx",
- c[i]);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- }
-
- ret = snprintf(buf + offset, remain, " }");
+ ret = snprintf(buf + offset, remain,
+ "\n userdata len %d sum 0x%x",
+ r->user.len, bytesum(r->user.data, r->user.len));
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
}
return offset;
diff --git a/src/set_elem.c b/src/set_elem.c
index d22643c..3e0ab0c 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -705,7 +705,7 @@ int nftnl_set_elem_parse_file(struct nftnl_set_elem *e, enum nftnl_parse_type ty
int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
const struct nftnl_set_elem *e)
{
- int ret, dregtype = DATA_NONE, offset = 0, i;
+ int ret, dregtype = DATA_NONE, offset = 0;
ret = snprintf(buf, remain, "element ");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
@@ -748,19 +748,9 @@ int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
}
if (e->user.len) {
- ret = snprintf(buf + offset, remain, " userdata = { ");
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
- for (i = 0; i < e->user.len; i++) {
- char *c = e->user.data;
-
- ret = snprintf(buf + offset, remain,
- isprint(c[i]) ? "%c" : "\\x%02hhx",
- c[i]);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- }
-
- ret = snprintf(buf + offset, remain, " }");
+ ret = snprintf(buf + offset, remain,
+ " userdata len %d sum 0x%x",
+ e->user.len, bytesum(e->user.data, e->user.len));
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}