diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2013-08-12 22:35:58 -0400 |
---|---|---|
committer | Steffen Klassert <steffen.klassert@secunet.com> | 2013-08-14 07:09:07 -0400 |
commit | 0ea9d5e3e0e03a63b11392f5613378977dae7eca (patch) | |
tree | a363333080f9f8647f3f80dc7e736a308c36b7cb | |
parent | 628e341f319f1a64a4639088faba952e4ec8f0a8 (diff) |
xfrm: introduce helper for safe determination of mtu
skb->sk socket can be of AF_INET or AF_INET6 address family. Thus we
always have to make sure we a referring to the correct interpretation
of skb->sk.
We only depend on header defines to query the mtu, so we don't introduce
a new dependency to ipv6 by this change.
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
-rw-r--r-- | include/net/route.h | 8 | ||||
-rw-r--r-- | include/net/xfrm.h | 12 | ||||
-rw-r--r-- | net/ipv4/ip_output.c | 8 | ||||
-rw-r--r-- | net/ipv4/xfrm4_output.c | 4 | ||||
-rw-r--r-- | net/ipv6/xfrm6_output.c | 5 |
5 files changed, 25 insertions, 12 deletions
diff --git a/include/net/route.h b/include/net/route.h index 2ea40c1b5e00..afdeeb5bec25 100644 --- a/include/net/route.h +++ b/include/net/route.h | |||
@@ -317,4 +317,12 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst) | |||
317 | return hoplimit; | 317 | return hoplimit; |
318 | } | 318 | } |
319 | 319 | ||
320 | static inline int ip_skb_dst_mtu(struct sk_buff *skb) | ||
321 | { | ||
322 | struct inet_sock *inet = skb->sk ? inet_sk(skb->sk) : NULL; | ||
323 | |||
324 | return (inet && inet->pmtudisc == IP_PMTUDISC_PROBE) ? | ||
325 | skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); | ||
326 | } | ||
327 | |||
320 | #endif /* _ROUTE_H */ | 328 | #endif /* _ROUTE_H */ |
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index e823786e7c66..b41d2d10ff0e 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <net/route.h> | 20 | #include <net/route.h> |
21 | #include <net/ipv6.h> | 21 | #include <net/ipv6.h> |
22 | #include <net/ip6_fib.h> | 22 | #include <net/ip6_fib.h> |
23 | #include <net/ip6_route.h> | ||
23 | #include <net/flow.h> | 24 | #include <net/flow.h> |
24 | 25 | ||
25 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
@@ -1723,4 +1724,15 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m) | |||
1723 | return ret; | 1724 | return ret; |
1724 | } | 1725 | } |
1725 | 1726 | ||
1727 | static inline int xfrm_skb_dst_mtu(struct sk_buff *skb) | ||
1728 | { | ||
1729 | struct sock *sk = skb->sk; | ||
1730 | |||
1731 | if (sk && sk->sk_family == AF_INET6) | ||
1732 | return ip6_skb_dst_mtu(skb); | ||
1733 | else if (sk && sk->sk_family == AF_INET) | ||
1734 | return ip_skb_dst_mtu(skb); | ||
1735 | return dst_mtu(skb_dst(skb)); | ||
1736 | } | ||
1737 | |||
1726 | #endif /* _NET_XFRM_H */ | 1738 | #endif /* _NET_XFRM_H */ |
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 4bcabf3ab4ca..9ee17e3d11c3 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c | |||
@@ -211,14 +211,6 @@ static inline int ip_finish_output2(struct sk_buff *skb) | |||
211 | return -EINVAL; | 211 | return -EINVAL; |
212 | } | 212 | } |
213 | 213 | ||
214 | static inline int ip_skb_dst_mtu(struct sk_buff *skb) | ||
215 | { | ||
216 | struct inet_sock *inet = skb->sk ? inet_sk(skb->sk) : NULL; | ||
217 | |||
218 | return (inet && inet->pmtudisc == IP_PMTUDISC_PROBE) ? | ||
219 | skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); | ||
220 | } | ||
221 | |||
222 | static int ip_finish_output(struct sk_buff *skb) | 214 | static int ip_finish_output(struct sk_buff *skb) |
223 | { | 215 | { |
224 | #if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM) | 216 | #if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM) |
diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c index 7a5491ffa4de..80baf4a3b1b5 100644 --- a/net/ipv4/xfrm4_output.c +++ b/net/ipv4/xfrm4_output.c | |||
@@ -21,7 +21,6 @@ | |||
21 | static int xfrm4_tunnel_check_size(struct sk_buff *skb) | 21 | static int xfrm4_tunnel_check_size(struct sk_buff *skb) |
22 | { | 22 | { |
23 | int mtu, ret = 0; | 23 | int mtu, ret = 0; |
24 | struct dst_entry *dst; | ||
25 | 24 | ||
26 | if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE) | 25 | if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE) |
27 | goto out; | 26 | goto out; |
@@ -29,8 +28,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) | |||
29 | if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df) | 28 | if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df) |
30 | goto out; | 29 | goto out; |
31 | 30 | ||
32 | dst = skb_dst(skb); | 31 | mtu = xfrm_skb_dst_mtu(skb); |
33 | mtu = dst_mtu(dst); | ||
34 | if (skb->len > mtu) { | 32 | if (skb->len > mtu) { |
35 | if (skb->sk) | 33 | if (skb->sk) |
36 | xfrm_local_error(skb, mtu); | 34 | xfrm_local_error(skb, mtu); |
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c index b64fff30eb06..3ac5ab264fed 100644 --- a/net/ipv6/xfrm6_output.c +++ b/net/ipv6/xfrm6_output.c | |||
@@ -138,7 +138,10 @@ static int __xfrm6_output(struct sk_buff *skb) | |||
138 | { | 138 | { |
139 | struct dst_entry *dst = skb_dst(skb); | 139 | struct dst_entry *dst = skb_dst(skb); |
140 | struct xfrm_state *x = dst->xfrm; | 140 | struct xfrm_state *x = dst->xfrm; |
141 | int mtu = ip6_skb_dst_mtu(skb); | 141 | int mtu = xfrm_skb_dst_mtu(skb); |
142 | |||
143 | if (mtu < IPV6_MIN_MTU) | ||
144 | mtu = IPV6_MIN_MTU; | ||
142 | 145 | ||
143 | if (skb->len > mtu && xfrm6_local_dontfrag(skb)) { | 146 | if (skb->len > mtu && xfrm6_local_dontfrag(skb)) { |
144 | xfrm6_local_rxpmtu(skb, mtu); | 147 | xfrm6_local_rxpmtu(skb, mtu); |