Skip to content

Commit 98e399f

Browse files
acmelDavid S. Miller
authored and
David S. Miller
committed
[SK_BUFF]: Introduce skb_mac_header()
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 <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 31713c3 commit 98e399f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+108
-88
lines changed

arch/um/drivers/daemon_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int daemon_read(int fd, struct sk_buff **skb,
4646
{
4747
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
4848
if(*skb == NULL) return(-ENOMEM);
49-
return(net_recvfrom(fd, (*skb)->mac.raw,
49+
return(net_recvfrom(fd, skb_mac_header(*skb),
5050
(*skb)->dev->mtu + ETH_HEADER_OTHER));
5151
}
5252

arch/um/drivers/mcast_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
5050
{
5151
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
5252
if(*skb == NULL) return(-ENOMEM);
53-
return(net_recvfrom(fd, (*skb)->mac.raw,
53+
return(net_recvfrom(fd, skb_mac_header(*skb),
5454
(*skb)->dev->mtu + ETH_HEADER_OTHER));
5555
}
5656

arch/um/drivers/pcap_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int pcap_read(int fd, struct sk_buff **skb,
3636
{
3737
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
3838
if(*skb == NULL) return(-ENOMEM);
39-
return(pcap_user_read(fd, (*skb)->mac.raw,
39+
return(pcap_user_read(fd, skb_mac_header(*skb),
4040
(*skb)->dev->mtu + ETH_HEADER_OTHER,
4141
(struct pcap_data *) &lp->user));
4242
}

arch/um/drivers/slip_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static unsigned short slip_protocol(struct sk_buff *skbuff)
4949
static int slip_read(int fd, struct sk_buff **skb,
5050
struct uml_net_private *lp)
5151
{
52-
return(slip_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu,
52+
return(slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
5353
(struct slip_data *) &lp->user));
5454
}
5555

arch/um/drivers/slirp_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static unsigned short slirp_protocol(struct sk_buff *skbuff)
5353
static int slirp_read(int fd, struct sk_buff **skb,
5454
struct uml_net_private *lp)
5555
{
56-
return(slirp_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu,
56+
return(slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
5757
(struct slirp_data *) &lp->user));
5858
}
5959

arch/um/os-Linux/drivers/ethertap_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
4343

4444
*skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP);
4545
if(*skb == NULL) return(-ENOMEM);
46-
len = net_recvfrom(fd, (*skb)->mac.raw,
46+
len = net_recvfrom(fd, skb_mac_header(*skb),
4747
(*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP);
4848
if(len <= 0) return(len);
4949
skb_pull(*skb, 2);

arch/um/os-Linux/drivers/tuntap_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int tuntap_read(int fd, struct sk_buff **skb,
4343
{
4444
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
4545
if(*skb == NULL) return(-ENOMEM);
46-
return(net_read(fd, (*skb)->mac.raw,
46+
return(net_read(fd, skb_mac_header(*skb),
4747
(*skb)->dev->mtu + ETH_HEADER_OTHER));
4848
}
4949

drivers/block/aoe/aoe.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct aoe_hdr {
5353

5454
static inline struct aoe_hdr *aoe_hdr(const struct sk_buff *skb)
5555
{
56-
return (struct aoe_hdr *)skb->mac.raw;
56+
return (struct aoe_hdr *)skb_mac_header(skb);
5757
}
5858
#endif
5959

drivers/ieee1394/eth1394.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct eth1394hdr {
9090

9191
static inline struct eth1394hdr *eth1394_hdr(const struct sk_buff *skb)
9292
{
93-
return (struct eth1394hdr *)skb->mac.raw;
93+
return (struct eth1394hdr *)skb_mac_header(skb);
9494
}
9595
#endif
9696

drivers/media/dvb/dvb-core/dvb_net.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static unsigned short dvb_net_eth_type_trans(struct sk_buff *skb,
174174
struct ethhdr *eth;
175175
unsigned char *rawp;
176176

177-
skb->mac.raw=skb->data;
177+
skb_reset_mac_header(skb);
178178
skb_pull(skb,dev->hard_header_len);
179179
eth = eth_hdr(skb);
180180

drivers/message/fusion/mptlan.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
714714
LANSendRequest_t *pSendReq;
715715
SGETransaction32_t *pTrans;
716716
SGESimple64_t *pSimple;
717+
const unsigned char *mac;
717718
dma_addr_t dma;
718719
unsigned long flags;
719720
int ctx;
@@ -784,6 +785,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
784785
// IOC_AND_NETDEV_NAMES_s_s(dev),
785786
// ctx, skb, skb->data));
786787

788+
mac = skb_mac_header(skb);
787789
#ifdef QLOGIC_NAA_WORKAROUND
788790
{
789791
struct NAA_Hosed *nh;
@@ -793,12 +795,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
793795
drops. */
794796
read_lock_irq(&bad_naa_lock);
795797
for (nh = mpt_bad_naa; nh != NULL; nh=nh->next) {
796-
if ((nh->ieee[0] == skb->mac.raw[0]) &&
797-
(nh->ieee[1] == skb->mac.raw[1]) &&
798-
(nh->ieee[2] == skb->mac.raw[2]) &&
799-
(nh->ieee[3] == skb->mac.raw[3]) &&
800-
(nh->ieee[4] == skb->mac.raw[4]) &&
801-
(nh->ieee[5] == skb->mac.raw[5])) {
798+
if ((nh->ieee[0] == mac[0]) &&
799+
(nh->ieee[1] == mac[1]) &&
800+
(nh->ieee[2] == mac[2]) &&
801+
(nh->ieee[3] == mac[3]) &&
802+
(nh->ieee[4] == mac[4]) &&
803+
(nh->ieee[5] == mac[5])) {
802804
cur_naa = nh->NAA;
803805
dlprintk ((KERN_INFO "mptlan/sdu_send: using NAA value "
804806
"= %04x.\n", cur_naa));
@@ -810,12 +812,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
810812
#endif
811813

812814
pTrans->TransactionDetails[0] = cpu_to_le32((cur_naa << 16) |
813-
(skb->mac.raw[0] << 8) |
814-
(skb->mac.raw[1] << 0));
815-
pTrans->TransactionDetails[1] = cpu_to_le32((skb->mac.raw[2] << 24) |
816-
(skb->mac.raw[3] << 16) |
817-
(skb->mac.raw[4] << 8) |
818-
(skb->mac.raw[5] << 0));
815+
(mac[0] << 8) |
816+
(mac[1] << 0));
817+
pTrans->TransactionDetails[1] = cpu_to_le32((mac[2] << 24) |
818+
(mac[3] << 16) |
819+
(mac[4] << 8) |
820+
(mac[5] << 0));
819821

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

drivers/net/arcnet/capmode.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void rx(struct net_device *dev, int bufnum,
123123
skb_put(skb, length + ARC_HDR_SIZE + sizeof(int));
124124
skb->dev = dev;
125125
skb_reset_mac_header(skb);
126-
pkt = (struct archdr *)skb->mac.raw;
126+
pkt = (struct archdr *)skb_mac_header(skb);
127127
skb_pull(skb, ARC_HDR_SIZE);
128128

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

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

275275

drivers/net/plip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
546546
struct ethhdr *eth;
547547
unsigned char *rawp;
548548

549-
skb->mac.raw=skb->data;
549+
skb_reset_mac_header(skb);
550550
skb_pull(skb,dev->hard_header_len);
551551
eth = eth_hdr(skb);
552552

drivers/net/slip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ sl_bump(struct slip *sl)
363363
}
364364
skb->dev = sl->dev;
365365
memcpy(skb_put(skb,count), sl->rbuff, count);
366-
skb->mac.raw=skb->data;
366+
skb_reset_mac_header(skb);
367367
skb->protocol=htons(ETH_P_IP);
368368
netif_rx(skb);
369369
sl->dev->last_rx = jiffies;

drivers/net/wan/hostess_sv11.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
5959
/* Drop the CRC - it's not a good idea to try and negotiate it ;) */
6060
skb_trim(skb, skb->len-2);
6161
skb->protocol=__constant_htons(ETH_P_WAN_PPP);
62-
skb->mac.raw=skb->data;
62+
skb_reset_mac_header(skb);
6363
skb->dev=c->netdevice;
6464
/*
6565
* Send it to the PPP layer. We don't have time to process

drivers/net/wan/sealevel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
6161
/* Drop the CRC - it's not a good idea to try and negotiate it ;) */
6262
skb_trim(skb, skb->len-2);
6363
skb->protocol=htons(ETH_P_WAN_PPP);
64-
skb->mac.raw=skb->data;
64+
skb_reset_mac_header(skb);
6565
skb->dev=c->netdevice;
6666
/*
6767
* Send it to the PPP layer. We don't have time to process

drivers/net/wan/syncppp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static void sppp_input (struct net_device *dev, struct sk_buff *skb)
227227
unsigned long flags;
228228

229229
skb->dev=dev;
230-
skb->mac.raw=skb->data;
230+
skb_reset_mac_header(skb);
231231

232232
if (dev->flags & IFF_RUNNING)
233233
{

drivers/net/wireless/airo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ static int add_airo_dev( struct net_device *dev );
24442444

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

drivers/net/wireless/hostap/hostap_main.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -590,20 +590,20 @@ void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
590590

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

597597

598598
int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr)
599599
{
600-
if (*(u32 *)skb->mac.raw == LWNG_CAP_DID_BASE) {
601-
memcpy(haddr, skb->mac.raw +
602-
sizeof(struct linux_wlan_ng_prism_hdr) + 10,
600+
const unsigned char *mac = skb_mac_header(skb);
601+
602+
if (*(u32 *)mac == LWNG_CAP_DID_BASE) {
603+
memcpy(haddr, mac + sizeof(struct linux_wlan_ng_prism_hdr) + 10,
603604
ETH_ALEN); /* addr2 */
604-
} else { /* (*(u32 *)skb->mac.raw == htonl(LWNG_CAPHDR_VERSION)) */
605-
memcpy(haddr, skb->mac.raw +
606-
sizeof(struct linux_wlan_ng_cap_hdr) + 10,
605+
} else { /* (*(u32 *)mac == htonl(LWNG_CAPHDR_VERSION)) */
606+
memcpy(haddr, mac + sizeof(struct linux_wlan_ng_cap_hdr) + 10,
607607
ETH_ALEN); /* addr2 */
608608
}
609609
return ETH_ALEN;

drivers/net/wireless/orinoco.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static void orinoco_stat_gather(struct net_device *dev,
689689
/* Note : gcc will optimise the whole section away if
690690
* WIRELESS_SPY is not defined... - Jean II */
691691
if (SPY_NUMBER(priv)) {
692-
orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
692+
orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
693693
desc->signal, desc->silence);
694694
}
695695
}

drivers/net/wireless/wavelan.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,8 @@ wv_packet_read(struct net_device * dev, u16 buf_off, int sksize)
25172517
skb->protocol = eth_type_trans(skb, dev);
25182518

25192519
#ifdef DEBUG_RX_INFO
2520-
wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2520+
wv_packet_info(skb_mac_header(skb), sksize, dev->name,
2521+
"wv_packet_read");
25212522
#endif /* DEBUG_RX_INFO */
25222523

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

25542555
/* Spying stuff */
25552556
#ifdef IW_WIRELESS_SPY
2556-
wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
2557+
wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE,
25572558
stats);
25582559
#endif /* IW_WIRELESS_SPY */
25592560
#ifdef HISTOGRAM

drivers/net/wireless/wavelan_cs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ wv_packet_read(struct net_device * dev,
28892889
skb->protocol = eth_type_trans(skb, dev);
28902890

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

28952895
/* Statistics gathering & stuff associated.
@@ -2923,7 +2923,7 @@ wv_packet_read(struct net_device * dev,
29232923
#endif /* WAVELAN_ROAMING */
29242924

29252925
#ifdef WIRELESS_SPY
2926-
wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2926+
wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, stats);
29272927
#endif /* WIRELESS_SPY */
29282928
#ifdef HISTOGRAM
29292929
wl_his_gather(dev, stats);

drivers/s390/net/claw.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3525,8 +3525,8 @@ unpack_read(struct net_device *dev )
35253525
memcpy(skb_put(skb,len_of_data),
35263526
privptr->p_mtc_envelope,
35273527
len_of_data);
3528-
skb->mac.raw=skb->data;
35293528
skb->dev=dev;
3529+
skb_reset_mac_header(skb);
35303530
skb->protocol=htons(ETH_P_IP);
35313531
skb->ip_summed=CHECKSUM_UNNECESSARY;
35323532
privptr->stats.rx_packets++;

include/linux/if_ether.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct ethhdr {
112112

113113
static inline struct ethhdr *eth_hdr(const struct sk_buff *skb)
114114
{
115-
return (struct ethhdr *)skb->mac.raw;
115+
return (struct ethhdr *)skb_mac_header(skb);
116116
}
117117

118118
#ifdef CONFIG_SYSCTL

include/linux/if_tr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct trh_hdr {
4747

4848
static inline struct trh_hdr *tr_hdr(const struct sk_buff *skb)
4949
{
50-
return (struct trh_hdr *)skb->mac.raw;
50+
return (struct trh_hdr *)skb_mac_header(skb);
5151
}
5252
#ifdef CONFIG_SYSCTL
5353
extern struct ctl_table tr_table[];

include/linux/if_vlan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct vlan_ethhdr {
5151

5252
static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
5353
{
54-
return (struct vlan_ethhdr *)skb->mac.raw;
54+
return (struct vlan_ethhdr *)skb_mac_header(skb);
5555
}
5656

5757
struct vlan_hdr {

include/linux/netfilter_bridge/ebt_802_3.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct ebt_802_3_hdr {
5454

5555
static inline struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
5656
{
57-
return (struct ebt_802_3_hdr *)skb->mac.raw;
57+
return (struct ebt_802_3_hdr *)skb_mac_header(skb);
5858
}
5959
#endif
6060

include/linux/skbuff.h

+10
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,16 @@ static inline void skb_reserve(struct sk_buff *skb, int len)
960960
skb->tail += len;
961961
}
962962

963+
static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
964+
{
965+
return skb->mac.raw;
966+
}
967+
968+
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
969+
{
970+
return skb->mac.raw != NULL;
971+
}
972+
963973
static inline void skb_reset_mac_header(struct sk_buff *skb)
964974
{
965975
skb->mac.raw = skb->data;

net/802/hippi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ __be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)
132132
*/
133133
skb->dev = dev;
134134
skb_reset_mac_header(skb);
135-
hip = (struct hippi_hdr *)skb->mac.raw;
135+
hip = (struct hippi_hdr *)skb_mac_header(skb);
136136
skb_pull(skb, HIPPI_HLEN);
137137

138138
/*

net/appletalk/ddp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
14841484
struct packet_type *pt, struct net_device *orig_dev)
14851485
{
14861486
/* Expand any short form frames */
1487-
if (skb->mac.raw[2] == 1) {
1487+
if (skb_mac_header(skb)[2] == 1) {
14881488
struct ddpehdr *ddp;
14891489
/* Find our address */
14901490
struct atalk_addr *ap = atalk_find_dev_addr(dev);
@@ -1510,8 +1510,8 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
15101510
* we write the network numbers !
15111511
*/
15121512

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

15161516
ddp->deh_dnet = ap->s_net; /* Network number */
15171517
ddp->deh_snet = ap->s_net;

net/ax25/af_ax25.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,10 @@ static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
16451645
struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
16461646
ax25_digi digi;
16471647
ax25_address src;
1648+
const unsigned char *mac = skb_mac_header(skb);
16481649

1649-
ax25_addr_parse(skb->mac.raw+1, skb->data-skb->mac.raw-1, &src, NULL, &digi, NULL, NULL);
1650-
1650+
ax25_addr_parse(mac + 1, skb->data - mac - 1, &src, NULL,
1651+
&digi, NULL, NULL);
16511652
sax->sax25_family = AF_AX25;
16521653
/* We set this correctly, even though we may not let the
16531654
application know the digi calls further down (because it

0 commit comments

Comments
 (0)