]> err.no Git - linux-2.6/commitdiff
[SK_BUFF]: Introduce skb_network_offset()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 11 Mar 2007 01:16:10 +0000 (22:16 -0300)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:24:58 +0000 (22:24 -0700)
For the quite common 'skb->nh.raw - skb->data' sequence.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
18 files changed:
drivers/isdn/i4l/isdn_net.c
drivers/net/atl1/atl1_main.c
drivers/net/chelsio/sge.c
drivers/net/cxgb3/sge.c
drivers/net/e1000/e1000_main.c
drivers/net/gianfar.c
drivers/net/ixgb/ixgb_main.c
drivers/net/netxen/netxen_nic_hw.c
include/linux/skbuff.h
net/ax25/ax25_out.c
net/core/neighbour.c
net/ipv4/ip_output.c
net/ipv6/icmp.c
net/ipv6/ip6_output.c
net/netfilter/nf_conntrack_core.c
net/packet/af_packet.c
net/sched/sch_teql.c
security/selinux/hooks.c

index fadb9291bc1b76c6796e91266549eb4d8febb65b..0c2b3752e46eaf15d276be9b9c17b3d195377892 100644 (file)
@@ -1121,7 +1121,7 @@ isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
        if (!skb)
                return;
        if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
-               int pullsize = (ulong)skb->nh.raw - (ulong)skb->data - ETH_HLEN;
+               const int pullsize = skb_network_offset(skb) - ETH_HLEN;
                if (pullsize > 0) {
                        printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
                        skb_pull(skb, pullsize);
index e3f181602e4faf8e6f09b11896a8828e2ce00761..793a61b2140f4eeff6cc8269ba17fc6c39a2598d 100644 (file)
@@ -1300,7 +1300,7 @@ static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb,
                            ~csum_tcpudp_magic(skb->nh.iph->saddr,
                                               skb->nh.iph->daddr, 0,
                                               IPPROTO_TCP, 0);
-                       ipofst = skb->nh.raw - skb->data;
+                       ipofst = skb_network_offset(skb);
                        if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */
                                tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT;
 
index 47fa8dcf7527a4288eedd9acb1844dc707946b30..8cdee67d582f256aa58dbb815e24b7a99ee9c69a 100644 (file)
@@ -1865,7 +1865,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
                ++st->tx_tso;
 
-               eth_type = skb->nh.raw - skb->data == ETH_HLEN ?
+               eth_type = skb_network_offset(skb) == ETH_HLEN ?
                        CPL_ETH_II : CPL_ETH_II_VLAN;
 
                hdr = (struct cpl_tx_pkt_lso *)skb_push(skb, sizeof(*hdr));
index 4dd712088bcf930850f44def47dbf29c6772946b..7e9e9db4fb978aa6b710e3ab41f3f9a8e2015585 100644 (file)
@@ -897,7 +897,7 @@ static void write_tx_pkt_wr(struct adapter *adap, struct sk_buff *skb,
                d->flit[2] = 0;
                cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT_LSO);
                hdr->cntrl = htonl(cntrl);
-               eth_type = skb->nh.raw - skb->data == ETH_HLEN ?
+               eth_type = skb_network_offset(skb) == ETH_HLEN ?
                    CPL_ETH_II : CPL_ETH_II_VLAN;
                tso_info |= V_LSO_ETH_TYPE(eth_type) |
                    V_LSO_IPHDR_WORDS(skb->nh.iph->ihl) |
index b28a915bd980983738fe30180c57c1c5956a01a0..86161011b53964b0c962e6ebc36013de9a08aca1 100644 (file)
@@ -2910,7 +2910,7 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                                                 0);
                        ipcse = 0;
                }
-               ipcss = skb->nh.raw - skb->data;
+               ipcss = skb_network_offset(skb);
                ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
                tucss = skb->h.raw - skb->data;
                tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
index 1d019195a3919869f43c2db7b51f5049338583d4..c7a70933c7594df11d6ee86ca29cc840adc49bad 100644 (file)
@@ -952,7 +952,7 @@ static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
         * frame (skb->data) and the start of the IP hdr.
         * l4os is the distance between the start of the
         * l3 hdr and the l4 hdr */
-       fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN);
+       fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN);
        fcb->l4os = (u16)(skb->h.raw - skb->nh.raw);
 
        fcb->flags = flags;
index afc2ec72529ee4ac22b76546dab7f3630d11aade..cfb791bb45e29218693191e7657f60800daf429e 100644 (file)
@@ -1195,7 +1195,7 @@ ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
                skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
                                                      skb->nh.iph->daddr,
                                                      0, IPPROTO_TCP, 0);
-               ipcss = skb->nh.raw - skb->data;
+               ipcss = skb_network_offset(skb);
                ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
                ipcse = skb->h.raw - skb->data - 1;
                tucss = skb->h.raw - skb->data;
