]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
[NETFILTER]: nf_conntrack: Introduces nf_ct_get_tuplepr and uses it
[linux-2.6.git] / net / ipv6 / netfilter / nf_conntrack_proto_icmpv6.c
index 3905cacc69af1d916feb0dc419b47b912e198d25..0fca7e8abeb71da3b407fbdbd45ac79e350c9509 100644 (file)
@@ -7,17 +7,9 @@
  *
  * Author:
  *     Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
- *
- * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
- *     - ICMPv6 tracking support. Derived from the original ip_conntrack code
- *       net/ipv4/netfilter/ip_conntrack_proto_icmp.c which had the following
- *       copyright information:
- *             (C) 1999-2001 Paul `Rusty' Russell
- *             (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
  */
 
 #include <linux/types.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/module.h>
 #include <linux/netfilter.h>
 
 static unsigned long nf_ct_icmpv6_timeout __read_mostly = 30*HZ;
 
-#if 0
-#define DEBUGP printk
-#else
-#define DEBUGP(format, args...)
-#endif
-
 static int icmpv6_pkt_to_tuple(const struct sk_buff *skb,
                               unsigned int dataoff,
                               struct nf_conntrack_tuple *tuple)
@@ -104,9 +90,9 @@ static int icmpv6_packet(struct nf_conn *ct,
                       unsigned int hooknum)
 {
        /* Try to delete connection immediately after all replies:
-           won't actually vanish as we still have skb, and del_timer
-           means this will only run once even if count hits zero twice
-           (theoretically possible with SMP) */
+          won't actually vanish as we still have skb, and del_timer
+          means this will only run once even if count hits zero twice
+          (theoretically possible with SMP) */
        if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
                if (atomic_dec_and_test(&ct->proto.icmp.count)
                    && del_timer(&ct->timeout))
@@ -133,8 +119,8 @@ static int icmpv6_new(struct nf_conn *conntrack,
 
        if (type < 0 || type >= sizeof(valid_new) || !valid_new[type]) {
                /* Can't create a new ICMPv6 `conn' with this. */
-               DEBUGP("icmpv6: can't create new conn with type %u\n",
-                      type + 128);
+               pr_debug("icmpv6: can't create new conn with type %u\n",
+                        type + 128);
                NF_CT_DUMP_TUPLE(&conntrack->tuplehash[0].tuple);
                return 0;
        }
@@ -150,60 +136,36 @@ icmpv6_error_message(struct sk_buff *skb,
 {
        struct nf_conntrack_tuple intuple, origtuple;
        struct nf_conntrack_tuple_hash *h;
-       struct icmp6hdr _hdr, *hp;
-       unsigned int inip6off;
        struct nf_conntrack_l4proto *inproto;
-       u_int8_t inprotonum;
-       unsigned int inprotoff;
 
        NF_CT_ASSERT(skb->nfct == NULL);
 
-       hp = skb_header_pointer(skb, icmp6off, sizeof(_hdr), &_hdr);
-       if (hp == NULL) {
-               DEBUGP("icmpv6_error: Can't get ICMPv6 hdr.\n");
-               return -NF_ACCEPT;
-       }
-
-       inip6off = icmp6off + sizeof(_hdr);
-       if (skb_copy_bits(skb, inip6off+offsetof(struct ipv6hdr, nexthdr),
-                         &inprotonum, sizeof(inprotonum)) != 0) {
-               DEBUGP("icmpv6_error: Can't get nexthdr in inner IPv6 header.\n");
-               return -NF_ACCEPT;
-       }
-       inprotoff = nf_ct_ipv6_skip_exthdr(skb,
-                                          inip6off + sizeof(struct ipv6hdr),
-                                          &inprotonum,
-                                          skb->len - inip6off
-                                                   - sizeof(struct ipv6hdr));
-
-       if ((inprotoff < 0) || (inprotoff > skb->len) ||
-           (inprotonum == NEXTHDR_FRAGMENT)) {
-               DEBUGP("icmpv6_error: Can't get protocol header in ICMPv6 payload.\n");
-               return -NF_ACCEPT;
-       }
-
-       inproto = __nf_ct_l4proto_find(PF_INET6, inprotonum);
-
        /* Are they talking about one of our connections? */
-       if (!nf_ct_get_tuple(skb, inip6off, inprotoff, PF_INET6, inprotonum,
-                            &origtuple, &nf_conntrack_l3proto_ipv6, inproto)) {
-               DEBUGP("icmpv6_error: Can't get tuple\n");
+       if (!nf_ct_get_tuplepr(skb,
+                              skb_network_offset(skb)
+                               + sizeof(struct ipv6hdr)
+                               + sizeof(struct icmp6hdr),
+                              PF_INET6, &origtuple)) {
+               pr_debug("icmpv6_error: Can't get tuple\n");
                return -NF_ACCEPT;
        }
 
+       /* rcu_read_lock()ed by nf_hook_slow */
+       inproto = __nf_ct_l4proto_find(PF_INET6, origtuple.dst.protonum);
+
        /* Ordinarily, we'd expect the inverted tupleproto, but it's
           been preserved inside the ICMP. */
        if (!nf_ct_invert_tuple(&intuple, &origtuple,
                                &nf_conntrack_l3proto_ipv6, inproto)) {
-               DEBUGP("icmpv6_error: Can't invert tuple\n");
+               pr_debug("icmpv6_error: Can't invert tuple\n");
                return -NF_ACCEPT;
        }
 
        *ctinfo = IP_CT_RELATED;
 
-       h = nf_conntrack_find_get(&intuple, NULL);
+       h = nf_conntrack_find_get(&intuple);
        if (!h) {
-               DEBUGP("icmpv6_error: no match\n");
+               pr_debug("icmpv6_error: no match\n");
                return -NF_ACCEPT;
        } else {
                if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY)
@@ -244,8 +206,7 @@ icmpv6_error(struct sk_buff *skb, unsigned int dataoff,
        return icmpv6_error_message(skb, dataoff, ctinfo, hooknum);
 }
 
-#if defined(CONFIG_NF_CT_NETLINK) || \
-    defined(CONFIG_NF_CT_NETLINK_MODULE)
+#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
 
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nfnetlink_conntrack.h>
@@ -327,8 +288,7 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
        .packet                 = icmpv6_packet,
        .new                    = icmpv6_new,
        .error                  = icmpv6_error,
-#if defined(CONFIG_NF_CT_NETLINK) || \
-    defined(CONFIG_NF_CT_NETLINK_MODULE)
+#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
        .tuple_to_nfattr        = icmpv6_tuple_to_nfattr,
        .nfattr_to_tuple        = icmpv6_nfattr_to_tuple,
 #endif