netfilter: xtables: add struct xt_mtdtor_param::net
[safe/jmp/linux-2.6] / net / ipv4 / ip_forward.c
index 0923add..a2991bc 100644 (file)
@@ -4,15 +4,13 @@
  *             interface as the means of communication with the user level.
  *
  *             The IP forwarding functionality.
- *             
- * Version:    $Id: ip_forward.c,v 1.48 2000/12/13 18:31:48 davem Exp $
  *
  * Authors:    see ip.c
  *
  * Fixes:
- *             Many            :       Split from ip.c , see ip_input.c for 
+ *             Many            :       Split from ip.c , see ip_input.c for
  *                                     history.
- *             Dave Gregorich  :       NULL ip_rt_put fix for multicast 
+ *             Dave Gregorich  :       NULL ip_rt_put fix for multicast
  *                                     routing.
  *             Jos Vos         :       Add call_out_firewall before sending,
  *                                     use output device for accounting.
  *             Mike McLagan    :       Routing by source
  */
 
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/mm.h>
-#include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
 #include <linux/icmp.h>
 #include <net/route.h>
 #include <net/xfrm.h>
 
-static inline int ip_forward_finish(struct sk_buff *skb)
+static int ip_forward_finish(struct sk_buff *skb)
 {
        struct ip_options * opt = &(IPCB(skb)->opt);
 
-       IP_INC_STATS_BH(IPSTATS_MIB_OUTFORWDATAGRAMS);
+       IP_INC_STATS_BH(dev_net(skb_dst(skb)->dev), IPSTATS_MIB_OUTFORWDATAGRAMS);
 
        if (unlikely(opt->optlen))
                ip_forward_options(skb);
@@ -60,6 +56,9 @@ int ip_forward(struct sk_buff *skb)
        struct rtable *rt;      /* Route we use */
        struct ip_options * opt = &(IPCB(skb)->opt);
 
+       if (skb_warn_if_lro(skb))
+               goto drop;
+
        if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb))
                goto drop;
 
@@ -69,28 +68,36 @@ int ip_forward(struct sk_buff *skb)
        if (skb->pkt_type != PACKET_HOST)
                goto drop;
 
-       skb->ip_summed = CHECKSUM_NONE;
-       
+       skb_forward_csum(skb);
+
        /*
         *      According to the RFC, we must first decrease the TTL field. If
         *      that reaches zero, we must reply an ICMP control message telling
         *      that the packet's lifetime expired.
         */
-       if (skb->nh.iph->ttl <= 1)
-                goto too_many_hops;
+       if (ip_hdr(skb)->ttl <= 1)
+               goto too_many_hops;
 
        if (!xfrm4_route_forward(skb))
                goto drop;
 
-       rt = (struct rtable*)skb->dst;
+       rt = skb_rtable(skb);
 
        if (opt->is_strictroute && rt->rt_dst != rt->rt_gateway)
                goto sr_failed;
 
+       if (unlikely(skb->len > dst_mtu(&rt->u.dst) && !skb_is_gso(skb) &&
+                    (ip_hdr(skb)->frag_off & htons(IP_DF))) && !skb->local_df) {
+               IP_INC_STATS(dev_net(rt->u.dst.dev), IPSTATS_MIB_FRAGFAILS);
+               icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+                         htonl(dst_mtu(&rt->u.dst)));
+               goto drop;
+       }
+
        /* We are about to mangle packet. Copy it! */
        if (skb_cow(skb, LL_RESERVED_SPACE(rt->u.dst.dev)+rt->u.dst.header_len))
                goto drop;
-       iph = skb->nh.iph;
+       iph = ip_hdr(skb);
 
        /* Decrease ttl after skb cow done */
        ip_decrease_ttl(iph);
@@ -99,24 +106,25 @@ int ip_forward(struct sk_buff *skb)
         *      We now generate an ICMP HOST REDIRECT giving the route
         *      we calculated.
         */
-       if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr)
+       if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb))
                ip_rt_send_redirect(skb);
 
        skb->priority = rt_tos2priority(iph->tos);
 
-       return NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, rt->u.dst.dev,
+       return NF_HOOK(PF_INET, NF_INET_FORWARD, skb, skb->dev, rt->u.dst.dev,
                       ip_forward_finish);
 
 sr_failed:
-        /*
+       /*
         *      Strict routing permits no gatewaying
         */
-         icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0);
-         goto drop;
+        icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0);
+        goto drop;
 
 too_many_hops:
-        /* Tell the sender its packet died... */
-        icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
+       /* Tell the sender its packet died... */
+       IP_INC_STATS_BH(dev_net(skb_dst(skb)->dev), IPSTATS_MIB_INHDRERRORS);
+       icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
 drop:
        kfree_skb(skb);
        return NET_RX_DROP;