Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_reset_network_header(skb)
Browse files Browse the repository at this point in the history
For the common, open coded 'skb->nh.raw = skb->data' operation, so that we can
later turn skb->nh.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 case, next 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 57effc7 commit c1d2bbe
Show file tree
Hide file tree
Showing 47 changed files with 78 additions and 68 deletions.
2 changes: 1 addition & 1 deletion drivers/block/aoe/aoecmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ new_skb(ulong len)
skb = alloc_skb(len, GFP_ATOMIC);
if (skb) {
skb_reset_mac_header(skb);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
skb->protocol = __constant_htons(ETH_P_AOE);
skb->priority = 0;
skb->next = skb->prev = NULL;
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/cxgb3/sge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,8 @@ static inline int rx_offload(struct t3cdev *tdev, struct sge_rspq *rq,
{
rq->offload_pkts++;
skb_reset_mac_header(skb);
skb->nh.raw = skb->h.raw = skb->data;
skb_reset_network_header(skb);
skb->h.raw = skb->data;

if (rq->polling) {
rx_gather[gather_idx++] = skb;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/hamradio/bpqether.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
}

skb->protocol = ax25_type_trans(skb, dev);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
dev->hard_header(skb, dev, ETH_P_BPQ, bpq->dest_addr, NULL, 0);
bpq->stats.tx_packets++;
bpq->stats.tx_bytes+=skb->len;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void emulate_large_send_offload(struct sk_buff *skb)
break;
skb_reserve(nskb, 32);
skb_set_mac_header(nskb, -ETH_HLEN);
nskb->nh.raw = nskb->data;
skb_reset_network_header(nskb);
iph = nskb->nh.iph;
memcpy(nskb->data, skb->nh.raw, doffset);
if (skb_copy_bits(skb,
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ static int pppoe_sendmsg(struct kiocb *iocb, struct socket *sock,

/* Reserve space for headers. */
skb_reserve(skb, dev->hard_header_len);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

skb->dev = dev;

Expand Down Expand Up @@ -884,7 +884,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
skb2->protocol = __constant_htons(ETH_P_PPP_SES);

skb2->nh.raw = skb2->data;
skb_reset_network_header(skb2);

skb2->dev = dev;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/hdlc_cisco.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
skb_put(skb, sizeof(struct cisco_packet));
skb->priority = TC_PRIO_CONTROL;
skb->dev = dev;
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

dev_queue_xmit(skb);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/hdlc_fr.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static void fr_lmi_send(struct net_device *dev, int fullrep)
skb_put(skb, i);
skb->priority = TC_PRIO_CONTROL;
skb->dev = dev;
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

dev_queue_xmit(skb);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wan/lmc/lmc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ static int lmc_rx (struct net_device *dev) /*fold00*/
skb->protocol = lmc_proto_type(sc, skb);
skb->protocol = htons(ETH_P_WAN_PPP);
skb_reset_mac_header(skb);
// skb->nh.raw = skb->data;
/* skb_reset_network_header(skb); */
skb->dev = dev;
lmc_proto_netif(sc, skb);

Expand Down Expand Up @@ -1706,7 +1706,7 @@ static int lmc_rx (struct net_device *dev) /*fold00*/

nsb->protocol = lmc_proto_type(sc, skb);
skb_reset_mac_header(nsb);
// nsb->nh.raw = nsb->data;
/* skb_reset_network_header(nsb); */
nsb->dev = dev;
lmc_proto_netif(sc, nsb);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/hostap/hostap_80211_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,8 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
skb2->dev = dev;
skb2->protocol = __constant_htons(ETH_P_802_3);
skb_reset_mac_header(skb2);
skb2->nh.raw = skb2->data;
/* skb2->nh.raw = skb2->data + ETH_HLEN; */
skb_reset_network_header(skb2);
/* skb2->nh.raw += ETH_HLEN; */
dev_queue_xmit(skb2);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/hostap/hostap_ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ static void prism2_send_mgmt(struct net_device *dev,

skb->dev = dev;
skb_reset_mac_header(skb);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
dev_queue_xmit(skb);
}
#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/hostap/hostap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype,

skb->dev = dev;
skb_reset_mac_header(skb);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
dev_queue_xmit(skb);

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

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

static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{
return skb->mac.raw;
Expand Down
2 changes: 1 addition & 1 deletion include/net/llc_pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static inline void llc_pdu_header_init(struct sk_buff *skb, u8 type,
struct llc_pdu_un *pdu;

skb_push(skb, hlen);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
pdu = llc_pdu_un_hdr(skb);
pdu->dsap = dsap;
pdu->ssap = ssap;
Expand Down
2 changes: 1 addition & 1 deletion net/appletalk/aarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
int hash;
struct aarp_entry *a;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

/* Check for LocalTalk first */
if (dev->type == ARPHRD_LOCALTLK) {
Expand Down
2 changes: 1 addition & 1 deletion net/atm/mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
memcpy(new_skb->data, eg->ctrl_info.DLL_header, eg->ctrl_info.DH_length);
new_skb->protocol = eth_type_trans(new_skb, dev);
new_skb->nh.raw = new_skb->data;
skb_reset_network_header(new_skb);

eg->latest_ip_addr = new_skb->nh.iph->saddr;
eg->packets_rcvd++;
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
goto out;
}

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

/* Add the PID if one is not supplied by the user in the skb */
if (!ax25->pidincl) {
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/ax25_ds_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void ax25_kiss_cmd(ax25_dev *ax25_dev, unsigned char cmd, unsigned char p
if ((skb = alloc_skb(2, GFP_ATOMIC)) == NULL)
return;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);
p = skb_put(skb, 2);

*p++ = cmd;
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 @@ -61,8 +61,8 @@ static int ax25_rx_fragment(ax25_cb *ax25, struct sk_buff *skb)
skb_reserve(skbn, AX25_MAX_HEADER_LEN);

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

/* Copy data from the fragments */
while ((skbo = skb_dequeue(&ax25->frag_queue)) != NULL) {
Expand Down Expand Up @@ -123,7 +123,7 @@ int ax25_rx_iframe(ax25_cb *ax25, struct sk_buff *skb)

skb_pull(skb, 1); /* Remove PID */
skb_reset_mac_header(skb);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
skb->dev = ax25->ax25_dev->dev;
skb->pkt_type = PACKET_HOST;
skb->protocol = htons(ETH_P_IP);
Expand Down Expand Up @@ -247,7 +247,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
case AX25_P_IP:
skb_pull(skb,2); /* drop PID/CTRL */
skb->h.raw = skb->data;
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
skb->dev = dev;
skb->pkt_type = PACKET_HOST;
skb->protocol = htons(ETH_P_IP);
Expand All @@ -257,7 +257,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->nh.raw = skb->data;
skb_reset_network_header(skb);
skb->dev = dev;
skb->pkt_type = PACKET_HOST;
skb->protocol = htons(ETH_P_ARP);
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/ax25_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int ax25_rebuild_header(struct sk_buff *skb)
src_c = *(ax25_address *)(bp + 8);

skb_pull(ourskb, AX25_HEADER_LEN - 1); /* Keep PID */
ourskb->nh.raw = ourskb->data;
skb_reset_network_header(ourskb);

ax25=ax25_send_frame(
ourskb,
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/ax25_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static void ax25_send_iframe(ax25_cb *ax25, struct sk_buff *skb, int poll_bit)
if (skb == NULL)
return;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

if (ax25->modulus == AX25_MODULUS) {
frame = skb_push(skb, 1);
Expand Down
4 changes: 2 additions & 2 deletions net/ax25/ax25_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void ax25_send_control(ax25_cb *ax25, int frametype, int poll_bit, int type)

skb_reserve(skb, ax25->ax25_dev->dev->hard_header_len);

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

/* Assume a response - address structure for DTE */
if (ax25->modulus == AX25_MODULUS) {
Expand Down Expand Up @@ -205,7 +205,7 @@ void ax25_return_dm(struct net_device *dev, ax25_address *src, ax25_address *des
return; /* Next SABM will get DM'd */

skb_reserve(skb, dev->hard_header_len);
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

ax25_digi_invert(digi, &retdigi);

Expand Down
5 changes: 3 additions & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
printk(KERN_CRIT "protocol %04x is "
"buggy, dev %s\n",
skb2->protocol, dev->name);
skb2->nh.raw = skb2->data;
skb_reset_network_header(skb2);
}

skb2->h.raw = skb2->nh.raw;
Expand Down Expand Up @@ -1771,7 +1771,8 @@ int netif_receive_skb(struct sk_buff *skb)

__get_cpu_var(netdev_rx_stat).total++;

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

pt_prev = NULL;
Expand Down
5 changes: 3 additions & 2 deletions net/core/netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ static void arp_reply(struct sk_buff *skb)
(2 * sizeof(u32)))))
return;

skb->h.raw = skb->nh.raw = skb->data;
skb_reset_network_header(skb);
skb->h.raw = skb->data;
arp = skb->nh.arph;

if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
Expand Down Expand Up @@ -389,7 +390,7 @@ static void arp_reply(struct sk_buff *skb)
if (!send_skb)
return;

send_skb->nh.raw = send_skb->data;
skb_reset_network_header(send_skb);
arp = (struct arphdr *) skb_put(send_skb, size);
send_skb->dev = skb->dev;
send_skb->protocol = htons(ETH_P_ARP);
Expand Down
4 changes: 2 additions & 2 deletions net/decnet/dn_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
pktlen = (__le16 *)skb_push(skb,2);
*pktlen = dn_htons(skb->len - 2);

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
}
Expand Down Expand Up @@ -1005,7 +1005,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
pktlen = (__le16 *)skb_push(skb, 2);
*pktlen = dn_htons(skb->len - 2);

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

if (dn_am_i_a_router(dn, dn_db, ifa)) {
struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
Expand Down
6 changes: 3 additions & 3 deletions net/decnet/dn_neigh.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static int dn_long_output(struct sk_buff *skb)
lp->s_class = 0;
lp->pt = 0;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
}
Expand Down Expand Up @@ -300,7 +300,7 @@ static int dn_short_output(struct sk_buff *skb)
sp->srcnode = cb->src;
sp->forward = cb->hops & 0x3f;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ static int dn_phase3_output(struct sk_buff *skb)
sp->srcnode = cb->src & dn_htons(0x03ff);
sp->forward = cb->hops & 0x3f;

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
}
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type
flags = *skb->data;
}

skb->nh.raw = skb->data;
skb_reset_network_header(skb);

/*
* Weed out future version DECnet
Expand Down
2 changes: 1 addition & 1 deletion net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
goto out_unlock;

skb_reserve(skb, LL_RESERVED_SPACE(dev));
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

eb = (struct ec_cb *)&skb->cb;

Expand Down
2 changes: 1 addition & 1 deletion net/ieee80211/ieee80211_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
skb2->dev = dev;
skb2->protocol = __constant_htons(ETH_P_802_3);
skb_reset_mac_header(skb2);
skb2->nh.raw = skb2->data;
skb_reset_network_header(skb2);
/* skb2->nh.raw = skb2->data + ETH_HLEN; */
dev_queue_xmit(skb2);
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
return NULL;

skb_reserve(skb, LL_RESERVED_SPACE(dev));
skb->nh.raw = skb->data;
skb_reset_network_header(skb);
arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4));
skb->dev = dev;
skb->protocol = htons(ETH_P_ARP);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
dst_release(skb2->dst);
skb2->dst = NULL;
skb_pull(skb2, skb->data - (u8*)eiph);
skb2->nh.raw = skb2->data;
skb_reset_network_header(skb2);

/* Try to guess incoming interface */
memset(&fl, 0, sizeof(fl));
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*))
ip_copy_metadata(skb2, skb);
skb_reserve(skb2, ll_rs);
skb_put(skb2, len + hlen);
skb2->nh.raw = skb2->data;
skb_reset_network_header(skb2);
skb2->h.raw = skb2->data + hlen;

/*
Expand Down Expand Up @@ -722,7 +722,7 @@ static inline int ip_ufo_append_data(struct sock *sk,
skb_put(skb,fragheaderlen + transhdrlen);

/* initialize network header pointer */
skb->nh.raw = skb->data;
skb_reset_network_header(skb);

/* initialize protocol header pointer */
skb->h.raw = skb->data + fragheaderlen;
Expand Down
Loading

0 comments on commit c1d2bbe

Please sign in to comment.