]> Pileus Git - ~andy/linux/blobdiff - net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
[NETFILTER]: nfnetlink: convert to generic netlink attribute functions
[~andy/linux] / net / ipv6 / netfilter / nf_conntrack_proto_icmpv6.c
index 9defc7e14554b4cc431deb5223764cb8a4deebe2..c18183823faffe9fbbfe5ecdf7c01e4cf67c69a4 100644 (file)
@@ -136,49 +136,23 @@ 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) {
-               pr_debug("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) {
-               pr_debug("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)) {
-               pr_debug("icmpv6_error: Can't get protocol header in ICMPv6 "
-                        "payload.\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)) {
+       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,
@@ -239,42 +213,42 @@ icmpv6_error(struct sk_buff *skb, unsigned int dataoff,
 static int icmpv6_tuple_to_nfattr(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 size_t cta_min_proto[CTA_PROTO_MAX+1] = {
+       [CTA_PROTO_ICMPV6_TYPE] = sizeof(u_int8_t),
+       [CTA_PROTO_ICMPV6_CODE] = sizeof(u_int8_t),
+       [CTA_PROTO_ICMPV6_ID]   = sizeof(u_int16_t)
 };
 
-static int icmpv6_nfattr_to_tuple(struct nfattr *tb[],
+static int icmpv6_nfattr_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])
+       if (!tb[CTA_PROTO_ICMPV6_TYPE]
+           || !tb[CTA_PROTO_ICMPV6_CODE]
+           || !tb[CTA_PROTO_ICMPV6_ID])
                return -EINVAL;
 
        if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
                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)
@@ -302,7 +276,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,
@@ -323,5 +297,3 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
        .ctl_table              = icmpv6_sysctl_table,
 #endif
 };
-
-EXPORT_SYMBOL(nf_conntrack_l4proto_icmpv6);