Skip to content

Commit

Permalink
ip: reject too-big defragmented DF-skb when forwarding
Browse files Browse the repository at this point in the history
Send icmp pmtu error if we find that the largest fragment of df-skb
exceeded the output path mtu.

The ip output path will still catch this later on but we can avoid the
forward/postrouting hook traversal by rejecting right away.

This is what ipv6 already does.

Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Westphal authored and David S. Miller committed May 25, 2015
1 parent b10e3d6 commit cf82624
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions net/ipv4/ip_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@
#include <net/route.h>
#include <net/xfrm.h>

static bool ip_may_fragment(const struct sk_buff *skb)
{
return unlikely((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0) ||
skb->ignore_df;
}

static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
{
if (skb->len <= mtu)
return false;

if (unlikely((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0))
return false;

/* original fragment exceeds mtu and DF is set */
if (unlikely(IPCB(skb)->frag_max_size > mtu))
return true;

if (skb->ignore_df)
return false;

if (skb_is_gso(skb) && skb_gso_network_seglen(skb) <= mtu)
return false;

Expand Down Expand Up @@ -114,7 +118,7 @@ int ip_forward(struct sk_buff *skb)

IPCB(skb)->flags |= IPSKB_FORWARDED;
mtu = ip_dst_mtu_maybe_forward(&rt->dst, true);
if (!ip_may_fragment(skb) && ip_exceeds_mtu(skb, mtu)) {
if (ip_exceeds_mtu(skb, mtu)) {
IP_INC_STATS(dev_net(rt->dst.dev), IPSTATS_MIB_FRAGFAILS);
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
htonl(mtu));
Expand Down

0 comments on commit cf82624

Please sign in to comment.