[NETFILTER]: Introduce NF_INET_ hook values
[safe/jmp/linux-2.6] / net / ipv6 / netfilter / nf_conntrack_proto_icmpv6.c
index 8814b95..e99384f 100644 (file)
 
 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)
@@ -125,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;
        }
@@ -142,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 > skb->len) || (inprotonum == NEXTHDR_FRAGMENT)) {
-               DEBUGP("icmpv6_error: Can't get protocol header in ICMPv6 payload.\n");
+       /* Are they talking about one of our connections? */
+       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, 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");
-               return -NF_ACCEPT;
-       }
+       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)
@@ -222,7 +192,7 @@ icmpv6_error(struct sk_buff *skb, unsigned int dataoff,
                return -NF_ACCEPT;
        }
 
-       if (nf_conntrack_checksum && hooknum == NF_IP6_PRE_ROUTING &&
+       if (nf_conntrack_checksum && hooknum == NF_INET_PRE_ROUTING &&
            nf_ip6_checksum(skb, hooknum, dataoff, IPPROTO_ICMPV6)) {
                nf_log_packet(PF_INET6, 0, skb, NULL, NULL, NULL,
                              "nf_ct_icmpv6: ICMPv6 checksum failed\n");
@@ -240,45 +210,42 @@ icmpv6_error(struct sk_buff *skb, unsigned int dataoff,
 
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nfnetlink_conntrack.h>
-static int icmpv6_tuple_to_nfattr(struct sk_buff *skb,
+static int icmpv6_tuple_to_nlattr(struct sk_buff *skb,
                                  const struct nf_conntrack_tuple *t)
 {
-       NFA_PUT(skb, CTA_PROTO_ICMPV6_ID, sizeof(u_int16_t),
+       NLA_PUT(skb, CTA_PROTO_ICMPV6_ID, sizeof(u_int16_t),
                &t->src.u.icmp.id);
-       NFA_PUT(skb, CTA_PROTO_ICMPV6_TYPE, sizeof(u_int8_t),
+       NLA_PUT(skb, CTA_PROTO_ICMPV6_TYPE, sizeof(u_int8_t),
                &t->dst.u.icmp.type);
-       NFA_PUT(skb, CTA_PROTO_ICMPV6_CODE, sizeof(u_int8_t),
+       NLA_PUT(skb, CTA_PROTO_ICMPV6_CODE, sizeof(u_int8_t),
                &t->dst.u.icmp.code);
 
        return 0;
 
-nfattr_failure:
+nla_put_failure:
        return -1;
 }
 
-static const size_t cta_min_proto[CTA_PROTO_MAX] = {
-       [CTA_PROTO_ICMPV6_TYPE-1] = sizeof(u_int8_t),
-       [CTA_PROTO_ICMPV6_CODE-1] = sizeof(u_int8_t),
-       [CTA_PROTO_ICMPV6_ID-1]   = sizeof(u_int16_t)
+static const struct nla_policy icmpv6_nla_policy[CTA_PROTO_MAX+1] = {
+       [CTA_PROTO_ICMPV6_TYPE] = { .type = NLA_U8 },
+       [CTA_PROTO_ICMPV6_CODE] = { .type = NLA_U8 },
+       [CTA_PROTO_ICMPV6_ID]   = { .type = NLA_U16 },
 };
 
-static int icmpv6_nfattr_to_tuple(struct nfattr *tb[],
+static int icmpv6_nlattr_to_tuple(struct nlattr *tb[],
                                struct nf_conntrack_tuple *tuple)
 {
-       if (!tb[CTA_PROTO_ICMPV6_TYPE-1]
-           || !tb[CTA_PROTO_ICMPV6_CODE-1]
-           || !tb[CTA_PROTO_ICMPV6_ID-1])
-               return -EINVAL;
-
-       if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
+       if (!tb[CTA_PROTO_ICMPV6_TYPE]
+           || !tb[CTA_PROTO_ICMPV6_CODE]
+           || !tb[CTA_PROTO_ICMPV6_ID])
                return -EINVAL;
 
        tuple->dst.u.icmp.type =
-                       *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMPV6_TYPE-1]);
+                       *(u_int8_t *)nla_data(tb[CTA_PROTO_ICMPV6_TYPE]);
        tuple->dst.u.icmp.code =
-                       *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMPV6_CODE-1]);
+                       *(u_int8_t *)nla_data(tb[CTA_PROTO_ICMPV6_CODE]);
        tuple->src.u.icmp.id =
-                       *(__be16 *)NFA_DATA(tb[CTA_PROTO_ICMPV6_ID-1]);
+                       *(__be16 *)nla_data(tb[CTA_PROTO_ICMPV6_ID]);
 
        if (tuple->dst.u.icmp.type < 128
            || tuple->dst.u.icmp.type - 128 >= sizeof(invmap)
@@ -293,7 +260,6 @@ static int icmpv6_nfattr_to_tuple(struct nfattr *tb[],
 static struct ctl_table_header *icmpv6_sysctl_header;
 static struct ctl_table icmpv6_sysctl_table[] = {
        {
-               .ctl_name       = NET_NF_CONNTRACK_ICMPV6_TIMEOUT,
                .procname       = "nf_conntrack_icmpv6_timeout",
                .data           = &nf_ct_icmpv6_timeout,
                .maxlen         = sizeof(unsigned int),
@@ -306,7 +272,7 @@ static struct ctl_table icmpv6_sysctl_table[] = {
 };
 #endif /* CONFIG_SYSCTL */
 
-struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
+struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly =
 {
        .l3proto                = PF_INET6,
        .l4proto                = IPPROTO_ICMPV6,
@@ -319,13 +285,12 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
        .new                    = icmpv6_new,
        .error                  = icmpv6_error,
 #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,
+       .tuple_to_nlattr        = icmpv6_tuple_to_nlattr,
+       .nlattr_to_tuple        = icmpv6_nlattr_to_tuple,
+       .nla_policy             = icmpv6_nla_policy,
 #endif
 #ifdef CONFIG_SYSCTL
        .ctl_table_header       = &icmpv6_sysctl_header,
        .ctl_table              = icmpv6_sysctl_table,
 #endif
 };
-
-EXPORT_SYMBOL(nf_conntrack_l4proto_icmpv6);