1 /* Kernel module to match various things tied to sockets associated with
2 locally generated outgoing packets.
4 Copyright (C) 2000,2001 Marc Boucher
6 #include <linux/module.h>
7 #include <linux/skbuff.h>
8 #include <linux/file.h>
11 #include <linux/netfilter_ipv6/ip6t_owner.h>
12 #include <linux/netfilter_ipv6/ip6_tables.h>
14 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
15 MODULE_DESCRIPTION("IP6 tables owner matching module");
16 MODULE_LICENSE("GPL");
19 match_pid(const struct sk_buff *skb, pid_t pid)
21 struct task_struct *p;
22 struct files_struct *files;
25 read_lock(&tasklist_lock);
26 p = find_task_by_pid(pid);
32 read_lock(&files->file_lock);
33 for (i=0; i < files->max_fds; i++) {
34 if (fcheck_files(files, i) == skb->sk->socket->file) {
35 read_unlock(&files->file_lock);
37 read_unlock(&tasklist_lock);
41 read_unlock(&files->file_lock);
45 read_unlock(&tasklist_lock);
50 match_sid(const struct sk_buff *skb, pid_t sid)
52 struct task_struct *p;
53 struct file *file = skb->sk->socket->file;
56 read_lock(&tasklist_lock);
58 struct files_struct *files;
59 if (p->session != sid)
65 read_lock(&files->file_lock);
66 for (i=0; i < files->max_fds; i++) {
67 if (fcheck_files(files, i) == file) {
72 read_unlock(&files->file_lock);
78 read_unlock(&tasklist_lock);
84 match(const struct sk_buff *skb,
85 const struct net_device *in,
86 const struct net_device *out,
87 const void *matchinfo,
93 const struct ip6t_owner_info *info = matchinfo;
95 if (!skb->sk || !skb->sk->socket || !skb->sk->socket->file)
98 if(info->match & IP6T_OWNER_UID) {
99 if((skb->sk->socket->file->f_uid != info->uid) ^
100 !!(info->invert & IP6T_OWNER_UID))
104 if(info->match & IP6T_OWNER_GID) {
105 if((skb->sk->socket->file->f_gid != info->gid) ^
106 !!(info->invert & IP6T_OWNER_GID))
110 if(info->match & IP6T_OWNER_PID) {
111 if (!match_pid(skb, info->pid) ^
112 !!(info->invert & IP6T_OWNER_PID))
116 if(info->match & IP6T_OWNER_SID) {
117 if (!match_sid(skb, info->sid) ^
118 !!(info->invert & IP6T_OWNER_SID))
126 checkentry(const char *tablename,
127 const struct ip6t_ip6 *ip,
129 unsigned int matchsize,
130 unsigned int hook_mask)
133 & ~((1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING))) {
134 printk("ip6t_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
138 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_owner_info)))
141 /* files->file_lock can not be used in a BH */
142 if (((struct ip6t_owner_info *)matchinfo)->match
143 & (IP6T_OWNER_PID|IP6T_OWNER_SID)) {
144 printk("ip6t_owner: pid and sid matching is broken on SMP.\n");
151 static struct ip6t_match owner_match
152 = { { NULL, NULL }, "owner", &match, &checkentry, NULL, THIS_MODULE };
154 static int __init init(void)
156 return ip6t_register_match(&owner_match);
159 static void __exit fini(void)
161 ip6t_unregister_match(&owner_match);