Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_reset_transport_header(skb)
Browse files Browse the repository at this point in the history
For the common, open coded 'skb->h.raw = skb->data' operation, so that we can
later turn skb->h.raw into a offset, reducing the size of struct sk_buff in
64bit land while possibly keeping it as a pointer on 32bit.

This one touches just the most simple cases:

skb->h.raw = skb->data;
skb->h.raw = {skb_push|[__]skb_pull}()

The next ones will handle the slightly more "complex" cases.

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
acmel authored and David S. Miller committed Apr 26, 2007
1 parent 0660e03 commit badff6d
Show file tree
Hide file tree
Showing 49 changed files with 82 additions and 73 deletions.
6 changes: 3 additions & 3 deletions drivers/infiniband/hw/cxgb3/iwch_cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static void send_mpa_req(struct iwch_ep *ep, struct sk_buff *skb)
*/
skb_get(skb);
set_arp_failure_handler(skb, arp_failure_discard);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
len = skb->len;
req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA));
Expand Down Expand Up @@ -559,7 +559,7 @@ static int send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen)
skb_get(skb);
skb->priority = CPL_PRIORITY_DATA;
set_arp_failure_handler(skb, arp_failure_discard);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA));
req->wr_lo = htonl(V_WR_TID(ep->hwtid));
Expand Down Expand Up @@ -610,7 +610,7 @@ static int send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen)
*/
skb_get(skb);
set_arp_failure_handler(skb, arp_failure_discard);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
len = skb->len;
req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA));
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/appletalk/cops.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ static void cops_rx(struct net_device *dev)

skb_reset_mac_header(skb); /* Point to entire packet. */
skb_pull(skb,3);
skb->h.raw = skb->data; /* Point to data (Skip header). */
skb_reset_transport_header(skb); /* Point to data (Skip header). */

/* Update the counters. */
lp->stats.rx_packets++;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/appletalk/ltpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ static int sendup_buffer (struct net_device *dev)
/* copy ddp(s,e)hdr + contents */
memcpy(skb->data,(void*)ltdmabuf,len);

skb->h.raw = skb->data;
skb_reset_transport_header(skb);

stats->rx_packets++;
stats->rx_bytes+=skb->len;
Expand Down Expand Up @@ -923,7 +923,7 @@ static int ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
cbuf.laptype = skb->data[2];
skb_pull(skb,3); /* skip past LLAP header */
cbuf.length = skb->len; /* this is host order */
skb->h.raw=skb->data;
skb_reset_transport_header(skb);

