Merge branch 'upstream' of master.kernel.org:/pub/scm/linux/kernel/git/linville/wirel...
[powerpc.git] / net / ipv4 / netfilter / ipt_REJECT.c
index b81821e..e4a1ddb 100644 (file)
@@ -22,6 +22,7 @@
 #include <net/tcp.h>
 #include <net/route.h>
 #include <net/dst.h>
+#include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include <linux/netfilter_ipv4/ipt_REJECT.h>
 #ifdef CONFIG_BRIDGE_NETFILTER
@@ -38,76 +39,16 @@ MODULE_DESCRIPTION("iptables REJECT target module");
 #define DEBUGP(format, args...)
 #endif
 
-static inline struct rtable *route_reverse(struct sk_buff *skb, 
-                                          struct tcphdr *tcph, int hook)
-{
-       struct iphdr *iph = skb->nh.iph;
-       struct dst_entry *odst;
-       struct flowi fl = {};
-       struct rtable *rt;
-
-       /* We don't require ip forwarding to be enabled to be able to
-        * send a RST reply for bridged traffic. */
-       if (hook != NF_IP_FORWARD
-#ifdef CONFIG_BRIDGE_NETFILTER
-           || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
-#endif
-          ) {
-               fl.nl_u.ip4_u.daddr = iph->saddr;
-               if (hook == NF_IP_LOCAL_IN)
-                       fl.nl_u.ip4_u.saddr = iph->daddr;
-               fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
-
-               if (ip_route_output_key(&rt, &fl) != 0)
-                       return NULL;
-       } else {
-               /* non-local src, find valid iif to satisfy
-                * rp-filter when calling ip_route_input. */
-               fl.nl_u.ip4_u.daddr = iph->daddr;
-               if (ip_route_output_key(&rt, &fl) != 0)
-                       return NULL;
-
-               odst = skb->dst;
-               if (ip_route_input(skb, iph->saddr, iph->daddr,
-                                  RT_TOS(iph->tos), rt->u.dst.dev) != 0) {
-                       dst_release(&rt->u.dst);
-                       return NULL;
-               }
-               dst_release(&rt->u.dst);
-               rt = (struct rtable *)skb->dst;
-               skb->dst = odst;
-
-               fl.nl_u.ip4_u.daddr = iph->saddr;
-               fl.nl_u.ip4_u.saddr = iph->daddr;
-               fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
-       }
-
-       if (rt->u.dst.error) {
-               dst_release(&rt->u.dst);
-               return NULL;
-       }
-
-       fl.proto = IPPROTO_TCP;
-       fl.fl_ip_sport = tcph->dest;
-       fl.fl_ip_dport = tcph->source;
-       security_skb_classify_flow(skb, &fl);
-
-       xfrm_lookup((struct dst_entry **)&rt, &fl, NULL, 0);
-
-       return rt;
-}
-
 /* Send RST reply */
 static void send_reset(struct sk_buff *oldskb, int hook)
 {
        struct sk_buff *nskb;
        struct iphdr *iph = oldskb->nh.iph;
        struct tcphdr _otcph, *oth, *tcph;
-       struct rtable *rt;
-       u_int16_t tmp_port;
-       u_int32_t tmp_addr;
+       __be16 tmp_port;
+       __be32 tmp_addr;
        int needs_ack;
-       int hh_len;
+       unsigned int addr_type;
 
        /* IP header checks: fragment. */
        if (oldskb->nh.iph->frag_off & htons(IP_OFFSET))
@@ -126,27 +67,17 @@ static void send_reset(struct sk_buff *oldskb, int hook)
        if (nf_ip_checksum(oldskb, hook, iph->ihl * 4, IPPROTO_TCP))
                return;
 
-       if ((rt = route_reverse(oldskb, oth, hook)) == NULL)
-               return;
-
-       hh_len = LL_RESERVED_SPACE(rt->u.dst.dev);
-
        /* We need a linear, writeable skb.  We also need to expand
           headroom in case hh_len of incoming interface < hh_len of
           outgoing interface */
-       nskb = skb_copy_expand(oldskb, hh_len, skb_tailroom(oldskb),
+       nskb = skb_copy_expand(oldskb, LL_MAX_HEADER, skb_tailroom(oldskb),
                               GFP_ATOMIC);
-       if (!nskb) {
-               dst_release(&rt->u.dst);
+       if (!nskb)
                return;
-       }
-
-       dst_release(nskb->dst);
-       nskb->dst = &rt->u.dst;
 
        /* This packet will not be the same as the other: clear nf fields */
        nf_reset(nskb);
-       nskb->nfmark = 0;
+       nskb->mark = 0;
        skb_init_secmark(nskb);
 
        tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
@@ -185,20 +116,33 @@ static void send_reset(struct sk_buff *oldskb, int hook)
        tcph->urg_ptr = 0;
 
        /* Adjust TCP checksum */
-       nskb->ip_summed = CHECKSUM_NONE;
        tcph->check = 0;
-       tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr),
+       tcph->check = tcp_v4_check(sizeof(struct tcphdr),
                                   nskb->nh.iph->saddr,
                                   nskb->nh.iph->daddr,
                                   csum_partial((char *)tcph,
                                                sizeof(struct tcphdr), 0));
 
-       /* Adjust IP TTL, DF */
-       nskb->nh.iph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
        /* Set DF, id = 0 */
        nskb->nh.iph->frag_off = htons(IP_DF);
        nskb->nh.iph->id = 0;
 
+       addr_type = RTN_UNSPEC;
+       if (hook != NF_IP_FORWARD
+#ifdef CONFIG_BRIDGE_NETFILTER
+           || (nskb->nf_bridge && nskb->nf_bridge->mask & BRNF_BRIDGED)
+#endif
+          )
+               addr_type = RTN_LOCAL;
+
+       if (ip_route_me_harder(&nskb, addr_type))
+               goto free_nskb;
+
+       nskb->ip_summed = CHECKSUM_NONE;
+
+       /* Adjust IP TTL */
+       nskb->nh.iph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
+
        /* Adjust IP checksum */
        nskb->nh.iph->check = 0;
        nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph, 
@@ -287,7 +231,7 @@ static int check(const char *tablename,
        } else if (rejinfo->with == IPT_TCP_RESET) {
                /* Must specify that it's a TCP packet */
                if (e->ip.proto != IPPROTO_TCP
-                   || (e->ip.invflags & IPT_INV_PROTO)) {
+                   || (e->ip.invflags & XT_INV_PROTO)) {
                        DEBUGP("REJECT: TCP_RESET invalid for non-tcp\n");
                        return 0;
                }
@@ -295,8 +239,9 @@ static int check(const char *tablename,
        return 1;
 }
 
-static struct ipt_target ipt_reject_reg = {
+static struct xt_target ipt_reject_reg = {
        .name           = "REJECT",
+       .family         = AF_INET,
        .target         = reject,
        .targetsize     = sizeof(struct ipt_reject_info),
        .table          = "filter",
@@ -308,12 +253,12 @@ static struct ipt_target ipt_reject_reg = {
 
 static int __init ipt_reject_init(void)
 {
-       return ipt_register_target(&ipt_reject_reg);
+       return xt_register_target(&ipt_reject_reg);
 }
 
 static void __exit ipt_reject_fini(void)
 {
-       ipt_unregister_target(&ipt_reject_reg);
+       xt_unregister_target(&ipt_reject_reg);
 }
 
 module_init(ipt_reject_init);