Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net...
[deliverable/linux.git] / net / netfilter / xt_cgroup.c
CommitLineData
82a37132
DB
1/*
2 * Xtables module to match the process control group.
3 *
4 * Might be used to implement individual "per-application" firewall
5 * policies in contrast to global policies based on control groups.
6 * Matching is based upon processes tagged to net_cls' classid marker.
7 *
8 * (C) 2013 Daniel Borkmann <dborkman@redhat.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/skbuff.h>
16#include <linux/module.h>
17#include <linux/netfilter/x_tables.h>
18#include <linux/netfilter/xt_cgroup.h>
19#include <net/sock.h>
20
21MODULE_LICENSE("GPL");
22MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>");
23MODULE_DESCRIPTION("Xtables: process control group matching");
24MODULE_ALIAS("ipt_cgroup");
25MODULE_ALIAS("ip6t_cgroup");
26
27static int cgroup_mt_check(const struct xt_mtchk_param *par)
28{
29 struct xt_cgroup_info *info = par->matchinfo;
30
31 if (info->invert & ~1)
32 return -EINVAL;
33
caa8ad94 34 return 0;
82a37132
DB
35}
36
37static bool
38cgroup_mt(const struct sk_buff *skb, struct xt_action_param *par)
39{
40 const struct xt_cgroup_info *info = par->matchinfo;
41
afb77180 42 if (skb->sk == NULL || !sk_fullsock(skb->sk))
82a37132
DB
43 return false;
44
2a56a1fe
TH
45 return (info->id == sock_cgroup_classid(&skb->sk->sk_cgrp_data)) ^
46 info->invert;
82a37132
DB
47}
48
49static struct xt_match cgroup_mt_reg __read_mostly = {
50 .name = "cgroup",
51 .revision = 0,
52 .family = NFPROTO_UNSPEC,
53 .checkentry = cgroup_mt_check,
54 .match = cgroup_mt,
55 .matchsize = sizeof(struct xt_cgroup_info),
56 .me = THIS_MODULE,
57 .hooks = (1 << NF_INET_LOCAL_OUT) |
a00e7634
AP
58 (1 << NF_INET_POST_ROUTING) |
59 (1 << NF_INET_LOCAL_IN),
82a37132
DB
60};
61
62static int __init cgroup_mt_init(void)
63{
64 return xt_register_match(&cgroup_mt_reg);
65}
66
67static void __exit cgroup_mt_exit(void)
68{
69 xt_unregister_match(&cgroup_mt_reg);
70}
71
72module_init(cgroup_mt_init);
73module_exit(cgroup_mt_exit);
This page took 0.109464 seconds and 5 git commands to generate.