Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SK_BUFF]: Introduce skb_network_offset()

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>

authored by

Arnaldo Carvalho de Melo and committed by
David S. Miller
bbe735e4 e7dd65da

+33 -28
+1 -1
drivers/isdn/i4l/isdn_net.c
··· 1121 1121 if (!skb) 1122 1122 return; 1123 1123 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) { 1124 - int pullsize = (ulong)skb->nh.raw - (ulong)skb->data - ETH_HLEN; 1124 + const int pullsize = skb_network_offset(skb) - ETH_HLEN; 1125 1125 if (pullsize > 0) { 1126 1126 printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize); 1127 1127 skb_pull(skb, pullsize);
+1 -1
drivers/net/atl1/atl1_main.c
··· 1300 1300 ~csum_tcpudp_magic(skb->nh.iph->saddr, 1301 1301 skb->nh.iph->daddr, 0, 1302 1302 IPPROTO_TCP, 0); 1303 - ipofst = skb->nh.raw - skb->data; 1303 + ipofst = skb_network_offset(skb); 1304 1304 if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */ 1305 1305 tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT; 1306 1306
+1 -1
drivers/net/chelsio/sge.c
··· 1865 1865 1866 1866 ++st->tx_tso; 1867 1867 1868 - eth_type = skb->nh.raw - skb->data == ETH_HLEN ? 1868 + eth_type = skb_network_offset(skb) == ETH_HLEN ? 1869 1869 CPL_ETH_II : CPL_ETH_II_VLAN; 1870 1870 1871 1871 hdr = (struct cpl_tx_pkt_lso *)skb_push(skb, sizeof(*hdr));
+1 -1
drivers/net/cxgb3/sge.c
··· 897 897 d->flit[2] = 0; 898 898 cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT_LSO); 899 899 hdr->cntrl = htonl(cntrl); 900 - eth_type = skb->nh.raw - skb->data == ETH_HLEN ? 900 + eth_type = skb_network_offset(skb) == ETH_HLEN ? 901 901 CPL_ETH_II : CPL_ETH_II_VLAN; 902 902 tso_info |= V_LSO_ETH_TYPE(eth_type) | 903 903 V_LSO_IPHDR_WORDS(skb->nh.iph->ihl) |
+1 -1
drivers/net/e1000/e1000_main.c
··· 2910 2910 0); 2911 2911 ipcse = 0; 2912 2912 } 2913 - ipcss = skb->nh.raw - skb->data; 2913 + ipcss = skb_network_offset(skb); 2914 2914 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; 2915 2915 tucss = skb->h.raw - skb->data; 2916 2916 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
+1 -1
drivers/net/gianfar.c
··· 952 952 * frame (skb->data) and the start of the IP hdr. 953 953 * l4os is the distance between the start of the 954 954 * l3 hdr and the l4 hdr */ 955 - fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN); 955 + fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN); 956 956 fcb->l4os = (u16)(skb->h.raw - skb->nh.raw); 957 957 958 958 fcb->flags = flags;
+1 -1
drivers/net/ixgb/ixgb_main.c
··· 1195 1195 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr, 1196 1196 skb->nh.iph->daddr, 1197 1197 0, IPPROTO_TCP, 0); 1198 - ipcss = skb->nh.raw - skb->data; 1198 + ipcss = skb_network_offset(skb); 1199 1199 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; 1200 1200 ipcse = skb->h.raw - skb->data - 1; 1201 1201 tucss = skb->h.raw - skb->data;
+1 -1
drivers/net/netxen/netxen_nic_hw.c
··· 386 386 } 387 387 adapter->stats.xmitcsummed++; 388 388 desc->tcp_hdr_offset = skb->h.raw - skb->data; 389 - desc->ip_hdr_offset = skb->nh.raw - skb->data; 389 + desc->ip_hdr_offset = skb_network_offset(skb); 390 390 } 391 391 392 392 int netxen_is_flash_supported(struct netxen_adapter *adapter)
+5
include/linux/skbuff.h
··· 965 965 skb->nh.raw = skb->data; 966 966 } 967 967 968 + static inline int skb_network_offset(const struct sk_buff *skb) 969 + { 970 + return skb->nh.raw - skb->data; 971 + } 972 + 968 973 static inline unsigned char *skb_mac_header(const struct sk_buff *skb) 969 974 { 970 975 return skb->mac.raw;
+2 -2
net/ax25/ax25_out.c
··· 148 148 149 149 if (ka9qfrag == 1) { 150 150 skb_reserve(skbn, frontlen + 2); 151 - skbn->nh.raw = skbn->data + (skb->nh.raw - skb->data); 151 + skbn->nh.raw = skbn->data + skb_network_offset(skb); 152 152 memcpy(skb_put(skbn, len), skb->data, len); 153 153 p = skb_push(skbn, 2); 154 154 ··· 161 161 } 162 162 } else { 163 163 skb_reserve(skbn, frontlen + 1); 164 - skbn->nh.raw = skbn->data + (skb->nh.raw - skb->data); 164 + skbn->nh.raw = skbn->data + skb_network_offset(skb); 165 165 memcpy(skb_put(skbn, len), skb->data, len); 166 166 p = skb_push(skbn, 1); 167 167 *p = AX25_P_TEXT;
+3 -3
net/core/neighbour.c
··· 1125 1125 { 1126 1126 struct net_device *dev = skb->dev; 1127 1127 1128 - __skb_pull(skb, skb->nh.raw - skb->data); 1128 + __skb_pull(skb, skb_network_offset(skb)); 1129 1129 1130 1130 if (dev->hard_header && 1131 1131 dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, ··· 1147 1147 if (!dst || !(neigh = dst->neighbour)) 1148 1148 goto discard; 1149 1149 1150 - __skb_pull(skb, skb->nh.raw - skb->data); 1150 + __skb_pull(skb, skb_network_offset(skb)); 1151 1151 1152 1152 if (!neigh_event_send(neigh, skb)) { 1153 1153 int err; ··· 1190 1190 struct neighbour *neigh = dst->neighbour; 1191 1191 struct net_device *dev = neigh->dev; 1192 1192 1193 - __skb_pull(skb, skb->nh.raw - skb->data); 1193 + __skb_pull(skb, skb_network_offset(skb)); 1194 1194 1195 1195 read_lock_bh(&neigh->lock); 1196 1196 err = dev->hard_header(skb, dev, ntohs(skb->protocol),
+2 -2
net/ipv4/ip_output.c
··· 96 96 static int ip_dev_loopback_xmit(struct sk_buff *newskb) 97 97 { 98 98 skb_reset_mac_header(newskb); 99 - __skb_pull(newskb, newskb->nh.raw - newskb->data); 99 + __skb_pull(newskb, skb_network_offset(newskb)); 100 100 newskb->pkt_type = PACKET_LOOPBACK; 101 101 newskb->ip_summed = CHECKSUM_UNNECESSARY; 102 102 BUG_TRAP(newskb->dst); ··· 1199 1199 1200 1200 /* move skb->data to ip header from ext header */ 1201 1201 if (skb->data < skb->nh.raw) 1202 - __skb_pull(skb, skb->nh.raw - skb->data); 1202 + __skb_pull(skb, skb_network_offset(skb)); 1203 1203 while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) { 1204 1204 __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw); 1205 1205 *tail_skb = tmp_skb;
+2 -2
net/ipv6/icmp.c
··· 206 206 { 207 207 u8 _optval, *op; 208 208 209 - offset += skb->nh.raw - skb->data; 209 + offset += skb_network_offset(skb); 210 210 op = skb_header_pointer(skb, offset, sizeof(_optval), &_optval); 211 211 if (op == NULL) 212 212 return 1; ··· 431 431 tclass = 0; 432 432 433 433 msg.skb = skb; 434 - msg.offset = skb->nh.raw - skb->data; 434 + msg.offset = skb_network_offset(skb); 435 435 msg.type = type; 436 436 437 437 len = skb->len - msg.offset;
+2 -2
net/ipv6/ip6_output.c
··· 89 89 static int ip6_dev_loopback_xmit(struct sk_buff *newskb) 90 90 { 91 91 skb_reset_mac_header(newskb); 92 - __skb_pull(newskb, newskb->nh.raw - newskb->data); 92 + __skb_pull(newskb, skb_network_offset(newskb)); 93 93 newskb->pkt_type = PACKET_LOOPBACK; 94 94 newskb->ip_summed = CHECKSUM_UNNECESSARY; 95 95 BUG_TRAP(newskb->dst); ··· 1330 1330 1331 1331 /* move skb->data to ip header from ext header */ 1332 1332 if (skb->data < skb->nh.raw) 1333 - __skb_pull(skb, skb->nh.raw - skb->data); 1333 + __skb_pull(skb, skb_network_offset(skb)); 1334 1334 while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) { 1335 1335 __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw); 1336 1336 *tail_skb = tmp_skb;
+2 -2
net/netfilter/nf_conntrack_core.c
··· 768 768 struct nf_conntrack_tuple_hash *h; 769 769 struct nf_conn *ct; 770 770 771 - if (!nf_ct_get_tuple(skb, (unsigned int)(skb->nh.raw - skb->data), 771 + if (!nf_ct_get_tuple(skb, skb_network_offset(skb), 772 772 dataoff, l3num, protonum, &tuple, l3proto, 773 773 l4proto)) { 774 774 DEBUGP("resolve_normal_ct: Can't get tuple\n"); ··· 960 960 if (do_acct) { 961 961 ct->counters[CTINFO2DIR(ctinfo)].packets++; 962 962 ct->counters[CTINFO2DIR(ctinfo)].bytes += 963 - skb->len - (unsigned int)(skb->nh.raw - skb->data); 963 + skb->len - skb_network_offset(skb); 964 964 965 965 if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000) 966 966 || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000))
+4 -4
net/packet/af_packet.c
··· 491 491 skb_push(skb, skb->data - skb_mac_header(skb)); 492 492 else if (skb->pkt_type == PACKET_OUTGOING) { 493 493 /* Special case: outgoing packets have ll header at head */ 494 - skb_pull(skb, skb->nh.raw - skb->data); 494 + skb_pull(skb, skb_network_offset(skb)); 495 495 } 496 496 } 497 497 ··· 595 595 skb_push(skb, skb->data - skb_mac_header(skb)); 596 596 else if (skb->pkt_type == PACKET_OUTGOING) { 597 597 /* Special case: outgoing packets have ll header at head */ 598 - skb_pull(skb, skb->nh.raw - skb->data); 598 + skb_pull(skb, skb_network_offset(skb)); 599 599 } 600 600 } 601 601 ··· 613 613 if (sk->sk_type == SOCK_DGRAM) { 614 614 macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16; 615 615 } else { 616 - unsigned maclen = skb->nh.raw - skb->data; 616 + unsigned maclen = skb_network_offset(skb); 617 617 netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen)); 618 618 macoff = netoff - maclen; 619 619 } ··· 1145 1145 aux.tp_len = PACKET_SKB_CB(skb)->origlen; 1146 1146 aux.tp_snaplen = skb->len; 1147 1147 aux.tp_mac = 0; 1148 - aux.tp_net = skb->nh.raw - skb->data; 1148 + aux.tp_net = skb_network_offset(skb); 1149 1149 1150 1150 put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux); 1151 1151 }
+1 -1
net/sched/sch_teql.c
··· 323 323 nores = 1; 324 324 break; 325 325 } 326 - __skb_pull(skb, skb->nh.raw - skb->data); 326 + __skb_pull(skb, skb_network_offset(skb)); 327 327 } while ((q = NEXT_SLAVE(q)) != start); 328 328 329 329 if (nores && skb_res == NULL) {
+2 -2
security/selinux/hooks.c
··· 2944 2944 int offset, ihlen, ret = -EINVAL; 2945 2945 struct iphdr _iph, *ih; 2946 2946 2947 - offset = skb->nh.raw - skb->data; 2947 + offset = skb_network_offset(skb); 2948 2948 ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); 2949 2949 if (ih == NULL) 2950 2950 goto out; ··· 3026 3026 int ret = -EINVAL, offset; 3027 3027 struct ipv6hdr _ipv6h, *ip6; 3028 3028 3029 - offset = skb->nh.raw - skb->data; 3029 + offset = skb_network_offset(skb); 3030 3030 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h); 3031 3031 if (ip6 == NULL) 3032 3032 goto out;