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 |
d3c5ee6d JE |
27 | owner_mt6(const struct sk_buff *skb, const struct net_device *in, |
28 | const struct net_device *out, const struct xt_match *match, | |
29 | const void *matchinfo, int offset, unsigned int protoff, | |
30 | bool *hotdrop) | |
1da177e4 LT |
31 | { |
32 | const struct ip6t_owner_info *info = matchinfo; | |
33 | ||
34 | if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file) | |
1d93a9cb | 35 | return false; |
1da177e4 | 36 | |
7c4e36bc | 37 | if (info->match & IP6T_OWNER_UID) |
f0daaa65 | 38 | if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ |
1da177e4 | 39 | !!(info->invert & IP6T_OWNER_UID)) |
1d93a9cb | 40 | return false; |
1da177e4 | 41 | |
7c4e36bc | 42 | if (info->match & IP6T_OWNER_GID) |
f0daaa65 | 43 | if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ |
1da177e4 | 44 | !!(info->invert & IP6T_OWNER_GID)) |
1d93a9cb | 45 | return false; |
1da177e4 | 46 | |
1d93a9cb | 47 | return true; |
1da177e4 LT |
48 | } |
49 | ||
ccb79bdc | 50 | static bool |
d3c5ee6d JE |
51 | owner_mt6_check(const char *tablename, const void *ip, |
52 | const struct xt_match *match, void *matchinfo, | |
53 | unsigned int hook_mask) | |
1da177e4 | 54 | { |
34b4a4a6 CH |
55 | const struct ip6t_owner_info *info = matchinfo; |
56 | ||
f0daaa65 | 57 | if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) { |
34b4a4a6 CH |
58 | printk("ipt_owner: pid and sid matching " |
59 | "not supported anymore\n"); | |
ccb79bdc | 60 | return false; |
1da177e4 | 61 | } |
ccb79bdc | 62 | return true; |
1da177e4 LT |
63 | } |
64 | ||
d3c5ee6d | 65 | static struct xt_match owner_mt6_reg __read_mostly = { |
1da177e4 | 66 | .name = "owner", |
6709dbbb | 67 | .family = AF_INET6, |
d3c5ee6d | 68 | .match = owner_mt6, |
7f939713 | 69 | .matchsize = sizeof(struct ip6t_owner_info), |
6e23ae2a PM |
70 | .hooks = (1 << NF_INET_LOCAL_OUT) | |
71 | (1 << NF_INET_POST_ROUTING), | |
d3c5ee6d | 72 | .checkentry = owner_mt6_check, |
1da177e4 LT |
73 | .me = THIS_MODULE, |
74 | }; | |
75 | ||
d3c5ee6d | 76 | static int __init owner_mt6_init(void) |
1da177e4 | 77 | { |
d3c5ee6d | 78 | return xt_register_match(&owner_mt6_reg); |
1da177e4 LT |
79 | } |
80 | ||
d3c5ee6d | 81 | static void __exit owner_mt6_exit(void) |
1da177e4 | 82 | { |
d3c5ee6d | 83 | xt_unregister_match(&owner_mt6_reg); |
1da177e4 LT |
84 | } |
85 | ||
d3c5ee6d JE |
86 | module_init(owner_mt6_init); |
87 | module_exit(owner_mt6_exit); |