[POWERPC] pseries: Use rtas_token instead of hand-rolled code
[linux-2.6/linux-loongson.git] / net / ipv6 / netfilter / ip6t_owner.c
blob6036613aef368789a6e4fe69de0c0be3e0b43000
1 /* Kernel module to match various things tied to sockets associated with
2 locally generated outgoing packets. */
4 /* (C) 2000-2001 Marc Boucher <marc@mbsi.ca>
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 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/file.h>
14 #include <linux/rcupdate.h>
15 #include <net/sock.h>
17 #include <linux/netfilter_ipv6/ip6t_owner.h>
18 #include <linux/netfilter_ipv6/ip6_tables.h>
19 #include <linux/netfilter/x_tables.h>
21 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
22 MODULE_DESCRIPTION("IP6 tables owner matching module");
23 MODULE_LICENSE("GPL");
26 static bool
27 match(const struct sk_buff *skb,
28 const struct net_device *in,
29 const struct net_device *out,
30 const struct xt_match *match,
31 const void *matchinfo,
32 int offset,
33 unsigned int protoff,
34 bool *hotdrop)
36 const struct ip6t_owner_info *info = matchinfo;
38 if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
39 return false;
41 if (info->match & IP6T_OWNER_UID)
42 if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
43 !!(info->invert & IP6T_OWNER_UID))
44 return false;
46 if (info->match & IP6T_OWNER_GID)
47 if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
48 !!(info->invert & IP6T_OWNER_GID))
49 return false;
51 return true;
54 static bool
55 checkentry(const char *tablename,
56 const void *ip,
57 const struct xt_match *match,
58 void *matchinfo,
59 unsigned int hook_mask)
61 const struct ip6t_owner_info *info = matchinfo;
63 if (info->match & (IP6T_OWNER_PID | IP6T_OWNER_SID)) {
64 printk("ipt_owner: pid and sid matching "
65 "not supported anymore\n");
66 return false;
68 return true;
71 static struct xt_match owner_match __read_mostly = {
72 .name = "owner",
73 .family = AF_INET6,
74 .match = match,
75 .matchsize = sizeof(struct ip6t_owner_info),
76 .hooks = (1 << NF_IP6_LOCAL_OUT) | (1 << NF_IP6_POST_ROUTING),
77 .checkentry = checkentry,
78 .me = THIS_MODULE,
81 static int __init ip6t_owner_init(void)
83 return xt_register_match(&owner_match);
86 static void __exit ip6t_owner_fini(void)
88 xt_unregister_match(&owner_match);
91 module_init(ip6t_owner_init);
92 module_exit(ip6t_owner_fini);