2001-10-29 04:08:49

by Taral

[permalink] [raw]
Subject: /proc/net/ip_conntrack problems

% 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.

--
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


2001-10-29 04:27:53

by Keith Owens

[permalink] [raw]
Subject: Re: /proc/net/ip_conntrack problems

On Sun, 28 Oct 2001 22:08:54 -0600,
Taral <[email protected]> wrote:
>% 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.

2001-10-29 04:36:36

by Taral

[permalink] [raw]
Subject: Re: /proc/net/ip_conntrack problems

On Mon, Oct 29, 2001 at 03:27:52PM +1100, Keith Owens wrote:
> 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?

--
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


Attachments:
(No filename) (801.00 B)
(No filename) (240.00 B)
Download all attachments

2001-10-29 21:19:06

by Mike Fedyk

[permalink] [raw]
Subject: Re: /proc/net/ip_conntrack problems

On Sun, Oct 28, 2001 at 10:36:51PM -0600, Taral wrote:
> On Mon, Oct 29, 2001 at 03:27:52PM +1100, Keith Owens wrote:
> > 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?
>

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

2001-10-29 22:24:19

by Taral

[permalink] [raw]
Subject: Re: /proc/net/ip_conntrack problems

On Mon, Oct 29, 2001 at 01:19:16PM -0800, Mike Fedyk wrote:
> 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.

--
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


Attachments:
(No filename) (647.00 B)
(No filename) (240.00 B)
Download all attachments