Skip to contentSkip to conversation

netfilter: prepare xt_cgroup for multi revisions

PATCH In review Tejun Heo 2 participants 4 messages Dec 21, 2015 – Dec 22, 2015

Subsystems (2)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/2 netfilter: prepare xt_cgroup for multi revisions

xt_cgroup will grow cgroup2 path based match. Postfix existing symbols with _v0 and prepare for multi revision registration.

Cc Daniel Borkmann <[email protected]>
Cc Daniel Wagner <[email protected]>
CC Neil Horman <[email protected]>
Cc Jan Engelhardt <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>

---
Hello,

This is the userspace part of cgroup2 support in xt_cgroup.

http://lkml.kernel.org/g/[email protected]

Thanks.

 include/uapi/linux/netfilter/xt_cgroup.h |    2 -
 net/netfilter/xt_cgroup.c                |   36 ++++++++++++++++---------------
 2 files changed, 20 insertions(+), 18 deletions(-)
include/uapi/linux/netfilter/xt_cgroup.h +1 -1
@@ -3,7 +3,7 @@
 
 #include <linux/types.h>
 
-struct xt_cgroup_info {
+struct xt_cgroup_info_v0 {
 	__u32 id;
 	__u32 invert;
 };
net/netfilter/xt_cgroup.c +19 -17
@@ -24,9 +24,9 @@ MODULE_DESCRIPTION("Xtables: process con
 MODULE_ALIAS("ipt_cgroup");
 MODULE_ALIAS("ip6t_cgroup");
 
-static int cgroup_mt_check(const struct xt_mtchk_param *par)
+static int cgroup_mt_check_v0(const struct xt_mtchk_param *par)
 {
-	struct xt_cgroup_info *info = par->matchinfo;
+	struct xt_cgroup_info_v0 *info = par->matchinfo;
 
 	if (info->invert & ~1)
 		return -EINVAL;
@@ -35,9 +35,9 @@ static int cgroup_mt_check(const struct
 }
 
 static bool
-cgroup_mt(const struct sk_buff *skb, struct xt_action_param *par)
+cgroup_mt_v0(const struct sk_buff *skb, struct xt_action_param *par)
 {
-	const struct xt_cgroup_info *info = par->matchinfo;
+	const struct xt_cgroup_info_v0 *info = par->matchinfo;
 
 	if (skb->sk == NULL || !sk_fullsock(skb->sk))
 		return false;
@@ -46,27 +46,29 @@ cgroup_mt(const struct sk_buff *skb, str
 		info->invert;
 }
 
-static struct xt_match cgroup_mt_reg __read_mostly = {
-	.name       = "cgroup",
-	.revision   = 0,
-	.family     = NFPROTO_UNSPEC,
-	.checkentry = cgroup_mt_check,
-	.match      = cgroup_mt,
-	.matchsize  = sizeof(struct xt_cgroup_info),
-	.me         = THIS_MODULE,
-	.hooks      = (1 << NF_INET_LOCAL_OUT) |
-		      (1 << NF_INET_POST_ROUTING) |
-		      (1 << NF_INET_LOCAL_IN),
+static struct xt_match cgroup_mt_reg[] __read_mostly = {
+	{
+		.name		= "cgroup",
+		.revision	= 0,
+		.family		= NFPROTO_UNSPEC,
+		.checkentry	= cgroup_mt_check_v0,
+		.match		= cgroup_mt_v0,
+		.matchsize	= sizeof(struct xt_cgroup_info_v0),
+		.me		= THIS_MODULE,
+		.hooks		= (1 << NF_INET_LOCAL_OUT) |
+				  (1 << NF_INET_POST_ROUTING) |
+				  (1 << NF_INET_LOCAL_IN),
+	},
 };
 
 static int __init cgroup_mt_init(void)
 {
-	return xt_register_match(&cgroup_mt_reg);
+	return xt_register_matches(cgroup_mt_reg, ARRAY_SIZE(cgroup_mt_reg));
 }
 
 static void __exit cgroup_mt_exit(void)
 {
-	xt_unregister_match(&cgroup_mt_reg);
+	xt_unregister_matches(cgroup_mt_reg, ARRAY_SIZE(cgroup_mt_reg));
 }
 
 module_init(cgroup_mt_init);
author
#1 lore raw

PATCH 2/2 netfilter: implement xt_cgroup cgroup2 path match

This patch implements xt_cgroup path match which matches cgroup2 membership of the associated socket. The match is recursive and invertible.

For rationales on introducing another cgroup based match, please refer to a preceding commit "sock, cgroup: add sock->sk_cgroup".

v3: Folded into xt_cgroup as a new revision interface as suggested by
Pablo.

v2: Included linux/limits.h from xt_cgroup2.h for PATH_MAX. Added
explicit alignment to the priv field. Both suggested by Jan.

Cc Daniel Borkmann <[email protected]>
Cc Daniel Wagner <[email protected]>
CC Neil Horman <[email protected]>
Cc Jan Engelhardt <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
---
 include/uapi/linux/netfilter/xt_cgroup.h |   13 +++++
 net/netfilter/xt_cgroup.c                |   69 +++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
include/uapi/linux/netfilter/xt_cgroup.h +13 -0
@@ -2,10 +2,23 @@
 #define _UAPI_XT_CGROUP_H
 
 #include <linux/types.h>
+#include <linux/limits.h>
 
 struct xt_cgroup_info_v0 {
 	__u32 id;
 	__u32 invert;
 };
 
+struct xt_cgroup_info_v1 {
+	__u8		has_path;
+	__u8		has_classid;
+	__u8		invert_path;
+	__u8		invert_classid;
+	char		path[PATH_MAX];
+	__u32		classid;
+
+	/* kernel internal data */
+	void		*priv __attribute__((aligned(8)));
+};
+
 #endif /* _UAPI_XT_CGROUP_H */
net/netfilter/xt_cgroup.c +69 -0

87 lines not on this page · raw message

#2 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

xt_cgroup will grow cgroup2 path based match. Postfix existing symbols with _v0 and prepare for multi revision registration.

Cc Daniel Borkmann <[email protected]>
Cc Daniel Wagner <[email protected]>
CC Neil Horman <[email protected]>
Cc Jan Engelhardt <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
Quoted 6 lines

---
Hello,

This is the userspace part of cgroup2 support in xt_cgroup.

http://lkml.kernel.org/g/[email protected]

Tejun, this patchset doesn't contain the userspace bits, this looks like you're resending kernel patches.

author
#3 lore raw

Hello,

Quoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Tejun Heo

xt_cgroup will grow cgroup2 path based match. Postfix existing symbols with _v0 and prepare for multi revision registration.

Cc Daniel Borkmann <[email protected]>
Cc Daniel Wagner <[email protected]>
CC Neil Horman <[email protected]>
Cc Jan Engelhardt <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>

---
Hello,

Quoted 6 lines
Quoted 3 lines

This is the userspace part of cgroup2 support in xt_cgroup.

http://lkml.kernel.org/g/[email protected]

Tejun, this patchset doesn't contain the userspace bits, this looks like you're resending kernel patches.

Heh, yeah, that's me being confused. My apologies. Lemme try again.

Thanks.

Signature · 1 line
tejun