diff options
author | Jan Engelhardt <jengelh@computergmbh.de> | 2008-01-15 02:42:06 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 18:02:25 -0500 |
commit | 917b6fbd6e8dd952c64d1d7468897160467d2cc0 (patch) | |
tree | f06c669f94bfec8a193583028b166ae20f16cfda | |
parent | 57de0abbffa9724e2a89860a49725d805bfc07ca (diff) |
[NETFILTER]: xt_policy: use the new union nf_inet_addr
Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/netfilter/xt_policy.h | 23 | ||||
-rw-r--r-- | net/netfilter/xt_policy.c | 15 |
2 files changed, 27 insertions, 11 deletions
diff --git a/include/linux/netfilter/xt_policy.h b/include/linux/netfilter/xt_policy.h index 45654d359a68..053d8cc65464 100644 --- a/include/linux/netfilter/xt_policy.h +++ b/include/linux/netfilter/xt_policy.h | |||
@@ -27,18 +27,33 @@ struct xt_policy_spec | |||
27 | reqid:1; | 27 | reqid:1; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #ifndef __KERNEL__ | ||
30 | union xt_policy_addr | 31 | union xt_policy_addr |
31 | { | 32 | { |
32 | struct in_addr a4; | 33 | struct in_addr a4; |
33 | struct in6_addr a6; | 34 | struct in6_addr a6; |
34 | }; | 35 | }; |
36 | #endif | ||
35 | 37 | ||
36 | struct xt_policy_elem | 38 | struct xt_policy_elem |
37 | { | 39 | { |
38 | union xt_policy_addr saddr; | 40 | union { |
39 | union xt_policy_addr smask; | 41 | #ifdef __KERNEL__ |
40 | union xt_policy_addr daddr; | 42 | struct { |
41 | union xt_policy_addr dmask; | 43 | union nf_inet_addr saddr; |
44 | union nf_inet_addr smask; | ||
45 | union nf_inet_addr daddr; | ||
46 | union nf_inet_addr dmask; | ||
47 | }; | ||
48 | #else | ||
49 | struct { | ||
50 | union xt_policy_addr saddr; | ||
51 | union xt_policy_addr smask; | ||
52 | union xt_policy_addr daddr; | ||
53 | union xt_policy_addr dmask; | ||
54 | }; | ||
55 | #endif | ||
56 | }; | ||
42 | __be32 spi; | 57 | __be32 spi; |
43 | u_int32_t reqid; | 58 | u_int32_t reqid; |
44 | u_int8_t proto; | 59 | u_int8_t proto; |
diff --git a/net/netfilter/xt_policy.c b/net/netfilter/xt_policy.c index 45731ca15b7d..47c2e4328a1b 100644 --- a/net/netfilter/xt_policy.c +++ b/net/netfilter/xt_policy.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <net/xfrm.h> | 14 | #include <net/xfrm.h> |
15 | 15 | ||
16 | #include <linux/netfilter.h> | ||
16 | #include <linux/netfilter/xt_policy.h> | 17 | #include <linux/netfilter/xt_policy.h> |
17 | #include <linux/netfilter/x_tables.h> | 18 | #include <linux/netfilter/x_tables.h> |
18 | 19 | ||
@@ -21,14 +22,14 @@ MODULE_DESCRIPTION("Xtables IPsec policy matching module"); | |||
21 | MODULE_LICENSE("GPL"); | 22 | MODULE_LICENSE("GPL"); |
22 | 23 | ||
23 | static inline bool | 24 | static inline bool |
24 | xt_addr_cmp(const union xt_policy_addr *a1, const union xt_policy_addr *m, | 25 | xt_addr_cmp(const union nf_inet_addr *a1, const union nf_inet_addr *m, |
25 | const union xt_policy_addr *a2, unsigned short family) | 26 | const union nf_inet_addr *a2, unsigned short family) |
26 | { | 27 | { |
27 | switch (family) { | 28 | switch (family) { |
28 | case AF_INET: | 29 | case AF_INET: |
29 | return !((a1->a4.s_addr ^ a2->a4.s_addr) & m->a4.s_addr); | 30 | return ((a1->ip ^ a2->ip) & m->ip) == 0; |
30 | case AF_INET6: | 31 | case AF_INET6: |
31 | return !ipv6_masked_addr_cmp(&a1->a6, &m->a6, &a2->a6); | 32 | return ipv6_masked_addr_cmp(&a1->in6, &m->in6, &a2->in6) == 0; |
32 | } | 33 | } |
33 | return false; | 34 | return false; |
34 | } | 35 | } |
@@ -38,12 +39,12 @@ match_xfrm_state(const struct xfrm_state *x, const struct xt_policy_elem *e, | |||
38 | unsigned short family) | 39 | unsigned short family) |
39 | { | 40 | { |
40 | #define MATCH_ADDR(x,y,z) (!e->match.x || \ | 41 | #define MATCH_ADDR(x,y,z) (!e->match.x || \ |
41 | (xt_addr_cmp(&e->x, &e->y, (z), family) \ | 42 | (xt_addr_cmp(&e->x, &e->y, (const union nf_inet_addr *)(z), family) \ |
42 | ^ e->invert.x)) | 43 | ^ e->invert.x)) |
43 | #define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x)) | 44 | #define MATCH(x,y) (!e->match.x || ((e->x == (y)) ^ e->invert.x)) |
44 | 45 | ||
45 | return MATCH_ADDR(saddr, smask, (union xt_policy_addr *)&x->props.saddr) && | 46 | return MATCH_ADDR(saddr, smask, &x->props.saddr) && |
46 | MATCH_ADDR(daddr, dmask, (union xt_policy_addr *)&x->id.daddr) && | 47 | MATCH_ADDR(daddr, dmask, &x->id.daddr) && |
47 | MATCH(proto, x->id.proto) && | 48 | MATCH(proto, x->id.proto) && |
48 | MATCH(mode, x->props.mode) && | 49 | MATCH(mode, x->props.mode) && |
49 | MATCH(spi, x->id.spi) && | 50 | MATCH(spi, x->id.spi) && |