diff options
author | Patrick McHardy <kaber@trash.net> | 2006-03-20 21:03:40 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-03-20 21:03:40 -0500 |
commit | c4b885139203d37f76662c37ae645fe8e0f4e4e5 (patch) | |
tree | 5cedf4d632b273df81bf1712b95dbc8b96cdc0e4 /net/ipv4 | |
parent | f2ffd9eeda82b476c034d733be08ecf6a87d2edf (diff) |
[NETFILTER]: x_tables: replace IPv4/IPv6 policy match by address family independant version
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/netfilter/Kconfig | 10 | ||||
-rw-r--r-- | net/ipv4/netfilter/Makefile | 1 | ||||
-rw-r--r-- | net/ipv4/netfilter/ipt_policy.c | 174 |
3 files changed, 0 insertions, 185 deletions
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig index db783036e4d8..933ee7a9efdf 100644 --- a/net/ipv4/netfilter/Kconfig +++ b/net/ipv4/netfilter/Kconfig | |||
@@ -303,16 +303,6 @@ config IP_NF_MATCH_HASHLIMIT | |||
303 | destination IP' or `500pps from any given source IP' with a single | 303 | destination IP' or `500pps from any given source IP' with a single |
304 | IPtables rule. | 304 | IPtables rule. |
305 | 305 | ||
306 | config IP_NF_MATCH_POLICY | ||
307 | tristate "IPsec policy match support" | ||
308 | depends on IP_NF_IPTABLES && XFRM | ||
309 | help | ||
310 | Policy matching allows you to match packets based on the | ||
311 | IPsec policy that was used during decapsulation/will | ||
312 | be used during encapsulation. | ||
313 | |||
314 | To compile it as a module, choose M here. If unsure, say N. | ||
315 | |||
316 | # `filter', generic and specific targets | 306 | # `filter', generic and specific targets |
317 | config IP_NF_FILTER | 307 | config IP_NF_FILTER |
318 | tristate "Packet filtering" | 308 | tristate "Packet filtering" |
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile index e5c5b3202f02..3fe80924ac54 100644 --- a/net/ipv4/netfilter/Makefile +++ b/net/ipv4/netfilter/Makefile | |||
@@ -57,7 +57,6 @@ obj-$(CONFIG_IP_NF_MATCH_DSCP) += ipt_dscp.o | |||
57 | obj-$(CONFIG_IP_NF_MATCH_AH_ESP) += ipt_ah.o ipt_esp.o | 57 | obj-$(CONFIG_IP_NF_MATCH_AH_ESP) += ipt_ah.o ipt_esp.o |
58 | obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o | 58 | obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o |
59 | obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o | 59 | obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o |
60 | obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o | ||
61 | 60 | ||
62 | # targets | 61 | # targets |
63 | obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o | 62 | obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o |
diff --git a/net/ipv4/netfilter/ipt_policy.c b/net/ipv4/netfilter/ipt_policy.c deleted file mode 100644 index b73f590b226b..000000000000 --- a/net/ipv4/netfilter/ipt_policy.c +++ /dev/null | |||
@@ -1,174 +0,0 @@ | |||
1 | /* IP tables module for matching IPsec policy | ||
2 | * | ||
3 | * Copyright (c) 2004,2005 Patrick McHardy, <kaber@trash.net> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/skbuff.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <net/xfrm.h> | ||
16 | |||
17 | #include <linux/netfilter_ipv4.h> | ||
18 | #include <linux/netfilter_ipv4/ip_tables.h> | ||
19 | #include <linux/netfilter_ipv4/ipt_policy.h> | ||
20 | |||
21 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); | ||
22 | MODULE_DESCRIPTION("IPtables IPsec policy matching module"); | ||
23 | MODULE_LICENSE("GPL"); | ||
24 | |||
25 | |||
26 | static inline int | ||
27 | match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e) | ||
28 | { | ||
29 | #define MATCH_ADDR(x,y,z) (!e->match.x || \ | ||
30 | ((e->x.a4.s_addr == (e->y.a4.s_addr & (z))) \ | ||
31 | ^ e->invert.x)) | ||
32 | #define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x)) | ||
33 | |||
34 | return MATCH_ADDR(saddr, smask, x->props.saddr.a4) && | ||
35 | MATCH_ADDR(daddr, dmask, x->id.daddr.a4) && | ||
36 | MATCH(proto, x->id.proto) && | ||
37 | MATCH(mode, x->props.mode) && | ||
38 | MATCH(spi, x->id.spi) && | ||
39 | MATCH(reqid, x->props.reqid); | ||
40 | } | ||
41 | |||
42 | static int | ||
43 | match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info) | ||
44 | { | ||
45 | const struct ipt_policy_elem *e; | ||
46 | struct sec_path *sp = skb->sp; | ||
47 | int strict = info->flags & IPT_POLICY_MATCH_STRICT; | ||
48 | int i, pos; | ||
49 | |||
50 | if (sp == NULL) | ||
51 | return -1; | ||
52 | if (strict && info->len != sp->len) | ||
53 | return 0; | ||
54 | |||
55 | for (i = sp->len - 1; i >= 0; i--) { | ||
56 | pos = strict ? i - sp->len + 1 : 0; | ||
57 | if (pos >= info->len) | ||
58 | return 0; | ||
59 | e = &info->pol[pos]; | ||
60 | |||
61 | if (match_xfrm_state(sp->x[i].xvec, e)) { | ||
62 | if (!strict) | ||
63 | return 1; | ||
64 | } else if (strict) | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | return strict ? 1 : 0; | ||
69 | } | ||
70 | |||
71 | static int | ||
72 | match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info) | ||
73 | { | ||
74 | const struct ipt_policy_elem *e; | ||
75 | struct dst_entry *dst = skb->dst; | ||
76 | int strict = info->flags & IPT_POLICY_MATCH_STRICT; | ||
77 | int i, pos; | ||
78 | |||
79 | if (dst->xfrm == NULL) | ||
80 | return -1; | ||
81 | |||
82 | for (i = 0; dst && dst->xfrm; dst = dst->child, i++) { | ||
83 | pos = strict ? i : 0; | ||
84 | if (pos >= info->len) | ||
85 | return 0; | ||
86 | e = &info->pol[pos]; | ||
87 | |||
88 | if (match_xfrm_state(dst->xfrm, e)) { | ||
89 | if (!strict) | ||
90 | return 1; | ||
91 | } else if (strict) | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | return strict ? i == info->len : 0; | ||
96 | } | ||
97 | |||
98 | static int match(const struct sk_buff *skb, | ||
99 | const struct net_device *in, | ||
100 | const struct net_device *out, | ||
101 | const struct xt_match *match, | ||
102 | const void *matchinfo, | ||
103 | int offset, | ||
104 | unsigned int protoff, | ||
105 | int *hotdrop) | ||
106 | { | ||
107 | const struct ipt_policy_info *info = matchinfo; | ||
108 | int ret; | ||
109 | |||
110 | if (info->flags & IPT_POLICY_MATCH_IN) | ||
111 | ret = match_policy_in(skb, info); | ||
112 | else | ||
113 | ret = match_policy_out(skb, info); | ||
114 | |||
115 | if (ret < 0) | ||
116 | ret = info->flags & IPT_POLICY_MATCH_NONE ? 1 : 0; | ||
117 | else if (info->flags & IPT_POLICY_MATCH_NONE) | ||
118 | ret = 0; | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static int checkentry(const char *tablename, const void *ip_void, | ||
124 | const struct xt_match *match, | ||
125 | void *matchinfo, unsigned int matchsize, | ||
126 | unsigned int hook_mask) | ||
127 | { | ||
128 | struct ipt_policy_info *info = matchinfo; | ||
129 | |||
130 | if (!(info->flags & (IPT_POLICY_MATCH_IN|IPT_POLICY_MATCH_OUT))) { | ||
131 | printk(KERN_ERR "ipt_policy: neither incoming nor " | ||
132 | "outgoing policy selected\n"); | ||
133 | return 0; | ||
134 | } | ||
135 | if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN) | ||
136 | && info->flags & IPT_POLICY_MATCH_OUT) { | ||
137 | printk(KERN_ERR "ipt_policy: output policy not valid in " | ||
138 | "PRE_ROUTING and INPUT\n"); | ||
139 | return 0; | ||
140 | } | ||
141 | if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT) | ||
142 | && info->flags & IPT_POLICY_MATCH_IN) { | ||
143 | printk(KERN_ERR "ipt_policy: input policy not valid in " | ||
144 | "POST_ROUTING and OUTPUT\n"); | ||
145 | return 0; | ||
146 | } | ||
147 | if (info->len > IPT_POLICY_MAX_ELEM) { | ||
148 | printk(KERN_ERR "ipt_policy: too many policy elements\n"); | ||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | static struct ipt_match policy_match = { | ||
156 | .name = "policy", | ||
157 | .match = match, | ||
158 | .matchsize = sizeof(struct ipt_policy_info), | ||
159 | .checkentry = checkentry, | ||
160 | .me = THIS_MODULE, | ||
161 | }; | ||
162 | |||
163 | static int __init init(void) | ||
164 | { | ||
165 | return ipt_register_match(&policy_match); | ||
166 | } | ||
167 | |||
168 | static void __exit fini(void) | ||
169 | { | ||
170 | ipt_unregister_match(&policy_match); | ||
171 | } | ||
172 | |||
173 | module_init(init); | ||
174 | module_exit(fini); | ||