Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_transport_header(skb)
Browse files Browse the repository at this point in the history
For the places where we need a pointer to the transport header, it is
still legal to touch skb->h.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 a27ef74 commit 9c70220
Show file tree
Hide file tree
Showing 42 changed files with 129 additions and 102 deletions.
7 changes: 5 additions & 2 deletions drivers/net/appletalk/ltpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ static int ltpc_xmit(struct sk_buff *skb, struct net_device *dev)

int i;
struct lt_sendlap cbuf;
unsigned char *hdr;

cbuf.command = LT_SENDLAP;
cbuf.dnode = skb->data[0];
Expand All @@ -932,11 +933,13 @@ static int ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
printk("\n");
}

do_write(dev,&cbuf,sizeof(cbuf),skb->h.raw,skb->len);
hdr = skb_transport_header(skb);
do_write(dev, &cbuf, sizeof(cbuf), hdr, skb->len);

if(debug & DEBUG_UPPER) {
printk("sent %d ddp bytes\n",skb->len);
for(i=0;i<skb->len;i++) printk("%02x ",skb->h.raw[i]);
for (i = 0; i < skb->len; i++)
printk("%02x ", hdr[i]);
printk("\n");
}

Expand Down
8 changes: 5 additions & 3 deletions drivers/net/cxgb3/sge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,12 +1324,14 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,

flits = skb_transport_offset(skb) / 8;
sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
sgl_flits = make_sgl(skb, sgp, skb->h.raw, skb->tail - skb->h.raw,
sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
skb->tail - skb_transport_header(skb),
adap->pdev);
if (need_skb_unmap()) {
setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
skb->destructor = deferred_unmap_destructor;
((struct unmap_info *)skb->cb)->len = skb->tail - skb->h.raw;
((struct unmap_info *)skb->cb)->len = (skb->tail -
skb_transport_header(skb));
}

write_wr_hdr_sgl(ndesc, skb, d, pidx, q, sgl, flits, sgl_flits,
Expand All @@ -1351,7 +1353,7 @@ static inline unsigned int calc_tx_descs_ofld(const struct sk_buff *skb)
return 1; /* packet fits as immediate data */

flits = skb_transport_offset(skb) / 8; /* headers */
if (skb->tail != skb->h.raw)
if (skb->tail != skb_transport_header(skb))
cnt++;
return flits_to_desc(flits + sgl_len(cnt));
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/s390/net/qeth_eddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ qeth_eddp_fill_context_tcp(struct qeth_eddp_context *ctx,
eddp = qeth_eddp_create_eddp_data(qhdr,
skb_network_header(skb),
ip_hdrlen(skb),
skb->h.raw,
skb_transport_header(skb),
tcp_hdrlen(skb));
else
eddp = qeth_eddp_create_eddp_data(qhdr,
skb_network_header(skb),
sizeof(struct ipv6hdr),
skb->h.raw,
skb_transport_header(skb),
tcp_hdrlen(skb));

if (eddp == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions include/linux/atalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct ddpehdr {

static __inline__ struct ddpehdr *ddp_hdr(struct sk_buff *skb)
{
return (struct ddpehdr *)skb->h.raw;
return (struct ddpehdr *)skb_transport_header(skb);
}

/* AppleTalk AARP headers */
Expand Down Expand Up @@ -129,7 +129,7 @@ struct elapaarp {

static __inline__ struct elapaarp *aarp_hdr(struct sk_buff *skb)
{
return (struct elapaarp *)skb->h.raw;
return (struct elapaarp *)skb_transport_header(skb);
}

/* Not specified - how long till we drop a resolved entry */
Expand Down
19 changes: 12 additions & 7 deletions include/linux/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,20 @@ enum {

static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
{
return (struct dccp_hdr *)skb->h.raw;
return (struct dccp_hdr *)skb_transport_header(skb);
}

static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
{
skb_push(skb, headlen);
skb_reset_transport_header(skb);
return memset(skb->h.raw, 0, headlen);
return memset(skb_transport_header(skb), 0, headlen);
}

static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
{
return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
return (struct dccp_hdr_ext *)(skb_transport_header(skb) +
sizeof(struct dccp_hdr));
}

static inline unsigned int __dccp_basic_hdr_len(const struct dccp_hdr *dh)
Expand Down Expand Up @@ -301,12 +302,14 @@ static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)

static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb)
{
return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb));
return (struct dccp_hdr_request *)(skb_transport_header(skb) +
dccp_basic_hdr_len(skb));
}

static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb)
{
return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb));
return (struct dccp_hdr_ack_bits *)(skb_transport_header(skb) +
dccp_basic_hdr_len(skb));
}

