Commit ff1199db authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: ctnetlink: add and use a helper for mark parsing

ctnetlink dumps can be filtered based on the connmark.

Prepare for status bit filtering by using a named structure and by
moving the mark parsing code to a helper.

Else ctnetlink_alloc_filter size grows a bit too big for my taste
when status handling is added.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 87663c39
...@@ -852,6 +852,11 @@ static int ctnetlink_done(struct netlink_callback *cb) ...@@ -852,6 +852,11 @@ static int ctnetlink_done(struct netlink_callback *cb)
return 0; return 0;
} }
struct ctnetlink_filter_u32 {
u32 val;
u32 mask;
};
struct ctnetlink_filter { struct ctnetlink_filter {
u8 family; u8 family;
...@@ -862,10 +867,7 @@ struct ctnetlink_filter { ...@@ -862,10 +867,7 @@ struct ctnetlink_filter {
struct nf_conntrack_tuple reply; struct nf_conntrack_tuple reply;
struct nf_conntrack_zone zone; struct nf_conntrack_zone zone;
struct { struct ctnetlink_filter_u32 mark;
u_int32_t val;
u_int32_t mask;
} mark;
}; };
static const struct nla_policy cta_filter_nla_policy[CTA_FILTER_MAX + 1] = { static const struct nla_policy cta_filter_nla_policy[CTA_FILTER_MAX + 1] = {
...@@ -907,6 +909,24 @@ static int ctnetlink_parse_tuple_filter(const struct nlattr * const cda[], ...@@ -907,6 +909,24 @@ static int ctnetlink_parse_tuple_filter(const struct nlattr * const cda[],
struct nf_conntrack_zone *zone, struct nf_conntrack_zone *zone,
u_int32_t flags); u_int32_t flags);
static int ctnetlink_filter_parse_mark(struct ctnetlink_filter_u32 *mark,
const struct nlattr * const cda[])
{
#ifdef CONFIG_NF_CONNTRACK_MARK
if (cda[CTA_MARK]) {
mark->val = ntohl(nla_get_be32(cda[CTA_MARK]));
if (cda[CTA_MARK_MASK])
mark->mask = ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
else
mark->mask = 0xffffffff;
} else if (cda[CTA_MARK_MASK]) {
return -EINVAL;
}
#endif
return 0;
}
static struct ctnetlink_filter * static struct ctnetlink_filter *
ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family) ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
{ {
...@@ -924,18 +944,10 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family) ...@@ -924,18 +944,10 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
filter->family = family; filter->family = family;
#ifdef CONFIG_NF_CONNTRACK_MARK err = ctnetlink_filter_parse_mark(&filter->mark, cda);
if (cda[CTA_MARK]) { if (err)
filter->mark.val = ntohl(nla_get_be32(cda[CTA_MARK]));
if (cda[CTA_MARK_MASK])
filter->mark.mask = ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
else
filter->mark.mask = 0xffffffff;
} else if (cda[CTA_MARK_MASK]) {
err = -EINVAL;
goto err_filter; goto err_filter;
}
#endif
if (!cda[CTA_FILTER]) if (!cda[CTA_FILTER])
return filter; return filter;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment