Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_network_header()
Browse files Browse the repository at this point in the history
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 <[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 bbe735e commit d56f90a
Show file tree
Hide file tree
Showing 59 changed files with 258 additions and 185 deletions.
5 changes: 3 additions & 2 deletions drivers/isdn/i4l/isdn_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,15 +872,16 @@ typedef struct {
static void
isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
{
u_char *p = skb->nh.raw; /* hopefully, this was set correctly */
/* hopefully, this was set correctly */
const u_char *p = skb_network_header(skb);
unsigned short proto = ntohs(skb->protocol);
int data_ofs;
ip_ports *ipp;
char addinfo[100];

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

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bonding/bond_alb.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct arp_pkt {

static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb)
{
return (struct arp_pkt *)skb->nh.raw;
return (struct arp_pkt *)skb_network_header(skb);
}

/* Forward declaration */
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ static DEFINE_PER_CPU(struct pcpu_lstats, pcpu_lstats);
static void emulate_large_send_offload(struct sk_buff *skb)
{
struct iphdr *iph = skb->nh.iph;
struct tcphdr *th = (struct tcphdr*)(skb->nh.raw + (iph->ihl * 4));
struct tcphdr *th = (struct tcphdr *)(skb_network_header(skb) +
(iph->ihl * 4));
unsigned int doffset = (iph->ihl + th->doff) * 4;
unsigned int mtu = skb_shinfo(skb)->gso_size + doffset;
unsigned int offset = 0;
Expand All @@ -93,7 +94,7 @@ static void emulate_large_send_offload(struct sk_buff *skb)
skb_set_mac_header(nskb, -ETH_HLEN);
skb_reset_network_header(nskb);
iph = nskb->nh.iph;
memcpy(nskb->data, skb->nh.raw, doffset);
memcpy(nskb->data, skb_network_header(skb), doffset);
if (skb_copy_bits(skb,
doffset + offset,
nskb->data + doffset,
Expand All @@ -108,7 +109,7 @@ static void emulate_large_send_offload(struct sk_buff *skb)
memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
nskb->pkt_type = skb->pkt_type;

th = (struct tcphdr*)(nskb->nh.raw + iph->ihl*4);
th = (struct tcphdr *)(skb_network_header(nskb) + iph->ihl * 4);
iph->tot_len = htons(frag_size + doffset);
iph->id = htons(id);
iph->check = 0;
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/pasemi_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,18 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD;

if (skb->ip_summed == CHECKSUM_PARTIAL) {
const unsigned char *nh = skb_network_header(skb);

switch (skb->nh.iph->protocol) {
case IPPROTO_TCP:
dflags |= XCT_MACTX_CSUM_TCP;
dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
dflags |= XCT_MACTX_IPO(nh - skb->data);
break;
case IPPROTO_UDP:
dflags |= XCT_MACTX_CSUM_UDP;
dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
dflags |= XCT_MACTX_IPO(nh - skb->data);
break;
}
}
Expand Down
6 changes: 4 additions & 2 deletions drivers/s390/net/qeth_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3778,9 +3778,11 @@ qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
}
/* try something else */
if (skb->protocol == ETH_P_IPV6)
return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
return (skb_network_header(skb)[24] == 0xff) ?
RTN_MULTICAST : 0;
else if (skb->protocol == ETH_P_IP)
return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
RTN_MULTICAST : 0;
/* ... */
if (!memcmp(skb->data, skb->dev->broadcast, 6))
return RTN_BROADCAST;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/if_pppox.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct pppoe_hdr {

static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb)
{
return (struct pppoe_hdr *)skb->nh.raw;
return (struct pppoe_hdr *)skb_network_header(skb);
}

struct pppoe_opt {
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 unsigned char *skb_network_header(const struct sk_buff *skb)
{
return skb->nh.raw;
}

static inline void skb_reset_network_header(struct sk_buff *skb)
{
skb->nh.raw = skb->data;
Expand Down
2 changes: 1 addition & 1 deletion include/net/cipso_ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extern int cipso_v4_rbm_strictvalid;
*/

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

/*
* DOI List Functions
Expand Down
6 changes: 4 additions & 2 deletions include/net/inet_ecn.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ static inline int INET_ECN_set_ce(struct sk_buff *skb)
{
switch (skb->protocol) {
case __constant_htons(ETH_P_IP):
if (skb->nh.raw + sizeof(struct iphdr) <= skb->tail)
if (skb_network_header(skb) + sizeof(struct iphdr) <=
skb->tail)
return IP_ECN_set_ce(skb->nh.iph);
break;

case __constant_htons(ETH_P_IPV6):
if (skb->nh.raw + sizeof(struct ipv6hdr) <= skb->tail)
if (skb_network_header(skb) + sizeof(struct ipv6hdr) <=
skb->tail)
return IP6_ECN_set_ce(skb->nh.ipv6h);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions include/net/llc_pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct llc_pdu_sn {

static inline struct llc_pdu_sn *llc_pdu_sn_hdr(struct sk_buff *skb)
{
return (struct llc_pdu_sn *)skb->nh.raw;
return (struct llc_pdu_sn *)skb_network_header(skb);
}

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

static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb)
{
return (struct llc_pdu_un *)skb->nh.raw;
return (struct llc_pdu_un *)skb_network_header(skb);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/net/pkt_cls.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
case TCF_LAYER_LINK:
return skb->data;
case TCF_LAYER_NETWORK:
return skb->nh.raw;
return skb_network_header(skb);
case TCF_LAYER_TRANSPORT:
return skb->h.raw;
}
Expand Down
12 changes: 7 additions & 5 deletions net/bridge/br_netfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ static int check_hbh_len(struct sk_buff *skb)
{
unsigned char *raw = (u8 *) (skb->nh.ipv6h + 1);
u32 pkt_len;
int off = raw - skb->nh.raw;
const unsigned char *nh = skb_network_header(skb);
int off = raw - nh;
int len = (raw[1] + 1) << 3;

if ((raw + len) - skb->data > skb_headlen(skb))
Expand All @@ -384,9 +385,9 @@ static int check_hbh_len(struct sk_buff *skb)
len -= 2;

while (len > 0) {
int optlen = skb->nh.raw[off + 1] + 2;
int optlen = nh[off + 1] + 2;

switch (skb->nh.raw[off]) {
switch (nh[off]) {
case IPV6_TLV_PAD0:
optlen = 1;
break;
Expand All @@ -395,9 +396,9 @@ static int check_hbh_len(struct sk_buff *skb)
break;

case IPV6_TLV_JUMBO:
if (skb->nh.raw[off + 1] != 4 || (off & 3) != 2)
if (nh[off + 1] != 4 || (off & 3) != 2)
goto bad;
pkt_len = ntohl(*(__be32 *) (skb->nh.raw + off + 2));
pkt_len = ntohl(*(__be32 *) (nh + off + 2));
if (pkt_len <= IPV6_MAXPLEN ||
skb->nh.ipv6h->payload_len)
goto bad;
Expand All @@ -406,6 +407,7 @@ static int check_hbh_len(struct sk_buff *skb)
if (pskb_trim_rcsum(skb,
pkt_len + sizeof(struct ipv6hdr)))
goto bad;
nh = skb_network_header(skb);
break;
default:
if (optlen > len)
Expand Down
9 changes: 5 additions & 4 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,8 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
*/
skb_reset_mac_header(skb2);

if (skb2->nh.raw < skb2->data ||
skb2->nh.raw > skb2->tail) {
if (skb_network_header(skb2) < skb2->data ||
skb_network_header(skb2) > skb2->tail) {
if (net_ratelimit())
printk(KERN_CRIT "protocol %04x is "
"buggy, dev %s\n",
Expand Down Expand Up @@ -1207,7 +1207,7 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
BUG_ON(skb_shinfo(skb)->frag_list);

skb_reset_mac_header(skb);
skb->mac_len = skb->nh.raw - skb->data;
skb->mac_len = skb->nh.raw - skb->mac.raw;
__skb_pull(skb, skb->mac_len);

if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
Expand All @@ -1224,7 +1224,8 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
segs = ERR_PTR(err);
if (err || skb_gso_ok(skb, features))
break;
__skb_push(skb, skb->data - skb->nh.raw);
__skb_push(skb, (skb->data -
skb_network_header(skb)));
}
segs = ptype->gso_segment(skb, features);
break;
Expand Down
2 changes: 1 addition & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void *__load_pointer(struct sk_buff *skb, int k)
u8 *ptr = NULL;

if (k >= SKF_NET_OFF)
ptr = skb->nh.raw + k - SKF_NET_OFF;
ptr = skb_network_header(skb) + k - SKF_NET_OFF;
else if (k >= SKF_LL_OFF)
ptr = skb_mac_header(skb) + k - SKF_LL_OFF;

Expand Down
8 changes: 4 additions & 4 deletions net/dccp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,

if (rxopt->srcrt)
opt = ipv6_invert_rthdr(sk,
(struct ipv6_rt_hdr *)(pktopts->nh.raw +
rxopt->srcrt));
(struct ipv6_rt_hdr *)(skb_network_header(pktopts) +
rxopt->srcrt));
}

if (opt != NULL && opt->srcrt != NULL) {
Expand Down Expand Up @@ -573,8 +573,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,

if (rxopt->srcrt)
opt = ipv6_invert_rthdr(sk,
(struct ipv6_rt_hdr *)(ireq6->pktopts->nh.raw +
rxopt->srcrt));
(struct ipv6_rt_hdr *)(skb_network_header(ireq6->pktopts) +
rxopt->srcrt));
}

if (dst == NULL) {
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 @@ -386,7 +386,7 @@ static int dn_return_short(struct sk_buff *skb)
__le16 tmp;

/* Add back headers */
skb_push(skb, skb->data - skb->nh.raw);
skb_push(skb, skb->data - skb_network_header(skb));

if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
return NET_RX_DROP;
Expand Down Expand Up @@ -425,7 +425,7 @@ static int dn_return_long(struct sk_buff *skb)
unsigned char tmp[ETH_ALEN];

/* Add back all headers */
skb_push(skb, skb->data - skb->nh.raw);
skb_push(skb, skb->data - skb_network_header(skb));

if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
return NET_RX_DROP;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
iph->id = htons(id++);
iph->tot_len = htons(skb->len - skb->mac_len);
iph->check = 0;
iph->check = ip_fast_csum(skb->nh.raw, iph->ihl);
iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
} while ((skb = skb->next));

out:
Expand Down
5 changes: 3 additions & 2 deletions net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
ah = (struct ip_auth_hdr*)skb->data;
iph = skb->nh.iph;

ihl = skb->data - skb->nh.raw;
ihl = skb->data - skb_network_header(skb);
memcpy(work_buf, iph, ihl);

iph->ttl = 0;
Expand All @@ -181,7 +181,8 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
}
}
((struct iphdr*)work_buf)->protocol = ah->nexthdr;
skb->h.raw = memcpy(skb->nh.raw += ah_hlen, work_buf, ihl);
skb->nh.raw += ah_hlen;
skb->h.raw = memcpy(skb_network_header(skb), work_buf, ihl);
__skb_pull(skb, ah_hlen + ihl);

return 0;
Expand Down
7 changes: 4 additions & 3 deletions net/ipv4/esp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
*(u8*)(trailer->tail + clen-skb->len - 2) = (clen - skb->len)-2;
pskb_put(skb, trailer, clen - skb->len);

__skb_push(skb, skb->data - skb->nh.raw);
__skb_push(skb, skb->data - skb_network_header(skb));
top_iph = skb->nh.iph;
esph = (struct ip_esp_hdr *)(skb->nh.raw + top_iph->ihl*4);
esph = (struct ip_esp_hdr *)(skb_network_header(skb) +
top_iph->ihl * 4);
top_iph->tot_len = htons(skb->len + alen);
*(u8*)(trailer->tail - 1) = top_iph->protocol;

Expand Down Expand Up @@ -222,7 +223,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)

if (x->encap) {
struct xfrm_encap_tmpl *encap = x->encap;
struct udphdr *uh = (void *)(skb->nh.raw + ihl);
struct udphdr *uh = (void *)(skb_network_header(skb) + ihl);

/*
* 1) if the NAT-T peer's IP or port changed then
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
u8 _inner_type, *itp;

itp = skb_header_pointer(skb_in,
skb_in->nh.raw +
skb_network_header(skb_in) +
(iph->ihl << 2) +
offsetof(struct icmphdr,
type) -
Expand Down Expand Up @@ -536,7 +536,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
icmp_param.data.icmph.un.gateway = info;
icmp_param.data.icmph.checksum = 0;
icmp_param.skb = skb_in;
icmp_param.offset = skb_in->nh.raw - skb_in->data;
icmp_param.offset = skb_network_offset(skb_in);
icmp_out_count(icmp_param.data.icmph.type);
inet_sk(icmp_socket->sk)->tos = tos;
ipc.addr = iph->saddr;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
}

skb_shinfo(head)->frag_list = head->next;
skb_push(head, head->data - head->nh.raw);
skb_push(head, head->data - skb_network_header(head));
atomic_sub(head->truesize, &ip_frag_mem);

for (fp=head->next; fp; fp = fp->next) {
Expand Down
Loading

0 comments on commit d56f90a

Please sign in to comment.