xtables socket classid matching
Subsystems (7)
v5 cover xtables socket classid matching
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Changelog:
* v4->v5:
- Fixed typo in patch 1, sorry for that, rest unchanged.
* v3->v4:
- Patch 3 is unchanged from previous version (only minor Kconfig update)
- Added patch 1 upon request, and while at it also patch 2
* v2->v3:
- After discussions w/ Tejun, let's not add any cgroups code here, thus we _only_ add code in netfilter area, nowhere else, that's even more simple and cleaner than proposed.
* v1->v2:
- Updated commit message, rebased
- Applied Gao Feng's feedback
Previous discussions, design considerations etc can be found in:
- v1: http://patchwork.ozlabs.org/patch/280687/
- v1/alt: http://patchwork.ozlabs.org/patch/282477/
- v2: http://patchwork.ozlabs.org/patch/284582/
- v3: http://patchwork.ozlabs.org/patch/304825/
Pablo, please find the unchanged user space part in [1].
Thanks !
[1] http://patchwork.ozlabs.org/patch/304826/
Daniel Borkmann (3):
net: net_cls: move cgroupfs classid handling into core
net: netprio: rename config to be more consistent with cgroup configs
netfilter: xtables: lightweight process control group matching
Documentation/cgroups/net_cls.txt | 5 ++ include/linux/cgroup_subsys.h | 4 +- include/linux/netdevice.h | 2 +- include/net/cls_cgroup.h | 40 ++++------- include/net/netprio_cgroup.h | 18 ++--- include/net/sock.h | 2 +- include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/xt_cgroup.h | 11 +++ net/Kconfig | 11 ++- net/core/Makefile | 3 +- net/core/dev.c | 2 +- net/core/netclassid_cgroup.c | 120 +++++++++++++++++++++++++++++++ net/core/sock.c | 14 +--- net/netfilter/Kconfig | 10 +++ net/netfilter/Makefile | 1 + net/netfilter/xt_cgroup.c | 71 ++++++++++++++++++ net/sched/Kconfig | 1 + net/sched/cls_cgroup.c | 111 +--------------------------- 18 files changed, 256 insertions(+), 171 deletions(-) create mode 100644 include/uapi/linux/netfilter/xt_cgroup.h create mode 100644 net/core/netclassid_cgroup.c create mode 100644 net/netfilter/xt_cgroup.c
Signature · 1 line
1.8.3.1
A message that is not in the archive (sent off-list or not yet received): 1388338032-14713-1-git-send-email-dborkman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
PATCH v5 1/3 net: net_cls: move cgroupfs classid handling into core
Zefan Li requested [1] to perform the following cleanup/refactoring:
- Split cgroupfs classid handling into net core to better express a possible more generic use.
- Disable module support for cgroupfs bits as the majority of other cgroupfs subsystems do not have that, and seems to be not wished from cgroup side. Zefan probably might want to follow-up for netprio later on.
- By this, code can be further reduced which previously took care of functionality built when compiled as module.
cgroupfs bits are being placed under net/core/netclassid_cgroup.c, so that we are consistent with {netclassid,netprio}_cgroup naming that is under net/core/ as suggested by Zefan.
No change in functionality, but only code refactoring that is being done here.
[1] http://patchwork.ozlabs.org/patch/304825/
--- include/linux/cgroup_subsys.h | 2 +- include/net/cls_cgroup.h | 40 +++++--------- net/Kconfig | 7 +++ net/core/Makefile | 1 + net/core/netclassid_cgroup.c | 120 ++++++++++++++++++++++++++++++++++++++++++ net/core/sock.c | 12 ----- net/sched/Kconfig | 1 + net/sched/cls_cgroup.c | 111 +------------------------------------- 8 files changed, 143 insertions(+), 151 deletions(-) create mode 100644 net/core/netclassid_cgroup.c
include/linux/cgroup_subsys.h +1 -1
@@ -31,7 +31,7 @@ SUBSYS(devices) SUBSYS(freezer)#endif -#if IS_SUBSYS_ENABLED (CONFIG_NET_CLS_CGROUP ) +#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) SUBSYS(net_cls)#endif
include/net/cls_cgroup.h +12 -28
@@ -16,17 +16,16 @@#include <linux/cgroup.h> #include <linux/hardirq.h> #include <linux/rcupdate.h> +#include <net/sock.h> -#if IS_ENABLED(CONFIG_NET_CLS_CGROUP) -struct cgroup_cls_state -{ +#ifdef CONFIG_CGROUP_NET_CLASSID +struct cgroup_cls_state {struct cgroup_subsys_state css;u32 classid; }; -void sock_update_classid(struct sock *sk); +struct cgroup_cls_state *task_cls_state (struct task_struct *p); -#if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)static inline u32 task_cls_classid (struct task_struct *p) {u32 classid;
@@ -41,33 +40,18 @@ static inline u32 task_cls_classid(struct task_struct *p)return classid; } -#elif IS_MODULE (CONFIG_NET_CLS_CGROUP ) -static inline u32 task_cls_classid (struct task_struct *p) -{ -struct cgroup_subsys_state *css; -u32 classid =0 ; - -if (in_interrupt ()) -return 0 ; - -rcu_read_lock (); - css =task_css (p, net_cls_subsys_id); -if (css) - classid =container_of (css, - struct cgroup_cls_state, css)->classid; -rcu_read_unlock (); -return classid; -} -#endif -#else /* !CGROUP_NET_CLS_CGROUP */ static inline void sock_update_classid (struct sock *sk) { -} +u32 classid; -static inline u32 task_cls_classid (struct task_struct *p) + classid =task_cls_classid (current); +if (classid != sk->sk_classid) + sk->sk_classid = classid; +} +#else /* !CONFIG_CGROUP_NET_CLASSID */ +static inline void sock_update_classid (struct sock *sk) { -return 0 ; } -#endif /* CGROUP_NET_CLS_CGROUP */ +#endif /* CONFIG_CGROUP_NET_CLASSID */ #endif /* _NET_CLS_CGROUP_H */
net/Kconfig +7 -0
@@ -245,6 +245,13 @@ config NETPRIO_CGROUP Cgroup subsystem for use in assigning processes to network priorities on a per-interface basis +config CGROUP_NET_CLASSID + boolean "Network classid cgroup" + depends on CGROUPS + ---help--- + Cgroup subsystem for use as general purpose socket classid marker that is + being used in cls_cgroup and for netfilter matching. + config NET_RX_BUSY_POLL boolean default y
net/core/Makefile +1 -0
@@ -22,3 +22,4 @@ obj-$(CONFIG_TRACEPOINTS) += net-traces.o obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o obj-$(CONFIG_NETPRIO_CGROUP) += netprio_cgroup.o +obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
net/core/netclassid_cgroup.c new file +120 -0
120 lines not on this page · raw message
net/core/sock.c +0 -12
@@ -1308,18 +1308,6 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)module_put (owner); } -#if IS_ENABLED (CONFIG_NET_CLS_CGROUP ) -void sock_update_classid (struct sock *sk) -{ -u32 classid; - - classid =task_cls_classid (current); -if (classid != sk->sk_classid) - sk->sk_classid = classid; -} -EXPORT_SYMBOL (sock_update_classid); -#endif -#if IS_ENABLED (CONFIG_NETPRIO_CGROUP )void sock_update_netprioidx (struct sock *sk) {
net/sched/Kconfig +1 -0
@@ -435,6 +435,7 @@ config NET_CLS_FLOW config NET_CLS_CGROUP tristate "Control Group Classifier" select NET_CLS + select CGROUP_NET_CLASSID depends on CGROUPS ---help--- Say Y here if you want to classify packets based on the control
net/sched/cls_cgroup.c +1 -110
135 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 5 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Looks good to me.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Li Zefan
Quoted 5 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Looks good to me.
Series applied, thanks.
Quoted 11 lines · Pablo Neira Ayuso
Quoted 8 lines · Li Zefan
Quoted 5 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Looks good to me.
Series applied, thanks.
Thanks a lot Pablo, as mentioned in [1], the _unchanged_ user space part is available in [2].
Let me know if you want me to resend it, or if you would like to take it from there.
Thanks,
Daniel
[1] http://www.spinics.net/lists/netfilter-devel/msg29467.html
[2] http://patchwork.ozlabs.org/patch/304826/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Daniel Borkmann
Quoted 10 lines · Pablo Neira Ayuso
Quoted 8 lines · Li Zefan
Quoted 5 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Looks good to me.
Quoted 7 lines
Quoted 1 line
Series applied, thanks.
Thanks a lot Pablo, as mentioned in [1], the _unchanged_ user space part is available in [2].
Let me know if you want me to resend it, or if you would like to take it from there.
No need to. I have applied that patch to iptables-next, thanks.
Quoted 14 lines · Pablo Neira Ayuso
Quoted 13 lines · Daniel Borkmann
Quoted 11 lines · Pablo Neira Ayuso
Quoted 8 lines · Li Zefan
Quoted 5 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Looks good to me.
Series applied, thanks.
Quoted 7 lines
Quoted 5 lines
Thanks a lot Pablo, as mentioned in [1], the _unchanged_ user space part is available in [2].
Let me know if you want me to resend it, or if you would like to take it from there.
No need to. I have applied that patch to iptables-next, thanks.
Awesome, thanks Pablo!
Hi,
@David: This patchset that Daniel sent me contains changes for /net/core/ stuff, let me know how you want me to handle this or if you please to apply this directly yourself.
Thanks!
Quoted 64 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Changelog:
*
v4->v5:
- Fixed typo in patch 1, sorry for that, rest unchanged.
*v3->v4:
- Patch 3 is unchanged from previous version (only minorKconfigupdate)
- Added patch 1 upon request, and while at it also patch 2
*v2->v3:
- After discussions w/ Tejun, let's not add any cgroups code here, thus we _only_ add code in netfilter area, nowhere else, that's even more simple and cleaner than proposed.
*v1->v2:
- Updated commit message, rebased
- Applied Gao Feng's feedbackPrevious discussions, design considerations etc can be found in:
- v1: http://patchwork.ozlabs.org/patch/280687/
- v1/alt: http://patchwork.ozlabs.org/patch/282477/
- v2: http://patchwork.ozlabs.org/patch/284582/
- v3: http://patchwork.ozlabs.org/patch/304825/Pablo, please find the unchanged user space part in [1].
Thanks !
[1] http://patchwork.ozlabs.org/patch/304826/
Daniel Borkmann (3):
net:net_cls: move cgroupfs classid handling into core
net: netprio: rename config to be more consistent with cgroup configs
netfilter: xtables: lightweight process control group matchingDocumentation/cgroups/net_cls.txt | 5 ++ include/linux/cgroup_subsys.h | 4 +- include/linux/netdevice.h | 2 +- include/net/cls_cgroup.h | 40 ++++------- include/net/netprio_cgroup.h | 18 ++--- include/net/sock.h | 2 +- include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/xt_cgroup.h | 11 +++ net/Kconfig | 11 ++- net/core/Makefile | 3 +- net/core/dev.c | 2 +- net/core/netclassid_cgroup.c | 120 +++++++++++++++++++++++++++++++ net/core/sock.c | 14 +--- net/netfilter/Kconfig | 10 +++ net/netfilter/Makefile | 1 + net/netfilter/xt_cgroup.c | 71 ++++++++++++++++++ net/sched/Kconfig | 1 + net/sched/cls_cgroup.c | 111 +--------------------------- 18 files changed, 256 insertions(+), 171 deletions(-) create mode 100644 include/uapi/linux/netfilter/xt_cgroup.h create mode 100644 net/core/netclassid_cgroup.c create mode 100644 net/netfilter/xt_cgroup.cSignature · 1 line
1.8.3.1
Quoted 5 lines · Pablo Neira Ayuso
Hi,
@David: This patchset that Daniel sent me contains changes for /net/core/ stuff, let me know how you want me to handle this or if you please to apply this directly yourself.
If so, I'll send a rebase for net-next, thanks.
Quoted 67 lines
Thanks!
Quoted 64 lines · Daniel Borkmann
The main patch is patch 3, please refer to the detailled description there. Patch 1 has been requested by cgroups people to have as a cleanup. While at it, I've also added a minor, trivial cleanup in patch 2 for consistency reasons.
Changelog:
*
v4->v5:
- Fixed typo in patch 1, sorry for that, rest unchanged.
*v3->v4:
- Patch 3 is unchanged from previous version (only minorKconfigupdate)
- Added patch 1 upon request, and while at it also patch 2
*v2->v3:
- After discussions w/ Tejun, let's not add any cgroups code here, thus we _only_ add code in netfilter area, nowhere else, that's even more simple and cleaner than proposed.
*v1->v2:
- Updated commit message, rebased
- Applied Gao Feng's feedbackPrevious discussions, design considerations etc can be found in:
- v1: http://patchwork.ozlabs.org/patch/280687/
- v1/alt: http://patchwork.ozlabs.org/patch/282477/
- v2: http://patchwork.ozlabs.org/patch/284582/
- v3: http://patchwork.ozlabs.org/patch/304825/Pablo, please find the unchanged user space part in [1].
Thanks !
[1] http://patchwork.ozlabs.org/patch/304826/
Daniel Borkmann (3):
net:net_cls: move cgroupfs classid handling into core
net: netprio: rename config to be more consistent with cgroup configs
netfilter: xtables: lightweight process control group matchingDocumentation/cgroups/net_cls.txt | 5 ++ include/linux/cgroup_subsys.h | 4 +- include/linux/netdevice.h | 2 +- include/net/cls_cgroup.h | 40 ++++------- include/net/netprio_cgroup.h | 18 ++--- include/net/sock.h | 2 +- include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/xt_cgroup.h | 11 +++ net/Kconfig | 11 ++- net/core/Makefile | 3 +- net/core/dev.c | 2 +- net/core/netclassid_cgroup.c | 120 +++++++++++++++++++++++++++++++ net/core/sock.c | 14 +--- net/netfilter/Kconfig | 10 +++ net/netfilter/Makefile | 1 + net/netfilter/xt_cgroup.c | 71 ++++++++++++++++++ net/sched/Kconfig | 1 + net/sched/cls_cgroup.c | 111 +--------------------------- 18 files changed, 256 insertions(+), 171 deletions(-)create mode 100644
include/uapi/linux/netfilter/xt_cgroup.hcreate mode 100644net/core/netclassid_cgroup.ccreate mode 100644net/netfilter/xt_cgroup.c--
1.8.3.1
From: Pablo Neira Ayuso <pablo-Cap9r6Oaw4JrovVCs/[email protected]>
Date: Tue, 31 Dec 2013 15:04:59 +0100
Quoted 5 lines
Hi,
@David: This patchset that Daniel sent me contains changes for /net/core/ stuff, let me know how you want me to handle this or if you please to apply this directly yourself.
You can take it in via your tree, thanks.
PATCH v5 2/3 net: netprio: rename config to be more consistent with cgroup configs
In reply to Daniel BorkmannWhile we're at it and introduced CGROUP_NET_CLASSID, lets also make NETPRIO_CGROUP more consistent with the rest of cgroups and rename it into CONFIG_CGROUP_NET_PRIO so that for networking, we now have CONFIG_CGROUP_NET_{PRIO,CLASSID}. This not only makes the CONFIG option consistent among networking cgroups, but also among cgroups CONFIG conventions in general as the vast majority has a prefix of CONFIG_CGROUP_<SUBSYS>.
--- include/linux/cgroup_subsys.h | 2 +- include/linux/netdevice.h | 2 +- include/net/netprio_cgroup.h | 18 ++++++------------ include/net/sock.h | 2 +- net/Kconfig | 4 ++-- net/core/Makefile | 2 +- net/core/dev.c | 2 +- net/core/sock.c | 2 +- 8 files changed, 14 insertions(+), 20 deletions(-)
include/linux/cgroup_subsys.h +1 -1
@@ -43,7 +43,7 @@ SUBSYS(blkio) SUBSYS(perf)#endif -#if IS_SUBSYS_ENABLED (CONFIG_NETPRIO_CGROUP ) +#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_PRIO ) SUBSYS(net_prio)#endif
include/linux/netdevice.h +1 -1
@@ -1444,7 +1444,7 @@ struct net_device {/* max exchange id for FCoE LRO by ddp */ unsigned int fcoe_ddp_xid;#endif -#if IS_ENABLED (CONFIG_NETPRIO_CGROUP ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )struct netprio_map __rcu *priomap;#endif /* phy device may attach itself for hardware timestamping */
include/net/netprio_cgroup.h +6 -12
@@ -13,12 +13,12 @@ #ifndef _NETPRIO_CGROUP_H #define _NETPRIO_CGROUP_H + #include <linux/cgroup.h> #include <linux/hardirq.h> #include <linux/rcupdate.h> - -#if IS_ENABLED(CONFIG_NETPRIO_CGROUP) +#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO) struct netprio_map { struct rcu_head rcu; u32 priomap_len;
@@ -27,8 +27,7 @@ struct netprio_map {void sock_update_netprioidx (struct sock *sk); -#if IS_BUILTIN (CONFIG_NETPRIO_CGROUP ) - +#if IS_BUILTIN (CONFIG_CGROUP_NET_PRIO )static inline u32 task_netprioidx (struct task_struct *p) {struct cgroup_subsys_state *css;
@@ -40,9 +39,7 @@ static inline u32 task_netprioidx(struct task_struct *p)rcu_read_unlock (); return idx; } - -#elif IS_MODULE(CONFIG_NETPRIO_CGROUP) - +#elif IS_MODULE(CONFIG_CGROUP_NET_PRIO)static inline u32 task_netprioidx (struct task_struct *p) {struct cgroup_subsys_state *css;
@@ -56,9 +53,7 @@ static inline u32 task_netprioidx(struct task_struct *p) return idx; }#endif - -#else /* !CONFIG_NETPRIO_CGROUP */ - +#else /* !CONFIG_CGROUP_NET_PRIO */ static inline u32 task_netprioidx (struct task_struct *p) {return 0 ;
@@ -66,6 +61,5 @@ static inline u32 task_netprioidx(struct task_struct *p)#define sock_update_netprioidx (sk) -#endif /* CONFIG_NETPRIO_CGROUP */ - +#endif /* CONFIG_CGROUP_NET_PRIO */ #endif /* _NET_CLS_CGROUP_H */
include/net/sock.h +1 -1
@@ -395,7 +395,7 @@ struct sock {unsigned short sk_ack_backlog;unsigned short sk_max_ack_backlog;__u32 sk_priority; -#if IS_ENABLED (CONFIG_NETPRIO_CGROUP ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )__u32 sk_cgrp_prioidx;#endif struct pid *sk_peer_pid;
net/Kconfig +2 -2
@@ -238,12 +238,12 @@ config XPS depends on SMP default y -config NETPRIO_CGROUP +config CGROUP_NET_PRIO tristate "Network priority cgroup" depends on CGROUPS ---help--- Cgroup subsystem for use in assigning processes to network priorities on - a per-interface basis + a per-interface basis. config CGROUP_NET_CLASSID boolean "Network classid cgroup"
net/core/Makefile +1 -1
@@ -21,5 +21,5 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o obj-$(CONFIG_TRACEPOINTS) += net-traces.o obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o -obj-$(CONFIG_NETPRIO_CGROUP) += netprio_cgroup.o +obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o obj-$(CONFIG_CGROUP_NET_CLASSID) += classid_cgroup.o
net/core/dev.c +1 -1
@@ -2747,7 +2747,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,return rc; } -#if IS_ENABLED (CONFIG_NETPRIO_CGROUP ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )static void skb_update_prio (struct sk_buff *skb) {struct netprio_map *map =rcu_dereference_bh (skb->dev->priomap);
net/core/sock.c +1 -1
@@ -1308,7 +1308,7 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)module_put (owner); } -#if IS_ENABLED (CONFIG_NETPRIO_CGROUP ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )void sock_update_netprioidx (struct sock *sk) {if (in_interrupt ())
Signature · 1 line
1.8.3.1
PATCH v5 3/3 netfilter: xtables: lightweight process control group matching
In reply to Daniel BorkmannIt would be useful e.g. in a server or desktop environment to have a facility in the notion of fine-grained "per application" or "per application group" firewall policies. Probably, users in the mobile, embedded area (e.g. Android based) with different security policy requirements for application groups could have great benefit from that as well. For example, with a little bit of configuration effort, an admin could whitelist well-known applications, and thus block otherwise unwanted "hard-to-track" applications like [1] from a user's machine. Blocking is just one example, but it is not limited to that, meaning we can have much different scenarios/policies that netfilter allows us than just blocking, e.g. fine grained settings where applications are allowed to connect/send traffic to, application traffic marking/conntracking, application-specific packet mangling, and so on.
Implementation of PID-based matching would not be appropriate as they frequently change, and child tracking would make that even more complex and ugly. Cgroups would be a perfect candidate for accomplishing that as they associate a set of tasks with a set of parameters for one or more subsystems, in our case the netfilter subsystem, which, of course, can be combined with other cgroup subsystems into something more complex if needed.
As mentioned, to overcome this constraint, such processes could be placed into one or multiple cgroups where different fine-grained rules can be defined depending on the application scenario, while e.g. everything else that is not part of that could be dropped (or vice versa), thus making life harder for unwanted processes to communicate to the outside world. So, we make use of cgroups here to track jobs and limit their resources in terms of iptables policies; in other words, limiting, tracking, etc what they are allowed to communicate.
In our case we're working on outgoing traffic based on which local socket that originated from. Also, one doesn't even need to have an a-prio knowledge of the application internals regarding their particular use of ports or protocols. Matching is *extremly* lightweight as we just test for the sk_classid marker of sockets, originating from net_cls. net_cls and netfilter do not contradict each other; in fact, each construct can live as standalone or they can be used in combination with each other, which is perfectly fine, plus it serves Tejun's requirement to not introduce a new cgroups subsystem. Through this, we result in a very minimal and efficient module, and don't add anything except netfilter code.
One possible, minimal usage example (many other iptables options can be applied obviously):
1) Configuring cgroups if not already done, e.g.:
mkdir /sys/fs/cgroup/net_cls
mount -t cgroup -o net_cls net_cls /sys/fs/cgroup/net_cls mkdir /sys/fs/cgroup/net_cls/0
echo 1 > /sys/fs/cgroup/net_cls/0/net_cls.classid (resp. a real flow handle id for tc)
2) Configuring netfilter (iptables-nftables), e.g.:
iptables -A OUTPUT -m cgroup ! --cgroup 1 -j DROP
3) Running applications, e.g.:
ping 208.67.222.222 <pid:1799>
echo 1799 > /sys/fs/cgroup/net_cls/0/tasks
64 bytes from 208.67.222.222: icmp_seq=44 ttl=49 time=11.9 ms [...]
ping 208.67.220.220 <pid:1804>
ping: sendmsg: Operation not permitted
[...]
echo 1804 > /sys/fs/cgroup/net_cls/0/tasks
64 bytes from 208.67.220.220: icmp_seq=89 ttl=56 time=19.0 ms [...]
Of course, real-world deployments would make use of cgroups user space toolsuite, or own custom policy daemons dynamically moving applications from/to various cgroups.
[1] http://www.blackhat.com/presentations/bh-europe-06/bh-eu-06-biondi/bh-eu-06-biondi-up.pdf
--- Documentation/cgroups/net_cls.txt | 5 +++ include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/xt_cgroup.h | 11 +++++ net/netfilter/Kconfig | 10 +++++ net/netfilter/Makefile | 1 + net/netfilter/xt_cgroup.c | 71 ++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 include/uapi/linux/netfilter/xt_cgroup.h create mode 100644 net/netfilter/xt_cgroup.c
Documentation/cgroups/net_cls.txt +5 -0
@@ -6,6 +6,8 @@ tag network packets with a class identifier (classid). The Traffic Controller (tc) can be used to assign different priorities to packets from different cgroups. +Also, Netfilter (iptables) can use this tag to perform +actions on such packets. Creating a net_cls cgroups instance creates a net_cls.classid file. This net_cls.classid value is initialized to 0.
@@ -32,3 +34,6 @@ tc class add dev eth0 parent 10: classid 10:1 htb rate 40mbit - creating traffic class 10:1 tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup + +configuring iptables, basic example: +iptables -A OUTPUT -m cgroup ! --cgroup 0x100001 -j DROP
include/uapi/linux/netfilter/Kbuild +1 -0
@@ -39,6 +39,7 @@ header-y += xt_TEE.h header-y += xt_TPROXY.h header-y += xt_addrtype.h header-y += xt_bpf.h +header-y += xt_cgroup.h header-y += xt_cluster.h header-y += xt_comment.h header-y += xt_connbytes.h
include/uapi/linux/netfilter/xt_cgroup.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _UAPI_XT_CGROUP_H +#define _UAPI_XT_CGROUP_H + +#include <linux/types.h> + +struct xt_cgroup_info { +__u32 id; +__u32 invert; +}; + +#endif /* _UAPI_XT_CGROUP_H */
net/netfilter/Kconfig +10 -0
@@ -858,6 +858,16 @@ config NETFILTER_XT_MATCH_BPF To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_MATCH_CGROUP + tristate '"control group" match support' + depends on NETFILTER_ADVANCED + depends on CGROUPS + select CGROUP_NET_CLASSID + ---help--- + Socket/process control group matching allows you to match locally + generated packets based on which net_cls control group processes + belong to. + config NETFILTER_XT_MATCH_CLUSTER tristate '"cluster" match support' depends on NF_CONNTRACK
net/netfilter/Makefile +1 -0
@@ -143,6 +143,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_MULTIPORT) += xt_multiport.o obj-$(CONFIG_NETFILTER_XT_MATCH_NFACCT) += xt_nfacct.o obj-$(CONFIG_NETFILTER_XT_MATCH_OSF) += xt_osf.o obj-$(CONFIG_NETFILTER_XT_MATCH_OWNER) += xt_owner.o +obj-$(CONFIG_NETFILTER_XT_MATCH_CGROUP) += xt_cgroup.o obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o obj-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += xt_pkttype.o obj-$(CONFIG_NETFILTER_XT_MATCH_POLICY) += xt_policy.o
net/netfilter/xt_cgroup.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
1.8.3.1