]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - net/ipv4/netfilter/ipt_owner.c
[NETFILTER]: x_tables: consistent and unique symbol names
[mirror_ubuntu-hirsute-kernel.git] / net / ipv4 / netfilter / ipt_owner.c
1 /* Kernel module to match various things tied to sockets associated with
2 locally generated outgoing packets. */
3
4 /* (C) 2000 Marc Boucher <marc@mbsi.ca>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/file.h>
14 #include <linux/rcupdate.h>
15 #include <net/sock.h>
16
17 #include <linux/netfilter_ipv4/ipt_owner.h>
18 #include <linux/netfilter/x_tables.h>
19
20 MODULE_LICENSE("GPL");
21 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
22 MODULE_DESCRIPTION("iptables owner match");
23
24 static bool
25 owner_mt(const struct sk_buff *skb, const struct net_device *in,
26 const struct net_device *out, const struct xt_match *match,
27 const void *matchinfo, int offset, unsigned int protoff,
28 bool *hotdrop)
29 {
30 const struct ipt_owner_info *info = matchinfo;
31
32 if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
33 return false;
34
35 if(info->match & IPT_OWNER_UID) {
36 if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
37 !!(info->invert & IPT_OWNER_UID))
38 return false;
39 }
40
41 if(info->match & IPT_OWNER_GID) {
42 if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
43 !!(info->invert & IPT_OWNER_GID))
44 return false;
45 }
46
47 return true;
48 }
49
50 static bool
51 owner_mt_check(const char *tablename, const void *ip,
52 const struct xt_match *match, void *matchinfo,
53 unsigned int hook_mask)
54 {
55 const struct ipt_owner_info *info = matchinfo;
56
57 if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
58 printk("ipt_owner: pid, sid and command matching "
59 "not supported anymore\n");
60 return false;
61 }
62 return true;
63 }
64
65 static struct xt_match owner_mt_reg __read_mostly = {
66 .name = "owner",
67 .family = AF_INET,
68 .match = owner_mt,
69 .matchsize = sizeof(struct ipt_owner_info),
70 .hooks = (1 << NF_INET_LOCAL_OUT) |
71 (1 << NF_INET_POST_ROUTING),
72 .checkentry = owner_mt_check,
73 .me = THIS_MODULE,
74 };
75
76 static int __init owner_mt_init(void)
77 {
78 return xt_register_match(&owner_mt_reg);
79 }
80
81 static void __exit owner_mt_exit(void)
82 {
83 xt_unregister_match(&owner_mt_reg);
84 }
85
86 module_init(owner_mt_init);
87 module_exit(owner_mt_exit);