Re: [PATCH v2 net-next af-packet 1/2] Enhance af-packet to provide(near zero)lossless packet capture functionality.

From: chetan loke
Date: Tue Jul 05 2011 - 10:53:36 EST


On Fri, Jul 1, 2011 at 6:36 PM, David Miller <davem@xxxxxxxxxxxxx> wrote:
> From: Chetan Loke <loke.chetan@xxxxxxxxx>
> Date: Tue, 21 Jun 2011 22:10:49 -0400
>
>> +struct bd_v1 {
> Â-
>> + Â Â __u32 Â block_status;
>> + Â Â __u32 Â num_pkts;
>> + Â Â __u32 Â offset_to_first_pkt;
> Â-
>> + Â Â __u32 Â blk_len;
> Â-
>> + Â Â __u64 Â seq_num;
> Â...
>> + Â Â union {
>> + Â Â Â Â Â Â struct {
>> + Â Â Â Â Â Â Â Â Â Â __u32 Â words[4];
>> + Â Â Â Â Â Â Â Â Â Â __u64 Â dword;
>> + Â Â Â Â Â Â } __attribute__ ((__packed__));
>> + Â Â Â Â Â Â struct bd_v1 bd1;
> Â...
>> +#define BLOCK_STATUS(x) Â Â Â((x)->words[0])
>> +#define BLOCK_NUM_PKTS(x) Â Â((x)->words[1])
>> +#define BLOCK_O2FP(x) Â Â Â Â Â Â Â Â((x)->words[2])
>> +#define BLOCK_LEN(x) Â Â Â Â ((x)->words[3])
>> +#define BLOCK_SNUM(x) Â Â Â Â Â Â Â Â((x)->dword)
>

Sorry, I was out on the long weekend. So couldn't get to this sooner.

> This BLOCK_SNUM definition is buggy. ÂIt modifies the
> first 64-bit word in the block descriptor.
>
> But the sequence number lives 16 bytes into the descriptor.

hmm? the words/dword are enveloped within a 'struct'. Can you please
double check?

>
> This value is only written to once and never used by anything.
> I would just remove it entirely.
>

It is used by the applications. Look at the code comments:
/*
* Quite a few uses of sequence number:
* 1. Make sure cache flush etc worked.
* Well, one can argue - why not use the increasing ts below?
* But look at 2. below first.
* 2. When you pass around blocks to other user space decoders,
* you can see which blk[s] is[are] outstanding etc.
* 3. Validate kernel code.
*/


> Next, having this overlay thing is entirely pointless. ÂJust refer to

It is useful.
Also, future versions of the block-descriptor can append a new field.
When that happens,
none of the code needs to worry about the version etc for the unchanged fields.
Look at setsockopt - I had to add an 'union' and pass that around to
avoid minimal code churn.
So the overlay may not be pointless.

> the block descriptor members directly! ÂYou certainly wouldn't have
> had this sequence number bug if you had done that.
>
Look at the sample app posted on:
git://lolpcap.git.sourceforge.net/gitroot/lolpcap/lolpcap

function - void validate_blk_seq_num(struct block_desc *pbd)

This function validates the block_sequence_number (which is
incremented sequentially).
The application attempts to validate the entire block layout.


Chetan Loke
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/