if(debug & DEBUG_UPPER) {
printk("command ");
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/cxgb3/sge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ static inline int rx_offload(struct t3cdev *tdev, struct sge_rspq *rq,
rq->offload_pkts++;
skb_reset_mac_header(skb);
skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

if (rq->polling) {
rx_gather[gather_idx++] = skb;
Expand Down
6 changes: 3 additions & 3 deletions include/linux/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)

static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
{
skb->h.raw = skb_push(skb, headlen);
memset(skb->h.raw, 0, headlen);
return dccp_hdr(skb);
skb_push(skb, headlen);
skb_reset_transport_header(skb);
return memset(skb->h.raw, 0, headlen);
}

static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
Expand Down
5 changes: 5 additions & 0 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ static inline void skb_reserve(struct sk_buff *skb, int len)
skb->tail += len;
}

static inline void skb_reset_transport_header(struct sk_buff *skb)
{
skb->h.raw = skb->data;
}

static inline unsigned char *skb_network_header(const struct sk_buff *skb)
{
return skb->nh.raw;
Expand Down
6 changes: 3 additions & 3 deletions net/appletalk/aarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void __aarp_send_query(struct aarp_entry *a)
/* Set up the buffer */
skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb_put(skb, sizeof(*eah));
skb->protocol = htons(ETH_P_ATALK);
skb->dev = dev;
Expand Down Expand Up @@ -166,7 +166,7 @@ static void aarp_send_reply(struct net_device *dev, struct atalk_addr *us,
/* Set up the buffer */
skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb_put(skb, sizeof(*eah));
skb->protocol = htons(ETH_P_ATALK);
skb->dev = dev;
Expand Down Expand Up @@ -217,7 +217,7 @@ static void aarp_send_probe(struct net_device *dev, struct atalk_addr *us)
/* Set up the buffer */
skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb_put(skb, sizeof(*eah));
skb->protocol = htons(ETH_P_ATALK);
skb->dev = dev;
Expand Down
4 changes: 2 additions & 2 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ static int handle_ip_over_ddp(struct sk_buff *skb)
skb->protocol = htons(ETH_P_IP);
skb_pull(skb, 13);
skb->dev = dev;
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

stats = dev->priv;
stats->rx_packets++;
Expand Down Expand Up @@ -1522,7 +1522,7 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
/* Non routable, so force a drop if we slip up later */
ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
}
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

return atalk_rcv(skb, dev, pt, orig_dev);
freeit:
Expand Down
4 changes: 2 additions & 2 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,8 @@ static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
if (!ax25_sk(sk)->pidincl)
skb_pull(skb, 1); /* Remove PID */

skb->h.raw = skb->data;
copied = skb->len;
skb_reset_transport_header(skb);
copied = skb->len;

if (copied > size) {
copied = size;
Expand Down
8 changes: 4 additions & 4 deletions net/ax25/ax25_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int ax25_rx_fragment(ax25_cb *ax25, struct sk_buff *skb)

skbn->dev = ax25->ax25_dev->dev;
skb_reset_network_header(skbn);
skbn->h.raw = skbn->data;
skb_reset_transport_header(skbn);

/* Copy data from the fragments */
while ((skbo = skb_dequeue(&ax25->frag_queue)) != NULL) {
Expand Down Expand Up @@ -196,7 +196,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
* Process the AX.25/LAPB frame.
*/

skb->h.raw = skb->data;
skb_reset_transport_header(skb);

if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) {
kfree_skb(skb);
Expand Down Expand Up @@ -246,7 +246,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
switch (skb->data[1]) {
case AX25_P_IP:
skb_pull(skb,2); /* drop PID/CTRL */
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb_reset_network_header(skb);
skb->dev = dev;
skb->pkt_type = PACKET_HOST;
Expand All @@ -256,7 +256,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,

case AX25_P_ARP:
skb_pull(skb,2);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb_reset_network_header(skb);
skb->dev = dev;
skb->pkt_type = PACKET_HOST;
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/af_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
copied = len;
}

skb->h.raw = skb->data;
skb_reset_transport_header(skb);
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);

skb_free_datagram(sk, skb);
Expand Down
9 changes: 5 additions & 4 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,11 @@ static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)
struct hci_acl_hdr *hdr;
int len = skb->len;

hdr = (struct hci_acl_hdr *) skb_push(skb, HCI_ACL_HDR_SIZE);
skb_push(skb, HCI_ACL_HDR_SIZE);
skb_reset_transport_header(skb);
hdr = (struct hci_acl_hdr *)skb->h.raw;
hdr->handle = cpu_to_le16(hci_handle_pack(handle, flags));
hdr->dlen = cpu_to_le16(len);

skb->h.raw = (void *) hdr;
}

int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags)
Expand Down Expand Up @@ -1143,7 +1143,8 @@ int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
hdr.handle = cpu_to_le16(conn->handle);
hdr.dlen = skb->len;

skb->h.raw = skb_push(skb, HCI_SCO_HDR_SIZE);
skb_push(skb, HCI_SCO_HDR_SIZE);
skb_reset_transport_header(skb);
memcpy(skb->h.raw, &hdr, HCI_SCO_HDR_SIZE);

skb->dev = (void *) hdev;
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
copied = len;
}

skb->h.raw = skb->data;
skb_reset_transport_header(skb);
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);

hci_sock_cmsg(sk, msg, skb);
Expand Down
2 changes: 1 addition & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ int netif_receive_skb(struct sk_buff *skb)
__get_cpu_var(netdev_rx_stat).total++;

skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
skb->mac_len = skb->nh.raw - skb->mac.raw;

pt_prev = NULL;
Expand Down
2 changes: 1 addition & 1 deletion net/core/netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void arp_reply(struct sk_buff *skb)
return;

skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
arp = arp_hdr(skb);

if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/dn_nsp_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ static int dn_nsp_rx_packet(struct sk_buff *skb)
if (!pskb_may_pull(skb, 2))
goto free_out;

skb->h.raw = skb->data;
skb_reset_transport_header(skb);
cb->nsp_flags = *ptr++;

if (decnet_debug_level & 2)
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/dn_nsp_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void dn_nsp_send(struct sk_buff *skb)
struct dst_entry *dst;
struct flowi fl;

skb->h.raw = skb->data;
skb_reset_transport_header(skb);
scp->stamp = jiffies;

