Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Dipankar Sarma | b835996 | 2005-09-09 13:04:14 -0700 | [diff] [blame] | 14 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | static int |
| 26 | match(const struct sk_buff *skb, |
| 27 | const struct net_device *in, |
| 28 | const struct net_device *out, |
| 29 | const void *matchinfo, |
| 30 | int offset, |
| 31 | unsigned int protoff, |
| 32 | int *hotdrop) |
| 33 | { |
| 34 | const struct ip6t_owner_info *info = matchinfo; |
| 35 | |
| 36 | if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file) |
| 37 | return 0; |
| 38 | |
| 39 | if(info->match & IP6T_OWNER_UID) { |
| 40 | if((skb->sk->sk_socket->file->f_uid != info->uid) ^ |
| 41 | !!(info->invert & IP6T_OWNER_UID)) |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | if(info->match & IP6T_OWNER_GID) { |
| 46 | if((skb->sk->sk_socket->file->f_gid != info->gid) ^ |
| 47 | !!(info->invert & IP6T_OWNER_GID)) |
| 48 | return 0; |
| 49 | } |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | static int |
| 55 | checkentry(const char *tablename, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 56 | const void *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | void *matchinfo, |
| 58 | unsigned int matchsize, |
| 59 | unsigned int hook_mask) |
| 60 | { |
Christoph Hellwig | 34b4a4a | 2005-08-14 17:33:59 -0700 | [diff] [blame] | 61 | const struct ip6t_owner_info *info = matchinfo; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (hook_mask |
| 64 | & ~((1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING))) { |
| 65 | printk("ip6t_owner: only valid for LOCAL_OUT or POST_ROUTING.\n"); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_owner_info))) |
| 70 | return 0; |
Christoph Hellwig | 34b4a4a | 2005-08-14 17:33:59 -0700 | [diff] [blame] | 71 | |
| 72 | if (info->match & (IP6T_OWNER_PID|IP6T_OWNER_SID)) { |
| 73 | printk("ipt_owner: pid and sid matching " |
| 74 | "not supported anymore\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |
Christoph Hellwig | 34b4a4a | 2005-08-14 17:33:59 -0700 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | static struct ip6t_match owner_match = { |
| 82 | .name = "owner", |
| 83 | .match = &match, |
| 84 | .checkentry = &checkentry, |
| 85 | .me = THIS_MODULE, |
| 86 | }; |
| 87 | |
| 88 | static int __init init(void) |
| 89 | { |
| 90 | return ip6t_register_match(&owner_match); |
| 91 | } |
| 92 | |
| 93 | static void __exit fini(void) |
| 94 | { |
| 95 | ip6t_unregister_match(&owner_match); |
| 96 | } |
| 97 | |
| 98 | module_init(init); |
| 99 | module_exit(fini); |