Skip to content

Commit

Permalink
xfrm: introduce helper for safe determination of mtu
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
strssndktn authored and klassert committed Aug 14, 2013
1 parent 628e341 commit 0ea9d5e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
8 changes: 8 additions & 0 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,12 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst)
return hoplimit;
}

static inline int ip_skb_dst_mtu(struct sk_buff *skb)
{
struct inet_sock *inet = skb->sk ? inet_sk(skb->sk) : NULL;

return (inet && inet->pmtudisc == IP_PMTUDISC_PROBE) ?
skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
}

#endif /* _ROUTE_H */
12 changes: 12 additions & 0 deletions include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <net/route.h>
#include <net/ipv6.h>
#include <net/ip6_fib.h>
#include <net/ip6_route.h>
#include <net/flow.h>

#include <linux/interrupt.h>
Expand Down Expand Up @@ -1723,4 +1724,15 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m)
return ret;
}

static inline int xfrm_skb_dst_mtu(struct sk_buff *skb)
{
struct sock *sk = skb->sk;

if (sk && sk->sk_family == AF_INET6)
return ip6_skb_dst_mtu(skb);
else if (sk && sk->sk_family == AF_INET)
return ip_skb_dst_mtu(skb);
return dst_mtu(skb_dst(skb));
}

#endif /* _NET_XFRM_H */
8 changes: 0 additions & 8 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ static inline int ip_finish_output2(struct sk_buff *skb)
return -EINVAL;
}

static inline int ip_skb_dst_mtu(struct sk_buff *skb)
{
struct inet_sock *inet = skb->sk ? inet_sk(skb->sk) : NULL;

return (inet && inet->pmtudisc == IP_PMTUDISC_PROBE) ?
skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
}

static int ip_finish_output(struct sk_buff *skb)
{
#if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM)
Expand Down
4 changes: 1 addition & 3 deletions net/ipv4/xfrm4_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
static int xfrm4_tunnel_check_size(struct sk_buff *skb)
{
int mtu, ret = 0;
struct dst_entry *dst;

if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE)
goto out;

if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df)
goto out;

dst = skb_dst(skb);
mtu = dst_mtu(dst);
mtu = xfrm_skb_dst_mtu(skb);
if (skb->len > mtu) {
if (skb->sk)
xfrm_local_error(skb, mtu);
Expand Down
5 changes: 4 additions & 1 deletion net/ipv6/xfrm6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ static int __xfrm6_output(struct sk_buff *skb)
{
struct dst_entry *dst = skb_dst(skb);
struct xfrm_state *x = dst->xfrm;
int mtu = ip6_skb_dst_mtu(skb);
int mtu = xfrm_skb_dst_mtu(skb);

if (mtu < IPV6_MIN_MTU)
mtu = IPV6_MIN_MTU;

if (skb->len > mtu && xfrm6_local_dontfrag(skb)) {
xfrm6_local_rxpmtu(skb, mtu);
Expand Down

0 comments on commit 0ea9d5e

Please sign in to comment.