Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* IP tables module for matching the routing realm |
2 | * | |
3 | * $Id: ipt_realm.c,v 1.3 2004/03/05 13:25:40 laforge Exp $ | |
4 | * | |
5 | * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/skbuff.h> | |
14 | #include <linux/netdevice.h> | |
15 | #include <net/route.h> | |
16 | ||
2e4e6a17 HW |
17 | #include <linux/netfilter_ipv4.h> |
18 | #include <linux/netfilter/xt_realm.h> | |
19 | #include <linux/netfilter/x_tables.h> | |
1da177e4 LT |
20 | |
21 | MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>"); | |
22 | MODULE_LICENSE("GPL"); | |
2e4e6a17 HW |
23 | MODULE_DESCRIPTION("X_tables realm match"); |
24 | MODULE_ALIAS("ipt_realm"); | |
1da177e4 LT |
25 | |
26 | static int | |
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, | |
2e4e6a17 | 33 | unsigned int protoff, |
1da177e4 LT |
34 | int *hotdrop) |
35 | { | |
2e4e6a17 | 36 | const struct xt_realm_info *info = matchinfo; |
1da177e4 LT |
37 | struct dst_entry *dst = skb->dst; |
38 | ||
39 | return (info->id == (dst->tclassid & info->mask)) ^ info->invert; | |
40 | } | |
41 | ||
2e4e6a17 | 42 | static struct xt_match realm_match = { |
1da177e4 | 43 | .name = "realm", |
5d04bff0 PM |
44 | .match = match, |
45 | .matchsize = sizeof(struct xt_realm_info), | |
46 | .hooks = (1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) | | |
47 | (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN), | |
a45049c5 | 48 | .family = AF_INET, |
1da177e4 LT |
49 | .me = THIS_MODULE |
50 | }; | |
51 | ||
52 | static int __init init(void) | |
53 | { | |
a45049c5 | 54 | return xt_register_match(&realm_match); |
1da177e4 LT |
55 | } |
56 | ||
57 | static void __exit fini(void) | |
58 | { | |
a45049c5 | 59 | xt_unregister_match(&realm_match); |
1da177e4 LT |
60 | } |
61 | ||
62 | module_init(init); | |
63 | module_exit(fini); |