diff mbox

extensions: libxt_cgroup: Add translation to nft

Message ID 20160108195313.GA2507@gmail.com
State Changes Requested
Delegated to: Pablo Neira
Headers show

Commit Message

Shivani Bhardwaj Jan. 8, 2016, 7:53 p.m. UTC
Add translation for the network classifier cgroup to nftables.

Examples:

$ sudo iptables-translate -A input -m cgroup --cgroup 0x100001 -j DROP
nft add rule ip filter input meta cgroup 1048577 counter drop

$ sudo iptables-translate -A input -m cgroup ! --cgroup 0x100001 -j DROP
nft add rule ip filter input meta cgroup != 1048577 counter drop

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
 extensions/libxt_cgroup.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Pablo Neira Ayuso Jan. 11, 2016, 7 p.m. UTC | #1
On Sat, Jan 09, 2016 at 01:23:13AM +0530, Shivani Bhardwaj wrote:
> Add translation for the network classifier cgroup to nftables.
> 
> Examples:
> 
> $ sudo iptables-translate -A input -m cgroup --cgroup 0x100001 -j DROP
> nft add rule ip filter input meta cgroup 1048577 counter drop
> 
> $ sudo iptables-translate -A input -m cgroup ! --cgroup 0x100001 -j DROP
> nft add rule ip filter input meta cgroup != 1048577 counter drop

Please, rebase upon the xlate4 branch. Tejun sent us the cgroups2
updates and this patch doesn't apply on top of those.

Thanks Shivani.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/extensions/libxt_cgroup.c b/extensions/libxt_cgroup.c
index e304e33..dea1417 100644
--- a/extensions/libxt_cgroup.c
+++ b/extensions/libxt_cgroup.c
@@ -48,6 +48,17 @@  static void cgroup_save(const void *ip, const struct xt_entry_match *match)
 	printf("%s --cgroup %u", info->invert ? " !" : "", info->id);
 }
 
+static int cgroup_xlate(const struct xt_entry_match *match,
+			struct xt_buf *buf, int numeric)
+{
+	const struct xt_cgroup_info *info = (void *) match->data;
+
+	xt_buf_add(buf, "meta cgroup%s %u ",
+		   info->invert ? " !=" : "", info->id);
+
+	return 1;
+}
+
 static struct xtables_match cgroup_match = {
 	.family		= NFPROTO_UNSPEC,
 	.name		= "cgroup",
@@ -59,6 +70,7 @@  static struct xtables_match cgroup_match = {
 	.save		= cgroup_save,
 	.x6_parse	= cgroup_parse,
 	.x6_options	= cgroup_opts,
+	.xlate		= cgroup_xlate,
 };
 
 void _init(void)