dst = sk_dst_check(sk, 0);
Expand Down
4 changes: 2 additions & 2 deletions net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static int dn_route_rx_long(struct sk_buff *skb)
goto drop_it;

skb_pull(skb, 20);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

/* Destination info */
ptr += 2;
Expand Down Expand Up @@ -542,7 +542,7 @@ static int dn_route_rx_short(struct sk_buff *skb)
goto drop_it;

skb_pull(skb, 5);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

cb->dst = *(__le16 *)ptr;
ptr += 2;
Expand Down
6 changes: 4 additions & 2 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,8 @@ static int inet_gso_send_check(struct sk_buff *skb)
if (unlikely(!pskb_may_pull(skb, ihl)))
goto out;

skb->h.raw = __skb_pull(skb, ihl);
__skb_pull(skb, ihl);
skb_reset_transport_header(skb);
iph = ip_hdr(skb);
proto = iph->protocol & (MAX_INET_PROTOS - 1);
err = -EPROTONOSUPPORT;
Expand Down Expand Up @@ -1163,7 +1164,8 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
if (unlikely(!pskb_may_pull(skb, ihl)))
goto out;

skb->h.raw = __skb_pull(skb, ihl);
__skb_pull(skb, ihl);
skb_reset_transport_header(skb);
iph = ip_hdr(skb);
id = ntohs(iph->id);
proto = iph->protocol & (MAX_INET_PROTOS - 1);
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
}
((struct iphdr*)work_buf)->protocol = ah->nexthdr;
skb->nh.raw += ah_hlen;
skb->h.raw = memcpy(skb_network_header(skb), work_buf, ihl);
memcpy(skb_network_header(skb), work_buf, ihl);
skb->h.raw = skb->nh.raw;
__skb_pull(skb, ah_hlen + ihl);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb)
__skb_pull(skb, ip_hdrlen(skb));

/* Point into the IP datagram, just past the header. */
skb->h.raw = skb->data;
skb_reset_transport_header(skb);

rcu_read_lock();
{
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*))
* before previous one went down. */
if (frag) {
frag->ip_summed = CHECKSUM_NONE;
frag->h.raw = frag->data;
skb_reset_transport_header(frag);
__skb_push(frag, hlen);
skb_reset_network_header(frag);
memcpy(skb_network_header(frag), iph, hlen);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
*/
skb_push(skb, sizeof(struct iphdr));
skb_reset_network_header(skb);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
msg = (struct igmpmsg *)skb_network_header(skb);
memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr));
msg->im_msgtype = IGMPMSG_WHOLEPKT;
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,8 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
* transport header to point to ESP. Keep UDP on the stack
* for later.
*/
skb->h.raw = __skb_pull(skb, len);
__skb_pull(skb, len);
skb_reset_transport_header(skb);

/* modify the protocol (it's ESP!) */
iph->protocol = IPPROTO_ESP;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/xfrm4_mode_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
skb->nh.raw = skb->h.raw;
}
ip_hdr(skb)->tot_len = htons(skb->len + ihl);
skb->h.raw = skb->data;
skb_reset_transport_header(skb);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
if (hdr->version != 6)
goto err;

skb->h.raw = (u8 *)(hdr + 1);
skb->h.raw = skb->nh.raw + sizeof(*hdr);
IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);

pkt_len = ntohs(hdr->payload_len);
Expand Down
8 changes: 4 additions & 4 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
* before previous one went down. */
if (frag) {
frag->ip_summed = CHECKSUM_NONE;
frag->h.raw = frag->data;
skb_reset_transport_header(frag);
fh = (struct frag_hdr*)__skb_push(frag, sizeof(struct frag_hdr));
__skb_push(frag, hlen);
skb_reset_network_header(frag);
Expand Down Expand Up @@ -747,8 +747,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
skb_reserve(frag, LL_RESERVED_SPACE(rt->u.dst.dev));
skb_put(frag, len + hlen + sizeof(struct frag_hdr));
skb_reset_network_header(frag);
fh = (struct frag_hdr*)(frag->data + hlen);
frag->h.raw = frag->data + hlen + sizeof(struct frag_hdr);
fh = (struct frag_hdr *)(skb_network_header(frag) + hlen);
frag->h.raw = frag->nh.raw + hlen + sizeof(struct frag_hdr);

/*
* Charge the memory for the fragment to any owner
Expand Down Expand Up @@ -991,7 +991,7 @@ static inline int ip6_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;
Expand Down
Loading

0 comments on commit badff6d

Please sign in to comment.