Skip to content

Commit d56f90a

Browse files
acmelDavid S. Miller
authored andcommitted
[SK_BUFF]: Introduce skb_network_header()
For the places where we need a pointer to the network header, it is still legal to touch skb->nh.raw directly if just adding to, subtracting from or setting it to another layer header. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bbe735e commit d56f90a

59 files changed

Lines changed: 258 additions & 185 deletions

Some content is hidden

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

‎drivers/isdn/i4l/isdn_net.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,15 +872,16 @@ typedef struct {
872872
static void
873873
isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
874874
{
875-
u_char *p = skb->nh.raw; /* hopefully, this was set correctly */
875+
/* hopefully, this was set correctly */
876+
const u_char *p = skb_network_header(skb);
876877
unsigned short proto = ntohs(skb->protocol);
877878
int data_ofs;
878879
ip_ports *ipp;
879880
char addinfo[100];
880881

881882
addinfo[0] = '\0';
882883
/* This check stolen from 2.1.72 dev_queue_xmit_nit() */
883-
if (skb->nh.raw < skb->data || skb->nh.raw >= skb->tail) {
884+
if (p < skb->data || p >= skb->tail) {
884885
/* fall back to old isdn_net_log_packet method() */
885886
char * buf = skb->data;
886887

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct arp_pkt {
106106

107107
static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb)
108108
{
109-
return (struct arp_pkt *)skb->nh.raw;
109+
return (struct arp_pkt *)skb_network_header(skb);
110110
}
111111

112112
/* Forward declaration */

‎drivers/net/loopback.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static DEFINE_PER_CPU(struct pcpu_lstats, pcpu_lstats);
7676
static void emulate_large_send_offload(struct sk_buff *skb)
7777
{
7878
struct iphdr *iph = skb->nh.iph;
79-
struct tcphdr *th = (struct tcphdr*)(skb->nh.raw + (iph->ihl * 4));
79+
struct tcphdr *th = (struct tcphdr *)(skb_network_header(skb) +
80+
(iph->ihl * 4));
8081
unsigned int doffset = (iph->ihl + th->doff) * 4;
8182
unsigned int mtu = skb_shinfo(skb)->gso_size + doffset;
8283
unsigned int offset = 0;
@@ -93,7 +94,7 @@ static void emulate_large_send_offload(struct sk_buff *skb)
9394
skb_set_mac_header(nskb, -ETH_HLEN);
9495
skb_reset_network_header(nskb);
9596
iph = nskb->nh.iph;
96-
memcpy(nskb->data, skb->nh.raw, doffset);
97+
memcpy(nskb->data, skb_network_header(skb), doffset);
9798
if (skb_copy_bits(skb,
9899
doffset + offset,
99100
nskb->data + doffset,
@@ -108,7 +109,7 @@ static void emulate_large_send_offload(struct sk_buff *skb)
108109
memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
109110
nskb->pkt_type = skb->pkt_type;
110111

111-
th = (struct tcphdr*)(nskb->nh.raw + iph->ihl*4);
112+
th = (struct tcphdr *)(skb_network_header(nskb) + iph->ihl * 4);
112113
iph->tot_len = htons(frag_size + doffset);
113114
iph->id = htons(id);
114115
iph->check = 0;

‎drivers/net/pasemi_mac.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,18 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
729729
dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD;
730730

731731
if (skb->ip_summed == CHECKSUM_PARTIAL) {
732+
const unsigned char *nh = skb_network_header(skb);
733+
732734
switch (skb->nh.iph->protocol) {
733735
case IPPROTO_TCP:
734736
dflags |= XCT_MACTX_CSUM_TCP;
735737
dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
736-
dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
738+
dflags |= XCT_MACTX_IPO(nh - skb->data);
737739
break;
738740
case IPPROTO_UDP:
739741
dflags |= XCT_MACTX_CSUM_UDP;
740742
dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
741-
dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
743+
dflags |= XCT_MACTX_IPO(nh - skb->data);
742744
break;
743745
}
744746
}

‎drivers/s390/net/qeth_main.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,9 +3778,11 @@ qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
37783778
}
37793779
/* try something else */
37803780
if (skb->protocol == ETH_P_IPV6)
3781-
return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3781+
return (skb_network_header(skb)[24] == 0xff) ?
3782+
RTN_MULTICAST : 0;
37823783
else if (skb->protocol == ETH_P_IP)
3783-
return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3784+
return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
3785+
RTN_MULTICAST : 0;
37843786
/* ... */
37853787
if (!memcmp(skb->data, skb->dev->broadcast, 6))
37863788
return RTN_BROADCAST;

‎include/linux/if_pppox.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct pppoe_hdr {
116116

117117
static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb)
118118
{
119-
return (struct pppoe_hdr *)skb->nh.raw;
119+
return (struct pppoe_hdr *)skb_network_header(skb);
120120
}
121121

122122
struct pppoe_opt {

‎include/linux/skbuff.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,11 @@ static inline void skb_reserve(struct sk_buff *skb, int len)
960960
skb->tail += len;
961961
}
962962

963+
static inline unsigned char *skb_network_header(const struct sk_buff *skb)
964+
{
965+
return skb->nh.raw;
966+
}
967+
963968
static inline void skb_reset_network_header(struct sk_buff *skb)
964969
{
965970
skb->nh.raw = skb->data;

‎include/net/cipso_ipv4.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ extern int cipso_v4_rbm_strictvalid;
120120
*/
121121

122122
#define CIPSO_V4_OPTEXIST(x) (IPCB(x)->opt.cipso != 0)
123-
#define CIPSO_V4_OPTPTR(x) ((x)->nh.raw + IPCB(x)->opt.cipso)
123+
#define CIPSO_V4_OPTPTR(x) (skb_network_header(x) + IPCB(x)->opt.cipso)
124124

125125
/*
126126
* DOI List Functions

‎include/net/inet_ecn.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ static inline int INET_ECN_set_ce(struct sk_buff *skb)
114114
{
115115
switch (skb->protocol) {
116116
case __constant_htons(ETH_P_IP):
117-
if (skb->nh.raw + sizeof(struct iphdr) <= skb->tail)
117+
if (skb_network_header(skb) + sizeof(struct iphdr) <=
118+
skb->tail)
118119
return IP_ECN_set_ce(skb->nh.iph);
119120
break;
120121

121122
case __constant_htons(ETH_P_IPV6):
122-
if (skb->nh.raw + sizeof(struct ipv6hdr) <= skb->tail)
123+
if (skb_network_header(skb) + sizeof(struct ipv6hdr) <=
124+
skb->tail)
123125
return IP6_ECN_set_ce(skb->nh.ipv6h);
124126
break;
125127
}

‎include/net/llc_pdu.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct llc_pdu_sn {
203203

204204
static inline struct llc_pdu_sn *llc_pdu_sn_hdr(struct sk_buff *skb)
205205
{
206-
return (struct llc_pdu_sn *)skb->nh.raw;
206+
return (struct llc_pdu_sn *)skb_network_header(skb);
207207
}
208208

209209
/* Un-numbered PDU format (3 bytes in length) */
@@ -215,7 +215,7 @@ struct llc_pdu_un {
215215

216216
static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb)
217217
{
218-
return (struct llc_pdu_un *)skb->nh.raw;
218+
return (struct llc_pdu_un *)skb_network_header(skb);
219219
}
220220

221221
/**

0 commit comments

Comments
 (0)