Re: [PATCH v2 net-next af-packet 1/2] Enhance af-packet to provide (near zero)lossless packet capture functionality.
From: chetan loke <hidden>
Date: 2011-07-05 14:53:30
Also in:
lkml
On Fri, Jul 1, 2011 at 6:36 PM, David Miller [off-list ref] wrote:
From: Chetan Loke <redacted> Date: Tue, 21 Jun 2011 22:10:49 -0400quoted
+struct bd_v1 {-quoted
+ __u32 block_status; + __u32 num_pkts; + __u32 offset_to_first_pkt;-quoted
+ __u32 blk_len;-quoted
+ __u64 seq_num;...quoted
+ union { + struct { + __u32 words[4]; + __u64 dword; + } __attribute__ ((__packed__)); + struct bd_v1 bd1;...quoted
+#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