Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_mac_header()
Browse files Browse the repository at this point in the history
For the places where we need a pointer to the mac header, it is still legal to
touch skb->mac.raw directly if just adding to, subtracting from or setting it
to another layer header.

This one also converts some more cases to skb_reset_mac_header() that my
regex missed as it had no spaces before nor after '=', ugh.

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 31713c3 commit 98e399f
Show file tree
Hide file tree
Showing 49 changed files with 108 additions and 88 deletions.
2 changes: 1 addition & 1 deletion arch/um/drivers/daemon_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static int daemon_read(int fd, struct sk_buff **skb,
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_recvfrom(fd, (*skb)->mac.raw,
return(net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
}

Expand Down
2 changes: 1 addition & 1 deletion arch/um/drivers/mcast_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_recvfrom(fd, (*skb)->mac.raw,
return(net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
}

Expand Down
2 changes: 1 addition & 1 deletion arch/um/drivers/pcap_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int pcap_read(int fd, struct sk_buff **skb,
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(pcap_user_read(fd, (*skb)->mac.raw,
return(pcap_user_read(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER,
(struct pcap_data *) &lp->user));
}
Expand Down
2 changes: 1 addition & 1 deletion arch/um/drivers/slip_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static unsigned short slip_protocol(struct sk_buff *skbuff)
static int slip_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slip_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu,
return(slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slip_data *) &lp->user));
}

Expand Down
2 changes: 1 addition & 1 deletion arch/um/drivers/slirp_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static unsigned short slirp_protocol(struct sk_buff *skbuff)
static int slirp_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slirp_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu,
return(slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slirp_data *) &lp->user));
}

Expand Down
2 changes: 1 addition & 1 deletion arch/um/os-Linux/drivers/ethertap_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)

*skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP);
if(*skb == NULL) return(-ENOMEM);
len = net_recvfrom(fd, (*skb)->mac.raw,
len = net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP);
if(len <= 0) return(len);
skb_pull(*skb, 2);
Expand Down
2 changes: 1 addition & 1 deletion arch/um/os-Linux/drivers/tuntap_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int tuntap_read(int fd, struct sk_buff **skb,
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_read(fd, (*skb)->mac.raw,
return(net_read(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/block/aoe/aoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct aoe_hdr {

static inline struct aoe_hdr *aoe_hdr(const struct sk_buff *skb)
{
return (struct aoe_hdr *)skb->mac.raw;
return (struct aoe_hdr *)skb_mac_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee1394/eth1394.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct eth1394hdr {

static inline struct eth1394hdr *eth1394_hdr(const struct sk_buff *skb)
{
return (struct eth1394hdr *)skb->mac.raw;
return (struct eth1394hdr *)skb_mac_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/dvb/dvb-core/dvb_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static unsigned short dvb_net_eth_type_trans(struct sk_buff *skb,
struct ethhdr *eth;
unsigned char *rawp;

skb->mac.raw=skb->data;
skb_reset_mac_header(skb);
skb_pull(skb,dev->hard_header_len);
eth = eth_hdr(skb);

Expand Down
26 changes: 14 additions & 12 deletions drivers/message/fusion/mptlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
LANSendRequest_t *pSendReq;
SGETransaction32_t *pTrans;
SGESimple64_t *pSimple;
const unsigned char *mac;
dma_addr_t dma;
unsigned long flags;
int ctx;
Expand Down Expand Up @@ -784,6 +785,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
// IOC_AND_NETDEV_NAMES_s_s(dev),
// ctx, skb, skb->data));

mac = skb_mac_header(skb);
#ifdef QLOGIC_NAA_WORKAROUND
{
struct NAA_Hosed *nh;
Expand All @@ -793,12 +795,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
drops. */
read_lock_irq(&bad_naa_lock);
for (nh = mpt_bad_naa; nh != NULL; nh=nh->next) {
if ((nh->ieee[0] == skb->mac.raw[0]) &&
(nh->ieee[1] == skb->mac.raw[1]) &&
(nh->ieee[2] == skb->mac.raw[2]) &&
(nh->ieee[3] == skb->mac.raw[3]) &&
(nh->ieee[4] == skb->mac.raw[4]) &&
(nh->ieee[5] == skb->mac.raw[5])) {
if ((nh->ieee[0] == mac[0]) &&
(nh->ieee[1] == mac[1]) &&
(nh->ieee[2] == mac[2]) &&
(nh->ieee[3] == mac[3]) &&
(nh->ieee[4] == mac[4]) &&
(nh->ieee[5] == mac[5])) {
cur_naa = nh->NAA;
dlprintk ((KERN_INFO "mptlan/sdu_send: using NAA value "
"= %04x.\n", cur_naa));
Expand All @@ -810,12 +812,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
#endif

pTrans->TransactionDetails[0] = cpu_to_le32((cur_naa << 16) |
(skb->mac.raw[0] << 8) |
(skb->mac.raw[1] << 0));
pTrans->TransactionDetails[1] = cpu_to_le32((skb->mac.raw[2] << 24) |
(skb->mac.raw[3] << 16) |
(skb->mac.raw[4] << 8) |
(skb->mac.raw[5] << 0));
(mac[0] << 8) |
(mac[1] << 0));
pTrans->TransactionDetails[1] = cpu_to_le32((mac[2] << 24) |
(mac[3] << 16) |
(mac[4] << 8) |
(mac[5] << 0));

pSimple = (SGESimple64_t *) &pTrans->TransactionDetails[2];

Expand Down
4 changes: 2 additions & 2 deletions drivers/net/arcnet/capmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void rx(struct net_device *dev, int bufnum,
skb_put(skb, length + ARC_HDR_SIZE + sizeof(int));
skb->dev = dev;
skb_reset_mac_header(skb);
pkt = (struct archdr *)skb->mac.raw;
pkt = (struct archdr *)skb_mac_header(skb);
skb_pull(skb, ARC_HDR_SIZE);

/* up to sizeof(pkt->soft) has already been copied from the card */
Expand Down Expand Up @@ -269,7 +269,7 @@ static int ack_tx(struct net_device *dev, int acked)
ackskb->dev = dev;

skb_reset_mac_header(ackskb);
ackpkt = (struct archdr *)ackskb->mac.raw;
ackpkt = (struct archdr *)skb_mac_header(ackskb);
/* skb_pull(ackskb, ARC_HDR_SIZE); */


Expand Down
2 changes: 1 addition & 1 deletion drivers/net/plip.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
struct ethhdr *eth;
unsigned char *rawp;

skb->mac.raw=skb->data;
skb_reset_mac_header(skb);
skb_pull(skb,dev->hard_header_len);
eth = eth_hdr(skb);

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/slip.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ sl_bump(struct slip *sl)
}
skb->dev = sl->dev;
memcpy(skb_put(skb,count), sl->rbuff, count);
skb->mac.raw=skb->data;
skb_reset_mac_header(skb);
skb->protocol=htons(ETH_P_IP);
netif_rx(skb);
sl->dev->last_rx = jiffies;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/hostess_sv11.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
/* Drop the CRC - it's not a good idea to try and negotiate it ;) */
skb_trim(skb, skb->len-2);
skb->protocol=__constant_htons(ETH_P_WAN_PPP);
skb->mac.raw=skb->data;
skb_reset_mac_header(skb);
skb->dev=c->netdevice;
/*
* Send it to the PPP layer. We don't have time to process
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/sealevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
/* Drop the CRC - it's not a good idea to try and negotiate it ;) */
skb_trim(skb, skb->len-2);
skb->protocol=htons(ETH_P_WAN_PPP);
skb->mac.raw=skb->data;
skb_reset_mac_header(skb);
skb->dev=c->netdevice;
/*
* Send it to the PPP layer. We don't have time to process
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/syncppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static void sppp_input (struct net_device *dev, struct sk_buff *skb)
unsigned long flags;

skb->dev=dev;
skb->mac.raw=skb->data;
skb_reset_mac_header(skb);

if (dev->flags & IFF_RUNNING)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/airo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ static int add_airo_dev( struct net_device *dev );

static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
{
memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
return ETH_ALEN;
}

Expand Down
14 changes: 7 additions & 7 deletions drivers/net/wireless/hostap/hostap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,20 +590,20 @@ void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)

int hostap_80211_header_parse(struct sk_buff *skb, unsigned char *haddr)
{
memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
return ETH_ALEN;
}


int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr)
{
if (*(u32 *)skb->mac.raw == LWNG_CAP_DID_BASE) {
memcpy(haddr, skb->mac.raw +
sizeof(struct linux_wlan_ng_prism_hdr) + 10,
const unsigned char *mac = skb_mac_header(skb);

if (*(u32 *)mac == LWNG_CAP_DID_BASE) {
memcpy(haddr, mac + sizeof(struct linux_wlan_ng_prism_hdr) + 10,
ETH_ALEN); /* addr2 */
} else { /* (*(u32 *)skb->mac.raw == htonl(LWNG_CAPHDR_VERSION)) */
memcpy(haddr, skb->mac.raw +
sizeof(struct linux_wlan_ng_cap_hdr) + 10,
} else { /* (*(u32 *)mac == htonl(LWNG_CAPHDR_VERSION)) */
memcpy(haddr, mac + sizeof(struct linux_wlan_ng_cap_hdr) + 10,
ETH_ALEN); /* addr2 */
}
return ETH_ALEN;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/orinoco.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ static void orinoco_stat_gather(struct net_device *dev,
/* Note : gcc will optimise the whole section away if
* WIRELESS_SPY is not defined... - Jean II */
if (SPY_NUMBER(priv)) {
orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
desc->signal, desc->silence);
}
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/wireless/wavelan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,8 @@ wv_packet_read(struct net_device * dev, u16 buf_off, int sksize)
skb->protocol = eth_type_trans(skb, dev);

#ifdef DEBUG_RX_INFO
wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
wv_packet_info(skb_mac_header(skb), sksize, dev->name,
"wv_packet_read");
#endif /* DEBUG_RX_INFO */

/* Statistics-gathering and associated stuff.
Expand Down Expand Up @@ -2553,7 +2554,7 @@ wv_packet_read(struct net_device * dev, u16 buf_off, int sksize)

/* Spying stuff */
#ifdef IW_WIRELESS_SPY
wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE,
stats);
#endif /* IW_WIRELESS_SPY */
#ifdef HISTOGRAM
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/wavelan_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ wv_packet_read(struct net_device * dev,
skb->protocol = eth_type_trans(skb, dev);

#ifdef DEBUG_RX_INFO
wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
wv_packet_info(skb_mac_header(skb), sksize, dev->name, "wv_packet_read");
#endif /* DEBUG_RX_INFO */

/* Statistics gathering & stuff associated.
Expand Down Expand Up @@ -2923,7 +2923,7 @@ wv_packet_read(struct net_device * dev,
#endif /* WAVELAN_ROAMING */

#ifdef WIRELESS_SPY
wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, stats);
#endif /* WIRELESS_SPY */
#ifdef HISTOGRAM
wl_his_gather(dev, stats);
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/net/claw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3525,8 +3525,8 @@ unpack_read(struct net_device *dev )
memcpy(skb_put(skb,len_of_data),
privptr->p_mtc_envelope,
len_of_data);
skb->mac.raw=skb->data;
skb->dev=dev;
skb_reset_mac_header(skb);
skb->protocol=htons(ETH_P_IP);
skb->ip_summed=CHECKSUM_UNNECESSARY;
privptr->stats.rx_packets++;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/if_ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct ethhdr {

static inline struct ethhdr *eth_hdr(const struct sk_buff *skb)
{
return (struct ethhdr *)skb->mac.raw;
return (struct ethhdr *)skb_mac_header(skb);
}

#ifdef CONFIG_SYSCTL
Expand Down
2 changes: 1 addition & 1 deletion include/linux/if_tr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct trh_hdr {

static inline struct trh_hdr *tr_hdr(const struct sk_buff *skb)
{
return (struct trh_hdr *)skb->mac.raw;
return (struct trh_hdr *)skb_mac_header(skb);
}
#ifdef CONFIG_SYSCTL
extern struct ctl_table tr_table[];
Expand Down
2 changes: 1 addition & 1 deletion include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct vlan_ethhdr {

static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
{
return (struct vlan_ethhdr *)skb->mac.raw;
return (struct vlan_ethhdr *)skb_mac_header(skb);
}

struct vlan_hdr {
Expand Down
2 changes: 1 addition & 1 deletion include/linux/netfilter_bridge/ebt_802_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct ebt_802_3_hdr {

static inline struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
{
return (struct ebt_802_3_hdr *)skb->mac.raw;
return (struct ebt_802_3_hdr *)skb_mac_header(skb);
}
#endif

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

static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{
return skb->mac.raw;
}

static inline int skb_mac_header_was_set(const struct sk_buff *skb)
{
return skb->mac.raw != NULL;
}

static inline void skb_reset_mac_header(struct sk_buff *skb)
{
skb->mac.raw = skb->data;
Expand Down
2 changes: 1 addition & 1 deletion net/802/hippi.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ __be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)
*/
skb->dev = dev;
skb_reset_mac_header(skb);
hip = (struct hippi_hdr *)skb->mac.raw;
hip = (struct hippi_hdr *)skb_mac_header(skb);
skb_pull(skb, HIPPI_HLEN);

/*
Expand Down
6 changes: 3 additions & 3 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
/* Expand any short form frames */
if (skb->mac.raw[2] == 1) {
if (skb_mac_header(skb)[2] == 1) {
struct ddpehdr *ddp;
/* Find our address */
struct atalk_addr *ap = atalk_find_dev_addr(dev);
Expand All @@ -1510,8 +1510,8 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
* we write the network numbers !
*/

ddp->deh_dnode = skb->mac.raw[0]; /* From physical header */
ddp->deh_snode = skb->mac.raw[1]; /* From physical header */
ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */
ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */

ddp->deh_dnet = ap->s_net; /* Network number */
ddp->deh_snet = ap->s_net;
Expand Down
5 changes: 3 additions & 2 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,9 +1645,10 @@ static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
ax25_digi digi;
ax25_address src;
const unsigned char *mac = skb_mac_header(skb);

ax25_addr_parse(skb->mac.raw+1, skb->data-skb->mac.raw-1, &src, NULL, &digi, NULL, NULL);

ax25_addr_parse(mac + 1, skb->data - mac - 1, &src, NULL,
&digi, NULL, NULL);
sax->sax25_family = AF_AX25;
/* We set this correctly, even though we may not let the
application know the digi calls further down (because it
Expand Down
Loading

0 comments on commit 98e399f

Please sign in to comment.