index 6537574a9cda98fe2c059a088499f6404e98a768..625e11ed6aae565f725f9073cb2e0133e342dda5 100644 (file)
@@ -386,7 +386,7 @@ void netxen_tso_check(struct netxen_adapter *adapter,
        }
        adapter->stats.xmitcsummed++;
        desc->tcp_hdr_offset = skb->h.raw - skb->data;
-       desc->ip_hdr_offset = skb->nh.raw - skb->data;
+       desc->ip_hdr_offset = skb_network_offset(skb);
 }
 
 int netxen_is_flash_supported(struct netxen_adapter *adapter)
index 6440c78fe625ddee7363bdfc7bc66b57995ce64c..47cc8b07c2b4d4fa611393f32943eacf11b1076c 100644 (file)
@@ -965,6 +965,11 @@ static inline void skb_reset_network_header(struct sk_buff *skb)
        skb->nh.raw = skb->data;
 }
 
+static inline int skb_network_offset(const struct sk_buff *skb)
+{
+       return skb->nh.raw - skb->data;
+}
+
 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
 {
        return skb->mac.raw;
index 6e08dc8dee40492f20833a4597cc8f5ff8b771a6..02dea851a11a0f0aaffacdd908c2348305a136b7 100644 (file)
@@ -148,7 +148,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
 
                        if (ka9qfrag == 1) {
                                skb_reserve(skbn, frontlen + 2);
-                               skbn->nh.raw = skbn->data + (skb->nh.raw - skb->data);
+                               skbn->nh.raw = skbn->data + skb_network_offset(skb);
                                memcpy(skb_put(skbn, len), skb->data, len);
                                p = skb_push(skbn, 2);
 
@@ -161,7 +161,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
                                }
                        } else {
                                skb_reserve(skbn, frontlen + 1);
-                               skbn->nh.raw = skbn->data + (skb->nh.raw - skb->data);
+                               skbn->nh.raw = skbn->data + skb_network_offset(skb);
                                memcpy(skb_put(skbn, len), skb->data, len);
                                p = skb_push(skbn, 1);
                                *p = AX25_P_TEXT;
index 841e3f32cab181c51ec5d50605e3f7560add79ae..c5653c512b4319c34d221d5332ca40d23fe784d2 100644 (file)
@@ -1125,7 +1125,7 @@ int neigh_compat_output(struct sk_buff *skb)
 {
        struct net_device *dev = skb->dev;
 
-       __skb_pull(skb, skb->nh.raw - skb->data);
+       __skb_pull(skb, skb_network_offset(skb));
 
        if (dev->hard_header &&
            dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL,
@@ -1147,7 +1147,7 @@ int neigh_resolve_output(struct sk_buff *skb)
        if (!dst || !(neigh = dst->neighbour))
                goto discard;
 
-       __skb_pull(skb, skb->nh.raw - skb->data);
+       __skb_pull(skb, skb_network_offset(skb));
 
        if (!neigh_event_send(neigh, skb)) {
                int err;
@@ -1190,7 +1190,7 @@ int neigh_connected_output(struct sk_buff *skb)
        struct neighbour *neigh = dst->neighbour;
        struct net_device *dev = neigh->dev;
 
-       __skb_pull(skb, skb->nh.raw - skb->data);
+       __skb_pull(skb, skb_network_offset(skb));
 
        read_lock_bh(&neigh->lock);
        err = dev->hard_header(skb, dev, ntohs(skb->protocol),
index 99cd90c22310d76850a1dd9b9b09c2b99ca0bd71..669f5d97c6eb487f771c518e4c7c21c43e98d07b 100644 (file)
@@ -96,7 +96,7 @@ __inline__ void ip_send_check(struct iphdr *iph)
 static int ip_dev_loopback_xmit(struct sk_buff *newskb)
 {
        skb_reset_mac_header(newskb);
-       __skb_pull(newskb, newskb->nh.raw - newskb->data);
+       __skb_pull(newskb, skb_network_offset(newskb));
        newskb->pkt_type = PACKET_LOOPBACK;
        newskb->ip_summed = CHECKSUM_UNNECESSARY;
        BUG_TRAP(newskb->dst);
@@ -1199,7 +1199,7 @@ int ip_push_pending_frames(struct sock *sk)
 
        /* move skb->data to ip header from ext header */
        if (skb->data < skb->nh.raw)
-               __skb_pull(skb, skb->nh.raw - skb->data);
+               __skb_pull(skb, skb_network_offset(skb));
        while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
                __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
                *tail_skb = tmp_skb;
index a91dfbce8433dc9dde8513c494c37094bc566475..aa4a0a59ffacdbb975cc27f4723b5d0b2566986e 100644 (file)
@@ -206,7 +206,7 @@ static __inline__ int opt_unrec(struct sk_buff *skb, __u32 offset)
 {
        u8 _optval, *op;
 
-       offset += skb->nh.raw - skb->data;
+       offset += skb_network_offset(skb);
        op = skb_header_pointer(skb, offset, sizeof(_optval), &_optval);
        if (op == NULL)
                return 1;
@@ -431,7 +431,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
                tclass = 0;
 
        msg.skb = skb;
-       msg.offset = skb->nh.raw - skb->data;
+       msg.offset = skb_network_offset(skb);
        msg.type = type;
 
        len = skb->len - msg.offset;
index 8a7b5c760147e1564455d24f1448e84315f08432..47d00210cba17f8d3cb0ef38e270ff84891bca3a 100644 (file)
@@ -89,7 +89,7 @@ static inline int ip6_output_finish(struct sk_buff *skb)
 static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
 {
        skb_reset_mac_header(newskb);
-       __skb_pull(newskb, newskb->nh.raw - newskb->data);
+       __skb_pull(newskb, skb_network_offset(newskb));
        newskb->pkt_type = PACKET_LOOPBACK;
        newskb->ip_summed = CHECKSUM_UNNECESSARY;
        BUG_TRAP(newskb->dst);
@@ -1330,7 +1330,7 @@ int ip6_push_pending_frames(struct sock *sk)
 
        /* move skb->data to ip header from ext header */
        if (skb->data < skb->nh.raw)
-               __skb_pull(skb, skb->nh.raw - skb->data);
+               __skb_pull(skb, skb_network_offset(skb));
        while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
                __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
                *tail_skb = tmp_skb;
index b3a70eb6d42ae8728a5d8803ea230e9d27ecbb10..7694c51f125186c90b64fd2b009067b798b76810 100644 (file)
@@ -768,7 +768,7 @@ resolve_normal_ct(struct sk_buff *skb,
        struct nf_conntrack_tuple_hash *h;
        struct nf_conn *ct;
 
-       if (!nf_ct_get_tuple(skb, (unsigned int)(skb->nh.raw - skb->data),
+       if (!nf_ct_get_tuple(skb, skb_network_offset(skb),
                             dataoff, l3num, protonum, &tuple, l3proto,
                             l4proto)) {
                DEBUGP("resolve_normal_ct: Can't get tuple\n");
@@ -960,7 +960,7 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
        if (do_acct) {
                ct->counters[CTINFO2DIR(ctinfo)].packets++;
                ct->counters[CTINFO2DIR(ctinfo)].bytes +=
-                       skb->len - (unsigned int)(skb->nh.raw - skb->data);
+                       skb->len - skb_network_offset(skb);
 
                if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000)
                    || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000))
index 1225e751b3f174587197f689315a720d2b73db74..a059cc7be672f9b110ce62a29cd44d41d96c1189 100644 (file)
@@ -491,7 +491,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
                        skb_push(skb, skb->data - skb_mac_header(skb));
                else if (skb->pkt_type == PACKET_OUTGOING) {
                        /* Special case: outgoing packets have ll header at head */
-                       skb_pull(skb, skb->nh.raw - skb->data);
+                       skb_pull(skb, skb_network_offset(skb));
                }
        }
 
@@ -595,7 +595,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
                        skb_push(skb, skb->data - skb_mac_header(skb));
                else if (skb->pkt_type == PACKET_OUTGOING) {
                        /* Special case: outgoing packets have ll header at head */
-                       skb_pull(skb, skb->nh.raw - skb->data);
+                       skb_pull(skb, skb_network_offset(skb));
                }
        }
 
@@ -613,7 +613,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
        if (sk->sk_type == SOCK_DGRAM) {
                macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16;
        } else {
-               unsigned maclen = skb->nh.raw - skb->data;
+               unsigned maclen = skb_network_offset(skb);
                netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen));
                macoff = netoff - maclen;
        }
@@ -1145,7 +1145,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
                aux.tp_len = PACKET_SKB_CB(skb)->origlen;
                aux.tp_snaplen = skb->len;
                aux.tp_mac = 0;
-               aux.tp_net = skb->nh.raw - skb->data;
+               aux.tp_net = skb_network_offset(skb);
 
                put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
        }
index 587123c61af94b654460ef237f02d8e6f4059feb..d24914db786124d187fc53a546d2ab9c5ebac958 100644 (file)
@@ -323,7 +323,7 @@ restart:
                        nores = 1;
                        break;
                }
-               __skb_pull(skb, skb->nh.raw - skb->data);
+               __skb_pull(skb, skb_network_offset(skb));
        } while ((q = NEXT_SLAVE(q)) != start);
 
        if (nores && skb_res == NULL) {
index d41e24d6ae4109509cc065091901fe48fcd8c447..addb58501057b0e1268cf60552e851d912030898 100644 (file)
@@ -2944,7 +2944,7 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
        int offset, ihlen, ret = -EINVAL;
        struct iphdr _iph, *ih;
 
-       offset = skb->nh.raw - skb->data;
+       offset = skb_network_offset(skb);
        ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
        if (ih == NULL)
                goto out;
@@ -3026,7 +3026,7 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
        int ret = -EINVAL, offset;
        struct ipv6hdr _ipv6h, *ip6;
 
-       offset = skb->nh.raw - skb->data;
+       offset = skb_network_offset(skb);
        ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
        if (ip6 == NULL)
                goto out;