diff options
author | Patrick McHardy <kaber@trash.net> | 2006-01-07 02:04:54 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-01-07 15:57:33 -0500 |
commit | 3e3850e989c5d2eb1aab6f0fd9257759f0f4cbc6 (patch) | |
tree | fa05d1de4767bc30e77442ffbacfe8bd8dd2213d | |
parent | 8cdfab8a43bb4b3da686ea503a702cb6f9f6a803 (diff) |
[NETFILTER]: Fix xfrm lookup in ip_route_me_harder/ip6_route_me_harder
ip_route_me_harder doesn't use the port numbers of the xfrm lookup and
uses ip_route_input for non-local addresses which doesn't do a xfrm
lookup, ip6_route_me_harder doesn't do a xfrm lookup at all.
Use xfrm_decode_session and do the lookup manually, make sure both
only do the lookup if the packet hasn't been transformed already.
Makeing sure the lookup only happens once needs a new field in the
IP6CB, which exceeds the size of skb->cb. The size of skb->cb is
increased to 48b. Apparently the IPv6 mobile extensions need some
more room anyway.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/ipv6.h | 3 | ||||
-rw-r--r-- | include/linux/skbuff.h | 2 | ||||
-rw-r--r-- | include/net/ip.h | 3 | ||||
-rw-r--r-- | include/net/xfrm.h | 2 | ||||
-rw-r--r-- | net/ipv4/ip_gre.c | 2 | ||||
-rw-r--r-- | net/ipv4/ipip.c | 2 | ||||
-rw-r--r-- | net/ipv4/netfilter.c | 12 | ||||
-rw-r--r-- | net/ipv4/xfrm4_output.c | 1 | ||||
-rw-r--r-- | net/ipv6/netfilter.c | 9 | ||||
-rw-r--r-- | net/ipv6/xfrm6_output.c | 1 | ||||
-rw-r--r-- | net/xfrm/xfrm_policy.c | 9 |
11 files changed, 34 insertions, 12 deletions
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index 5cfc71529595..9c8f4c9ed429 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h | |||
@@ -192,6 +192,9 @@ struct inet6_skb_parm { | |||
192 | __u16 dst1; | 192 | __u16 dst1; |
193 | __u16 lastopt; | 193 | __u16 lastopt; |
194 | __u32 nhoff; | 194 | __u32 nhoff; |
195 | __u16 flags; | ||
196 | |||
197 | #define IP6SKB_XFRM_TRANSFORMED 1 | ||
195 | }; | 198 | }; |
196 | 199 | ||
197 | #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb)) | 200 | #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb)) |
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 483cfc47ec34..e5fd66c5650b 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -251,7 +251,7 @@ struct sk_buff { | |||
251 | * want to keep them across layers you have to do a skb_clone() | 251 | * want to keep them across layers you have to do a skb_clone() |
252 | * first. This is owned by whoever has the skb queued ATM. | 252 | * first. This is owned by whoever has the skb queued ATM. |
253 | */ | 253 | */ |
254 | char cb[40]; | 254 | char cb[48]; |
255 | 255 | ||
256 | unsigned int len, | 256 | unsigned int len, |
257 | data_len, | 257 | data_len, |
diff --git a/include/net/ip.h b/include/net/ip.h index 52f4d9c69704..a494d04e5dea 100644 --- a/include/net/ip.h +++ b/include/net/ip.h | |||
@@ -39,7 +39,8 @@ struct inet_skb_parm | |||
39 | 39 | ||
40 | #define IPSKB_FORWARDED 1 | 40 | #define IPSKB_FORWARDED 1 |
41 | #define IPSKB_XFRM_TUNNEL_SIZE 2 | 41 | #define IPSKB_XFRM_TUNNEL_SIZE 2 |
42 | #define IPSKB_FRAG_COMPLETE 4 | 42 | #define IPSKB_XFRM_TRANSFORMED 4 |
43 | #define IPSKB_FRAG_COMPLETE 8 | ||
43 | }; | 44 | }; |
44 | 45 | ||
45 | struct ipcm_cookie | 46 | struct ipcm_cookie |
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 297d09d28fe4..d6111a2f0a23 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -668,7 +668,7 @@ static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *s | |||
668 | return xfrm_policy_check(sk, dir, skb, AF_INET6); | 668 | return xfrm_policy_check(sk, dir, skb, AF_INET6); |
669 | } | 669 | } |
670 | 670 | ||
671 | 671 | extern int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family); | |
672 | extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family); | 672 | extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family); |
673 | 673 | ||
674 | static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) | 674 | static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) |
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 65c3a91ed85e..de16e944777f 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c | |||
@@ -832,7 +832,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) | |||
832 | skb->h.raw = skb->nh.raw; | 832 | skb->h.raw = skb->nh.raw; |
833 | skb->nh.raw = skb_push(skb, gre_hlen); | 833 | skb->nh.raw = skb_push(skb, gre_hlen); |
834 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); | 834 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
835 | IPCB(skb)->flags &= ~IPSKB_XFRM_TUNNEL_SIZE; | 835 | IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE|IPSKB_XFRM_TRANSFORMED); |
836 | dst_release(skb->dst); | 836 | dst_release(skb->dst); |
837 | skb->dst = &rt->u.dst; | 837 | skb->dst = &rt->u.dst; |
838 | 838 | ||
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 078b59be91f4..bbd85f5ec985 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c | |||
@@ -621,7 +621,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) | |||
621 | skb->h.raw = skb->nh.raw; | 621 | skb->h.raw = skb->nh.raw; |
622 | skb->nh.raw = skb_push(skb, sizeof(struct iphdr)); | 622 | skb->nh.raw = skb_push(skb, sizeof(struct iphdr)); |
623 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); | 623 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
624 | IPCB(skb)->flags &= ~IPSKB_XFRM_TUNNEL_SIZE; | 624 | IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE|IPSKB_XFRM_TRANSFORMED); |
625 | dst_release(skb->dst); | 625 | dst_release(skb->dst); |
626 | skb->dst = &rt->u.dst; | 626 | skb->dst = &rt->u.dst; |
627 | 627 | ||
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c index ae0779d82c5d..4c637a1cbd23 100644 --- a/net/ipv4/netfilter.c +++ b/net/ipv4/netfilter.c | |||
@@ -7,11 +7,13 @@ | |||
7 | #include <linux/netfilter.h> | 7 | #include <linux/netfilter.h> |
8 | #include <linux/netfilter_ipv4.h> | 8 | #include <linux/netfilter_ipv4.h> |
9 | 9 | ||
10 | #include <linux/ip.h> | ||
10 | #include <linux/tcp.h> | 11 | #include <linux/tcp.h> |
11 | #include <linux/udp.h> | 12 | #include <linux/udp.h> |
12 | #include <linux/icmp.h> | 13 | #include <linux/icmp.h> |
13 | #include <net/route.h> | 14 | #include <net/route.h> |
14 | #include <linux/ip.h> | 15 | #include <net/xfrm.h> |
16 | #include <net/ip.h> | ||
15 | 17 | ||
16 | /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ | 18 | /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ |
17 | int ip_route_me_harder(struct sk_buff **pskb) | 19 | int ip_route_me_harder(struct sk_buff **pskb) |
@@ -33,7 +35,6 @@ int ip_route_me_harder(struct sk_buff **pskb) | |||
33 | #ifdef CONFIG_IP_ROUTE_FWMARK | 35 | #ifdef CONFIG_IP_ROUTE_FWMARK |
34 | fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark; | 36 | fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark; |
35 | #endif | 37 | #endif |
36 | fl.proto = iph->protocol; | ||
37 | if (ip_route_output_key(&rt, &fl) != 0) | 38 | if (ip_route_output_key(&rt, &fl) != 0) |
38 | return -1; | 39 | return -1; |
39 | 40 | ||
@@ -60,6 +61,13 @@ int ip_route_me_harder(struct sk_buff **pskb) | |||
60 | if ((*pskb)->dst->error) | 61 | if ((*pskb)->dst->error) |
61 | return -1; | 62 | return -1; |
62 | 63 | ||
64 | #ifdef CONFIG_XFRM | ||
65 | if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED) && | ||
66 | xfrm_decode_session(*pskb, &fl, AF_INET) == 0) | ||
67 | if (xfrm_lookup(&(*pskb)->dst, &fl, (*pskb)->sk, 0)) | ||
68 | return -1; | ||
69 | #endif | ||
70 | |||
63 | /* Change in oif may mean change in hh_len. */ | 71 | /* Change in oif may mean change in hh_len. */ |
64 | hh_len = (*pskb)->dst->dev->hard_header_len; | 72 | hh_len = (*pskb)->dst->dev->hard_header_len; |
65 | if (skb_headroom(*pskb) < hh_len) { | 73 | if (skb_headroom(*pskb) < hh_len) { |
diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c index 51fabb8f7c54..160c48800ab8 100644 --- a/net/ipv4/xfrm4_output.c +++ b/net/ipv4/xfrm4_output.c | |||
@@ -140,6 +140,7 @@ static int xfrm4_output_one(struct sk_buff *skb) | |||
140 | x = dst->xfrm; | 140 | x = dst->xfrm; |
141 | } while (x && !x->props.mode); | 141 | } while (x && !x->props.mode); |
142 | 142 | ||
143 | IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED; | ||
143 | err = 0; | 144 | err = 0; |
144 | 145 | ||
145 | out_exit: | 146 | out_exit: |
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c index f8626ebf90fd..b63678328a3b 100644 --- a/net/ipv6/netfilter.c +++ b/net/ipv6/netfilter.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <net/dst.h> | 10 | #include <net/dst.h> |
11 | #include <net/ipv6.h> | 11 | #include <net/ipv6.h> |
12 | #include <net/ip6_route.h> | 12 | #include <net/ip6_route.h> |
13 | #include <net/xfrm.h> | ||
13 | 14 | ||
14 | int ip6_route_me_harder(struct sk_buff *skb) | 15 | int ip6_route_me_harder(struct sk_buff *skb) |
15 | { | 16 | { |
@@ -21,11 +22,17 @@ int ip6_route_me_harder(struct sk_buff *skb) | |||
21 | { .ip6_u = | 22 | { .ip6_u = |
22 | { .daddr = iph->daddr, | 23 | { .daddr = iph->daddr, |
23 | .saddr = iph->saddr, } }, | 24 | .saddr = iph->saddr, } }, |
24 | .proto = iph->nexthdr, | ||
25 | }; | 25 | }; |
26 | 26 | ||
27 | dst = ip6_route_output(skb->sk, &fl); | 27 | dst = ip6_route_output(skb->sk, &fl); |
28 | 28 | ||
29 | #ifdef CONFIG_XFRM | ||
30 | if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && | ||
31 | xfrm_decode_session(skb, &fl, AF_INET6) == 0) | ||
32 | if (xfrm_lookup(&skb->dst, &fl, skb->sk, 0)) | ||
33 | return -1; | ||
34 | #endif | ||
35 | |||
29 | if (dst->error) { | 36 | if (dst->error) { |
30 | IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); | 37 | IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); |
31 | LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n"); | 38 | LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n"); |
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c index fc0ea38953c4..80242172a5df 100644 --- a/net/ipv6/xfrm6_output.c +++ b/net/ipv6/xfrm6_output.c | |||
@@ -139,6 +139,7 @@ static int xfrm6_output_one(struct sk_buff *skb) | |||
139 | x = dst->xfrm; | 139 | x = dst->xfrm; |
140 | } while (x && !x->props.mode); | 140 | } while (x && !x->props.mode); |
141 | 141 | ||
142 | IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED; | ||
142 | err = 0; | 143 | err = 0; |
143 | 144 | ||
144 | out_exit: | 145 | out_exit: |
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 64a447375fdb..f2edc9225b6a 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c | |||
@@ -951,8 +951,8 @@ xfrm_policy_ok(struct xfrm_tmpl *tmpl, struct sec_path *sp, int start, | |||
951 | return start; | 951 | return start; |
952 | } | 952 | } |
953 | 953 | ||
954 | static int | 954 | int |
955 | _decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family) | 955 | xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family) |
956 | { | 956 | { |
957 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); | 957 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); |
958 | 958 | ||
@@ -963,6 +963,7 @@ _decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family) | |||
963 | xfrm_policy_put_afinfo(afinfo); | 963 | xfrm_policy_put_afinfo(afinfo); |
964 | return 0; | 964 | return 0; |
965 | } | 965 | } |
966 | EXPORT_SYMBOL(xfrm_decode_session); | ||
966 | 967 | ||
967 | static inline int secpath_has_tunnel(struct sec_path *sp, int k) | 968 | static inline int secpath_has_tunnel(struct sec_path *sp, int k) |
968 | { | 969 | { |
@@ -982,7 +983,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, | |||
982 | u8 fl_dir = policy_to_flow_dir(dir); | 983 | u8 fl_dir = policy_to_flow_dir(dir); |
983 | u32 sk_sid; | 984 | u32 sk_sid; |
984 | 985 | ||
985 | if (_decode_session(skb, &fl, family) < 0) | 986 | if (xfrm_decode_session(skb, &fl, family) < 0) |
986 | return 0; | 987 | return 0; |
987 | 988 | ||
988 | sk_sid = security_sk_sid(sk, &fl, fl_dir); | 989 | sk_sid = security_sk_sid(sk, &fl, fl_dir); |
@@ -1055,7 +1056,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family) | |||
1055 | { | 1056 | { |
1056 | struct flowi fl; | 1057 | struct flowi fl; |
1057 | 1058 | ||
1058 | if (_decode_session(skb, &fl, family) < 0) | 1059 | if (xfrm_decode_session(skb, &fl, family) < 0) |
1059 | return 0; | 1060 | return 0; |
1060 | 1061 | ||
1061 | return xfrm_lookup(&skb->dst, &fl, NULL, 0) == 0; | 1062 | return xfrm_lookup(&skb->dst, &fl, NULL, 0) == 0; |