Subject: RE: [PATCH] Packet socket: mmapped IO: PACKET_TX_RING

From: Johann Baudy <[email-masked]>
Date: Tue, 04 Nov 2008 23:45:43 +0100

Hi Vitali,

> Here's the code I came up with to determine the offset - anyone see any problems?
> 
> union {
>    tpacket2_hdr *t2;
>    u8 *raw;
> }
> 
> struct page *first_frag;
> u32 page_offset;
> 
> first_frag = skb_shinfo(skb)->frags[0].page;
> page_offset = skb_shinfo(skb)->frags[0].page_offset;
> 
> page_offset -= (skb_headlen(skb) + sizeof(struct tpacket2_hdr));
> if (unlikely(page_offset < 0)) {
> 	first_frag--;
> 	page_offset += PAGE_SIZE;
> }
> frame.raw = page_address(first_frag) + page_offset;
> 

This won't work if your network card doesn't support Scatter/Gather IO.
Indeed, when SG is not supported, fragmented packets are linearized
after dev_queue_xmit() call. Thus addresses of pages are then lost.

Best regards,
Johann