Skip to contentSkip to conversation

/proc/net/ip_conntrack problems

DISCUSSION Taral 3 participants 5 messages Oct 29, 2001

lore
Share & tools
lore

Taral

author
#0 lore raw

% dd if=/proc/net/ip_conntrack bs=128 | wc -l
0+0 records in
0+0 records out

      0
% dd if=/proc/net/ip_conntrack bs=256 | wc -l
0+3 records in
0+3 records out
      3
% dd if=/proc/net/ip_conntrack bs=512 | wc -l
0+2 records in
0+2 records out
      5

Can anyone explain this? (2.4.13-ac3) It's wreaking havoc with my program.

Signature · 4 lines
Taral <[email protected]>
This message is digitally signed. Please PGP encrypt mail to me.
"Any technology, no matter how primitive, is magic to those who don't
understand it." -- Florence Ambrose
#1 lore raw
Quoted 10 lines · Taral

% dd if=/proc/net/ip_conntrack bs=128 | wc -l
0+0 records in
0+0 records out

     0
% dd if=/proc/net/ip_conntrack bs=256 | wc -l
0+3 records in
0+3 records out
     3

Can anyone explain this? (2.4.13-ac3) It's wreaking havoc with my program.

Some /proc output is blocked, it will only return complete lines. If your buffer is not big enough to hold the next line then you don't get anything at all. Try cat /proc/net/ip_conntrack | wc.

author
#2 lore raw
In reply to Taral
Quoted 3 lines · Keith Owens

Some /proc output is blocked, it will only return complete lines. If your buffer is not big enough to hold the next line then you don't get anything at all. Try cat /proc/net/ip_conntrack | wc.

So why are 2 lines missing when I change the blocking factor from 256 to 512? Even cat reads in 16k blocks... Also:

% dd if=/proc/net/ip_conntrack bs=512 | perl -ne 'print length()."\n"' 0+2 records in
0+2 records out
153
138
169
151
167
139

No line is longer than 256 chars, so why are 2 lines missing when I read in 256 byte blocks?

Signature · 4 lines
Taral <[email protected]>
This message is digitally signed. Please PGP encrypt mail to me.
"Any technology, no matter how primitive, is magic to those who don't
understand it." -- Florence Ambrose
#3 lore raw
In reply to Taral
Quoted 18 lines · Taral
Quoted 3 lines · Keith Owens

Some /proc output is blocked, it will only return complete lines. If your buffer is not big enough to hold the next line then you don't get anything at all. Try cat /proc/net/ip_conntrack | wc.

So why are 2 lines missing when I change the blocking factor from 256 to 512? Even cat reads in 16k blocks... Also:

% dd if=/proc/net/ip_conntrack bs=512 | perl -ne 'print length()."\n"' 0+2 records in
0+2 records out
153
138
169
151
167
139

Quoted 3 lines

No line is longer than 256 chars, so why are 2 lines missing when I read in 256 byte blocks?

Because you would need the buffer size to hit the moving target of any of the boundaries of the lines. So you would need (for the example above) buffer sizes of:
153
291
460
611
778
778

16k blocks would hold all of those...

IIRC, proc files have trouble returning output larget than one page (4k)...

Mike

author
#4 lore raw
In reply to Taral
Quoted 11 lines · Mike Fedyk

Because you would need the buffer size to hit the moving target of any of the boundaries of the lines. So you would need (for the example above) buffer sizes of:
153
291
460
611
778
778

16k blocks would hold all of those...

Wrong again. /proc/net/ip_conntrack has code to support incrementally reading the file. It's broken, I'm just not sure _how_ it's broken.

Signature · 4 lines
Taral <[email protected]>
This message is digitally signed. Please PGP encrypt mail to me.
"Any technology, no matter how primitive, is magic to those who don't
understand it." -- Florence Ambrose