]> err.no Git - linux-2.6/blobdiff - net/ipv6/netfilter/nf_conntrack_reasm.c
[8021Q]: vlan_ioctl_handler: fix return value
[linux-2.6] / net / ipv6 / netfilter / nf_conntrack_reasm.c
index 15ab1e3e8b564143f3a9166f97463cacdb2a27f2..25442a8c1ba82fec69f40226f31487d4b4adfddb 100644 (file)
 #include <linux/kernel.h>
 #include <linux/module.h>
 
-#if 0
-#define DEBUGP printk
-#else
-#define DEBUGP(format, args...)
-#endif
-
 #define NF_CT_FRAG6_HIGH_THRESH 262144 /* == 256*1024 */
 #define NF_CT_FRAG6_LOW_THRESH 196608  /* == 192*1024 */
 #define NF_CT_FRAG6_TIMEOUT IPV6_FRAG_TIMEOUT
@@ -82,7 +76,7 @@ struct nf_ct_frag6_queue
        struct sk_buff          *fragments;
        int                     len;
        int                     meat;
-       struct timeval          stamp;
+       ktime_t                 stamp;
        unsigned int            csum;
        __u8                    last_in;        /* has first/last segment arrived? */
 #define COMPLETE               4
@@ -343,7 +337,7 @@ nf_ct_frag6_create(unsigned int hash, __be32 id, struct in6_addr *src,                                 str
        struct nf_ct_frag6_queue *fq;
 
        if ((fq = frag_alloc_queue()) == NULL) {
-               DEBUGP("Can't alloc new queue\n");
+               pr_debug("Can't alloc new queue\n");
                goto oom;
        }
 
@@ -353,9 +347,7 @@ nf_ct_frag6_create(unsigned int hash, __be32 id, struct in6_addr *src,                                 str
        ipv6_addr_copy(&fq->saddr, src);
        ipv6_addr_copy(&fq->daddr, dst);
 
-       init_timer(&fq->timer);
-       fq->timer.function = nf_ct_frag6_expire;
-       fq->timer.data = (long) fq;
+       setup_timer(&fq->timer, nf_ct_frag6_expire, (unsigned long)fq);
        spin_lock_init(&fq->lock);
        atomic_set(&fq->refcnt, 1);
 
@@ -395,24 +387,25 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
        int offset, end;
 
        if (fq->last_in & COMPLETE) {
-               DEBUGP("Allready completed\n");
+               pr_debug("Allready completed\n");
                goto err;
        }
 
        offset = ntohs(fhdr->frag_off) & ~0x7;
-       end = offset + (ntohs(skb->nh.ipv6h->payload_len) -
-                       ((u8 *) (fhdr + 1) - (u8 *) (skb->nh.ipv6h + 1)));
+       end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
+                       ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
 
        if ((unsigned int)end > IPV6_MAXPLEN) {
-               DEBUGP("offset is too large.\n");
+               pr_debug("offset is too large.\n");
                return -1;
        }
 
-       if (skb->ip_summed == CHECKSUM_COMPLETE)
+       if (skb->ip_summed == CHECKSUM_COMPLETE) {
+               const unsigned char *nh = skb_network_header(skb);
                skb->csum = csum_sub(skb->csum,
-                                    csum_partial(skb->nh.raw,
-                                                 (u8*)(fhdr + 1) - skb->nh.raw,
+                                    csum_partial(nh, (u8 *)(fhdr + 1) - nh,
                                                  0));
+       }
 
        /* Is this the final fragment? */
        if (!(fhdr->frag_off & htons(IP6_MF))) {
@@ -421,7 +414,7 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
                 */
                if (end < fq->len ||
                    ((fq->last_in & LAST_IN) && end != fq->len)) {
-                       DEBUGP("already received last fragment\n");
+                       pr_debug("already received last fragment\n");
                        goto err;
                }
                fq->last_in |= LAST_IN;
@@ -434,13 +427,13 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
                        /* RFC2460 says always send parameter problem in
                         * this case. -DaveM
                         */
-                       DEBUGP("the end of this fragment is not rounded to 8 bytes.\n");
+                       pr_debug("end of fragment not rounded to 8 bytes.\n");
                        return -1;
                }
                if (end > fq->len) {
                        /* Some bits beyond end -> corruption. */
                        if (fq->last_in & LAST_IN) {
-                               DEBUGP("last packet already reached.\n");
+                               pr_debug("last packet already reached.\n");
                                goto err;
                        }
                        fq->len = end;
@@ -452,11 +445,11 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
 
        /* Point into the IP datagram 'data' part. */
        if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) {
-               DEBUGP("queue: message is too short.\n");
+               pr_debug("queue: message is too short.\n");
                goto err;
        }
        if (pskb_trim_rcsum(skb, end - offset)) {
-               DEBUGP("Can't trim\n");
+               pr_debug("Can't trim\n");
                goto err;
        }
 
@@ -481,11 +474,11 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
                if (i > 0) {
                        offset += i;
                        if (end <= offset) {
-                               DEBUGP("overlap\n");
+                               pr_debug("overlap\n");
                                goto err;
                        }
                        if (!pskb_pull(skb, i)) {
-                               DEBUGP("Can't pull\n");
+                               pr_debug("Can't pull\n");
                                goto err;
                        }
                        if (skb->ip_summed != CHECKSUM_UNNECESSARY)
@@ -504,7 +497,7 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
                        /* Eat head of the next overlapped fragment
                         * and leave the loop. The next ones cannot overlap.
                         */
-                       DEBUGP("Eat head of the overlapped parts.: %d", i);
+                       pr_debug("Eat head of the overlapped parts.: %d", i);
                        if (!pskb_pull(next, i))
                                goto err;
 
@@ -542,7 +535,7 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
                fq->fragments = skb;
 
        skb->dev = NULL;
-       skb_get_timestamp(skb, &fq->stamp);
+       fq->stamp = skb->tstamp;
        fq->meat += skb->len;
        atomic_add(skb->truesize, &nf_ct_frag6_mem);
 
@@ -583,15 +576,17 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
        BUG_TRAP(NFCT_FRAG6_CB(head)->offset == 0);
 
        /* Unfragmented part is taken from the first segment. */
-       payload_len = (head->data - head->nh.raw) - sizeof(struct ipv6hdr) + fq->len - sizeof(struct frag_hdr);
+       payload_len = ((head->data - skb_network_header(head)) -
+                      sizeof(struct ipv6hdr) + fq->len -
+                      sizeof(struct frag_hdr));
        if (payload_len > IPV6_MAXPLEN) {
-               DEBUGP("payload len is too large.\n");
+               pr_debug("payload len is too large.\n");
                goto out_oversize;
        }
 
        /* Head of list must not be cloned. */
        if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) {
-               DEBUGP("skb is cloned but can't expand head");
+               pr_debug("skb is cloned but can't expand head");
                goto out_oom;
        }
 
@@ -603,7 +598,7 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
                int i, plen = 0;
 
                if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL) {
-                       DEBUGP("Can't alloc skb\n");
+                       pr_debug("Can't alloc skb\n");
                        goto out_oom;
                }
                clone->next = head->next;
@@ -624,15 +619,15 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
 
        /* We have to remove fragment header from datagram and to relocate
         * header in order to calculate ICV correctly. */
-       head->nh.raw[fq->nhoffset] = head->h.raw[0];
+       skb_network_header(head)[fq->nhoffset] = skb_transport_header(head)[0];
        memmove(head->head + sizeof(struct frag_hdr), head->head,
                (head->data - head->head) - sizeof(struct frag_hdr));
-       head->mac.raw += sizeof(struct frag_hdr);
-       head->nh.raw += sizeof(struct frag_hdr);
+       head->mac_header += sizeof(struct frag_hdr);
+       head->network_header += sizeof(struct frag_hdr);
 
        skb_shinfo(head)->frag_list = head->next;
-       head->h.raw = head->data;
-       skb_push(head, head->data - head->nh.raw);
+       skb_reset_transport_header(head);
+       skb_push(head, head->data - skb_network_header(head));
        atomic_sub(head->truesize, &nf_ct_frag6_mem);
 
        for (fp=head->next; fp; fp = fp->next) {
@@ -648,12 +643,14 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
 
        head->next = NULL;
        head->dev = dev;
-       skb_set_timestamp(head, &fq->stamp);
-       head->nh.ipv6h->payload_len = htons(payload_len);
+       head->tstamp = fq->stamp;
+       ipv6_hdr(head)->payload_len = htons(payload_len);
 
        /* Yes, and fold redundant checksum back. 8) */
        if (head->ip_summed == CHECKSUM_COMPLETE)
-               head->csum = csum_partial(head->nh.raw, head->h.raw-head->nh.raw, head->csum);
+               head->csum = csum_partial(skb_network_header(head),
+                                         skb_network_header_len(head),
+                                         head->csum);
 
        fq->fragments = NULL;
 
@@ -701,9 +698,10 @@ out_fail:
 static int
 find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
 {
-       u8 nexthdr = skb->nh.ipv6h->nexthdr;
-       u8 prev_nhoff = (u8 *)&skb->nh.ipv6h->nexthdr - skb->data;
-       int start = (u8 *)(skb->nh.ipv6h+1) - skb->data;
+       u8 nexthdr = ipv6_hdr(skb)->nexthdr;
+       const int netoff = skb_network_offset(skb);
+       u8 prev_nhoff = netoff + offsetof(struct ipv6hdr, nexthdr);
+       int start = netoff + sizeof(struct ipv6hdr);
        int len = skb->len - start;
        u8 prevhdr = NEXTHDR_IPV6;
 
@@ -715,11 +713,11 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
                        return -1;
                }
                if (len < (int)sizeof(struct ipv6_opt_hdr)) {
-                       DEBUGP("too short\n");
+                       pr_debug("too short\n");
                        return -1;
                }
                if (nexthdr == NEXTHDR_NONE) {
-                       DEBUGP("next header is none\n");
+                       pr_debug("next header is none\n");
                        return -1;
                }
                if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
@@ -759,8 +757,8 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
        struct sk_buff *ret_skb = NULL;
 
        /* Jumbo payload inhibits frag. header */
-       if (skb->nh.ipv6h->payload_len == 0) {
-               DEBUGP("payload len = 0\n");
+       if (ipv6_hdr(skb)->payload_len == 0) {
+               pr_debug("payload len = 0\n");
                return skb;
        }
 
@@ -769,23 +767,23 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
 
        clone = skb_clone(skb, GFP_ATOMIC);
        if (clone == NULL) {
-               DEBUGP("Can't clone skb\n");
+               pr_debug("Can't clone skb\n");
                return skb;
        }
 
        NFCT_FRAG6_CB(clone)->orig = skb;
 
        if (!pskb_may_pull(clone, fhoff + sizeof(*fhdr))) {
-               DEBUGP("message is too short.\n");
+               pr_debug("message is too short.\n");
                goto ret_orig;
        }
 
-       clone->h.raw = clone->data + fhoff;
-       hdr = clone->nh.ipv6h;
-       fhdr = (struct frag_hdr *)clone->h.raw;
+       skb_set_transport_header(clone, fhoff);
+       hdr = ipv6_hdr(clone);
+       fhdr = (struct frag_hdr *)skb_transport_header(clone);
 
        if (!(fhdr->frag_off & htons(0xFFF9))) {
-               DEBUGP("Invalid fragment offset\n");
+               pr_debug("Invalid fragment offset\n");
                /* It is not a fragmented frame */
                goto ret_orig;
        }
@@ -795,7 +793,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
 
        fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr);
        if (fq == NULL) {
-               DEBUGP("Can't find and can't create new queue\n");
+               pr_debug("Can't find and can't create new queue\n");
                goto ret_orig;
        }
 
@@ -803,7 +801,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
 
        if (nf_ct_frag6_queue(fq, clone, fhdr, nhoff) < 0) {
                spin_unlock(&fq->lock);
-               DEBUGP("Can't insert skb to queue\n");
+               pr_debug("Can't insert skb to queue\n");
                fq_put(fq, NULL);
                goto ret_orig;
        }
@@ -811,7 +809,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
        if (fq->last_in == (FIRST_IN|LAST_IN) && fq->meat == fq->len) {
                ret_skb = nf_ct_frag6_reasm(fq, dev);
                if (ret_skb == NULL)
-                       DEBUGP("Can't reassemble fragmented packets\n");
+                       pr_debug("Can't reassemble fragmented packets\n");
        }
        spin_unlock(&fq->lock);
 
@@ -864,8 +862,7 @@ int nf_ct_frag6_init(void)
        nf_ct_frag6_hash_rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
                                   (jiffies ^ (jiffies >> 6)));
 
-       init_timer(&nf_ct_frag6_secret_timer);
-       nf_ct_frag6_secret_timer.function = nf_ct_frag6_secret_rebuild;
+       setup_timer(&nf_ct_frag6_secret_timer, nf_ct_frag6_secret_rebuild, 0);
        nf_ct_frag6_secret_timer.expires = jiffies
                                           + nf_ct_frag6_secret_interval;
        add_timer(&nf_ct_frag6_secret_timer);