Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Kernel module to match various things tied to sockets associated with |
2 | locally generated outgoing packets. */ | |
3 | ||
4 | /* (C) 2000-2001 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> | |
b835996f | 14 | #include <linux/rcupdate.h> |
1da177e4 LT |
15 | #include <net/sock.h> |
16 | ||
17 | #include <linux/netfilter_ipv6/ip6t_owner.h> | |
18 | #include <linux/netfilter_ipv6/ip6_tables.h> | |
19 | ||
20 | MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); | |
21 | MODULE_DESCRIPTION("IP6 tables owner matching module"); | |
22 | MODULE_LICENSE("GPL"); | |
23 | ||
1da177e4 LT |
24 | |
25 | static int | |
26 | match(const struct sk_buff *skb, | |
27 | const struct net_device *in, | |
28 | const struct net_device *out, | |
c4986734 | 29 | const struct xt_match *match, |
1da177e4 LT |
30 | const void *matchinfo, |
31 | int offset, | |
32 | unsigned int protoff, | |
33 | int *hotdrop) | |
34 | { | |
35 | const struct ip6t_owner_info *info = matchinfo; | |
36 | ||
37 | if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file) | |
38 | return 0; | |
39 | ||
f0daaa65 YK |
40 | if (info->match & IP6T_OWNER_UID) { |
41 | if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ | |
1da177e4 LT |
42 | !!(info->invert & IP6T_OWNER_UID)) |
43 | return 0; | |
44 | } | |
45 | ||
f0daaa65 YK |
46 | if (info->match & IP6T_OWNER_GID) { |
47 | if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ | |
1da177e4 LT |
48 | !!(info->invert & IP6T_OWNER_GID)) |
49 | return 0; | |
50 | } | |
51 | ||
1da177e4 LT |
52 | return 1; |
53 | } | |
54 | ||
55 | static int | |
56 | checkentry(const char *tablename, | |
f0daaa65 | 57 | const void *ip, |
c4986734 | 58 | const struct xt_match *match, |
f0daaa65 YK |
59 | void *matchinfo, |
60 | unsigned int matchsize, | |
61 | unsigned int hook_mask) | |
1da177e4 | 62 | { |
34b4a4a6 CH |
63 | const struct ip6t_owner_info *info = matchinfo; |
64 | ||
f0daaa65 | 65 | if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) { |
34b4a4a6 CH |
66 | printk("ipt_owner: pid and sid matching " |
67 | "not supported anymore\n"); | |
1da177e4 LT |
68 | return 0; |
69 | } | |
1da177e4 LT |
70 | return 1; |
71 | } | |
72 | ||
73 | static struct ip6t_match owner_match = { | |
74 | .name = "owner", | |
7f939713 PM |
75 | .match = match, |
76 | .matchsize = sizeof(struct ip6t_owner_info), | |
77 | .hooks = (1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING), | |
78 | .checkentry = checkentry, | |
1da177e4 LT |
79 | .me = THIS_MODULE, |
80 | }; | |
81 | ||
82 | static int __init init(void) | |
83 | { | |
84 | return ip6t_register_match(&owner_match); | |
85 | } | |
86 | ||
87 | static void __exit fini(void) | |
88 | { | |
89 | ip6t_unregister_match(&owner_match); | |
90 | } | |
91 | ||
92 | module_init(init); | |
93 | module_exit(fini); |