static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
Expand All @@ -317,12 +320,14 @@ static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)

static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
{
return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb));
return (struct dccp_hdr_response *)(skb_transport_header(skb) +
dccp_basic_hdr_len(skb));
}

static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb)
{
return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb));
return (struct dccp_hdr_reset *)(skb_transport_header(skb) +
dccp_basic_hdr_len(skb));
}

static inline unsigned int __dccp_hdr_len(const struct dccp_hdr *dh)
Expand Down
2 changes: 1 addition & 1 deletion include/linux/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct icmphdr {

static inline struct icmphdr *icmp_hdr(const struct sk_buff *skb)
{
return (struct icmphdr *)skb->h.raw;
return (struct icmphdr *)skb_transport_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/linux/icmpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct icmp6hdr {

static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
{
return (struct icmp6hdr *)skb->h.raw;
return (struct icmp6hdr *)skb_transport_header(skb);
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions include/linux/igmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ struct igmpv3_query {

static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
{
return (struct igmphdr *)skb->h.raw;
return (struct igmphdr *)skb_transport_header(skb);
}

static inline struct igmpv3_report *
igmpv3_report_hdr(const struct sk_buff *skb)
{
return (struct igmpv3_report *)skb->h.raw;
return (struct igmpv3_report *)skb_transport_header(skb);
}

static inline struct igmpv3_query *
igmpv3_query_hdr(const struct sk_buff *skb)
{
return (struct igmpv3_query *)skb->h.raw;
return (struct igmpv3_query *)skb_transport_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/linux/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static inline struct iphdr *ip_hdr(const struct sk_buff *skb)

static inline struct iphdr *ipip_hdr(const struct sk_buff *skb)
{
return (struct iphdr *)skb->h.raw;
return (struct iphdr *)skb_transport_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/linux/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)

static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
{
return (struct ipv6hdr *)skb->h.raw;
return (struct ipv6hdr *)skb_transport_header(skb);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion include/linux/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct sctphdr {

static inline struct sctphdr *sctp_hdr(const struct sk_buff *skb)
{
return (struct sctphdr *)skb->h.raw;
return (struct sctphdr *)skb_transport_header(skb);
}
#endif

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

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

static inline void skb_reset_transport_header(struct sk_buff *skb)
{
skb->h.raw = skb->data;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct tcp_md5sig {

static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
{
return (struct tcphdr *)skb->h.raw;
return (struct tcphdr *)skb_transport_header(skb);
}

static inline unsigned int tcp_hdrlen(const struct sk_buff *skb)
Expand Down
2 changes: 1 addition & 1 deletion include/linux/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct udphdr {

static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
return (struct udphdr *)skb->h.raw;
return (struct udphdr *)skb_transport_header(skb);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/net/ipx.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ipxhdr {

static __inline__ struct ipxhdr *ipx_hdr(struct sk_buff *skb)
{
return (struct ipxhdr *)skb->h.raw;
return (struct ipxhdr *)skb_transport_header(skb);
}

struct ipx_interface {
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 @@ -328,7 +328,7 @@ static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
case TCF_LAYER_NETWORK:
return skb_network_header(skb);
case TCF_LAYER_TRANSPORT:
return skb->h.raw;
return skb_transport_header(skb);
}

return NULL;
Expand Down
4 changes: 2 additions & 2 deletions include/net/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ static inline int udp_lib_checksum_complete(struct sk_buff *skb)
*/
static inline __wsum udp_csum_outgoing(struct sock *sk, struct sk_buff *skb)
{
__wsum csum = csum_partial(skb->h.raw, sizeof(struct udphdr), 0);

__wsum csum = csum_partial(skb_transport_header(skb),
sizeof(struct udphdr), 0);
skb_queue_walk(&sk->sk_write_queue, skb) {
csum = csum_add(csum, skb->csum);
}
Expand Down
2 changes: 1 addition & 1 deletion net/802/psnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
};

rcu_read_lock();
proto = find_snap_client(skb->h.raw);
proto = find_snap_client(skb_transport_header(skb));
if (proto) {
/* Pass the frame on. */
skb->h.raw += 5;
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 @@ -1585,9 +1585,10 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,

skb_set_transport_header(skb, lv);

SOCK_DEBUG(sk, "base=%p pos=%p\n", skb->data, skb->h.raw);
SOCK_DEBUG(sk, "base=%p pos=%p\n",
skb->data, skb_transport_header(skb));

*skb->h.raw = AX25_UI;
*skb_transport_header(skb) = AX25_UI;

/* Datagram frames go straight out of the door as UI */
ax25_queue_xmit(skb, ax25->ax25_dev->dev);
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)

skb_push(skb, HCI_ACL_HDR_SIZE);
skb_reset_transport_header(skb);
hdr = (struct hci_acl_hdr *)skb->h.raw;
hdr = (struct hci_acl_hdr *)skb_transport_header(skb);
hdr->handle = cpu_to_le16(hci_handle_pack(handle, flags));
hdr->dlen = cpu_to_le16(len);
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)

skb_push(skb, HCI_SCO_HDR_SIZE);
skb_reset_transport_header(skb);
memcpy(skb->h.raw, &hdr, HCI_SCO_HDR_SIZE);
memcpy(skb_transport_header(skb), &hdr, HCI_SCO_HDR_SIZE);

skb->dev = (void *) hdev;
bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
Expand Down
6 changes: 3 additions & 3 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,12 @@ int skb_checksum_help(struct sk_buff *skb)
BUG_ON(offset > (int)skb->len);
csum = skb_checksum(skb, offset, skb->len-offset, 0);

offset = skb->tail - skb->h.raw;
offset = skb->tail - skb_transport_header(skb);
BUG_ON(offset <= 0);
BUG_ON(skb->csum_offset + 2 > offset);

*(__sum16*)(skb->h.raw + skb->csum_offset) = csum_fold(csum);

*(__sum16 *)(skb_transport_header(skb) +
skb->csum_offset) = csum_fold(csum);
out_set_summed:
skb->ip_summed = CHECKSUM_NONE;
out:
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 @@ -943,7 +943,7 @@ static void aun_data_available(struct sock *sk, int slen)
printk(KERN_DEBUG "AUN: recvfrom() error %d\n", -err);
}

data = skb->h.raw + sizeof(struct udphdr);
data = skb_transport_header(skb) + sizeof(struct udphdr);
ah = (struct aunhdr *)data;
len = skb->len - sizeof(struct udphdr);
ip = ip_hdr(skb);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int igmpv3_sendpack(struct sk_buff *skb)
struct iphdr *pip = ip_hdr(skb);
struct igmphdr *pig = igmp_hdr(skb);
const int iplen = skb->tail - skb->nh.raw;
const int igmplen = skb->tail - skb->h.raw;
const int igmplen = skb->tail - skb_transport_header(skb);

pip->tot_len = htons(iplen);
ip_send_check(pip);
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 @@ -619,7 +619,7 @@ static int ipgre_rcv(struct sk_buff *skb)
skb_reset_mac_header(skb);
__pskb_pull(skb, offset);
skb_reset_network_header(skb);
skb_postpull_rcsum(skb, skb->h.raw, offset);
skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
skb->pkt_type = PACKET_HOST;
#ifdef CONFIG_NET_IPGRE_BROADCAST
if (MULTICAST(iph->daddr)) {
Expand Down
6 changes: 4 additions & 2 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ ssize_t ip_append_page(struct sock *sk, struct page *page,
if (fraggap) {
skb->csum = skb_copy_and_csum_bits(skb_prev,
maxfraglen,
skb->h.raw,
skb_transport_header(skb),
fraggap, 0);
skb_prev->csum = csum_sub(skb_prev->csum,
skb->csum);
Expand Down Expand Up @@ -1374,7 +1374,9 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
&ipc, rt, MSG_DONTWAIT);
if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) {
if (arg->csumoffset >= 0)
*((__sum16 *)skb->h.raw + arg->csumoffset) = csum_fold(csum_add(skb->csum, arg->csum));
*((__sum16 *)skb_transport_header(skb) +
arg->csumoffset) = csum_fold(csum_add(skb->csum,
arg->csum));
skb->ip_summed = CHECKSUM_NONE;
ip_push_pending_frames(sk);
}
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/ipconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
goto drop;

/* Basic sanity checks can be done without the lock. */
rarp = (struct arphdr *)skb->h.raw;
rarp = (struct arphdr *)skb_transport_header(skb);

/* If this test doesn't pass, it's not IP, or we should
* ignore it anyway.
Expand All @@ -455,7 +455,7 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
goto drop;

/* OK, it is all there and looks valid, process... */
rarp = (struct arphdr *)skb->h.raw;
rarp = (struct arphdr *)skb_transport_header(skb);
rarp_ptr = (unsigned char *) (rarp + 1);

/* One reply at a time, please. */
Expand Down
Loading

0 comments on commit 9c70220

Please sign in to comment.