]>
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> | |
6709dbbb | 19 | #include <linux/netfilter/x_tables.h> |
1da177e4 LT |
20 | |
21 | MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); | |
22 | MODULE_DESCRIPTION("IP6 tables owner matching module"); | |
23 | MODULE_LICENSE("GPL"); | |
24 | ||
1da177e4 | 25 | |
1d93a9cb | 26 | static bool |
1da177e4 LT |
27 | match(const struct sk_buff *skb, |
28 | const struct net_device *in, | |
29 | const struct net_device *out, | |
c4986734 | 30 | const struct xt_match *match, |
1da177e4 LT |
31 | const void *matchinfo, |
32 | int offset, | |
33 | unsigned int protoff, | |
cff533ac | 34 | bool *hotdrop) |
1da177e4 LT |
35 | { |
36 | const struct ip6t_owner_info *info = matchinfo; | |
37 | ||
38 | if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file) | |
1d93a9cb | 39 | return false; |
1da177e4 | 40 | |
7c4e36bc | 41 | if (info->match & IP6T_OWNER_UID) |
f0daaa65 | 42 | if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ |
1da177e4 | 43 | !!(info->invert & IP6T_OWNER_UID)) |
1d93a9cb | 44 | return false; |
1da177e4 | 45 | |
7c4e36bc | 46 | if (info->match & IP6T_OWNER_GID) |
f0daaa65 | 47 | if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ |
1da177e4 | 48 | !!(info->invert & IP6T_OWNER_GID)) |
1d93a9cb | 49 | return false; |
1da177e4 | 50 | |
1d93a9cb | 51 | return true; |
1da177e4 LT |
52 | } |
53 | ||
ccb79bdc | 54 | static bool |
1da177e4 | 55 | checkentry(const char *tablename, |
f0daaa65 | 56 | const void *ip, |
c4986734 | 57 | const struct xt_match *match, |
f0daaa65 | 58 | void *matchinfo, |
f0daaa65 | 59 | unsigned int hook_mask) |
1da177e4 | 60 | { |
34b4a4a6 CH |
61 | const struct ip6t_owner_info *info = matchinfo; |
62 | ||
f0daaa65 | 63 | if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) { |
34b4a4a6 CH |
64 | printk("ipt_owner: pid and sid matching " |
65 | "not supported anymore\n"); | |
ccb79bdc | 66 | return false; |
1da177e4 | 67 | } |
ccb79bdc | 68 | return true; |
1da177e4 LT |
69 | } |
70 | ||
9f15c530 | 71 | static struct xt_match owner_match __read_mostly = { |
1da177e4 | 72 | .name = "owner", |
6709dbbb | 73 | .family = AF_INET6, |
7f939713 PM |
74 | .match = match, |
75 | .matchsize = sizeof(struct ip6t_owner_info), | |
6e23ae2a PM |
76 | .hooks = (1 << NF_INET_LOCAL_OUT) | |
77 | (1 << NF_INET_POST_ROUTING), | |
7f939713 | 78 | .checkentry = checkentry, |
1da177e4 LT |
79 | .me = THIS_MODULE, |
80 | }; | |
81 | ||
65b4b4e8 | 82 | static int __init ip6t_owner_init(void) |
1da177e4 | 83 | { |
6709dbbb | 84 | return xt_register_match(&owner_match); |
1da177e4 LT |
85 | } |
86 | ||
65b4b4e8 | 87 | static void __exit ip6t_owner_fini(void) |
1da177e4 | 88 | { |
6709dbbb | 89 | xt_unregister_match(&owner_match); |
1da177e4 LT |
90 | } |
91 | ||
65b4b4e8 AM |
92 | module_init(ip6t_owner_init); |
93 | module_exit(ip6t_owner_fini); |