[SK_BUFF]: Introduce skb_set_transport_header
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 13 Mar 2007 16:51:52 +0000 (13:51 -0300)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:25:17 +0000 (22:25 -0700)
For the cases where the transport header is being set to a offset from
skb->data.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
include/linux/skbuff.h
net/ax25/af_ax25.c
net/ax25/ax25_in.c
net/ipv4/esp4.c
net/ipv4/ip_output.c
net/ipv4/tcp_input.c
net/ipv6/ah6.c
net/ipv6/esp6.c
net/ipv6/netfilter/nf_conntrack_reasm.c
net/ipv6/xfrm6_mode_beet.c
net/ipv6/xfrm6_mode_ro.c
net/ipv6/xfrm6_mode_transport.c

index 64c3c1687e49e6c43b67d2c234d2209fde303e50..684292efa823fb8f189ba2a2fc2e0df5bd5bc7f8 100644 (file)
@@ -962,6 +962,12 @@ static inline void skb_reset_transport_header(struct sk_buff *skb)
        skb->h.raw = skb->data;
 }
 
+static inline void skb_set_transport_header(struct sk_buff *skb,
+                                           const int offset)
+{
+       skb->h.raw = skb->data + offset;
+}
+
 static inline int skb_transport_offset(const struct sk_buff *skb)
 {
        return skb->h.raw - skb->data;
index 14db01a4ff631ce255e7d6c5bcbea9fb0bef27c8..75d4d695edecb7fbf1a1b29fa02d06b0a555c140 100644 (file)
@@ -1425,7 +1425,6 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
        struct sockaddr_ax25 sax;
        struct sk_buff *skb;
        ax25_digi dtmp, *dp;
-       unsigned char *asmptr;
        ax25_cb *ax25;
        size_t size;
        int lv, err, addr_len = msg->msg_namelen;
@@ -1551,10 +1550,8 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
        skb_reset_network_header(skb);
 
        /* Add the PID if one is not supplied by the user in the skb */
-       if (!ax25->pidincl) {
-               asmptr  = skb_push(skb, 1);
-               *asmptr = sk->sk_protocol;
-       }
+       if (!ax25->pidincl)
+               *skb_push(skb, 1) = sk->sk_protocol;
 
        SOCK_DEBUG(sk, "AX.25: Transmitting buffer\n");
 
@@ -1573,7 +1570,7 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
                goto out;
        }
 
-       asmptr = skb_push(skb, 1 + ax25_addr_size(dp));
+       skb_push(skb, 1 + ax25_addr_size(dp));
 
        SOCK_DEBUG(sk, "Building AX.25 Header (dp=%p).\n", dp);
 
@@ -1581,17 +1578,16 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
                SOCK_DEBUG(sk, "Num digipeaters=%d\n", dp->ndigi);
 
        /* Build an AX.25 header */
-       asmptr += (lv = ax25_addr_build(asmptr, &ax25->source_addr,
-                                       &sax.sax25_call, dp,
-                                       AX25_COMMAND, AX25_MODULUS));
+       lv = ax25_addr_build(skb->data, &ax25->source_addr, &sax.sax25_call,
+                            dp, AX25_COMMAND, AX25_MODULUS);
 
        SOCK_DEBUG(sk, "Built header (%d bytes)\n",lv);
 
-       skb->h.raw = asmptr;
+       skb_set_transport_header(skb, lv);
 
-       SOCK_DEBUG(sk, "base=%p pos=%p\n", skb->data, asmptr);
+       SOCK_DEBUG(sk, "base=%p pos=%p\n", skb->data, skb->h.raw);
 
-       *asmptr = AX25_UI;
+       *skb->h.raw = AX25_UI;
 
        /* Datagram frames go straight out of the door as UI */
        ax25_queue_xmit(skb, ax25->ax25_dev->dev);
