From: Patrick McHardy <kaber@trash.net>
To: Harald Welte <laforge@netfilter.org>
Cc: Linux Netdev List <netdev@vger.kernel.org>,
Netfilter Development Mailinglist
<netfilter-devel@lists.netfilter.org>
Subject: Re: [PATCH] add new iptables ipt_connbytes match
Date: Fri, 12 Aug 2005 04:52:49 +0200 [thread overview]
Message-ID: <42FC0F01.5090802@trash.net> (raw)
In-Reply-To: <20050811200349.GN5353@rama.de.gnumonks.org>
Harald Welte wrote:
> +/* 64bit divisor, dividend and result. dynamic precision */
> +static u_int64_t div64_64(u_int64_t divisor, u_int64_t dividend)
> +{
> + u_int64_t result = divisor;
> +
> + if (dividend > 0xffffffff) {
> + int first_bit = find_first_bit((unsigned long *) ÷nd, sizeof(dividend));
> + /* calculate number of bits to shift. shift exactly enough
> + * bits to make dividend fit in 32bits. */
> + int num_shift = (64 - 32 - first_bit);
> + /* first bit has to be < 32, since dividend was > 0xffffffff */
> + result = result >> num_shift;
> + dividend = dividend >> num_shift;
> + }
> +
> + do_div(divisor, dividend);
> +
> + return divisor;
> +}
This functions looks broken. Divisor and divident are mixed up, the
shifted result variable is not used in the actual division, the
"first bit has to be < 32" assumption is wrong and num_shift is
calculated incorrectly. To find a 32-bit divisor consisting of the
most-significant 32 bits we need to find the highest bit set and
subtract 32 from this, then right-shift by that value if it is larger
than 0. I can send a fixed patch tomorrow but I'm too tired now.
> + case IPT_CONNBYTES_WHAT_PKTS:
I would really prefer the name IPT_CONNBYTES_PKTS :)
Regards
Patrick
next prev parent reply other threads:[~2005-08-12 2:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-11 20:03 [PATCH] add new iptables ipt_connbytes match Harald Welte
2005-08-11 22:42 ` David S. Miller
2005-08-12 11:39 ` Andi Kleen
2005-08-12 11:57 ` Patrick McHardy
2005-08-12 12:03 ` Andi Kleen
2005-08-12 15:37 ` Harald Welte
2005-08-12 18:12 ` David S. Miller
2005-08-12 18:23 ` Andi Kleen
2005-08-12 19:03 ` Harald Welte
2005-08-12 19:08 ` Andi Kleen
2005-08-12 19:09 ` David S. Miller
2005-08-13 14:50 ` Harald Welte
2005-08-13 20:54 ` David S. Miller
2005-08-13 15:45 ` [PATCH] introduce and use aligned_u64 in nfnetlink Harald Welte
2005-08-13 20:56 ` David S. Miller
2005-08-13 15:46 ` [PATCH] add new iptables ipt_connbytes match Harald Welte
2005-08-13 20:56 ` David S. Miller
2005-08-12 11:46 ` Harald Welte
2005-08-12 2:52 ` Patrick McHardy [this message]
2005-08-12 11:56 ` Harald Welte
2005-08-13 1:20 ` Patrick McHardy
2005-08-13 14:51 ` Harald Welte
2005-08-13 20:59 ` David S. Miller
2005-08-13 20:58 ` David S. Miller
2005-08-16 11:18 ` Amin Azez
2005-08-17 10:29 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42FC0F01.5090802@trash.net \
--to=kaber@trash.net \
--cc=laforge@netfilter.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).