From: Jakub Kicinski <kubakici@wp.pl>
To: Niu Xilei <niu_xilei@163.com>
Cc: davem@davemloft.net, tglx@linutronix.de, fw@strlen.de,
peterz@infradead.org, steffen.klassert@secunet.com,
bigeasy@linutronix.de, jonathan.lemon@gmail.com,
pabeni@redhat.com, anshuman.khandual@arm.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] pktgen: create packet use IPv6 source address between src6_min and src6_max.
Date: Mon, 13 Jan 2020 04:51:36 -0800 [thread overview]
Message-ID: <20200113045136.4d59dded@cakuba> (raw)
In-Reply-To: <20200113112103.6766-1-niu_xilei@163.com>
The subject line could use some rewording, I think.
On Mon, 13 Jan 2020 19:21:02 +0800, Niu Xilei wrote:
> Pktgen can use only one IPv6 source address from output device, or src6 command
> setting. In pressure test we need create lots of session more than 65536.If
> IPSRC_RND flag is set, generate random source address between src6_min and src6_max.
>
> Signed-off-by: Niu Xilei <niu_xilei@163.com>
>
> Changes since v1:
> - only create IPv6 source address over least significant 64 bit range
> +/* generate ipv6 source addr */
> +static inline void set_src_in6_addr(struct pktgen_dev *pkt_dev)
Please just use "static" instead of "static inline". The compiler will
be clever enough to decide the inlining.
> +{
> + __be64 min6_h, min6_l, max6_h, max6_l, addr_l, *t;
> + u64 min6, max6, rand, i;
> + struct in6_addr addr6;
> +
> + memcpy(&min6_h, pkt_dev->min_in6_saddr.s6_addr, 8);
> + memcpy(&min6_l, pkt_dev->min_in6_saddr.s6_addr + 8, 8);
> + memcpy(&max6_h, pkt_dev->max_in6_saddr.s6_addr, 8);
> + memcpy(&max6_l, pkt_dev->max_in6_saddr.s6_addr + 8, 8);
> +
> + /* only generate source address in least significant 64 bits range
> + * most significant 64 bits must be equal
> + */
> + if (max6_h != min6_h)
> + return;
> +
> + addr6 = pkt_dev->min_in6_saddr;
> + t = (__be64 *)addr6.s6_addr + 1;
> + min6 = be64_to_cpu(min6_l);
> + max6 = be64_to_cpu(max6_l);
> +
> + if (min6 < max6) {
Since this code is executed on every packet, would it be possible to
pre-compute the decision if the IPv6 address is to be generated or not?
We have 4 memcpy()s and 2 byte swaps, and the conditions never change,
so it could be computed at setup time, right?
> + if (pkt_dev->flags & F_IPSRC_RND) {
> + do {
> + prandom_bytes(&rand, sizeof(rand));
> + rand = rand % (max6 - min6) + min6;
> + addr_l = cpu_to_be64(rand);
> + memcpy(t, &addr_l, 8);
> + } while (ipv6_addr_loopback(&addr6) ||
> + ipv6_addr_v4mapped(&addr6) ||
> + ipv6_addr_is_multicast(&addr6));
> + } else {
> + addr6 = pkt_dev->cur_in6_saddr;
> + i = be64_to_cpu(*t);
> + if (++i > max6)
> + i = min6;
> + addr_l = cpu_to_be64(i);
> + memcpy(t, &addr_l, 8);
> + }
> + }
> + pkt_dev->cur_in6_saddr = addr6;
> +}
prev parent reply other threads:[~2020-01-13 12:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-13 11:21 [PATCH v2] pktgen: create packet use IPv6 source address between src6_min and src6_max Niu Xilei
2020-01-13 12:51 ` Jakub Kicinski [this message]
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=20200113045136.4d59dded@cakuba \
--to=kubakici@wp.pl \
--cc=anshuman.khandual@arm.com \
--cc=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=fw@strlen.de \
--cc=jonathan.lemon@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=niu_xilei@163.com \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=steffen.klassert@secunet.com \
--cc=tglx@linutronix.de \
/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).