index 724ad5ce75d45f223b0b630eef318b9ade9f374b..31c59387a6fca0095246054b9fe4188feb56480c 100644 (file)
@@ -233,7 +233,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
 
        /* UI frame - bypass LAPB processing */
        if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) {
-               skb->h.raw = skb->data + 2;             /* skip control and pid */
+               skb_set_transport_header(skb, 2); /* skip control and pid */
 
                ax25_send_to_raw(&dest, skb, skb->data[1]);
 
index 957674562801028d2ffa844c334a4e291a7e932b..82543eebfa52f93696d9c564a9e16033a76d131e 100644 (file)
@@ -261,7 +261,8 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
 
        iph->protocol = nexthdr[1];
        pskb_trim(skb, skb->len - alen - padlen - 2);
-       skb->h.raw = __skb_pull(skb, sizeof(*esph) + esp->conf.ivlen) - ihl;
+       __skb_pull(skb, sizeof(*esph) + esp->conf.ivlen);
+       skb_set_transport_header(skb, -ihl);
 
        return 0;
 
index 63c05be0764d4f678630b6ac981a0b5024bc46f4..6d92358fc51343c8b23e4fbe31e9f14f090e2e98 100644 (file)
@@ -593,7 +593,7 @@ slow_path:
                skb_reserve(skb2, ll_rs);
                skb_put(skb2, len + hlen);
                skb_reset_network_header(skb2);
-               skb2->h.raw = skb2->data + hlen;
+               skb2->h.raw = skb2->nh.raw + hlen;
 
                /*
                 *      Charge the memory for the fragment to any owner
@@ -724,7 +724,7 @@ static inline int ip_ufo_append_data(struct sock *sk,
                skb_reset_network_header(skb);
 
                /* initialize protocol header pointer */
-               skb->h.raw = skb->data + fragheaderlen;
+               skb->h.raw = skb->nh.raw + fragheaderlen;
 
                skb->ip_summed = CHECKSUM_PARTIAL;
                skb->csum = 0;
@@ -1099,8 +1099,6 @@ ssize_t   ip_append_page(struct sock *sk, struct page *page,
                }
                if (len <= 0) {
                        struct sk_buff *skb_prev;
-                       char *data;
-                       struct iphdr *iph;
                        int alloclen;
 
                        skb_prev = skb;
@@ -1123,16 +1121,15 @@ ssize_t ip_append_page(struct sock *sk, struct page *page,
                        /*
                         *      Find where to start putting bytes.
                         */
-                       data = skb_put(skb, fragheaderlen + fraggap);
+                       skb_put(skb, fragheaderlen + fraggap);
                        skb_reset_network_header(skb);
-                       iph = ip_hdr(skb);
-                       data += fragheaderlen;
-                       skb->h.raw = data;
+                       skb->h.raw = skb->nh.raw + fragheaderlen;
 
                        if (fraggap) {
-                               skb->csum = skb_copy_and_csum_bits(
-                                       skb_prev, maxfraglen,
-                                       data, fraggap, 0);
+                               skb->csum = skb_copy_and_csum_bits(skb_prev,
+                                                                  maxfraglen,
+                                                                  skb->h.raw,
+                                                                  fraggap, 0);
                                skb_prev->csum = csum_sub(skb_prev->csum,
                                                          skb->csum);
                                pskb_trim_unique(skb_prev, maxfraglen);
index 5da823a322508c7002a52928d1aa9de7036c9856..2776a8b013396e5f443897a59a4c427a8396e120 100644 (file)
@@ -3636,7 +3636,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list,
                skb_set_mac_header(nskb, skb_mac_header(skb) - skb->head);
                skb_set_network_header(nskb,
                                       skb_network_header(skb) - skb->head);
-               nskb->h.raw = nskb->data + (skb->h.raw - skb->head);
+               skb_set_transport_header(nskb, skb->h.raw - skb->head);
 
                skb_reserve(nskb, header);
                memcpy(nskb->head, skb->head, header);
index b682d2368c2a5154e48eedb017ee8a3400590cb5..e5ee981d3e10a8e80fac479a4975afbab57f4946 100644 (file)
@@ -247,7 +247,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
        memcpy(tmp_base, top_iph, sizeof(tmp_base));
 
        tmp_ext = NULL;
-       extlen = skb->h.raw - (unsigned char *)(top_iph + 1);
+       extlen = skb_transport_offset(skb) + sizeof(struct ipv6hdr);
        if (extlen) {
                extlen += sizeof(*tmp_ext);
                tmp_ext = kmalloc(extlen, GFP_ATOMIC);
index 35905867ded161b46b88a67a0523de6c0daf0e7b..ad522b7b5771ab435d1330726c082b7193228879 100644 (file)
@@ -228,8 +228,8 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
                ret = nexthdr[1];
        }
 
-       skb->h.raw = __skb_pull(skb, sizeof(*esph) + esp->conf.ivlen) - hdr_len;
-
+       __skb_pull(skb, sizeof(*esph) + esp->conf.ivlen);
+       skb_set_transport_header(skb, -hdr_len);
 out:
        return ret;
 }
index 75138cf1fa61b3a77c656a2a669e49e67b9075e4..015950522c8bb01750ebfd789cfb9ca29fbb998d 100644 (file)
@@ -785,7 +785,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
                goto ret_orig;
        }
 
-       clone->h.raw = clone->data + fhoff;
+       skb_set_transport_header(clone, fhoff);
        hdr = ipv6_hdr(clone);
        fhdr = (struct frag_hdr *)clone->h.raw;
 
index b5a48c255f074a54b90cfe27878c9366cc56bcb1..abac09409ded7d6ba5449b5b9b456ff280552735 100644 (file)
@@ -42,7 +42,7 @@ static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
 
        hdr_len = ip6_find_1stfragopt(skb, &prevhdr);
        skb->nh.raw = prevhdr - x->props.header_len;
-       skb->h.raw = skb->data + hdr_len;
+       skb_set_transport_header(skb, hdr_len);
        memmove(skb->data, iph, hdr_len);
 
        skb_reset_network_header(skb);
index d01958d921ac1012be1393e7b8242601b47e6535..da48ecf3fe96504d302ce7838bc25f63fd78a0cc 100644 (file)
@@ -54,7 +54,7 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
 
        hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
        skb->nh.raw = prevhdr - x->props.header_len;
-       skb->h.raw = skb->data + hdr_len;
+       skb_set_transport_header(skb, hdr_len);
        memmove(skb->data, iph, hdr_len);
        return 0;
 }
index cae6cacd58c4a45b0b0fbd2b81b7882bb4287555..0134d74ef087fdfde24e5c58c5bf0d3d9bc4a3dd 100644 (file)
@@ -36,7 +36,7 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
 
        hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
        skb->nh.raw = prevhdr - x->props.header_len;
-       skb->h.raw = skb->data + hdr_len;
+       skb_set_transport_header(skb, hdr_len);
        memmove(skb->data, iph, hdr_len);
        return 0;
 }