summaryrefslogtreecommitdiffstats
path: root/extensions/libxt_devgroup.c
diff options
context:
space:
mode:
authorShivani Bhardwaj <shivanib134@gmail.com>2015-12-23 20:14:02 +0530
committerPablo Neira Ayuso <pablo@netfilter.org>2016-02-16 19:30:22 +0100
commit924ab13fb48eb45b5f41fb8cfc897e7eafaa11b8 (patch)
tree206b9ebcc5b5e35dc4aed62f3eccfc9253bf8f73 /extensions/libxt_devgroup.c
parente172b5f5920674b7992a124e335664e34a006b90 (diff)
extensions: libxt_devgroup: Add translation to nft
Add translation for device group to nftables. Examples: $ sudo iptables-translate -A FORWARD -m devgroup --src-group 0x2 -j ACCEPT nft add rule ip filter FORWARD iifgroup 0x2 counter accept $ sudo iptables-translate -A FORWARD -m devgroup --dst-group 0xc/0xc -j ACCEPT nft add rule ip filter FORWARD oifgroup and 0xc == 0xc counter accept $ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 46000 -m devgroup --src-group 23 -j ACCEPT nft add rule ip mangle PREROUTING tcp dport 46000 iifgroup 0x17 counter accept $ sudo iptables-translate -A FORWARD -m devgroup ! --dst-group 0xc/0xc -j ACCEPT nft add rule ip filter FORWARD oifgroup and 0xc != 0xc counter accept $ sudo iptables-translate -A FORWARD -m devgroup ! --src-group 0x2 -j ACCEPT nft add rule ip filter FORWARD iifgroup != 0x2 counter accept Signed-off-by : Shivani Bhardwaj <shivanib134@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'extensions/libxt_devgroup.c')
-rw-r--r--extensions/libxt_devgroup.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c
index 1a526273..645f2f31 100644
--- a/extensions/libxt_devgroup.c
+++ b/extensions/libxt_devgroup.c
@@ -151,6 +151,58 @@ static void devgroup_check(struct xt_fcheck_call *cb)
"'--src-group' or '--dst-group'");
}
+static void
+print_devgroup_xlate(unsigned int id, uint32_t op, unsigned int mask,
+ struct xt_buf *buf, int numeric)
+{
+ const char *name = NULL;
+
+ if (mask != 0xffffffff)
+ xt_buf_add(buf, "and 0x%x %s 0x%x ", id,
+ op == XT_OP_EQ ? "==" : "!=", mask);
+ else {
+ if (numeric == 0)
+ name = xtables_lmap_id2name(devgroups, id);
+ if (name)
+ xt_buf_add(buf, "%s ", name);
+ else
+ xt_buf_add(buf, "%s0x%x ",
+ op == XT_OP_EQ ? "" : "!= ", id);
+ }
+}
+
+static void devgroup_show_xlate(const struct xt_devgroup_info *info,
+ struct xt_buf *buf, int numeric)
+{
+ enum xt_op op = XT_OP_EQ;
+
+ if (info->flags & XT_DEVGROUP_MATCH_SRC) {
+ if (info->flags & XT_DEVGROUP_INVERT_SRC)
+ op = XT_OP_NEQ;
+ xt_buf_add(buf, "iifgroup ");
+ print_devgroup_xlate(info->src_group, op,
+ info->src_mask, buf, numeric);
+ }
+
+ if (info->flags & XT_DEVGROUP_MATCH_DST) {
+ if (info->flags & XT_DEVGROUP_INVERT_DST)
+ op = XT_OP_NEQ;
+ xt_buf_add(buf, "oifgroup ");
+ print_devgroup_xlate(info->dst_group, op,
+ info->dst_mask, buf, numeric);
+ }
+}
+
+static int devgroup_xlate(const struct xt_entry_match *match,
+ struct xt_buf *buf, int numeric)
+{
+ const struct xt_devgroup_info *info = (const void *)match->data;
+
+ devgroup_show_xlate(info, buf, 0);
+
+ return 1;
+}
+
static struct xtables_match devgroup_mt_reg = {
.name = "devgroup",
.version = XTABLES_VERSION,
@@ -164,6 +216,7 @@ static struct xtables_match devgroup_mt_reg = {
.x6_parse = devgroup_parse,
.x6_fcheck = devgroup_check,
.x6_options = devgroup_opts,
+ .xlate = devgroup_xlate,
};
void _init(void)