Commit bbe735e4 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by David S. Miller

[SK_BUFF]: Introduce skb_network_offset()

For the quite common 'skb->nh.raw - skb->data' sequence.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e7dd65da
...@@ -1121,7 +1121,7 @@ isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev) ...@@ -1121,7 +1121,7 @@ isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
if (!skb) if (!skb)
return; return;
if (lp->p_encap == ISDN_NET_ENCAP_ETHER) { 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) { if (pullsize > 0) {
printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize); printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
skb_pull(skb, pullsize); skb_pull(skb, pullsize);
......
...@@ -1300,7 +1300,7 @@ static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb, ...@@ -1300,7 +1300,7 @@ static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb,
~csum_tcpudp_magic(skb->nh.iph->saddr, ~csum_tcpudp_magic(skb->nh.iph->saddr,
skb->nh.iph->daddr, 0, skb->nh.iph->daddr, 0,
IPPROTO_TCP, 0); IPPROTO_TCP, 0);
ipofst = skb->nh.raw - skb->data; ipofst = skb_network_offset(skb);
if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */ if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */
tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT; tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT;
......
...@@ -1865,7 +1865,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -1865,7 +1865,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
++st->tx_tso; ++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; CPL_ETH_II : CPL_ETH_II_VLAN;
hdr = (struct cpl_tx_pkt_lso *)skb_push(skb, sizeof(*hdr)); hdr = (struct cpl_tx_pkt_lso *)skb_push(skb, sizeof(*hdr));
......
...@@ -897,7 +897,7 @@ static void write_tx_pkt_wr(struct adapter *adap, struct sk_buff *skb, ...@@ -897,7 +897,7 @@ static void write_tx_pkt_wr(struct adapter *adap, struct sk_buff *skb,
d->flit[2] = 0; d->flit[2] = 0;
cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT_LSO); cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT_LSO);
hdr->cntrl = htonl(cntrl); 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; CPL_ETH_II : CPL_ETH_II_VLAN;
tso_info |= V_LSO_ETH_TYPE(eth_type) | tso_info |= V_LSO_ETH_TYPE(eth_type) |
V_LSO_IPHDR_WORDS(skb->nh.iph->ihl) | V_LSO_IPHDR_WORDS(skb->nh.iph->ihl) |
......
...@@ -2910,7 +2910,7 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, ...@@ -2910,7 +2910,7 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
0); 0);
ipcse = 0; ipcse = 0;
} }
ipcss = skb->nh.raw - skb->data; ipcss = skb_network_offset(skb);
ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
tucss = skb->h.raw - skb->data; tucss = skb->h.raw - skb->data;
tucso = (void *)&(skb->h.th->check) - (void *)skb->data; tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
......
...@@ -952,7 +952,7 @@ static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb) ...@@ -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. * frame (skb->data) and the start of the IP hdr.
* l4os is the distance between the start of the * l4os is the distance between the start of the
* l3 hdr and the l4 hdr */ * 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->l4os = (u16)(skb->h.raw - skb->nh.raw);
fcb->flags = flags; fcb->flags = flags;
......
...@@ -1195,7 +1195,7 @@ ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb) ...@@ -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->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
skb->nh.iph->daddr, skb->nh.iph->daddr,
0, IPPROTO_TCP, 0); 0, IPPROTO_TCP, 0);
ipcss = skb->nh.raw - skb->data; ipcss = skb_network_offset(skb);
ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
ipcse = skb->h.raw - skb->data - 1; ipcse = skb->h.raw - skb->data - 1;
tucss = skb->h.raw - skb->data; tucss = skb->h.raw - skb->data;
......
...@@ -386,7 +386,7 @@ void netxen_tso_check(struct netxen_adapter *adapter, ...@@ -386,7 +386,7 @@ void netxen_tso_check(struct netxen_adapter *adapter,
} }
adapter->stats.xmitcsummed++; adapter->stats.xmitcsummed++;
desc->tcp_hdr_offset = skb->h.raw - skb->data; 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) int netxen_is_flash_supported(struct netxen_adapter *adapter)
......
...@@ -965,6 +965,11 @@ static inline void skb_reset_network_header(struct sk_buff *skb) ...@@ -965,6 +965,11 @@ static inline void skb_reset_network_header(struct sk_buff *skb)
skb->nh.raw = skb->data; 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) static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{ {
return skb->mac.raw; return skb->mac.raw;
......
...@@ -148,7 +148,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb) ...@@ -148,7 +148,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
if (ka9qfrag == 1) { if (ka9qfrag == 1) {
skb_reserve(skbn, frontlen + 2); 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); memcpy(skb_put(skbn, len), skb->data, len);
p = skb_push(skbn, 2); p = skb_push(skbn, 2);
...@@ -161,7 +161,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb) ...@@ -161,7 +161,7 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
} }
} else { } else {
skb_reserve(skbn, frontlen + 1); 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); memcpy(skb_put(skbn, len), skb->data, len);
p = skb_push(skbn, 1); p = skb_push(skbn, 1);
*p = AX25_P_TEXT; *p = AX25_P_TEXT;
......
...@@ -1125,7 +1125,7 @@ int neigh_compat_output(struct sk_buff *skb) ...@@ -1125,7 +1125,7 @@ int neigh_compat_output(struct sk_buff *skb)
{ {
struct net_device *dev = skb->dev; 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 && if (dev->hard_header &&
dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL,
...@@ -1147,7 +1147,7 @@ int neigh_resolve_output(struct sk_buff *skb) ...@@ -1147,7 +1147,7 @@ int neigh_resolve_output(struct sk_buff *skb)
if (!dst || !(neigh = dst->neighbour)) if (!dst || !(neigh = dst->neighbour))
goto discard; goto discard;
__skb_pull(skb, skb->nh.raw - skb->data); __skb_pull(skb, skb_network_offset(skb));
if (!neigh_event_send(neigh, skb)) { if (!neigh_event_send(neigh, skb)) {
int err; int err;
...@@ -1190,7 +1190,7 @@ int neigh_connected_output(struct sk_buff *skb) ...@@ -1190,7 +1190,7 @@ int neigh_connected_output(struct sk_buff *skb)
struct neighbour *neigh = dst->neighbour; struct neighbour *neigh = dst->neighbour;
struct net_device *dev = neigh->dev; 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); read_lock_bh(&neigh->lock);
err = dev->hard_header(skb, dev, ntohs(skb->protocol), err = dev->hard_header(skb, dev, ntohs(skb->protocol),
......
...@@ -96,7 +96,7 @@ __inline__ void ip_send_check(struct iphdr *iph) ...@@ -96,7 +96,7 @@ __inline__ void ip_send_check(struct iphdr *iph)
static int ip_dev_loopback_xmit(struct sk_buff *newskb) static int ip_dev_loopback_xmit(struct sk_buff *newskb)
{ {
skb_reset_mac_header(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->pkt_type = PACKET_LOOPBACK;
newskb->ip_summed = CHECKSUM_UNNECESSARY; newskb->ip_summed = CHECKSUM_UNNECESSARY;
BUG_TRAP(newskb->dst); BUG_TRAP(newskb->dst);
...@@ -1199,7 +1199,7 @@ int ip_push_pending_frames(struct sock *sk) ...@@ -1199,7 +1199,7 @@ int ip_push_pending_frames(struct sock *sk)
/* move skb->data to ip header from ext header */ /* move skb->data to ip header from ext header */
if (skb->data < skb->nh.raw) 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) { while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
__skb_pull(tmp_skb, skb->h.raw - skb->nh.raw); __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
*tail_skb = tmp_skb; *tail_skb = tmp_skb;
......
...@@ -206,7 +206,7 @@ static __inline__ int opt_unrec(struct sk_buff *skb, __u32 offset) ...@@ -206,7 +206,7 @@ static __inline__ int opt_unrec(struct sk_buff *skb, __u32 offset)
{ {
u8 _optval, *op; u8 _optval, *op;
offset += skb->nh.raw - skb->data; offset += skb_network_offset(skb);
op = skb_header_pointer(skb, offset, sizeof(_optval), &_optval); op = skb_header_pointer(skb, offset, sizeof(_optval), &_optval);
if (op == NULL) if (op == NULL)
return 1; return 1;
...@@ -431,7 +431,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info, ...@@ -431,7 +431,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
tclass = 0; tclass = 0;
msg.skb = skb; msg.skb = skb;
msg.offset = skb->nh.raw - skb->data; msg.offset = skb_network_offset(skb);
msg.type = type; msg.type = type;
len = skb->len - msg.offset; len = skb->len - msg.offset;
......
...@@ -89,7 +89,7 @@ static inline int ip6_output_finish(struct sk_buff *skb) ...@@ -89,7 +89,7 @@ static inline int ip6_output_finish(struct sk_buff *skb)
static int ip6_dev_loopback_xmit(struct sk_buff *newskb) static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
{ {
skb_reset_mac_header(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->pkt_type = PACKET_LOOPBACK;
newskb->ip_summed = CHECKSUM_UNNECESSARY; newskb->ip_summed = CHECKSUM_UNNECESSARY;
BUG_TRAP(newskb->dst); BUG_TRAP(newskb->dst);
...@@ -1330,7 +1330,7 @@ int ip6_push_pending_frames(struct sock *sk) ...@@ -1330,7 +1330,7 @@ int ip6_push_pending_frames(struct sock *sk)
/* move skb->data to ip header from ext header */ /* move skb->data to ip header from ext header */
if (skb->data < skb->nh.raw) 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) { while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
__skb_pull(tmp_skb, skb->h.raw - skb->nh.raw); __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
*tail_skb = tmp_skb; *tail_skb = tmp_skb;
......
...@@ -768,7 +768,7 @@ resolve_normal_ct(struct sk_buff *skb, ...@@ -768,7 +768,7 @@ resolve_normal_ct(struct sk_buff *skb,
struct nf_conntrack_tuple_hash *h; struct nf_conntrack_tuple_hash *h;
struct nf_conn *ct; 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, dataoff, l3num, protonum, &tuple, l3proto,
l4proto)) { l4proto)) {
DEBUGP("resolve_normal_ct: Can't get tuple\n"); DEBUGP("resolve_normal_ct: Can't get tuple\n");
...@@ -960,7 +960,7 @@ void __nf_ct_refresh_acct(struct nf_conn *ct, ...@@ -960,7 +960,7 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
if (do_acct) { if (do_acct) {
ct->counters[CTINFO2DIR(ctinfo)].packets++; ct->counters[CTINFO2DIR(ctinfo)].packets++;
ct->counters[CTINFO2DIR(ctinfo)].bytes += 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) if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000)
|| (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000)) || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000))
......
...@@ -491,7 +491,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet ...@@ -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)); skb_push(skb, skb->data - skb_mac_header(skb));
else if (skb->pkt_type == PACKET_OUTGOING) { else if (skb->pkt_type == PACKET_OUTGOING) {
/* Special case: outgoing packets have ll header at head */ /* 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 ...@@ -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)); skb_push(skb, skb->data - skb_mac_header(skb));
else if (skb->pkt_type == PACKET_OUTGOING) { else if (skb->pkt_type == PACKET_OUTGOING) {
/* Special case: outgoing packets have ll header at head */ /* 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 ...@@ -613,7 +613,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
if (sk->sk_type == SOCK_DGRAM) { if (sk->sk_type == SOCK_DGRAM) {
macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16; macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16;
} else { } else {
unsigned maclen = skb->nh.raw - skb->data; unsigned maclen = skb_network_offset(skb);
netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen)); netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen));
macoff = netoff - maclen; macoff = netoff - maclen;
} }
...@@ -1145,7 +1145,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock, ...@@ -1145,7 +1145,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
aux.tp_len = PACKET_SKB_CB(skb)->origlen; aux.tp_len = PACKET_SKB_CB(skb)->origlen;
aux.tp_snaplen = skb->len; aux.tp_snaplen = skb->len;
aux.tp_mac = 0; 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); put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
} }
......
...@@ -323,7 +323,7 @@ static int teql_master_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -323,7 +323,7 @@ static int teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
nores = 1; nores = 1;
break; break;
} }
__skb_pull(skb, skb->nh.raw - skb->data); __skb_pull(skb, skb_network_offset(skb));
} while ((q = NEXT_SLAVE(q)) != start); } while ((q = NEXT_SLAVE(q)) != start);
if (nores && skb_res == NULL) { if (nores && skb_res == NULL) {
......
...@@ -2944,7 +2944,7 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb, ...@@ -2944,7 +2944,7 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
int offset, ihlen, ret = -EINVAL; int offset, ihlen, ret = -EINVAL;
struct iphdr _iph, *ih; struct iphdr _iph, *ih;
offset = skb->nh.raw - skb->data; offset = skb_network_offset(skb);
ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
if (ih == NULL) if (ih == NULL)
goto out; goto out;
...@@ -3026,7 +3026,7 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb, ...@@ -3026,7 +3026,7 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
int ret = -EINVAL, offset; int ret = -EINVAL, offset;
struct ipv6hdr _ipv6h, *ip6; struct ipv6hdr _ipv6h, *ip6;
offset = skb->nh.raw - skb->data; offset = skb_network_offset(skb);
ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h); ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
if (ip6 == NULL) if (ip6 == NULL)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment